當前位置: 首頁>>代碼示例>>C#>>正文


C# Ast類代碼示例

本文整理匯總了C#中Ast的典型用法代碼示例。如果您正苦於以下問題:C# Ast類的具體用法?C# Ast怎麽用?C# Ast使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Ast類屬於命名空間,在下文中一共展示了Ast類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AnalyzeDSCResource

        /// <summary>
        /// AnalyzeDSCResource: Analyzes the ast to check that Write-Verbose is called for DSC Resources
        /// <param name="ast">The script's ast</param>
        /// <param name="fileName">The script's file name</param>
        /// </summary>
        public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName)
        {
            if (ast == null)
            {
                throw new ArgumentNullException(Strings.NullAstErrorMessage);
            }            

            IEnumerable<Ast> functionDefinitionAsts = Helper.Instance.DscResourceFunctions(ast);

            foreach (FunctionDefinitionAst functionDefinitionAst in functionDefinitionAsts)
            {
                var commandAsts = functionDefinitionAst.Body.FindAll(testAst => testAst is CommandAst, false);
                bool hasVerbose = false;

                if (null != commandAsts)
                {
                    foreach (CommandAst commandAst in commandAsts)
                    {
                        hasVerbose |= String.Equals(commandAst.GetCommandName(), "Write-Verbose", StringComparison.OrdinalIgnoreCase);
                    }
                }

                if (!hasVerbose)
                {
                    yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.UseVerboseMessageInDSCResourceErrorFunction, functionDefinitionAst.Name),
                        functionDefinitionAst.Extent, GetName(), DiagnosticSeverity.Information, fileName);
                }

            }
        }
開發者ID:AndrewGaspar,項目名稱:PSScriptAnalyzer,代碼行數:35,代碼來源:UseVerboseMessageInDSCResource.cs

示例2: Scope

 internal Scope(IParameterMetadataProvider ast, ScopeType scopeType)
 {
     _ast = (Ast)ast;
     _scopeType = scopeType;
     _typeTable = new Dictionary<string, TypeLookupResult>(StringComparer.OrdinalIgnoreCase);
     _variableTable = new Dictionary<string, Ast>(StringComparer.OrdinalIgnoreCase);
 }
開發者ID:40a,項目名稱:PowerShell,代碼行數:7,代碼來源:SymbolResolver.cs

示例3: AnalyzeScript

        /// <summary>
        /// MisleadingBacktick: Checks that lines don't end with a backtick followed by a whitespace
        /// </summary>
        public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
        {
            if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage);

            string[] lines = NewlineRegex.Split(ast.Extent.Text);

            if((ast.Extent.EndLineNumber - ast.Extent.StartLineNumber + 1) != lines.Length)
            {
                // Did not match the number of lines that the extent indicated
                yield break;
            }

            foreach (int i in Enumerable.Range(0, lines.Length))
            {
                string line = lines[i];

                Match match = TrailingEscapedWhitespaceRegex.Match(line);

                if(match.Success)
                {
                    int lineNumber = ast.Extent.StartLineNumber + i;

                    ScriptPosition start = new ScriptPosition(fileName, lineNumber, match.Index, line);
                    ScriptPosition end = new ScriptPosition(fileName, lineNumber, match.Index + match.Length, line);

                    yield return new DiagnosticRecord(
                        string.Format(CultureInfo.CurrentCulture, Strings.MisleadingBacktickError),
                            new ScriptExtent(start, end), GetName(), DiagnosticSeverity.Warning, fileName);
                }
            }
        }
開發者ID:rkeithhill,項目名稱:PSScriptAnalyzer,代碼行數:34,代碼來源:MisleadingBacktick.cs

示例4: VisitBlockExpression

        public virtual Ast.Expression VisitBlockExpression(Ast.BlockExpression blockExpression)
        {
            foreach (var expression in blockExpression.Expressions)
                this.Visit(expression);

            return blockExpression;
        }
開發者ID:swijnands,項目名稱:LinqExtender,代碼行數:7,代碼來源:ExpressionVisitor.cs

示例5: VisitBinaryExpression

        public virtual Ast.Expression VisitBinaryExpression(Ast.BinaryExpression expression)
        {
            this.Visit(expression.Left);
            this.Visit(expression.Right);

            return expression;
        }
開發者ID:swijnands,項目名稱:LinqExtender,代碼行數:7,代碼來源:ExpressionVisitor.cs

示例6: VisitMethodInvocationExpression

        public override void VisitMethodInvocationExpression(Ast.Expressions.MethodInvocationExpression node)
        {
            MethodDefinition methodDef = node.MethodExpression.MethodDefinition;
            if (methodDef == null)
            {
                base.VisitMethodInvocationExpression(node);
                return;
            }

            Visit(node.MethodExpression);

            for (int i = 0; i < node.Arguments.Count; i++)
            {
                UnaryExpression unaryArgument = node.Arguments[i] as UnaryExpression;
                if (methodDef.Parameters[i].IsOutParameter() && (unaryArgument != null && unaryArgument.Operator == UnaryOperator.AddressReference &&
                     CheckExpression(unaryArgument.Operand) || CheckExpression(node.Arguments[i])))
                {
                    this.searchResult = UsageFinderSearchResult.Assigned;
                    return;
                }
                else
                {
                    Visit(node.Arguments[i]);
                    if (this.searchResult != UsageFinderSearchResult.NotFound)
                    {
                        return;
                    }
                }
            }
        }
開發者ID:besturn,項目名稱:JustDecompileEngine,代碼行數:30,代碼來源:BaseUsageFinder.cs

示例7: AstBuilder_ComplexExpression_Build

        public void AstBuilder_ComplexExpression_Build()
        {
            var tree = new Ast("+", true);
            tree.Operands.Add(new Ast("4"));
            tree.Operands.Add(new Ast("6"));

            var buffer = new Ast("/", true);
            buffer.Operands.Add(new Ast("81"));
            buffer.Operands.Add(new Ast("-3"));

            var anotherBuffer = new Ast("*", true);
            anotherBuffer.Operands.Add(new Ast("3"));
            anotherBuffer.Operands.Add(new Ast("3"));
            buffer.Operands.Add(anotherBuffer);

            tree.Operands.Add(buffer);

            buffer = new Ast("-", true);
            buffer.Operands.Add(new Ast("10"));
            buffer.Operands.Add(new Ast("12"));

            tree.Operands.Add(buffer);
            var input = "(+ 4 6 (/ 81 -3 (* 3 3 ))( - 10 12 ))";

            var actualTree = new AstBuilder().Build(new Tokenizer().GetTokens(input));
            Assert.IsTrue(actualTree.Equals(tree));
        }
開發者ID:fanatt20,項目名稱:ProgrammingTasks,代碼行數:27,代碼來源:AstBuilderTest.cs

示例8: AnalyzeScript

        /// <summary>
        /// AnalyzeScript: Run Test Module Manifest to check that none of the required fields are missing. From the ILintScriptRule interface.
        /// </summary>
        /// <param name="ast">The script's ast</param>
        /// <param name="fileName">The script's file name</param>
        /// <returns>A List of diagnostic results of this rule</returns>
        public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
        {
            if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage);

            if (String.Equals(System.IO.Path.GetExtension(fileName), ".psd1", StringComparison.OrdinalIgnoreCase))
            {
                IEnumerable<ErrorRecord> errorRecords;
                var psModuleInfo = Helper.Instance.GetModuleManifest(fileName, out errorRecords);
                if (errorRecords != null)
                {
                    foreach (var errorRecord in errorRecords)
                    {
                        if (Helper.IsMissingManifestMemberException(errorRecord))
                        {
                            System.Diagnostics.Debug.Assert(
                                errorRecord.Exception != null && !String.IsNullOrWhiteSpace(errorRecord.Exception.Message),
                                Strings.NullErrorMessage);
                            var hashTableAst = ast.Find(x => x is HashtableAst, false);
                            if (hashTableAst == null)
                            {
                                yield break;
                            }
                            yield return new DiagnosticRecord(
                                errorRecord.Exception.Message,
                                hashTableAst.Extent,
                                GetName(),
                                DiagnosticSeverity.Warning,
                                fileName,
                                suggestedCorrections:GetCorrectionExtent(hashTableAst as HashtableAst));
                        }

                    }
                }
            }
        }
開發者ID:kilasuit,項目名稱:PSScriptAnalyzer,代碼行數:41,代碼來源:MissingModuleManifestField.cs

示例9: Compile

        public LuaFile Compile(Ast.Chunk c, string name)
        {
            file = new LuaFile();
            block = new Block();
            block.Chunk.Name = name;
            block.Chunk.ArgumentCount = 0;
            block.Chunk.Vararg = 2;

            DoChunk(c);

            file.Main = block.Chunk;
            file.Main.ArgumentCount = 0;
            file.Main.Vararg = 2;
            file.Main.UpvalueCount = file.Main.Upvalues.Count;
            bool addRet = file.Main.Instructions.Count == 0;
            if (addRet == false)
                addRet = file.Main.Instructions[file.Main.Instructions.Count - 1].Opcode != Instruction.LuaOpcode.RETURN;
            if (addRet)
            {
                Instruction ret = new Instruction("RETURN");
                ret.A = 0;
                ret.B = 1;
                ret.C = 0;
                file.Main.Instructions.Add(ret);
            }
            return file;
        }
開發者ID:zeta945,項目名稱:SharpLua,代碼行數:27,代碼來源:Compiler3.cs

示例10: Emit

            public override void Emit(VirtualMachine.InstructionList into, Ast.OperationDestination Destination)
            {
                //Prepare loop control variables
                List.Emit(into, Ast.OperationDestination.Stack);	//[email protected]
                LengthFunc.Emit(into, Ast.OperationDestination.Stack); //[email protected]
                into.AddInstructions("MOVE NEXT PUSH # SET [email protected]", 0);			//[email protected]

                var LoopStart = into.Count;

                into.AddInstructions(
                    "LOAD_PARAMETER NEXT R #" + TotalVariable.Name, TotalVariable.Offset,
                    "GREATER_EQUAL PEEK R R #PEEK = [email protected]",
                    "IF_TRUE R",
                    "JUMP NEXT", 0);

                var BreakPoint = into.Count - 1;

                Indexer.Emit(into, Ast.OperationDestination.Stack);
                Body.Emit(into, Ast.OperationDestination.Discard);

                into.AddInstructions(
                    "MOVE POP #REMOVE [email protected]",
                    "INCREMENT PEEK PEEK",
                    "JUMP NEXT", LoopStart);

                into[BreakPoint] = into.Count;

                into.AddInstructions("CLEANUP NEXT #REMOVE [email protected], [email protected], [email protected]", 3);
            }
開發者ID:Blecki,項目名稱:EtcScript,代碼行數:29,代碼來源:ForeachXInList.cs

示例11: AnalyzeScript

        /// <summary>
        /// AnalyzeScript: Analyzes the script to check if any non-constant members have been invoked.
        /// </summary>
        public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
        {
            if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage);

            IEnumerable<Ast> memberExpression = ast.FindAll(testAst => testAst is MemberExpressionAst, true);
            foreach (MemberExpressionAst member in memberExpression)
            {
                string context = member.Member.Extent.ToString();
                if (context.Contains("("))
                {
                    //check if parenthesis and have non-constant members
                    IEnumerable<Ast> binaryExpression = member.FindAll(
                        binaryAst => binaryAst is BinaryExpressionAst, true);
                    if (binaryExpression.Any())
                    {
                        foreach (BinaryExpressionAst bin in binaryExpression)
                        {
                            if (!bin.Operator.Equals(null))
                            {
                                yield return
                                    new DiagnosticRecord(
                                        string.Format(CultureInfo.CurrentCulture,
                                            Strings.AvoidInvokingEmptyMembersError,
                                            context),
                                        member.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
                            }
                        }
                    }
                }
            }
        
        }
開發者ID:AndrewGaspar,項目名稱:PSScriptAnalyzer,代碼行數:35,代碼來源:AvoidInvokingEmptyMembers.cs

示例12: ForeachIn

 public ForeachIn(Token Source, String VariableName, Ast.Node List, Ast.Node Body)
     : base(Source)
 {
     this.VariableName = VariableName;
     this.List = List;
     this.Body = Body;
 }
開發者ID:Blecki,項目名稱:EtcScript,代碼行數:7,代碼來源:ForeachXInList.cs

示例13: Process

 public Ast.Statements.BlockStatement Process(Decompiler.DecompilationContext context, Ast.Statements.BlockStatement body)
 {
     this.methodContext = context.MethodContext;
     mappedInstructions.UnionWith(body.UnderlyingSameMethodInstructions);
     Visit(body);
     return body;
 }
開發者ID:juancarlosbaezpozos,項目名稱:JustDecompileEngine,代碼行數:7,代碼來源:MapUnconditionalBranchesStep.cs

示例14: IsConstant

        public static bool IsConstant(Ast ast, out object constantValue, bool forAttribute = false, bool forRequires = false)
        {
            try
            {
                if ((bool)ast.Accept(new IsConstantValueVisitor { CheckingAttributeArgument = forAttribute, CheckingRequiresArgument = forRequires }))
                {
                    Ast parent = ast.Parent;
                    while (parent != null)
                    {
                        if (parent is DataStatementAst)
                        {
                            break;
                        }
                        parent = parent.Parent;
                    }

                    if (parent == null)
                    {
                        constantValue = ast.Accept(new ConstantValueVisitor { AttributeArgument = forAttribute, RequiresArgument = forRequires });
                        return true;
                    }
                }
            }
            catch (Exception e)
            {
                // If we get an exception, ignore it and assume the expression isn't constant.
                // This can happen, e.g. if a cast is invalid:
                //     [int]"zed"
                CommandProcessorBase.CheckForSevereException(e);
            }

            constantValue = null;
            return false;
        }
開發者ID:40a,項目名稱:PowerShell,代碼行數:34,代碼來源:ConstantValues.cs

示例15: CompletionAnalysis

 internal CompletionAnalysis(Ast ast, Token[] tokens, IScriptPosition cursorPosition, Hashtable options)
 {
     _ast = ast;
     _tokens = tokens;
     _cursorPosition = cursorPosition;
     _options = options;
 }
開發者ID:dfinke,項目名稱:powershell,代碼行數:7,代碼來源:CompletionAnalysis.cs


注:本文中的Ast類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。