From c4061125c45aa6e339f9387bb35fcaade71bb865 Mon Sep 17 00:00:00 2001 From: i22007 Date: Tue, 14 May 2024 11:39:14 +0200 Subject: [PATCH] Add method parameters to bytecode --- src/main/java/ast/parameter/ParameterListNode.java | 2 +- src/main/java/bytecode/Mapper.java | 10 ++++++++-- src/main/java/bytecode/MethodCodeGen.java | 8 +++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/ast/parameter/ParameterListNode.java b/src/main/java/ast/parameter/ParameterListNode.java index 34c615a..f409a65 100644 --- a/src/main/java/ast/parameter/ParameterListNode.java +++ b/src/main/java/ast/parameter/ParameterListNode.java @@ -6,7 +6,7 @@ import java.util.ArrayList; import java.util.List; public class ParameterListNode extends ASTNode { - List parameters = new ArrayList<>(); + public List parameters = new ArrayList<>(); public ParameterListNode(List parameters){ this.parameters = parameters; diff --git a/src/main/java/bytecode/Mapper.java b/src/main/java/bytecode/Mapper.java index 7f1b219..dbc452e 100644 --- a/src/main/java/bytecode/Mapper.java +++ b/src/main/java/bytecode/Mapper.java @@ -1,5 +1,7 @@ package bytecode; +import ast.parameter.ParameterListNode; +import ast.parameter.ParameterNode; import ast.type.AccessTypeNode; import ast.type.EnumAccessTypeNode; import ast.type.EnumTypeNode; @@ -17,8 +19,12 @@ public class Mapper { return 0; } - public String generateMethodDescriptor(TypeNode typeNode) { - String descriptor = "()"; + public String generateMethodDescriptor(TypeNode typeNode, ParameterListNode parameterListNode) { + String descriptor = "("; + for(ParameterNode parameterNode : parameterListNode.parameters) { + descriptor += getTypeChar(parameterNode.type.enumTypeNode); + } + descriptor += ")"; descriptor += getTypeChar(typeNode.enumTypeNode); return descriptor; } diff --git a/src/main/java/bytecode/MethodCodeGen.java b/src/main/java/bytecode/MethodCodeGen.java index fd8a29a..2e352be 100644 --- a/src/main/java/bytecode/MethodCodeGen.java +++ b/src/main/java/bytecode/MethodCodeGen.java @@ -9,6 +9,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor { private ClassWriter classWriter; Mapper mapper = new Mapper(); + private MethodVisitor methodVisitor; public MethodCodeGen(ClassWriter classWriter) { this.classWriter = classWriter; @@ -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), + methodVisitor = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility), methodNode.identifier, - mapper.generateMethodDescriptor(methodNode.type), + mapper.generateMethodDescriptor(methodNode.type, methodNode.parameters), null, null); - method.visitEnd(); + // methodNode.parameters.accept(this); + methodVisitor.visitEnd(); } }