-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPointer.java
More file actions
92 lines (82 loc) · 2.35 KB
/
APointer.java
File metadata and controls
92 lines (82 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package pta;
public class APointer {
public static boolean useContext = true;
String name, field;
// `indexlv` is used to distinguish generated allocId (for NewMultiArrayExpr)
// We can't use "field" to store this because during the execution of
// anderson, it is possible that there will be pointers with both nontrivial
// `indexlv` and `field`
int id, indexlv;
String context;
public APointer(String name_, String field_, String context_) {
name = name_;
field = field_;
id = 0;
indexlv = 0;
context = useContext ? context_ : "qwq";
}
public APointer(String name_, String field_, int indexlv_, String context_) {
name = name_;
field = field_;
id = 0;
indexlv = indexlv_;
context = useContext ? context_ : "qwq";
}
public APointer(int id_, String field_, String context_) {
name = null;
field = field_;
id = id_;
indexlv = 0;
context = useContext ? context_ : "qwq";
}
public APointer(int id_, String field_, int indexlv_, String context_) {
name = null;
field = field_;
id = id_;
indexlv = indexlv_;
context = useContext ? context_ : "qwq";
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
APointer that = (APointer) o;
boolean ret = true;
if (name != null && that.name != null)
ret &= name.equals(that.name);
else if (name == null ^ that.name == null)
return false;
if (field != null && that.field != null)
ret &= field.equals(that.field);
else if (field == null ^ that.field == null)
return false;
return ret && id == that.id && indexlv == that.indexlv && context.equals(that.context);
}
public APointer deField() {
if (name == null)
return new APointer(id, null, indexlv, context);
else
return new APointer(name, null, indexlv, context);
}
public String hashString() {
return id + "||" + name + "." + field + "[[" + indexlv + "]]" + "&" + context + "&";
}
@Override
public int hashCode() {
return hashString().hashCode();
}
@Override
public String toString() {
String indexlvexpr = "";
if (indexlv != 0)
indexlvexpr = "[[" + Integer.toString(indexlv) + "]]";
if (name == null)
return context + ": " + "Alloc_" + id + indexlvexpr;
else if (field == null)
return context + ": " + name + indexlvexpr;
else
return context + ": " + name + "." + field + indexlvexpr;
}
}