Search in sources :

Example 16 with IMethod

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;
}
Also used : IProperty(dyvilx.tools.compiler.ast.field.IProperty) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 17 with IMethod

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);
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 18 with IMethod

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);
    }
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 19 with IMethod

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;
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 20 with IMethod

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);
    }
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Aggregations

IMethod (dyvilx.tools.compiler.ast.method.IMethod)31 IValue (dyvilx.tools.compiler.ast.expression.IValue)6 IField (dyvilx.tools.compiler.ast.field.IField)4 IProperty (dyvilx.tools.compiler.ast.field.IProperty)4 IType (dyvilx.tools.compiler.ast.type.IType)3 TreeSet (dyvil.collection.mutable.TreeSet)2 Name (dyvil.lang.Name)2 SourcePosition (dyvil.source.position.SourcePosition)2 IContext (dyvilx.tools.compiler.ast.context.IContext)2 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)2 IImportContext (dyvilx.tools.compiler.ast.imports.IImportContext)2 ImportDeclaration (dyvilx.tools.compiler.ast.imports.ImportDeclaration)2 MatchList (dyvilx.tools.compiler.ast.method.MatchList)2 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)2 PrintStream (java.io.PrintStream)2 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)1 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)1 IImplicitContext (dyvilx.tools.compiler.ast.context.IImplicitContext)1