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;
|
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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user