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 dbc452e..fb4f484 100644 --- a/src/main/java/bytecode/Mapper.java +++ b/src/main/java/bytecode/Mapper.java @@ -1,11 +1,6 @@ package bytecode; -import ast.parameter.ParameterListNode; -import ast.parameter.ParameterNode; -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 { @@ -19,13 +14,9 @@ public class Mapper { return 0; } - public String generateMethodDescriptor(TypeNode typeNode, ParameterListNode parameterListNode) { - String descriptor = "("; - for(ParameterNode parameterNode : parameterListNode.parameters) { - descriptor += getTypeChar(parameterNode.type.enumTypeNode); - } - descriptor += ")"; - descriptor += getTypeChar(typeNode.enumTypeNode); + public String generateMethodDescriptor(BaseTypeNode baseTypeNode) { + String descriptor = "()"; + descriptor += getTypeChar(baseTypeNode.enumType); return descriptor; } diff --git a/src/main/java/bytecode/MethodCodeGen.java b/src/main/java/bytecode/MethodCodeGen.java index 2e352be..c8a38f3 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; @@ -28,13 +29,13 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor { @Override public void visit(MethodNode methodNode) { - methodVisitor = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility), - methodNode.identifier, - mapper.generateMethodDescriptor(methodNode.type, methodNode.parameters), - null, - null); - - // methodNode.parameters.accept(this); - methodVisitor.visitEnd(); + if(methodNode.type instanceof BaseTypeNode baseTypeNode){ + MethodVisitor method = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility), + methodNode.identifier, + mapper.generateMethodDescriptor(baseTypeNode), + null, + null); + method.visitEnd(); + } } }