Search in sources :

Example 71 with IType

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);
        }
    }
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IType(dyvilx.tools.compiler.ast.type.IType)

Example 72 with IType

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();
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 73 with IType

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;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue) IType(dyvilx.tools.compiler.ast.type.IType)

Example 74 with IType

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);
}
Also used : TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 75 with IType

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), "");
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) MethodWriterImpl(dyvilx.tools.compiler.backend.MethodWriterImpl) Name(dyvil.lang.Name) IContext(dyvilx.tools.compiler.ast.context.IContext) IClassMember(dyvilx.tools.compiler.ast.member.IClassMember) AnnotationReader(dyvilx.tools.compiler.backend.visitor.AnnotationReader) IType(dyvilx.tools.compiler.ast.type.IType) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) Opcodes(dyvil.reflect.Opcodes) IVariable(dyvilx.tools.compiler.ast.field.IVariable) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) AnnotatableVisitor(dyvilx.tools.asm.AnnotatableVisitor) ModifierUtil(dyvilx.tools.compiler.ast.attribute.modifiers.ModifierUtil) ClassWriter(dyvilx.tools.compiler.backend.ClassWriter) ICallableMember(dyvilx.tools.compiler.ast.method.ICallableMember) BytecodeException(dyvilx.tools.compiler.backend.exception.BytecodeException) DummyValue(dyvilx.tools.compiler.ast.expression.DummyValue) Modifiers(dyvil.reflect.Modifiers) AnnotationVisitor(dyvilx.tools.asm.AnnotationVisitor) MethodWriter(dyvilx.tools.compiler.backend.MethodWriter) TypeReference(dyvilx.tools.asm.TypeReference) IClass(dyvilx.tools.compiler.ast.classes.IClass) InternalType(dyvilx.tools.compiler.ast.type.raw.InternalType) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) AnnotatableVisitor(dyvilx.tools.asm.AnnotatableVisitor) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IType (dyvilx.tools.compiler.ast.type.IType)159 IClass (dyvilx.tools.compiler.ast.classes.IClass)26 Marker (dyvilx.tools.parsing.marker.Marker)23 IValue (dyvilx.tools.compiler.ast.expression.IValue)21 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)13 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)11 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)10 SourcePosition (dyvil.source.position.SourcePosition)9 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)9 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)9 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)9 TypeList (dyvilx.tools.compiler.ast.type.TypeList)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 IVariable (dyvilx.tools.compiler.ast.field.IVariable)6 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)6 MethodWriter (dyvilx.tools.compiler.backend.MethodWriter)6 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Name (dyvil.lang.Name)4