Compare commits
No commits in common. "6f9791455d83e442d698966f0d13f49a74634bb9" and "c44ed5446d0059a3bfc6f1265460ff88eca882a6" have entirely different histories.
6f9791455d
...
c44ed5446d
@ -38,7 +38,16 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
|
||||
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);
|
||||
|
||||
if(this.returnType == "not" && statement instanceof ReturnStatement){
|
||||
ReturnStatement returnStatement = (ReturnStatement) statement;
|
||||
this.returnType = returnStatement.getTypeCheckResult().type;
|
||||
}
|
||||
|
||||
if(statement instanceof LocalVarDecl){
|
||||
LocalVarDecl localVarDecl = (LocalVarDecl) statement;
|
||||
localVars.put(localVarDecl.identifier, localVarDecl.type);
|
||||
@ -68,17 +77,12 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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))
|
||||
if (!typeOfCurrentStatement.type.equals(this.returnType)) {
|
||||
if (!typeOfCurrentStatement.type.equals("void"))
|
||||
throw new Exception("TypeCheck Exception: Block returns the wrong type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
result.type = this.returnType;
|
||||
// todo check if the block returns the needed return type in every case
|
||||
// todo ignore unreachable statements?
|
||||
|
Loading…
Reference in New Issue
Block a user