Search in sources :

Example 6 with IType

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

the class NamedGenericType method checkCount.

private IType checkCount(MarkerList markers, ITypeParametric generic, String kind, IType type) {
    final int genericArity = generic.typeArity();
    if (genericArity <= 0) {
        markers.add(Markers.semanticError(this.position, "type.generic." + kind + ".not_generic", type));
        return type.atPosition(this.position);
    }
    if (genericArity != this.arguments.size()) {
        final Marker marker = Markers.semanticError(this.position, "type.generic." + kind + ".count_mismatch", type);
        marker.addInfo(Markers.getSemantic("type.generic.argument_count", this.arguments.size()));
        marker.addInfo(Markers.getSemantic("type.generic.parameter_count", genericArity));
        markers.add(marker);
    }
    return type.getConcreteType(typeParameter -> this.arguments.get(typeParameter.getIndex())).atPosition(this.position);
}
Also used : DataOutput(java.io.DataOutput) IContext(dyvilx.tools.compiler.ast.context.IContext) Package(dyvilx.tools.compiler.ast.structure.Package) Name(dyvil.lang.Name) ResolvedTypeVarType(dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType) IType(dyvilx.tools.compiler.ast.type.IType) IOException(java.io.IOException) Types(dyvilx.tools.compiler.ast.type.builtin.Types) PackageType(dyvilx.tools.compiler.ast.type.raw.PackageType) Marker(dyvilx.tools.parsing.marker.Marker) ITypeAlias(dyvilx.tools.compiler.ast.type.alias.ITypeAlias) ITypeParametric(dyvilx.tools.compiler.ast.generic.ITypeParametric) Markers(dyvilx.tools.compiler.util.Markers) SourcePosition(dyvil.source.position.SourcePosition) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) TypeList(dyvilx.tools.compiler.ast.type.TypeList) MarkerList(dyvilx.tools.parsing.marker.MarkerList) DataInput(java.io.DataInput) MatchList(dyvilx.tools.compiler.ast.method.MatchList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IUnresolvedType(dyvilx.tools.compiler.ast.type.raw.IUnresolvedType) Marker(dyvilx.tools.parsing.marker.Marker)

Example 7 with IType

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

the class NamedGenericType method resolveWithParent.

private IType resolveWithParent(MarkerList markers) {
    final IClass theClass = this.parent.resolveClass(this.name);
    if (theClass != null) {
        final IType classType = theClass.getThisType();
        return this.checkCount(markers, theClass, "class", classType);
    }
    final Package thePackage = this.parent.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);
    }
    markers.add(Markers.semanticError(this.position, "resolve.type.package", this.name, this.parent));
    return this;
}
Also used : PackageType(dyvilx.tools.compiler.ast.type.raw.PackageType) IClass(dyvilx.tools.compiler.ast.classes.IClass) Package(dyvilx.tools.compiler.ast.structure.Package) IType(dyvilx.tools.compiler.ast.type.IType)

Example 8 with IType

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

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

the class PostfixType method resolveType.

@Override
public IType resolveType(MarkerList markers, IContext context) {
    final String unqualified = this.name.unqualified;
    final IType argument = this.arguments.get(0);
    if (unqualified.length() == 1) {
        switch(unqualified.charAt(0)) {
            case '?':
                return NullableType.apply(argument).resolveType(markers, context);
            case '!':
                return new ImplicitNullableType(argument).resolveType(markers, context);
            case '*':
                return new ReferenceType(argument).resolveType(markers, context);
            case '^':
                return new ImplicitReferenceType(argument).resolveType(markers, context);
        }
    }
    return super.resolveType(markers, context);
}
Also used : ImplicitNullableType(dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType) ImplicitReferenceType(dyvilx.tools.compiler.ast.reference.ImplicitReferenceType) ImplicitReferenceType(dyvilx.tools.compiler.ast.reference.ImplicitReferenceType) ReferenceType(dyvilx.tools.compiler.ast.reference.ReferenceType) IType(dyvilx.tools.compiler.ast.type.IType)

Example 10 with IType

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

the class CatchBlock method check.

@Override
public void check(MarkerList markers, IContext context) {
    this.variable.check(markers, context);
    final IType type = this.variable.getType();
    if (!Types.isSuperType(Types.THROWABLE, type)) {
        final Marker marker = Markers.semanticError(this.variable.getPosition(), "try.catch.type.not_throwable");
        marker.addInfo(Markers.getSemantic("exception.type", type));
        markers.add(marker);
    }
    context = context.push(this);
    this.action.check(markers, context);
    context.pop();
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) 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