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;
}
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);
}
}
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();
}
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();
}
}
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;
}
Aggregations