Search in sources :

Example 16 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter 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 17 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class TypeParameter method computeReifiedKind.

protected void computeReifiedKind() {
    if (this.reifiedKind != null) {
        return;
    }
    final Annotation reifiedAnnotation = this.getAnnotation(Types.REIFIED_CLASS);
    if (reifiedAnnotation != null) {
        final IParameter parameter = Types.REIFIED_CLASS.getParameters().get(0);
        this.reifiedKind = AnnotationUtil.getEnumValue(reifiedAnnotation.getArguments(), parameter, Reified.Type.class);
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) CovariantTypeVarType(dyvilx.tools.compiler.ast.type.typevar.CovariantTypeVarType) IType(dyvilx.tools.compiler.ast.type.IType) Types.isSuperType(dyvilx.tools.compiler.ast.type.builtin.Types.isSuperType) IntersectionType(dyvilx.tools.compiler.ast.type.compound.IntersectionType) ElementType(java.lang.annotation.ElementType) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Example 18 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class CodeClass method writeClassParameters.

private void writeClassParameters(ClassWriter writer) throws BytecodeException {
    final int parameterCount = this.parameters.size();
    if (parameterCount == 0) {
        return;
    }
    final AnnotationVisitor annotationVisitor = writer.visitAnnotation(AnnotationUtil.CLASS_PARAMETERS, false);
    final AnnotationVisitor arrayVisitor = annotationVisitor.visitArray("names");
    for (int i = 0; i < parameterCount; i++) {
        final IParameter parameter = this.parameters.get(i);
        parameter.write(writer);
        arrayVisitor.visit("", parameter.getInternalName());
    }
    arrayVisitor.visitEnd();
    annotationVisitor.visitEnd();
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) AnnotationVisitor(dyvilx.tools.asm.AnnotationVisitor)

Example 19 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class AnnotationMetadata method write.

@Override
public void write(ClassWriter writer) throws BytecodeException {
    for (IParameter parameter : this.theClass.getParameters()) {
        final StringBuilder desc = new StringBuilder("()");
        parameter.getType().appendExtendedName(desc);
        final MethodVisitor methodVisitor = writer.visitMethod(Modifiers.PUBLIC | Modifiers.ABSTRACT, parameter.getInternalName(), desc.toString(), null, null);
        final IValue argument = parameter.getValue();
        if (argument != null && argument.isAnnotationConstant()) {
            final AnnotationVisitor av = methodVisitor.visitAnnotationDefault();
            argument.writeAnnotationValue(av, parameter.getInternalName());
            av.visitEnd();
        }
        methodVisitor.visitEnd();
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) AnnotationVisitor(dyvilx.tools.asm.AnnotationVisitor) MethodVisitor(dyvilx.tools.asm.MethodVisitor)

Example 20 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class CaseClassMetadata method createApplyMethod.

private CodeMethod createApplyMethod() {
    // static final func apply<TypeParams...>(classParams...: ClassParamTypes...) -> This
    final SourcePosition position = this.theClass.position();
    final AttributeList attributes = AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC_FINAL | Modifiers.GENERATED);
    final IType type = this.theClass.getThisType();
    final CodeMethod applyMethod = new CodeMethod(this.theClass, Names.apply, type, attributes);
    applyMethod.setPosition(position);
    applyMethod.getTypeParameters().addAll(this.theClass.getTypeParameters());
    this.copyClassParameters(applyMethod);
    // = new This<TypeParams...>(classParams...)
    final ArgumentList arguments = new ArgumentList();
    for (IParameter param : applyMethod.getParameters()) {
        // no need to check for override class parameters here, since we are dealing with parameters of the
        // apply method
        final IValue access;
        if (param.isVarargs()) {
            access = new VarargsOperator(position, new FieldAccess(param));
        } else {
            access = new FieldAccess(param);
        }
        arguments.add(access);
    }
    // = new This(params...)
    applyMethod.setValue(new ConstructorCall(this.theClass.position(), this.theClass.getThisType(), arguments));
    return applyMethod;
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) CodeMethod(dyvilx.tools.compiler.ast.method.CodeMethod) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) VarargsOperator(dyvilx.tools.compiler.ast.expression.intrinsic.VarargsOperator) SourcePosition(dyvil.source.position.SourcePosition) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)28 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)12 IType (dyvilx.tools.compiler.ast.type.IType)11 IValue (dyvilx.tools.compiler.ast.expression.IValue)9 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 SourcePosition (dyvil.source.position.SourcePosition)5 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)5 IClass (dyvilx.tools.compiler.ast.classes.IClass)4 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)4 LambdaExpr (dyvilx.tools.compiler.ast.expression.LambdaExpr)3 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)3 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)3 Name (dyvil.lang.Name)2 AnnotationVisitor (dyvilx.tools.asm.AnnotationVisitor)2 FieldAssignment (dyvilx.tools.compiler.ast.expression.access.FieldAssignment)2 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)2 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 Reified (dyvil.annotation.Reified)1 MethodVisitor (dyvilx.tools.asm.MethodVisitor)1