use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class AssignmentRelationFactory method findInDestructNodes.
private void findInDestructNodes(Multimap<Symbol, Object> assgns, DestructNode dNode) {
for (Iterator<DestructNode> dnIter = dNode.stream().iterator(); dnIter.hasNext(); ) {
DestructNode dnChild = dnIter.next();
ControlFlowElement lhs = dnChild.getVarRef() != null ? dnChild.getVarRef() : dnChild.getVarDecl();
EObject rhs = DestructureUtilsForSymbols.getValueFromDestructuring(symbolFactory, dnChild);
if (rhs == null) {
Symbol undefinedSymbol = symbolFactory.getUndefined();
createRelation(assgns, lhs, undefinedSymbol, null);
} else {
createRelation(assgns, lhs, (Expression) rhs);
}
}
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class GuardStructureFactory method getCondition.
/**
* @return the top {@link Expression} of a {@link GuardStructure}, or null.
*/
private static Expression getCondition(ControlFlowEdge edge) {
Expression condition = null;
Node previousNode = edge.start;
ControlFlowElement previousCFE = previousNode.getControlFlowElement();
if (previousCFE instanceof ConditionalExpression) {
ConditionalExpression ce = (ConditionalExpression) previousCFE;
condition = ce.getExpression();
} else if (previousCFE instanceof BinaryLogicalExpression) {
BinaryLogicalExpression ble = (BinaryLogicalExpression) previousCFE;
condition = ble.getLhs();
} else if (previousCFE instanceof IfStatement) {
IfStatement is = (IfStatement) previousCFE;
condition = is.getExpression();
} else if (previousCFE instanceof WhileStatement) {
WhileStatement ws = (WhileStatement) previousCFE;
condition = ws.getExpression();
} else if (previousCFE instanceof DoStatement) {
DoStatement ws = (DoStatement) previousCFE;
condition = ws.getExpression();
} else if (previousCFE instanceof ForStatement) {
ForStatement ws = (ForStatement) previousCFE;
condition = ws.getExpression();
}
return condition;
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class DirectPathAnalyses method getSomeCommonPredecessors.
private Set<ControlFlowElement> getSomeCommonPredecessors(ControlFlowElement cfeA, ControlFlowElement cfeB) {
LinkedHashSet<ControlFlowElement> commonPredSet = new LinkedHashSet<>();
// step 1: traverse all predecessors, beginning from cfeA: mark each
Set<ControlFlowElement> marked = new HashSet<>();
LinkedList<ControlFlowElement> curCFEs = new LinkedList<>();
// marked.add(cfeA);
curCFEs.add(cfeA);
while (!curCFEs.isEmpty()) {
ControlFlowElement cfe = curCFEs.removeFirst();
if (!marked.contains(cfe)) {
marked.add(cfe);
Set<ControlFlowElement> preds = spa.getPredecessors(cfe);
curCFEs.addAll(preds);
}
}
// step 2: traverse all predecessors, beginning from cfeB: find mark (this is a common pred.)
Set<ControlFlowElement> visited = new HashSet<>();
curCFEs.clear();
curCFEs.add(cfeB);
while (!curCFEs.isEmpty()) {
ControlFlowElement cfe = curCFEs.removeFirst();
if (marked.contains(cfe)) {
commonPredSet.add(cfe);
} else {
if (!visited.contains(cfe)) {
visited.add(cfe);
Set<ControlFlowElement> preds = spa.getPredecessors(cfe);
curCFEs.addAll(preds);
}
}
}
return commonPredSet;
}
use of org.eclipse.n4js.n4JS.ControlFlowElement 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.n4JS.ControlFlowElement in project n4js by eclipse.
the class UsedBeforeDeclaredAnalyserOnDataflow method getUsedButNotDeclaredIdentifierRefs.
/**
* @return all {@link IdentifierRef}s that are used before declared
*/
public List<ControlFlowElement> getUsedButNotDeclaredIdentifierRefs() {
List<ControlFlowElement> idRefs = new LinkedList<>();
for (Assumption ass : failedAssumptions.values()) {
for (PartialResult result : ass.failedBranches) {
UsedBeforeFailed ubf = (UsedBeforeFailed) result;
idRefs.add(ubf.useLocation);
}
}
return idRefs;
}
Aggregations