Search in sources :

Example 6 with ControlFlowElement

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

the class FlowgraphsXpectMethod method preds.

/**
 * This xpect method can evaluate the direct predecessors of a code element. The predecessors can be limited when
 * specifying the edge type.
 * <p>
 * <b>Attention:</b> The type parameter <i>does not</i> work on self loops!
 */
@ParameterParser(syntax = "('type' arg1=STRING)? ('at' arg2=OFFSET)?")
@Xpect
public void preds(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, String type, IEObjectCoveringRegion offset) {
    ControlFlowType cfType = getControlFlowType(type);
    ControlFlowElement cfe = getCFE(offset);
    Set<ControlFlowElement> preds = getFlowAnalyzer(cfe).getPredecessorsSkipInternal(cfe);
    filterByControlFlowType(cfe, preds, cfType);
    List<String> predTexts = new LinkedList<>();
    for (ControlFlowElement succ : preds) {
        String predText = FGUtils.getSourceText(succ);
        predTexts.add(predText);
    }
    expectation.assertEquals(predTexts);
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 7 with ControlFlowElement

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

the class FlowgraphsXpectMethod method performBranchAnalysis.

private AllBranchPrintVisitor performBranchAnalysis(IEObjectCoveringRegion offset, String directionName, IEObjectCoveringRegion referenceOffset) {
    EObjectCoveringRegion offsetImpl = (EObjectCoveringRegion) offset;
    EObjectCoveringRegion referenceOffsetImpl = (EObjectCoveringRegion) referenceOffset;
    ControlFlowElement startCFE = getCFEWithReference(offsetImpl, referenceOffsetImpl);
    ControlFlowElement referenceCFE = getCFE(referenceOffset);
    TraverseDirection direction = getDirection(directionName);
    ControlFlowElement container = FGUtils.getCFContainer(referenceCFE);
    AllBranchPrintVisitor appw = new AllBranchPrintVisitor(container, startCFE, direction);
    getFlowAnalyzer(referenceCFE).accept(appw);
    return appw;
}
Also used : AllBranchPrintVisitor(org.eclipse.n4js.flowgraphs.analysers.AllBranchPrintVisitor) IEObjectCoveringRegion(org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.IEObjectCoveringRegion) EObjectCoveringRegion(org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.EObjectCoveringRegion) TraverseDirection(org.eclipse.n4js.flowgraphs.analysis.TraverseDirection) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 8 with ControlFlowElement

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

the class FlowgraphsXpectMethod method commonPreds.

/**
 * This xpect method can evaluate all common predecessors of two {@link ControlFlowElement}s.
 */
@ParameterParser(syntax = "'of' arg1=OFFSET 'and' arg2=OFFSET")
@Xpect
public void commonPreds(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion a, IEObjectCoveringRegion b) {
    ControlFlowElement aCFE = getCFE(a);
    ControlFlowElement bCFE = getCFE(b);
    Set<ControlFlowElement> commonPreds = getFlowAnalyzer(aCFE).getCommonPredecessors(aCFE, bCFE);
    List<String> commonPredStrs = new LinkedList<>();
    for (ControlFlowElement commonPred : commonPreds) {
        String commonPredStr = FGUtils.getSourceText(commonPred);
        commonPredStrs.add(commonPredStr);
    }
    expectation.assertEquals(commonPredStrs);
}
Also used : ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 9 with ControlFlowElement

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

the class FGUtils method getAllContainersOfTypeUptoCFContainer.

/**
 * Returns all containers of the given {@link ControlFlowElement} that are assignable from the given class. The
 * results are all in the same container like the given cfe is.
 */
@SuppressWarnings("unchecked")
public static <T> LinkedList<T> getAllContainersOfTypeUptoCFContainer(ControlFlowElement cfe, Class<T> clazz) {
    LinkedList<T> results = new LinkedList<>();
    ControlFlowElement curCFE = cfe;
    while (curCFE != null && !isCFContainer(curCFE)) {
        if (clazz.isAssignableFrom(curCFE.getClass())) {
            results.add((T) curCFE);
        }
        curCFE = getContainer(curCFE);
    }
    return results;
}
Also used : ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList)

Example 10 with ControlFlowElement

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

the class SuccessorPredecessorAnalysis method getPredecessors.

/**
 * see {@link N4JSFlowAnalyser#getPredecessors(ControlFlowElement)}
 */
public Set<ControlFlowElement> getPredecessors(ControlFlowElement cfe) {
    NextEdgesProvider nextEdgesProvider = new NextEdgesProvider.Backward();
    Node nextNode = getNextNode(cfe, false, 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