use of org.eclipse.n4js.n4JS.ConditionalExpression in project n4js by eclipse.
the class Assumption method callHoldsOnDataflow.
/**
* Called from {@link DataFlowBranchWalker}.
* <p>
* Method transforms multiple right hand sides into separate calls to
* {@link #callHoldsOnDataflow(Symbol, Collection)}. Multiple right hand sides occur when either using
* {@link ConditionalExpression}s <br/>
* {@code let v = 1 ? null : undefined;} <br/>
* or when using nested {@link AssignmentExpression}s <br/>
* {@code let v = a = null;}.
*/
final void callHoldsOnDataflow(Symbol lhs, Collection<Object> rhss) {
checkState(isOpen());
Set<PartialResult.Type> resultSet = new HashSet<>();
for (Object rhs : rhss) {
Symbol rSymbol = null;
PartialResult result = null;
if (rhs instanceof Symbol) {
rSymbol = (Symbol) rhs;
result = holdsOnDataflow(lhs, rSymbol, null);
aliases.remove(lhs);
if (rSymbol.isVariableSymbol() && followAliases()) {
aliases.add(rSymbol);
}
} else if (rhs instanceof Expression) {
Expression rValue = (Expression) rhs;
result = holdsOnDataflow(lhs, null, rValue);
}
if (result != null) {
resultSet.add(result.type);
handleHoldResult(result, lhs);
}
}
if (resultSet.size() > 1 && resultSet.contains(PartialResult.Type.Unclear)) {
openBranch = true;
}
}
use of org.eclipse.n4js.n4JS.ConditionalExpression 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;
}
Aggregations