internal static ReachabilityAnalysis Create(Statement statement, Func <AstNode, CancellationToken, ResolveResult> resolver, CSharpTypeResolveContext typeResolveContext, CancellationToken cancellationToken) { var cfgBuilder = new ControlFlowGraphBuilder(); var cfg = cfgBuilder.BuildControlFlowGraph(statement, resolver, typeResolveContext, cancellationToken); return(Create(cfg, cancellationToken)); }
void InsertAnonymousMethods(int insertPos, AstNode node, ControlFlowGraphBuilder cfgBuilder, CancellationToken cancellationToken) { // Ignore any statements, as those have their own ControlFlowNode and get handled separately if (node is Statement) { return; } AnonymousMethodExpression ame = node as AnonymousMethodExpression; if (ame != null) { allNodes.InsertRange(insertPos, cfgBuilder.BuildControlFlowGraph(ame.Body, resolver, cancellationToken).Cast <DefiniteAssignmentNode>()); return; } LambdaExpression lambda = node as LambdaExpression; if (lambda != null && lambda.Body is Statement) { allNodes.InsertRange(insertPos, cfgBuilder.BuildControlFlowGraph((Statement)lambda.Body, resolver, cancellationToken).Cast <DefiniteAssignmentNode>()); return; } // Descend into child expressions // Iterate backwards so that anonymous methods are inserted in the correct order for (AstNode child = node.LastChild; child != null; child = child.PrevSibling) { InsertAnonymousMethods(insertPos, child, cfgBuilder, cancellationToken); } }
public static ReachabilityAnalysis Create(Statement statement, CSharpAstResolver resolver = null, CancellationToken cancellationToken = default(CancellationToken)) { var cfgBuilder = new ControlFlowGraphBuilder(); var cfg = cfgBuilder.BuildControlFlowGraph(statement, resolver, cancellationToken); return(Create(cfg, cancellationToken)); }