Search in sources :

Example 6 with RepresentingNode

use of org.eclipse.n4js.flowgraphs.model.RepresentingNode in project n4js by eclipse.

the class JumpFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, Statement stmt, Expression expr, JumpToken jumptoken) {
    ComplexNode cNode = new ComplexNode(astpp.container(), stmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), stmt);
    cNode.addNode(entryNode);
    Node expression = null;
    if (expr != null) {
        expression = DelegatingNodeFactory.create(astpp, NodeNames.EXPRESSION, stmt, expr);
        cNode.addNode(expression);
    }
    Node jumpNode = new RepresentingNode(NodeNames.JUMP, astpp.pos(), stmt);
    cNode.addNode(jumpNode);
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), stmt);
    cNode.addNode(exitNode);
    List<Node> cfs = new LinkedList<>();
    cfs.add(entryNode);
    cfs.add(expression);
    cNode.connectInternalSucc(entryNode, expression);
    Node beforeDeadNode = ListUtils.filterNulls(entryNode, expression).getLast();
    cNode.connectInternalSucc(beforeDeadNode, jumpNode);
    cNode.connectInternalSucc(ControlFlowType.DeadCode, jumpNode, exitNode);
    jumpNode.addJumpToken(jumptoken);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    cNode.setJumpNode(jumpNode);
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) LinkedList(java.util.LinkedList)

Example 7 with RepresentingNode

use of org.eclipse.n4js.flowgraphs.model.RepresentingNode in project n4js by eclipse.

the class VariableStatementFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, VariableStatement varDeclStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), varDeclStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), varDeclStmt);
    List<Node> varDeclNodes = new LinkedList<>();
    for (int n = 0; n < varDeclStmt.getVarDeclsOrBindings().size(); n++) {
        VariableDeclarationOrBinding varDOB = varDeclStmt.getVarDeclsOrBindings().get(n);
        Node varDeclNode = DelegatingNodeFactory.create(astpp, "declaration_" + n, varDeclStmt, varDOB);
        varDeclNodes.add(varDeclNode);
    }
    Node exitNode = new RepresentingNode(NodeNames.EXIT, astpp.pos(), varDeclStmt);
    cNode.addNode(entryNode);
    for (Node varDeclNode : varDeclNodes) cNode.addNode(varDeclNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.addAll(varDeclNodes);
    nodes.add(exitNode);
    cNode.connectInternalSucc(nodes);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) Node(org.eclipse.n4js.flowgraphs.model.Node) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) VariableDeclarationOrBinding(org.eclipse.n4js.n4JS.VariableDeclarationOrBinding) LinkedList(java.util.LinkedList)

Example 8 with RepresentingNode

use of org.eclipse.n4js.flowgraphs.model.RepresentingNode in project n4js by eclipse.

the class SuccessorPredecessorAnalysis method getNextCFEs.

/**
 * @return the set of all next {@link ControlFlowElement}
 */
private Set<ControlFlowElement> getNextCFEs(NextEdgesProvider nextEdgesProvider, ControlFlowElement cfe, Node nextNode) {
    Objects.requireNonNull(cfe);
    Set<ControlFlowElement> nexts = new HashSet<>();
    LinkedList<ControlFlowEdge> allEdges = new LinkedList<>();
    List<ControlFlowEdge> nextEdges = nextEdgesProvider.getNextEdges(nextNode, ControlFlowType.NonDeadTypes);
    allEdges.addAll(nextEdges);
    while (!allEdges.isEmpty()) {
        ControlFlowEdge nextEdge = allEdges.removeFirst();
        nextNode = nextEdgesProvider.getNextNode(nextEdge);
        if (nextNode instanceof RepresentingNode) {
            ControlFlowElement succ = nextNode.getRepresentedControlFlowElement();
            nexts.add(succ);
        } else {
            nextEdges = nextEdgesProvider.getNextEdges(nextNode, ControlFlowType.NonDeadTypes);
            allEdges.addAll(nextEdges);
        }
    }
    return nexts;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 9 with RepresentingNode

use of org.eclipse.n4js.flowgraphs.model.RepresentingNode in project n4js by eclipse.

the class GraphVisitor method visit.

@Override
protected final void visit(Node node) {
    if (node instanceof RepresentingNode) {
        ControlFlowElement cfe = node.getRepresentedControlFlowElement();
        visit(cfe);
    }
}
Also used : RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 10 with RepresentingNode

use of org.eclipse.n4js.flowgraphs.model.RepresentingNode in project n4js by eclipse.

the class BranchWalker method visit.

@Override
protected final void visit(Node start, Node end, ControlFlowEdge edge) {
    pEdgeTypes.add(edge.cfType);
    if (end instanceof RepresentingNode || this.getContainer() == end.getControlFlowElement()) {
        ControlFlowElement endCFE = end.getRepresentedControlFlowElement();
        endCFE = endCFE == null ? end.getControlFlowElement() : endCFE;
        if (lastRN != null) {
            ControlFlowElement startCFE = lastRN.getRepresentedControlFlowElement();
            startCFE = startCFE == null ? lastRN.getControlFlowElement() : startCFE;
            FlowEdge flowEdge = new FlowEdge(startCFE, endCFE, pEdgeTypes);
            visit(flowEdge);
            pEdgeTypes.clear();
        } else {
            HashSet<EdgeInfo> edgeInfos = new HashSet<>();
            addPredecedingRepNodes(this, edgeInfos, new EdgeInfo(this));
            for (EdgeInfo edgeInfo : edgeInfos) {
                ControlFlowElement startCFE = edgeInfo.startNode.getRepresentedControlFlowElement();
                startCFE = startCFE == null ? edgeInfo.startNode.getControlFlowElement() : startCFE;
                FlowEdge flowEdge = new FlowEdge(startCFE, endCFE, edgeInfo.pEdgeTypes);
                edgeInfo.edgeOwner.visit(flowEdge);
            }
            pEdgeTypes.clear();
        }
    }
}
Also used : FlowEdge(org.eclipse.n4js.flowgraphs.FlowEdge) ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) HashSet(java.util.HashSet)

Aggregations

RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)13 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)8 Node (org.eclipse.n4js.flowgraphs.model.Node)8 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)6 LinkedList (java.util.LinkedList)5 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)5 ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)3 HashSet (java.util.HashSet)2 FlowEdge (org.eclipse.n4js.flowgraphs.FlowEdge)2 CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)2 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)1 JumpToken (org.eclipse.n4js.flowgraphs.model.JumpToken)1 BindingElement (org.eclipse.n4js.n4JS.BindingElement)1 VariableDeclarationOrBinding (org.eclipse.n4js.n4JS.VariableDeclarationOrBinding)1