From ce49d20a5fe3726e1800bc495a25c7617212abf4 Mon Sep 17 00:00:00 2001 From: Emanuele Grasso <96300448+L0P0P@users.noreply.github.com> Date: Sun, 14 Jul 2024 18:48:09 +0200 Subject: Reaching definition analysis (#17) Co-authored-by: Santo Cariotti Co-authored-by: geno Co-authored-by: geno --- src/ast/nodes/TrailerNode.java | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'src/ast/nodes/TrailerNode.java') 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 exprs; private final TerminalNode methodCall; - private final boolean isParenthesis; private final boolean isEmpty; - public TrailerNode(Node arglist, ArrayList exprs, TerminalNode methodCall, boolean isParenthesis) { + public TrailerNode(Node arglist, ArrayList 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; + } + } -- cgit v1.2.3-18-g5258