Search in sources :

Example 1 with UnknownTypeRef

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

the class InferenceContext method containsInterestingLowerBound.

private boolean containsInterestingLowerBound(TypeRef[] typeRefs) {
    final Type undefinedType = RuleEnvironmentExtensions.undefinedType(G);
    final Type nullType = RuleEnvironmentExtensions.nullType(G);
    for (int i = 0; i < typeRefs.length; i++) {
        final TypeRef curr = typeRefs[i];
        if (curr instanceof ParameterizedTypeRef) {
            // for ParameterizedTypeRefs, it depends on the declared type:
            final Type currDeclType = curr.getDeclaredType();
            if (currDeclType != null && currDeclType != undefinedType && currDeclType != nullType) {
                // wow, that bound is interesting!
                return true;
            }
        } else {
            // all non-ParameterizedTypeRefs are interesting, except UnknownTypeRef:
            if (!(curr instanceof UnknownTypeRef)) {
                // wow, that bound looks intriguing!
                return true;
            }
        }
    }
    // no interesting bounds encountered
    return false;
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)

Example 2 with UnknownTypeRef

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

the class InternalTypeSystem method _applyRuleTypeTypeDefiningElement_1.

private TypeRef _applyRuleTypeTypeDefiningElement_1(final RuleEnvironment G, final TypeDefiningElement elem) throws RuleFailedException {
    TypeRef _elvis = null;
    TypeRef _wrapTypeInTypeRef = TypeUtils.wrapTypeInTypeRef(elem.getDefinedType());
    if (_wrapTypeInTypeRef != null) {
        _elvis = _wrapTypeInTypeRef;
    } else {
        UnknownTypeRef _createUnknownTypeRef = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
        _elvis = _createUnknownTypeRef;
    }
    return _elvis;
}
Also used : UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) 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)

Example 3 with UnknownTypeRef

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

the class ComposedMemberInfo method handleTypeRefLists.

private void handleTypeRefLists(TMember member, RuleEnvironment G) {
    TypeRef typeRef = TypeUtils.getMemberTypeRef(member);
    TypeRef typeRefSubst = ts.substTypeVariablesInTypeRef(G, typeRef);
    if (typeRefSubst != null && !(typeRefSubst instanceof UnknownTypeRef)) {
        TypeRef typeRefCopy = TypeUtils.copyIfContained(typeRefSubst);
        typeRefs.add(typeRefCopy);
        typeRef2G.put(typeRefCopy, G);
        if (member.getMemberType() == MemberType.METHOD) {
            if (TypeUtils.isVoid(typeRefCopy)) {
                methodTypeRefsVoid.add(typeRefCopy);
            } else {
                methodTypeRefsNonVoid.add(typeRefCopy);
            }
        }
        MemberType currMType = member.getMemberType();
        if (!typeRefsMap.containsKey(currMType)) {
            typeRefsMap.put(currMType, new LinkedList<>());
        }
        List<TypeRef> typeRefsOfMemberType = typeRefsMap.get(currMType);
        typeRefsOfMemberType.add(typeRefCopy);
    }
}
Also used : UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) MemberType(org.eclipse.n4js.ts.types.MemberType) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)

Example 4 with UnknownTypeRef

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

the class ComposedMemberInfo method initFParAggregate.

private void initFParAggregate(ComposedFParInfo fpAggr) {
    for (Pair<TFormalParameter, RuleEnvironment> fpPair : fpAggr.fpSiblings) {
        TFormalParameter tFpar = fpPair.getKey();
        RuleEnvironment G = fpPair.getValue();
        // handle: name
        final String nextName = tFpar.getName();
        if (nextName != null && !fpAggr.names.contains(nextName)) {
            fpAggr.names.add(nextName);
        }
        // handle: typeRef lists
        TypeRef typeRefSubst = ts.substTypeVariablesInTypeRef(G, tFpar.getTypeRef());
        if (typeRefSubst != null && !(typeRefSubst instanceof UnknownTypeRef)) {
            TypeRef typeRefCopy = TypeUtils.copyIfContained(typeRefSubst);
            fpAggr.typeRefs.add(typeRefCopy);
            if (tFpar.isVariadic()) {
                fpAggr.typeRefsVariadic.add(typeRefCopy);
            }
        }
        // handle: optional
        fpAggr.allOptional &= tFpar.isOptional();
        fpAggr.allNonOptional &= !tFpar.isOptional();
    }
}
Also used : TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment)

Example 5 with UnknownTypeRef

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

the class InternalTypeSystem method applyRuleSubstTypeVariablesInParameterizedTypeRef.

protected Result<TypeArgument> applyRuleSubstTypeVariablesInParameterizedTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedTypeRef typeRef) throws RuleFailedException {
    // output parameter
    TypeRef result = null;
    result = typeRef;
    Type _declaredType = typeRef.getDeclaredType();
    if ((_declaredType instanceof TypeVariable)) {
        Type _declaredType_1 = typeRef.getDeclaredType();
        final TypeVariable typeVar = ((TypeVariable) _declaredType_1);
        /* { var temp = env(G, typeVar, TypeRef) if (typeRef instanceof ParameterizedTypeRefStructural) { if (temp instanceof ParameterizedTypeRef) { var ptrs = TypeUtils.copyToParameterizedTypeRefStructural(temp); ptrs.setTypingStrategy(typeRef.getTypingStrategy()); temp = ptrs; } } val tempDeclaredType = temp.declaredType if (typeVar !== tempDeclaredType && (TypeUtils.isOrContainsRefToTypeVar(temp) || (tempDeclaredType !== null && tempDeclaredType.generic)) && G.get(GUARD_SUBST_TYPE_VARS -> temp) === null) { val G2 = G.wrap; G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) G2 |- temp ~> result result = TypeUtils.copy(result); } else { result = TypeUtils.copy(temp); } TypeUtils.copyTypeModifiers(result, typeRef) } or { val List<TypeRef> l_raw = env(G, typeVar, List) val l = newArrayList; for(var i=0;i<l_raw.size;i++) { val temp = l_raw.get(i); val tempDeclaredType = temp.declaredType; if(typeVar !== tempDeclaredType && (TypeUtils.isOrContainsRefToTypeVar(temp) || (tempDeclaredType !== null && tempDeclaredType.generic)) && G.get(GUARD_SUBST_TYPE_VARS -> temp) === null) { val G2 = G.wrap; G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) G2 |- temp ~> var TypeRef tempResult tempResult = TypeUtils.copy(tempResult); l += tempResult; } else { l += TypeUtils.copy(temp); } } result = if(typeVar.declaredCovariant) { typeSystemHelper.createIntersectionType(G,l) } else if(typeVar.declaredContravariant) { typeSystemHelper.createUnionType(G,l) } else { G.addInconsistentSubstitutions(typeVar, l); TypeRefsFactory.eINSTANCE.createUnknownTypeRef }; TypeUtils.copyTypeModifiers(result, typeRef) } or { } */
        {
            RuleFailedException previousFailure = null;
            try {
                TypeRef temp = this.<TypeRef>env(G, typeVar, TypeRef.class);
                if ((typeRef instanceof ParameterizedTypeRefStructural)) {
                    if ((temp instanceof ParameterizedTypeRef)) {
                        ParameterizedTypeRefStructural ptrs = TypeUtils.copyToParameterizedTypeRefStructural(((ParameterizedTypeRef) temp));
                        ptrs.setTypingStrategy(((ParameterizedTypeRefStructural) typeRef).getTypingStrategy());
                        temp = ptrs;
                    }
                }
                final Type tempDeclaredType = temp.getDeclaredType();
                if ((((typeVar != tempDeclaredType) && (TypeUtils.isOrContainsRefToTypeVar(temp) || ((tempDeclaredType != null) && tempDeclaredType.isGeneric()))) && (G.get(Pair.<String, TypeRef>of(RuleEnvironmentExtensions.GUARD_SUBST_TYPE_VARS, temp)) == null))) {
                    final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
                    Pair<String, TypeRef> _mappedTo = Pair.<String, TypeRef>of(RuleEnvironmentExtensions.GUARD_SUBST_TYPE_VARS, temp);
                    boolean _add = G2.add(_mappedTo, Boolean.TRUE);
                    /* G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) */
                    if (!_add) {
                        sneakyThrowRuleFailedException("G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE)");
                    }
                    /* G2 |- temp ~> result */
                    Result<TypeArgument> result_1 = substTypeVariablesInternal(G2, _trace_, temp);
                    checkAssignableTo(result_1.getFirst(), TypeRef.class);
                    result = (TypeRef) result_1.getFirst();
                    result = TypeUtils.<TypeRef>copy(result);
                } else {
                    result = TypeUtils.<TypeRef>copy(temp);
                }
                TypeUtils.copyTypeModifiers(result, typeRef);
            } catch (Exception e) {
                previousFailure = extractRuleFailedException(e);
                /* { val List<TypeRef> l_raw = env(G, typeVar, List) val l = newArrayList; for(var i=0;i<l_raw.size;i++) { val temp = l_raw.get(i); val tempDeclaredType = temp.declaredType; if(typeVar !== tempDeclaredType && (TypeUtils.isOrContainsRefToTypeVar(temp) || (tempDeclaredType !== null && tempDeclaredType.generic)) && G.get(GUARD_SUBST_TYPE_VARS -> temp) === null) { val G2 = G.wrap; G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) G2 |- temp ~> var TypeRef tempResult tempResult = TypeUtils.copy(tempResult); l += tempResult; } else { l += TypeUtils.copy(temp); } } result = if(typeVar.declaredCovariant) { typeSystemHelper.createIntersectionType(G,l) } else if(typeVar.declaredContravariant) { typeSystemHelper.createUnionType(G,l) } else { G.addInconsistentSubstitutions(typeVar, l); TypeRefsFactory.eINSTANCE.createUnknownTypeRef }; TypeUtils.copyTypeModifiers(result, typeRef) } or { } */
                {
                    try {
                        final List<TypeRef> l_raw = this.<List>env(G, typeVar, List.class);
                        final ArrayList<TypeRef> l = CollectionLiterals.<TypeRef>newArrayList();
                        for (int i = 0; (i < l_raw.size()); i++) {
                            final TypeRef temp_1 = l_raw.get(i);
                            final Type tempDeclaredType_1 = temp_1.getDeclaredType();
                            if ((((typeVar != tempDeclaredType_1) && (TypeUtils.isOrContainsRefToTypeVar(temp_1) || ((tempDeclaredType_1 != null) && tempDeclaredType_1.isGeneric()))) && (G.get(Pair.<String, TypeRef>of(RuleEnvironmentExtensions.GUARD_SUBST_TYPE_VARS, temp_1)) == null))) {
                                final RuleEnvironment G2_1 = RuleEnvironmentExtensions.wrap(G);
                                Pair<String, TypeRef> _mappedTo_1 = Pair.<String, TypeRef>of(RuleEnvironmentExtensions.GUARD_SUBST_TYPE_VARS, temp_1);
                                boolean _add_1 = G2_1.add(_mappedTo_1, Boolean.TRUE);
                                /* G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE) */
                                if (!_add_1) {
                                    sneakyThrowRuleFailedException("G2.add(GUARD_SUBST_TYPE_VARS -> temp, Boolean.TRUE)");
                                }
                                /* G2 |- temp ~> var TypeRef tempResult */
                                TypeRef tempResult = null;
                                Result<TypeArgument> result_2 = substTypeVariablesInternal(G2_1, _trace_, temp_1);
                                checkAssignableTo(result_2.getFirst(), TypeRef.class);
                                tempResult = (TypeRef) result_2.getFirst();
                                tempResult = TypeUtils.<TypeRef>copy(tempResult);
                                /* l += tempResult */
                                if (!l.add(tempResult)) {
                                    sneakyThrowRuleFailedException("l += tempResult");
                                }
                            } else {
                                TypeRef _copy = TypeUtils.<TypeRef>copy(temp_1);
                                /* l += TypeUtils.copy(temp) */
                                if (!l.add(_copy)) {
                                    sneakyThrowRuleFailedException("l += TypeUtils.copy(temp)");
                                }
                            }
                        }
                        TypeRef _xifexpression = null;
                        boolean _isDeclaredCovariant = typeVar.isDeclaredCovariant();
                        if (_isDeclaredCovariant) {
                            _xifexpression = this.typeSystemHelper.createIntersectionType(G, ((TypeRef[]) Conversions.unwrapArray(l, TypeRef.class)));
                        } else {
                            TypeRef _xifexpression_1 = null;
                            boolean _isDeclaredContravariant = typeVar.isDeclaredContravariant();
                            if (_isDeclaredContravariant) {
                                _xifexpression_1 = this.typeSystemHelper.createUnionType(G, ((TypeRef[]) Conversions.unwrapArray(l, TypeRef.class)));
                            } else {
                                UnknownTypeRef _xblockexpression = null;
                                {
                                    RuleEnvironmentExtensions.addInconsistentSubstitutions(G, typeVar, l);
                                    _xblockexpression = (TypeRefsFactory.eINSTANCE.createUnknownTypeRef());
                                }
                                _xifexpression_1 = _xblockexpression;
                            }
                            _xifexpression = _xifexpression_1;
                        }
                        result = _xifexpression;
                        TypeUtils.copyTypeModifiers(result, typeRef);
                    } catch (Exception e_1) {
                        previousFailure = extractRuleFailedException(e_1);
                    }
                }
            }
        }
    }
    boolean _and = false;
    Type _declaredType_2 = null;
    if (typeRef != null) {
        _declaredType_2 = typeRef.getDeclaredType();
    }
    boolean _tripleNotEquals = (_declaredType_2 != null);
    if (!_tripleNotEquals) {
        _and = false;
    } else {
        boolean _isGeneric = typeRef.getDeclaredType().isGeneric();
        _and = _isGeneric;
    }
    if (_and) {
        final int len = typeRef.getTypeArgs().size();
        boolean haveSubstitution = false;
        final TypeArgument[] argsChanged = new TypeArgument[len];
        for (int i = 0; (i < len); i++) {
            final TypeArgument arg = typeRef.getTypeArgs().get(i);
            /* G |- arg ~> var TypeArgument argSubst */
            TypeArgument argSubst = null;
            Result<TypeArgument> result_2 = substTypeVariablesInternal(G, _trace_, arg);
            checkAssignableTo(result_2.getFirst(), TypeArgument.class);
            argSubst = (TypeArgument) result_2.getFirst();
            if ((argSubst != arg)) {
                argsChanged[i] = argSubst;
                haveSubstitution = true;
            }
        }
        if (haveSubstitution) {
            if ((result == typeRef)) {
                result = TypeUtils.<ParameterizedTypeRef>copy(typeRef);
            }
            for (int i = 0; (i < len); i++) {
                final TypeArgument argCh = argsChanged[i];
                if ((argCh != null)) {
                    result.getTypeArgs().set(i, argCh);
                }
            }
        }
    }
    if ((result instanceof StructuralTypeRef)) {
        result = this.typeSystemHelper.substTypeVariablesInStructuralMembers(G, ((StructuralTypeRef) result));
    }
    return new Result<TypeArgument>(result);
}
Also used : ParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural) 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) ArrayList(java.util.ArrayList) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) 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) 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) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) Pair(org.eclipse.xtext.xbase.lib.Pair) PropertyNameValuePair(org.eclipse.n4js.n4JS.PropertyNameValuePair)

Aggregations

TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)7 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)7 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)5 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)4 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)4 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)4 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)4 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)4 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)4 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)4 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)4 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)4 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)3 Result (org.eclipse.xsemantics.runtime.Result)3 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)2 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)2 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)2 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)2 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)2 CastExpression (org.eclipse.n4js.n4JS.CastExpression)2