Search in sources :

Example 21 with IMethod

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

the class ClassMetadata method checkMembers.

private void checkMembers(ClassBody body) {
    for (int i = 0, count = body.methodCount(); i < count; i++) {
        this.checkMethod(body.getMethod(i));
    }
    for (int i = 0, count = body.propertyCount(); i < count; i++) {
        final IMethod getter = body.getProperty(i).getGetter();
        if (getter != null) {
            this.checkMethod(getter);
        }
    // only check the getter
    }
    for (int i = 0, count = body.fieldCount(); i < count; i++) {
        final IField field = body.getField(i);
        this.checkField(field);
        final IProperty property = field.getProperty();
        final IMethod getter;
        if (property != null && (getter = property.getGetter()) != null) {
            this.checkMethod(getter);
        }
    // only check the getter
    }
}
Also used : IProperty(dyvilx.tools.compiler.ast.field.IProperty) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IField(dyvilx.tools.compiler.ast.field.IField)

Example 22 with IMethod

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

the class InterfaceMetadata method getFunctionalMethod.

@Override
public IMethod getFunctionalMethod() {
    if (this.functionalMethodSearched) {
        return this.functionalMethod;
    }
    this.functionalMethodSearched = true;
    final ClassBody body = this.theClass.getBody();
    if (body == null) {
        return null;
    }
    for (IMethod method : body.allMethods()) {
        if (method.isFunctional()) {
            if (this.functionalMethod != null) {
                // duplicate detected
                return this.functionalMethod = null;
            }
            this.functionalMethod = method;
        }
    }
    return this.functionalMethod;
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 23 with IMethod

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

Example 24 with IMethod

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

the class MethodCall method resolveImplicitCall.

protected IValue resolveImplicitCall(MarkerList markers, IContext context) {
    final IValue implicit = context.resolveImplicit(null);
    if (implicit == null) {
        return null;
    }
    final IMethod method = ICall.resolveMethod(context, implicit, this.name, this.arguments);
    if (method == null) {
        return null;
    }
    this.receiver = implicit;
    return this.checkArguments(markers, context, method);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 25 with IMethod

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

the class LiteralConversion method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (this.method == null) {
        final MatchList<IMethod> candidates = IContext.resolveMethods(type, null, this.name, this.arguments);
        if (candidates.isEmpty()) {
            this.type = type;
            this.reportResolve(markers, candidates);
            return this;
        } else if (candidates.isAmbigous()) {
            this.type = type;
            super.reportResolve(markers, candidates);
            return this;
        }
        return this.checkArguments(markers, context, candidates.getBestMember()).withType(type, typeContext, markers, // will probably recurse
        context);
    }
    final IType thisType = this.getType();
    if (Types.isSuperType(type, thisType)) {
        return this;
    }
    // T! -> T, if necessary
    final IValue value = thisType.convertTo(this, type, typeContext, markers, context);
    if (value != null) {
        return value;
    }
    final Marker marker = Markers.semanticError(this.position, "literal.type.incompatible");
    marker.addInfo(Markers.getSemantic("type.expected", type));
    marker.addInfo(Markers.getSemantic("literal.type.conversion", thisType));
    marker.addInfo(Markers.getSemantic("literal.type.method", Util.methodSignatureToString(this.method, typeContext)));
    markers.add(marker);
    return this;
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

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