use of org.eclipse.n4js.n4JS.UnaryExpression 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.UnaryExpression in project n4js by eclipse.
the class GuardFactory method createGuardForTypeof.
private static Guard createGuardForTypeof(EObject topContainer, UnaryExpression ue, boolean negateTree, boolean negateEqe, Expression rhs) {
if (rhs instanceof StringLiteral) {
StringLiteral rhsStringLit = (StringLiteral) rhs;
String lit = rhsStringLit.getValue();
if (!"undefined".equals(lit)) {
return null;
}
}
Expression typeofExpr = ue.getExpression();
if (SymbolFactory.canCreate(typeofExpr)) {
GuardAssertion asserts = FlowAssertionFactory.getGuard(topContainer, ue.eContainer(), negateTree, negateEqe);
Guard guard = createIsUndefinedGuard(ue, asserts, typeofExpr);
return guard;
}
return null;
}
Aggregations