use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class AssignmentRelationFactory method findInAllDestructNodes.
private void findInAllDestructNodes(Multimap<Symbol, Object> assgns, ControlFlowElement cfe) {
EObject top = DestructureUtils.getTop(cfe);
DestructNode dNode = DestructNode.unify(top);
if (dNode == null) {
return;
}
if (top instanceof ForStatement) {
ForStatement fs = (ForStatement) top;
Expression fsExpr = fs.getExpression();
if (fsExpr instanceof ArrayLiteral) {
ArrayLiteral al = (ArrayLiteral) fsExpr;
EObject rootOfDestrNode = DestructureUtils.getRoot(cfe);
for (ArrayElement arrElem : al.getElements()) {
dNode = DestructNode.unify(rootOfDestrNode, arrElem.getExpression());
findInDestructNodes(assgns, dNode);
}
}
} else {
findInDestructNodes(assgns, dNode);
}
}
use of org.eclipse.n4js.n4JS.Expression 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.Expression in project n4js by eclipse.
the class SymbolOfParameterizedPropertyAccessExpression method createSymbolKey.
@Override
protected Object createSymbolKey() {
List<Object> keyChain = new LinkedList<>();
keyChain.add(getDeclaration());
Expression lastContext = getContext();
Symbol tgtSymbol = getContextSymbol();
while (tgtSymbol != null) {
keyChain.add(tgtSymbol.getDeclaration());
lastContext = tgtSymbol.getContext();
tgtSymbol = tgtSymbol.getContextSymbol();
}
if (lastContext != null) {
keyChain.add(lastContext);
}
int hash = Objects.hash(keyChain.toArray(new Object[keyChain.size()]));
return hash;
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class GuardFactory method createGuardForEquality.
private static Guard createGuardForEquality(EObject topContainer, boolean negateTree, EqualityExpression eqe, boolean sameEqualNot) {
Expression lhs = eqe.getLhs();
Expression rhs = eqe.getRhs();
UnaryOperator luo = lhs instanceof UnaryExpression ? ((UnaryExpression) lhs).getOp() : null;
UnaryOperator ruo = rhs instanceof UnaryExpression ? ((UnaryExpression) rhs).getOp() : null;
// typeof foo != 'undefined'
if (luo == UnaryOperator.TYPEOF) {
return createGuardForTypeof(topContainer, (UnaryExpression) lhs, negateTree, sameEqualNot, rhs);
}
if (ruo == UnaryOperator.TYPEOF) {
return createGuardForTypeof(topContainer, (UnaryExpression) rhs, negateTree, sameEqualNot, lhs);
}
// name == void 0
if (luo == UnaryOperator.VOID && SymbolFactory.canCreate(rhs)) {
return createGuardForVoid(topContainer, (UnaryExpression) lhs, negateTree, sameEqualNot, rhs);
}
if (ruo == UnaryOperator.VOID && SymbolFactory.canCreate(lhs)) {
return createGuardForVoid(topContainer, (UnaryExpression) rhs, negateTree, sameEqualNot, lhs);
}
// v == null|undefined|0
if (SymbolFactory.canCreate(lhs) && SymbolFactory.canCreate(rhs)) {
GuardType guardType = getGuardType(lhs);
Expression symbolExpr = rhs;
if (guardType == null) {
guardType = getGuardType(rhs);
symbolExpr = lhs;
}
if (guardType != null) {
return createGuardForNUZ(topContainer, eqe, negateTree, sameEqualNot, guardType, symbolExpr);
}
}
return null;
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class GuardFactory method createGuardForInstanceof.
private static Guard createGuardForInstanceof(EObject topContainer, boolean negateTree, RelationalExpression re) {
Expression lhs = re.getLhs();
Expression rhs = re.getRhs();
if (SymbolFactory.canCreate(lhs)) {
GuardAssertion asserts = FlowAssertionFactory.getGuard(topContainer, re, negateTree, false);
Guard guard = createIsZeroGuard(re, asserts, lhs, rhs);
return guard;
}
return null;
}
Aggregations