Add method parameters to bytecode
This commit is contained in:
parent
d27ec0643a
commit
c4061125c4
@ -6,7 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ParameterListNode extends ASTNode {
|
||||
List<ParameterNode> parameters = new ArrayList<>();
|
||||
public List<ParameterNode> parameters = new ArrayList<>();
|
||||
|
||||
public ParameterListNode(List<ParameterNode> parameters){
|
||||
this.parameters = parameters;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user