01: /*
02: * HanselValue.java
03: *
04: * Created on 22. August 2004, 14:14
05: */
06:
07: package org.hansel.stack;
08:
09: import org.objectweb.asm.Type;
10: import org.objectweb.asm.tree.analysis.Value;
11:
12: /**
13: *
14: * @author Niklas Mehner
15: */
16: public class HanselValue implements Value {
17: public static final HanselValue ZERO_1 = new HanselValue("0",
18: false, 1);
19: public static final HanselValue ZERO_2 = new HanselValue("0",
20: false, 2);
21: public static final HanselValue ONE_1 = new HanselValue("1", false,
22: 1);
23: public static final HanselValue ONE_2 = new HanselValue("1", false,
24: 2);
25: public static final HanselValue NULL = new HanselValue("null",
26: false, 1);
27: public static final HanselValue DONT_CARE = new HanselValue(
28: "unknown", false, 1);
29:
30: private String value;
31: private boolean booleanType;
32: private int size;
33:
34: public HanselValue(String value, boolean booleanType, int size) {
35: this .value = value;
36: this .booleanType = booleanType;
37: this .size = size;
38: }
39:
40: public boolean isBoolType() {
41: return booleanType;
42: }
43:
44: public boolean equals(Value obj) {
45: return value.equals(((HanselValue) obj).value);
46: }
47:
48: public int getSize() {
49: return size;
50: }
51:
52: public HanselValue invert() {
53: return new NotOp(this );
54: }
55:
56: public HanselValue compress() {
57: return this ;
58: }
59:
60: public String toString() {
61: return value;
62: }
63:
64: public String toString(Type requiredType) {
65: String result = toString();
66:
67: // Translate integers into booleans if required.
68: if (requiredType == Type.BOOLEAN_TYPE) {
69: if ("0".equals(value)) {
70: return "false";
71: }
72:
73: if ("1".equals(value)) {
74: return "true";
75: }
76: }
77:
78: return result;
79: }
80:
81: }
|