-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariableDelta.java
More file actions
126 lines (98 loc) · 3 KB
/
VariableDelta.java
File metadata and controls
126 lines (98 loc) · 3 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import java.util.*;
public class VariableDelta implements Comparable<VariableDelta> {
public String type;
public String scope;
public String name;
public String value;
public long address;
public long pointsTo;
public String size;
public VariableDelta(
String typeIn,
String scopeIn,
String nameIn,
String valueIn,
long addressIn)
{
type = typeIn;
scope = scopeIn;
name = nameIn;
value = valueIn;
address = addressIn;
pointsTo = -1;
determineSize();
}
public VariableDelta(
String typeIn,
String scopeIn,
String nameIn,
String valueIn,
long addressIn,
long pointsToIn)
{
type = typeIn;
scope = scopeIn;
name = nameIn;
value = valueIn;
address = addressIn;
pointsTo = pointsToIn;
determineSize();
}
// Copy constructor
public VariableDelta(VariableDelta delta) {
this(delta.type, delta.scope, delta.name, delta.value, delta.address, delta.pointsTo);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VariableDelta delta = (VariableDelta) o;
if (scope != null ? !scope.equals(delta.scope) : delta.scope != null) return false;
if (name != null ? !name.equals(delta.name) : delta.name != null) return false;
if (type != null ? !type.equals(delta.type) : delta.type != null) return false;
if (value != null ? !value.equals(delta.value) : delta.value != null) return false;
if (address != delta.address) return false;
return true;
}
@Override
public int hashCode() {
return Objects.hash(type, scope, name, value, address, pointsTo);
}
@Override
public String toString() {
return "[" + scope + "," + name + "]=" + value + System.lineSeparator();
}
public boolean isSameVariable(VariableDelta o) {
return type.equals(o.type) &&
scope.equals(o.scope) &&
name.equals(o.name);
}
public String getKey() {
return scope + "," + name;
}
private void determineSize() {
if (type.contains("pointer")) size = "<address width>";
else if (type.contains("long long")) size = "8";
else if (type.contains("long")) {
if (UIUtils.architecture == 64) size = "8";
else if (UIUtils.architecture == 32) size = "4";
}
else if (type.contains("int")) size = "4";
else if (type.contains("short")) size = "2";
else if (type.contains("char")) size = "1";
else if (type.contains("float")) size = "4";
else if (type.contains("double")) size = "4-8";
else size = "Unknown";
}
public static void applyDelta(VariableDelta target, VariableDelta delta) {
assert target.isSameVariable(delta);
target.type = delta.type;
target.scope = delta.scope;
target.name = delta.name;
target.value = delta.value;
target.address = delta.address;
}
public int compareTo(VariableDelta other) {
return Long.compare(other.address, address); // reverse order
}
} // VariableDelta class