summaryrefslogtreecommitdiff
path: root/src/ast/nodes/ArglistNode.java
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-06-30 13:45:57 +0200
committerGitHub <noreply@github.com>2024-06-30 13:45:57 +0200
commit8aa8b5834953cab15c0687608f4fafea2e6c61be (patch)
tree1835ae7c789136b4a6c44c12efd4247a0b96d893 /src/ast/nodes/ArglistNode.java
parent7125bb27fedaafd5a56b5122e4251b182448ddac (diff)
parent06d7c8dee25c065b1a569337f34d3cd5e892a31d (diff)
Merge pull request #10 from boozec/check-semantics
Co-Authored-By: geno <gabriele.genovese2@studio.unibo.it> Co-Authored-By: L0P0P <grassoemanuele@live.com>
Diffstat (limited to 'src/ast/nodes/ArglistNode.java')
-rw-r--r--src/ast/nodes/ArglistNode.java34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/ast/nodes/ArglistNode.java b/src/ast/nodes/ArglistNode.java
index f0c33e1..425e4c6 100644
--- a/src/ast/nodes/ArglistNode.java
+++ b/src/ast/nodes/ArglistNode.java
@@ -1,15 +1,16 @@
package ast.nodes;
+import ast.types.*;
import java.util.ArrayList;
-
+import java.util.Arrays;
import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
-import ast.types.*;
/**
* Node for the `arglist` statement of the grammar.
*/
public class ArglistNode implements Node {
+
protected ArrayList<Node> arguments;
public ArglistNode(ArrayList<Node> arguments) {
@@ -18,15 +19,40 @@ 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) {
- errors.addAll(arg.checkSemantics(ST, _nesting));
+ if (arg instanceof ExprNode) {
+ ExprNode argExpr = (ExprNode) arg;
+ String argName = argExpr.getId();
+
+ // TODO: check fucking IntType for params
+ // TODO: remove fucking comments
+ if (argName != null) {
+ if (Arrays.asList(bif).contains(argName)) {
+ continue;
+ }
+
+ if (ST.lookup(argName) != null && ST.lookup(argName).getType() instanceof ImportType) {
+ continue;
+ }
+
+ if (ST.nslookup(argName) < 0 && argExpr.typeCheck() instanceof AtomType) {
+ errors.add(new SemanticError("name '" + argName + "' is not defined."));
+ }
+ } else {
+ errors.addAll(arg.checkSemantics(ST, _nesting));
+ }
+ }
}
return errors;
}
+ public int getArgumentNumber() {
+ return arguments.size();
+ }
+
@Override
public Type typeCheck() {
return new VoidType();