Search in sources :

Example 46 with ControlFlowElement

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

the class GraphVisitorAnalysis method forwardAnalysis.

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

Example 47 with ControlFlowElement

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

the class ASTIterator method pop.

private ControlFlowElement pop() {
    searchNextCFE();
    ControlFlowElement firstElem = (ControlFlowElement) nextElems.remove(0);
    if (!containerStack.isEmpty() && firstElem == containerStack.get(containerStack.size() - 1)) {
        containerStack.remove(containerStack.size() - 1);
        return pop();
    }
    List<EObject> children = OrderedEContentProvider.eContents(firstElem);
    boolean isContainer = FGUtils.isCFContainer(firstElem);
    if (isContainer) {
        containerStack.add(firstElem);
        nextElems.add(0, firstElem);
    }
    nextElems.addAll(0, children);
    return firstElem;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 48 with ControlFlowElement

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

the class ASTIterator method searchNextCFE.

private void searchNextCFE() {
    int idx = 0;
    while (isClosingContainer(idx)) {
        idx++;
    }
    while (nextElems.size() > idx && !(nextElems.get(idx) instanceof ControlFlowElement)) {
        EObject firstElem = nextElems.remove(idx);
        List<EObject> children = OrderedEContentProvider.eContents(firstElem);
        nextElems.addAll(idx, children);
        while (isClosingContainer(idx)) {
            idx++;
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 49 with ControlFlowElement

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

the class FGUtils method getContainer.

/**
 * @return the container of the given {@link ControlFlowElement}. Omits AST elements that are not part of the CFG.
 */
private static ControlFlowElement getContainer(ControlFlowElement curCFE) {
    EObject eObj = curCFE;
    do {
        eObj = eObj.eContainer();
    } while (eObj != null && !(eObj instanceof ControlFlowElement));
    curCFE = (ControlFlowElement) eObj;
    return curCFE;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 50 with ControlFlowElement

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

the class DeadCodeAnalyser method findPrecedingStatement.

private ControlFlowElement findPrecedingStatement(ControlFlowElement cfe) {
    ControlFlowElement precedingStatement = null;
    Statement stmt = EcoreUtil2.getContainerOfType(cfe, Statement.class);
    if (stmt != null) {
        EObject stmtContainer = stmt.eContainer();
        if (stmtContainer != null && stmtContainer instanceof Block) {
            Block block = (Block) stmtContainer;
            EList<Statement> stmts = block.getStatements();
            int index = stmts.indexOf(stmt);
            if (index > 0) {
                precedingStatement = stmts.get(index - 1);
            }
        }
    }
    return precedingStatement;
}
Also used : ExpressionStatement(org.eclipse.n4js.n4JS.ExpressionStatement) Statement(org.eclipse.n4js.n4JS.Statement) ReturnStatement(org.eclipse.n4js.n4JS.ReturnStatement) EObject(org.eclipse.emf.ecore.EObject) Block(org.eclipse.n4js.n4JS.Block) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Aggregations

ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)52 EObject (org.eclipse.emf.ecore.EObject)12 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)12 LinkedList (java.util.LinkedList)10 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)10 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)9 Xpect (org.eclipse.xpect.runner.Xpect)9 Node (org.eclipse.n4js.flowgraphs.model.Node)8 HashSet (java.util.HashSet)7 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)5 ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)4 HashMap (java.util.HashMap)3 FlowEdge (org.eclipse.n4js.flowgraphs.FlowEdge)3 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)3 LinkedHashSet (java.util.LinkedHashSet)2 N4JSFlowAnalyser (org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser)2 Assumption (org.eclipse.n4js.flowgraphs.dataflow.Assumption)2 Symbol (org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol)2 Block (org.eclipse.n4js.n4JS.Block)2 ExpressionStatement (org.eclipse.n4js.n4JS.ExpressionStatement)2