use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.
the class ClassBody method getMethodMatches.
public void getMethodMatches(MatchList<IMethod> list, IValue receiver, Name name, ArgumentList arguments) {
if (name == null) {
for (IMethod method : this.methods()) {
method.checkMatch(list, receiver, null, arguments);
}
for (IProperty property : this.allProperties()) {
property.checkMatch(list, receiver, null, arguments);
}
return;
}
final MethodLink[] cache = this.getNamedMethodCache();
if (cache.length == 0) {
// no methods
return;
}
final int hash = hash(name);
final int index = hash & (cache.length - 1);
for (MethodLink link = cache[index]; link != null; link = link.next) {
if (link.hash == hash) {
link.method.checkMatch(list, receiver, name, arguments);
}
}
return;
}
use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.
the class ClassBody method checkPropertyImplements.
public static boolean checkPropertyImplements(IProperty property, IMethod candidate, ITypeContext typeContext) {
final IMethod getter = property.getGetter();
final IMethod setter = property.getSetter();
return getter != null && checkMethodImplements(getter, candidate, typeContext) || setter != null && checkMethodImplements(setter, candidate, typeContext);
}
use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.
the class ClassBody method addToCache.
private void addToCache(IProperty property) {
final IMethod getter = property.getGetter();
if (getter != null) {
this.addToCache(getter);
}
final IMethod setter = property.getSetter();
if (setter != null) {
this.addToCache(setter);
}
}
use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.
the class ClassBody method getNamedMethodCache.
// Cache
public MethodLink[] getNamedMethodCache() {
if (this.namedMethodCache != null) {
return this.namedMethodCache;
}
/*
* The cache size is calculated as follows: We sum the number of methods assuming they all have unique names, add
* twice the amount of properties with the same assumption and half the amount of fields, assuming there are
* as many property getters and setters as there are fields. At the end, we compute the next power of two that
* is larger than our sum, and use it as the cache size.
*/
final int cacheSize = MathUtils.nextPowerOf2(this.methodCount + (this.propertyCount << 1) + this.fieldCount);
final int mask = cacheSize - 1;
this.namedMethodCache = new MethodLink[cacheSize];
for (IMethod method : this.allMethods()) {
addToCache(this.namedMethodCache, method, mask);
}
return this.namedMethodCache;
}
use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.
the class ClassBody method addPropertyMethods.
private static void addPropertyMethods(ArrayList.Builder<IMethod> builder, IProperty prop) {
final IMethod getter = prop.getGetter();
if (getter != null) {
builder.add(getter);
}
final IMethod setter = prop.getSetter();
if (setter != null) {
builder.add(setter);
}
}
Aggregations