Search in sources :

Example 16 with Result

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

the class InternalTypeSystem method applyRuleLowerBoundFunctionTypeExprOrRef.

protected Result<TypeRef> applyRuleLowerBoundFunctionTypeExprOrRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final FunctionTypeExprOrRef F) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    T = this.typeSystemHelper.createLowerBoundOfFunctionTypeExprOrRef(G, F);
    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 17 with Result

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

the class InternalTypeSystem method applyRuleTypeTVariable.

protected Result<TypeRef> applyRuleTypeTVariable(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TVariable tvariable) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    T = tvariable.getTypeRef();
    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 18 with Result

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

the class InternalTypeSystem method applyRuleExpectedTypeInAssignmentExpression.

protected Result<TypeRef> applyRuleExpectedTypeInAssignmentExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final AssignmentExpression expr, final Expression operand) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    /* { ! jsVariantHelper.isTypeAware(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { DestructureUtils.isTopOfDestructuringAssignment(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
    {
        RuleFailedException previousFailure = null;
        try {
            boolean _isTypeAware = this.jsVariantHelper.isTypeAware(expr);
            boolean _not = (!_isTypeAware);
            /* ! jsVariantHelper.isTypeAware(expr) */
            if (!_not) {
                sneakyThrowRuleFailedException("! jsVariantHelper.isTypeAware(expr)");
            }
            Expression _lhs = expr.getLhs();
            boolean _tripleEquals = (operand == _lhs);
            if (_tripleEquals) {
                T = RuleEnvironmentExtensions.bottomTypeRef(G);
            } else {
                T = RuleEnvironmentExtensions.topTypeRef(G);
            }
        } catch (Exception e) {
            previousFailure = extractRuleFailedException(e);
            /* { DestructureUtils.isTopOfDestructuringAssignment(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
            {
                try {
                    boolean _isTopOfDestructuringAssignment = DestructureUtils.isTopOfDestructuringAssignment(expr);
                    /* DestructureUtils.isTopOfDestructuringAssignment(expr) */
                    if (!_isTopOfDestructuringAssignment) {
                        sneakyThrowRuleFailedException("DestructureUtils.isTopOfDestructuringAssignment(expr)");
                    }
                    Expression _lhs_1 = expr.getLhs();
                    boolean _tripleEquals_1 = (operand == _lhs_1);
                    if (_tripleEquals_1) {
                        T = RuleEnvironmentExtensions.bottomTypeRef(G);
                    } else {
                        T = RuleEnvironmentExtensions.topTypeRef(G);
                    }
                } catch (Exception e_1) {
                    previousFailure = extractRuleFailedException(e_1);
                    /* { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
                    {
                        try {
                            AssignmentOperator _op = expr.getOp();
                            boolean _tripleEquals_2 = (_op == AssignmentOperator.ASSIGN);
                            /* expr.op===AssignmentOperator.ASSIGN */
                            if (!_tripleEquals_2) {
                                sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ASSIGN");
                            }
                            Expression _lhs_2 = expr.getLhs();
                            boolean _tripleEquals_3 = (operand == _lhs_2);
                            if (_tripleEquals_3) {
                                T = RuleEnvironmentExtensions.bottomTypeRef(G);
                            } else {
                                /* G |- expr.lhs : T */
                                Expression _lhs_3 = expr.getLhs();
                                Result<TypeRef> result = typeInternal(G, _trace_, _lhs_3);
                                checkAssignableTo(result.getFirst(), TypeRef.class);
                                T = (TypeRef) result.getFirst();
                            }
                        } catch (Exception e_2) {
                            previousFailure = extractRuleFailedException(e_2);
                            /* { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
                            {
                                try {
                                    AssignmentOperator _op_1 = expr.getOp();
                                    boolean _tripleEquals_4 = (_op_1 == AssignmentOperator.ADD_ASSIGN);
                                    /* expr.op===AssignmentOperator.ADD_ASSIGN */
                                    if (!_tripleEquals_4) {
                                        sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ADD_ASSIGN");
                                    }
                                    Expression _lhs_4 = expr.getLhs();
                                    boolean _tripleEquals_5 = (operand == _lhs_4);
                                    if (_tripleEquals_5) {
                                        T = TypeUtils.createNonSimplifiedIntersectionType(RuleEnvironmentExtensions.numberTypeRef(G), RuleEnvironmentExtensions.stringTypeRef(G));
                                    } else {
                                        /* G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef */
                                        Expression _lhs_5 = expr.getLhs();
                                        ParameterizedTypeRef lhsTypeRef = null;
                                        Result<TypeRef> result_1 = typeInternal(G, _trace_, _lhs_5);
                                        checkAssignableTo(result_1.getFirst(), ParameterizedTypeRef.class);
                                        lhsTypeRef = (ParameterizedTypeRef) result_1.getFirst();
                                        Type _declaredType = lhsTypeRef.getDeclaredType();
                                        PrimitiveType _stringType = RuleEnvironmentExtensions.stringType(G);
                                        boolean _tripleEquals_6 = (_declaredType == _stringType);
                                        if (_tripleEquals_6) {
                                            T = RuleEnvironmentExtensions.anyTypeRef(G);
                                        } else {
                                            boolean _isNumeric = RuleEnvironmentExtensions.isNumeric(G, lhsTypeRef.getDeclaredType());
                                            if (_isNumeric) {
                                                T = RuleEnvironmentExtensions.numberTypeRef(G);
                                            } else {
                                                T = RuleEnvironmentExtensions.anyTypeRef(G);
                                            }
                                        }
                                    }
                                } catch (Exception e_3) {
                                    previousFailure = extractRuleFailedException(e_3);
                                    T = RuleEnvironmentExtensions.numberTypeRef(G);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return new Result<TypeRef>(T);
}
Also used : 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) 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) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) 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 19 with Result

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

the class InternalTypeSystem method applyRuleUpperBoundWildcardTypeRef.

protected Result<TypeRef> applyRuleUpperBoundWildcardTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final Wildcard wildcard) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final TypeRef ub = wildcard.getDeclaredOrImplicitUpperBound();
    if ((ub != null)) {
        T = ub;
    } 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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 20 with Result

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

the class InternalTypeSystem method applyRuleSubtypeBoundThisTypeRef.

protected Result<Boolean> applyRuleSubtypeBoundThisTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BoundThisTypeRef left, final BoundThisTypeRef right) throws RuleFailedException {
    boolean _isUseSiteStructuralTyping = right.isUseSiteStructuralTyping();
    if (_isUseSiteStructuralTyping) {
        final StructuralTypingResult result = this.typeSystemHelper.isStructuralSubtype(G, left, right);
        boolean _isValue = result.isValue();
        boolean _not = (!_isValue);
        if (_not) {
            /* fail error result.message data PRIORITY_ERROR */
            String _message = result.getMessage();
            String error = _message;
            Object data = TypeSystemErrorExtensions.PRIORITY_ERROR;
            throwForExplicitFail(error, new ErrorInformation(null, null, data));
        }
    } else {
        boolean _isUseSiteStructuralTyping_1 = left.isUseSiteStructuralTyping();
        boolean _isUseSiteStructuralTyping_2 = right.isUseSiteStructuralTyping();
        boolean _tripleEquals = (Boolean.valueOf(_isUseSiteStructuralTyping_1) == Boolean.valueOf(_isUseSiteStructuralTyping_2));
        /* left.useSiteStructuralTyping === right.useSiteStructuralTyping */
        if (!_tripleEquals) {
            sneakyThrowRuleFailedException("left.useSiteStructuralTyping === right.useSiteStructuralTyping");
        }
        /* G |- left.actualThisTypeRef <: right.actualThisTypeRef */
        ParameterizedTypeRef _actualThisTypeRef = left.getActualThisTypeRef();
        ParameterizedTypeRef _actualThisTypeRef_1 = right.getActualThisTypeRef();
        subtypeInternal(G, _trace_, _actualThisTypeRef, _actualThisTypeRef_1);
    }
    return new Result<Boolean>(true);
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) ErrorInformation(org.eclipse.xsemantics.runtime.ErrorInformation) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) EObject(org.eclipse.emf.ecore.EObject) TaggedTemplateString(org.eclipse.n4js.n4JS.TaggedTemplateString) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

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