Beispiel #1
0
        public IList <ControlFlowNode> BuildControlFlowGraph(Statement statement, CSharpAstResolver resolver, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }
            if (resolver == null)
            {
                throw new ArgumentNullException("resolver");
            }

            NodeCreationVisitor nodeCreationVisitor = new NodeCreationVisitor();

            nodeCreationVisitor.builder = this;
            try {
                this.nodes             = new List <ControlFlowNode>();
                this.labels            = new Dictionary <string, ControlFlowNode>();
                this.gotoStatements    = new List <ControlFlowNode>();
                this.rootStatement     = statement;
                this.resolver          = resolver;
                this.cancellationToken = cancellationToken;

                ControlFlowNode entryPoint = CreateStartNode(statement);
                statement.AcceptVisitor(nodeCreationVisitor, entryPoint);

                // Resolve goto statements:
                foreach (ControlFlowNode gotoStmt in gotoStatements)
                {
                    string          label = ((GotoStatement)gotoStmt.NextStatement).Label;
                    ControlFlowNode labelNode;
                    if (labels.TryGetValue(label, out labelNode))
                    {
                        nodeCreationVisitor.Connect(gotoStmt, labelNode, ControlFlowEdgeType.Jump);
                    }
                }

                AnnotateLeaveEdgesWithTryFinallyBlocks();

                return(nodes);
            } finally {
                this.nodes             = null;
                this.labels            = null;
                this.gotoStatements    = null;
                this.rootStatement     = null;
                this.resolver          = null;
                this.cancellationToken = CancellationToken.None;
            }
        }
Beispiel #2
0
        internal IList <ControlFlowNode> BuildControlFlowGraph(Statement statement, Func <AstNode, CancellationToken, ResolveResult> resolver, CSharpTypeResolveContext typeResolveContext, CancellationToken cancellationToken)
        {
            NodeCreationVisitor nodeCreationVisitor = new NodeCreationVisitor();

            nodeCreationVisitor.builder = this;
            try
            {
                this.nodes              = new List <ControlFlowNode>();
                this.labels             = new Dictionary <string, ControlFlowNode>();
                this.gotoStatements     = new List <ControlFlowNode>();
                this.rootStatement      = statement;
                this.resolver           = resolver;
                this.typeResolveContext = typeResolveContext;
                this.cancellationToken  = cancellationToken;

                ControlFlowNode entryPoint = CreateStartNode(statement);
                statement.AcceptVisitor(nodeCreationVisitor, entryPoint);

                // Resolve goto statements:
                foreach (ControlFlowNode gotoStmt in gotoStatements)
                {
                    string          label = ((GotoStatement)gotoStmt.NextStatement).Label;
                    ControlFlowNode labelNode;
                    if (labels.TryGetValue(label, out labelNode))
                    {
                        nodeCreationVisitor.Connect(gotoStmt, labelNode, ControlFlowEdgeType.Jump);
                    }
                }

                AnnotateLeaveEdgesWithTryFinallyBlocks();

                return(nodes);
            }
            finally
            {
                this.nodes              = null;
                this.labels             = null;
                this.gotoStatements     = null;
                this.rootStatement      = null;
                this.resolver           = null;
                this.typeResolveContext = null;
                this.cancellationToken  = CancellationToken.None;
            }
        }
Beispiel #3
0
        internal IList <ControlFlowNode> BuildControlFlowGraph(StatementSyntax statement, SemanticModel typeResolveContext, Func <SyntaxNode, CancellationToken, ISymbol> resolver, CancellationToken cancellationToken)
        {
            NodeCreationVisitor nodeCreationVisitor = new NodeCreationVisitor();

            nodeCreationVisitor.builder = this;
            try {
                this.nodes              = new List <ControlFlowNode>();
                this.labels             = new Dictionary <string, ControlFlowNode>();
                this.gotoStatements     = new List <GotoStatementSyntax>();
                this.rootStatement      = statement;
                this.resolver           = resolver;
                this.typeResolveContext = typeResolveContext;
                this.cancellationToken  = cancellationToken;
                // TODO:
                nodeCreationVisitor.curNode = CreateStartNode(statement);
                nodeCreationVisitor.Visit(statement);

                // Resolve goto statements:
                foreach (var gotoStmt in gotoStatements)
                {
                    string          label = ((GotoStatementSyntax)gotoStmt).Expression?.ToString();
                    ControlFlowNode labelNode;
                    if (labels.TryGetValue(label, out labelNode))
                    {
                        nodeCreationVisitor.Connect(nodeCreationVisitor.curNode, labelNode, ControlFlowEdgeType.Jump);
                    }
                }

                AnnotateLeaveEdgesWithTryFinallyBlocks();

                return(nodes);
            } finally {
                this.nodes              = null;
                this.labels             = null;
                this.gotoStatements     = null;
                this.rootStatement      = null;
                this.resolver           = null;
                this.typeResolveContext = null;
                this.cancellationToken  = CancellationToken.None;
            }
        }
        internal IList<ControlFlowNode> BuildControlFlowGraph(StatementSyntax statement, SemanticModel typeResolveContext, Func<SyntaxNode, CancellationToken, ISymbol> resolver, CancellationToken cancellationToken)
        {
            NodeCreationVisitor nodeCreationVisitor = new NodeCreationVisitor();
            nodeCreationVisitor.builder = this;
            try {
                this.nodes = new List<ControlFlowNode>();
                this.labels = new Dictionary<string, ControlFlowNode>();
                this.gotoStatements = new List<GotoStatementSyntax>();
                this.rootStatement = statement;
                this.resolver = resolver;
                this.typeResolveContext = typeResolveContext;
                this.cancellationToken = cancellationToken;
                // TODO:
                nodeCreationVisitor.curNode = CreateStartNode(statement);
                nodeCreationVisitor.Visit(statement);

                // Resolve goto statements:
                foreach (var gotoStmt in gotoStatements) {
                    string label = ((GotoStatementSyntax)gotoStmt).Expression?.ToString();
                    ControlFlowNode labelNode;
                    if (labels.TryGetValue(label, out labelNode))
                        nodeCreationVisitor.Connect(nodeCreationVisitor.curNode, labelNode, ControlFlowEdgeType.Jump);
                }

                AnnotateLeaveEdgesWithTryFinallyBlocks();

                return nodes;
            } finally {
                this.nodes = null;
                this.labels = null;
                this.gotoStatements = null;
                this.rootStatement = null;
                this.resolver = null;
                this.typeResolveContext = null;
                this.cancellationToken = CancellationToken.None;
            }
        }