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;
}
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;
}
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++;
}
}
}
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;
}
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;
}
Aggregations