Search in sources :

Example 1 with LabelledStatement

use of org.eclipse.n4js.n4JS.LabelledStatement in project n4js by eclipse.

the class BreakStatementImpl method setLabel.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setLabel(LabelledStatement newLabel) {
    LabelledStatement oldLabel = label;
    label = newLabel;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.BREAK_STATEMENT__LABEL, oldLabel, label));
}
Also used : LabelledStatement(org.eclipse.n4js.n4JS.LabelledStatement) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 2 with LabelledStatement

use of org.eclipse.n4js.n4JS.LabelledStatement in project n4js by eclipse.

the class DoWhileFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, DoStatement doStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), doStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), doStmt);
    Node bodyNode = DelegatingNodeFactory.create(astpp, NodeNames.BODY, doStmt, doStmt.getStatement());
    Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, doStmt, doStmt.getExpression());
    Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), doStmt);
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), doStmt);
    cNode.addNode(entryNode);
    cNode.addNode(bodyNode);
    cNode.addNode(conditionNode);
    cNode.addNode(conditionForkNode);
    cNode.addNode(exitNode);
    cNode.connectInternalSucc(entryNode, bodyNode, conditionNode, conditionForkNode);
    cNode.connectInternalSucc(ControlFlowType.LoopReenter, conditionForkNode, bodyNode);
    cNode.connectInternalSucc(ControlFlowType.LoopExit, conditionForkNode, exitNode);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    // catch for short-circuits
    conditionForkNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
    exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse, ControlFlowType.LoopExit));
    LabelledStatement lblStmt = ASTUtils.getLabelledStatement(doStmt);
    exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
    conditionNode.addCatchToken(new CatchToken(ControlFlowType.Continue, lblStmt));
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) LabelledStatement(org.eclipse.n4js.n4JS.LabelledStatement) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) Node(org.eclipse.n4js.flowgraphs.model.Node) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Example 3 with LabelledStatement

use of org.eclipse.n4js.n4JS.LabelledStatement in project n4js by eclipse.

the class ForFactory method buildForPlain.

private static ComplexNode buildForPlain(ReentrantASTIterator astpp, ForStatement forStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), forStmt);
    List<Node> initNodes = new LinkedList<>();
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), forStmt);
    Node conditionNode = null;
    Node bodyNode = null;
    Node updatesNode = null;
    if (forStmt.getVarDeclsOrBindings() != null) {
        int i = 0;
        for (VariableDeclarationOrBinding vdob : forStmt.getVarDeclsOrBindings()) {
            Node initNode = DelegatingNodeFactory.create(astpp, "init_" + i, forStmt, vdob);
            initNodes.add(initNode);
            i++;
        }
    }
    if (forStmt.getInitExpr() != null) {
        Node initNode = DelegatingNodeFactory.create(astpp, NodeNames.INITS, forStmt, forStmt.getInitExpr());
        initNodes.add(initNode);
    }
    if (forStmt.getExpression() != null) {
        conditionNode = DelegatingNodeFactory.create(astpp, NodeNames.CONDITION, forStmt, forStmt.getExpression());
    }
    Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), forStmt);
    bodyNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.BODY, forStmt, forStmt.getStatement());
    Node continueCatchNode = new HelperNode(NodeNames.CONTINUE_CATCH, astpp.pos(), forStmt);
    if (forStmt.getUpdateExpr() != null) {
        updatesNode = DelegatingNodeFactory.create(astpp, NodeNames.UPDATES, forStmt, forStmt.getUpdateExpr());
    }
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), forStmt);
    cNode.addNode(entryNode);
    cNode.addNode(exitNode);
    for (Node initNode : initNodes) cNode.addNode(initNode);
    cNode.addNode(conditionNode);
    cNode.addNode(conditionForkNode);
    cNode.addNode(bodyNode);
    cNode.addNode(continueCatchNode);
    cNode.addNode(updatesNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.addAll(initNodes);
    nodes.add(conditionNode);
    nodes.add(conditionForkNode);
    cNode.connectInternalSucc(nodes);
    cNode.connectInternalSucc(ControlFlowType.LoopEnter, conditionForkNode, bodyNode);
    if (conditionNode != null) {
        cNode.connectInternalSucc(ControlFlowType.LoopExit, conditionForkNode, exitNode);
        cNode.connectInternalSucc(bodyNode, continueCatchNode, updatesNode);
        Node beforeConditionNode = ListUtils.filterNulls(bodyNode, continueCatchNode, updatesNode).getLast();
        cNode.connectInternalSucc(ControlFlowType.LoopRepeat, beforeConditionNode, conditionNode);
    } else {
        cNode.connectInternalSucc(bodyNode, continueCatchNode, updatesNode);
        LinkedList<Node> loopCycle = ListUtils.filterNulls(continueCatchNode, updatesNode);
        Node loopSrc = loopCycle.getLast();
        cNode.connectInternalSucc(ControlFlowType.LoopInfinite, loopSrc, conditionForkNode);
        cNode.connectInternalSucc(ControlFlowType.DeadCode, loopSrc, exitNode);
    }
    // catch for short-circuits
    conditionForkNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
    exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse, ControlFlowType.LoopExit));
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    LabelledStatement lblStmt = ASTUtils.getLabelledStatement(forStmt);
    exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
    continueCatchNode.addCatchToken(new CatchToken(ControlFlowType.Continue, lblStmt));
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) LabelledStatement(org.eclipse.n4js.n4JS.LabelledStatement) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) Node(org.eclipse.n4js.flowgraphs.model.Node) VariableDeclarationOrBinding(org.eclipse.n4js.n4JS.VariableDeclarationOrBinding) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken) LinkedList(java.util.LinkedList)

Example 4 with LabelledStatement

use of org.eclipse.n4js.n4JS.LabelledStatement in project n4js by eclipse.

the class SwitchFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, SwitchStatement switchStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), switchStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), switchStmt);
    Node pivotNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.PIVOT, switchStmt, switchStmt.getExpression());
    cNode.addNode(entryNode);
    cNode.addNode(pivotNode);
    List<Node> caseNodes = new LinkedList<>();
    // Assumption: clauses are ordered analog to the source code
    List<AbstractCaseClause> caseClauses = switchStmt.getCases();
    for (int n = 0; n < caseClauses.size(); n++) {
        AbstractCaseClause cc = caseClauses.get(n);
        Node caseNode = null;
        if (cc instanceof CaseClause) {
            caseNode = DelegatingNodeFactory.create(astpp, "case_" + n, switchStmt, cc);
        }
        if (cc instanceof DefaultClause) {
            caseNode = DelegatingNodeFactory.create(astpp, NodeNames.DEFAULT, switchStmt, cc);
        }
        caseNodes.add(caseNode);
        cNode.addNode(caseNode);
    }
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), switchStmt);
    cNode.addNode(exitNode);
    List<Node> cfs = new LinkedList<>();
    cfs.add(entryNode);
    cfs.add(pivotNode);
    cNode.connectInternalSucc(cfs);
    for (Node cnf : caseNodes) {
        cNode.connectInternalSucc(pivotNode, cnf);
    }
    cfs.clear();
    cfs.addAll(caseNodes);
    cfs.add(exitNode);
    // See {@link JumpFactory} how {@link BreakStatements} modify the control flow
    cNode.connectInternalSucc(cfs);
    if (switchStmt.getDefaultClause() == null)
        cNode.connectInternalSucc(pivotNode, exitNode);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    LabelledStatement lblStmt = ASTUtils.getLabelledStatement(switchStmt);
    exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
    return cNode;
}
Also used : DefaultClause(org.eclipse.n4js.n4JS.DefaultClause) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) LabelledStatement(org.eclipse.n4js.n4JS.LabelledStatement) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) Node(org.eclipse.n4js.flowgraphs.model.Node) AbstractCaseClause(org.eclipse.n4js.n4JS.AbstractCaseClause) CaseClause(org.eclipse.n4js.n4JS.CaseClause) AbstractCaseClause(org.eclipse.n4js.n4JS.AbstractCaseClause) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken) LinkedList(java.util.LinkedList)

Example 5 with LabelledStatement

use of org.eclipse.n4js.n4JS.LabelledStatement in project n4js by eclipse.

the class WhileFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, WhileStatement whileStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), whileStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), whileStmt);
    Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, whileStmt, whileStmt.getExpression());
    Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), whileStmt);
    Node bodyNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.BODY, whileStmt, whileStmt.getStatement());
    Node continueCatchNode = new HelperNode(NodeNames.CONTINUE_CATCH, astpp.pos(), whileStmt);
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), whileStmt);
    cNode.addNode(entryNode);
    cNode.addNode(conditionNode);
    cNode.addNode(conditionForkNode);
    cNode.addNode(bodyNode);
    cNode.addNode(continueCatchNode);
    cNode.addNode(exitNode);
    cNode.connectInternalSucc(entryNode, conditionNode, conditionForkNode);
    cNode.connectInternalSucc(ControlFlowType.LoopEnter, conditionForkNode, bodyNode);
    cNode.connectInternalSucc(ControlFlowType.LoopExit, conditionForkNode, exitNode);
    cNode.connectInternalSucc(bodyNode, continueCatchNode);
    cNode.connectInternalSucc(ControlFlowType.LoopRepeat, continueCatchNode, conditionNode);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    // catch for short-circuits
    conditionForkNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
    exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse, ControlFlowType.LoopExit));
    LabelledStatement lblStmt = ASTUtils.getLabelledStatement(whileStmt);
    exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
    continueCatchNode.addCatchToken(new CatchToken(ControlFlowType.Continue, lblStmt));
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) LabelledStatement(org.eclipse.n4js.n4JS.LabelledStatement) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) Node(org.eclipse.n4js.flowgraphs.model.Node) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Aggregations

LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)10 CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)6 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)6 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)6 Node (org.eclipse.n4js.flowgraphs.model.Node)6 LinkedList (java.util.LinkedList)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 CaseClause (org.eclipse.n4js.n4JS.CaseClause)2 DefaultClause (org.eclipse.n4js.n4JS.DefaultClause)2 EPackage (org.eclipse.emf.ecore.EPackage)1 AbstractCaseClause (org.eclipse.n4js.n4JS.AbstractCaseClause)1 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)1 Annotation (org.eclipse.n4js.n4JS.Annotation)1 AnnotationList (org.eclipse.n4js.n4JS.AnnotationList)1 Argument (org.eclipse.n4js.n4JS.Argument)1 ArrayBindingPattern (org.eclipse.n4js.n4JS.ArrayBindingPattern)1 ArrayElement (org.eclipse.n4js.n4JS.ArrayElement)1 ArrayLiteral (org.eclipse.n4js.n4JS.ArrayLiteral)1 ArrayPadding (org.eclipse.n4js.n4JS.ArrayPadding)1 ArrowFunction (org.eclipse.n4js.n4JS.ArrowFunction)1