empty class now working

This commit is contained in:
JonathanFleischmann 2024-05-08 15:51:25 +02:00
parent 8c1ae8712e
commit 4b071ea149
4 changed files with 11 additions and 3 deletions

View File

@ -27,7 +27,7 @@ public class Compiler {
public static TypedClass generateTypedASTFromAst(Class ast) { public static TypedClass generateTypedASTFromAst(Class ast) {
TypedClass typedAST = new TypedClass(); TypedClass typedAST = new TypedClass();
typedAST.startConversion(ast); typedAST = (TypedClass) typedAST.startConversion(ast);
return typedAST; return typedAST;
} }
@ -64,6 +64,6 @@ public class Compiler {
} }
public static void main(String[] args) { public static void main(String[] args) {
generateByteCodeFileFromFile("src/main/resources/JavaTestfiles/PublicClass.java", "OnlyClass"); generateByteCodeFileFromFile("src/main/resources/JavaTestfiles/ClassWithConstructor.java", "ClassWithConstructor");
} }
} }

View File

@ -6,7 +6,9 @@ import de.maishai.typedast.CodeGenUtils;
import de.maishai.typedast.TypedNode; import de.maishai.typedast.TypedNode;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.TypedStatement; import de.maishai.typedast.TypedStatement;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
@ -16,6 +18,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@Data @Data
@AllArgsConstructor
@NoArgsConstructor
public class TypedClass implements TypedNode { public class TypedClass implements TypedNode {
private String className; private String className;
private List<TypedField> typedFields; private List<TypedField> typedFields;
@ -52,6 +56,10 @@ public class TypedClass implements TypedNode {
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) { public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
TypedClass typedClass = new TypedClass(); TypedClass typedClass = new TypedClass();
Class c = (Class) unTypedAST; Class c = (Class) unTypedAST;
typedClass.setClassName(c.classname());
typedClass.setTypedFields(new ArrayList<>());
typedClass.setTypedMethods(new ArrayList<>());
typedClass.setTypedConstructors(new ArrayList<>());
for (Declaration field : c.fieldDeclarations()) { for (Declaration field : c.fieldDeclarations()) {
TypedField typedField = new TypedField(); TypedField typedField = new TypedField();

View File

@ -25,7 +25,7 @@ import de.maishai.typedast.Type;
import java.util.List; import java.util.List;
public class AbstractSyntax_ClassWithMoreComplexMethodAndMain { public class AbstractSyntax_ClassWithMultipleMethods {
public static Class get() { public static Class get() {
List<Declaration> declarations = List.of( List<Declaration> declarations = List.of(
new Declaration( new Declaration(