Search in sources :

Example 1 with MatchList

use of dyvilx.tools.compiler.ast.method.MatchList in project Dyvil by Dyvil.

the class CompleteCommand method findExtensions.

private static void findExtensions(IContext context, IType type, IValue value, Set<IMethod> methods, String start, boolean statics) {
    final MatchList<IMethod> matchList = new MatchList<>(context, true);
    type.getMethodMatches(matchList, value, null, null);
    context.getMethodMatches(matchList, value, null, null);
    Types.BASE_CONTEXT.getMethodMatches(matchList, value, null, null);
    for (Candidate<IMethod> candidate : matchList) {
        final IMethod member = candidate.getMember();
        if (member.hasModifier(Modifiers.INFIX) || member.getEnclosingClass() != type.getTheClass()) {
            checkMember(methods, member, start, true);
        }
    }
}
Also used : MatchList(dyvilx.tools.compiler.ast.method.MatchList) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 2 with MatchList

use of dyvilx.tools.compiler.ast.method.MatchList in project Dyvil by Dyvil.

the class ICall method resolveMethods.

static MatchList<IMethod> resolveMethods(IContext context, IValue receiver, Name name, ArgumentList arguments) {
    @SuppressWarnings("UnnecessaryLocalVariable") final IImplicitContext implicitContext = context;
    final MatchList<IMethod> matches = new MatchList<>(implicitContext);
    // Methods available via the receiver type
    if (receiver != null) {
        receiver.getType().getMethodMatches(matches, receiver, name, arguments);
        if (matches.hasCandidate()) {
            return matches;
        }
    }
    // Methods available via the first argument
    if (arguments.size() == 1) {
        arguments.getFirst().getType().getMethodMatches(matches, receiver, name, arguments);
        // b) an implicit conversion function from int to SomeType
        if (matches.hasCandidate()) {
            return matches;
        }
    }
    // Methods available in the enclosing context
    context.getMethodMatches(matches, receiver, name, arguments);
    if (matches.hasCandidate()) {
        return matches;
    }
    // Methods available through implicit conversions of the receiver
    if (receiver != null) {
        MatchList<IMethod> implicits = IContext.resolveImplicits(implicitContext, receiver, null);
        for (Candidate<IMethod> candidate : implicits) {
            candidate.getMember().getType().getMethodMatches(matches, receiver, name, arguments);
        }
        // resolved again.
        if (matches.hasCandidate()) {
            return matches;
        }
    }
    // Methods available through the Lang Header
    Types.BASE_CONTEXT.getMethodMatches(matches, receiver, name, arguments);
    return matches;
}
Also used : MatchList(dyvilx.tools.compiler.ast.method.MatchList) IImplicitContext(dyvilx.tools.compiler.ast.context.IImplicitContext) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Aggregations

IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 MatchList (dyvilx.tools.compiler.ast.method.MatchList)2 IImplicitContext (dyvilx.tools.compiler.ast.context.IImplicitContext)1