本文整理汇总了C#中Analyzer.BuildAst方法的典型用法代码示例。如果您正苦于以下问题:C# Analyzer.BuildAst方法的具体用法?C# Analyzer.BuildAst怎么用?C# Analyzer.BuildAst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Analyzer
的用法示例。
在下文中一共展示了Analyzer.BuildAst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Analyze
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Expression.Analyze"]/*'/>
internal override Evaluation Analyze(Analyzer/*!*/ analyzer, ExInfoFromParent info)
{
access = info.Access;
// assertion:
if (kind == EvalKinds.Assert)
{
if (analyzer.Context.Config.Compiler.Debug)
{
Evaluation code_evaluation = code.Analyze(analyzer, ExInfoFromParent.DefaultExInfo);
// string parameter is parsed and converted to an expression:
if (code_evaluation.HasValue)
{
inlinedCode = Convert.ObjectToString(code_evaluation.Value);
if (inlinedCode != "")
{
const string prefix = "return ";
// position setup:
Position pos = Position.Initial;
// the position of the last character before the parsed string:
pos.FirstLine = code.Position.FirstLine;
pos.FirstOffset = code.Position.FirstOffset - prefix.Length + 1;
pos.FirstColumn = code.Position.FirstColumn - prefix.Length + 1;
List<Statement> statements = analyzer.BuildAst(pos, String.Concat(prefix, inlinedCode, ";"));
// code is unevaluable:
if (statements == null)
return new Evaluation(this, true);
if (statements.Count > 1)
analyzer.ErrorSink.Add(Warnings.MultipleStatementsInAssertion, analyzer.SourceUnit, position);
Debug.Assert(statements.Count > 0 && statements[0] is JumpStmt);
this.code = ((JumpStmt)statements[0]).Expression;
}
else
{
// empty assertion:
return new Evaluation(this, true);
}
}
else
{
code = code_evaluation.Expression;
}
}
else
{
// replace with "true" value in release mode:
return new Evaluation(this, true);
}
}
// it is not necessary to analyze an argument nor set the declaring function's contains-eval property
// in the case of synthetic eval:
if (kind != EvalKinds.SyntheticEval)
{
code = code.Analyze(analyzer, ExInfoFromParent.DefaultExInfo).Literalize();
analyzer.AddCurrentRoutineProperty(RoutineProperties.ContainsEval);
}
return new Evaluation(this);
}