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


C# Ast.Accept方法代码示例

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


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

示例1: 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

示例2: IsAstSafe

 public static bool IsAstSafe(Ast ast, GetSafeValueVisitor.SafeValueContext safeValueContext)
 {
     IsSafeValueVisitor visitor = new IsSafeValueVisitor(safeValueContext);
     if ((bool)ast.Accept(visitor) && visitor._visitCount < MaxVisitCount)
     {
         return true;
     }
     return false;
 }
开发者ID:40a,项目名称:PowerShell,代码行数:9,代码来源:SafeValues.cs

示例3: IsConstant

 public static bool IsConstant(Ast ast, out object constantValue, bool forAttribute = false, bool forRequires = false)
 {
     try
     {
         IsConstantValueVisitor visitor2 = new IsConstantValueVisitor {
             CheckingAttributeArgument = forAttribute,
             CheckingRequiresArgument = forRequires
         };
         if ((bool) ast.Accept(visitor2))
         {
             Ast parent = ast.Parent;
             while (parent != null)
             {
                 if (parent is DataStatementAst)
                 {
                     break;
                 }
                 parent = parent.Parent;
             }
             if (parent == null)
             {
                 ConstantValueVisitor visitor = new ConstantValueVisitor {
                     AttributeArgument = forAttribute,
                     RequiresArgument = forRequires
                 };
                 constantValue = ast.Accept(visitor);
                 return true;
             }
         }
     }
     catch (Exception exception)
     {
         CommandProcessorBase.CheckForSevereException(exception);
     }
     constantValue = null;
     return false;
 }
开发者ID:nickchal,项目名称:pash,代码行数:37,代码来源:IsConstantValueVisitor.cs

示例4: CompileAndInvoke

 private static object CompileAndInvoke(Ast ast)
 {
     object obj2;
     try
     {
         Compiler visitor = new Compiler {
             CompilingConstantExpression = true
         };
         obj2 = Expression.Lambda((Expression) ast.Accept(visitor), new ParameterExpression[0]).Compile().DynamicInvoke(new object[0]);
     }
     catch (TargetInvocationException exception)
     {
         throw exception.InnerException;
     }
     return obj2;
 }
开发者ID:nickchal,项目名称:pash,代码行数:16,代码来源:ConstantValueVisitor.cs

示例5: PostVisit

 public void PostVisit(Ast ast)
 {
     ast.Accept(_symbolResolvePostActionVisitor);
 }
开发者ID:40a,项目名称:PowerShell,代码行数:4,代码来源:SymbolResolver.cs

示例6: GenerateWhileLoop

 private void GenerateWhileLoop(string loopLabel, Action generateCondition, Action generateLoopBody, Ast continueAction = null)
 {
     Block next = new Block();
     if (continueAction != null)
     {
         Block block2 = new Block();
         this._currentBlock.FlowsTo(block2);
         this._currentBlock = next;
         continueAction.Accept(this);
         this._currentBlock.FlowsTo(block2);
         this._currentBlock = block2;
     }
     else
     {
         this._currentBlock.FlowsTo(next);
         this._currentBlock = next;
     }
     Block block3 = new Block();
     Block block4 = new Block();
     if (generateCondition != null)
     {
         generateCondition();
         this._currentBlock.FlowsTo(block4);
     }
     this._loopTargets.Add(new LoopGotoTargets(loopLabel ?? "", block4, next));
     this._currentBlock.FlowsTo(block3);
     this._currentBlock = block3;
     generateLoopBody();
     this._currentBlock.FlowsTo(next);
     this._currentBlock = block4;
     this._loopTargets.RemoveAt(this._loopTargets.Count - 1);
 }
开发者ID:nickchal,项目名称:pash,代码行数:32,代码来源:VariableAnalysis.cs

示例7: GenerateWhileLoop

        private 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.Accept(this);

                _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:40a,项目名称:PowerShell,代码行数:60,代码来源:VariableAnalysis.cs

示例8: Compile

 internal Expression Compile(Ast ast)
 {
     return (Expression)ast.Accept(this);
 }
开发者ID:40a,项目名称:PowerShell,代码行数:4,代码来源:Compiler.cs

示例9: GetSafeValue

        public static object GetSafeValue(Ast ast, ExecutionContext context, SafeValueContext safeValueContext)
        {
            s_context = context;
            if (IsSafeValueVisitor.IsAstSafe(ast, safeValueContext))
            {
                return ast.Accept(new GetSafeValueVisitor());
            }

            if (safeValueContext == SafeValueContext.ModuleAnalysis)
            {
                return null;
            }
            throw PSTraceSource.NewArgumentException("ast");
        }
开发者ID:40a,项目名称:PowerShell,代码行数:14,代码来源:SafeValues.cs

示例10: CompileAndInvoke

 private static object CompileAndInvoke(Ast ast)
 {
     try
     {
         var compiler = new Compiler { CompilingConstantExpression = true };
         return Expression.Lambda((Expression)ast.Accept(compiler)).Compile().DynamicInvoke();
     }
     catch (TargetInvocationException tie)
     {
         throw tie.InnerException;
     }
 }
开发者ID:40a,项目名称:PowerShell,代码行数:12,代码来源:ConstantValues.cs

示例11: CheckIsConstant

 private void CheckIsConstant(Ast ast, string msg)
 {
     Diagnostics.Assert(
         (bool)ast.Accept(new IsConstantValueVisitor { CheckingAttributeArgument = this.AttributeArgument, CheckingRequiresArgument = RequiresArgument }), msg);
 }
开发者ID:40a,项目名称:PowerShell,代码行数:5,代码来源:ConstantValues.cs

示例12: IsValidAttributeArgument

 private bool IsValidAttributeArgument(Ast ast, IsConstantValueVisitor visitor)
 {
     return (bool)ast.Accept(visitor);
 }
开发者ID:dfinke,项目名称:powershell,代码行数:4,代码来源:SemanticChecks.cs

示例13: IsValidAttributeArgument

 private bool IsValidAttributeArgument(Ast ast)
 {
     var obj = ast.Accept(this._isConstantValueVisitor);
     if (obj is bool) return (bool)obj;
     return false;
 }
开发者ID:nickchal,项目名称:pash,代码行数:6,代码来源:SemanticChecks.cs


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