use of dyvilx.tools.compiler.ast.field.capture.CaptureField in project Dyvil by Dyvil.
the class AnonymousClassMetadata method write.
@Override
public void write(ClassWriter writer) throws BytecodeException {
final CaptureHelper<CaptureField> captureHelper = this.theClass.captureHelper;
final FieldThis thisField = this.theClass.thisField;
final IConstructor constructor = this.theClass.constructor;
captureHelper.writeCaptureFields(writer);
final MethodWriter initWriter = new MethodWriterImpl(writer, writer.visitMethod(Modifiers.MANDATED, "<init>", this.theClass.getConstructorDesc(), null, null));
final ParameterList parameterList = constructor.getParameters();
final int parameterCount = parameterList.size();
// Signature & Parameter Data
initWriter.setThisType(this.theClass.getInternalName());
parameterList.write(initWriter);
int index = initWriter.localCount();
int thisIndex = index;
if (thisField != null) {
thisField.writeField(writer);
index = initWriter.visitParameter(index, thisField.getName(), thisField.getTargetClass().getThisType(), Modifiers.MANDATED);
}
captureHelper.writeCaptureParameters(initWriter, index);
// Constructor Body
initWriter.visitCode();
initWriter.visitVarInsn(Opcodes.ALOAD, 0);
for (int i = 0; i < parameterCount; i++) {
parameterList.get(i).writeGet(initWriter);
}
constructor.writeInvoke(initWriter, 0);
if (thisField != null) {
initWriter.visitVarInsn(Opcodes.ALOAD, 0);
initWriter.visitVarInsn(Opcodes.ALOAD, thisIndex);
initWriter.visitFieldInsn(Opcodes.PUTFIELD, this.theClass.getInternalName(), thisField.getName(), thisField.getDescriptor());
}
captureHelper.writeFieldAssignments(initWriter);
this.theClass.writeClassInit(initWriter);
initWriter.visitEnd(Types.VOID);
}
Aggregations