Search in sources :

Example 1 with ITypeParameter

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

the class ClassGenericType method argumentsMatch.

protected boolean argumentsMatch(IType type) {
    final int count = Math.min(this.arguments.size(), this.getTheClass().typeArity());
    final TypeParameterList classTypeParams = this.getTheClass().getTypeParameters();
    for (int i = 0; i < count; i++) {
        final ITypeParameter typeVar = classTypeParams.get(i);
        final IType thisArgument = this.arguments.get(i);
        final IType thatArgument = type.resolveType(typeVar);
        if (thatArgument != null && !Variance.checkCompatible(typeVar.getVariance(), thisArgument, thatArgument)) {
            return false;
        }
    }
    return true;
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) IType(dyvilx.tools.compiler.ast.type.IType)

Example 2 with ITypeParameter

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

the class NamedGenericType method resolveTopLevelWith.

private IType resolveTopLevelWith(MarkerList markers, IContext context) {
    final MatchList<ITypeAlias> typeAliases = IContext.resolveTypeAlias(context, null, this.name, this.arguments);
    if (typeAliases.hasCandidate()) {
        final ITypeAlias typeAlias = typeAliases.getBestMember();
        final IType aliasType = typeAlias.getType();
        if (!aliasType.isResolved()) {
            markers.add(Markers.semanticError(this.position, "type.alias.unresolved", this.name));
            return aliasType.atPosition(this.position);
        }
        return this.checkCount(markers, typeAlias, "type_alias", aliasType);
    }
    final IClass theClass = context.resolveClass(this.name);
    if (theClass != null) {
        final IType classType = theClass.getThisType();
        return this.checkCount(markers, theClass, "class", classType);
    }
    final ITypeParameter typeParameter = context.resolveTypeParameter(this.name);
    if (typeParameter != null) {
        markers.add(Markers.semanticError(this.position, "type.generic.type_parameter.not_generic", typeParameter.getName()));
        return new ResolvedTypeVarType(typeParameter, this.position);
    }
    final Package thePackage = context.resolvePackage(this.name);
    if (thePackage != null) {
        markers.add(Markers.semanticError(this.position, "type.generic.package.not_generic", thePackage.getName()));
        return new PackageType(thePackage).atPosition(this.position);
    }
    return null;
}
Also used : ITypeAlias(dyvilx.tools.compiler.ast.type.alias.ITypeAlias) PackageType(dyvilx.tools.compiler.ast.type.raw.PackageType) ResolvedTypeVarType(dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) IClass(dyvilx.tools.compiler.ast.classes.IClass) Package(dyvilx.tools.compiler.ast.structure.Package) IType(dyvilx.tools.compiler.ast.type.IType)

Example 3 with ITypeParameter

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

the class ResolvedGenericType method checkType.

@Override
public void checkType(MarkerList markers, IContext context, int position) {
    ModifierUtil.checkVisibility(this.theClass, this.position, markers, context);
    // Check if the Type Variable Bounds accept the supplied Type Arguments
    final int count = Math.min(this.arguments.size(), this.theClass.typeArity());
    final TypeParameterList classTypeParams = this.theClass.getTypeParameters();
    for (int i = 0; i < count; i++) {
        final ITypeParameter typeParameter = classTypeParams.get(i);
        final IType typeArgument = this.resolveType(typeParameter);
        if (typeArgument.isResolved() && !typeParameter.isAssignableFrom(typeArgument, null)) {
            final Marker marker = Markers.semanticError(typeArgument.getPosition(), "type.generic.incompatible", typeParameter.getName().qualified, this.theClass.getFullName());
            marker.addInfo(Markers.getSemantic("type.generic.argument", typeArgument));
            marker.addInfo(Markers.getSemantic("type_parameter.declaration", typeParameter));
            markers.add(marker);
        }
    }
    if ((position & TypePosition.GENERIC_FLAG) == 0) {
        markers.add(Markers.semanticError(this.position, "type.generic.class"));
    }
    super.checkType(markers, context, position);
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 4 with ITypeParameter

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

the class NamedType method resolveTopLevelWith.

private IType resolveTopLevelWith(@SuppressWarnings("UnusedParameters") MarkerList markers, IContext context) {
    final MatchList<ITypeAlias> typeAliases = IContext.resolveTypeAlias(context, null, this.name, TypeList.EMPTY);
    if (typeAliases.hasCandidate()) {
        final ITypeAlias typeAlias = typeAliases.getBestMember();
        final IType type = typeAlias.getType();
        if (!type.isResolved() && markers != null) {
            markers.add(Markers.semanticError(this.position, "type.alias.unresolved", this.name));
            return type.atPosition(this.position);
        }
        return type.getConcreteType(ITypeContext.DEFAULT).atPosition(this.position);
    }
    final IClass theClass = context.resolveClass(this.name);
    if (theClass != null) {
        return new ResolvedClassType(theClass, this.position);
    }
    final ITypeParameter typeParameter = context.resolveTypeParameter(this.name);
    if (typeParameter != null) {
        return new ResolvedTypeVarType(typeParameter, this.position);
    }
    final Package thePackage = context.resolvePackage(this.name);
    if (thePackage != null) {
        return new PackageType(thePackage).atPosition(this.position);
    }
    return null;
}
Also used : ITypeAlias(dyvilx.tools.compiler.ast.type.alias.ITypeAlias) ResolvedTypeVarType(dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) IClass(dyvilx.tools.compiler.ast.classes.IClass) Package(dyvilx.tools.compiler.ast.structure.Package) IType(dyvilx.tools.compiler.ast.type.IType)

Example 5 with ITypeParameter

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

the class ExternalClass method resolveGenerics.

private void resolveGenerics() {
    if ((this.resolved & GENERICS) != 0) {
        return;
    }
    this.resolved |= GENERICS;
    final int typeParams;
    if (this.typeParameters == null || (typeParams = this.typeParameters.size()) <= 0) {
        return;
    }
    final IContext context = this.getCombiningContext();
    for (int i = 0; i < typeParams; i++) {
        final ITypeParameter typeParameter = this.typeParameters.get(i);
        typeParameter.resolveTypes(null, context);
    }
}
Also used : IContext(dyvilx.tools.compiler.ast.context.IContext) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter)

Aggregations

ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)10 IType (dyvilx.tools.compiler.ast.type.IType)8 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)5 IClass (dyvilx.tools.compiler.ast.classes.IClass)3 Marker (dyvilx.tools.parsing.marker.Marker)3 Package (dyvilx.tools.compiler.ast.structure.Package)2 ITypeAlias (dyvilx.tools.compiler.ast.type.alias.ITypeAlias)2 ResolvedTypeVarType (dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType)2 Reified (dyvil.annotation.Reified)1 IContext (dyvilx.tools.compiler.ast.context.IContext)1 GenericData (dyvilx.tools.compiler.ast.generic.GenericData)1 PackageType (dyvilx.tools.compiler.ast.type.raw.PackageType)1 CovariantTypeVarType (dyvilx.tools.compiler.ast.type.typevar.CovariantTypeVarType)1