Add the list of TypedLocalVariable to TypedMethod and implemented the typeCheck

This commit is contained in:
ahmad 2024-05-12 15:46:14 +02:00
parent 092cbb5af9
commit ede0b38987

View File

@ -20,8 +20,8 @@ public class TypedMethod implements TypedNode {
private String name;
private Type returnType;
private List<TypedParameter> typedParameters = new ArrayList<>();
private TypedBlock typedBlock;
private List<TypedLocalVariable> localVariables = new ArrayList<>();
private TypedBlock typedBlock;
public TypedMethod(TypedClass clas, Method unTypedMethod) {
convertToTypedMethod(clas, unTypedMethod);
@ -40,12 +40,11 @@ public class TypedMethod implements TypedNode {
throw new RuntimeException("Method " + name + " already exists");
}, () -> {
});
//localVar.put(name, returnType);
}
public void convertToTypedBlock(TypedClass clas, Method unTypedMethod) {
typedBlock = new TypedBlock(clas, unTypedMethod.block());
typeCheck(clas);
}
public boolean isLocalVariablePresent(String localVarName) {
@ -67,13 +66,11 @@ public class TypedMethod implements TypedNode {
@Override
public Type typeCheck(TypedClass clas) {
/* if (localVar.containsKey(name)) {
throw new RuntimeException("Method " + name + " already exists");
if(returnType != Type.VOID){
if(typedBlock.typeCheck(clas) != returnType){
throw new RuntimeException("Method " + name + " must return " + returnType);
}
}
localVar.put(name, returnType);
for (TypedParameter typedParameter : typedParameters) {
typedParameter.typeCheck( clas);
}*/
return returnType;
}