use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class FieldAssignment method capture.
@Override
protected void capture(MarkerList markers, IContext context) {
this.field = this.field.capture(context);
// in case the field was captured, this ensures reference capture takes place
if (!this.field.setAssigned()) {
final Marker marker = Markers.semanticError(this.position, "reference.variable.assignment", Util.memberNamed(this.field));
markers.add(marker);
}
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class SuperExpr method resolveTypes.
@Override
public void resolveTypes(MarkerList markers, IContext context) {
if (!context.isThisAvailable()) {
markers.add(Markers.semantic(this.position, "super.access.static"));
return;
}
if (this.type != Types.UNKNOWN) {
this.type = this.type.resolveType(markers, context);
if (this.type.isResolved()) {
this.checkSuperType(markers, context);
}
return;
}
final IClass enclosingClass = context.getThisClass();
final IType superType = enclosingClass.getSuperType();
if (superType == null) {
final Marker marker = Markers.semanticError(this.position, "super.access.type");
marker.addInfo(Markers.getSemantic("type.enclosing", enclosingClass.getClassType()));
markers.add(marker);
return;
}
this.type = superType;
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class SuperExpr method checkSuperType.
private void checkSuperType(MarkerList markers, IContext context) {
final IClass superClass = this.type.getTheClass();
final IClass enclosingClass = context.getThisClass();
final IType enclosingType = enclosingClass.getClassType();
final String message;
boolean indirectSuperInterface = false;
if (superClass == enclosingClass) {
// The specified type is the same as the enclosing type
message = "super.type.enclosing";
} else if (!Types.isSuperType(this.type, enclosingType)) {
message = "super.type.invalid";
} else {
// Check if the specified type is either the direct super type or a direct super interface
final IType superType = enclosingClass.getSuperType();
if (superType.isSameClass(this.type)) {
this.type = superType;
return;
}
if (superClass.isInterface()) {
final TypeList interfaces = enclosingClass.getInterfaces();
if (interfaces != null) {
for (int i = 0, count = interfaces.size(); i < count; i++) {
final IType interfaceType = interfaces.get(i);
if (interfaceType.isSameClass(this.type)) {
this.type = interfaceType;
return;
}
}
}
indirectSuperInterface = true;
}
message = "super.type.indirect";
}
final Marker marker = Markers.semanticError(this.type.getPosition(), message);
if (indirectSuperInterface) {
marker.addInfo(Markers.getSemantic("super.type.interface.info", this.type, enclosingClass.getName()));
}
marker.addInfo(Markers.getSemantic("type.enclosing", enclosingType));
marker.addInfo(Markers.getSemantic("super.type.requested", this.type));
markers.add(marker);
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class IDataMember method checkAssign.
default IValue checkAssign(MarkerList markers, IContext context, SourcePosition position, IValue receiver, IValue newValue) {
if (this.hasModifier(Modifiers.FINAL) && !context.isConstructor()) {
markers.add(Markers.semanticError(position, this.getKind().getName() + ".assign.final", this.getName()));
}
final IType type = this.getType();
final ITypeContext typeContext = receiver == null ? ITypeContext.NULL : receiver.getType();
final TypeChecker.MarkerSupplier markerSupplier = (errorPosition, expected, actual) -> {
final String kindName = this.getKind().getName();
final Marker marker = Markers.semanticError(errorPosition, kindName + ".assign.type", this.getName());
marker.addInfo(Markers.getSemantic(kindName + ".type", expected));
marker.addInfo(Markers.getSemantic("value.type", actual));
return marker;
};
return TypeChecker.convertValue(newValue, type, typeContext, markers, context, markerSupplier);
}
use of dyvilx.tools.parsing.marker.Marker 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