Search in sources :

Example 96 with TypeRef

use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.

the class InternalTypeSystem method applyRuleExpectedTypeInJSXPropertyAttribute.

protected Result<TypeRef> applyRuleExpectedTypeInJSXPropertyAttribute(final RuleEnvironment G, final RuleApplicationTrace _trace_, final JSXPropertyAttribute container, final Expression expr) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
    final EObject jsxElem = container.eContainer();
    if ((jsxElem instanceof JSXElement)) {
        final TypeRef propsTypeRef = this.reactHelper.getPropsType(((JSXElement) jsxElem));
        if ((propsTypeRef != null)) {
            final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
            this.typeSystemHelper.addSubstitutions(G2, propsTypeRef);
            RuleEnvironmentExtensions.addThisType(G2, propsTypeRef);
            /* G2 |- container.getProperty() : var TypeRef propertyTypeRef */
            IdentifiableElement _property = container.getProperty();
            TypeRef propertyTypeRef = null;
            Result<TypeRef> result = typeInternal(G2, _trace_, _property);
            checkAssignableTo(result.getFirst(), TypeRef.class);
            propertyTypeRef = (TypeRef) result.getFirst();
            /* G2 |- propertyTypeRef ~> T */
            Result<TypeArgument> result_1 = substTypeVariablesInternal(G2, _trace_, propertyTypeRef);
            checkAssignableTo(result_1.getFirst(), TypeRef.class);
            T = (TypeRef) result_1.getFirst();
        }
    }
    return new Result<TypeRef>(T);
}
Also used : JSXElement(org.eclipse.n4js.n4JS.JSXElement) 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) EObject(org.eclipse.emf.ecore.EObject) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 97 with TypeRef

use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeGetterDeclaration.

protected Result<TypeRef> applyRuleTypeGetterDeclaration(final RuleEnvironment G, final RuleApplicationTrace _trace_, final GetterDeclaration getter) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    TypeRef _declaredTypeRef = getter.getDeclaredTypeRef();
    boolean _tripleNotEquals = (_declaredTypeRef != null);
    if (_tripleNotEquals) {
        T = getter.getDeclaredTypeRef();
    } else {
        TGetter _definedGetter = getter.getDefinedGetter();
        TypeRef _declaredTypeRef_1 = null;
        if (_definedGetter != null) {
            _declaredTypeRef_1 = _definedGetter.getDeclaredTypeRef();
        }
        boolean _tripleNotEquals_1 = (_declaredTypeRef_1 != null);
        if (_tripleNotEquals_1) {
            T = getter.getDefinedGetter().getDeclaredTypeRef();
        } 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) TGetter(org.eclipse.n4js.ts.types.TGetter) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 98 with TypeRef

use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.

the class InternalTypeSystem method expectedTypeInImpl.

protected Result<TypeRef> expectedTypeInImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final VariableDeclaration vdecl, final Expression rhs) throws RuleFailedException {
    try {
        final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
        final Result<TypeRef> _result_ = applyRuleExpectedTypeOfRightSideInVariableDeclaration(G, _subtrace_, vdecl, rhs);
        addToTrace(_trace_, new Provider<Object>() {

            public Object get() {
                return ruleName("expectedTypeOfRightSideInVariableDeclaration") + stringRepForEnv(G) + " |- " + stringRep(vdecl) + " |> " + stringRep(rhs) + " : " + stringRep(_result_.getFirst());
            }
        });
        addAsSubtrace(_trace_, _subtrace_);
        return _result_;
    } catch (Exception e_applyRuleExpectedTypeOfRightSideInVariableDeclaration) {
        expectedTypeInThrowException(ruleName("expectedTypeOfRightSideInVariableDeclaration") + stringRepForEnv(G) + " |- " + stringRep(vdecl) + " |> " + stringRep(rhs) + " : " + "TypeRef", EXPECTEDTYPEOFRIGHTSIDEINVARIABLEDECLARATION, e_applyRuleExpectedTypeOfRightSideInVariableDeclaration, vdecl, rhs, new ErrorInformation[] { new ErrorInformation(vdecl), new ErrorInformation(rhs) });
        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 99 with TypeRef

use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.

the class InternalTypeSystem method typeImpl.

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

            public Object get() {
                return ruleName("typeTemplateLiteral") + stringRepForEnv(G) + " |- " + stringRep(l) + " : " + stringRep(_result_.getFirst());
            }
        });
        addAsSubtrace(_trace_, _subtrace_);
        return _result_;
    } catch (Exception e_applyRuleTypeTemplateLiteral) {
        typeThrowException(ruleName("typeTemplateLiteral") + stringRepForEnv(G) + " |- " + stringRep(l) + " : " + "ParameterizedTypeRef", TYPETEMPLATELITERAL, e_applyRuleTypeTemplateLiteral, l, new ErrorInformation[] { new ErrorInformation(l) });
        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 100 with TypeRef

use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeBinaryLogicalExpression.

protected Result<TypeRef> applyRuleTypeBinaryLogicalExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BinaryLogicalExpression e) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final Expression lhs = e.getLhs();
    final Expression rhs = e.getRhs();
    boolean _xifexpression = false;
    if ((lhs instanceof ArrayLiteral)) {
        _xifexpression = ((ArrayLiteral) lhs).getElements().isEmpty();
    }
    final boolean lhsIsEmptyArrayLiteral = _xifexpression;
    boolean _xifexpression_1 = false;
    if ((rhs instanceof ArrayLiteral)) {
        _xifexpression_1 = ((ArrayLiteral) rhs).getElements().isEmpty();
    }
    final boolean rhsIsEmptyArrayLiteral = _xifexpression_1;
    /* G |- e.lhs : var TypeRef L */
    Expression _lhs = e.getLhs();
    TypeRef L = null;
    Result<TypeRef> result = typeInternal(G, _trace_, _lhs);
    checkAssignableTo(result.getFirst(), TypeRef.class);
    L = (TypeRef) result.getFirst();
    /* G |- e.rhs : var TypeRef R */
    Expression _rhs = e.getRhs();
    TypeRef R = null;
    Result<TypeRef> result_1 = typeInternal(G, _trace_, _rhs);
    checkAssignableTo(result_1.getFirst(), TypeRef.class);
    R = (TypeRef) result_1.getFirst();
    boolean _and = false;
    boolean _lhsIsEmptyArrayLiteral = lhsIsEmptyArrayLiteral;
    if (!_lhsIsEmptyArrayLiteral) {
        _and = false;
    } else {
        Type _declaredType = null;
        if (R != null) {
            _declaredType = R.getDeclaredType();
        }
        TObjectPrototype _arrayType = RuleEnvironmentExtensions.arrayType(G);
        boolean _tripleEquals = (_declaredType == _arrayType);
        _and = _tripleEquals;
    }
    if (_and) {
        T = R;
    } else {
        boolean _and_1 = false;
        boolean _rhsIsEmptyArrayLiteral = rhsIsEmptyArrayLiteral;
        if (!_rhsIsEmptyArrayLiteral) {
            _and_1 = false;
        } else {
            Type _declaredType_1 = null;
            if (L != null) {
                _declaredType_1 = L.getDeclaredType();
            }
            TObjectPrototype _arrayType_1 = RuleEnvironmentExtensions.arrayType(G);
            boolean _tripleEquals_1 = (_declaredType_1 == _arrayType_1);
            _and_1 = _tripleEquals_1;
        }
        if (_and_1) {
            T = L;
        } else {
            T = this.typeSystemHelper.createUnionType(G, L, R);
        }
    }
    return new Result<TypeRef>(T);
}
Also used : 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) 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) ArrayLiteral(org.eclipse.n4js.n4JS.ArrayLiteral) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Aggregations

TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)292 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)223 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)206 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)206 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)205 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)202 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)201 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)200 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)200 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)200 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)199 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)193 EObject (org.eclipse.emf.ecore.EObject)117 RuleFailedException (org.eclipse.xsemantics.runtime.RuleFailedException)117 ErrorInformation (org.eclipse.xsemantics.runtime.ErrorInformation)103 RuleApplicationTrace (org.eclipse.xsemantics.runtime.RuleApplicationTrace)101 Result (org.eclipse.xsemantics.runtime.Result)90 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)89 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)42 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)26