Integrated the typedMethodMain in typed AST

This commit is contained in:
Ahmad 2024-06-23 13:39:51 +02:00
parent 976312d5ae
commit 7b786ff19d
2 changed files with 49 additions and 0 deletions

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