diff options
author | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-30 13:36:37 +0200 |
---|---|---|
committer | geno <gabriele.genovese2@studio.unibo.it> | 2024-06-30 13:36:37 +0200 |
commit | afff6a80cd58f7787efa1398f7c8cbdce8989323 (patch) | |
tree | e6021201d6e7049da640687c7ce61c898aaea4d8 /src/semanticanalysis | |
parent | aaa97e2e41c0aa17a6f99099dd39bb73a935fe02 (diff) |
fixed warnings, better formatting, final added where possible
Diffstat (limited to 'src/semanticanalysis')
-rw-r--r-- | src/semanticanalysis/STentry.java | 7 | ||||
-rw-r--r-- | src/semanticanalysis/SemanticError.java | 4 | ||||
-rw-r--r-- | src/semanticanalysis/Share.java | 4 | ||||
-rw-r--r-- | src/semanticanalysis/SymbolTable.java | 20 |
4 files changed, 15 insertions, 20 deletions
diff --git a/src/semanticanalysis/STentry.java b/src/semanticanalysis/STentry.java index 07b62c8..51fb109 100644 --- a/src/semanticanalysis/STentry.java +++ b/src/semanticanalysis/STentry.java @@ -6,9 +6,10 @@ import ast.types.Type; * Entry class for the symbol table. */ public class STentry { - private Type type; - private int offset; - private int nesting; + + private final Type type; + private final int offset; + private final int nesting; private String label; public STentry(Type type, int offset, int nesting) { diff --git a/src/semanticanalysis/SemanticError.java b/src/semanticanalysis/SemanticError.java index 745e3fb..ac2dc4c 100644 --- a/src/semanticanalysis/SemanticError.java +++ b/src/semanticanalysis/SemanticError.java @@ -4,12 +4,14 @@ package semanticanalysis; * Class respresents a semantic error. */ public class SemanticError { - private String msg; + + private final String msg; public SemanticError(String msg) { this.msg = msg; } + @Override public String toString() { return msg; } diff --git a/src/semanticanalysis/Share.java b/src/semanticanalysis/Share.java index c98fc53..7542cf7 100644 --- a/src/semanticanalysis/Share.java +++ b/src/semanticanalysis/Share.java @@ -1,7 +1,7 @@ package semanticanalysis; -import java.util.*; import java.io.*; +import java.util.*; public class Share { @@ -10,7 +10,7 @@ public class Share { * generic because it's used a custom contains function. */ public static ArrayList<SemanticError> removeDuplicates(ArrayList<SemanticError> list) { - ArrayList<SemanticError> newList = new ArrayList<SemanticError>(); + ArrayList<SemanticError> newList = new ArrayList(); for (SemanticError element : list) { if (!customContains(newList, element)) { diff --git a/src/semanticanalysis/SymbolTable.java b/src/semanticanalysis/SymbolTable.java index db9649c..b620af7 100644 --- a/src/semanticanalysis/SymbolTable.java +++ b/src/semanticanalysis/SymbolTable.java @@ -1,8 +1,8 @@ package semanticanalysis; +import ast.types.*; import java.util.ArrayList; import java.util.HashMap; -import ast.types.*; /** * Class representing a symbol table. It's a list of hash table symbol table. We @@ -11,12 +11,12 @@ import ast.types.*; */ public class SymbolTable { - private ArrayList<HashMap<String, STentry>> symbolTable; - private ArrayList<Integer> offset; + private final ArrayList<HashMap<String, STentry>> symbolTable; + private final ArrayList<Integer> offset; public SymbolTable() { - this.symbolTable = new ArrayList<HashMap<String, STentry>>(); - this.offset = new ArrayList<Integer>(); + this.symbolTable = new ArrayList(); + this.offset = new ArrayList(); } /** @@ -96,7 +96,7 @@ public class SymbolTable { */ public boolean top_lookup(String id) { int n = symbolTable.size() - 1; - STentry T = null; + STentry T; HashMap<String, STentry> H = symbolTable.get(n); T = H.get(id); return (T != null); @@ -125,14 +125,6 @@ public class SymbolTable { // We always increment the offset by 1 otherwise we need ad-hoc bytecode // operations - // FIXME: wtf is that? - // if (type.getClass().equals((new BoolType()).getClass())) { - // offs = offs + 1; - // } else if (type.getClass().equals((new IntType()).getClass())) { - // offs = offs + 1; - // } else { - // offs = offs + 1; - // } offs = offs + 1; this.offset.add(offs); |