summaryrefslogtreecommitdiff
path: root/st/TokenKey.java
diff options
context:
space:
mode:
Diffstat (limited to 'st/TokenKey.java')
-rw-r--r--st/TokenKey.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/st/TokenKey.java b/st/TokenKey.java
new file mode 100644
index 0000000..2319917
--- /dev/null
+++ b/st/TokenKey.java
@@ -0,0 +1,45 @@
+package st;
+
+/**
+ * This class is a data structure used to distinguish tokens in
+ * a given program. Tokens are considered unique if their "beginLine"
+ * and name are different.
+ */
+public class TokenKey {
+
+ private String name;
+ private int beginLine;
+
+ public TokenKey(String name, int beginLine) {
+ // classes CANNOT collide, so CALLEES ARE EXPECTED TO USE ZERO!
+ this.name = name;
+ this.beginLine = beginLine;
+ }
+
+ @Override public String toString() {
+ return String.format("%s (%d)",
+ this.name,
+ this.beginLine);
+ }
+
+
+ @Override public boolean equals(Object other) {
+ boolean ret = false;
+ TokenKey o;
+ if (other instanceof TokenKey &&
+ (o = (TokenKey) other).name == this.name &&
+ o.beginLine == this.beginLine) {
+ ret = true;
+ }
+ return ret;
+ }
+
+ @Override public int hashCode() {
+ return this.name.hashCode();
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+}