use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeFormalParameter.
protected Result<TypeRef> applyRuleTypeFormalParameter(final RuleEnvironment G, final RuleApplicationTrace _trace_, final FormalParameter fpar) throws RuleFailedException {
// output parameter
TypeRef T = null;
final TypeRef fparTypeRef = fpar.getDeclaredTypeRef();
if ((fparTypeRef != null)) {
if (((fparTypeRef instanceof ThisTypeRefStructural) || ((fparTypeRef instanceof FunctionTypeExpression) && IteratorExtensions.<TFormalParameter>exists(Iterators.<TFormalParameter>filter(((FunctionTypeExpression) fparTypeRef).eAllContents(), TFormalParameter.class), ((Function1<TFormalParameter, Boolean>) (TFormalParameter currFpar) -> {
TypeRef _typeRef = currFpar.getTypeRef();
return Boolean.valueOf((_typeRef instanceof ThisTypeRef));
}))))) {
T = this.typeSystemHelper.bindAndSubstituteThisTypeRef(G, fparTypeRef, fparTypeRef);
} else {
TypeRef _xifexpression = null;
TFormalParameter _definedTypeElement = null;
if (fpar != null) {
_definedTypeElement = fpar.getDefinedTypeElement();
}
TypeRef _typeRef = null;
if (_definedTypeElement != null) {
_typeRef = _definedTypeElement.getTypeRef();
}
boolean _tripleNotEquals = (_typeRef != null);
if (_tripleNotEquals) {
_xifexpression = fpar.getDefinedTypeElement().getTypeRef();
} else {
_xifexpression = fpar.getDeclaredTypeRef();
}
T = _xifexpression;
}
} else {
boolean _isHasInitializerAssignment = fpar.isHasInitializerAssignment();
if (_isHasInitializerAssignment) {
Expression _initializer = fpar.getInitializer();
boolean _tripleNotEquals_1 = (_initializer != null);
if (_tripleNotEquals_1) {
/* G |- fpar.initializer : var TypeRef E */
Expression _initializer_1 = fpar.getInitializer();
TypeRef E = null;
Result<TypeRef> result = typeInternal(G, _trace_, _initializer_1);
checkAssignableTo(result.getFirst(), TypeRef.class);
E = (TypeRef) result.getFirst();
T = this.typeSystemHelper.sanitizeTypeOfVariableFieldProperty(G, E);
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
} else {
boolean _enforceDynamicTypes = this.jsVariantHelper.enforceDynamicTypes(fpar);
if (_enforceDynamicTypes) {
T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
} else {
/* T = env(G, fpar, TypeRef) or T = G.anyTypeRef */
{
RuleFailedException previousFailure = null;
try {
T = this.<TypeRef>env(G, fpar, TypeRef.class);
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
}
}
}
}
T = TypeUtils.wrapIfVariadic(RuleEnvironmentExtensions.getPredefinedTypes(G).builtInTypeScope, T, fpar);
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeAssignmentExpression.
protected Result<TypeRef> applyRuleTypeAssignmentExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final AssignmentExpression expr) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* { expr.op===AssignmentOperator.ASSIGN; G |- expr.rhs: T } or { expr.op===AssignmentOperator.ADD_ASSIGN G |- expr.lhs: var ParameterizedTypeRef l G |- expr.rhs: var ParameterizedTypeRef r val lnum = l.declaredType == G.booleanType || G.isNumeric(l.declaredType); val rnum = r.declaredType == G.booleanType || G.isNumeric(r.declaredType); val undef = l.declaredType == G.undefinedType || l.declaredType == G.nullType || r.declaredType == G.undefinedType || r.declaredType == G.nullType; !(lnum && rnum); !(undef && (lnum || rnum)); T = G.stringTypeRef } or { T = G.numberTypeRef } */
{
RuleFailedException previousFailure = null;
try {
AssignmentOperator _op = expr.getOp();
boolean _tripleEquals = (_op == AssignmentOperator.ASSIGN);
/* expr.op===AssignmentOperator.ASSIGN */
if (!_tripleEquals) {
sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ASSIGN");
}
/* G |- expr.rhs: T */
Expression _rhs = expr.getRhs();
Result<TypeRef> result = typeInternal(G, _trace_, _rhs);
checkAssignableTo(result.getFirst(), TypeRef.class);
T = (TypeRef) result.getFirst();
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { expr.op===AssignmentOperator.ADD_ASSIGN G |- expr.lhs: var ParameterizedTypeRef l G |- expr.rhs: var ParameterizedTypeRef r val lnum = l.declaredType == G.booleanType || G.isNumeric(l.declaredType); val rnum = r.declaredType == G.booleanType || G.isNumeric(r.declaredType); val undef = l.declaredType == G.undefinedType || l.declaredType == G.nullType || r.declaredType == G.undefinedType || r.declaredType == G.nullType; !(lnum && rnum); !(undef && (lnum || rnum)); T = G.stringTypeRef } or { T = G.numberTypeRef } */
{
try {
AssignmentOperator _op_1 = expr.getOp();
boolean _tripleEquals_1 = (_op_1 == AssignmentOperator.ADD_ASSIGN);
/* expr.op===AssignmentOperator.ADD_ASSIGN */
if (!_tripleEquals_1) {
sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ADD_ASSIGN");
}
/* G |- expr.lhs: var ParameterizedTypeRef l */
Expression _lhs = expr.getLhs();
ParameterizedTypeRef l = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _lhs);
checkAssignableTo(result_1.getFirst(), ParameterizedTypeRef.class);
l = (ParameterizedTypeRef) result_1.getFirst();
/* G |- expr.rhs: var ParameterizedTypeRef r */
Expression _rhs_1 = expr.getRhs();
ParameterizedTypeRef r = null;
Result<TypeRef> result_2 = typeInternal(G, _trace_, _rhs_1);
checkAssignableTo(result_2.getFirst(), ParameterizedTypeRef.class);
r = (ParameterizedTypeRef) result_2.getFirst();
final boolean lnum = (Objects.equal(l.getDeclaredType(), RuleEnvironmentExtensions.booleanType(G)) || RuleEnvironmentExtensions.isNumeric(G, l.getDeclaredType()));
final boolean rnum = (Objects.equal(r.getDeclaredType(), RuleEnvironmentExtensions.booleanType(G)) || RuleEnvironmentExtensions.isNumeric(G, r.getDeclaredType()));
final boolean undef = (((Objects.equal(l.getDeclaredType(), RuleEnvironmentExtensions.undefinedType(G)) || Objects.equal(l.getDeclaredType(), RuleEnvironmentExtensions.nullType(G))) || Objects.equal(r.getDeclaredType(), RuleEnvironmentExtensions.undefinedType(G))) || Objects.equal(r.getDeclaredType(), RuleEnvironmentExtensions.nullType(G)));
/* !(lnum && rnum) */
if (!(!(lnum && rnum))) {
sneakyThrowRuleFailedException("!(lnum && rnum)");
}
/* !(undef && (lnum || rnum)) */
if (!(!(undef && (lnum || rnum)))) {
sneakyThrowRuleFailedException("!(undef && (lnum || rnum))");
}
T = RuleEnvironmentExtensions.stringTypeRef(G);
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
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 applyRuleTypeN4FieldDeclaration.
protected Result<TypeRef> applyRuleTypeN4FieldDeclaration(final RuleEnvironment G, final RuleApplicationTrace _trace_, final N4FieldDeclaration fieldDecl) throws RuleFailedException {
// output parameter
TypeRef T = null;
TypeRef _declaredTypeRef = fieldDecl.getDeclaredTypeRef();
boolean _tripleNotEquals = (_declaredTypeRef != null);
if (_tripleNotEquals) {
T = fieldDecl.getDeclaredTypeRef();
} else {
Expression _expression = fieldDecl.getExpression();
boolean _tripleNotEquals_1 = (_expression != null);
if (_tripleNotEquals_1) {
/* G |- fieldDecl.expression : var TypeRef E */
Expression _expression_1 = fieldDecl.getExpression();
TypeRef E = null;
Result<TypeRef> result = typeInternal(G, _trace_, _expression_1);
checkAssignableTo(result.getFirst(), TypeRef.class);
E = (TypeRef) result.getFirst();
/* G |~ E /\ E */
Result<TypeRef> result_1 = upperBoundInternal(G, _trace_, E);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
E = (TypeRef) result_1.getFirst();
if ((((E.getDeclaredType() == RuleEnvironmentExtensions.undefinedType(G)) || (E.getDeclaredType() == RuleEnvironmentExtensions.nullType(G))) || (E.getDeclaredType() == RuleEnvironmentExtensions.voidType(G)))) {
T = RuleEnvironmentExtensions.anyTypeRef(G);
} else {
T = E;
}
} 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 applyRuleTypeAwaitExpression.
protected Result<TypeRef> applyRuleTypeAwaitExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final AwaitExpression e) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* G |- e.expression : var TypeRef exprType */
Expression _expression = e.getExpression();
TypeRef exprType = null;
Result<TypeRef> result = typeInternal(G, _trace_, _expression);
checkAssignableTo(result.getFirst(), TypeRef.class);
exprType = (TypeRef) result.getFirst();
Type _declaredType = exprType.getDeclaredType();
TClass _promiseType = RuleEnvironmentExtensions.promiseType(G);
boolean _tripleEquals = (_declaredType == _promiseType);
if (_tripleEquals) {
/* G |~ exprType.typeArgs.get(0) /\ T */
TypeArgument _get = exprType.getTypeArgs().get(0);
Result<TypeRef> result_1 = upperBoundInternal(G, _trace_, _get);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
T = (TypeRef) result_1.getFirst();
} else {
boolean _isPromisifiableExpression = this.promisifyHelper.isPromisifiableExpression(e.getExpression());
if (_isPromisifiableExpression) {
final TypeRef promisifiedReturnTypeRef = this.promisifyHelper.extractPromisifiedReturnType(e.getExpression());
Type _declaredType_1 = promisifiedReturnTypeRef.getDeclaredType();
TClass _promiseType_1 = RuleEnvironmentExtensions.promiseType(G);
boolean _tripleEquals_1 = (_declaredType_1 == _promiseType_1);
if (_tripleEquals_1) {
/* G |~ promisifiedReturnTypeRef.typeArgs.get(0) /\ T */
TypeArgument _get_1 = promisifiedReturnTypeRef.getTypeArgs().get(0);
Result<TypeRef> result_2 = upperBoundInternal(G, _trace_, _get_1);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
T = (TypeRef) result_2.getFirst();
} else {
T = promisifiedReturnTypeRef;
}
} else {
T = exprType;
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.Expression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeArrayElement.
protected Result<TypeRef> applyRuleTypeArrayElement(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ArrayElement e) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* G |- e.expression: T */
Expression _expression = e.getExpression();
Result<TypeRef> result = typeInternal(G, _trace_, _expression);
checkAssignableTo(result.getFirst(), TypeRef.class);
T = (TypeRef) result.getFirst();
return new Result<TypeRef>(T);
}
Aggregations