mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 16:48: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.ast.records.*;
|
||||||
import de.maishai.typedast.MethodContext;
|
import de.maishai.typedast.MethodContext;
|
||||||
import de.maishai.typedast.TypedExpression;
|
import de.maishai.typedast.TypedExpression;
|
||||||
import de.maishai.typedast.TypedNode;
|
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -28,21 +27,38 @@ public class TypedFieldVarAccess implements TypedExpression {
|
|||||||
field = unTypedFieldVarAccess.field();
|
field = unTypedFieldVarAccess.field();
|
||||||
recursiveOwnerChain = getKindOfExpression(localVar, clas, unTypedFieldVarAccess.recursiveOwnerChain());
|
recursiveOwnerChain = getKindOfExpression(localVar, clas, unTypedFieldVarAccess.recursiveOwnerChain());
|
||||||
name = unTypedFieldVarAccess.id();
|
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
|
@Override
|
||||||
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
|
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(field){
|
||||||
if(name.startsWith("this.")){
|
if(clas.isThereField(name)){
|
||||||
type = localVar.get(name.substring(5));
|
type = clas.getFieldType(name);
|
||||||
}else{
|
}
|
||||||
throw new RuntimeException("Variable " + name + " not declared");
|
}else{
|
||||||
|
if(clas.isParameterWitNameInMethod(name)){
|
||||||
|
type = clas.getParameterType(name);
|
||||||
|
}else if(localVar.containsKey(name)){
|
||||||
|
type = localVar.get(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user