use of org.eclipse.n4js.flowgraphs.model.RepresentingNode in project n4js by eclipse.
the class JumpFactory method buildComplexNode.
static ComplexNode buildComplexNode(ReentrantASTIterator astpp, Statement stmt, Expression expr, JumpToken jumptoken) {
ComplexNode cNode = new ComplexNode(astpp.container(), stmt);
Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), stmt);
cNode.addNode(entryNode);
Node expression = null;
if (expr != null) {
expression = DelegatingNodeFactory.create(astpp, NodeNames.EXPRESSION, stmt, expr);
cNode.addNode(expression);
}
Node jumpNode = new RepresentingNode(NodeNames.JUMP, astpp.pos(), stmt);
cNode.addNode(jumpNode);
Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), stmt);
cNode.addNode(exitNode);
List<Node> cfs = new LinkedList<>();
cfs.add(entryNode);
cfs.add(expression);
cNode.connectInternalSucc(entryNode, expression);
Node beforeDeadNode = ListUtils.filterNulls(entryNode, expression).getLast();
cNode.connectInternalSucc(beforeDeadNode, jumpNode);
cNode.connectInternalSucc(ControlFlowType.DeadCode, jumpNode, exitNode);
jumpNode.addJumpToken(jumptoken);
cNode.setEntryNode(entryNode);
cNode.setExitNode(exitNode);
cNode.setJumpNode(jumpNode);
return cNode;
}
use of org.eclipse.n4js.flowgraphs.model.RepresentingNode in project n4js by eclipse.
the class VariableStatementFactory method buildComplexNode.
static ComplexNode buildComplexNode(ReentrantASTIterator astpp, VariableStatement varDeclStmt) {
ComplexNode cNode = new ComplexNode(astpp.container(), varDeclStmt);
Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), varDeclStmt);
List<Node> varDeclNodes = new LinkedList<>();
for (int n = 0; n < varDeclStmt.getVarDeclsOrBindings().size(); n++) {
VariableDeclarationOrBinding varDOB = varDeclStmt.getVarDeclsOrBindings().get(n);
Node varDeclNode = DelegatingNodeFactory.create(astpp, "declaration_" + n, varDeclStmt, varDOB);
varDeclNodes.add(varDeclNode);
}
Node exitNode = new RepresentingNode(NodeNames.EXIT, astpp.pos(), varDeclStmt);
cNode.addNode(entryNode);
for (Node varDeclNode : varDeclNodes) cNode.addNode(varDeclNode);
cNode.addNode(exitNode);
List<Node> nodes = new LinkedList<>();
nodes.add(entryNode);
nodes.addAll(varDeclNodes);
nodes.add(exitNode);
cNode.connectInternalSucc(nodes);
cNode.setEntryNode(entryNode);
cNode.setExitNode(exitNode);
return cNode;
}
use of org.eclipse.n4js.flowgraphs.model.RepresentingNode 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;
}
use of org.eclipse.n4js.flowgraphs.model.RepresentingNode in project n4js by eclipse.
the class GraphVisitor method visit.
@Override
protected final void visit(Node node) {
if (node instanceof RepresentingNode) {
ControlFlowElement cfe = node.getRepresentedControlFlowElement();
visit(cfe);
}
}
use of org.eclipse.n4js.flowgraphs.model.RepresentingNode 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();
}
}
}
Aggregations