本文整理汇总了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);
}
}
}
示例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);
}
示例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);
}
}
}
示例4: VisitBlockExpression
public virtual Ast.Expression VisitBlockExpression(Ast.BlockExpression blockExpression)
{
foreach (var expression in blockExpression.Expressions)
this.Visit(expression);
return blockExpression;
}
示例5: VisitBinaryExpression
public virtual Ast.Expression VisitBinaryExpression(Ast.BinaryExpression expression)
{
this.Visit(expression.Left);
this.Visit(expression.Right);
return expression;
}
示例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;
}
}
}
}
示例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));
}
示例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));
}
}
}
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例15: CompletionAnalysis
internal CompletionAnalysis(Ast ast, Token[] tokens, IScriptPosition cursorPosition, Hashtable options)
{
_ast = ast;
_tokens = tokens;
_cursorPosition = cursorPosition;
_options = options;
}