mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08:38:03 +00:00
Updated the typeCheck of TypedIfElse
This commit is contained in:
parent
2322d161e6
commit
092cbb5af9
@ -19,7 +19,6 @@ public class TypedFor implements TypedStatement {
|
||||
private TypedExpression cond;
|
||||
private TypedAssignment inc;
|
||||
private TypedBlock typedBlock;
|
||||
//TODO: type of block in for loop
|
||||
private Type type;
|
||||
|
||||
public TypedFor(TypedClass clas, For unTypedFor) {
|
||||
|
@ -18,7 +18,6 @@ public class TypedIfElse implements TypedStatement {
|
||||
private TypedExpression typedCon;
|
||||
private TypedBlock ifTypedBlock;
|
||||
private TypedBlock elseTypedBlock;
|
||||
//TODO: add Type
|
||||
private Type type;
|
||||
|
||||
public TypedIfElse(TypedClass clas, IfElse unTypedIfElse) {
|
||||
@ -33,18 +32,24 @@ public class TypedIfElse implements TypedStatement {
|
||||
|
||||
@Override
|
||||
public Type typeCheck(TypedClass clas) {
|
||||
|
||||
/*
|
||||
if (typedCon.typeCheck(clas) != Type.BOOL) {
|
||||
throw new RuntimeException("If condition must be a boolean");
|
||||
}
|
||||
if (ifTypedBlock.typeCheck(clas) != Type.VOID) {
|
||||
throw new RuntimeException("If block must be of type void");
|
||||
}
|
||||
|
||||
//TODO: catch all cases of return when one method has a return type
|
||||
*/
|
||||
//TODO: it still not catching the all cases when return is used
|
||||
if (ifTypedBlock.typeCheck(clas) == elseTypedBlock.typeCheck(clas)) {
|
||||
type = ifTypedBlock.typeCheck(clas);
|
||||
}
|
||||
if (elseTypedBlock.typeCheck(clas) == Type.VOID) {
|
||||
type = ifTypedBlock.typeCheck(clas);
|
||||
}
|
||||
if (ifTypedBlock.typeCheck(clas) == Type.VOID) {
|
||||
type = elseTypedBlock.typeCheck(clas);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user