summaryrefslogtreecommitdiff
path: root/src/ast/nodes/FuncdefNode.java
diff options
context:
space:
mode:
authorEmanuele Grasso <96300448+L0P0P@users.noreply.github.com>2024-07-14 18:48:09 +0200
committerGitHub <noreply@github.com>2024-07-14 18:48:09 +0200
commitce49d20a5fe3726e1800bc495a25c7617212abf4 (patch)
tree5a1a79efa79e7bf6dcf3d3151aec2edf6a47b3e7 /src/ast/nodes/FuncdefNode.java
parent57599a42b863cc48050c137de2ec108aa1d59a44 (diff)
Reaching definition analysis (#17)
Co-authored-by: Santo Cariotti <santo@dcariotti.me> Co-authored-by: geno <gabriele.genovese2@studio.unibo.it> Co-authored-by: geno <gabrigeno@gmail.com>
Diffstat (limited to 'src/ast/nodes/FuncdefNode.java')
-rw-r--r--src/ast/nodes/FuncdefNode.java25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/ast/nodes/FuncdefNode.java b/src/ast/nodes/FuncdefNode.java
index c2671b2..e99f3a3 100644
--- a/src/ast/nodes/FuncdefNode.java
+++ b/src/ast/nodes/FuncdefNode.java
@@ -22,7 +22,11 @@ public class FuncdefNode implements Node {
public FuncdefNode(TerminalNode name, Node paramlist, Node block) {
this.name = name;
- this.paramlist = paramlist;
+ if (paramlist != null) {
+ this.paramlist = paramlist;
+ } else {
+ this.paramlist = new ParamlistNode(new ArrayList<Node>());
+ }
this.block = block;
this.funLabel = Label.newFun("FUN");
}
@@ -62,7 +66,6 @@ public class FuncdefNode implements Node {
return errors;
}
- // FIXME: this type must be the same of the return stmt variable
@Override
public Type typeCheck() {
return new VoidType();
@@ -84,17 +87,29 @@ public class FuncdefNode implements Node {
}
@Override
- public String toPrint(String prefix) {
+ public String printAST(String prefix) {
String str = prefix + "Funcdef(" + name + ")\n";
prefix += " ";
if (paramlist != null) {
- str += paramlist.toPrint(prefix);
+ str += paramlist.printAST(prefix);
}
- str += block.toPrint(prefix);
+ str += block.printAST(prefix);
+
+ return str;
+ }
+
+ @Override
+ public String toPrint(String prefix) {
+ String str = "\n" + prefix + "def " + this.name + '(';
+ if (paramlist != null) {
+ str += paramlist.toPrint("");
+ }
+ str += "):\n";
+ str += block.toPrint(prefix + "\t") + "\n";
return str;
}