diff options
author | Emanuele Grasso <96300448+L0P0P@users.noreply.github.com> | 2024-07-14 18:48:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-14 18:48:09 +0200 |
commit | ce49d20a5fe3726e1800bc495a25c7617212abf4 (patch) | |
tree | 5a1a79efa79e7bf6dcf3d3151aec2edf6a47b3e7 /src/ast/nodes/AssignmentNode.java | |
parent | 57599a42b863cc48050c137de2ec108aa1d59a44 (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/AssignmentNode.java')
-rw-r--r-- | src/ast/nodes/AssignmentNode.java | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/ast/nodes/AssignmentNode.java b/src/ast/nodes/AssignmentNode.java index 13e7a33..688be76 100644 --- a/src/ast/nodes/AssignmentNode.java +++ b/src/ast/nodes/AssignmentNode.java @@ -16,15 +16,20 @@ public class AssignmentNode implements Node { private final Node assign; private final ExprListNode rhr; + private final int startIndex; + private final int endIndex; + // Useful for code gen private int offset; private boolean alreadyDef; - public AssignmentNode(Node lhr, Node assign, Node rhr) { + public AssignmentNode(Node lhr, Node assign, Node rhr, int startIndex, int endIndex) { this.lhr = (ExprListNode) lhr; this.assign = assign; this.rhr = (ExprListNode) rhr; this.alreadyDef = false; + this.startIndex = startIndex; + this.endIndex = endIndex; } @Override @@ -42,11 +47,10 @@ public class AssignmentNode implements Node { STentry e = ST.lookup(leftAtom.getId()); if (ft != null) { ft.addLocalVar(); - } else { - Label.addGlobalVar(); } if (e == null) { + Label.addGlobalVar(); ST.insert(leftAtom.getId(), new AtomType(), _nesting, ""); e = ST.lookup(leftAtom.getId()); } else { @@ -58,9 +62,9 @@ public class AssignmentNode implements Node { offset = e.getOffset(); } return errors; + } - // TODO: check it out for this type @Override public Type typeCheck() { return rhr.typeCheck(); @@ -92,9 +96,31 @@ public class AssignmentNode implements Node { } @Override + public String printAST(String prefix) { + return prefix + "Assignment\n" + lhr.printAST(prefix + " ") + assign.printAST(prefix + " ") + + rhr.printAST(prefix + " "); + } + + @Override public String toPrint(String prefix) { - return prefix + "Assignment\n" + lhr.toPrint(prefix + " ") + assign.toPrint(prefix + " ") - + rhr.toPrint(prefix + " "); + String str = prefix; + str += lhr.toPrint("") + " " + assign.toPrint("") + " " + rhr.toPrint(""); + return str; } + public ExprListNode getLhr() { + return lhr; + } + + public ExprListNode getRhr() { + return rhr; + } + + public int getLhrIndex() { + return this.startIndex; + } + + public int getRhrIndex() { + return this.endIndex; + } } |