Search in sources :

Example 6 with SuperLiteral

use of org.eclipse.n4js.n4JS.SuperLiteral in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeIndexedAccessExpression.

protected Result<TypeRef> applyRuleTypeIndexedAccessExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final IndexedAccessExpression expr) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    /* { expr.target === null || expr.index === null; T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } or { expr.target instanceof SuperLiteral T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } or { G |- expr.target : var TypeRef targetTypeRef targetTypeRef = typeSystemHelper.resolveType(G, targetTypeRef); G |- expr.index : var TypeRef indexTypeRef; val targetDeclType = targetTypeRef.declaredType; val targetIsLiteralOfStringBasedEnum = targetDeclType instanceof TEnum && AnnotationDefinition.STRING_BASED.hasAnnotation(targetDeclType); val indexIsNumeric = { G |- indexTypeRef <: G.numberTypeRef }; val indexValue = ASTMetaInfoUtils.getCompileTimeValue(expr.index); val memberName = N4JSLanguageUtils.derivePropertyNameFromCompileTimeValue(indexValue); if (indexIsNumeric && (targetTypeRef.isArrayLike || targetIsLiteralOfStringBasedEnum)) { if (targetDeclType.generic && targetTypeRef.typeArgs.isEmpty) { T = G.anyTypeRef } else { val G2 = G.wrap typeSystemHelper.addSubstitutions(G2, targetTypeRef) G2.addThisType(targetTypeRef) val elementTypeRef = if(targetIsLiteralOfStringBasedEnum) { G.stringType.elementType } else { targetDeclType.elementType }; G2 |- elementTypeRef ~> T } } else if (memberName!==null) { val staticAccess = (targetTypeRef instanceof TypeTypeRef) val checkVisibility = false val scope = memberScopingHelper.createMemberScope(targetTypeRef, expr, checkVisibility, staticAccess) val memberDesc = if(memberName!==null && !memberName.isEmpty()) { scope.getSingleElement(qualifiedNameConverter.toQualifiedName(memberName)) }; val member = if(memberDesc!==null && !IEObjectDescriptionWithError.isErrorDescription(memberDesc)) { memberDesc.getEObjectOrProxy() }; if(member instanceof TMember && !member.eIsProxy) { G |- (member as TMember) : var TypeRef memberTypeRef val G2 = G.wrap typeSystemHelper.addSubstitutions(G2,targetTypeRef) G2.addThisType(targetTypeRef) G2 |- memberTypeRef ~> T } else if (targetTypeRef.dynamic) { T = G.anyTypeRefDynamic } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } else if (targetTypeRef.dynamic) { T = G.anyTypeRefDynamic } else { T = G.anyTypeRef } } */
    {
        RuleFailedException previousFailure = null;
        try {
            /* expr.target === null || expr.index === null */
            if (!((expr.getTarget() == null) || (expr.getIndex() == null))) {
                sneakyThrowRuleFailedException("expr.target === null || expr.index === null");
            }
            T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
        } catch (Exception e) {
            previousFailure = extractRuleFailedException(e);
            /* { expr.target instanceof SuperLiteral T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } or { G |- expr.target : var TypeRef targetTypeRef targetTypeRef = typeSystemHelper.resolveType(G, targetTypeRef); G |- expr.index : var TypeRef indexTypeRef; val targetDeclType = targetTypeRef.declaredType; val targetIsLiteralOfStringBasedEnum = targetDeclType instanceof TEnum && AnnotationDefinition.STRING_BASED.hasAnnotation(targetDeclType); val indexIsNumeric = { G |- indexTypeRef <: G.numberTypeRef }; val indexValue = ASTMetaInfoUtils.getCompileTimeValue(expr.index); val memberName = N4JSLanguageUtils.derivePropertyNameFromCompileTimeValue(indexValue); if (indexIsNumeric && (targetTypeRef.isArrayLike || targetIsLiteralOfStringBasedEnum)) { if (targetDeclType.generic && targetTypeRef.typeArgs.isEmpty) { T = G.anyTypeRef } else { val G2 = G.wrap typeSystemHelper.addSubstitutions(G2, targetTypeRef) G2.addThisType(targetTypeRef) val elementTypeRef = if(targetIsLiteralOfStringBasedEnum) { G.stringType.elementType } else { targetDeclType.elementType }; G2 |- elementTypeRef ~> T } } else if (memberName!==null) { val staticAccess = (targetTypeRef instanceof TypeTypeRef) val checkVisibility = false val scope = memberScopingHelper.createMemberScope(targetTypeRef, expr, checkVisibility, staticAccess) val memberDesc = if(memberName!==null && !memberName.isEmpty()) { scope.getSingleElement(qualifiedNameConverter.toQualifiedName(memberName)) }; val member = if(memberDesc!==null && !IEObjectDescriptionWithError.isErrorDescription(memberDesc)) { memberDesc.getEObjectOrProxy() }; if(member instanceof TMember && !member.eIsProxy) { G |- (member as TMember) : var TypeRef memberTypeRef val G2 = G.wrap typeSystemHelper.addSubstitutions(G2,targetTypeRef) G2.addThisType(targetTypeRef) G2 |- memberTypeRef ~> T } else if (targetTypeRef.dynamic) { T = G.anyTypeRefDynamic } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } else if (targetTypeRef.dynamic) { T = G.anyTypeRefDynamic } else { T = G.anyTypeRef } } */
            {
                try {
                    Expression _target = expr.getTarget();
                    /* expr.target instanceof SuperLiteral */
                    if (!(_target instanceof SuperLiteral)) {
                        sneakyThrowRuleFailedException("expr.target instanceof SuperLiteral");
                    }
                    T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
                } catch (Exception e_1) {
                    previousFailure = extractRuleFailedException(e_1);
                    /* G |- expr.target : var TypeRef targetTypeRef */
                    Expression _target_1 = expr.getTarget();
                    TypeRef targetTypeRef = null;
                    Result<TypeRef> result = typeInternal(G, _trace_, _target_1);
                    checkAssignableTo(result.getFirst(), TypeRef.class);
                    targetTypeRef = (TypeRef) result.getFirst();
                    targetTypeRef = this.typeSystemHelper.resolveType(G, targetTypeRef);
                    /* G |- expr.index : var TypeRef indexTypeRef */
                    Expression _index = expr.getIndex();
                    TypeRef indexTypeRef = null;
                    Result<TypeRef> result_1 = typeInternal(G, _trace_, _index);
                    checkAssignableTo(result_1.getFirst(), TypeRef.class);
                    indexTypeRef = (TypeRef) result_1.getFirst();
                    final Type targetDeclType = targetTypeRef.getDeclaredType();
                    final boolean targetIsLiteralOfStringBasedEnum = ((targetDeclType instanceof TEnum) && AnnotationDefinition.STRING_BASED.hasAnnotation(targetDeclType));
                    /* G |- indexTypeRef <: G.numberTypeRef */
                    ParameterizedTypeRef _numberTypeRef = RuleEnvironmentExtensions.numberTypeRef(G);
                    boolean _ruleinvocation = subtypeSucceeded(G, _trace_, indexTypeRef, _numberTypeRef);
                    final boolean indexIsNumeric = _ruleinvocation;
                    final CompileTimeValue indexValue = ASTMetaInfoUtils.getCompileTimeValue(expr.getIndex());
                    final String memberName = N4JSLanguageUtils.derivePropertyNameFromCompileTimeValue(indexValue);
                    if ((indexIsNumeric && (targetTypeRef.isArrayLike() || targetIsLiteralOfStringBasedEnum))) {
                        if ((targetDeclType.isGeneric() && targetTypeRef.getTypeArgs().isEmpty())) {
                            T = RuleEnvironmentExtensions.anyTypeRef(G);
                        } else {
                            final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
                            this.typeSystemHelper.addSubstitutions(G2, targetTypeRef);
                            RuleEnvironmentExtensions.addThisType(G2, targetTypeRef);
                            TypeRef _xifexpression = null;
                            if (targetIsLiteralOfStringBasedEnum) {
                                _xifexpression = RuleEnvironmentExtensions.stringType(G).getElementType();
                            } else {
                                _xifexpression = targetDeclType.getElementType();
                            }
                            final TypeRef elementTypeRef = _xifexpression;
                            /* G2 |- elementTypeRef ~> T */
                            Result<TypeArgument> result_2 = substTypeVariablesInternal(G2, _trace_, elementTypeRef);
                            checkAssignableTo(result_2.getFirst(), TypeRef.class);
                            T = (TypeRef) result_2.getFirst();
                        }
                    } else {
                        if ((memberName != null)) {
                            final boolean staticAccess = (targetTypeRef instanceof TypeTypeRef);
                            final boolean checkVisibility = false;
                            final IScope scope = this.memberScopingHelper.createMemberScope(targetTypeRef, expr, checkVisibility, staticAccess);
                            IEObjectDescription _xifexpression_1 = null;
                            if (((memberName != null) && (!memberName.isEmpty()))) {
                                _xifexpression_1 = scope.getSingleElement(this.qualifiedNameConverter.toQualifiedName(memberName));
                            }
                            final IEObjectDescription memberDesc = _xifexpression_1;
                            EObject _xifexpression_2 = null;
                            if (((memberDesc != null) && (!IEObjectDescriptionWithError.isErrorDescription(memberDesc)))) {
                                _xifexpression_2 = memberDesc.getEObjectOrProxy();
                            }
                            final EObject member = _xifexpression_2;
                            if (((member instanceof TMember) && (!member.eIsProxy()))) {
                                /* G |- (member as TMember) : var TypeRef memberTypeRef */
                                TypeRef memberTypeRef = null;
                                Result<TypeRef> result_3 = typeInternal(G, _trace_, ((TMember) member));
                                checkAssignableTo(result_3.getFirst(), TypeRef.class);
                                memberTypeRef = (TypeRef) result_3.getFirst();
                                final RuleEnvironment G2_1 = RuleEnvironmentExtensions.wrap(G);
                                this.typeSystemHelper.addSubstitutions(G2_1, targetTypeRef);
                                RuleEnvironmentExtensions.addThisType(G2_1, targetTypeRef);
                                /* G2 |- memberTypeRef ~> T */
                                Result<TypeArgument> result_4 = substTypeVariablesInternal(G2_1, _trace_, memberTypeRef);
                                checkAssignableTo(result_4.getFirst(), TypeRef.class);
                                T = (TypeRef) result_4.getFirst();
                            } else {
                                boolean _isDynamic = targetTypeRef.isDynamic();
                                if (_isDynamic) {
                                    T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
                                } else {
                                    T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
                                }
                            }
                        } else {
                            boolean _isDynamic_1 = targetTypeRef.isDynamic();
                            if (_isDynamic_1) {
                                T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
                            } else {
                                T = RuleEnvironmentExtensions.anyTypeRef(G);
                            }
                        }
                    }
                }
            }
        }
    }
    return new Result<TypeRef>(T);
}
Also used : ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) SuperLiteral(org.eclipse.n4js.n4JS.SuperLiteral) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) TaggedTemplateString(org.eclipse.n4js.n4JS.TaggedTemplateString) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) CompileTimeValue(org.eclipse.n4js.compileTime.CompileTimeValue) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) BinaryBitwiseExpression(org.eclipse.n4js.n4JS.BinaryBitwiseExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) UnionTypeExpression(org.eclipse.n4js.ts.typeRefs.UnionTypeExpression) FunctionExpression(org.eclipse.n4js.n4JS.FunctionExpression) PromisifyExpression(org.eclipse.n4js.n4JS.PromisifyExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) AdditiveExpression(org.eclipse.n4js.n4JS.AdditiveExpression) PostfixExpression(org.eclipse.n4js.n4JS.PostfixExpression) YieldExpression(org.eclipse.n4js.n4JS.YieldExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) NewExpression(org.eclipse.n4js.n4JS.NewExpression) IntersectionTypeExpression(org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression) AwaitExpression(org.eclipse.n4js.n4JS.AwaitExpression) CommaExpression(org.eclipse.n4js.n4JS.CommaExpression) Expression(org.eclipse.n4js.n4JS.Expression) CastExpression(org.eclipse.n4js.n4JS.CastExpression) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ShiftExpression(org.eclipse.n4js.n4JS.ShiftExpression) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) MultiplicativeExpression(org.eclipse.n4js.n4JS.MultiplicativeExpression) N4ClassExpression(org.eclipse.n4js.n4JS.N4ClassExpression) TEnum(org.eclipse.n4js.ts.types.TEnum) EObject(org.eclipse.emf.ecore.EObject) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) IScope(org.eclipse.xtext.scoping.IScope) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) TMember(org.eclipse.n4js.ts.types.TMember)

Example 7 with SuperLiteral

use of org.eclipse.n4js.n4JS.SuperLiteral in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeCallExpression.

protected Result<TypeRef> applyRuleTypeCallExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedCallExpression expr) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    /* G |- expr.target : var TypeRef targetTypeRef */
    Expression _target = expr.getTarget();
    TypeRef targetTypeRef = null;
    Result<TypeRef> result = typeInternal(G, _trace_, _target);
    checkAssignableTo(result.getFirst(), TypeRef.class);
    targetTypeRef = (TypeRef) result.getFirst();
    if ((targetTypeRef instanceof FunctionTypeExprOrRef)) {
        final FunctionTypeExprOrRef F = ((FunctionTypeExprOrRef) targetTypeRef);
        final TFunction tFunction = F.getFunctionType();
        /* { val inferring = env(G, GUARD_TYPE_CALL_EXPRESSION -> expr, TypeRef) G |- inferring ~> T } or { val G2 = G.wrap; G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef) if(expr.eContainer instanceof AwaitExpression && expr.eContainmentFeature === N4JSPackage.eINSTANCE.getAwaitExpression_Expression() && tFunction!==null && AnnotationDefinition.PROMISIFIABLE.hasAnnotation(tFunction)) { T = promisifyHelper.extractPromisifiedReturnType(expr); } else { T = F.returnTypeRef ?: G.anyTypeRef; } typeSystemHelper.addSubstitutions(G2, expr, targetTypeRef); G2 |- T ~> T T = versionResolver.resolveVersion(T, F); if (T instanceof BoundThisTypeRef && !(expr.receiver instanceof ThisLiteral || expr.receiver instanceof SuperLiteral)) { G2 |~ T /\ T } } */
        {
            RuleFailedException previousFailure = null;
            try {
                Pair<String, ParameterizedCallExpression> _mappedTo = Pair.<String, ParameterizedCallExpression>of(RuleEnvironmentExtensions.GUARD_TYPE_CALL_EXPRESSION, expr);
                final TypeRef inferring = this.<TypeRef>env(G, _mappedTo, TypeRef.class);
                /* G |- inferring ~> T */
                Result<TypeArgument> result_1 = substTypeVariablesInternal(G, _trace_, inferring);
                checkAssignableTo(result_1.getFirst(), TypeRef.class);
                T = (TypeRef) result_1.getFirst();
            } catch (Exception e) {
                previousFailure = extractRuleFailedException(e);
                final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
                Pair<String, ParameterizedCallExpression> _mappedTo_1 = Pair.<String, ParameterizedCallExpression>of(RuleEnvironmentExtensions.GUARD_TYPE_CALL_EXPRESSION, expr);
                boolean _add = G2.add(_mappedTo_1, F.getReturnTypeRef());
                /* G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef) */
                if (!_add) {
                    sneakyThrowRuleFailedException("G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef)");
                }
                if (((((expr.eContainer() instanceof AwaitExpression) && (expr.eContainmentFeature() == N4JSPackage.eINSTANCE.getAwaitExpression_Expression())) && (tFunction != null)) && AnnotationDefinition.PROMISIFIABLE.hasAnnotation(tFunction))) {
                    T = this.promisifyHelper.extractPromisifiedReturnType(expr);
                } else {
                    TypeRef _elvis = null;
                    TypeRef _returnTypeRef = F.getReturnTypeRef();
                    if (_returnTypeRef != null) {
                        _elvis = _returnTypeRef;
                    } else {
                        ParameterizedTypeRef _anyTypeRef = RuleEnvironmentExtensions.anyTypeRef(G);
                        _elvis = _anyTypeRef;
                    }
                    T = _elvis;
                }
                this.typeSystemHelper.addSubstitutions(G2, expr, targetTypeRef);
                /* G2 |- T ~> T */
                Result<TypeArgument> result_2 = substTypeVariablesInternal(G2, _trace_, T);
                checkAssignableTo(result_2.getFirst(), TypeRef.class);
                T = (TypeRef) result_2.getFirst();
                T = this.versionResolver.<TypeRef, FunctionTypeExprOrRef>resolveVersion(T, F);
                if (((T instanceof BoundThisTypeRef) && (!((expr.getReceiver() instanceof ThisLiteral) || (expr.getReceiver() instanceof SuperLiteral))))) {
                    /* G2 |~ T /\ T */
                    Result<TypeRef> result_3 = upperBoundInternal(G2, _trace_, T);
                    checkAssignableTo(result_3.getFirst(), TypeRef.class);
                    T = (TypeRef) result_3.getFirst();
                }
            }
        }
    } else {
        Type _declaredType = null;
        if (targetTypeRef != null) {
            _declaredType = targetTypeRef.getDeclaredType();
        }
        TObjectPrototype _functionType = RuleEnvironmentExtensions.functionType(G);
        boolean _tripleEquals = (_declaredType == _functionType);
        if (_tripleEquals) {
            T = RuleEnvironmentExtensions.anyTypeRef(G);
        } else {
            boolean _isDynamic = targetTypeRef.isDynamic();
            if (_isDynamic) {
                T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
            } else {
                T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
            }
        }
    }
    return new Result<TypeRef>(T);
}
Also used : ThisLiteral(org.eclipse.n4js.n4JS.ThisLiteral) TObjectPrototype(org.eclipse.n4js.ts.types.TObjectPrototype) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) SuperLiteral(org.eclipse.n4js.n4JS.SuperLiteral) TaggedTemplateString(org.eclipse.n4js.n4JS.TaggedTemplateString) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) AwaitExpression(org.eclipse.n4js.n4JS.AwaitExpression) TFunction(org.eclipse.n4js.ts.types.TFunction) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) BinaryBitwiseExpression(org.eclipse.n4js.n4JS.BinaryBitwiseExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) UnionTypeExpression(org.eclipse.n4js.ts.typeRefs.UnionTypeExpression) FunctionExpression(org.eclipse.n4js.n4JS.FunctionExpression) PromisifyExpression(org.eclipse.n4js.n4JS.PromisifyExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) AdditiveExpression(org.eclipse.n4js.n4JS.AdditiveExpression) PostfixExpression(org.eclipse.n4js.n4JS.PostfixExpression) YieldExpression(org.eclipse.n4js.n4JS.YieldExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) NewExpression(org.eclipse.n4js.n4JS.NewExpression) IntersectionTypeExpression(org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression) AwaitExpression(org.eclipse.n4js.n4JS.AwaitExpression) CommaExpression(org.eclipse.n4js.n4JS.CommaExpression) Expression(org.eclipse.n4js.n4JS.Expression) CastExpression(org.eclipse.n4js.n4JS.CastExpression) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ShiftExpression(org.eclipse.n4js.n4JS.ShiftExpression) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) MultiplicativeExpression(org.eclipse.n4js.n4JS.MultiplicativeExpression) N4ClassExpression(org.eclipse.n4js.n4JS.N4ClassExpression) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) FunctionTypeExprOrRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeExprOrRef) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) Pair(org.eclipse.xtext.xbase.lib.Pair) PropertyNameValuePair(org.eclipse.n4js.n4JS.PropertyNameValuePair)

Example 8 with SuperLiteral

use of org.eclipse.n4js.n4JS.SuperLiteral 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);
}
Also used : ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) TClassifier(org.eclipse.n4js.ts.types.TClassifier) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) SuperLiteral(org.eclipse.n4js.n4JS.SuperLiteral) TaggedTemplateString(org.eclipse.n4js.n4JS.TaggedTemplateString) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) N4ClassDeclaration(org.eclipse.n4js.n4JS.N4ClassDeclaration) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) Wildcard(org.eclipse.n4js.ts.typeRefs.Wildcard) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) Pair(org.eclipse.xtext.xbase.lib.Pair) PropertyNameValuePair(org.eclipse.n4js.n4JS.PropertyNameValuePair) ThisLiteral(org.eclipse.n4js.n4JS.ThisLiteral) TMethod(org.eclipse.n4js.ts.types.TMethod) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) BinaryBitwiseExpression(org.eclipse.n4js.n4JS.BinaryBitwiseExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) UnionTypeExpression(org.eclipse.n4js.ts.typeRefs.UnionTypeExpression) FunctionExpression(org.eclipse.n4js.n4JS.FunctionExpression) PromisifyExpression(org.eclipse.n4js.n4JS.PromisifyExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) AdditiveExpression(org.eclipse.n4js.n4JS.AdditiveExpression) PostfixExpression(org.eclipse.n4js.n4JS.PostfixExpression) YieldExpression(org.eclipse.n4js.n4JS.YieldExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) NewExpression(org.eclipse.n4js.n4JS.NewExpression) IntersectionTypeExpression(org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression) AwaitExpression(org.eclipse.n4js.n4JS.AwaitExpression) CommaExpression(org.eclipse.n4js.n4JS.CommaExpression) Expression(org.eclipse.n4js.n4JS.Expression) CastExpression(org.eclipse.n4js.n4JS.CastExpression) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ShiftExpression(org.eclipse.n4js.n4JS.ShiftExpression) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) MultiplicativeExpression(org.eclipse.n4js.n4JS.MultiplicativeExpression) N4ClassExpression(org.eclipse.n4js.n4JS.N4ClassExpression) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) FunctionTypeExprOrRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeExprOrRef) TClass(org.eclipse.n4js.ts.types.TClass)

Aggregations

ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)8 SuperLiteral (org.eclipse.n4js.n4JS.SuperLiteral)8 Expression (org.eclipse.n4js.n4JS.Expression)7 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)5 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)5 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)5 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)5 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)5 CastExpression (org.eclipse.n4js.n4JS.CastExpression)5 CommaExpression (org.eclipse.n4js.n4JS.CommaExpression)5 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)5 EqualityExpression (org.eclipse.n4js.n4JS.EqualityExpression)5 FunctionExpression (org.eclipse.n4js.n4JS.FunctionExpression)5 IndexedAccessExpression (org.eclipse.n4js.n4JS.IndexedAccessExpression)5 MultiplicativeExpression (org.eclipse.n4js.n4JS.MultiplicativeExpression)5 N4ClassExpression (org.eclipse.n4js.n4JS.N4ClassExpression)5 NewExpression (org.eclipse.n4js.n4JS.NewExpression)5 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)5 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)5 PostfixExpression (org.eclipse.n4js.n4JS.PostfixExpression)5