Merge branch 'refs/heads/main' into testsuites

This commit is contained in:
JonathanFleischmann 2024-06-23 14:32:39 +02:00
commit f0ca5324d8
3 changed files with 50 additions and 1 deletions

View File

@ -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"));
}
}

View File

@ -24,6 +24,7 @@ public class TypedClass implements TypedNode {
private List<TypedDeclaration> typedDeclarations = new ArrayList<>();
private List<TypedMethod> typedMethods = new ArrayList<>();
private List<TypedConstructor> 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

View File

@ -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;
}
}