Search in sources :

Example 21 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class Annotation method write.

public void write(AnnotationVisitor writer) {
    final IClass iclass = this.type.getTheClass();
    final ParameterList parameterList = iclass.getParameters();
    for (int i = 0, count = parameterList.size(); i < count; i++) {
        final IParameter parameter = parameterList.get(i);
        final IValue argument = this.arguments.get(parameter);
        if (argument != null) {
            argument.writeAnnotationValue(writer, parameter.getName().qualified);
        }
    }
    writer.visitEnd();
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass)

Example 22 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class CodeAnnotation method check.

@Override
public void check(MarkerList markers, IContext context, ElementType target) {
    super.check(markers, context, target);
    if (this.type == null || !this.type.isResolved()) {
        return;
    }
    final IClass theClass = this.type.getTheClass();
    if (theClass == null) {
        return;
    }
    if (!theClass.isAnnotation()) {
        markers.add(Markers.semanticError(this.position, "annotation.type", this.type.getName()));
        return;
    }
    if (target == null) {
        return;
    }
    final IClassMetadata metadata = theClass.getMetadata();
    if (!metadata.isTarget(target)) {
        final Marker error = Markers.semanticError(this.position, "annotation.target", this.type.getName());
        error.addInfo(Markers.getSemantic("annotation.target.element", target));
        error.addInfo(Markers.getSemantic("annotation.target.allowed", metadata.getTargets()));
        markers.add(error);
    }
}
Also used : IClassMetadata(dyvilx.tools.compiler.ast.classes.metadata.IClassMetadata) IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker)

Example 23 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class CodeMethod method filterOverride.

private boolean filterOverride(IMethod candidate, MarkerList markers, ITypeContext typeContext) {
    final String candidateInternalName = candidate.getInternalName();
    final boolean sameName = this.name == candidate.getName();
    final boolean sameInternalName = this.getInternalName().equals(candidateInternalName);
    if (// same name but different internal name
    sameName && !sameInternalName) {
        if (this.name.qualified.equals(this.internalName)) // no AutoMangled or BytecodeName annotation, otherwise the user probably knows what they are doing and
        // doesn't need a warning
        {
            final Marker marker = Markers.semantic(this.position, "method.override.mangled_mismatch", this.name, candidateInternalName);
            marker.addInfo(Markers.getSemantic("method.override.mangled_mismatch.info", candidateInternalName));
            markers.add(marker);
        }
        return true;
    }
    if (!sameName && sameInternalName) {
        final Marker marker = Markers.semanticError(this.position, "method.override.mangled_clash", this.name, candidate.getName(), candidateInternalName);
        marker.addInfo(Markers.getSemantic("method.override.mangled_clash.info"));
        // hard error so it doesn't matter if we remove or not - bytecode will never be generated
        return true;
    }
    // sameName && sameInternalName should be true
    final IClass enclosingClass = candidate.getEnclosingClass();
    boolean errors = true;
    for (IMethod method : this.overrideMethods) {
        if (method != candidate && method.getEnclosingClass() == enclosingClass) {
            // If this method overrides two methods from the same class, we do not produce any parameter label errors
            errors = false;
        }
    }
    final ParameterList params = candidate.getParameters();
    for (int i = 0, count = params.size(); i < count; i++) {
        final IParameter thisParam = this.parameters.get(i);
        final Name thisName = thisParam.getLabel();
        final Name otherName = params.get(i).getLabel();
        if (thisName == otherName || thisName == null || otherName == null) {
            // Parameter labels match
            continue;
        }
        if (errors) {
            final Marker marker = Markers.semantic(thisParam.getPosition(), "method.override.parameter_label", i + 1, thisName, otherName);
            addOverrideInfo(typeContext, candidate, marker);
            markers.add(marker);
        }
        // This method does not properly override the candidate
        return true;
    }
    return false;
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) Marker(dyvilx.tools.parsing.marker.Marker) IClass(dyvilx.tools.compiler.ast.classes.IClass) Name(dyvil.lang.Name)

Example 24 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass 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 25 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class IParameter method writeGetDefaultValue.

default void writeGetDefaultValue(MethodWriter writer) {
    final ICallableMember method = this.getMethod();
    final IClass enclosingClass = this.getEnclosingClass();
    final String name = (method == null ? DEFAULT_PREFIX_INIT : method.getInternalName() + DEFAULT_PREFIX) + this.getInternalName();
    final String desc = "()" + this.getDescriptor();
    writer.visitMethodInsn(Opcodes.INVOKESTATIC, enclosingClass.getInternalName(), name, desc, enclosingClass.isInterface());
}
Also used : ICallableMember(dyvilx.tools.compiler.ast.method.ICallableMember) IClass(dyvilx.tools.compiler.ast.classes.IClass)

Aggregations

IClass (dyvilx.tools.compiler.ast.classes.IClass)57 IType (dyvilx.tools.compiler.ast.type.IType)23 Marker (dyvilx.tools.parsing.marker.Marker)9 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)6 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)5 Package (dyvilx.tools.compiler.ast.structure.Package)5 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)4 Name (dyvil.lang.Name)3 IValue (dyvilx.tools.compiler.ast.expression.IValue)3 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)3 IHeaderUnit (dyvilx.tools.compiler.ast.header.IHeaderUnit)3 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)2 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)2 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)2 TypeList (dyvilx.tools.compiler.ast.type.TypeList)2 ITypeAlias (dyvilx.tools.compiler.ast.type.alias.ITypeAlias)2 PackageType (dyvilx.tools.compiler.ast.type.raw.PackageType)2 ResolvedTypeVarType (dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType)2 Handle (dyvilx.tools.asm.Handle)1 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)1