use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeYieldExpression.
protected Result<TypeRef> applyRuleTypeYieldExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final YieldExpression y) throws RuleFailedException {
// output parameter
TypeRef T = null;
TypeRef t = null;
boolean _isMany = y.isMany();
if (_isMany) {
final Expression yieldValue = y.getExpression();
/* G |- yieldValue : var TypeRef yieldValueTypeRef */
TypeRef yieldValueTypeRef = null;
Result<TypeRef> result = typeInternal(G, _trace_, yieldValue);
checkAssignableTo(result.getFirst(), TypeRef.class);
yieldValueTypeRef = (TypeRef) result.getFirst();
final BuiltInTypeScope scope = RuleEnvironmentExtensions.getPredefinedTypes(G).builtInTypeScope;
boolean _isGenerator = TypeUtils.isGenerator(yieldValueTypeRef, scope);
if (_isGenerator) {
t = this.typeSystemHelper.getGeneratorTReturn(G, yieldValueTypeRef);
} else {
final ParameterizedTypeRef itTypeRef = RuleEnvironmentExtensions.iterableTypeRef(G, TypeUtils.createWildcard());
/* G |- yieldValueTypeRef <: itTypeRef */
boolean _ruleinvocation = subtypeSucceeded(G, _trace_, yieldValueTypeRef, itTypeRef);
final boolean isIterable = _ruleinvocation;
if (isIterable) {
t = scope.getAnyTypeRef();
}
}
} else {
final TypeRef actualGenTypeRef = this.typeSystemHelper.getActualGeneratorReturnType(G, y);
if ((actualGenTypeRef != null)) {
t = this.typeSystemHelper.getGeneratorTNext(G, actualGenTypeRef);
}
}
if ((t == null)) {
t = RuleEnvironmentExtensions.anyTypeRef(G);
}
T = t;
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleExpectedTypeInRelationalExpression.
protected Result<TypeRef> applyRuleExpectedTypeInRelationalExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final RelationalExpression e, final Expression expression) throws RuleFailedException {
// output parameter
TypeRef T = null;
RelationalOperator _op = e.getOp();
if (_op != null) {
switch(_op) {
case INSTANCEOF:
Expression _rhs = e.getRhs();
boolean _tripleEquals = (expression == _rhs);
if (_tripleEquals) {
T = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.functionTypeRef(G), TypeUtils.createTypeTypeRef(RuleEnvironmentExtensions.objectTypeRef(G), false), TypeUtils.createTypeTypeRef(RuleEnvironmentExtensions.n4EnumTypeRef(G), false));
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
break;
case IN:
Expression _rhs_1 = e.getRhs();
boolean _tripleEquals_1 = (expression == _rhs_1);
if (_tripleEquals_1) {
T = RuleEnvironmentExtensions.objectTypeRef(G);
} else {
boolean _isTypeAware = this.jsVariantHelper.isTypeAware(e);
if (_isTypeAware) {
T = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.numberTypeRef(G), RuleEnvironmentExtensions.stringTypeRef(G));
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
}
break;
default:
boolean _isTypeAware_1 = this.jsVariantHelper.isTypeAware(e);
if (_isTypeAware_1) {
final UnionTypeExpression primsTR = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.numberTypeRef(G), RuleEnvironmentExtensions.stringTypeRef(G), RuleEnvironmentExtensions.booleanTypeRef(G));
Expression _xifexpression = null;
Expression _lhs = e.getLhs();
boolean _tripleEquals_2 = (expression == _lhs);
if (_tripleEquals_2) {
_xifexpression = e.getRhs();
} else {
_xifexpression = e.getLhs();
}
final Expression otherSide = _xifexpression;
/* G |- otherSide : var TypeRef otherSideTR */
TypeRef otherSideTR = null;
Result<TypeRef> result = typeInternal(G, _trace_, otherSide);
checkAssignableTo(result.getFirst(), TypeRef.class);
otherSideTR = (TypeRef) result.getFirst();
boolean _and = false;
/* G |- otherSideTR <: primsTR */
boolean _ruleinvocation = subtypeSucceeded(G, _trace_, otherSideTR, primsTR);
if (!_ruleinvocation) {
_and = false;
} else {
/* G |- otherSideTR <: G.nullTypeRef */
ParameterizedTypeRef _nullTypeRef = RuleEnvironmentExtensions.nullTypeRef(G);
boolean _ruleinvocation_1 = subtypeSucceeded(G, _trace_, otherSideTR, _nullTypeRef);
boolean _not = (!_ruleinvocation_1);
_and = _not;
}
if (_and) {
T = otherSideTR;
} else {
T = primsTR;
}
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
break;
}
} else {
boolean _isTypeAware_1 = this.jsVariantHelper.isTypeAware(e);
if (_isTypeAware_1) {
final UnionTypeExpression primsTR = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.numberTypeRef(G), RuleEnvironmentExtensions.stringTypeRef(G), RuleEnvironmentExtensions.booleanTypeRef(G));
Expression _xifexpression = null;
Expression _lhs = e.getLhs();
boolean _tripleEquals_2 = (expression == _lhs);
if (_tripleEquals_2) {
_xifexpression = e.getRhs();
} else {
_xifexpression = e.getLhs();
}
final Expression otherSide = _xifexpression;
/* G |- otherSide : var TypeRef otherSideTR */
TypeRef otherSideTR = null;
Result<TypeRef> result = typeInternal(G, _trace_, otherSide);
checkAssignableTo(result.getFirst(), TypeRef.class);
otherSideTR = (TypeRef) result.getFirst();
boolean _and = false;
/* G |- otherSideTR <: primsTR */
boolean _ruleinvocation = subtypeSucceeded(G, _trace_, otherSideTR, primsTR);
if (!_ruleinvocation) {
_and = false;
} else {
/* G |- otherSideTR <: G.nullTypeRef */
ParameterizedTypeRef _nullTypeRef = RuleEnvironmentExtensions.nullTypeRef(G);
boolean _ruleinvocation_1 = subtypeSucceeded(G, _trace_, otherSideTR, _nullTypeRef);
boolean _not = (!_ruleinvocation_1);
_and = _not;
}
if (_and) {
T = otherSideTR;
} else {
T = primsTR;
}
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeConditionalExpression.
protected Result<TypeRef> applyRuleTypeConditionalExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ConditionalExpression expr) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* G |- expr.trueExpression : var TypeRef left */
Expression _trueExpression = expr.getTrueExpression();
TypeRef left = null;
Result<TypeRef> result = typeInternal(G, _trace_, _trueExpression);
checkAssignableTo(result.getFirst(), TypeRef.class);
left = (TypeRef) result.getFirst();
/* G |- expr.falseExpression : var TypeRef right */
Expression _falseExpression = expr.getFalseExpression();
TypeRef right = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _falseExpression);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
right = (TypeRef) result_1.getFirst();
T = this.typeSystemHelper.createUnionType(G, left, right);
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleExpectedTypeInAssignmentExpression.
protected Result<TypeRef> applyRuleExpectedTypeInAssignmentExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final AssignmentExpression expr, final Expression operand) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* { ! jsVariantHelper.isTypeAware(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { DestructureUtils.isTopOfDestructuringAssignment(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
{
RuleFailedException previousFailure = null;
try {
boolean _isTypeAware = this.jsVariantHelper.isTypeAware(expr);
boolean _not = (!_isTypeAware);
/* ! jsVariantHelper.isTypeAware(expr) */
if (!_not) {
sneakyThrowRuleFailedException("! jsVariantHelper.isTypeAware(expr)");
}
Expression _lhs = expr.getLhs();
boolean _tripleEquals = (operand == _lhs);
if (_tripleEquals) {
T = RuleEnvironmentExtensions.bottomTypeRef(G);
} else {
T = RuleEnvironmentExtensions.topTypeRef(G);
}
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { DestructureUtils.isTopOfDestructuringAssignment(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
{
try {
boolean _isTopOfDestructuringAssignment = DestructureUtils.isTopOfDestructuringAssignment(expr);
/* DestructureUtils.isTopOfDestructuringAssignment(expr) */
if (!_isTopOfDestructuringAssignment) {
sneakyThrowRuleFailedException("DestructureUtils.isTopOfDestructuringAssignment(expr)");
}
Expression _lhs_1 = expr.getLhs();
boolean _tripleEquals_1 = (operand == _lhs_1);
if (_tripleEquals_1) {
T = RuleEnvironmentExtensions.bottomTypeRef(G);
} else {
T = RuleEnvironmentExtensions.topTypeRef(G);
}
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
/* { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
{
try {
AssignmentOperator _op = expr.getOp();
boolean _tripleEquals_2 = (_op == AssignmentOperator.ASSIGN);
/* expr.op===AssignmentOperator.ASSIGN */
if (!_tripleEquals_2) {
sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ASSIGN");
}
Expression _lhs_2 = expr.getLhs();
boolean _tripleEquals_3 = (operand == _lhs_2);
if (_tripleEquals_3) {
T = RuleEnvironmentExtensions.bottomTypeRef(G);
} else {
/* G |- expr.lhs : T */
Expression _lhs_3 = expr.getLhs();
Result<TypeRef> result = typeInternal(G, _trace_, _lhs_3);
checkAssignableTo(result.getFirst(), TypeRef.class);
T = (TypeRef) result.getFirst();
}
} catch (Exception e_2) {
previousFailure = extractRuleFailedException(e_2);
/* { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
{
try {
AssignmentOperator _op_1 = expr.getOp();
boolean _tripleEquals_4 = (_op_1 == AssignmentOperator.ADD_ASSIGN);
/* expr.op===AssignmentOperator.ADD_ASSIGN */
if (!_tripleEquals_4) {
sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ADD_ASSIGN");
}
Expression _lhs_4 = expr.getLhs();
boolean _tripleEquals_5 = (operand == _lhs_4);
if (_tripleEquals_5) {
T = TypeUtils.createNonSimplifiedIntersectionType(RuleEnvironmentExtensions.numberTypeRef(G), RuleEnvironmentExtensions.stringTypeRef(G));
} else {
/* G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef */
Expression _lhs_5 = expr.getLhs();
ParameterizedTypeRef lhsTypeRef = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _lhs_5);
checkAssignableTo(result_1.getFirst(), ParameterizedTypeRef.class);
lhsTypeRef = (ParameterizedTypeRef) result_1.getFirst();
Type _declaredType = lhsTypeRef.getDeclaredType();
PrimitiveType _stringType = RuleEnvironmentExtensions.stringType(G);
boolean _tripleEquals_6 = (_declaredType == _stringType);
if (_tripleEquals_6) {
T = RuleEnvironmentExtensions.anyTypeRef(G);
} else {
boolean _isNumeric = RuleEnvironmentExtensions.isNumeric(G, lhsTypeRef.getDeclaredType());
if (_isNumeric) {
T = RuleEnvironmentExtensions.numberTypeRef(G);
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
}
}
} catch (Exception e_3) {
previousFailure = extractRuleFailedException(e_3);
T = RuleEnvironmentExtensions.numberTypeRef(G);
}
}
}
}
}
}
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.Expression 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);
}
Aggregations