code-generator #8

Merged
i22007 merged 11 commits from code-generator into main 2024-05-14 13:34:52 +00:00
3 changed files with 14 additions and 6 deletions
Showing only changes of commit c4061125c4 - Show all commits

View File

@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ParameterListNode extends ASTNode { public class ParameterListNode extends ASTNode {
List<ParameterNode> parameters = new ArrayList<>(); public List<ParameterNode> parameters = new ArrayList<>();
public ParameterListNode(List<ParameterNode> parameters){ public ParameterListNode(List<ParameterNode> parameters){
this.parameters = parameters; this.parameters = parameters;

View File

@ -1,5 +1,7 @@
package bytecode; package bytecode;
import ast.parameter.ParameterListNode;
import ast.parameter.ParameterNode;
import ast.type.AccessTypeNode; import ast.type.AccessTypeNode;
import ast.type.EnumAccessTypeNode; import ast.type.EnumAccessTypeNode;
import ast.type.EnumTypeNode; import ast.type.EnumTypeNode;
@ -17,8 +19,12 @@ public class Mapper {
return 0; return 0;
} }
public String generateMethodDescriptor(TypeNode typeNode) { public String generateMethodDescriptor(TypeNode typeNode, ParameterListNode parameterListNode) {
String descriptor = "()"; String descriptor = "(";
for(ParameterNode parameterNode : parameterListNode.parameters) {
descriptor += getTypeChar(parameterNode.type.enumTypeNode);
}
descriptor += ")";
descriptor += getTypeChar(typeNode.enumTypeNode); descriptor += getTypeChar(typeNode.enumTypeNode);
return descriptor; return descriptor;
} }

View File

@ -9,6 +9,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
private ClassWriter classWriter; private ClassWriter classWriter;
Mapper mapper = new Mapper(); Mapper mapper = new Mapper();
private MethodVisitor methodVisitor;
public MethodCodeGen(ClassWriter classWriter) { public MethodCodeGen(ClassWriter classWriter) {
this.classWriter = classWriter; this.classWriter = classWriter;
@ -27,12 +28,13 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override @Override
public void visit(MethodNode methodNode) { public void visit(MethodNode methodNode) {
MethodVisitor method = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility), methodVisitor = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility),
methodNode.identifier, methodNode.identifier,
mapper.generateMethodDescriptor(methodNode.type), mapper.generateMethodDescriptor(methodNode.type, methodNode.parameters),
null, null,
null); null);
method.visitEnd(); // methodNode.parameters.accept(this);
methodVisitor.visitEnd();
} }
} }