Search in sources :

Example 1 with ComplexNode

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

the class GraphVisitorAnalysis method backwardAnalysis.

/**
 * see {@link N4JSFlowAnalyser#accept(GraphVisitor...)}
 */
public void backwardAnalysis(FlowAnalyser[] flowAnalysers) {
    if (!forwardAnalysisDone) {
        throw new IllegalStateException("Forward analysis must be performed first.");
    }
    List<GraphVisitorInternal> graphVisitors = getGraphVisitors(flowAnalysers, TraverseDirection.Backward);
    GraphVisitorGuideInternal guide = new GraphVisitorGuideInternal(flowAnalyzer, graphVisitors);
    guide.init();
    for (ControlFlowElement container : cfg.getAllContainers()) {
        ComplexNode cnContainer = cfg.getComplexNode(container);
        guide.walkthroughBackward(cnContainer);
    }
    guide.terminate();
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 2 with ComplexNode

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

the class DirectPathAnalyses method getPath.

/**
 * @return a path from cfeFrom to cfeTo that does not include over cfeNotVia
 */
public Path getPath(ControlFlowElement cfeFrom, ControlFlowElement cfeTo, ControlFlowElement cfeNotVia) {
    ComplexNode cnStart = cfg.getComplexNode(cfeFrom);
    ComplexNode cnEnd = cfg.getComplexNode(cfeTo);
    Node nStart = cnStart.getRepresent();
    Node nEnd = cnEnd.getRepresent();
    Node nNotVia = null;
    if (cfeNotVia != null) {
        ComplexNode cnNotVia = cfg.getComplexNode(cfeNotVia);
        nNotVia = cnNotVia.getRepresent();
    }
    Path path = buildPath(nStart, nEnd, nNotVia);
    return path;
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node)

Example 3 with ComplexNode

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

the class EdgeGuide method getFirstEdgeGuides.

static List<EdgeGuide> getFirstEdgeGuides(ComplexNode cn, NextEdgesProvider edgeProvider, Collection<BranchWalkerInternal> activatedPaths) {
    List<EdgeGuide> nextEGs = new LinkedList<>();
    Node node = edgeProvider.getStartNode(cn);
    List<ControlFlowEdge> nextEdges = edgeProvider.getNextEdges(node);
    Iterator<ControlFlowEdge> nextEdgeIt = nextEdges.iterator();
    if (nextEdges.size() == 1) {
        ControlFlowEdge nextEdge = nextEdgeIt.next();
        EdgeGuide eg = new EdgeGuide(edgeProvider.copy(), nextEdge, activatedPaths);
        eg.deadContext.update(eg.getPrevNode());
        nextEGs.add(eg);
    }
    if (nextEdges.size() > 1) {
        while (nextEdgeIt.hasNext()) {
            ControlFlowEdge nextEdge = nextEdgeIt.next();
            Collection<BranchWalkerInternal> forkedPaths = new HashSet<>();
            for (BranchWalkerInternal aPath : activatedPaths) {
                BranchWalkerInternal forkedPath = aPath.callFork();
                forkedPaths.add(forkedPath);
            }
            EdgeGuide eg = new EdgeGuide(edgeProvider.copy(), nextEdge, forkedPaths);
            eg.deadContext.update(eg.getPrevNode());
            nextEGs.add(eg);
        }
    }
    return nextEGs;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 4 with ComplexNode

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

the class ConditionalExpressionFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, ConditionalExpression condExpr) {
    ComplexNode cNode = new ComplexNode(astpp.container(), condExpr);
    HelperNode entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), condExpr);
    Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, condExpr, condExpr.getExpression());
    HelperNode conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), condExpr);
    Node thenNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.THEN, condExpr, condExpr.getTrueExpression());
    Node elseNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.ELSE, condExpr, condExpr.getFalseExpression());
    Node exitNode = new RepresentingNode(NodeNames.EXIT, astpp.pos(), condExpr);
    cNode.addNode(entryNode);
    cNode.addNode(conditionNode);
    cNode.addNode(conditionForkNode);
    cNode.addNode(thenNode);
    cNode.addNode(elseNode);
    cNode.addNode(exitNode);
    cNode.connectInternalSucc(entryNode, conditionNode, conditionForkNode);
    cNode.connectInternalSucc(ControlFlowType.IfTrue, conditionForkNode, thenNode);
    cNode.connectInternalSucc(thenNode, exitNode);
    cNode.connectInternalSucc(ControlFlowType.IfFalse, conditionForkNode, elseNode);
    cNode.connectInternalSucc(elseNode, exitNode);
    // catch for short-circuits
    thenNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
    // catch for short-circuits
    elseNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse));
    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) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Example 5 with ComplexNode

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

the class DebuggerStatementFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, DebuggerStatement empty) {
    ComplexNode cNode = new ComplexNode(astpp.container(), empty);
    Node entryAndExitNode = new RepresentingNode(NodeNames.ENTRY_EXIT, astpp.pos(), empty);
    cNode.addNode(entryAndExitNode);
    cNode.setEntryNode(entryAndExitNode);
    cNode.setExitNode(entryAndExitNode);
    return cNode;
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) Node(org.eclipse.n4js.flowgraphs.model.Node) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode)

Aggregations

ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)33 Node (org.eclipse.n4js.flowgraphs.model.Node)27 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)17 LinkedList (java.util.LinkedList)13 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)12 CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)11 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)7 LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)6 DelegatingNode (org.eclipse.n4js.flowgraphs.model.DelegatingNode)5 ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)4 HashSet (java.util.HashSet)3 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)3 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)3 VariableDeclarationOrBinding (org.eclipse.n4js.n4JS.VariableDeclarationOrBinding)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 AbstractCaseClause (org.eclipse.n4js.n4JS.AbstractCaseClause)2 Block (org.eclipse.n4js.n4JS.Block)2 CaseClause (org.eclipse.n4js.n4JS.CaseClause)2 Statement (org.eclipse.n4js.n4JS.Statement)2