Search in sources :

Example 21 with Result

use of org.eclipse.xsemantics.runtime.Result in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeUnaryExpression.

protected Result<TypeRef> applyRuleTypeUnaryExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final UnaryExpression e) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    if ((((e.getOp() == UnaryOperator.NEG) || (e.getOp() == UnaryOperator.POS)) && (e.getExpression() instanceof IntLiteral))) {
        /* G |- e.expression : T */
        Expression _expression = e.getExpression();
        Result<TypeRef> result = typeInternal(G, _trace_, _expression);
        checkAssignableTo(result.getFirst(), TypeRef.class);
        T = (TypeRef) result.getFirst();
    } else {
        UnaryOperator _op = e.getOp();
        if (_op != null) {
            switch(_op) {
                case DELETE:
                    T = RuleEnvironmentExtensions.booleanTypeRef(G);
                    break;
                case VOID:
                    T = RuleEnvironmentExtensions.undefinedTypeRef(G);
                    break;
                case TYPEOF:
                    T = RuleEnvironmentExtensions.stringTypeRef(G);
                    break;
                case NOT:
                    T = RuleEnvironmentExtensions.booleanTypeRef(G);
                    break;
                default:
                    T = RuleEnvironmentExtensions.numberTypeRef(G);
                    break;
            }
        } else {
            T = RuleEnvironmentExtensions.numberTypeRef(G);
        }
    }
    return new Result<TypeRef>(T);
}
Also used : 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) 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) IntLiteral(org.eclipse.n4js.n4JS.IntLiteral) UnaryOperator(org.eclipse.n4js.n4JS.UnaryOperator) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 22 with Result

use of org.eclipse.xsemantics.runtime.Result 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);
}
Also used : TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) 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) 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) ThisTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ThisTypeRefStructural) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 23 with Result

use of org.eclipse.xsemantics.runtime.Result 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);
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) 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) 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) AssignmentOperator(org.eclipse.n4js.n4JS.AssignmentOperator) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 24 with Result

use of org.eclipse.xsemantics.runtime.Result in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeIdentifierRef.

protected Result<TypeRef> applyRuleTypeIdentifierRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final IdentifierRef idref) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    /* G |- idref.id : T */
    IdentifiableElement _id = idref.getId();
    Result<TypeRef> result = typeInternal(G, _trace_, _id);
    checkAssignableTo(result.getFirst(), TypeRef.class);
    T = (TypeRef) result.getFirst();
    T = this.versionResolver.<TypeRef, IdentifierRef>resolveVersion(T, idref);
    if (((idref.eContainer() instanceof ParameterizedCallExpression) && (idref.eContainmentFeature() == N4JSPackage.eINSTANCE.getParameterizedCallExpression_Target()))) {
        final TMethod callableCtorFunction = this.typeSystemHelper.getCallableClassConstructorFunction(G, T);
        if ((callableCtorFunction != null)) {
            T = TypeExtensions.ref(callableCtorFunction);
        }
    }
    return new Result<TypeRef>(T);
}
Also used : TMethod(org.eclipse.n4js.ts.types.TMethod) 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) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 25 with Result

use of org.eclipse.xsemantics.runtime.Result in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeSuperLiteral.

protected Result<TypeRef> applyRuleTypeSuperLiteral(final RuleEnvironment G, final RuleApplicationTrace _trace_, final SuperLiteral superLiteral) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final N4MemberDeclaration containingMemberDecl = EcoreUtil2.<N4MemberDeclaration>getContainerOfType(superLiteral.eContainer(), N4MemberDeclaration.class);
    /* if (containingMemberDecl === null) { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } else { val containingClass = (containingMemberDecl.eContainer as N4ClassDeclaration).definedType as TClass; val superClass = G.getDeclaredOrImplicitSuperType(containingClass) var effectiveSuperClass = superClass if( containingClass.isStaticPolyfill ) { effectiveSuperClass = G.getDeclaredOrImplicitSuperType( superClass as TClass ) } { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } } or { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } */
    {
        RuleFailedException previousFailure = null;
        try {
            if ((containingMemberDecl == null)) {
                T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
            } else {
                EObject _eContainer = containingMemberDecl.eContainer();
                Type _definedType = ((N4ClassDeclaration) _eContainer).getDefinedType();
                final TClass containingClass = ((TClass) _definedType);
                final TClassifier superClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, containingClass);
                TClassifier effectiveSuperClass = superClass;
                boolean _isStaticPolyfill = containingClass.isStaticPolyfill();
                if (_isStaticPolyfill) {
                    effectiveSuperClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, ((TClass) superClass));
                }
                /* { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
                {
                    try {
                        /* superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression */
                        if (!((superLiteral.eContainer() instanceof ParameterizedPropertyAccessExpression) || (superLiteral.eContainer() instanceof IndexedAccessExpression))) {
                            sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression");
                        }
                        boolean _isStatic = containingMemberDecl.isStatic();
                        if (_isStatic) {
                            TypeRef _createConstructorTypeRef = null;
                            if (effectiveSuperClass != null) {
                                _createConstructorTypeRef = TypeUtils.createConstructorTypeRef(effectiveSuperClass);
                            }
                            T = _createConstructorTypeRef;
                        } else {
                            ParameterizedTypeRef _createTypeRef = null;
                            if (effectiveSuperClass != null) {
                                _createTypeRef = TypeUtils.createTypeRef(effectiveSuperClass);
                            }
                            T = _createTypeRef;
                        }
                        if ((T != null)) {
                            T = TypeUtils.enforceNominalTyping(T);
                        }
                    } catch (Exception e) {
                        previousFailure = extractRuleFailedException(e);
                        /* { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
                        {
                            try {
                                EObject _eContainer_1 = superLiteral.eContainer();
                                /* superLiteral.eContainer instanceof ParameterizedCallExpression */
                                if (!(_eContainer_1 instanceof ParameterizedCallExpression)) {
                                    sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedCallExpression");
                                }
                                if (((containingMemberDecl instanceof N4MethodDeclaration) && Objects.equal(containingMemberDecl.getName(), "constructor"))) {
                                    final TMethod ctor = this.containerTypesHelper.fromContext(superLiteral.eResource()).findConstructor(effectiveSuperClass);
                                    ParameterizedTypeRef _createTypeRef_1 = null;
                                    if (ctor != null) {
                                        _createTypeRef_1 = TypeUtils.createTypeRef(ctor);
                                    }
                                    T = _createTypeRef_1;
                                } else {
                                    T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
                                }
                            } catch (Exception e_1) {
                                previousFailure = extractRuleFailedException(e_1);
                                EObject _eContainer_2 = superLiteral.eContainer();
                                /* superLiteral.eContainer instanceof NewExpression */
                                if (!(_eContainer_2 instanceof NewExpression)) {
                                    sneakyThrowRuleFailedException("superLiteral.eContainer instanceof NewExpression");
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e_2) {
            previousFailure = extractRuleFailedException(e_2);
            T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
        }
    }
    return new Result<TypeRef>(T);
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) TMethod(org.eclipse.n4js.ts.types.TMethod) 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) NewExpression(org.eclipse.n4js.n4JS.NewExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) 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) 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) EObject(org.eclipse.emf.ecore.EObject) N4MethodDeclaration(org.eclipse.n4js.n4JS.N4MethodDeclaration) TClass(org.eclipse.n4js.ts.types.TClass)

Aggregations

Result (org.eclipse.xsemantics.runtime.Result)93 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)92 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)91 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)90 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)90 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)89 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)89 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)89 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)89 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)89 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)89 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)89 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)89 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)89 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)25 IndexedAccessExpression (org.eclipse.n4js.n4JS.IndexedAccessExpression)24 NewExpression (org.eclipse.n4js.n4JS.NewExpression)24 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)24 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)23 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)23