mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:28: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
|
@Data
|
||||||
public class TypedAssignment implements TypedStatement {
|
public class TypedAssignment implements TypedStatement {
|
||||||
private TypedId loc;
|
private TypedId loc;
|
||||||
private AssignSign assignSign;
|
|
||||||
private TypedExpression value;
|
private TypedExpression value;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -21,15 +20,14 @@ public class TypedAssignment implements TypedStatement {
|
|||||||
if (!localVar.containsKey(loc.getName())) {
|
if (!localVar.containsKey(loc.getName())) {
|
||||||
throw new RuntimeException("Variable not declared");
|
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user