use of org.eclipse.n4js.n4JS.UnaryOperator in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeUnaryExpression.
protected Result<TypeRef> applyRuleTypeUnaryExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final UnaryExpression e) throws RuleFailedException {
// output parameter
TypeRef T = null;
if ((((e.getOp() == UnaryOperator.NEG) || (e.getOp() == UnaryOperator.POS)) && (e.getExpression() instanceof IntLiteral))) {
/* G |- e.expression : T */
Expression _expression = e.getExpression();
Result<TypeRef> result = typeInternal(G, _trace_, _expression);
checkAssignableTo(result.getFirst(), TypeRef.class);
T = (TypeRef) result.getFirst();
} else {
UnaryOperator _op = e.getOp();
if (_op != null) {
switch(_op) {
case DELETE:
T = RuleEnvironmentExtensions.booleanTypeRef(G);
break;
case VOID:
T = RuleEnvironmentExtensions.undefinedTypeRef(G);
break;
case TYPEOF:
T = RuleEnvironmentExtensions.stringTypeRef(G);
break;
case NOT:
T = RuleEnvironmentExtensions.booleanTypeRef(G);
break;
default:
T = RuleEnvironmentExtensions.numberTypeRef(G);
break;
}
} else {
T = RuleEnvironmentExtensions.numberTypeRef(G);
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.UnaryOperator in project n4js by eclipse.
the class PrettyPrinterSwitch method caseUnaryExpression.
@Override
public Boolean caseUnaryExpression(UnaryExpression original) {
final UnaryOperator op = original.getOp();
write(op.getLiteral());
// the following 3 unary operators require an additional space between operator and operand
if (op == UnaryOperator.TYPEOF || op == UnaryOperator.DELETE || op == UnaryOperator.VOID) {
write(' ');
}
process(original.getExpression());
return DONE;
}
use of org.eclipse.n4js.n4JS.UnaryOperator 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.UnaryOperator in project n4js by eclipse.
the class UnaryExpressionImpl method setOp.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setOp(UnaryOperator newOp) {
UnaryOperator oldOp = op;
op = newOp == null ? OP_EDEFAULT : newOp;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.UNARY_EXPRESSION__OP, oldOp, op));
}
use of org.eclipse.n4js.n4JS.UnaryOperator in project n4js by eclipse.
the class InternalTypeSystem method applyRuleExpectedTypeInUnaryExpression.
protected Result<TypeRef> applyRuleExpectedTypeInUnaryExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final UnaryExpression e, final Expression expression) throws RuleFailedException {
// output parameter
TypeRef T = null;
StaticBaseTypeRef _xifexpression = null;
boolean _isTypeAware = this.jsVariantHelper.isTypeAware(e);
if (_isTypeAware) {
StaticBaseTypeRef _switchResult = null;
UnaryOperator _op = e.getOp();
if (_op != null) {
switch(_op) {
case DELETE:
_switchResult = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
break;
case VOID:
_switchResult = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
break;
case TYPEOF:
_switchResult = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
break;
case INC:
_switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
break;
case DEC:
_switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
break;
case POS:
_switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
break;
case NEG:
_switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
break;
case INV:
_switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
break;
case NOT:
_switchResult = RuleEnvironmentExtensions.anyTypeRef(G);
break;
default:
_switchResult = RuleEnvironmentExtensions.anyTypeRef(G);
break;
}
} else {
_switchResult = RuleEnvironmentExtensions.anyTypeRef(G);
}
_xifexpression = _switchResult;
} else {
StaticBaseTypeRef _switchResult_1 = null;
UnaryOperator _op_1 = e.getOp();
if (_op_1 != null) {
switch(_op_1) {
case DELETE:
_switchResult_1 = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
break;
case VOID:
_switchResult_1 = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
break;
case TYPEOF:
_switchResult_1 = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
break;
default:
_switchResult_1 = RuleEnvironmentExtensions.anyTypeRef(G);
break;
}
} else {
_switchResult_1 = RuleEnvironmentExtensions.anyTypeRef(G);
}
_xifexpression = _switchResult_1;
}
T = _xifexpression;
return new Result<TypeRef>(T);
}
Aggregations