Search in sources :

Example 11 with RepresentingNode

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

the class BinaryLogicalExpressionFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, BinaryLogicalExpression lbExpr) {
    ComplexNode cNode = new ComplexNode(astpp.container(), lbExpr);
    HelperNode entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), lbExpr);
    Node lhsNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.LHS, lbExpr, lbExpr.getLhs());
    Node scJumpNode = new HelperNode(NodeNames.SHORT_CIRCUIT_JUMP, astpp.pos(), lbExpr);
    Node rhsNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.RHS, lbExpr, lbExpr.getRhs());
    Node exitNode = new RepresentingNode(NodeNames.EXIT, astpp.pos(), lbExpr);
    cNode.addNode(entryNode);
    cNode.addNode(lhsNode);
    cNode.addNode(scJumpNode);
    cNode.addNode(rhsNode);
    cNode.addNode(exitNode);
    ControlFlowType thenCFT = null;
    ControlFlowType elseCFT = null;
    switch(lbExpr.getOp()) {
        case OR:
            thenCFT = ControlFlowType.IfFalse;
            elseCFT = ControlFlowType.IfTrue;
            break;
        case AND:
            thenCFT = ControlFlowType.IfTrue;
            elseCFT = ControlFlowType.IfFalse;
            break;
    }
    cNode.connectInternalSucc(entryNode, lhsNode, scJumpNode);
    cNode.connectInternalSucc(thenCFT, scJumpNode, rhsNode);
    cNode.connectInternalSucc(rhsNode, exitNode);
    // short-circuit evaluation
    scJumpNode.addJumpToken(new JumpToken(elseCFT));
    cNode.setJumpNode(scJumpNode);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    rhsNode.addCatchToken(new CatchToken(thenCFT));
    boolean isCatchingLhs = isTopJumpCatcher(lbExpr);
    if (isCatchingLhs) {
        exitNode.addCatchToken(new CatchToken(elseCFT));
        exitNode.addCatchToken(new CatchToken(thenCFT));
    } else {
    // TODO: minor improvement: add the following jump node
    // exitNode.addJumpToken(new JumpToken(thenCFT)); // short-circuit evaluation
    // cNode.setJumpNode(scJumpNode);
    }
    return cNode;
}
Also used : JumpToken(org.eclipse.n4js.flowgraphs.model.JumpToken) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) 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) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Example 12 with RepresentingNode

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

the class StandardCFEFactory method buildComplexNode.

private static ComplexNode buildComplexNode(ReentrantASTIterator astpp, ControlFlowElement cfe, boolean isRepresenting) {
    ComplexNode cNode = new ComplexNode(astpp.container(), cfe);
    HelperNode entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), cfe);
    List<Node> argumentNodes = CFEChildren.get(astpp, cfe);
    Node exitNode;
    String extName;
    if (argumentNodes.isEmpty()) {
        entryNode = null;
        extName = NodeNames.ENTRY_EXIT;
    } else {
        extName = NodeNames.EXIT;
    }
    if (isRepresenting) {
        exitNode = new RepresentingNode(extName, astpp.pos(), cfe);
    } else {
        exitNode = new HelperNode(extName, astpp.pos(), cfe);
    }
    cNode.addNode(entryNode);
    for (Node arg : argumentNodes) cNode.addNode(arg);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.addAll(argumentNodes);
    nodes.add(exitNode);
    cNode.connectInternalSucc(nodes);
    if (argumentNodes.isEmpty()) {
        cNode.setEntryNode(exitNode);
    } else {
        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) LinkedList(java.util.LinkedList)

Example 13 with RepresentingNode

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

the class VariableDeclarationFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, VariableDeclaration vd) {
    ComplexNode cNode = new ComplexNode(astpp.container(), vd);
    HelperNode entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), vd);
    Node expressionNode = null;
    if (vd.getExpression() != null) {
        expressionNode = DelegatingNodeFactory.create(astpp, NodeNames.EXPRESSION, vd, vd.getExpression());
    }
    Node exitNode = new RepresentingNode(NodeNames.EXIT, astpp.pos(), vd);
    cNode.addNode(entryNode);
    cNode.addNode(expressionNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.add(expressionNode);
    nodes.add(exitNode);
    cNode.connectInternalSucc(nodes);
    if (vd.eContainer() instanceof BindingElement) {
        // In this case, the expression is the default value
        // TODO: improve this: find out if this is true or false
        cNode.connectInternalSucc(entryNode, exitNode);
    }
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) BindingElement(org.eclipse.n4js.n4JS.BindingElement) 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) LinkedList(java.util.LinkedList)

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