From c823894eb2fb82a229eb9810d70466b818c5d585 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 27 Jun 2024 21:43:13 +0200 Subject: [PATCH] fix problem with new --- .../typedast/LoggingMethodVisitor.java | 80 +++++++++++++++++++ .../de/maishai/typedast/MethodContext.java | 7 +- .../typedast/typedclass/TypedAssignment.java | 2 +- .../maishai/typedast/typedclass/TypedNew.java | 1 + .../Features/ByteCode_ClassObjects.java | 70 ++++++++-------- 5 files changed, 121 insertions(+), 39 deletions(-) create mode 100644 src/main/java/de/maishai/typedast/LoggingMethodVisitor.java diff --git a/src/main/java/de/maishai/typedast/LoggingMethodVisitor.java b/src/main/java/de/maishai/typedast/LoggingMethodVisitor.java new file mode 100644 index 0000000..5e4b2c1 --- /dev/null +++ b/src/main/java/de/maishai/typedast/LoggingMethodVisitor.java @@ -0,0 +1,80 @@ +package de.maishai.typedast; + +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +public class LoggingMethodVisitor extends MethodVisitor { + + public LoggingMethodVisitor(MethodVisitor methodVisitor) { + super(Opcodes.ASM9, methodVisitor); + System.out.println("\n--- Visiting Method ---"); + } + + public static String opcodeToString(int opcode) { + for (java.lang.reflect.Field field : Opcodes.class.getDeclaredFields()) { + try { + if (field.getType() == int.class && field.getInt(null) == opcode) { + return field.getName(); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + return "UNKNOWN"; + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { + System.out.println("visitMethodInsn: " + opcodeToString(opcode) + ", " + owner + ", " + name + ", " + descriptor + ", " + isInterface); + super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); + } + + @Override + public void visitVarInsn(int opcode, int varIndex) { + System.out.println("visitVarInsn: " + opcodeToString(opcode) + ", " + varIndex); + super.visitVarInsn(opcode, varIndex); + } + + @Override + public void visitTypeInsn(int opcode, String type) { + System.out.println("visitTypeInsn: " + opcodeToString(opcode) + ", " + type); + super.visitTypeInsn(opcode, type); + } + + @Override + public void visitInsn(int opcode) { + System.out.println("visitInsn: " + opcodeToString(opcode)); + super.visitInsn(opcode); + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String descriptor) { + System.out.println("visitMethodInsn: " + opcodeToString(opcode) + ", " + owner + ", " + name + ", " + descriptor); + super.visitMethodInsn(opcode, owner, name, descriptor); + } + + @Override + public void visitFieldInsn(int opcode, String owner, String name, String descriptor) { + System.out.println("visitFieldInsn: " + opcodeToString(opcode) + ", " + owner + ", " + name + ", " + descriptor); + super.visitFieldInsn(opcode, owner, name, descriptor); + } + + @Override + public void visitMaxs(int maxStack, int maxLocals) { + System.out.println("visitMaxs: " + maxStack + ", " + maxLocals); + super.visitMaxs(maxStack, maxLocals); + } + + @Override + public void visitIntInsn(int opcode, int operand) { + String opcodeString = opcode == Opcodes.BIPUSH ? "BIPUSH" : "SIPUSH"; + System.out.println("visitIntInsn: " + opcodeString + ", " + operand); + super.visitIntInsn(opcode, operand); + } + + @Override + public void visitLdcInsn(Object value) { + System.out.println("visitLdcInsn: " + value); + super.visitLdcInsn(value); + } +} diff --git a/src/main/java/de/maishai/typedast/MethodContext.java b/src/main/java/de/maishai/typedast/MethodContext.java index 9e741e1..41b4e3b 100644 --- a/src/main/java/de/maishai/typedast/MethodContext.java +++ b/src/main/java/de/maishai/typedast/MethodContext.java @@ -28,7 +28,12 @@ public class MethodContext { private final Deque