Search in sources :

Example 31 with ControlFlowElement

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

the class FlowgraphsXpectMethod method cfContainer.

/**
 * This xpect method can evaluate the control flow container of a given {@link ControlFlowElement}.
 */
@ParameterParser(syntax = "('of' arg1=OFFSET)?")
@Xpect
public void cfContainer(@StringExpectation IStringExpectation expectation, IEObjectCoveringRegion offset) {
    ControlFlowElement cfe = getCFE(offset);
    ControlFlowElement container = getFlowAnalyzer(cfe).getContainer(cfe);
    EObject containerContainer = container.eContainer();
    String ccString = (containerContainer != null) ? FGUtils.getClassName(containerContainer) + "::" : "";
    String containerStr = ccString + FGUtils.getClassName(container);
    expectation.assertEquals(containerStr);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 32 with ControlFlowElement

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

the class SuccessorPredecessorAnalysis method getSuccessorsSkipInternal.

/**
 * see {@link N4JSFlowAnalyser#getSuccessorsSkipInternal(ControlFlowElement)}
 */
public Set<ControlFlowElement> getSuccessorsSkipInternal(ControlFlowElement cfe) {
    NextEdgesProvider nextEdgesProvider = new NextEdgesProvider.Forward();
    Node nextNode = getNextNode(cfe, true, nextEdgesProvider);
    Set<ControlFlowElement> successors = getNextCFEs(nextEdgesProvider, cfe, nextNode);
    return successors;
}
Also used : RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 33 with ControlFlowElement

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

the class SuccessorPredecessorAnalysis method getSuccessors.

/**
 * see {@link N4JSFlowAnalyser#getSuccessors(ControlFlowElement)}
 */
public Set<ControlFlowElement> getSuccessors(ControlFlowElement cfe) {
    NextEdgesProvider nextEdgesProvider = new NextEdgesProvider.Forward();
    Node nextNode = getNextNode(cfe, false, nextEdgesProvider);
    Set<ControlFlowElement> successors = getNextCFEs(nextEdgesProvider, cfe, nextNode);
    return successors;
}
Also used : RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 34 with ControlFlowElement

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

the class SuccessorPredecessorAnalysis method getNextCFEs.

/**
 * @return the set of all next {@link ControlFlowElement}
 */
private Set<ControlFlowElement> getNextCFEs(NextEdgesProvider nextEdgesProvider, ControlFlowElement cfe, Node nextNode) {
    Objects.requireNonNull(cfe);
    Set<ControlFlowElement> nexts = new HashSet<>();
    LinkedList<ControlFlowEdge> allEdges = new LinkedList<>();
    List<ControlFlowEdge> nextEdges = nextEdgesProvider.getNextEdges(nextNode, ControlFlowType.NonDeadTypes);
    allEdges.addAll(nextEdges);
    while (!allEdges.isEmpty()) {
        ControlFlowEdge nextEdge = allEdges.removeFirst();
        nextNode = nextEdgesProvider.getNextNode(nextEdge);
        if (nextNode instanceof RepresentingNode) {
            ControlFlowElement succ = nextNode.getRepresentedControlFlowElement();
            nexts.add(succ);
        } else {
            nextEdges = nextEdgesProvider.getNextEdges(nextNode, ControlFlowType.NonDeadTypes);
            allEdges.addAll(nextEdges);
        }
    }
    return nexts;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 35 with ControlFlowElement

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

the class SuccessorPredecessorAnalysis method getPredecessorsSkipInternal.

/**
 * see {@link N4JSFlowAnalyser#getPredecessorsSkipInternal(ControlFlowElement)}
 */
public Set<ControlFlowElement> getPredecessorsSkipInternal(ControlFlowElement cfe) {
    NextEdgesProvider nextEdgesProvider = new NextEdgesProvider.Backward();
    Node nextNode = getNextNode(cfe, true, nextEdgesProvider);
    Set<ControlFlowElement> predecessors = getNextCFEs(nextEdgesProvider, cfe, nextNode);
    return predecessors;
}
Also used : RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) 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