summaryrefslogtreecommitdiff
path: root/src/ast/nodes/IfNode.java
diff options
context:
space:
mode:
authorgeno <gabriele.genovese2@studio.unibo.it>2024-06-30 13:36:37 +0200
committergeno <gabriele.genovese2@studio.unibo.it>2024-06-30 13:36:37 +0200
commitafff6a80cd58f7787efa1398f7c8cbdce8989323 (patch)
treee6021201d6e7049da640687c7ce61c898aaea4d8 /src/ast/nodes/IfNode.java
parentaaa97e2e41c0aa17a6f99099dd39bb73a935fe02 (diff)
fixed warnings, better formatting, final added where possible
Diffstat (limited to 'src/ast/nodes/IfNode.java')
-rw-r--r--src/ast/nodes/IfNode.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/ast/nodes/IfNode.java b/src/ast/nodes/IfNode.java
index f51d486..b0e1ddb 100644
--- a/src/ast/nodes/IfNode.java
+++ b/src/ast/nodes/IfNode.java
@@ -9,9 +9,10 @@ import semanticanalysis.SymbolTable;
* 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;
@@ -21,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));
@@ -38,9 +39,9 @@ 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 {
+ if (thenexp.getClass().equals(elseexp.getClass())) {
+ return thenexp;
+ }else {
System.out.println("Type Error: incompatible types in then and else branches.");
return new ErrorType();
}