make file pretty
This commit is contained in:
@@ -55,17 +55,19 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
statements[i] = (Statement) currentStatement;
|
statements[i] = (Statement) currentStatement;
|
||||||
actualStatementCount += 1;
|
actualStatementCount += 1;
|
||||||
|
|
||||||
// We use the existance of a type to indicate that this statement returns something
|
// We use the existance of a type to indicate that this statement returns
|
||||||
// for which the VariableDeclaration is an exception
|
// something for which the VariableDeclaration is an exception
|
||||||
if (currentStatement.type != null && !(currentStatement instanceof VariableDeclaration)) {
|
if (currentStatement.type != null && !(currentStatement instanceof VariableDeclaration)) {
|
||||||
// check whether the type matches
|
// check whether the type matches
|
||||||
try {
|
try {
|
||||||
this.currentDeclaredReturnType.combine(currentStatement.type);
|
this.currentDeclaredReturnType.combine(currentStatement.type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(Helper.getErrorPrefix(currentStatement.line, currentStatement.col) + e.getMessage());
|
throw new RuntimeException(
|
||||||
|
Helper.getErrorPrefix(currentStatement.line, currentStatement.col) + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// since we have a return guaranteed, every statement after this one is unreachable code
|
// since we have a return guaranteed, every statement
|
||||||
|
// after this one is unreachable code
|
||||||
hasReturn = true;
|
hasReturn = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -125,8 +127,9 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (thenBlock.type != null && type != null) {
|
if (thenBlock.type != null && type != null) {
|
||||||
// Since a block verifies that it can combine with the return type of the function
|
// Since a block verifies that it can combine with the return type of the
|
||||||
// it is defined in, we do not have check whether the then and alt block return types match
|
// function it is defined in, we do not have check whether the then and
|
||||||
|
// alt block return types match
|
||||||
result.type = thenBlock.type;
|
result.type = thenBlock.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,7 +561,7 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
// Visit the block, make sure that a return value is guaranteed
|
// Visit the block, make sure that a return value is guaranteed
|
||||||
Node block = this.visit(ctx.braced_block());
|
Node block = this.visit(ctx.braced_block());
|
||||||
if (block.type == null) {
|
if (block.type == null) {
|
||||||
String error = "Function " + name +" has to return something of type " + returnType.getName() +".";
|
String error = "Function " + name + " has to return something of type " + returnType.getName() + ".";
|
||||||
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
|
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,7 +611,7 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
try {
|
try {
|
||||||
expression.type.combine(func.signature[i]); // Make sure the types are matching
|
expression.type.combine(func.signature[i]); // Make sure the types are matching
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(Helper.getErrorPrefix(line, col) + "argument " + i +" " + e.getMessage());
|
throw new RuntimeException(Helper.getErrorPrefix(line, col) + "argument " + i + " " + e.getMessage());
|
||||||
}
|
}
|
||||||
args[i] = expression;
|
args[i] = expression;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user