Search in sources :

Example 1 with IHeaderUnit

use of dyvilx.tools.compiler.ast.header.IHeaderUnit 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)

Example 2 with IHeaderUnit

use of dyvilx.tools.compiler.ast.header.IHeaderUnit in project Dyvil by Dyvil.

the class ClassConstructorCall method resolve.

@Override
public IValue resolve(MarkerList markers, IContext context) {
    this.type.resolve(markers, context);
    this.arguments.resolve(markers, context);
    this.resolveCall(markers, context, true);
    final IClass enclosingClass = context.getThisClass();
    assert enclosingClass != null;
    this.nestedClass.setConstructor(this.constructor);
    this.nestedClass.setEnclosingClass(enclosingClass);
    final IHeaderUnit header = enclosingClass.getHeader();
    assert header != null;
    this.nestedClass.setHeader(header);
    header.addCompilable(this.nestedClass);
    this.nestedClass.resolve(markers, context);
    return this;
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) IHeaderUnit(dyvilx.tools.compiler.ast.header.IHeaderUnit)

Example 3 with IHeaderUnit

use of dyvilx.tools.compiler.ast.header.IHeaderUnit in project Dyvil by Dyvil.

the class AbstractClass method getVisibility.

@Override
public byte getVisibility(IClassMember member) {
    final IClass enclosingClass = member.getEnclosingClass();
    if (enclosingClass == this) {
        return VISIBLE;
    }
    int level = member.getAccessLevel();
    if ((level & Modifiers.INTERNAL) != 0) {
        if (enclosingClass instanceof ExternalClass) {
            return INTERNAL;
        }
        level &= ~Modifiers.INTERNAL;
    }
    if (level == Modifiers.PUBLIC) {
        return VISIBLE;
    }
    if (level == Modifiers.PROTECTED || level == Modifiers.PRIVATE_PROTECTED) {
        if (Types.isSuperClass(enclosingClass, this)) {
            // The enclosing class of the member is a super class of this
            return VISIBLE;
        }
    }
    if (level == Modifiers.PROTECTED || level == Modifiers.PACKAGE) {
        final IHeaderUnit thisUnit = this.getHeader();
        final IHeaderUnit memberUnit = enclosingClass.getHeader();
        if (thisUnit != null && memberUnit != null && thisUnit.getPackage() == memberUnit.getPackage()) {
            // The two units are in the same package
            return VISIBLE;
        }
    }
    return INVISIBLE;
}
Also used : ExternalClass(dyvilx.tools.compiler.ast.external.ExternalClass) IHeaderUnit(dyvilx.tools.compiler.ast.header.IHeaderUnit)

Example 4 with IHeaderUnit

use of dyvilx.tools.compiler.ast.header.IHeaderUnit in project Dyvil by Dyvil.

the class ClassBody method resolveTypes.

// endregion
// region Phases
@Override
public void resolveTypes(MarkerList markers, IContext context) {
    final IHeaderUnit header = this.enclosingClass.getHeader();
    for (int i = 0; i < this.classCount; i++) {
        final IClass innerClass = this.classes[i];
        innerClass.setHeader(header);
        innerClass.resolveTypes(markers, context);
    }
    for (int i = 0; i < this.fieldCount; i++) {
        this.fields[i].resolveTypes(markers, context);
    }
    for (int i = 0; i < this.propertyCount; i++) {
        this.properties[i].resolveTypes(markers, context);
    }
    for (int i = 0; i < this.methodCount; i++) {
        this.methods[i].resolveTypes(markers, context);
    }
    for (int i = 0; i < this.constructorCount; i++) {
        this.constructors[i].resolveTypes(markers, context);
    }
    for (int i = 0; i < this.initializerCount; i++) {
        this.initializers[i].resolveTypes(markers, context);
    }
}
Also used : IHeaderUnit(dyvilx.tools.compiler.ast.header.IHeaderUnit)

Example 5 with IHeaderUnit

use of dyvilx.tools.compiler.ast.header.IHeaderUnit in project Dyvil by Dyvil.

the class SingleImport method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context, IImportContext parentContext, int mask) {
    if (this.parent != null) {
        this.parent.resolveTypes(markers, context, parentContext, KindedImport.PARENT);
        parentContext = this.parent.asParentContext();
    }
    boolean resolved = false;
    this.resolver = parentContext;
    this.mask = mask;
    if ((mask & KindedImport.CLASS) != 0) {
        final IClass theClass = parentContext.resolveClass(this.name);
        if (theClass != null) {
            this.asParentContext = theClass;
            resolved = true;
        }
    }
    if ((mask & KindedImport.HEADER) != 0) {
        final IHeaderUnit header = parentContext.resolveHeader(this.name);
        if (header != null) {
            if ((mask & KindedImport.INLINE) != 0 && this.checkInline(markers, context, header)) {
                this.asContext = new CombiningContext(this, header.getContext());
            }
            this.asParentContext = !resolved ? header : new CombiningContext(header, this.asParentContext);
            resolved = true;
        }
    }
    if ((mask & KindedImport.PACKAGE) != 0) {
        final Package thePackage = parentContext.resolvePackage(this.name);
        if (thePackage != null) {
            this.asParentContext = !resolved ? thePackage : new CombiningContext(thePackage, this.asParentContext);
            resolved = true;
        }
    }
    if (!resolved) {
        this.asParentContext = IDefaultContext.DEFAULT;
        if (mask == KindedImport.PARENT) {
            // when resolving as a parent import, the resolve method is never called,
            // so we need the error reporting to happen here.
            this.reportResolve(markers);
        }
    }
// otherwise error later
}
Also used : CombiningContext(dyvilx.tools.compiler.ast.context.CombiningContext) IClass(dyvilx.tools.compiler.ast.classes.IClass) Package(dyvilx.tools.compiler.ast.structure.Package) IHeaderUnit(dyvilx.tools.compiler.ast.header.IHeaderUnit)

Aggregations

IHeaderUnit (dyvilx.tools.compiler.ast.header.IHeaderUnit)5 IClass (dyvilx.tools.compiler.ast.classes.IClass)3 Name (dyvil.lang.Name)1 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)1 ExternalClass (dyvilx.tools.compiler.ast.external.ExternalClass)1 Package (dyvilx.tools.compiler.ast.structure.Package)1