mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 16:48:03 +00:00
Updated the TypeCheck of TypedAssignement
This commit is contained in:
parent
cdbb3ae55f
commit
34a20668b6
@ -23,6 +23,7 @@ public class TypedAssignment implements TypedStatement {
|
||||
public TypedAssignment(Map<String, Type> localVar, TypedClass clas, Assignment untyped) {
|
||||
convertToTypedAssignment(localVar, clas, untyped);
|
||||
}
|
||||
|
||||
public void convertToTypedAssignment(Map<String, Type> localVar, TypedClass clas, Assignment untyped) {
|
||||
varName = untyped.location().id();
|
||||
value = getKindOfExpression(localVar, clas, untyped.value());
|
||||
@ -30,13 +31,20 @@ public class TypedAssignment implements TypedStatement {
|
||||
|
||||
@Override
|
||||
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
|
||||
Type typeLeft = null;
|
||||
if (!localVar.containsKey(varName)) {
|
||||
throw new RuntimeException("Variable not declared");
|
||||
if(clas.isThereField(varName)){
|
||||
typeLeft = clas.getFieldType(varName);
|
||||
}else {
|
||||
throw new RuntimeException("Variable not declared");
|
||||
}
|
||||
} else {
|
||||
typeLeft = localVar.get(varName);
|
||||
}
|
||||
Type typeLeft = localVar.get(varName);
|
||||
|
||||
Type typeRight = value.typeCheck(localVar, clas);
|
||||
|
||||
if (typeLeft.equals(typeRight) ) {
|
||||
if (typeLeft.equals(typeRight)) {
|
||||
type = typeLeft;
|
||||
return typeLeft;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user