Search in sources :

Example 1 with Package

use of dyvilx.tools.compiler.ast.structure.Package 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 Package

use of dyvilx.tools.compiler.ast.structure.Package 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 Package

use of dyvilx.tools.compiler.ast.structure.Package 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 4 with Package

use of dyvilx.tools.compiler.ast.structure.Package in project Dyvil by Dyvil.

the class Library method resolvePackage.

public Package resolvePackage(String internal) {
    Package pack = this.packages.get(internal);
    if (pack != null) {
        return pack;
    }
    if (!this.isSubPackage(internal)) {
        return null;
    }
    int currentIndex = internal.indexOf('/');
    if (currentIndex < 0) {
        return Package.rootPackage.createSubPackage(internal);
    }
    String currentPart = internal.substring(0, currentIndex);
    pack = Package.rootPackage.createSubPackage(currentPart);
    if (pack == null) {
        return null;
    }
    do {
        int endIndex = internal.indexOf('/', currentIndex + 1);
        if (endIndex < 0) {
            endIndex = internal.length();
        }
        if (endIndex - currentIndex <= 0) {
            break;
        }
        currentPart = internal.substring(currentIndex + 1, endIndex);
        pack = pack.createSubPackage(currentPart);
        if (pack == null) {
            return null;
        }
        currentIndex = endIndex;
    } while (true);
    return pack;
}
Also used : Package(dyvilx.tools.compiler.ast.structure.Package)

Example 5 with Package

use of dyvilx.tools.compiler.ast.structure.Package in project Dyvil by Dyvil.

the class NamedType method resolveWithParent.

private IType resolveWithParent(MarkerList markers) {
    final IClass theClass = this.parent.resolveClass(this.name);
    if (theClass != null) {
        return new ResolvedClassType(theClass, this.position);
    }
    final Package thePackage = this.parent.resolvePackage(this.name);
    if (thePackage != null) {
        return new PackageType(thePackage).atPosition(this.position);
    }
    if (markers == null) {
        // FieldAccess support
        return null;
    }
    markers.add(Markers.semanticError(this.position, "resolve.type.package", this.name, this.parent));
    return this;
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) Package(dyvilx.tools.compiler.ast.structure.Package)

Aggregations

Package (dyvilx.tools.compiler.ast.structure.Package)7 IClass (dyvilx.tools.compiler.ast.classes.IClass)5 IType (dyvilx.tools.compiler.ast.type.IType)3 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)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 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)1 IHeaderUnit (dyvilx.tools.compiler.ast.header.IHeaderUnit)1 ImportDeclaration (dyvilx.tools.compiler.ast.imports.ImportDeclaration)1