use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleThisTypeRefEObject.
protected Result<TypeRef> applyRuleThisTypeRefEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EObject location) throws RuleFailedException {
// output parameter
TypeRef T = null;
final FunctionOrFieldAccessor containingFunctionOrAccessor = N4JSASTUtils.getContainingFunctionOrAccessor(location);
boolean _matched = false;
if (containingFunctionOrAccessor instanceof ArrowFunction) {
_matched = true;
/* G |~ containingFunctionOrAccessor ~> T */
Result<TypeRef> result = thisTypeRefInternal(G, _trace_, ((ArrowFunction) containingFunctionOrAccessor));
checkAssignableTo(result.getFirst(), TypeRef.class);
T = (TypeRef) result.getFirst();
}
if (!_matched) {
IdentifiableElement _definedFunctionOrAccessor = null;
if (containingFunctionOrAccessor != null) {
_definedFunctionOrAccessor = containingFunctionOrAccessor.getDefinedFunctionOrAccessor();
}
final IdentifiableElement containingTFunctionOrAccessor = _definedFunctionOrAccessor;
final TypeRef declaredThisType = TypeSystemHelper.declaredThisType(containingTFunctionOrAccessor);
if ((declaredThisType != null)) {
if ((declaredThisType instanceof ParameterizedTypeRef)) {
/* G |~ declaredThisType ~> T */
Result<TypeRef> result = thisTypeRefInternal(G, _trace_, ((ParameterizedTypeRef) declaredThisType));
checkAssignableTo(result.getFirst(), TypeRef.class);
T = (TypeRef) result.getFirst();
} else {
T = declaredThisType;
}
} else {
final ThisTarget thisTarget = N4JSASTUtils.getProbableThisTarget(location);
boolean _matched_1 = false;
if (thisTarget instanceof ObjectLiteral) {
_matched_1 = true;
/* G |- thisTarget: T */
Result<TypeRef> result_1 = typeInternal(G, _trace_, ((ObjectLiteral) thisTarget));
checkAssignableTo(result_1.getFirst(), TypeRef.class);
T = (TypeRef) result_1.getFirst();
}
if (!_matched_1) {
if (thisTarget instanceof N4ClassifierDefinition) {
_matched_1 = true;
Type thisTargetDEFTYPE = ((N4ClassifierDefinition) thisTarget).getDefinedType();
if ((thisTarget instanceof N4ClassDeclaration)) {
final TClass clazz = ((N4ClassDeclaration) thisTarget).getDefinedTypeAsClass();
if (((clazz != null) && clazz.isStaticPolyfill())) {
final Type actualClazz = clazz.getSuperClassRef().getDeclaredType();
if ((actualClazz != null)) {
thisTargetDEFTYPE = actualClazz;
}
}
}
if ((thisTargetDEFTYPE != null)) {
final FunctionDefinition containingFunction = N4JSASTUtils.getContainingFunction(location);
if (((containingFunction instanceof N4MethodDeclaration) && ((N4MemberDeclaration) containingFunction).isStatic())) {
boolean _isInReturnDeclaration_Of_StaticMethod = RuleEnvironmentExtensions.isInReturnDeclaration_Of_StaticMethod(location, ((N4MethodDeclaration) containingFunction));
if (_isInReturnDeclaration_Of_StaticMethod) {
/* G |~ thisTargetDEFTYPE.ref ~> T */
TypeRef _ref = TypeExtensions.ref(thisTargetDEFTYPE);
Result<TypeRef> result_1 = thisTypeRefInternal(G, _trace_, _ref);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
T = (TypeRef) result_1.getFirst();
} else {
boolean _isInBody_Of_StaticMethod = RuleEnvironmentExtensions.isInBody_Of_StaticMethod(location, ((N4MethodDeclaration) containingFunction));
if (_isInBody_Of_StaticMethod) {
T = TypeUtils.createClassifierBoundThisTypeRef(TypeUtils.createTypeTypeRef(TypeExtensions.ref(thisTargetDEFTYPE), false));
} else {
T = TypeUtils.createConstructorTypeRef(thisTargetDEFTYPE);
}
}
} else {
final N4FieldDeclaration n4Field = EcoreUtil2.<N4FieldDeclaration>getContainerOfType(location, N4FieldDeclaration.class);
if (((n4Field != null) && n4Field.isStatic())) {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
} else {
final N4GetterDeclaration n4Getter = EcoreUtil2.<N4GetterDeclaration>getContainerOfType(location, N4GetterDeclaration.class);
if (((n4Getter != null) && n4Getter.isStatic())) {
T = TypeUtils.createConstructorTypeRef(thisTargetDEFTYPE);
} else {
final N4SetterDeclaration n4Setter = EcoreUtil2.<N4SetterDeclaration>getContainerOfType(location, N4SetterDeclaration.class);
if (((n4Setter != null) && n4Setter.isStatic())) {
T = TypeUtils.createConstructorTypeRef(thisTargetDEFTYPE);
} else {
/* G |~ thisTargetDEFTYPE.ref ~> T */
TypeRef _ref_1 = TypeExtensions.ref(thisTargetDEFTYPE);
Result<TypeRef> result_2 = thisTypeRefInternal(G, _trace_, _ref_1);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
T = (TypeRef) result_2.getFirst();
}
}
}
}
} else {
T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
}
}
}
if (!_matched_1) {
boolean _hasGlobalObject = this.jsVariantHelper.hasGlobalObject(location);
if (_hasGlobalObject) {
T = RuleEnvironmentExtensions.globalObjectTypeRef(G);
} else {
T = RuleEnvironmentExtensions.undefinedTypeRef(G);
}
}
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeTGetter.
protected Result<TypeRef> applyRuleTypeTGetter(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TGetter tgetter) throws RuleFailedException {
// output parameter
TypeRef T = null;
TypeRef _elvis = null;
TypeRef _declaredTypeRef = tgetter.getDeclaredTypeRef();
if (_declaredTypeRef != null) {
_elvis = _declaredTypeRef;
} else {
ParameterizedTypeRef _anyTypeRef = RuleEnvironmentExtensions.anyTypeRef(G);
_elvis = _anyTypeRef;
}
T = _elvis;
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleSubtypeExistentialTypeRef_Right.
protected Result<Boolean> applyRuleSubtypeExistentialTypeRef_Right(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeRef left, final ExistentialTypeRef existentialTypeRef) throws RuleFailedException {
boolean _isExistentialTypeToBeReopened = RuleEnvironmentExtensions.isExistentialTypeToBeReopened(G, existentialTypeRef);
if (_isExistentialTypeToBeReopened) {
final Wildcard wildThing = existentialTypeRef.getWildcard();
/* G |~ wildThing /\ var TypeRef upperBound */
TypeRef upperBound = null;
Result<TypeRef> result = upperBoundInternal(G, _trace_, wildThing);
checkAssignableTo(result.getFirst(), TypeRef.class);
upperBound = (TypeRef) result.getFirst();
/* G |~ wildThing \/ var TypeRef lowerBound */
TypeRef lowerBound = null;
Result<TypeRef> result_1 = lowerBoundInternal(G, _trace_, wildThing);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
lowerBound = (TypeRef) result_1.getFirst();
/* G |- left <: upperBound */
subtypeInternal(G, _trace_, left, upperBound);
/* G |- lowerBound <: left */
subtypeInternal(G, _trace_, lowerBound, left);
} else {
/* left===existentialTypeRef or { left instanceof ParameterizedTypeRef && (left as ParameterizedTypeRef).declaredType instanceof NullType } or { G |~ existentialTypeRef \/ var TypeRef lowerExt G |- left <: lowerExt } */
{
RuleFailedException previousFailure = null;
try {
/* left===existentialTypeRef */
if (!(left == existentialTypeRef)) {
sneakyThrowRuleFailedException("left===existentialTypeRef");
}
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { left instanceof ParameterizedTypeRef && (left as ParameterizedTypeRef).declaredType instanceof NullType } or { G |~ existentialTypeRef \/ var TypeRef lowerExt G |- left <: lowerExt } */
{
try {
/* left instanceof ParameterizedTypeRef && (left as ParameterizedTypeRef).declaredType instanceof NullType */
if (!((left instanceof ParameterizedTypeRef) && (((ParameterizedTypeRef) left).getDeclaredType() instanceof NullType))) {
sneakyThrowRuleFailedException("left instanceof ParameterizedTypeRef && (left as ParameterizedTypeRef).declaredType instanceof NullType");
}
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
/* G |~ existentialTypeRef \/ var TypeRef lowerExt */
TypeRef lowerExt = null;
Result<TypeRef> result_2 = lowerBoundInternal(G, _trace_, existentialTypeRef);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
lowerExt = (TypeRef) result_2.getFirst();
/* G |- left <: lowerExt */
subtypeInternal(G, _trace_, left, lowerExt);
}
}
}
}
}
return new Result<Boolean>(true);
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleSubtypeTypeRefBoundThisTypeRef.
protected Result<Boolean> applyRuleSubtypeTypeRefBoundThisTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeRef left, final BoundThisTypeRef boundThisTypeRef) throws RuleFailedException {
/* left===boundThisTypeRef or { val leftType = left.declaredType leftType===G.undefinedType || leftType===G.nullType } or { if (boundThisTypeRef.isUseSiteStructuralTyping || (null !== boundThisTypeRef.actualThisTypeRef && null !== boundThisTypeRef.actualThisTypeRef.declaredType && boundThisTypeRef.actualThisTypeRef.declaredType.final)) { val resolvedTypeRef = TypeUtils.createResolvedThisTypeRef(boundThisTypeRef); G |- left <: resolvedTypeRef } else { fail } } */
{
RuleFailedException previousFailure = null;
try {
/* left===boundThisTypeRef */
if (!(left == boundThisTypeRef)) {
sneakyThrowRuleFailedException("left===boundThisTypeRef");
}
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { val leftType = left.declaredType leftType===G.undefinedType || leftType===G.nullType } or { if (boundThisTypeRef.isUseSiteStructuralTyping || (null !== boundThisTypeRef.actualThisTypeRef && null !== boundThisTypeRef.actualThisTypeRef.declaredType && boundThisTypeRef.actualThisTypeRef.declaredType.final)) { val resolvedTypeRef = TypeUtils.createResolvedThisTypeRef(boundThisTypeRef); G |- left <: resolvedTypeRef } else { fail } } */
{
try {
final Type leftType = left.getDeclaredType();
/* leftType===G.undefinedType || leftType===G.nullType */
if (!((leftType == RuleEnvironmentExtensions.undefinedType(G)) || (leftType == RuleEnvironmentExtensions.nullType(G)))) {
sneakyThrowRuleFailedException("leftType===G.undefinedType || leftType===G.nullType");
}
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
if ((boundThisTypeRef.isUseSiteStructuralTyping() || (((null != boundThisTypeRef.getActualThisTypeRef()) && (null != boundThisTypeRef.getActualThisTypeRef().getDeclaredType())) && boundThisTypeRef.getActualThisTypeRef().getDeclaredType().isFinal()))) {
final ParameterizedTypeRef resolvedTypeRef = TypeUtils.createResolvedThisTypeRef(boundThisTypeRef);
/* G |- left <: resolvedTypeRef */
subtypeInternal(G, _trace_, left, resolvedTypeRef);
} else {
/* fail */
throwForExplicitFail();
}
}
}
}
}
return new Result<Boolean>(true);
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef 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);
}
Aggregations