Search in sources :

Example 51 with Result

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

the class InternalTypeSystem method applyRuleExpectedTypeInYieldStatement.

protected Result<TypeRef> applyRuleExpectedTypeInYieldStatement(final RuleEnvironment G, final RuleApplicationTrace _trace_, final YieldExpression yieldExpr, final Expression expression) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    /* G |- expression : var TypeRef exprTypeRef */
    TypeRef exprTypeRef = null;
    Result<TypeRef> result = typeInternal(G, _trace_, expression);
    checkAssignableTo(result.getFirst(), TypeRef.class);
    exprTypeRef = (TypeRef) result.getFirst();
    T = this.typeSystemHelper.getExpectedTypeOfYieldValueExpression(G, yieldExpr, exprTypeRef);
    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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 52 with Result

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

the class InternalTypeSystem method applyRuleExpectedTypeInMultiplicativeExpression.

protected Result<TypeRef> applyRuleExpectedTypeInMultiplicativeExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final MultiplicativeExpression e, final Expression expression) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 53 with Result

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

the class InternalTypeSystem method applyRuleExpectedTypeInReturnStatement.

protected Result<TypeRef> applyRuleExpectedTypeInReturnStatement(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ReturnStatement stmt, final Expression expression) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    T = this.typeSystemHelper.getExpectedTypeOfReturnValueExpression(G, expression);
    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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 54 with Result

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

the class InternalTypeSystem method applyRuleLowerBoundUnionTypeExpression.

protected Result<TypeRef> applyRuleLowerBoundUnionTypeExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final UnionTypeExpression U) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final Function1<TypeRef, TypeRef> _function = (TypeRef it) -> {
        TypeRef _xblockexpression = null;
        {
            TypeRef E = null;
            /* G|~ it \/ E */
            Result<TypeRef> result = lowerBoundInternal(G, _trace_, it);
            checkAssignableTo(result.getFirst(), TypeRef.class);
            E = (TypeRef) result.getFirst();
            _xblockexpression = E;
        }
        return _xblockexpression;
    };
    T = TypeUtils.createNonSimplifiedUnionType(ListExtensions.<TypeRef, TypeRef>map(U.getTypeRefs(), _function));
    TypeUtils.copyTypeModifiers(T, U);
    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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 55 with Result

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

the class InternalTypeSystem method applyRuleExpectedTypeOfArgument.

protected Result<TypeRef> applyRuleExpectedTypeOfArgument(final RuleEnvironment G, final RuleApplicationTrace _trace_, final Argument argument, final Expression argumentExpression) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final EObject expr = argument.eContainer();
    if ((expr instanceof NewExpression)) {
        boolean _contains = ((NewExpression) expr).getArguments().contains(argument);
        boolean _not = (!_contains);
        if (_not) {
        } else {
            /* G |- expr.callee : var TypeTypeRef ctorTypeRef */
            Expression _callee = ((NewExpression) expr).getCallee();
            TypeTypeRef ctorTypeRef = null;
            Result<TypeRef> result = typeInternal(G, _trace_, _callee);
            checkAssignableTo(result.getFirst(), TypeTypeRef.class);
            ctorTypeRef = (TypeTypeRef) result.getFirst();
            TypeRef typeRefOfInstanceToCreate = this.typeSystemHelper.createTypeRefFromStaticType(G, ctorTypeRef, ((TypeArgument[]) Conversions.unwrapArray(((NewExpression) expr).getTypeArgs(), TypeArgument.class)));
            Type _declaredType = typeRefOfInstanceToCreate.getDeclaredType();
            ContainerType<?> typeOfInstanceToCreate = ((ContainerType<?>) _declaredType);
            final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
            this.typeSystemHelper.addSubstitutions(G2, typeRefOfInstanceToCreate);
            RuleEnvironmentExtensions.addThisType(G2, typeRefOfInstanceToCreate);
            TMethod ctor = this.containerTypesHelper.fromContext(((NewExpression) expr).eResource()).findConstructor(typeOfInstanceToCreate);
            TFormalParameter _fparForArgIdx = null;
            if (ctor != null) {
                _fparForArgIdx = ctor.getFparForArgIdx(ECollections.indexOf(((NewExpression) expr).getArguments(), argument, 0));
            }
            final TFormalParameter fpar = _fparForArgIdx;
            if ((fpar == null)) {
                T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
            } else {
                final TypeRef paramType = fpar.getTypeRef();
                if ((paramType == null)) {
                    T = RuleEnvironmentExtensions.anyTypeRef(G2);
                } else {
                    /* G2 |- paramType ~> T */
                    Result<TypeArgument> result_1 = substTypeVariablesInternal(G2, _trace_, paramType);
                    checkAssignableTo(result_1.getFirst(), TypeRef.class);
                    T = (TypeRef) result_1.getFirst();
                }
            }
        }
    } else {
        if ((expr instanceof ParameterizedCallExpression)) {
            boolean _contains_1 = ((ParameterizedCallExpression) expr).getArguments().contains(argument);
            /* expr.arguments.contains(argument) */
            if (!_contains_1) {
                sneakyThrowRuleFailedException("expr.arguments.contains(argument)");
            }
            /* G |- expr.target : var TypeRef targetTypeRef */
            Expression _target = ((ParameterizedCallExpression) expr).getTarget();
            TypeRef targetTypeRef = null;
            Result<TypeRef> result_2 = typeInternal(G, _trace_, _target);
            checkAssignableTo(result_2.getFirst(), TypeRef.class);
            targetTypeRef = (TypeRef) result_2.getFirst();
            if ((targetTypeRef instanceof FunctionTypeExprOrRef)) {
                final FunctionTypeExprOrRef F = ((FunctionTypeExprOrRef) targetTypeRef);
                final int argIndex = ECollections.indexOf(((ParameterizedCallExpression) expr).getArguments(), argument, 0);
                final TFormalParameter fpar_1 = F.getFparForArgIdx(argIndex);
                if ((fpar_1 == null)) {
                    T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
                } else {
                    final TypeRef paramType_1 = fpar_1.getTypeRef();
                    if ((paramType_1 == null)) {
                        T = RuleEnvironmentExtensions.anyTypeRef(G);
                    } else {
                        final RuleEnvironment G2_1 = RuleEnvironmentExtensions.wrap(G);
                        this.typeSystemHelper.addSubstitutions(G2_1, ((ParameterizedCallExpression) expr), F);
                        Expression _target_1 = ((ParameterizedCallExpression) expr).getTarget();
                        if ((_target_1 instanceof SuperLiteral)) {
                            N4ClassDeclaration _containerOfType = EcoreUtil2.<N4ClassDeclaration>getContainerOfType(expr, N4ClassDeclaration.class);
                            Type _definedType = null;
                            if (_containerOfType != null) {
                                _definedType = _containerOfType.getDefinedType();
                            }
                            final Type containingClass = _definedType;
                            if ((containingClass instanceof TClass)) {
                                RuleEnvironmentExtensions.addThisType(G2_1, TypeExtensions.ref(containingClass));
                                ParameterizedTypeRef _superClassRef = ((TClass) containingClass).getSuperClassRef();
                                boolean _tripleNotEquals = (_superClassRef != null);
                                if (_tripleNotEquals) {
                                    this.typeSystemHelper.addSubstitutions(G2_1, ((TClass) containingClass).getSuperClassRef());
                                }
                                if ((paramType_1 instanceof ThisTypeRefStructural)) {
                                    RuleEnvironmentExtensions.addThisType(G2_1, ((TClass) containingClass).getSuperClassRef());
                                }
                            }
                        }
                        /* G2 |- paramType ~> T */
                        Result<TypeArgument> result_3 = substTypeVariablesInternal(G2_1, _trace_, paramType_1);
                        checkAssignableTo(result_3.getFirst(), TypeRef.class);
                        T = (TypeRef) result_3.getFirst();
                    }
                }
            } else {
                T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
            }
        }
    }
    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) NewExpression(org.eclipse.n4js.n4JS.NewExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) SuperLiteral(org.eclipse.n4js.n4JS.SuperLiteral) N4ClassDeclaration(org.eclipse.n4js.n4JS.N4ClassDeclaration) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) 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) EObject(org.eclipse.emf.ecore.EObject) ThisTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ThisTypeRefStructural) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) FunctionTypeExprOrRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeExprOrRef) 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