summaryrefslogtreecommitdiff
path: root/src/ast/nodes
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast/nodes')
-rw-r--r--src/ast/nodes/ArglistNode.java5
-rw-r--r--src/ast/nodes/AssignmentNode.java13
-rw-r--r--src/ast/nodes/AtomNode.java2
-rw-r--r--src/ast/nodes/AugassignNode.java5
-rw-r--r--src/ast/nodes/BlockNode.java10
-rw-r--r--src/ast/nodes/CompForNode.java2
-rw-r--r--src/ast/nodes/CompIterNode.java2
-rw-r--r--src/ast/nodes/CompNode.java4
-rw-r--r--src/ast/nodes/CompoundNode.java10
-rw-r--r--src/ast/nodes/DottedNameNode.java3
-rw-r--r--src/ast/nodes/ExprNode.java12
-rw-r--r--src/ast/nodes/ForStmtNode.java6
-rw-r--r--src/ast/nodes/FuncdefNode.java11
-rw-r--r--src/ast/nodes/IfNode.java15
-rw-r--r--src/ast/nodes/ImportNode.java19
-rw-r--r--src/ast/nodes/Node.java10
-rw-r--r--src/ast/nodes/ParamdefNode.java2
-rw-r--r--src/ast/nodes/ParamlistNode.java7
-rw-r--r--src/ast/nodes/ReturnStmtNode.java8
-rw-r--r--src/ast/nodes/RootNode.java4
-rw-r--r--src/ast/nodes/SimpleStmtNode.java11
-rw-r--r--src/ast/nodes/SimpleStmtsNode.java5
-rw-r--r--src/ast/nodes/TestlistCompNode.java4
-rw-r--r--src/ast/nodes/TrailerNode.java14
-rw-r--r--src/ast/nodes/WhileStmtNode.java10
25 files changed, 97 insertions, 97 deletions
diff --git a/src/ast/nodes/ArglistNode.java b/src/ast/nodes/ArglistNode.java
index c29a4e0..55a568d 100644
--- a/src/ast/nodes/ArglistNode.java
+++ b/src/ast/nodes/ArglistNode.java
@@ -19,11 +19,10 @@ public class ArglistNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
for (var arg : arguments) {
- if (arg instanceof ExprNode) {
- ExprNode argExpr = (ExprNode) arg;
+ if (arg instanceof ExprNode argExpr) {
String argName = argExpr.getId();
// TODO: check fucking IntType for params
diff --git a/src/ast/nodes/AssignmentNode.java b/src/ast/nodes/AssignmentNode.java
index 74d7283..558e392 100644
--- a/src/ast/nodes/AssignmentNode.java
+++ b/src/ast/nodes/AssignmentNode.java
@@ -10,9 +10,9 @@ import semanticanalysis.SymbolTable;
*/
public class AssignmentNode implements Node {
- private ExprListNode lhr;
- private Node assign;
- private ExprListNode rhr;
+ private final ExprListNode lhr;
+ private final Node assign;
+ private final ExprListNode rhr;
public AssignmentNode(Node lhr, Node assign, Node rhr) {
this.lhr = (ExprListNode) lhr;
@@ -22,7 +22,7 @@ public class AssignmentNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
// errors.addAll(lhr.checkSemantics(ST, _nesting));
errors.addAll(assign.checkSemantics(ST, _nesting));
@@ -32,7 +32,6 @@ public class AssignmentNode implements Node {
// FIXME: unused variable
// int rsize = rhr.getSize();
-
// if (lsize == rsize) {
for (int i = 0; i < lsize; i++) {
ExprNode latom = (ExprNode) lhr.getElem(i);
@@ -40,8 +39,8 @@ public class AssignmentNode implements Node {
// ExprNode ratom = (ExprNode) rhr.getElem(i);
}
// } else {
- // FIX: sgravata da più problemi che altro
- // errors.add(new SemanticError("ValueError: different size of left or right side assignment"));
+ // FIX: sgravata da più problemi che altro
+ // errors.add(new SemanticError("ValueError: different size of left or right side assignment"));
// }
return errors;
diff --git a/src/ast/nodes/AtomNode.java b/src/ast/nodes/AtomNode.java
index fef72ec..47a15d7 100644
--- a/src/ast/nodes/AtomNode.java
+++ b/src/ast/nodes/AtomNode.java
@@ -30,7 +30,7 @@ public class AtomNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- var errors = new ArrayList<SemanticError>();
+ var errors = new ArrayList();
if (val != null) {
if ((this.typeCheck() instanceof AtomType) && ST.nslookup(this.getId()) < 0) {
diff --git a/src/ast/nodes/AugassignNode.java b/src/ast/nodes/AugassignNode.java
index 629fbcd..7ced63e 100644
--- a/src/ast/nodes/AugassignNode.java
+++ b/src/ast/nodes/AugassignNode.java
@@ -12,7 +12,8 @@ import org.antlr.v4.runtime.tree.TerminalNode;
* Node for the `augassign` statement of the grammar.
*/
public class AugassignNode implements Node {
- private TerminalNode val;
+
+ private final TerminalNode val;
public AugassignNode(TerminalNode val) {
this.val = val;
@@ -20,7 +21,7 @@ public class AugassignNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- return new ArrayList<SemanticError>();
+ return new ArrayList();
}
// FIXME: use the right type
diff --git a/src/ast/nodes/BlockNode.java b/src/ast/nodes/BlockNode.java
index a38b4ea..d9a151d 100644
--- a/src/ast/nodes/BlockNode.java
+++ b/src/ast/nodes/BlockNode.java
@@ -1,23 +1,22 @@
package ast.nodes;
-import java.util.ArrayList;
-
import ast.types.*;
+import java.util.ArrayList;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
/**
- * Node for `block` statement of the grammar.
- * It extends the `RootNode`.
+ * Node for `block` statement of the grammar. It extends the `RootNode`.
*/
public class BlockNode extends RootNode {
+
public BlockNode(ArrayList<Node> childs) {
super(childs);
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
// Check semantics for each child
for (Node child : childs) {
@@ -27,7 +26,6 @@ public class BlockNode extends RootNode {
return errors;
}
-
@Override
public Type typeCheck() {
return new VoidType();
diff --git a/src/ast/nodes/CompForNode.java b/src/ast/nodes/CompForNode.java
index 06c7aee..b7c6924 100644
--- a/src/ast/nodes/CompForNode.java
+++ b/src/ast/nodes/CompForNode.java
@@ -23,7 +23,7 @@ public class CompForNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
errors.addAll(exprlist.checkSemantics(ST, _nesting));
errors.addAll(single_expr.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/CompIterNode.java b/src/ast/nodes/CompIterNode.java
index 6704bd7..8de9f2f 100644
--- a/src/ast/nodes/CompIterNode.java
+++ b/src/ast/nodes/CompIterNode.java
@@ -19,7 +19,7 @@ public class CompIterNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (comp_for != null) {
errors.addAll(comp_for.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/CompNode.java b/src/ast/nodes/CompNode.java
index 8be6ea1..22906df 100644
--- a/src/ast/nodes/CompNode.java
+++ b/src/ast/nodes/CompNode.java
@@ -12,7 +12,7 @@ import org.antlr.v4.runtime.tree.TerminalNode;
*/
public class CompNode implements Node {
- private TerminalNode op;
+ private final TerminalNode op;
public CompNode(TerminalNode op) {
this.op = op;
@@ -20,7 +20,7 @@ public class CompNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- return new ArrayList<SemanticError>();
+ return new ArrayList();
}
// TODO: it should be boolean, right?
diff --git a/src/ast/nodes/CompoundNode.java b/src/ast/nodes/CompoundNode.java
index d21c2c7..845f05e 100644
--- a/src/ast/nodes/CompoundNode.java
+++ b/src/ast/nodes/CompoundNode.java
@@ -10,10 +10,10 @@ import semanticanalysis.SymbolTable;
*/
public class CompoundNode implements Node {
- private Node ifNode;
- private Node funcDef;
- private Node forStmt;
- private Node whileStmt;
+ private final Node ifNode;
+ private final Node funcDef;
+ private final Node forStmt;
+ private final Node whileStmt;
public CompoundNode(Node ifNode, Node funcDef, Node forStmt, Node whileStmt) {
this.ifNode = ifNode;
@@ -24,7 +24,7 @@ public class CompoundNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (ifNode != null) {
errors.addAll(ifNode.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/DottedNameNode.java b/src/ast/nodes/DottedNameNode.java
index df86c99..23f14c1 100644
--- a/src/ast/nodes/DottedNameNode.java
+++ b/src/ast/nodes/DottedNameNode.java
@@ -11,6 +11,7 @@ import org.antlr.v4.runtime.tree.TerminalNode;
* Node for the `dooted_name` statement of the grammar.
*/
public class DottedNameNode implements Node {
+
protected ArrayList<TerminalNode> names;
public DottedNameNode(ArrayList<TerminalNode> names) {
@@ -19,7 +20,7 @@ public class DottedNameNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
for (int i = 0; i < names.size(); ++i) {
ST.insert(names.get(i).toString(), this.typeCheck(), _nesting, null);
diff --git a/src/ast/nodes/ExprNode.java b/src/ast/nodes/ExprNode.java
index 8e3b896..873d537 100644
--- a/src/ast/nodes/ExprNode.java
+++ b/src/ast/nodes/ExprNode.java
@@ -12,11 +12,11 @@ import semanticanalysis.SymbolTable;
*/
public class ExprNode implements Node {
- private AtomNode atom;
- private Node compOp;
- private String op;
- private ArrayList<Node> exprs;
- private ArrayList<Node> trailers;
+ private final AtomNode atom;
+ private final Node compOp;
+ private final String op;
+ private final ArrayList<Node> exprs;
+ private final ArrayList<Node> trailers;
public ExprNode(Node atom, Node compOp, ArrayList<Node> exprs, String op, ArrayList<Node> trailers) {
this.atom = (AtomNode) atom;
@@ -52,7 +52,7 @@ public class ExprNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
// check if the atom is a function
if (atom != null && !trailers.isEmpty()) {
diff --git a/src/ast/nodes/ForStmtNode.java b/src/ast/nodes/ForStmtNode.java
index d4c5e56..74c6ffc 100644
--- a/src/ast/nodes/ForStmtNode.java
+++ b/src/ast/nodes/ForStmtNode.java
@@ -10,8 +10,8 @@ import semanticanalysis.SymbolTable;
*/
public class ForStmtNode implements Node {
- private Node exprList;
- private Node block;
+ private final Node exprList;
+ private final Node block;
public ForStmtNode(Node exprList, Node block) {
this.exprList = exprList;
@@ -34,7 +34,7 @@ public class ForStmtNode implements Node {
*/
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
// Save every atom in the expression's list, except the last one
var l = (ExprListNode) exprList;
diff --git a/src/ast/nodes/FuncdefNode.java b/src/ast/nodes/FuncdefNode.java
index 8985e08..c4f5846 100644
--- a/src/ast/nodes/FuncdefNode.java
+++ b/src/ast/nodes/FuncdefNode.java
@@ -14,9 +14,9 @@ import org.antlr.v4.runtime.tree.TerminalNode;
*/
public class FuncdefNode implements Node {
- private TerminalNode name;
- private Node paramlist;
- private Node block;
+ private final TerminalNode name;
+ private final Node paramlist;
+ private final Node block;
public FuncdefNode(TerminalNode name, Node paramlist, Node block) {
this.name = name;
@@ -26,14 +26,14 @@ public class FuncdefNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
int paramNumber = ((ParamlistNode) paramlist).getParamNumber();
Type returnType = this.block.typeCheck();
FunctionType ft = new FunctionType(paramNumber, returnType);
ST.insert(this.name.toString(), ft, _nesting, "");
- HashMap<String, STentry> HM = new HashMap<String, STentry>();
+ HashMap<String, STentry> HM = new HashMap();
ST.add(HM);
@@ -66,6 +66,7 @@ public class FuncdefNode implements Node {
return "";
}
+ @Override
public String toPrint(String prefix) {
String str = prefix + "Funcdef(" + name + ")\n";
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();
}
diff --git a/src/ast/nodes/ImportNode.java b/src/ast/nodes/ImportNode.java
index 900a909..7e95ee3 100644
--- a/src/ast/nodes/ImportNode.java
+++ b/src/ast/nodes/ImportNode.java
@@ -1,20 +1,20 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `import_stmt` statement of the grammar.
*/
public class ImportNode implements Node {
- private Node dottedName;
- private boolean isFrom;
- private boolean importAs;
- private boolean importAll;
- private ArrayList<String> names;
+
+ private final Node dottedName;
+ private final boolean isFrom;
+ private final boolean importAs;
+ private final boolean importAll;
+ private final ArrayList<String> names;
public ImportNode(Node dottedName, boolean isFrom, boolean importAs, boolean importAll,
ArrayList<String> names) {
@@ -27,7 +27,7 @@ public class ImportNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (isFrom) {
for (int i = 0; i < names.size(); ++i) {
@@ -75,8 +75,9 @@ public class ImportNode implements Node {
}
for (int i = 0; i < names.size(); ++i) {
- if (i == 0 && importAs)
+ if (i == 0 && importAs) {
continue;
+ }
str += prefix + names.get(i) + "\n";
}
diff --git a/src/ast/nodes/Node.java b/src/ast/nodes/Node.java
index 77ba669..9fb58b8 100644
--- a/src/ast/nodes/Node.java
+++ b/src/ast/nodes/Node.java
@@ -1,10 +1,9 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Base interface for a Node.
@@ -87,8 +86,7 @@ public interface Node {
/**
* Checks semantics for a given node for a SymbolTable ST and a level of
- * nesting.
- * Returns a list of `SemanticError`.
+ * nesting. Returns a list of `SemanticError`.
*/
ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting);
@@ -104,8 +102,8 @@ public interface Node {
String codeGeneration();
/**
- * Returns a string for a given node with a prefix.
- * It used when an AST wants to be visualized on screen.
+ * Returns a string for a given node with a prefix. It used when an AST
+ * wants to be visualized on screen.
*/
String toPrint(String prefix);
}
diff --git a/src/ast/nodes/ParamdefNode.java b/src/ast/nodes/ParamdefNode.java
index adadf72..6cdb2d0 100644
--- a/src/ast/nodes/ParamdefNode.java
+++ b/src/ast/nodes/ParamdefNode.java
@@ -17,7 +17,7 @@ public class ParamdefNode extends AtomNode {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- var errors = new ArrayList<SemanticError>();
+ var errors = new ArrayList();
String paramName = this.getId();
if (!ST.top_lookup(paramName)) {
diff --git a/src/ast/nodes/ParamlistNode.java b/src/ast/nodes/ParamlistNode.java
index 0a9696f..cf75d08 100644
--- a/src/ast/nodes/ParamlistNode.java
+++ b/src/ast/nodes/ParamlistNode.java
@@ -1,17 +1,16 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `param_list` statement of the grammar.
*/
public class ParamlistNode implements Node {
- private ArrayList<Node> params;
+ private final ArrayList<Node> params;
public ParamlistNode(ArrayList<Node> _params) {
params = _params;
@@ -19,7 +18,7 @@ public class ParamlistNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
for (var param : params) {
errors.addAll(param.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/ReturnStmtNode.java b/src/ast/nodes/ReturnStmtNode.java
index 0f2dd74..8e34813 100644
--- a/src/ast/nodes/ReturnStmtNode.java
+++ b/src/ast/nodes/ReturnStmtNode.java
@@ -1,16 +1,16 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `return_stmt` statement of the grammar.
*/
public class ReturnStmtNode implements Node {
- private Node exprList;
+
+ private final Node exprList;
public ReturnStmtNode(Node exprList) {
this.exprList = exprList;
@@ -18,7 +18,7 @@ public class ReturnStmtNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (this.exprList != null) {
errors.addAll(this.exprList.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/RootNode.java b/src/ast/nodes/RootNode.java
index 4b29e8d..5bbce8c 100644
--- a/src/ast/nodes/RootNode.java
+++ b/src/ast/nodes/RootNode.java
@@ -20,10 +20,10 @@ public class RootNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
// Create a new HashMap for the current scope
- HashMap<String, STentry> HM = new HashMap<String, STentry>();
+ HashMap<String, STentry> HM = new HashMap();
// Add the HashMap to the SymbolTable
ST.add(HM);
diff --git a/src/ast/nodes/SimpleStmtNode.java b/src/ast/nodes/SimpleStmtNode.java
index b7e5455..b2bc880 100644
--- a/src/ast/nodes/SimpleStmtNode.java
+++ b/src/ast/nodes/SimpleStmtNode.java
@@ -9,10 +9,11 @@ import semanticanalysis.SymbolTable;
* Node for the `simple_stmt` statement of the grammar.
*/
public class SimpleStmtNode implements Node {
- private Node assignment;
- private Node expr;
- private Node returnStmt;
- private Node importStmt;
+
+ private final Node assignment;
+ private final Node expr;
+ private final Node returnStmt;
+ private final Node importStmt;
public SimpleStmtNode(Node assignment, Node expr, Node returnStmt, Node importStmt) {
this.assignment = assignment;
@@ -23,7 +24,7 @@ public class SimpleStmtNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (assignment != null) {
errors.addAll(assignment.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/SimpleStmtsNode.java b/src/ast/nodes/SimpleStmtsNode.java
index 97bffff..ae1044b 100644
--- a/src/ast/nodes/SimpleStmtsNode.java
+++ b/src/ast/nodes/SimpleStmtsNode.java
@@ -9,7 +9,8 @@ import semanticanalysis.SymbolTable;
* Node for the `simple_stmts` statement of the grammar.
*/
public class SimpleStmtsNode implements Node {
- private ArrayList<Node> stmts;
+
+ private final ArrayList<Node> stmts;
public SimpleStmtsNode(ArrayList<Node> stmts) {
this.stmts = stmts;
@@ -17,7 +18,7 @@ public class SimpleStmtsNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
for (Node stmt : stmts) {
errors.addAll(stmt.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/TestlistCompNode.java b/src/ast/nodes/TestlistCompNode.java
index cba056c..32049f5 100644
--- a/src/ast/nodes/TestlistCompNode.java
+++ b/src/ast/nodes/TestlistCompNode.java
@@ -10,8 +10,8 @@ import semanticanalysis.SymbolTable;
*/
public class TestlistCompNode implements Node {
- private ArrayList<Node> exprs;
- private CompForNode comp;
+ private final ArrayList<Node> exprs;
+ private final CompForNode comp;
public TestlistCompNode(ArrayList<Node> exprs, Node comp) {
this.exprs = exprs;
diff --git a/src/ast/nodes/TrailerNode.java b/src/ast/nodes/TrailerNode.java
index 22e43a0..aaa72f3 100644
--- a/src/ast/nodes/TrailerNode.java
+++ b/src/ast/nodes/TrailerNode.java
@@ -12,11 +12,11 @@ import org.antlr.v4.runtime.tree.TerminalNode;
*/
public class TrailerNode implements Node {
- private Node arglist;
- private ArrayList<Node> exprs;
- private TerminalNode methodCall;
- private boolean isParenthesis;
- private boolean isEmpty;
+ private final Node arglist;
+ private final ArrayList<Node> exprs;
+ private final TerminalNode methodCall;
+ private final boolean isParenthesis;
+ private final boolean isEmpty;
public TrailerNode(Node arglist, ArrayList<Node> exprs, TerminalNode methodCall, boolean isParenthesis) {
this.arglist = arglist;
@@ -24,12 +24,12 @@ public class TrailerNode implements Node {
this.methodCall = methodCall;
this.isParenthesis = isParenthesis;
- this.isEmpty = (this.arglist == null && this.exprs.size() == 0 && this.methodCall == null);
+ this.isEmpty = (this.arglist == null && this.exprs.isEmpty() && this.methodCall == null);
}
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
if (arglist != null) {
errors.addAll(arglist.checkSemantics(ST, _nesting));
diff --git a/src/ast/nodes/WhileStmtNode.java b/src/ast/nodes/WhileStmtNode.java
index 6353ec1..1db01ea 100644
--- a/src/ast/nodes/WhileStmtNode.java
+++ b/src/ast/nodes/WhileStmtNode.java
@@ -1,17 +1,17 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `while_stmt` statement of the grammar.
*/
public class WhileStmtNode implements Node {
- private Node expr;
- private Node block;
+
+ private final Node expr;
+ private final Node block;
public WhileStmtNode(Node expr, Node block) {
this.expr = expr;
@@ -20,7 +20,7 @@ public class WhileStmtNode implements Node {
@Override
public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
- ArrayList<SemanticError> errors = new ArrayList<SemanticError>();
+ ArrayList<SemanticError> errors = new ArrayList();
errors.addAll(expr.checkSemantics(ST, _nesting));
errors.addAll(block.checkSemantics(ST, _nesting));