use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class CodeMethod method checkOverrideMethods.
private void checkOverrideMethods(MarkerList markers) {
if (this.checkNoOverride(markers)) {
return;
}
final ITypeContext typeContext = this.enclosingClass.getThisType();
this.filterOverrides(markers, typeContext);
if (this.checkNoOverride(markers)) {
return;
}
if (!this.isOverride() && !this.attributes.hasFlag(Modifiers.GENERATED)) {
markers.add(Markers.semantic(this.position, "method.overrides", this.name));
}
final boolean thisTypeResolved = this.type.isResolved();
for (IMethod overrideMethod : this.overrideMethods) {
ModifierUtil.checkOverride(this, overrideMethod, markers);
if (!thisTypeResolved) {
continue;
}
final IType superReturnType = overrideMethod.getType().getConcreteType(typeContext);
if (// avoid extra error
superReturnType != this.type && superReturnType.isResolved() && !Types.isSuperType(superReturnType.asParameterType(), this.type)) {
final Marker marker = Markers.semanticError(this.position, "method.override.type.incompatible", this.name);
marker.addInfo(Markers.getSemantic("method.type", this.type));
marker.addInfo(Markers.getSemantic("method.override.type", superReturnType));
addOverrideInfo(typeContext, overrideMethod, marker);
markers.add(marker);
}
}
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class CodeMethod method resolveTypes.
@Override
public void resolveTypes(MarkerList markers, IContext context) {
if (this.thisType != null) {
// Resolve the explicit receiver type, but do not expose type parameters of this method
this.thisType = this.thisType.resolveType(markers, context);
// Check the self type for compatibility
final IType thisType = this.thisType;
final IClass thisClass = thisType.getTheClass();
if (!this.isStatic() && thisClass != null && thisClass != this.enclosingClass) {
final Marker marker = Markers.semanticError(thisType.getPosition(), "method.this_type.incompatible", this.getName());
marker.addInfo(Markers.getSemantic("method.this_type", thisType));
marker.addInfo(Markers.getSemantic("method.enclosing_class", this.enclosingClass.getFullName()));
markers.add(marker);
}
} else {
this.thisType = this.enclosingClass.getThisType();
}
context = context.push(this);
if (this.typeParameters != null) {
this.typeParameters.resolveTypes(markers, context);
}
// Return type has to be resolved after type parameters
super.resolveTypes(markers, context);
this.parameters.resolveTypes(markers, context);
if (this.parameters.isLastVariadic()) {
this.attributes.addFlag(Modifiers.ACC_VARARGS);
}
if (this.exceptions != null) {
this.exceptions.resolveTypes(markers, context);
}
if (this.value != null) {
this.value.resolveTypes(markers, context);
}
context.pop();
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class ArgumentList method checkVarargsMatch.
protected static //
int checkVarargsMatch(//
int[] matchValues, //
IType[] matchTypes, //
int matchStartIndex, //
IValue[] values, //
int startIndex, //
int endIndex, IParameter param, IImplicitContext implicitContext) {
final IValue argument = values[startIndex];
final IType paramType = param.getCovariantType();
final int matchIndex = matchStartIndex + startIndex;
if (argument.checkVarargs(false)) {
return checkMatch_(matchValues, matchTypes, matchIndex, argument, paramType, implicitContext) ? 0 : MISMATCH;
}
if (startIndex == endIndex) {
return 0;
}
final int count = endIndex - startIndex;
final ArrayExpr arrayExpr = newArrayExpr(values, startIndex, count);
if (!checkMatch_(matchValues, matchTypes, matchIndex, arrayExpr, paramType, implicitContext)) {
return MISMATCH;
}
// We fill the remaining entries that are reserved for the (now wrapped) varargs values with the match value
// of the array expression and the element type
final int value = matchValues[matchIndex];
final IType type = arrayExpr.getElementType();
for (int i = 0; i < count; i++) {
matchValues[matchIndex + i] = value;
matchTypes[matchIndex + i] = type;
}
return count;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class ArgumentList method convertValue.
static IValue convertValue(IValue value, IParameter parameter, GenericData genericData, MarkerList markers, IContext context) {
if (genericData != null && value.isPolyExpression()) {
// Lock available type arguments before type-checking a poly-expression
genericData.lockAvailable();
}
final IType type = parameter.getCovariantType();
final TypeChecker.MarkerSupplier markerSupplier = TypeChecker.markerSupplier("method.access.argument_type", parameter.getName());
return TypeChecker.convertValue(value, type, genericData, markers, context, markerSupplier);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class IParameter method writeParameter.
default void writeParameter(MethodWriter writer) {
final AttributeList annotations = this.getAttributes();
final IType type = this.getInternalType();
final long flags = ModifierUtil.getFlags(this);
final int index = this.getIndex();
final int localIndex = writer.localCount();
this.setLocalIndex(localIndex);
// Add the ACC_VARARGS modifier if necessary
final int javaModifiers = ModifierUtil.getJavaModifiers(flags) | (this.isVarargs() ? Modifiers.ACC_VARARGS : 0);
writer.visitParameter(localIndex, this.getQualifiedLabel(), type, javaModifiers);
// Annotations
final AnnotatableVisitor visitor = (desc, visible) -> writer.visitParameterAnnotation(index, desc, visible);
if (annotations != null) {
annotations.write(visitor);
}
ModifierUtil.writeModifiers(visitor, flags);
IType.writeAnnotations(type, writer, TypeReference.newFormalParameterReference(index), "");
}
Aggregations