summaryrefslogtreecommitdiff
path: root/src/ast/nodes/TrailerNode.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/TrailerNode.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/TrailerNode.java')
-rw-r--r--src/ast/nodes/TrailerNode.java39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/ast/nodes/TrailerNode.java b/src/ast/nodes/TrailerNode.java
index d70e962..27eb166 100644
--- a/src/ast/nodes/TrailerNode.java
+++ b/src/ast/nodes/TrailerNode.java
@@ -12,17 +12,19 @@ import org.antlr.v4.runtime.tree.TerminalNode;
*/
public class TrailerNode implements Node {
+ private String prefix;
+ private String suffix;
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) {
+ public TrailerNode(Node arglist, ArrayList<Node> exprs, TerminalNode methodCall, String prefix, String suffix){
this.arglist = arglist;
this.exprs = exprs;
this.methodCall = methodCall;
- this.isParenthesis = isParenthesis;
+ this.prefix = prefix;
+ this.suffix = suffix;
this.isEmpty = (this.arglist == null && this.exprs.isEmpty() && this.methodCall == null);
}
@@ -50,10 +52,6 @@ public class TrailerNode implements Node {
return ((ArglistNode) arglist).getArgumentNumber();
}
- public boolean isParenthesis() {
- return this.isParenthesis;
- }
-
@Override
public Type typeCheck() {
return new VoidType();
@@ -68,17 +66,17 @@ public class TrailerNode implements Node {
}
@Override
- public String toPrint(String prefix) {
+ public String printAST(String prefix) {
String str = prefix + "TrailerNode\n";
prefix += " ";
if (arglist != null) {
- str += arglist.toPrint(prefix);
+ str += arglist.printAST(prefix);
}
for (var expr : exprs) {
- str += expr.toPrint(prefix);
+ str += expr.printAST(prefix);
}
if (methodCall != null) {
@@ -92,4 +90,25 @@ public class TrailerNode implements Node {
return str;
}
+ @Override
+ public String toPrint(String prefix) {
+ String str = prefix + this.prefix;
+
+ if (arglist != null) {
+ str += arglist.toPrint("");
+ } else if (methodCall != null) {
+ str += methodCall.getText();
+ } else {
+ for (var expr : exprs) {
+ str += expr.toPrint("");
+ if (exprs.indexOf(expr) != exprs.size() - 1) {
+ str += ", ";
+ }
+ }
+ }
+
+ str += this.suffix;
+ return str;
+ }
+
}