summaryrefslogtreecommitdiff
path: root/src/ast/nodes/IfNode.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast/nodes/IfNode.java')
-rw-r--r--src/ast/nodes/IfNode.java22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/ast/nodes/IfNode.java b/src/ast/nodes/IfNode.java
index 50dde4a..b0e1ddb 100644
--- a/src/ast/nodes/IfNode.java
+++ b/src/ast/nodes/IfNode.java
@@ -1,18 +1,18 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `if` statement of the grammar.
*/
public class IfNode implements Node {
- private Node guard;
- private Node thenbranch;
- private Node elsebranch;
+
+ private final Node guard;
+ private final Node thenbranch;
+ private final Node elsebranch;
public IfNode(Node guard, Node thenbranch, Node elsebranch) {
this.guard = guard;
@@ -22,7 +22,7 @@ public class IfNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
errors.addAll(guard.checkSemantics(ST, _nesting));
errors.addAll(thenbranch.checkSemantics(ST, _nesting));
@@ -39,14 +39,14 @@ public class IfNode implements Node {
if (guard.typeCheck() instanceof BoolType) {
Type thenexp = thenbranch.typeCheck();
Type elseexp = elsebranch.typeCheck();
- if (thenexp.getClass().equals(elseexp.getClass()))
- return thenexp;
- else {
- System.out.println("Type Error: incompatible types in then and else branches");
+ if (thenexp.getClass().equals(elseexp.getClass())) {
+ return thenexp;
+ }else {
+ System.out.println("Type Error: incompatible types in then and else branches.");
return new ErrorType();
}
} else {
- System.out.println("Type Error: non boolean condition in if");
+ System.out.println("Type Error: non boolean condition in if.");
return new ErrorType();
}
}