Add AccesTypeToOpcode mapper
This commit is contained in:
parent
44452d204b
commit
26653ac719
@ -13,7 +13,8 @@ import java.io.IOException;
|
||||
public class ClassCodeGen {
|
||||
public void generateClassCode(ClassNode classNode) {
|
||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, classNode.name, null,
|
||||
Mapper mapper = new Mapper();
|
||||
classWriter.visit(Opcodes.V1_8, mapper.mapAccesTypeToOpcode(classNode.accessType), classNode.name, null,
|
||||
"java/lang/Object", null);
|
||||
|
||||
for (MemberNode memberNode : classNode.members) {
|
||||
|
@ -8,6 +8,7 @@ import org.objectweb.asm.Opcodes;
|
||||
public class FieldCodeGen {
|
||||
|
||||
public void generateFieldCode(ClassWriter classWriter, FieldNode fieldNode) {
|
||||
FieldVisitor fieldVisitor = classWriter.visitField(Opcodes.ACC_PUBLIC, fieldNode.name, "", null, null);
|
||||
Mapper mapper = new Mapper();
|
||||
FieldVisitor fieldVisitor = classWriter.visitField(mapper.mapAccesTypeToOpcode(fieldNode.accessTypeNode), fieldNode.name, "", null, null);
|
||||
}
|
||||
}
|
||||
|
17
src/main/java/bytecode/Mapper.java
Normal file
17
src/main/java/bytecode/Mapper.java
Normal file
@ -0,0 +1,17 @@
|
||||
package bytecode;
|
||||
|
||||
import ast.AccessTypeNode;
|
||||
import ast.EnumAccessTypeNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class Mapper {
|
||||
public int mapAccesTypeToOpcode(AccessTypeNode type) {
|
||||
switch (type.enumAccessTypeNode) {
|
||||
case EnumAccessTypeNode.PUBLIC:
|
||||
return Opcodes.ACC_PUBLIC;
|
||||
case EnumAccessTypeNode.PRIVATE:
|
||||
return Opcodes.ACC_PRIVATE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -7,8 +7,9 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class MethodCodeGen {
|
||||
public void generateMethodCode(ClassWriter classWriter, MethodNode methodNode) {
|
||||
Mapper mapper = new Mapper();
|
||||
MethodVisitor constructor =
|
||||
classWriter.visitMethod(Opcodes.ACC_PUBLIC,
|
||||
classWriter.visitMethod(mapper.mapAccesTypeToOpcode(methodNode.visibility),
|
||||
"<init>",
|
||||
"()V",
|
||||
null,
|
||||
|
Loading…
Reference in New Issue
Block a user