本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例5: PostVisit
public void PostVisit(Ast ast)
{
ast.Accept(_symbolResolvePostActionVisitor);
}
示例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);
}
示例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);
}
示例8: Compile
internal Expression Compile(Ast ast)
{
return (Expression)ast.Accept(this);
}
示例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");
}
示例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;
}
}
示例11: CheckIsConstant
private void CheckIsConstant(Ast ast, string msg)
{
Diagnostics.Assert(
(bool)ast.Accept(new IsConstantValueVisitor { CheckingAttributeArgument = this.AttributeArgument, CheckingRequiresArgument = RequiresArgument }), msg);
}
示例12: IsValidAttributeArgument
private bool IsValidAttributeArgument(Ast ast, IsConstantValueVisitor visitor)
{
return (bool)ast.Accept(visitor);
}
示例13: IsValidAttributeArgument
private bool IsValidAttributeArgument(Ast ast)
{
var obj = ast.Accept(this._isConstantValueVisitor);
if (obj is bool) return (bool)obj;
return false;
}