Compare commits

...

2 Commits

Author SHA1 Message Date
f5da71478f Merge remote-tracking branch 'origin/johns-branch' into code-generator 2024-05-14 11:44:44 +02:00
Bruder John
a8638fe70c fixed error 2024-05-14 11:40:43 +02:00
3 changed files with 17 additions and 22 deletions

View File

@ -4,6 +4,7 @@ import ast.ClassNode;
import ast.member.FieldNode; import ast.member.FieldNode;
import ast.member.MemberNode; import ast.member.MemberNode;
import ast.member.MethodNode; import ast.member.MethodNode;
import ast.type.BaseTypeNode;
import bytecode.visitor.ClassVisitor; import bytecode.visitor.ClassVisitor;
import java.io.File; import java.io.File;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
@ -39,7 +40,9 @@ public class ClassCodeGen implements ClassVisitor {
@Override @Override
public void visit(FieldNode fieldNode) { 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(); classWriter.visitEnd();
} }

View File

@ -1,11 +1,6 @@
package bytecode; package bytecode;
import ast.parameter.ParameterListNode; import ast.type.*;
import ast.parameter.ParameterNode;
import ast.type.AccessTypeNode;
import ast.type.EnumAccessTypeNode;
import ast.type.EnumTypeNode;
import ast.type.TypeNode;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
public class Mapper { public class Mapper {
@ -19,13 +14,9 @@ public class Mapper {
return 0; return 0;
} }
public String generateMethodDescriptor(TypeNode typeNode, ParameterListNode parameterListNode) { public String generateMethodDescriptor(BaseTypeNode baseTypeNode) {
String descriptor = "("; String descriptor = "()";
for(ParameterNode parameterNode : parameterListNode.parameters) { descriptor += getTypeChar(baseTypeNode.enumType);
descriptor += getTypeChar(parameterNode.type.enumTypeNode);
}
descriptor += ")";
descriptor += getTypeChar(typeNode.enumTypeNode);
return descriptor; return descriptor;
} }

View File

@ -2,6 +2,7 @@ package bytecode;
import ast.member.ConstructorNode; import ast.member.ConstructorNode;
import ast.member.MethodNode; import ast.member.MethodNode;
import ast.type.BaseTypeNode;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
@ -28,13 +29,13 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override @Override
public void visit(MethodNode methodNode) { public void visit(MethodNode methodNode) {
methodVisitor = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility), if(methodNode.type instanceof BaseTypeNode baseTypeNode){
methodNode.identifier, MethodVisitor method = classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility),
mapper.generateMethodDescriptor(methodNode.type, methodNode.parameters), methodNode.identifier,
null, mapper.generateMethodDescriptor(baseTypeNode),
null); null,
null);
// methodNode.parameters.accept(this); method.visitEnd();
methodVisitor.visitEnd(); }
} }
} }