use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.
the class InternalTypeSystem method applyRuleSubstTypeVariablesInParameterizedTypeRef.
protected Result<TypeArgument> applyRuleSubstTypeVariablesInParameterizedTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedTypeRef typeRef) throws RuleFailedException {
// output parameter
TypeRef result = null;
result = typeRef;
Type _declaredType = typeRef.getDeclaredType();
if ((_declaredType instanceof TypeVariable)) {
Type _declaredType_1 = typeRef.getDeclaredType();
final TypeVariable typeVar = ((TypeVariable) _declaredType_1);
/* { var temp = env(G, typeVar, TypeRef) if (typeRef instanceof ParameterizedTypeRefStructural) { if (temp instanceof ParameterizedTypeRef) { var ptrs = TypeUtils.copyToParameterizedTypeRefStructural(temp); ptrs.setTypingStrategy(typeRef.getTypingStrategy()); temp = ptrs; } } val tempDeclaredType = temp.declaredType if (typeVar !== tempDeclaredType && (TypeUtils.isOrContainsRefToTypeVar(temp) || (tempDeclaredType !== null && tempDeclaredType.generic)) && G.get(GUARD_SUBST_TYPE_VARS -> temp) === null) { val G2 = G.wrap; G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) G2 |- temp ~> result result = TypeUtils.copy(result); } else { result = TypeUtils.copy(temp); } TypeUtils.copyTypeModifiers(result, typeRef) } or { val List<TypeRef> l_raw = env(G, typeVar, List) val l = newArrayList; for(var i=0;i<l_raw.size;i++) { val temp = l_raw.get(i); val tempDeclaredType = temp.declaredType; if(typeVar !== tempDeclaredType && (TypeUtils.isOrContainsRefToTypeVar(temp) || (tempDeclaredType !== null && tempDeclaredType.generic)) && G.get(GUARD_SUBST_TYPE_VARS -> temp) === null) { val G2 = G.wrap; G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) G2 |- temp ~> var TypeRef tempResult tempResult = TypeUtils.copy(tempResult); l += tempResult; } else { l += TypeUtils.copy(temp); } } result = if(typeVar.declaredCovariant) { typeSystemHelper.createIntersectionType(G,l) } else if(typeVar.declaredContravariant) { typeSystemHelper.createUnionType(G,l) } else { G.addInconsistentSubstitutions(typeVar, l); TypeRefsFactory.eINSTANCE.createUnknownTypeRef }; TypeUtils.copyTypeModifiers(result, typeRef) } or { } */
{
RuleFailedException previousFailure = null;
try {
TypeRef temp = this.<TypeRef>env(G, typeVar, TypeRef.class);
if ((typeRef instanceof ParameterizedTypeRefStructural)) {
if ((temp instanceof ParameterizedTypeRef)) {
ParameterizedTypeRefStructural ptrs = TypeUtils.copyToParameterizedTypeRefStructural(((ParameterizedTypeRef) temp));
ptrs.setTypingStrategy(((ParameterizedTypeRefStructural) typeRef).getTypingStrategy());
temp = ptrs;
}
}
final Type tempDeclaredType = temp.getDeclaredType();
if ((((typeVar != tempDeclaredType) && (TypeUtils.isOrContainsRefToTypeVar(temp) || ((tempDeclaredType != null) && tempDeclaredType.isGeneric()))) && (G.get(Pair.<String, TypeRef>of(RuleEnvironmentExtensions.GUARD_SUBST_TYPE_VARS, temp)) == null))) {
final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
Pair<String, TypeRef> _mappedTo = Pair.<String, TypeRef>of(RuleEnvironmentExtensions.GUARD_SUBST_TYPE_VARS, temp);
boolean _add = G2.add(_mappedTo, Boolean.TRUE);
/* G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) */
if (!_add) {
sneakyThrowRuleFailedException("G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE)");
}
/* G2 |- temp ~> result */
Result<TypeArgument> result_1 = substTypeVariablesInternal(G2, _trace_, temp);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
result = (TypeRef) result_1.getFirst();
result = TypeUtils.<TypeRef>copy(result);
} else {
result = TypeUtils.<TypeRef>copy(temp);
}
TypeUtils.copyTypeModifiers(result, typeRef);
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { val List<TypeRef> l_raw = env(G, typeVar, List) val l = newArrayList; for(var i=0;i<l_raw.size;i++) { val temp = l_raw.get(i); val tempDeclaredType = temp.declaredType; if(typeVar !== tempDeclaredType && (TypeUtils.isOrContainsRefToTypeVar(temp) || (tempDeclaredType !== null && tempDeclaredType.generic)) && G.get(GUARD_SUBST_TYPE_VARS -> temp) === null) { val G2 = G.wrap; G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) G2 |- temp ~> var TypeRef tempResult tempResult = TypeUtils.copy(tempResult); l += tempResult; } else { l += TypeUtils.copy(temp); } } result = if(typeVar.declaredCovariant) { typeSystemHelper.createIntersectionType(G,l) } else if(typeVar.declaredContravariant) { typeSystemHelper.createUnionType(G,l) } else { G.addInconsistentSubstitutions(typeVar, l); TypeRefsFactory.eINSTANCE.createUnknownTypeRef }; TypeUtils.copyTypeModifiers(result, typeRef) } or { } */
{
try {
final List<TypeRef> l_raw = this.<List>env(G, typeVar, List.class);
final ArrayList<TypeRef> l = CollectionLiterals.<TypeRef>newArrayList();
for (int i = 0; (i < l_raw.size()); i++) {
final TypeRef temp_1 = l_raw.get(i);
final Type tempDeclaredType_1 = temp_1.getDeclaredType();
if ((((typeVar != tempDeclaredType_1) && (TypeUtils.isOrContainsRefToTypeVar(temp_1) || ((tempDeclaredType_1 != null) && tempDeclaredType_1.isGeneric()))) && (G.get(Pair.<String, TypeRef>of(RuleEnvironmentExtensions.GUARD_SUBST_TYPE_VARS, temp_1)) == null))) {
final RuleEnvironment G2_1 = RuleEnvironmentExtensions.wrap(G);
Pair<String, TypeRef> _mappedTo_1 = Pair.<String, TypeRef>of(RuleEnvironmentExtensions.GUARD_SUBST_TYPE_VARS, temp_1);
boolean _add_1 = G2_1.add(_mappedTo_1, Boolean.TRUE);
/* G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) */
if (!_add_1) {
sneakyThrowRuleFailedException("G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE)");
}
/* G2 |- temp ~> var TypeRef tempResult */
TypeRef tempResult = null;
Result<TypeArgument> result_2 = substTypeVariablesInternal(G2_1, _trace_, temp_1);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
tempResult = (TypeRef) result_2.getFirst();
tempResult = TypeUtils.<TypeRef>copy(tempResult);
/* l += tempResult */
if (!l.add(tempResult)) {
sneakyThrowRuleFailedException("l += tempResult");
}
} else {
TypeRef _copy = TypeUtils.<TypeRef>copy(temp_1);
/* l += TypeUtils.copy(temp) */
if (!l.add(_copy)) {
sneakyThrowRuleFailedException("l += TypeUtils.copy(temp)");
}
}
}
TypeRef _xifexpression = null;
boolean _isDeclaredCovariant = typeVar.isDeclaredCovariant();
if (_isDeclaredCovariant) {
_xifexpression = this.typeSystemHelper.createIntersectionType(G, ((TypeRef[]) Conversions.unwrapArray(l, TypeRef.class)));
} else {
TypeRef _xifexpression_1 = null;
boolean _isDeclaredContravariant = typeVar.isDeclaredContravariant();
if (_isDeclaredContravariant) {
_xifexpression_1 = this.typeSystemHelper.createUnionType(G, ((TypeRef[]) Conversions.unwrapArray(l, TypeRef.class)));
} else {
UnknownTypeRef _xblockexpression = null;
{
RuleEnvironmentExtensions.addInconsistentSubstitutions(G, typeVar, l);
_xblockexpression = (TypeRefsFactory.eINSTANCE.createUnknownTypeRef());
}
_xifexpression_1 = _xblockexpression;
}
_xifexpression = _xifexpression_1;
}
result = _xifexpression;
TypeUtils.copyTypeModifiers(result, typeRef);
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
}
}
}
}
}
boolean _and = false;
Type _declaredType_2 = null;
if (typeRef != null) {
_declaredType_2 = typeRef.getDeclaredType();
}
boolean _tripleNotEquals = (_declaredType_2 != null);
if (!_tripleNotEquals) {
_and = false;
} else {
boolean _isGeneric = typeRef.getDeclaredType().isGeneric();
_and = _isGeneric;
}
if (_and) {
final int len = typeRef.getTypeArgs().size();
boolean haveSubstitution = false;
final TypeArgument[] argsChanged = new TypeArgument[len];
for (int i = 0; (i < len); i++) {
final TypeArgument arg = typeRef.getTypeArgs().get(i);
/* G |- arg ~> var TypeArgument argSubst */
TypeArgument argSubst = null;
Result<TypeArgument> result_2 = substTypeVariablesInternal(G, _trace_, arg);
checkAssignableTo(result_2.getFirst(), TypeArgument.class);
argSubst = (TypeArgument) result_2.getFirst();
if ((argSubst != arg)) {
argsChanged[i] = argSubst;
haveSubstitution = true;
}
}
if (haveSubstitution) {
if ((result == typeRef)) {
result = TypeUtils.<ParameterizedTypeRef>copy(typeRef);
}
for (int i = 0; (i < len); i++) {
final TypeArgument argCh = argsChanged[i];
if ((argCh != null)) {
result.getTypeArgs().set(i, argCh);
}
}
}
}
if ((result instanceof StructuralTypeRef)) {
result = this.typeSystemHelper.substTypeVariablesInStructuralMembers(G, ((StructuralTypeRef) result));
}
return new Result<TypeArgument>(result);
}
use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.
the class InternalTypeSystem method applyRuleSubstTypeVariablesInTypeTypeRef.
protected Result<TypeArgument> applyRuleSubstTypeVariablesInTypeTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeTypeRef typeRef) throws RuleFailedException {
// output parameter
TypeTypeRef result = null;
/* G |- typeRef.getTypeArg ~> var TypeArgument tResult */
TypeArgument _typeArg = typeRef.getTypeArg();
TypeArgument tResult = null;
Result<TypeArgument> result_1 = substTypeVariablesInternal(G, _trace_, _typeArg);
checkAssignableTo(result_1.getFirst(), TypeArgument.class);
tResult = (TypeArgument) result_1.getFirst();
TypeArgument _typeArg_1 = typeRef.getTypeArg();
boolean _tripleNotEquals = (_typeArg_1 != tResult);
if (_tripleNotEquals) {
tResult = TypeUtils.<TypeArgument>copyIfContained(tResult);
result = TypeUtils.<TypeTypeRef>copyIfContained(typeRef);
result.setTypeArg(tResult);
} else {
result = typeRef;
}
return new Result<TypeArgument>(result);
}
use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypePropertyAccessExpression.
protected Result<TypeRef> applyRuleTypePropertyAccessExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedPropertyAccessExpression expr) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* { T = env(G, GUARD_TYPE_PROPERTY_ACCESS_EXPRESSION -> expr, TypeRef) } or { val G2 = G.wrap G2.add(GUARD_TYPE_PROPERTY_ACCESS_EXPRESSION -> expr, G2.anyTypeRef) G2 |- expr.target : var TypeRef receiverTypeRef typeSystemHelper.addSubstitutions(G2,receiverTypeRef) G2.addThisType(receiverTypeRef) if (! (receiverTypeRef instanceof UnknownTypeRef) && (expr.target instanceof SuperLiteral || expr.target instanceof ThisLiteral) ) { var containingClass = EcoreUtil2.getContainerOfType(expr,N4ClassDeclaration)?.definedType; if (containingClass instanceof TClass) { if (containingClass.isStaticPolyfill) { containingClass = containingClass.superClassRef?.declaredType } if (containingClass instanceof TClass) { if (containingClass?.superClassRef!==null) { typeSystemHelper.addSubstitutions(G2, containingClass.superClassRef) } } } } val prop = expr.property; var TypeRef propTypeRef; if(prop instanceof TMethod && (prop as TMethod).isConstructor) { val TypeArgument ctorTypeArg = switch(receiverTypeRef) { TypeTypeRef: G.functionTypeRef ParameterizedTypeRef, BoundThisTypeRef: { val declType = if(receiverTypeRef instanceof BoundThisTypeRef) { receiverTypeRef.actualThisTypeRef?.declaredType } else { receiverTypeRef.declaredType }; val finalCtorSig = if(declType instanceof TClassifier) N4JSLanguageUtils.hasCovariantConstructor(declType); if(finalCtorSig) { declType.ref } else if(declType!==null) { TypeUtils.createWildcardExtends(declType.ref) } else { null } } }; propTypeRef = if(ctorTypeArg!==null) { TypeUtils.createTypeTypeRef(ctorTypeArg, true) } else { TypeRefsFactory.eINSTANCE.createUnknownTypeRef }; } else if(receiverTypeRef.dynamic && prop!==null && prop.eIsProxy) { propTypeRef = G.anyTypeRefDynamic; } else { G2.wrap |- prop : propTypeRef if(expr.parameterized) { typeSystemHelper.addSubstitutions(G2,expr); } } G2 |- propTypeRef ~> T T = versionResolver.resolveVersion(T, receiverTypeRef); if (expr.target instanceof SuperLiteral && T instanceof FunctionTypeExprOrRef ) { val F = T as FunctionTypeExprOrRef; if ((T as FunctionTypeExprOrRef).returnTypeRef instanceof BoundThisTypeRef) { var TypeRef rawT; G |~ expr ~> rawT; val thisTypeRef = TypeUtils.enforceNominalTyping(rawT); if (T instanceof FunctionTypeExpression && T.eContainer===null) { val fte = T as FunctionTypeExpression fte.returnTypeRef = TypeUtils.copyIfContained(thisTypeRef); } else { T = TypeUtils.createFunctionTypeExpression(null, F.typeVars, F.fpars, thisTypeRef); } } } } */
{
RuleFailedException previousFailure = null;
try {
Pair<String, ParameterizedPropertyAccessExpression> _mappedTo = Pair.<String, ParameterizedPropertyAccessExpression>of(RuleEnvironmentExtensions.GUARD_TYPE_PROPERTY_ACCESS_EXPRESSION, expr);
T = this.<TypeRef>env(G, _mappedTo, TypeRef.class);
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
Pair<String, ParameterizedPropertyAccessExpression> _mappedTo_1 = Pair.<String, ParameterizedPropertyAccessExpression>of(RuleEnvironmentExtensions.GUARD_TYPE_PROPERTY_ACCESS_EXPRESSION, expr);
boolean _add = G2.add(_mappedTo_1, RuleEnvironmentExtensions.anyTypeRef(G2));
/* G2.add(GUARD_TYPE_PROPERTY_ACCESS_EXPRESSION -> expr, G2.anyTypeRef) */
if (!_add) {
sneakyThrowRuleFailedException("G2.add(GUARD_TYPE_PROPERTY_ACCESS_EXPRESSION -> expr, G2.anyTypeRef)");
}
/* G2 |- expr.target : var TypeRef receiverTypeRef */
Expression _target = expr.getTarget();
TypeRef receiverTypeRef = null;
Result<TypeRef> result = typeInternal(G2, _trace_, _target);
checkAssignableTo(result.getFirst(), TypeRef.class);
receiverTypeRef = (TypeRef) result.getFirst();
this.typeSystemHelper.addSubstitutions(G2, receiverTypeRef);
RuleEnvironmentExtensions.addThisType(G2, receiverTypeRef);
if (((!(receiverTypeRef instanceof UnknownTypeRef)) && ((expr.getTarget() instanceof SuperLiteral) || (expr.getTarget() instanceof ThisLiteral)))) {
N4ClassDeclaration _containerOfType = EcoreUtil2.<N4ClassDeclaration>getContainerOfType(expr, N4ClassDeclaration.class);
Type _definedType = null;
if (_containerOfType != null) {
_definedType = _containerOfType.getDefinedType();
}
Type containingClass = _definedType;
if ((containingClass instanceof TClass)) {
boolean _isStaticPolyfill = ((TClass) containingClass).isStaticPolyfill();
if (_isStaticPolyfill) {
ParameterizedTypeRef _superClassRef = ((TClass) containingClass).getSuperClassRef();
Type _declaredType = null;
if (_superClassRef != null) {
_declaredType = _superClassRef.getDeclaredType();
}
containingClass = _declaredType;
}
if ((containingClass instanceof TClass)) {
ParameterizedTypeRef _superClassRef_1 = null;
if (((TClass) containingClass) != null) {
_superClassRef_1 = ((TClass) containingClass).getSuperClassRef();
}
boolean _tripleNotEquals = (_superClassRef_1 != null);
if (_tripleNotEquals) {
this.typeSystemHelper.addSubstitutions(G2, ((TClass) containingClass).getSuperClassRef());
}
}
}
}
final IdentifiableElement prop = expr.getProperty();
TypeRef propTypeRef = null;
if (((prop instanceof TMethod) && ((TMethod) prop).isConstructor())) {
TypeArgument _switchResult = null;
boolean _matched = false;
if (receiverTypeRef instanceof TypeTypeRef) {
_matched = true;
_switchResult = RuleEnvironmentExtensions.functionTypeRef(G);
}
if (!_matched) {
if (receiverTypeRef instanceof ParameterizedTypeRef) {
_matched = true;
}
if (!_matched) {
if (receiverTypeRef instanceof BoundThisTypeRef) {
_matched = true;
}
}
if (_matched) {
TypeArgument _xblockexpression = null;
{
Type _xifexpression = null;
if ((receiverTypeRef instanceof BoundThisTypeRef)) {
ParameterizedTypeRef _actualThisTypeRef = ((BoundThisTypeRef) receiverTypeRef).getActualThisTypeRef();
Type _declaredType_1 = null;
if (_actualThisTypeRef != null) {
_declaredType_1 = _actualThisTypeRef.getDeclaredType();
}
_xifexpression = _declaredType_1;
} else {
_xifexpression = ((BaseTypeRef) receiverTypeRef).getDeclaredType();
}
final Type declType = _xifexpression;
boolean _xifexpression_1 = false;
if ((declType instanceof TClassifier)) {
_xifexpression_1 = N4JSLanguageUtils.hasCovariantConstructor(((TClassifier) declType));
}
final boolean finalCtorSig = _xifexpression_1;
TypeArgument _xifexpression_2 = null;
if (finalCtorSig) {
_xifexpression_2 = TypeExtensions.ref(declType);
} else {
Wildcard _xifexpression_3 = null;
if ((declType != null)) {
_xifexpression_3 = TypeUtils.createWildcardExtends(TypeExtensions.ref(declType));
} else {
_xifexpression_3 = null;
}
_xifexpression_2 = _xifexpression_3;
}
_xblockexpression = (_xifexpression_2);
}
_switchResult = _xblockexpression;
}
}
final TypeArgument ctorTypeArg = _switchResult;
TypeRef _xifexpression = null;
if ((ctorTypeArg != null)) {
_xifexpression = TypeUtils.createTypeTypeRef(ctorTypeArg, true);
} else {
_xifexpression = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
propTypeRef = _xifexpression;
} else {
if (((receiverTypeRef.isDynamic() && (prop != null)) && prop.eIsProxy())) {
propTypeRef = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
} else {
/* G2.wrap |- prop : propTypeRef */
RuleEnvironment _wrap = RuleEnvironmentExtensions.wrap(G2);
Result<TypeRef> result_1 = typeInternal(_wrap, _trace_, prop);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
propTypeRef = (TypeRef) result_1.getFirst();
boolean _isParameterized = expr.isParameterized();
if (_isParameterized) {
this.typeSystemHelper.addSubstitutions(G2, expr);
}
}
}
/* G2 |- propTypeRef ~> T */
Result<TypeArgument> result_2 = substTypeVariablesInternal(G2, _trace_, propTypeRef);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
T = (TypeRef) result_2.getFirst();
T = this.versionResolver.<TypeRef, TypeRef>resolveVersion(T, receiverTypeRef);
if (((expr.getTarget() instanceof SuperLiteral) && (T instanceof FunctionTypeExprOrRef))) {
final FunctionTypeExprOrRef F = ((FunctionTypeExprOrRef) T);
TypeRef _returnTypeRef = ((FunctionTypeExprOrRef) T).getReturnTypeRef();
if ((_returnTypeRef instanceof BoundThisTypeRef)) {
TypeRef rawT = null;
/* G |~ expr ~> rawT */
Result<TypeRef> result_3 = thisTypeRefInternal(G, _trace_, expr);
checkAssignableTo(result_3.getFirst(), TypeRef.class);
rawT = (TypeRef) result_3.getFirst();
final TypeRef thisTypeRef = TypeUtils.enforceNominalTyping(rawT);
if (((T instanceof FunctionTypeExpression) && (T.eContainer() == null))) {
final FunctionTypeExpression fte = ((FunctionTypeExpression) T);
fte.setReturnTypeRef(TypeUtils.<TypeRef>copyIfContained(thisTypeRef));
} else {
T = TypeUtils.createFunctionTypeExpression(null, F.getTypeVars(), F.getFpars(), thisTypeRef);
}
}
}
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.
the class InternalTypeSystem method applyRuleUpperBoundTypeTypeRef.
protected Result<TypeRef> applyRuleUpperBoundTypeTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeTypeRef ct) throws RuleFailedException {
// output parameter
TypeRef T = null;
final TypeArgument typeArg = ct.getTypeArg();
if ((typeArg instanceof BoundThisTypeRef)) {
final ParameterizedTypeRef typeArgNew = TypeUtils.createResolvedThisTypeRef(((BoundThisTypeRef) typeArg));
T = TypeUtils.createTypeTypeRef(typeArgNew, ct.isConstructorRef());
} else {
T = ct;
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeVariableDeclaration.
protected Result<TypeRef> applyRuleTypeVariableDeclaration(final RuleEnvironment G, final RuleApplicationTrace _trace_, final VariableDeclaration vdecl) throws RuleFailedException {
// output parameter
TypeRef T = null;
TypeRef _declaredTypeRef = vdecl.getDeclaredTypeRef();
boolean _tripleNotEquals = (_declaredTypeRef != null);
if (_tripleNotEquals) {
T = vdecl.getDeclaredTypeRef();
} else {
EObject _eContainer = vdecl.eContainer();
if ((_eContainer instanceof BindingElement)) {
Expression _expression = vdecl.getExpression();
Pair<String, Expression> _mappedTo = Pair.<String, Expression>of(RuleEnvironmentExtensions.GUARD_VARIABLE_DECLARATION, _expression);
Object _get = G.get(_mappedTo);
boolean _tripleEquals = (_get == null);
if (_tripleEquals) {
final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
Expression _expression_1 = vdecl.getExpression();
Pair<String, Expression> _mappedTo_1 = Pair.<String, Expression>of(RuleEnvironmentExtensions.GUARD_VARIABLE_DECLARATION, _expression_1);
boolean _add = G2.add(_mappedTo_1, Boolean.TRUE);
/* G2.add(GUARD_VARIABLE_DECLARATION->vdecl.expression,Boolean.TRUE) */
if (!_add) {
sneakyThrowRuleFailedException("G2.add(GUARD_VARIABLE_DECLARATION->vdecl.expression,Boolean.TRUE)");
}
TypeRef _elvis = null;
TypeRef _typeOfVariableDeclarationInDestructuringPattern = this.destructureHelper.getTypeOfVariableDeclarationInDestructuringPattern(G2, vdecl);
if (_typeOfVariableDeclarationInDestructuringPattern != null) {
_elvis = _typeOfVariableDeclarationInDestructuringPattern;
} else {
ParameterizedTypeRef _anyTypeRef = RuleEnvironmentExtensions.anyTypeRef(G);
_elvis = _anyTypeRef;
}
T = _elvis;
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
} else {
if (((vdecl.eContainer() instanceof ForStatement) && ((ForStatement) vdecl.eContainer()).isForOf())) {
EObject _eContainer_1 = vdecl.eContainer();
final ForStatement forOfStmnt = ((ForStatement) _eContainer_1);
EObject _eContainer_2 = vdecl.eContainer();
Pair<String, EObject> _mappedTo_2 = Pair.<String, EObject>of(RuleEnvironmentExtensions.GUARD_VARIABLE_DECLARATION, _eContainer_2);
Object _get_1 = G.get(_mappedTo_2);
boolean _tripleEquals_1 = (_get_1 == null);
if (_tripleEquals_1) {
final RuleEnvironment G2_1 = RuleEnvironmentExtensions.wrap(G);
EObject _eContainer_3 = vdecl.eContainer();
Pair<String, EObject> _mappedTo_3 = Pair.<String, EObject>of(RuleEnvironmentExtensions.GUARD_VARIABLE_DECLARATION, _eContainer_3);
boolean _add_1 = G2_1.add(_mappedTo_3, Boolean.TRUE);
/* G2.add(GUARD_VARIABLE_DECLARATION->vdecl.eContainer,Boolean.TRUE) */
if (!_add_1) {
sneakyThrowRuleFailedException("G2.add(GUARD_VARIABLE_DECLARATION->vdecl.eContainer,Boolean.TRUE)");
}
/* { G2 |- forOfStmnt.expression : var TypeRef ofPartTypeRef val elemType = destructureHelper.extractIterableElementType(G2, ofPartTypeRef) elemType!==null G2 |~ elemType /\ T } or { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } */
{
RuleFailedException previousFailure = null;
try {
/* G2 |- forOfStmnt.expression : var TypeRef ofPartTypeRef */
Expression _expression_2 = forOfStmnt.getExpression();
TypeRef ofPartTypeRef = null;
Result<TypeRef> result = typeInternal(G2_1, _trace_, _expression_2);
checkAssignableTo(result.getFirst(), TypeRef.class);
ofPartTypeRef = (TypeRef) result.getFirst();
final TypeArgument elemType = this.destructureHelper.extractIterableElementType(G2_1, ofPartTypeRef);
/* elemType!==null */
if (!(elemType != null)) {
sneakyThrowRuleFailedException("elemType!==null");
}
/* G2 |~ elemType /\ T */
Result<TypeRef> result_1 = upperBoundInternal(G2_1, _trace_, elemType);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
T = (TypeRef) result_1.getFirst();
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
}
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
} else {
if (((vdecl.eContainer() instanceof ForStatement) && ((ForStatement) vdecl.eContainer()).isForIn())) {
T = RuleEnvironmentExtensions.stringTypeRef(G);
} else {
Expression _expression_3 = vdecl.getExpression();
boolean _tripleNotEquals_1 = (_expression_3 != null);
if (_tripleNotEquals_1) {
Expression _expression_4 = vdecl.getExpression();
Pair<String, Expression> _mappedTo_4 = Pair.<String, Expression>of(RuleEnvironmentExtensions.GUARD_VARIABLE_DECLARATION, _expression_4);
Object _get_2 = G.get(_mappedTo_4);
boolean _tripleEquals_2 = (_get_2 == null);
if (_tripleEquals_2) {
final RuleEnvironment G2_2 = RuleEnvironmentExtensions.wrap(G);
Expression _expression_5 = vdecl.getExpression();
Pair<String, Expression> _mappedTo_5 = Pair.<String, Expression>of(RuleEnvironmentExtensions.GUARD_VARIABLE_DECLARATION, _expression_5);
boolean _add_2 = G2_2.add(_mappedTo_5, Boolean.TRUE);
/* G2.add(GUARD_VARIABLE_DECLARATION->vdecl.expression,Boolean.TRUE) */
if (!_add_2) {
sneakyThrowRuleFailedException("G2.add(GUARD_VARIABLE_DECLARATION->vdecl.expression,Boolean.TRUE)");
}
/* G2 |- vdecl.expression: var TypeRef E */
Expression _expression_6 = vdecl.getExpression();
TypeRef E = null;
Result<TypeRef> result_2 = typeInternal(G2_2, _trace_, _expression_6);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
E = (TypeRef) result_2.getFirst();
if (((E instanceof BoundThisTypeRef) || ((E instanceof TypeTypeRef) && (((TypeTypeRef) E).getTypeArg() instanceof BoundThisTypeRef)))) {
} else {
/* G2 |~ E /\ E */
Result<TypeRef> result_3 = upperBoundInternal(G2_2, _trace_, E);
checkAssignableTo(result_3.getFirst(), TypeRef.class);
E = (TypeRef) result_3.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);
}
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
}
}
}
}
boolean _enforceDynamicTypes = this.jsVariantHelper.enforceDynamicTypes(vdecl);
if (_enforceDynamicTypes) {
T = this.typeSystemHelper.makeDynamic(T);
}
return new Result<TypeRef>(T);
}
Aggregations