summaryrefslogtreecommitdiff
path: root/src/ast/nodes/FuncdefNode.java
diff options
context:
space:
mode:
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;
}