当前位置: 首页>>代码示例>>C#>>正文


C# Ast.Visit方法代码示例

本文整理汇总了C#中Ast.Visit方法的典型用法代码示例。如果您正苦于以下问题:C# Ast.Visit方法的具体用法?C# Ast.Visit怎么用?C# Ast.Visit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ast的用法示例。


在下文中一共展示了Ast.Visit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindCommandAtPosition

        /// <summary>
        /// Finds the symbol (always Command type) at a given file location
        /// </summary>
        /// <param name="scriptAst">The abstract syntax tree of the given script</param>
        /// <param name="lineNumber">The line number of the cursor for the given script</param>
        /// <param name="columnNumber">The column number of the cursor for the given script</param>
        /// <returns>SymbolReference of found command</returns>
        public static SymbolReference FindCommandAtPosition(Ast scriptAst, int lineNumber, int columnNumber)
        {
            FindCommandVisitor commandVisitor = new FindCommandVisitor(lineNumber, columnNumber);
            scriptAst.Visit(commandVisitor);

            return commandVisitor.FoundCommandReference;
        }
开发者ID:juvchan,项目名称:PowerShellEditorServices,代码行数:14,代码来源:AstOperations.cs

示例2: FindDotSourcedIncludes

        /// <summary>
        /// Finds all files dot sourced in a script
        /// </summary>
        /// <param name="scriptAst">The abstract syntax tree of the given script</param>
        /// <returns></returns>
        public static string[] FindDotSourcedIncludes(Ast scriptAst)
        {
            FindDotSourcedVisitor dotSourcedVisitor = new FindDotSourcedVisitor();
            scriptAst.Visit(dotSourcedVisitor);

            return dotSourcedVisitor.DotSourcedFiles.ToArray();
        }
开发者ID:juvchan,项目名称:PowerShellEditorServices,代码行数:12,代码来源:AstOperations.cs

示例3: GetText

        public string GetText(Ast ast)
        {
            var visitor = new GetTextAstVisitor(this);
            ast.Visit(visitor);

            return visitor.Text;
        }
开发者ID:cmanrus,项目名称:challenge,代码行数:7,代码来源:PSScriptAst.cs

示例4: AnalyzeScript

        /// <summary>
        /// AnalyzeScript: check that Write-Host or Console.Write are not used.
        /// </summary>
        public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
        {
            if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage);

            records = new List<DiagnosticRecord>();
            this.fileName = fileName;

            ast.Visit(this);

            return records;
        }
开发者ID:nick4eva,项目名称:PSScriptAnalyzer,代码行数:14,代码来源:AvoidUsingWriteHost.cs

示例5: FindDefinitionOfSymbol

        /// <summary>
        /// Finds the definition of the symbol 
        /// </summary>
        /// <param name="scriptAst">The abstract syntax tree of the given script</param>
        /// <param name="symbolReference">The symbol that we are looking for the definition of</param>
        /// <returns>A SymbolReference of the definition of the symbolReference</returns>
        public static SymbolReference FindDefinitionOfSymbol(
            Ast scriptAst,
            SymbolReference symbolReference)
        {
            FindDeclartionVisitor declarationVisitor =
                new FindDeclartionVisitor(
                    symbolReference);
            scriptAst.Visit(declarationVisitor);

            return declarationVisitor.FoundDeclartion;
        }
开发者ID:juvchan,项目名称:PowerShellEditorServices,代码行数:17,代码来源:AstOperations.cs

示例6: AnalyzeScript

        /// <summary>
        /// AnalyzeScript: Analyzes the ast to check that cmdlets have help.
        /// </summary>
        /// <param name="ast">The script's ast</param>
        /// <param name="fileName">The name of the script</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);

            DiagnosticRecords.Clear();
            this.fileName = fileName;
            exportedFunctions = Helper.Instance.GetExportedFunction(ast);

            ast.Visit(this);

            return DiagnosticRecords;
        }
开发者ID:GoFrag,项目名称:PSScriptAnalyzer,代码行数:18,代码来源:ProvideCommentHelp.cs

示例7: AnalyzeScript

        /// <summary>
        /// AnalyzeScript: Checks that objects return in a cmdlet have their types declared in OutputType Attribute
        /// </summary>
        /// <param name="ast">The script's ast</param>
        /// <param name="fileName">The name of the script</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);

            DiagnosticRecords.Clear();
            this.fileName = fileName;

            _classes = ast.FindAll(item => item is TypeDefinitionAst && ((item as TypeDefinitionAst).IsClass), true).Cast<TypeDefinitionAst>();

            ast.Visit(this);

            return DiagnosticRecords;
        }
开发者ID:nick4eva,项目名称:PSScriptAnalyzer,代码行数:19,代码来源:UseOutputTypeCorrectly.cs

示例8: EvaluateAst

        public object EvaluateAst(Ast expressionAst, bool writeSideEffectsToPipeline)
        {
            var subVisitor = this.CloneSub(writeSideEffectsToPipeline);
            expressionAst.Visit(subVisitor);
            var result = subVisitor._pipelineCommandRuntime.OutputStream.Read();

            if (result.Count == 0)
            {
                return null;
            }
            else if (result.Count == 1)
            {
                return result.Single();
            }
            return result.ToArray();
        }
开发者ID:bitwiseman,项目名称:Pash,代码行数:16,代码来源:ExecutionVisitor.cs

示例9: FindSymbolsInDocument

        /// <summary>
        /// Finds all symbols in a script
        /// </summary>
        /// <param name="scriptAst">The abstract syntax tree of the given script</param>
        /// <param name="powerShellVersion">The PowerShell version the Ast was generated from</param>
        /// <returns>A collection of SymbolReference objects</returns>
        static public IEnumerable<SymbolReference> FindSymbolsInDocument(Ast scriptAst, Version powerShellVersion)
        {
            IEnumerable<SymbolReference> symbolReferences = null;

            if (powerShellVersion >= new Version(5,0))
            {
#if PowerShellv5
                FindSymbolsVisitor2 findSymbolsVisitor = new FindSymbolsVisitor2();
                scriptAst.Visit(findSymbolsVisitor);
                symbolReferences = findSymbolsVisitor.SymbolReferences;
#endif
            }
            else
            {
                FindSymbolsVisitor findSymbolsVisitor = new FindSymbolsVisitor();
                scriptAst.Visit(findSymbolsVisitor);
                symbolReferences = findSymbolsVisitor.SymbolReferences;
            }

            return symbolReferences;
        }
开发者ID:modulexcite,项目名称:PowerShellEditorServices,代码行数:27,代码来源:AstOperations.cs

示例10: Validate

        private string Validate(Ast rootAst)
        {
            if (_parseErrors != null && _parseErrors.Length > 0)
            {
                // Move the cursor to the point of error
                _current = _parseErrors[0].Extent.EndOffset;
                return _parseErrors[0].Message;
            }

            var validationVisitor = new CommandValidationVisitor(rootAst);
            rootAst.Visit(validationVisitor);
            if (!string.IsNullOrWhiteSpace(validationVisitor.detectedError))
            {
                return validationVisitor.detectedError;
            }

            return null;
        }
开发者ID:rkeithhill,项目名称:PSReadLine,代码行数:18,代码来源:BasicEditing.cs

示例11: EvaluateAst

        object EvaluateAst(Ast expressionAst, bool writeSideEffectsToPipeline)
        {
            var subVisitor = this.CloneSub(writeSideEffectsToPipeline);
            expressionAst.Visit(subVisitor);
            var result = subVisitor._pipelineCommandRuntime.outputResults.Read();

            if (result.Count == 0) return null;
            if (result.Count == 1) return result.Single();
            return result;
        }
开发者ID:JayBazuzi,项目名称:Pash,代码行数:10,代码来源:ExecutionVisitor.cs

示例12: EvaluateLoopBodyAst

        public bool EvaluateLoopBodyAst(Ast expressionAst, string loopLabel)
        {
            var loopCanContinue = true;

            try
            {
                expressionAst.Visit(this);
            }
            catch (LoopFlowException e)
            {
                if (!String.IsNullOrEmpty(e.Label) && !e.Label.Equals(loopLabel))
                {
                    throw;
                }
                loopCanContinue = e is ContinueException;
            }

            // return if the loop can continue execution or should break
            return loopCanContinue;
        }
开发者ID:mauve,项目名称:Pash,代码行数:20,代码来源:ExecutionVisitor.cs

示例13: GenerateWhileLoop

        internal void GenerateWhileLoop(string loopLabel,
                                       Action generateCondition,
                                       Action generateLoopBody,
                                       Ast continueAction = null)
        {
            // We model the flow graph like this (if continueAction is null, the first part is slightly different):
            //    goto L
            //    :ContinueTarget
            //        continueAction
            //    :L
            //    if (condition)
            //    {
            //        loop body
            //        // break -> goto BreakTarget
            //        // continue -> goto ContinueTarget
            //        goto ContinueTarget
            //    }
            //    :BreakTarget

            var continueBlock = new Block();

            if (continueAction != null)
            {
                var blockAfterContinue = new Block();

                // Represent the goto over the condition before the first iteration.
                _currentBlock.FlowsTo(blockAfterContinue);

                _currentBlock = continueBlock;
                continueAction.Visit(this.Decorator);

                _currentBlock.FlowsTo(blockAfterContinue);
                _currentBlock = blockAfterContinue;
            }
            else
            {
                _currentBlock.FlowsTo(continueBlock);
                _currentBlock = continueBlock;
            }

            var bodyBlock = new Block();
            var breakBlock = new Block();

            // Condition can be null from an uncommon for loop: for() {}
            if (generateCondition != null)
            {
                generateCondition();
                _currentBlock.FlowsTo(breakBlock);
            }

            _loopTargets.Add(new LoopGotoTargets(loopLabel ?? "", breakBlock, continueBlock));
            _currentBlock.FlowsTo(bodyBlock);
            _currentBlock = bodyBlock;
            generateLoopBody();
            _currentBlock.FlowsTo(continueBlock);

            _currentBlock = breakBlock;

            _loopTargets.RemoveAt(_loopTargets.Count - 1);
        }
开发者ID:GoFrag,项目名称:PSScriptAnalyzer,代码行数:60,代码来源:VariableAnalysisBase.cs

示例14: VisitChildren

 private void VisitChildren(Ast ast, object newParentObject)
 {
     this.ParentObjectStack.Push(newParentObject);
     ast.Visit(this);
     this.ParentObjectStack.Pop();
 }
开发者ID:c0ns0le,项目名称:PsISEProjectExplorer,代码行数:6,代码来源:Powershell5TokenVisitor.cs

示例15: AnalyzeImpl

        /// <summary>
        /// Used to analyze scriptbloct, functionmemberast or functiondefinitionast
        /// </summary>
        /// <param name="ast"></param>
        /// <returns></returns>
        public void AnalyzeImpl(Ast ast, VariableAnalysis outerAnalysis)
        {
            if (!(ast is ScriptBlockAst || ast is FunctionMemberAst || ast is FunctionDefinitionAst))
            {
                return;
            }

            _variables = FindAllVariablesVisitor.Visit(ast);

            Init();

            if (ast is FunctionMemberAst || ast is FunctionDefinitionAst)
            {
                IEnumerable<ParameterAst> parameters = FindParameters(ast, ast.GetType());
                if (parameters != null)
                {
                    ProcessParameters(parameters);
                }
            }
            else
            {
                ScriptBlockAst sbAst = ast as ScriptBlockAst;
                if (sbAst != null && sbAst.ParamBlock != null && sbAst.ParamBlock.Parameters != null)
                {
                    ProcessParameters(sbAst.ParamBlock.Parameters);
                }
            }

            if (ast is FunctionMemberAst)
            {
                (ast as FunctionMemberAst).Body.Visit(this.Decorator);
            }
            else if (ast is FunctionDefinitionAst)
            {
                (ast as FunctionDefinitionAst).Body.Visit(this.Decorator);
            }
            else
            {
                ast.Visit(this.Decorator);
            }

            Ast parent = ast;

            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }

            List<TypeDefinitionAst> classes = parent.FindAll(item =>
                item is TypeDefinitionAst && (item as TypeDefinitionAst).IsClass, true)
                .Cast<TypeDefinitionAst>().ToList();

            if (outerAnalysis != null)
            {
                // Initialize the variables from outside
                var outerDictionary = outerAnalysis.InternalVariablesDictionary;
                foreach (var details in outerDictionary.Values)
                {
                    if (details.DefinedBlock != null)
                    {
                        var assignTarget = new AssignmentTarget(details.RealName, details.Type);
                        assignTarget.Constant = details.Constant;
                        if (!_variables.ContainsKey(assignTarget.Name))
                        {
                            _variables.Add(assignTarget.Name, new VariableAnalysisDetails
                            {
                                Name = assignTarget.Name,
                                RealName = assignTarget.Name,
                                Type = assignTarget.Type
                            });
                        }
                        Entry.AddFirstAst(assignTarget);
                    }
                }

                foreach (var key in _variables.Keys)
                {
                    if (outerDictionary.ContainsKey(key))
                    {
                        var outerItem = outerDictionary[key];
                        var innerItem = _variables[key];
                        innerItem.Constant = outerItem.Constant;
                        innerItem.Name = outerItem.Name;
                        innerItem.RealName = outerItem.RealName;
                        innerItem.Type = outerItem.Type;
                    }
                }
            }

            var dictionaries = Block.SparseSimpleConstants(_variables, Entry, classes);
            VariablesDictionary = dictionaries.Item1;
            InternalVariablesDictionary = new Dictionary<string, VariableAnalysisDetails>(StringComparer.OrdinalIgnoreCase);

            foreach (var KVP in dictionaries.Item2)
            {
//.........这里部分代码省略.........
开发者ID:nick4eva,项目名称:PSScriptAnalyzer,代码行数:101,代码来源:VariableAnalysis.cs


注:本文中的Ast.Visit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。