mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 16:48:03 +00:00
Integrated the typedMethodMain in typed AST
This commit is contained in:
parent
976312d5ae
commit
7b786ff19d
@ -24,6 +24,7 @@ public class TypedClass implements TypedNode {
|
|||||||
private List<TypedDeclaration> typedDeclarations = new ArrayList<>();
|
private List<TypedDeclaration> typedDeclarations = new ArrayList<>();
|
||||||
private List<TypedMethod> typedMethods = new ArrayList<>();
|
private List<TypedMethod> typedMethods = new ArrayList<>();
|
||||||
private List<TypedConstructor> typedConstructors = new ArrayList<>();
|
private List<TypedConstructor> typedConstructors = new ArrayList<>();
|
||||||
|
private TypedMain typedMain;
|
||||||
private TypedMethod currentMethod;
|
private TypedMethod currentMethod;
|
||||||
private TypedConstructor currentConstructor;
|
private TypedConstructor currentConstructor;
|
||||||
private Type type;
|
private Type type;
|
||||||
@ -58,6 +59,12 @@ public class TypedClass implements TypedNode {
|
|||||||
for (Method method : c.methods()) {
|
for (Method method : c.methods()) {
|
||||||
typedMethods.add(new TypedMethod(typedProgram, method));
|
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) {
|
public void covertBlocksOfConstructorsAndMethods(TypedProgram typedProgram, Class c) {
|
||||||
@ -77,6 +84,14 @@ public class TypedClass implements TypedNode {
|
|||||||
exitCurrentMethod();
|
exitCurrentMethod();
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c.mainmeth() != null) {
|
||||||
|
enterCurrentMethod(typedMain.getTypedMethod());
|
||||||
|
typedMain.convertToTypedMethod(typedProgram, c);
|
||||||
|
exitCurrentMethod();
|
||||||
|
} else {
|
||||||
|
typedMain = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
34
src/main/java/de/maishai/typedast/typedclass/TypedMain.java
Normal file
34
src/main/java/de/maishai/typedast/typedclass/TypedMain.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user