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);
}
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;
}
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;
}
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);
}
}
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
}
Aggregations