Search in sources :

Example 26 with Node

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

the class SuccessorPredecessorAnalysis method getPredecessorsSkipInternal.

/**
 * see {@link N4JSFlowAnalyser#getPredecessorsSkipInternal(ControlFlowElement)}
 */
public Set<ControlFlowElement> getPredecessorsSkipInternal(ControlFlowElement cfe) {
    NextEdgesProvider nextEdgesProvider = new NextEdgesProvider.Backward();
    Node nextNode = getNextNode(cfe, true, nextEdgesProvider);
    Set<ControlFlowElement> predecessors = getNextCFEs(nextEdgesProvider, cfe, nextNode);
    return predecessors;
}
Also used : RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 27 with Node

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

the class GuardStructureFactory method getCondition.

/**
 * @return the top {@link Expression} of a {@link GuardStructure}, or null.
 */
private static Expression getCondition(ControlFlowEdge edge) {
    Expression condition = null;
    Node previousNode = edge.start;
    ControlFlowElement previousCFE = previousNode.getControlFlowElement();
    if (previousCFE instanceof ConditionalExpression) {
        ConditionalExpression ce = (ConditionalExpression) previousCFE;
        condition = ce.getExpression();
    } else if (previousCFE instanceof BinaryLogicalExpression) {
        BinaryLogicalExpression ble = (BinaryLogicalExpression) previousCFE;
        condition = ble.getLhs();
    } else if (previousCFE instanceof IfStatement) {
        IfStatement is = (IfStatement) previousCFE;
        condition = is.getExpression();
    } else if (previousCFE instanceof WhileStatement) {
        WhileStatement ws = (WhileStatement) previousCFE;
        condition = ws.getExpression();
    } else if (previousCFE instanceof DoStatement) {
        DoStatement ws = (DoStatement) previousCFE;
        condition = ws.getExpression();
    } else if (previousCFE instanceof ForStatement) {
        ForStatement ws = (ForStatement) previousCFE;
        condition = ws.getExpression();
    }
    return condition;
}
Also used : IfStatement(org.eclipse.n4js.n4JS.IfStatement) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) DoStatement(org.eclipse.n4js.n4JS.DoStatement) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) Node(org.eclipse.n4js.flowgraphs.model.Node) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) WhileStatement(org.eclipse.n4js.n4JS.WhileStatement) ForStatement(org.eclipse.n4js.n4JS.ForStatement) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 28 with Node

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

the class EdgeGuideWorklist method getAllVisitedNodes.

/**
 * @return a set of all visited nodes
 */
Set<Node> getAllVisitedNodes(ComplexNode cn, NextEdgesProvider edgeProvider) {
    Set<Node> allVisitedNodes = new HashSet<>();
    for (ControlFlowEdge edge : allVisitedEdges) {
        allVisitedNodes.add(edge.start);
        allVisitedNodes.add(edge.end);
    }
    allVisitedNodes.add(edgeProvider.getStartNode(cn));
    return allVisitedNodes;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) HashSet(java.util.HashSet)

Example 29 with Node

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

the class EdgeGuideQueue method isJoinGroup.

private boolean isJoinGroup(EdgeGuide eg1, EdgeGuide eg2) {
    Node nextN1 = eg1.getNextNode();
    Node nextN2 = eg2.getNextNode();
    boolean isJoinGroup = nextN1 == nextN2 && eg1.finallyContext.equals(eg2.finallyContext);
    return isJoinGroup;
}
Also used : Node(org.eclipse.n4js.flowgraphs.model.Node)

Example 30 with Node

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

the class EdgeGuideQueue method compareASTPosition.

private static int compareASTPosition(EdgeGuide eg1, EdgeGuide eg2) {
    Node nextNode1 = eg1.getNextNode();
    Node nextNode2 = eg2.getNextNode();
    int p2 = nextNode2.astPosition;
    int p1 = nextNode1.astPosition;
    boolean isForward = eg1.edgeProvider.isForward();
    int posDiff = (isForward) ? p1 - p2 : p2 - p1;
    return posDiff;
}
Also used : Node(org.eclipse.n4js.flowgraphs.model.Node)

Aggregations

Node (org.eclipse.n4js.flowgraphs.model.Node)41 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)34 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)17 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)17 LinkedList (java.util.LinkedList)16 CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)11 ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)8 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)8 LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)6 DelegatingNode (org.eclipse.n4js.flowgraphs.model.DelegatingNode)5 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)4 HashSet (java.util.HashSet)3 VariableDeclarationOrBinding (org.eclipse.n4js.n4JS.VariableDeclarationOrBinding)3 AbstractCaseClause (org.eclipse.n4js.n4JS.AbstractCaseClause)2 CaseClause (org.eclipse.n4js.n4JS.CaseClause)2 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)2 Statement (org.eclipse.n4js.n4JS.Statement)2 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 DummyBackwardVisitor (org.eclipse.n4js.flowgraphs.analysers.DummyBackwardVisitor)1