Search in sources :

Example 6 with TypeParameterList

use of dyvilx.tools.compiler.ast.generic.TypeParameterList in project Dyvil by Dyvil.

the class ClassGenericType method inferTypes.

@Override
public void inferTypes(IType concrete, ITypeContext typeContext) {
    final TypeParameterList classTypeParams = this.getTheClass().getTypeParameters();
    for (int i = 0, size = this.arguments.size(); i < size; i++) {
        final ITypeParameter typeVar = classTypeParams.get(i);
        final IType concreteType = concrete.resolveType(typeVar);
        if (concreteType != null) {
            this.arguments.get(i).inferTypes(concreteType, typeContext);
        }
    }
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) IType(dyvilx.tools.compiler.ast.type.IType)

Example 7 with TypeParameterList

use of dyvilx.tools.compiler.ast.generic.TypeParameterList in project Dyvil by Dyvil.

the class TupleExpr method getTypeMatch.

@Override
public int getTypeMatch(IType type, IImplicitContext implicitContext) {
    final int arity = this.values.size();
    final IClass tupleClass = TupleType.getTupleClass(arity);
    if (!Types.isSuperClass(type, tupleClass.getClassType())) {
        if (type.getAnnotation(LazyFields.TUPLE_CONVERTIBLE) != null) {
            return CONVERSION_MATCH;
        }
        return MISMATCH;
    }
    // reset type
    this.tupleType = null;
    final TypeParameterList typeParameters = typeParameters(tupleClass, arity);
    int min = EXACT_MATCH;
    for (int i = 0; i < arity; i++) {
        final IType elementType = Types.resolveTypeSafely(type, typeParameters.get(i));
        final int match = TypeChecker.getTypeMatch(this.values.get(i), elementType, implicitContext);
        if (match == MISMATCH) {
            return MISMATCH;
        }
        if (match < min) {
            min = match;
        }
    }
    return min;
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

Example 8 with TypeParameterList

use of dyvilx.tools.compiler.ast.generic.TypeParameterList in project Dyvil by Dyvil.

the class TupleExpr method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final Annotation annotation = type.getAnnotation(LazyFields.TUPLE_CONVERTIBLE);
    if (annotation != null) {
        return new LiteralConversion(this, annotation, this.values).withType(type, typeContext, markers, context);
    }
    final int arity = this.values.size();
    final IClass tupleClass = TupleType.getTupleClass(arity);
    if (!Types.isSuperClass(type, tupleClass.getClassType())) {
        return null;
    }
    // reset type
    this.tupleType = null;
    final TypeParameterList typeParameters = typeParameters(tupleClass, arity);
    for (int i = 0; i < arity; i++) {
        final IType elementType = Types.resolveTypeSafely(type, typeParameters.get(i));
        final IValue value = TypeChecker.convertValue(this.values.get(i), elementType, typeContext, markers, context, LazyFields.ELEMENT_MARKER_SUPPLIER);
        this.values.set(i, value);
    }
    return this;
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 9 with TypeParameterList

use of dyvilx.tools.compiler.ast.generic.TypeParameterList in project Dyvil by Dyvil.

the class TupleSurrogate method withType.

@Override
public Pattern withType(IType type, MarkerList markers) {
    final IClass tupleClass = TupleType.getTupleClass(this.patternCount);
    if (tupleClass == null) {
        return null;
    }
    final IType tupleType = tupleClass.getClassType();
    if (!Types.isSuperClass(type, tupleType)) {
        return null;
    }
    // reset type to recompute it later
    this.tupleType = null;
    final TypeParameterList typeParameters = tupleClass.getTypeParameters();
    for (int i = 0; i < this.patternCount; i++) {
        final IType elementType = Types.resolveTypeSafely(type, typeParameters.get(i));
        final Pattern pattern = this.patterns[i];
        final Pattern typedPattern = pattern.withType(elementType, markers);
        if (typedPattern == null) {
            final Marker marker = Markers.semanticError(pattern.getPosition(), "pattern.tuple.element.type");
            marker.addInfo(Markers.getSemantic("pattern.type", pattern.getType()));
            marker.addInfo(Markers.getSemantic("tuple.element.type", elementType));
            markers.add(marker);
        } else {
            this.patterns[i] = typedPattern;
        }
    }
    if (!Types.isSuperClass(tupleType, type)) {
        return new TypeCheckPattern(this, type, tupleType);
    }
    return this;
}
Also used : TypeCheckPattern(dyvilx.tools.compiler.ast.pattern.TypeCheckPattern) AbstractPattern(dyvilx.tools.compiler.ast.pattern.AbstractPattern) TypeCheckPattern(dyvilx.tools.compiler.ast.pattern.TypeCheckPattern) Pattern(dyvilx.tools.compiler.ast.pattern.Pattern) TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)9 IType (dyvilx.tools.compiler.ast.type.IType)8 IClass (dyvilx.tools.compiler.ast.classes.IClass)5 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)5 Marker (dyvilx.tools.parsing.marker.Marker)3 Reified (dyvil.annotation.Reified)1 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)1 GenericData (dyvilx.tools.compiler.ast.generic.GenericData)1 AbstractPattern (dyvilx.tools.compiler.ast.pattern.AbstractPattern)1 Pattern (dyvilx.tools.compiler.ast.pattern.Pattern)1 TypeCheckPattern (dyvilx.tools.compiler.ast.pattern.TypeCheckPattern)1