use of org.eclipse.n4js.n4JS.BinaryLogicalExpression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeBinaryLogicalExpression.
protected Result<TypeRef> applyRuleTypeBinaryLogicalExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BinaryLogicalExpression e) throws RuleFailedException {
// output parameter
TypeRef T = null;
final Expression lhs = e.getLhs();
final Expression rhs = e.getRhs();
boolean _xifexpression = false;
if ((lhs instanceof ArrayLiteral)) {
_xifexpression = ((ArrayLiteral) lhs).getElements().isEmpty();
}
final boolean lhsIsEmptyArrayLiteral = _xifexpression;
boolean _xifexpression_1 = false;
if ((rhs instanceof ArrayLiteral)) {
_xifexpression_1 = ((ArrayLiteral) rhs).getElements().isEmpty();
}
final boolean rhsIsEmptyArrayLiteral = _xifexpression_1;
/* G |- e.lhs : var TypeRef L */
Expression _lhs = e.getLhs();
TypeRef L = null;
Result<TypeRef> result = typeInternal(G, _trace_, _lhs);
checkAssignableTo(result.getFirst(), TypeRef.class);
L = (TypeRef) result.getFirst();
/* G |- e.rhs : var TypeRef R */
Expression _rhs = e.getRhs();
TypeRef R = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _rhs);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
R = (TypeRef) result_1.getFirst();
boolean _and = false;
boolean _lhsIsEmptyArrayLiteral = lhsIsEmptyArrayLiteral;
if (!_lhsIsEmptyArrayLiteral) {
_and = false;
} else {
Type _declaredType = null;
if (R != null) {
_declaredType = R.getDeclaredType();
}
TObjectPrototype _arrayType = RuleEnvironmentExtensions.arrayType(G);
boolean _tripleEquals = (_declaredType == _arrayType);
_and = _tripleEquals;
}
if (_and) {
T = R;
} else {
boolean _and_1 = false;
boolean _rhsIsEmptyArrayLiteral = rhsIsEmptyArrayLiteral;
if (!_rhsIsEmptyArrayLiteral) {
_and_1 = false;
} else {
Type _declaredType_1 = null;
if (L != null) {
_declaredType_1 = L.getDeclaredType();
}
TObjectPrototype _arrayType_1 = RuleEnvironmentExtensions.arrayType(G);
boolean _tripleEquals_1 = (_declaredType_1 == _arrayType_1);
_and_1 = _tripleEquals_1;
}
if (_and_1) {
T = L;
} else {
T = this.typeSystemHelper.createUnionType(G, L, R);
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.BinaryLogicalExpression in project n4js by eclipse.
the class AssignmentRelationFactory method handleSubexpressions.
private void handleSubexpressions(Multimap<Symbol, Object> assgns, ControlFlowElement lhs, Expression rhs) {
rhs = ASTUtils.unwrapParentheses(rhs);
if (rhs instanceof AssignmentExpression) {
AssignmentExpression ae = (AssignmentExpression) rhs;
Expression innerRhs = ae.getRhs();
// The inner assignment is handled already.
handleSubexpressions(assgns, lhs, innerRhs);
} else if (rhs instanceof ConditionalExpression) {
ConditionalExpression ce = (ConditionalExpression) rhs;
Expression trueExpr = ce.getTrueExpression();
Expression falseExpr = ce.getFalseExpression();
handleSubexpressions(assgns, lhs, trueExpr);
handleSubexpressions(assgns, lhs, falseExpr);
} else if (rhs instanceof BinaryLogicalExpression) {
BinaryLogicalExpression ble = (BinaryLogicalExpression) rhs;
if (ble.getOp() == BinaryLogicalOperator.OR) {
handleSubexpressions(assgns, lhs, ble.getLhs());
}
handleSubexpressions(assgns, lhs, ble.getRhs());
} else {
createRelation(assgns, lhs, rhs);
}
}
use of org.eclipse.n4js.n4JS.BinaryLogicalExpression in project n4js by eclipse.
the class FlowAssertionFactory method addBooleanExpressions.
private static void addBooleanExpressions(EObject topContainer, ArrayList<BooleanExpression> bExprs, EObject condition) {
if (topContainer == condition) {
return;
}
BooleanExpression nextValue = null;
if (condition instanceof UnaryExpression) {
UnaryExpression ue = (UnaryExpression) condition;
if (ue.getOp() == UnaryOperator.NOT) {
nextValue = BooleanExpression.not;
}
} else if (condition instanceof BinaryLogicalExpression) {
BinaryLogicalExpression ble = (BinaryLogicalExpression) condition;
switch(ble.getOp()) {
case AND:
nextValue = BooleanExpression.and;
break;
case OR:
nextValue = BooleanExpression.or;
break;
}
} else if (condition instanceof EqualityExpression) {
EqualityExpression ee = (EqualityExpression) condition;
switch(ee.getOp()) {
case EQ:
case SAME:
nextValue = BooleanExpression.eq;
break;
case NEQ:
case NSAME:
nextValue = BooleanExpression.neq;
break;
}
}
if (nextValue != null) {
bExprs.add(nextValue);
}
EObject parent = condition.eContainer();
// tail recursion
addBooleanExpressions(topContainer, bExprs, parent);
}
use of org.eclipse.n4js.n4JS.BinaryLogicalExpression in project n4js by eclipse.
the class GuardFactory method createGuardForTruthy.
private static Guard createGuardForTruthy(EObject topContainer, Expression expr, boolean negateTree) {
if (SymbolFactory.canCreate(expr)) {
EObject parent = expr.eContainer();
boolean isTruthy = false;
isTruthy |= parent instanceof Statement;
isTruthy |= parent instanceof ParenExpression;
isTruthy |= parent instanceof ConditionalExpression;
isTruthy |= parent instanceof BinaryLogicalExpression;
isTruthy |= parent instanceof UnaryExpression && ((UnaryExpression) parent).getOp() == UnaryOperator.NOT;
if (isTruthy) {
GuardAssertion asserts = FlowAssertionFactory.getGuard(topContainer, expr, negateTree, false);
Guard guard = createIsTruthyGuard(expr, asserts);
return guard;
}
}
return null;
}
use of org.eclipse.n4js.n4JS.BinaryLogicalExpression in project n4js by eclipse.
the class BinaryLogicalExpressionFactory method isTopJumpCatcher.
/**
* Short circuit evaluation of a {@link BinaryLogicalExpression} <i>ble</i> causes jumps that start at a lhs
* condition and jump e.g. directly into the then or else block. However, sometimes this jump does not target such a
* then or else block, for instance when <i>ble</i> is not used as a condition. In this case, the <i>ble</i> itself
* or one of its parents will catch the short circuit jump.
* <p>
* This method returns true if the given {@link BinaryLogicalExpression} is catching a jump that is caused by a
* short circuit evaluation. It returns false, if there is a parent element that will catch the jump instead.
*/
private static boolean isTopJumpCatcher(BinaryLogicalExpression ble) {
EObject child, parent = ble;
do {
// skip parentheses
child = parent;
parent = parent.eContainer();
} while (parent instanceof ParenExpression);
if (parent instanceof BinaryLogicalExpression) {
return false;
}
if (parent instanceof ConditionalExpression) {
ConditionalExpression isParent = (ConditionalExpression) parent;
return isParent.getExpression() != child;
}
if (parent instanceof Statement) {
if (parent instanceof IfStatement) {
IfStatement isParent = (IfStatement) parent;
return isParent.getExpression() != child;
}
if (parent instanceof ForStatement) {
ForStatement isParent = (ForStatement) parent;
return isParent.getExpression() != child || !isParent.isForPlain();
}
if (parent instanceof WhileStatement) {
WhileStatement isParent = (WhileStatement) parent;
return isParent.getExpression() != child;
}
if (parent instanceof DoStatement) {
DoStatement isParent = (DoStatement) parent;
return isParent.getExpression() != child;
}
}
return true;
}
Aggregations