Search in sources :

Example 91 with RuleFailedException

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

the class InternalTypeSystem method typeImpl.

protected Result<TypeRef> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final NewTarget nt) throws RuleFailedException {
    try {
        final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
        final Result<TypeRef> _result_ = applyRuleTypeNewTarget(G, _subtrace_, nt);
        addToTrace(_trace_, new Provider<Object>() {

            public Object get() {
                return ruleName("typeNewTarget") + stringRepForEnv(G) + " |- " + stringRep(nt) + " : " + stringRep(_result_.getFirst());
            }
        });
        addAsSubtrace(_trace_, _subtrace_);
        return _result_;
    } catch (Exception e_applyRuleTypeNewTarget) {
        typeThrowException(ruleName("typeNewTarget") + stringRepForEnv(G) + " |- " + stringRep(nt) + " : " + "TypeRef", TYPENEWTARGET, e_applyRuleTypeNewTarget, nt, new ErrorInformation[] { new ErrorInformation(nt) });
        return null;
    }
}
Also used : ErrorInformation(org.eclipse.xsemantics.runtime.ErrorInformation) 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) RuleApplicationTrace(org.eclipse.xsemantics.runtime.RuleApplicationTrace) EObject(org.eclipse.emf.ecore.EObject) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException)

Example 92 with RuleFailedException

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

the class InternalTypeSystem method substTypeVariablesImpl.

protected Result<TypeArgument> substTypeVariablesImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeArgument type) throws RuleFailedException {
    try {
        final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
        final Result<TypeArgument> _result_ = applyRuleSubstTypeVariablesBaseCase(G, _subtrace_, type);
        addToTrace(_trace_, new Provider<Object>() {

            public Object get() {
                return ruleName("substTypeVariablesBaseCase") + stringRepForEnv(G) + " |- " + stringRep(type) + " ~> " + stringRep(_result_.getFirst());
            }
        });
        addAsSubtrace(_trace_, _subtrace_);
        return _result_;
    } catch (Exception e_applyRuleSubstTypeVariablesBaseCase) {
        substTypeVariablesThrowException(ruleName("substTypeVariablesBaseCase") + stringRepForEnv(G) + " |- " + stringRep(type) + " ~> " + "TypeArgument", SUBSTTYPEVARIABLESBASECASE, e_applyRuleSubstTypeVariablesBaseCase, type, new ErrorInformation[] { new ErrorInformation(type) });
        return null;
    }
}
Also used : ErrorInformation(org.eclipse.xsemantics.runtime.ErrorInformation) RuleApplicationTrace(org.eclipse.xsemantics.runtime.RuleApplicationTrace) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) EObject(org.eclipse.emf.ecore.EObject) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException)

Example 93 with RuleFailedException

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

the class InternalTypeSystem method typeImpl.

protected Result<TypeRef> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ModuleNamespaceVirtualType t) throws RuleFailedException {
    try {
        final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
        final Result<TypeRef> _result_ = applyRuleTypeModuleNamespace(G, _subtrace_, t);
        addToTrace(_trace_, new Provider<Object>() {

            public Object get() {
                return ruleName("typeModuleNamespace") + stringRepForEnv(G) + " |- " + stringRep(t) + " : " + stringRep(_result_.getFirst());
            }
        });
        addAsSubtrace(_trace_, _subtrace_);
        return _result_;
    } catch (Exception e_applyRuleTypeModuleNamespace) {
        typeThrowException(ruleName("typeModuleNamespace") + stringRepForEnv(G) + " |- " + stringRep(t) + " : " + "TypeRef", TYPEMODULENAMESPACE, e_applyRuleTypeModuleNamespace, t, new ErrorInformation[] { new ErrorInformation(t) });
        return null;
    }
}
Also used : ErrorInformation(org.eclipse.xsemantics.runtime.ErrorInformation) 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) RuleApplicationTrace(org.eclipse.xsemantics.runtime.RuleApplicationTrace) EObject(org.eclipse.emf.ecore.EObject) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException)

Example 94 with RuleFailedException

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

the class N4JSValidatorErrorGenerator method generateErrors.

/**
 * Copied from super class to create error messages from RuleFailedExceptions via method
 * {@link TypeSystemErrorExtensions#compileMessage(RuleFailedException)}.
 */
@Override
protected void generateErrors(ValidationMessageAcceptor validationMessageAcceptor, RuleFailedException ruleFailedException, EObject originalSource) {
    if (ruleFailedException == null) {
        return;
    }
    Iterable<RuleFailedException> allFailures = filter.filterRuleFailedExceptions(ruleFailedException);
    // the last information about a model element with error
    ErrorInformation lastErrorInformationWithSource = null;
    // an associated model element
    for (RuleFailedException ruleFailedException2 : allFailures) {
        lastErrorInformationWithSource = generateErrors(validationMessageAcceptor, // only change w.r.t. super-class method:
        TypeSystemErrorExtensions.compileMessage(ruleFailedException2), // ================================================================
        ruleFailedException2.getIssue(), filter.filterErrorInformation(ruleFailedException2), lastErrorInformationWithSource, originalSource);
    }
}
Also used : ErrorInformation(org.eclipse.xsemantics.runtime.ErrorInformation) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException)

Example 95 with RuleFailedException

use of org.eclipse.xsemantics.runtime.RuleFailedException 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)

Aggregations

RuleFailedException (org.eclipse.xsemantics.runtime.RuleFailedException)146 EObject (org.eclipse.emf.ecore.EObject)131 ErrorInformation (org.eclipse.xsemantics.runtime.ErrorInformation)129 RuleApplicationTrace (org.eclipse.xsemantics.runtime.RuleApplicationTrace)127 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)117 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)117 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)116 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)116 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)116 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)116 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)116 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)116 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)116 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)116 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)116 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)116 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)16 Result (org.eclipse.xsemantics.runtime.Result)16 TypeArgument (org.eclipse.n4js.ts.typeRefs.TypeArgument)15 Expression (org.eclipse.n4js.n4JS.Expression)8