mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:08:03 +00:00
Added the implementationf of typeCheck in typedAssignment
This commit is contained in:
parent
b61af71076
commit
201d6e03b9
@ -13,7 +13,6 @@ import java.util.Map;
|
||||
@Data
|
||||
public class TypedAssignment implements TypedStatement {
|
||||
private TypedId loc;
|
||||
private AssignSign assignSign;
|
||||
private TypedExpression value;
|
||||
|
||||
@Override
|
||||
@ -21,15 +20,14 @@ public class TypedAssignment implements TypedStatement {
|
||||
if (!localVar.containsKey(loc.getName())) {
|
||||
throw new RuntimeException("Variable not declared");
|
||||
}
|
||||
//ASSIGN : '=';ADD_ASSIGN : '+='; SUB_ASSIGN : '-='; MUL_ASSIGN : '*=';
|
||||
if (assignSign == AssignSign.ASSIGN || assignSign == AssignSign.ADD_ASSIGN ||
|
||||
assignSign == AssignSign.SUB_ASSIGN || assignSign == AssignSign.MUL_ASSIGN) {
|
||||
if (localVar.get(loc.getName()) != Type.INT || value.typeCheck(localVar, classes) != Type.INT) {
|
||||
throw new RuntimeException("Type mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
return localVar.get(loc.getName());
|
||||
Type typeLeft = localVar.get(loc.getName());
|
||||
Type typeRight = value.typeCheck(localVar, classes);
|
||||
|
||||
if (typeLeft.equals(typeRight) ) {
|
||||
return typeLeft;
|
||||
}
|
||||
throw new RuntimeException("type of left not equals with type right");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user