use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class DataFlowBranchWalker method visit.
@Override
protected void visit(Node node) {
if (node.effectInfos.isEmpty()) {
return;
}
ControlFlowElement cfe = node.getControlFlowElement();
Multimap<Symbol, Object> assgns = getDataFlowVisitorHost().getAssignmentRelationFactory().findAssignments(cfe);
Set<Symbol> handledDataFlowSymbols = new HashSet<>();
for (Symbol lhs : assgns.keySet()) {
Collection<Object> rhss = assgns.get(lhs);
boolean handledDataFlow = handleDataflow(lhs, rhss);
if (handledDataFlow) {
handledDataFlowSymbols.add(lhs);
}
}
for (EffectInfo effect : node.effectInfos) {
handleVisitEffect(cfe, effect, handledDataFlowSymbols);
}
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class GraphVisitorAnalysis method backwardAnalysis.
/**
* see {@link N4JSFlowAnalyser#accept(GraphVisitor...)}
*/
public void backwardAnalysis(FlowAnalyser[] flowAnalysers) {
if (!forwardAnalysisDone) {
throw new IllegalStateException("Forward analysis must be performed first.");
}
List<GraphVisitorInternal> graphVisitors = getGraphVisitors(flowAnalysers, TraverseDirection.Backward);
GraphVisitorGuideInternal guide = new GraphVisitorGuideInternal(flowAnalyzer, graphVisitors);
guide.init();
for (ControlFlowElement container : cfg.getAllContainers()) {
ComplexNode cnContainer = cfg.getComplexNode(container);
guide.walkthroughBackward(cnContainer);
}
guide.terminate();
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class PathWalkerGuide method visitNode.
@Override
public void visitNode(Node node) {
if (node instanceof RepresentingNode) {
ControlFlowElement cfeEnd = node.getRepresentedControlFlowElement();
if (lastVisitedNode != null) {
ControlFlowElement cfeStart = lastVisitedNode.getRepresentedControlFlowElement();
FlowEdge edge = new FlowEdge(cfeStart, cfeEnd, cfTypes);
walker.visit(edge);
}
cfTypes.clear();
walker.visit(cfeEnd);
lastVisitedNode = node;
}
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class DeadCodeAnalyser method isDeadCode.
/**
* This method deals with the fact that {@link Statement}s are not represented in the control flow graph.
*
* @return true iff the given {@link ControlFlowElement} is dead code.
*/
public boolean isDeadCode(ControlFlowElement cfe) {
cfe = CFEMapper.map(cfe);
if (FGUtils.isControlStatement(cfe)) {
Set<ControlFlowElement> succs = flowAnalyzer.getSuccessors(cfe);
for (ControlFlowElement succ : succs) {
if (!isDeadCode(succ)) {
return false;
}
}
return true;
}
if (allLiveNodes.contains(cfe)) {
return false;
}
Set<ControlFlowElement> preds = flowAnalyzer.getPredecessorsSkipInternal(cfe);
if (preds.isEmpty()) {
return true;
}
Set<ControlFlowElement> visited = new HashSet<>();
while (!preds.isEmpty()) {
ControlFlowElement pred = preds.iterator().next();
preds.remove(pred);
if (visited.contains(pred))
continue;
if (allLiveNodes.contains(pred)) {
return false;
}
preds.addAll(flowAnalyzer.getPredecessorsSkipInternal(pred));
visited.add(pred);
}
return true;
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class DeadCodeAnalyser method separateOnTheirBlocks.
/**
* Separates the given set into sets where all {@link ControlFlowElement}s of each set have the same containing
* {@link Block}.
* <p>
* Note that the assumption is:<br/>
* <i>No block can contain more than one single dead code region.</i>
*/
private Collection<Set<ControlFlowElement>> separateOnTheirBlocks(Set<ControlFlowElement> unreachableElems) {
Map<EObject, Set<ControlFlowElement>> unreachablesMap = new HashMap<>();
for (ControlFlowElement unreachableElem : unreachableElems) {
HashSet<ControlFlowElement> moreUnreachableElems = new HashSet<>();
EObject cfeBlock = getReachableContainer(unreachableElems, unreachableElem, moreUnreachableElems);
if (cfeBlock == null)
continue;
if (!unreachablesMap.containsKey(cfeBlock)) {
unreachablesMap.put(cfeBlock, new HashSet<>());
}
Set<ControlFlowElement> unreachableInBlock = unreachablesMap.get(cfeBlock);
unreachableInBlock.add(unreachableElem);
unreachableInBlock.addAll(moreUnreachableElems);
}
return unreachablesMap.values();
}
Aggregations