diff --git a/src/main/java/de/maishai/Compiler.java b/src/main/java/de/maishai/Compiler.java index 9a06d14..91a8a6a 100644 --- a/src/main/java/de/maishai/Compiler.java +++ b/src/main/java/de/maishai/Compiler.java @@ -98,7 +98,7 @@ public class Compiler { } public static void main(String[] args) { - generateByteCodeFileFromFile(List.of("src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java"), + generateByteCodeFileFromFile(List.of("src/test/testFiles/JavaTestfilesMore/ClassCanBeBytecoded.java"), List.of("ClassCanBeBytecoded")); } } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java index 3ce8d81..da842a0 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java @@ -24,6 +24,7 @@ public class TypedClass implements TypedNode { private List typedDeclarations = new ArrayList<>(); private List typedMethods = new ArrayList<>(); private List typedConstructors = new ArrayList<>(); + private TypedMain typedMain; private TypedMethod currentMethod; private TypedConstructor currentConstructor; private Type type; @@ -58,6 +59,12 @@ public class TypedClass implements TypedNode { for (Method method : c.methods()) { typedMethods.add(new TypedMethod(typedProgram, method)); } + if (c.mainmeth() != null) { + typedMain = new TypedMain(); + typedMethods.add(typedMain.getTypedMethod()); + } else { + typedMain = null; + } } public void covertBlocksOfConstructorsAndMethods(TypedProgram typedProgram, Class c) { @@ -77,6 +84,14 @@ public class TypedClass implements TypedNode { exitCurrentMethod(); j++; } + + if (c.mainmeth() != null) { + enterCurrentMethod(typedMain.getTypedMethod()); + typedMain.convertToTypedMethod(typedProgram, c); + exitCurrentMethod(); + } else { + typedMain = null; + } } @Override diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedMain.java b/src/main/java/de/maishai/typedast/typedclass/TypedMain.java new file mode 100644 index 0000000..da981c0 --- /dev/null +++ b/src/main/java/de/maishai/typedast/typedclass/TypedMain.java @@ -0,0 +1,34 @@ +package de.maishai.typedast.typedclass; + +import de.maishai.ast.records.Class; +import de.maishai.typedast.Type; +import de.maishai.typedast.TypedNode; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@Data +@AllArgsConstructor +public class TypedMain implements TypedNode { + private Type type = Type.VOID; + private TypedMethod typedMethod; + + public TypedMain(){ + typedMethod = new TypedMethod(); + typedMethod.setName("main"); + typedMethod.setReturnType(type); + typedMethod.setTypedParameters(List.of(new TypedParameter("args", Type.REFERENCE("String[]")))); + } + + public void convertToTypedMethod(TypedProgram typedProgram, Class unTypedClass){ + typedMethod.setTypedBlock(new TypedBlock(typedProgram, unTypedClass.mainmeth())); + } + + @Override + public Type typeCheck(TypedProgram typedProgram) { + return type; + } +}