Search in sources :

Example 11 with TFunction

use of org.eclipse.n4js.ts.types.TFunction in project n4js by eclipse.

the class N4MethodDeclarationImpl method getDefinedFunction.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public TFunction getDefinedFunction() {
    final Type defType = this.getDefinedType();
    TFunction _xifexpression = null;
    if ((defType instanceof TFunction)) {
        _xifexpression = ((TFunction) defType);
    }
    return _xifexpression;
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TFunction(org.eclipse.n4js.ts.types.TFunction)

Example 12 with TFunction

use of org.eclipse.n4js.ts.types.TFunction in project n4js by eclipse.

the class N4JSResourceDescription method getCrossRefTypeAcceptor.

private IAcceptor<EObject> getCrossRefTypeAcceptor(final Set<EObject> crossRefTypesAddHere) {
    IAcceptor<EObject> acceptor = new IAcceptor<EObject>() {

        @Override
        public void accept(EObject to) {
            if (to instanceof Type || to instanceof TVariable || to instanceof TEnumLiteral) {
                crossRefTypesAddHere.add(to);
            }
            // Add declared type of a field to cross ref types
            if (to instanceof TFunction) {
                TypeRef returnTypeRef = ((TFunction) to).getReturnTypeRef();
                crossRefTypesAddHere.add(returnTypeRef.getDeclaredType());
            }
            if (to instanceof TField) {
                TypeRef typeRef = ((TField) to).getTypeRef();
                crossRefTypesAddHere.add(typeRef.getDeclaredType());
            }
            // In case of TMember, add the containing type as well
            if (to instanceof TMember) {
                TMember casted = (TMember) to;
                ContainerType<?> declaringType = casted.getContainingType();
                crossRefTypesAddHere.add(declaringType);
            }
        }
    };
    return acceptor;
}
Also used : ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type) TFunction(org.eclipse.n4js.ts.types.TFunction) TVariable(org.eclipse.n4js.ts.types.TVariable) TField(org.eclipse.n4js.ts.types.TField) TEnumLiteral(org.eclipse.n4js.ts.types.TEnumLiteral) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) EObject(org.eclipse.emf.ecore.EObject) IAcceptor(org.eclipse.xtext.util.IAcceptor) TMember(org.eclipse.n4js.ts.types.TMember)

Example 13 with TFunction

use of org.eclipse.n4js.ts.types.TFunction 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)

Example 14 with TFunction

use of org.eclipse.n4js.ts.types.TFunction in project n4js by eclipse.

the class SpecModuleFile method add.

/**
 * Adds another region change entry to this file.
 */
@Override
public void add(SpecSection specElem) {
    if (!(specElem instanceof SpecIdentifiableElementSection))
        return;
    SpecIdentifiableElementSection specIE = (SpecIdentifiableElementSection) specElem;
    EObject container = specIE.idElement.eContainer();
    if (container instanceof Type) {
        addTypeElement((Type) container, specIE);
        return;
    }
    if (specIE.idElement instanceof TFunction) {
        functions.add(specIE);
        allSections.add(specIE);
        return;
    }
    if (specIE.idElement instanceof TVariable) {
        variables.add(specIE);
        allSections.add(specIE);
        return;
    }
    if (specIE.idElement instanceof Type) {
        addTypeElement((Type) specIE.idElement, specIE);
        return;
    }
    throw new RuntimeException("Missing Implementation");
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TFunction(org.eclipse.n4js.ts.types.TFunction) TVariable(org.eclipse.n4js.ts.types.TVariable) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

TFunction (org.eclipse.n4js.ts.types.TFunction)14 Type (org.eclipse.n4js.ts.types.Type)8 EObject (org.eclipse.emf.ecore.EObject)4 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)3 TypeArgument (org.eclipse.n4js.ts.typeRefs.TypeArgument)3 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)3 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)2 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)2 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)2 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)2 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)2 FunctionTypeExprOrRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeExprOrRef)2 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)2 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)2 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)2 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)2 ContainerType (org.eclipse.n4js.ts.types.ContainerType)2 TVariable (org.eclipse.n4js.ts.types.TVariable)2 HashSet (java.util.HashSet)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1