make file pretty
This commit is contained in:
@@ -29,7 +29,7 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
funcs[i] = (FunctionDefinition) this.visit(ctx.functionDef(i));
|
funcs[i] = (FunctionDefinition) this.visit(ctx.functionDef(i));
|
||||||
}
|
}
|
||||||
Expression expression = (Expression) this.visit(ctx.expression());
|
Expression expression = (Expression) this.visit(ctx.expression());
|
||||||
Program result = new Program(funcs, expression);
|
Program result = new Program(funcs, expression);
|
||||||
result.type = expression.type;
|
result.type = expression.type;
|
||||||
result.line = ctx.start.getLine();
|
result.line = ctx.start.getLine();
|
||||||
result.col = ctx.start.getCharPositionInLine();
|
result.col = ctx.start.getCharPositionInLine();
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -98,7 +100,7 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
ctx.start.getLine();
|
ctx.start.getLine();
|
||||||
ctx.start.getCharPositionInLine();
|
ctx.start.getCharPositionInLine();
|
||||||
Node expression = this.visit(ctx.expression());
|
Node expression = this.visit(ctx.expression());
|
||||||
PrintStatement result = new PrintStatement((Expression) expression);
|
PrintStatement result = new PrintStatement((Expression) expression);
|
||||||
result.type = null;
|
result.type = null;
|
||||||
result.line = ctx.start.getLine();
|
result.line = ctx.start.getLine();
|
||||||
result.col = ctx.start.getCharPositionInLine();
|
result.col = ctx.start.getCharPositionInLine();
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +179,7 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
|
|
||||||
if (this.vars.get(name) != null) {
|
if (this.vars.get(name) != null) {
|
||||||
String error = "Redeclaration of variable with name \"" + name + "\".";
|
String error = "Redeclaration of variable with name \"" + name + "\".";
|
||||||
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
|
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the appropriate instance
|
// Create the appropriate instance
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,11 +607,11 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
// Evaluate every argument
|
// Evaluate every argument
|
||||||
Expression[] args = new Expression[argCount];
|
Expression[] args = new Expression[argCount];
|
||||||
for (int i = 0; i < argCount; i++) {
|
for (int i = 0; i < argCount; i++) {
|
||||||
Expression expression = (Expression) this.visit(ctx.functionCall().arguments().expression(i));
|
Expression expression = (Expression) this.visit(ctx.functionCall().arguments().expression(i));
|
||||||
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