add bases for conversions

This commit is contained in:
404Simon 2024-05-02 15:40:25 +02:00
parent b022244498
commit 0aa5976bc1

View File

@ -3,7 +3,11 @@ package de.maishai.typedast.typedclass;
import de.maishai.typedast.Node;
import de.maishai.typedast.Type;
import lombok.Data;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -19,8 +23,47 @@ public class Class implements Node {
return null;
}
public Node startConversion(de.maishai.ast.records.Class c) {
Map<String, Type> local = new HashMap<>();
Map<String, Class> classMap = new HashMap<>();
return convertToTypedAST(local, classMap);
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes) {
return null;
}
public void codeGen() {
ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object", null);
for(Field field : fields) {
//field.codeGen(cw);
}
for(Method m: methods) {
//m.codeGen(cw);
}
writeClassfile(cw, name);
}
public static void writeClassfile(ClassWriter cw, String name) {
byte[] code = cw.toByteArray();
try {
java.io.FileOutputStream fos = new java.io.FileOutputStream("output/" + name + ".class");
fos.write(code);
fos.close();
} catch (java.io.IOException e) {
System.out.println("Error writing classfile: " + e);
}
}
public static void main(String[] args) {
Class c = new Class();
c.fields = new ArrayList<>();
c.methods = new ArrayList<>();
c.setName("Test");
c.codeGen();
}
}