Search in sources :

Example 21 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class NullableType method withAnnotation.

@Override
public IType withAnnotation(Annotation annotation) {
    switch(annotation.getTypeDescriptor()) {
        case AnnotationUtil.NOTNULL_INTERNAL:
            return this.type;
        case AnnotationUtil.NULLABLE_INTERNAL:
            return this;
    }
    final IType withAnnotation = this.type.withAnnotation(annotation);
    if (withAnnotation == null) {
        return null;
    }
    this.type = withAnnotation;
    return this;
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 22 with IType

use of dyvilx.tools.compiler.ast.type.IType 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 23 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class NamedType method resolveTopLevel.

private IType resolveTopLevel(MarkerList markers, IContext context) {
    final IType primitive = Types.resolvePrimitive(this.name);
    if (primitive != null) {
        return primitive.atPosition(this.position);
    }
    IType type = this.resolveTopLevelWith(markers, context);
    if (type != null) {
        return type;
    }
    type = this.resolveTopLevelWith(markers, Types.BASE_CONTEXT);
    if (type != null) {
        return type;
    }
    if (markers == null) {
        // FieldAccess support
        return null;
    }
    markers.add(Markers.semanticError(this.position, "resolve.type", this.name));
    return this;
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 24 with IType

use of dyvilx.tools.compiler.ast.type.IType 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 25 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class TypeAlias method checkMatch.

// Resolution
@Override
public void checkMatch(MatchList<ITypeAlias> matches, IType receiver, Name name, TypeList arguments) {
    if (name != this.name && name != null) {
        return;
    }
    if (arguments == null) {
        matches.add(new Candidate<>(this));
        return;
    }
    final int size = arguments.size();
    if (size != this.typeArity()) {
        matches.add(new Candidate<>(this, true));
        return;
    }
    final int[] matchValues = new int[size];
    final IType[] matchTypes = new IType[size];
    boolean invalid = false;
    for (int i = 0; i < size; i++) {
        final IType bound = this.typeParameters.get(i).getUpperBound();
        final IType argument = arguments.get(i);
        final int match = Types.getTypeMatch(bound, argument);
        if (match == IValue.MISMATCH) {
            invalid = true;
        }
        matchValues[i] = match;
        matchTypes[i] = bound;
    }
    matches.add(new Candidate<>(this, matchValues, matchTypes, 0, 0, invalid));
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IType (dyvilx.tools.compiler.ast.type.IType)159 IClass (dyvilx.tools.compiler.ast.classes.IClass)26 Marker (dyvilx.tools.parsing.marker.Marker)23 IValue (dyvilx.tools.compiler.ast.expression.IValue)21 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)13 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)11 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)10 SourcePosition (dyvil.source.position.SourcePosition)9 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)9 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)9 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)9 TypeList (dyvilx.tools.compiler.ast.type.TypeList)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 IVariable (dyvilx.tools.compiler.ast.field.IVariable)6 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)6 MethodWriter (dyvilx.tools.compiler.backend.MethodWriter)6 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Name (dyvil.lang.Name)4