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