Skip to content

Commit c9200af

Browse files
Removed long field from Number class
1 parent 6353876 commit c9200af

File tree

2 files changed

+6
-51
lines changed

2 files changed

+6
-51
lines changed

src/main/java/it/unipr/analysis/AbstractMemory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,10 @@ public byte[] readBytes(int offset, int length) {
409409
byte[] out = new byte[length];
410410
for (int i = 0; i < length; i++) {
411411
AbstractByte b = backing[offset + i];
412+
// Treat TOP/unknown as 0x00
412413
if (b.isTop())
413414
return null;
414-
out[i] = b.isTop() ? (byte) 0 : b.getValue();
415+
out[i] = b.getValue();
415416
}
416417
return out;
417418
}

src/main/java/it/unipr/analysis/Number.java

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,15 @@ public class Number implements Comparable<Number> {
1717
*/
1818
public static final BigInteger MAX_INT = BigInteger.valueOf(2).pow(31);
1919

20-
/**
21-
* Maximal representable long value.
22-
*/
23-
public static final BigInteger MAX_LONG = BigInteger.valueOf(2).pow(63);
24-
2520
public static final Number ZERO = new Number(0);
2621
public static final Number ONE = new Number(1);
2722

2823
public enum Type {
2924
INT,
30-
LONG,
3125
BIGINTEGER
3226
}
3327

3428
private final int i;
35-
private final long l;
3629
private final BigInteger b;
3730

3831
/**
@@ -42,33 +35,15 @@ public enum Type {
4235
*/
4336
public Number(int i) {
4437
this.i = i;
45-
this.l = -1;
46-
this.b = null;
47-
}
48-
49-
/**
50-
* Builds a number starting from a long value.
51-
*
52-
* @param l the long value
53-
*/
54-
public Number(long l) {
55-
this.l = l;
5638
this.b = null;
57-
this.i = -1;
5839
}
5940

6041
public Number(BigInteger other) {
6142
if (other.compareTo(MAX_INT) < 0) {
6243
this.i = other.intValue();
63-
this.l = -1;
64-
this.b = null;
65-
} else if (other.compareTo(MAX_LONG) < 0) {
66-
this.i = -1;
67-
this.l = other.longValue();
6844
this.b = null;
6945
} else {
7046
this.i = -1;
71-
this.l = -1;
7247
this.b = other;
7348
}
7449
}
@@ -81,9 +56,8 @@ public Number(BigInteger other) {
8156
public Type getType() {
8257
if (b != null)
8358
return Type.BIGINTEGER;
84-
if (i != -1)
85-
return Type.INT;
86-
return Type.LONG;
59+
60+
return Type.INT;
8761
}
8862

8963
/**
@@ -95,14 +69,6 @@ public int getInt() {
9569
return i;
9670
}
9771

98-
/**
99-
* Yields the long value.
100-
*
101-
* @return the long value
102-
*/
103-
public long getLong() {
104-
return l;
105-
}
10672

10773
/**
10874
* Yields the big integer value.
@@ -117,8 +83,6 @@ public static BigInteger toBigInteger(Number other) {
11783
BigInteger ot;
11884
if (other.getType() == Type.INT)
11985
ot = BigInteger.valueOf(other.getInt());
120-
else if (other.getType() == Type.LONG)
121-
ot = BigInteger.valueOf(other.getLong());
12286
else
12387
ot = other.getBigInteger();
12488

@@ -135,8 +99,6 @@ else if (other.getType() == Type.LONG)
13599
public Number add(Number other) {
136100
if (this.getType() == other.getType() && other.getType() == Type.INT)
137101
return new Number(i + other.getInt());
138-
if (this.getType() == other.getType() && other.getType() == Type.LONG)
139-
return new Number((long) l + other.getLong());
140102

141103
BigInteger me = toBigInteger(this);
142104
BigInteger ot = toBigInteger(other);
@@ -154,8 +116,6 @@ public Number add(Number other) {
154116
public Number subtract(Number other) {
155117
if (this.getType() == other.getType() && other.getType() == Type.INT)
156118
return new Number(i - other.getInt());
157-
if (this.getType() == other.getType() && other.getType() == Type.LONG)
158-
return new Number(l - other.getLong());
159119

160120
BigInteger me = toBigInteger(this);
161121
BigInteger ot = toBigInteger(other);
@@ -186,8 +146,6 @@ public Number multiply(Number other) {
186146
public Number divide(Number other) {
187147
if (this.getType() == other.getType() && other.getType() == Type.INT)
188148
return new Number(i / other.getInt());
189-
if (this.getType() == other.getType() && other.getType() == Type.LONG)
190-
return new Number(l / other.getLong());
191149

192150
BigInteger me = toBigInteger(this);
193151
BigInteger ot = toBigInteger(other);
@@ -291,25 +249,21 @@ public Number shiftLeft(int other) {
291249
BigInteger mask = BigInteger.ONE.shiftLeft(256).subtract(BigInteger.ONE);
292250
BigInteger evmResult = shifted.and(mask);
293251
return new Number(evmResult);
294-
252+
295253
}
296254

297255
@Override
298256
public String toString() {
299257
if (b != null)
300258
return b.toString();
301-
if (i != -1)
302-
return i + "";
303-
return l + "";
259+
return i + "";
304260
}
305261

306262
@Override
307263
public int compareTo(Number other) {
308264
if (getType() == other.getType()) {
309265
if (getType() == Type.INT)
310266
return Integer.compare(this.i, other.i);
311-
else if (getType() == Type.LONG)
312-
return Long.compare(this.l, other.l);
313267
}
314268

315269
// Otherwise, fall back to BigInteger comparisons.

0 commit comments

Comments
 (0)