mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:28:03 +00:00
Implemented typeCheck of TypedFieldVarAccess
This commit is contained in:
parent
6e2a331a66
commit
a8c44dc13b
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user