Compare commits
2 Commits
c44ed5446d
...
6f9791455d
Author | SHA1 | Date | |
---|---|---|---|
|
6f9791455d | ||
|
0f76b1fdae |
@ -38,16 +38,7 @@ public class BlockStatement extends AbstractType implements IStatement {
|
|||||||
|
|
||||||
for (IStatement statement : statements) {
|
for (IStatement statement : statements) {
|
||||||
|
|
||||||
System.out.println(statement.getClass()); //todo remove
|
|
||||||
// todo remove later if there are no null statement any more
|
|
||||||
if (statement != null) {
|
|
||||||
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
||||||
|
|
||||||
if(this.returnType == "not" && statement instanceof ReturnStatement){
|
|
||||||
ReturnStatement returnStatement = (ReturnStatement) statement;
|
|
||||||
this.returnType = returnStatement.getTypeCheckResult().type;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(statement instanceof LocalVarDecl){
|
if(statement instanceof LocalVarDecl){
|
||||||
LocalVarDecl localVarDecl = (LocalVarDecl) statement;
|
LocalVarDecl localVarDecl = (LocalVarDecl) statement;
|
||||||
localVars.put(localVarDecl.identifier, localVarDecl.type);
|
localVars.put(localVarDecl.identifier, localVarDecl.type);
|
||||||
@ -77,12 +68,17 @@ public class BlockStatement extends AbstractType implements IStatement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!typeOfCurrentStatement.type.equals(this.returnType)) {
|
|
||||||
if (!typeOfCurrentStatement.type.equals("void"))
|
if(typeOfCurrentStatement.type.equals("void"))
|
||||||
|
continue;
|
||||||
|
// set return of block if not known yet
|
||||||
|
|
||||||
|
if(this.returnType.equals("not"))
|
||||||
|
this.returnType = typeOfCurrentStatement.type;
|
||||||
|
|
||||||
|
if (!typeOfCurrentStatement.type.equals(this.returnType))
|
||||||
throw new Exception("TypeCheck Exception: Block returns the wrong type.");
|
throw new Exception("TypeCheck Exception: Block returns the wrong type.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
result.type = this.returnType;
|
result.type = this.returnType;
|
||||||
// todo check if the block returns the needed return type in every case
|
// todo check if the block returns the needed return type in every case
|
||||||
// todo ignore unreachable statements?
|
// todo ignore unreachable statements?
|
||||||
|
Loading…
Reference in New Issue
Block a user