diff --git a/src/main/java/bytecode/ClassCodeGen.java b/src/main/java/bytecode/ClassCodeGen.java index 59be9ee..7a1c0f0 100644 --- a/src/main/java/bytecode/ClassCodeGen.java +++ b/src/main/java/bytecode/ClassCodeGen.java @@ -4,6 +4,7 @@ import ast.ClassNode; import ast.member.FieldNode; import ast.member.MemberNode; import ast.member.MethodNode; +import ast.type.BaseTypeNode; import bytecode.visitor.ClassVisitor; import java.io.File; import org.objectweb.asm.ClassWriter; @@ -39,7 +40,9 @@ public class ClassCodeGen implements ClassVisitor { @Override public void visit(FieldNode fieldNode) { - classWriter.visitField(mapper.mapAccesTypeToOpcode(fieldNode.accessTypeNode), fieldNode.identifier, mapper.getTypeChar(fieldNode.type.enumTypeNode), null, null ); + if(fieldNode.type instanceof BaseTypeNode baseTypeNode){ + classWriter.visitField(mapper.mapAccesTypeToOpcode(fieldNode.accessTypeNode), fieldNode.identifier, mapper.getTypeChar(baseTypeNode.enumType), null, null ); + } classWriter.visitEnd(); } diff --git a/src/main/java/bytecode/Mapper.java b/src/main/java/bytecode/Mapper.java index 7f1b219..fb4f484 100644 --- a/src/main/java/bytecode/Mapper.java +++ b/src/main/java/bytecode/Mapper.java @@ -1,9 +1,6 @@ package bytecode; -import ast.type.AccessTypeNode; -import ast.type.EnumAccessTypeNode; -import ast.type.EnumTypeNode; -import ast.type.TypeNode; +import ast.type.*; import org.objectweb.asm.Opcodes; public class Mapper { @@ -17,9 +14,9 @@ public class Mapper { return 0; } - public String generateMethodDescriptor(TypeNode typeNode) { + public String generateMethodDescriptor(BaseTypeNode baseTypeNode) { String descriptor = "()"; - descriptor += getTypeChar(typeNode.enumTypeNode); + descriptor += getTypeChar(baseTypeNode.enumType); return descriptor; } diff --git a/src/main/java/bytecode/MethodCodeGen.java b/src/main/java/bytecode/MethodCodeGen.java index fd8a29a..e544a8b 100644 --- a/src/main/java/bytecode/MethodCodeGen.java +++ b/src/main/java/bytecode/MethodCodeGen.java @@ -2,6 +2,7 @@ package bytecode; import ast.member.ConstructorNode; import ast.member.MethodNode; +import ast.type.BaseTypeNode; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; @@ -27,12 +28,13 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor { @Override public void visit(MethodNode methodNode) { - MethodVisitor method = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility), - methodNode.identifier, - mapper.generateMethodDescriptor(methodNode.type), - null, - null); - - method.visitEnd(); + if(methodNode.type instanceof BaseTypeNode baseTypeNode){ + MethodVisitor method = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility), + methodNode.identifier, + mapper.generateMethodDescriptor(baseTypeNode), + null, + null); + method.visitEnd(); + } } }