Search in sources :

Example 41 with ControlFlowElement

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

the class BranchWalker method visit.

@Override
protected final void visit(Node start, Node end, ControlFlowEdge edge) {
    pEdgeTypes.add(edge.cfType);
    if (end instanceof RepresentingNode || this.getContainer() == end.getControlFlowElement()) {
        ControlFlowElement endCFE = end.getRepresentedControlFlowElement();
        endCFE = endCFE == null ? end.getControlFlowElement() : endCFE;
        if (lastRN != null) {
            ControlFlowElement startCFE = lastRN.getRepresentedControlFlowElement();
            startCFE = startCFE == null ? lastRN.getControlFlowElement() : startCFE;
            FlowEdge flowEdge = new FlowEdge(startCFE, endCFE, pEdgeTypes);
            visit(flowEdge);
            pEdgeTypes.clear();
        } else {
            HashSet<EdgeInfo> edgeInfos = new HashSet<>();
            addPredecedingRepNodes(this, edgeInfos, new EdgeInfo(this));
            for (EdgeInfo edgeInfo : edgeInfos) {
                ControlFlowElement startCFE = edgeInfo.startNode.getRepresentedControlFlowElement();
                startCFE = startCFE == null ? edgeInfo.startNode.getControlFlowElement() : startCFE;
                FlowEdge flowEdge = new FlowEdge(startCFE, endCFE, edgeInfo.pEdgeTypes);
                edgeInfo.edgeOwner.visit(flowEdge);
            }
            pEdgeTypes.clear();
        }
    }
}
Also used : FlowEdge(org.eclipse.n4js.flowgraphs.FlowEdge) ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) HashSet(java.util.HashSet)

Example 42 with ControlFlowElement

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

the class CFEMapper method map.

/**
 * Maps the given {@link EObject} to another {@link EObject} which will be used in the control flow graph. This
 * method invokes the internal mapping methods repeatedly until a fixpoint is reached.
 */
public static ControlFlowElement map(ControlFlowElement eObj) {
    ControlFlowElement eObjTmp = eObj;
    ControlFlowElement lastEObj = null;
    while (eObjTmp != null) {
        lastEObj = eObjTmp;
        eObjTmp = mapInternal(eObjTmp);
    }
    return lastEObj;
}
Also used : ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 43 with ControlFlowElement

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

the class CatchNodeFinder method find.

/**
 * @return the node to which the given {@code jumpNode} jumps via the given {@link JumpToken}. Can return null.
 */
static Pair<Node, ControlFlowType> find(JumpToken jumpToken, Node jumpNode, ComplexNodeMapper cnMapper) {
    CatchEvaluator catchEvaluator = getCatchEvaluator(jumpToken);
    ControlFlowElement cfe = jumpNode.getControlFlowElement();
    cfe = skipContainers(cfe);
    ControlFlowElement lastCFE = null;
    while (cfe != null) {
        Pair<Node, ControlFlowType> catcher = findCatchNode(jumpToken, cfe, lastCFE, catchEvaluator, cnMapper);
        if (catcher != null)
            return catcher;
        lastCFE = cfe;
        cfe = getContainer(cfe);
    }
    return null;
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 44 with ControlFlowElement

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

the class ControlFlowGraphFactory method connectNode.

/**
 * Connects all nodes based on
 * <ul>
 * <li/>the delegating nodes, and
 * <li/>the internal successor information of each node.
 * </ul>
 */
private static void connectNode(ComplexNodeMapper cnMapper, Node mNode) {
    Node internalStartNode = mNode;
    ControlFlowElement subASTElem = mNode.getDelegatedControlFlowElement();
    if (subASTElem != null) {
        ComplexNode subCN = cnMapper.get(subASTElem);
        if (subCN != null) {
            // can be null in case of malformed AST
            EdgeUtils.connectCF(mNode, subCN.getEntry());
            internalStartNode = subCN.getExit();
        }
    }
    Set<Node> internalSuccs = mNode.getInternalSuccessors();
    for (Node internalSucc : internalSuccs) {
        ControlFlowType cfType = mNode.getInternalSuccessorControlFlowType(internalSucc);
        EdgeUtils.connectCF(internalStartNode, internalSucc, cfType);
    }
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) DelegatingNode(org.eclipse.n4js.flowgraphs.model.DelegatingNode) Node(org.eclipse.n4js.flowgraphs.model.Node) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 45 with ControlFlowElement

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

the class ControlFlowGraphFactory method getEnteringFinallyBlock.

private static FinallyBlock getEnteringFinallyBlock(Node catchNode) {
    if (catchNode.name.equals(NodeNames.FINALLY)) {
        ControlFlowElement cfe = catchNode.getDelegatedControlFlowElement();
        EObject cfeContainer = cfe.eContainer();
        return (FinallyBlock) cfeContainer;
    }
    return null;
}
Also used : FinallyBlock(org.eclipse.n4js.n4JS.FinallyBlock) EObject(org.eclipse.emf.ecore.EObject) 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