Search in sources :

Example 1 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass 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 2 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass 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 IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class Types method addSuperClasses.

private static void addSuperClasses(IType type, Collection<IClass> types) {
    final IClass theClass = type.getTheClass();
    if (theClass == null) {
        return;
    }
    types.add(theClass);
    final IType superType = theClass.getSuperType();
    if (superType != null) {
        addSuperClasses(superType, types);
    }
    final TypeList interfaces = theClass.getInterfaces();
    if (interfaces == null) {
        return;
    }
    for (int i = 0, count = interfaces.size(); i < count; i++) {
        addSuperClasses(interfaces.get(i), types);
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) TypeList(dyvilx.tools.compiler.ast.type.TypeList) IType(dyvilx.tools.compiler.ast.type.IType)

Example 4 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass 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 IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class Package method resolveClass.

@Override
public IClass resolveClass(Name name) {
    for (IHeaderUnit c : this.headers) {
        if (c.getName() == name) {
            return c.getClass(name);
        }
    }
    for (IClass c : this.classes) {
        if (c.getName() == name) {
            return c;
        }
    }
    String qualifiedName = name.qualified;
    // Check for inner / nested / anonymous classes
    final int cashIndex = qualifiedName.lastIndexOf('$');
    if (cashIndex < 0) {
        return this.loadClass(name, qualifiedName);
    }
    final Name outerName = Name.fromRaw(qualifiedName.substring(0, cashIndex));
    final Name innerName = Name.fromRaw(qualifiedName.substring(cashIndex + 1));
    final IClass outerClass = this.resolveClass(outerName);
    if (outerClass != null) {
        return outerClass.resolveClass(innerName);
    }
    return this.loadClass(name, qualifiedName);
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) IHeaderUnit(dyvilx.tools.compiler.ast.header.IHeaderUnit) Name(dyvil.lang.Name)

Aggregations

IClass (dyvilx.tools.compiler.ast.classes.IClass)57 IType (dyvilx.tools.compiler.ast.type.IType)23 Marker (dyvilx.tools.parsing.marker.Marker)9 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)6 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)5 Package (dyvilx.tools.compiler.ast.structure.Package)5 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)4 Name (dyvil.lang.Name)3 IValue (dyvilx.tools.compiler.ast.expression.IValue)3 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)3 IHeaderUnit (dyvilx.tools.compiler.ast.header.IHeaderUnit)3 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)2 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)2 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)2 TypeList (dyvilx.tools.compiler.ast.type.TypeList)2 ITypeAlias (dyvilx.tools.compiler.ast.type.alias.ITypeAlias)2 PackageType (dyvilx.tools.compiler.ast.type.raw.PackageType)2 ResolvedTypeVarType (dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType)2 Handle (dyvilx.tools.asm.Handle)1 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)1