Search in sources :

Example 36 with ControlFlowElement

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

the class AssignmentRelationFactory method findInDestructNodes.

private void findInDestructNodes(Multimap<Symbol, Object> assgns, DestructNode dNode) {
    for (Iterator<DestructNode> dnIter = dNode.stream().iterator(); dnIter.hasNext(); ) {
        DestructNode dnChild = dnIter.next();
        ControlFlowElement lhs = dnChild.getVarRef() != null ? dnChild.getVarRef() : dnChild.getVarDecl();
        EObject rhs = DestructureUtilsForSymbols.getValueFromDestructuring(symbolFactory, dnChild);
        if (rhs == null) {
            Symbol undefinedSymbol = symbolFactory.getUndefined();
            createRelation(assgns, lhs, undefinedSymbol, null);
        } else {
            createRelation(assgns, lhs, (Expression) rhs);
        }
    }
}
Also used : Symbol(org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol) EObject(org.eclipse.emf.ecore.EObject) DestructNode(org.eclipse.n4js.n4JS.DestructNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 37 with ControlFlowElement

use of org.eclipse.n4js.n4JS.ControlFlowElement 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 38 with ControlFlowElement

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

the class DirectPathAnalyses method getSomeCommonPredecessors.

private Set<ControlFlowElement> getSomeCommonPredecessors(ControlFlowElement cfeA, ControlFlowElement cfeB) {
    LinkedHashSet<ControlFlowElement> commonPredSet = new LinkedHashSet<>();
    // step 1: traverse all predecessors, beginning from cfeA: mark each
    Set<ControlFlowElement> marked = new HashSet<>();
    LinkedList<ControlFlowElement> curCFEs = new LinkedList<>();
    // marked.add(cfeA);
    curCFEs.add(cfeA);
    while (!curCFEs.isEmpty()) {
        ControlFlowElement cfe = curCFEs.removeFirst();
        if (!marked.contains(cfe)) {
            marked.add(cfe);
            Set<ControlFlowElement> preds = spa.getPredecessors(cfe);
            curCFEs.addAll(preds);
        }
    }
    // step 2: traverse all predecessors, beginning from cfeB: find mark (this is a common pred.)
    Set<ControlFlowElement> visited = new HashSet<>();
    curCFEs.clear();
    curCFEs.add(cfeB);
    while (!curCFEs.isEmpty()) {
        ControlFlowElement cfe = curCFEs.removeFirst();
        if (marked.contains(cfe)) {
            commonPredSet.add(cfe);
        } else {
            if (!visited.contains(cfe)) {
                visited.add(cfe);
                Set<ControlFlowElement> preds = spa.getPredecessors(cfe);
                curCFEs.addAll(preds);
            }
        }
    }
    return commonPredSet;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 39 with ControlFlowElement

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

the class GraphVisitor method visit.

@Override
protected final void visit(Node node) {
    if (node instanceof RepresentingNode) {
        ControlFlowElement cfe = node.getRepresentedControlFlowElement();
        visit(cfe);
    }
}
Also used : RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 40 with ControlFlowElement

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

the class UsedBeforeDeclaredAnalyserOnDataflow method getUsedButNotDeclaredIdentifierRefs.

/**
 * @return all {@link IdentifierRef}s that are used before declared
 */
public List<ControlFlowElement> getUsedButNotDeclaredIdentifierRefs() {
    List<ControlFlowElement> idRefs = new LinkedList<>();
    for (Assumption ass : failedAssumptions.values()) {
        for (PartialResult result : ass.failedBranches) {
            UsedBeforeFailed ubf = (UsedBeforeFailed) result;
            idRefs.add(ubf.useLocation);
        }
    }
    return idRefs;
}
Also used : PartialResult(org.eclipse.n4js.flowgraphs.dataflow.PartialResult) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Assumption(org.eclipse.n4js.flowgraphs.dataflow.Assumption)

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