Skip to content

Commit 13a0bd3

Browse files
committed
Adding ability to retrieve constants from ConstantValueTags
1 parent 27274c8 commit 13a0bd3

File tree

6 files changed

+104
-79
lines changed

6 files changed

+104
-79
lines changed

src/soot/tagkit/ConstantValueTag.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,24 @@
2525

2626
package soot.tagkit;
2727

28-
public abstract class ConstantValueTag implements Tag
29-
{
30-
protected byte[] bytes; // encoded constant
31-
32-
protected ConstantValueTag() {
33-
}
34-
35-
public String getName() {
36-
String className = getClass().getName();
37-
return className.substring(className.lastIndexOf('.') + 1);
38-
}
39-
40-
public byte[] getValue() {
41-
return bytes;
42-
}
43-
public abstract String toString();
44-
}
28+
import soot.jimple.Constant;
29+
30+
public abstract class ConstantValueTag implements Tag {
31+
protected byte[] bytes; // encoded constant
32+
33+
protected ConstantValueTag() {
34+
}
35+
36+
public String getName() {
37+
String className = getClass().getName();
38+
return className.substring(className.lastIndexOf('.') + 1);
39+
}
4540

41+
public byte[] getValue() {
42+
return bytes;
43+
}
44+
45+
public abstract Constant getConstant();
46+
47+
public abstract String toString();
48+
}

src/soot/tagkit/DoubleConstantValueTag.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
package soot.tagkit;
2727

28+
import soot.jimple.Constant;
29+
import soot.jimple.DoubleConstant;
30+
2831
public class DoubleConstantValueTag extends ConstantValueTag
2932
{
3033
private final double value;
@@ -72,5 +75,10 @@ public DoubleConstantValueTag(double val){
7275
public String toString() {
7376
return "ConstantValue: "+Double.toString(value);
7477
}
78+
79+
@Override
80+
public DoubleConstant getConstant() {
81+
return DoubleConstant.v(value);
82+
}
7583
}
7684

src/soot/tagkit/FloatConstantValueTag.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
package soot.tagkit;
2727

28+
import soot.jimple.Constant;
29+
import soot.jimple.FloatConstant;
30+
2831
public class FloatConstantValueTag extends ConstantValueTag
2932
{
3033
private final float value;
@@ -64,5 +67,10 @@ public float getFloatValue() {
6467
public String toString() {
6568
return "ConstantValue: "+Float.toString(value);
6669
}
70+
71+
@Override
72+
public FloatConstant getConstant() {
73+
return FloatConstant.v(value);
74+
}
6775
}
6876

src/soot/tagkit/IntegerConstantValueTag.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,27 @@
2525

2626
package soot.tagkit;
2727

28-
public class IntegerConstantValueTag extends ConstantValueTag
29-
{
30-
private final int value;
31-
32-
public IntegerConstantValueTag(int value) {
33-
this.value = value;
34-
this.bytes = new byte[] {
35-
(byte)((value >> 24) & 0xff),
36-
(byte)((value >> 16) & 0xff),
37-
(byte)((value >> 8) & 0xff),
38-
(byte)((value ) & 0xff)
39-
};
40-
}
41-
42-
public int getIntValue() {
43-
return value;
44-
}
45-
public String toString() {
46-
return "ConstantValue: "+Integer.toString(value);
47-
}
48-
}
28+
import soot.jimple.IntConstant;
29+
30+
public class IntegerConstantValueTag extends ConstantValueTag {
31+
private final int value;
32+
33+
public IntegerConstantValueTag(int value) {
34+
this.value = value;
35+
this.bytes = new byte[] { (byte) ((value >> 24) & 0xff), (byte) ((value >> 16) & 0xff),
36+
(byte) ((value >> 8) & 0xff), (byte) ((value) & 0xff) };
37+
}
4938

39+
public int getIntValue() {
40+
return value;
41+
}
42+
43+
public String toString() {
44+
return "ConstantValue: " + Integer.toString(value);
45+
}
46+
47+
@Override
48+
public IntConstant getConstant() {
49+
return IntConstant.v(value);
50+
}
51+
}

src/soot/tagkit/LongConstantValueTag.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,28 @@
2525

2626
package soot.tagkit;
2727

28-
public class LongConstantValueTag extends ConstantValueTag
29-
{
30-
private final long value;
31-
32-
public LongConstantValueTag(long value) {
33-
this.value = value;
34-
this.bytes = new byte[] {
35-
(byte)((value >> 56) & 0xff),
36-
(byte)((value >> 48) & 0xff),
37-
(byte)((value >> 40) & 0xff),
38-
(byte)((value >> 32) & 0xff),
39-
(byte)((value >> 24) & 0xff),
40-
(byte)((value >> 16) & 0xff),
41-
(byte)((value >> 8) & 0xff),
42-
(byte)((value ) & 0xff)
43-
};
44-
}
45-
46-
public long getLongValue() {
47-
return value;
48-
}
49-
public String toString() {
50-
return "ConstantValue: "+Long.toString(value);
51-
}
52-
}
28+
import soot.jimple.LongConstant;
29+
30+
public class LongConstantValueTag extends ConstantValueTag {
31+
private final long value;
32+
33+
public LongConstantValueTag(long value) {
34+
this.value = value;
35+
this.bytes = new byte[] { (byte) ((value >> 56) & 0xff), (byte) ((value >> 48) & 0xff),
36+
(byte) ((value >> 40) & 0xff), (byte) ((value >> 32) & 0xff), (byte) ((value >> 24) & 0xff),
37+
(byte) ((value >> 16) & 0xff), (byte) ((value >> 8) & 0xff), (byte) ((value) & 0xff) };
38+
}
5339

40+
public long getLongValue() {
41+
return value;
42+
}
43+
44+
public String toString() {
45+
return "ConstantValue: " + Long.toString(value);
46+
}
47+
48+
@Override
49+
public LongConstant getConstant() {
50+
return LongConstant.v(value);
51+
}
52+
}

src/soot/tagkit/StringConstantValueTag.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,26 @@
2626
package soot.tagkit;
2727

2828
import soot.coffi.CONSTANT_Utf8_info;
29+
import soot.jimple.StringConstant;
2930

30-
public class StringConstantValueTag extends ConstantValueTag
31-
{
32-
private final String value;
33-
34-
public StringConstantValueTag(String value) {
35-
this.value = value;
36-
this.bytes = CONSTANT_Utf8_info.toUtf8(value);
37-
}
38-
39-
public String getStringValue() {
40-
return value;
41-
}
42-
public String toString() {
43-
return "ConstantValue: "+value;
44-
}
45-
}
31+
public class StringConstantValueTag extends ConstantValueTag {
32+
private final String value;
33+
34+
public StringConstantValueTag(String value) {
35+
this.value = value;
36+
this.bytes = CONSTANT_Utf8_info.toUtf8(value);
37+
}
38+
39+
public String getStringValue() {
40+
return value;
41+
}
4642

43+
public String toString() {
44+
return "ConstantValue: " + value;
45+
}
46+
47+
@Override
48+
public StringConstant getConstant() {
49+
return StringConstant.v(value);
50+
}
51+
}

0 commit comments

Comments
 (0)