Implemented typeCheck of TypedFieldVarAccess

This commit is contained in:
ahmad 2024-05-11 11:44:28 +02:00
parent 6e2a331a66
commit a8c44dc13b

View File

@ -3,7 +3,6 @@ package de.maishai.typedast.typedclass;
import de.maishai.ast.records.*;
import de.maishai.typedast.MethodContext;
import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.TypedNode;
import de.maishai.typedast.Type;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -28,21 +27,38 @@ public class TypedFieldVarAccess implements TypedExpression {
field = unTypedFieldVarAccess.field();
recursiveOwnerChain = getKindOfExpression(localVar, clas, unTypedFieldVarAccess.recursiveOwnerChain());
name = unTypedFieldVarAccess.id();
type = localVar.get(unTypedFieldVarAccess.id());
if(field) {
if (clas.isThereField(name)) {
type = clas.getFieldType(name);
}
} else if(localVar.containsKey(name)){
type = localVar.get(name);
}else{
throw new RuntimeException("Variable not declared");
}
}
@Override
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
Type type = localVar.get(name);
if (type == null) {
//TODO: check if field variable or local variable
if(name.startsWith("this.")){
type = localVar.get(name.substring(5));
}else{
throw new RuntimeException("Variable " + name + " not declared");
if(field){
if(clas.isThereField(name)){
type = clas.getFieldType(name);
}
}else{
if(clas.isParameterWitNameInMethod(name)){
type = clas.getParameterType(name);
}else if(localVar.containsKey(name)){
type = localVar.get(name);
}
}
return type;
}