001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
015: * more details.
016: *
017: * You should have received a copy of the GNU General Public License along
018: * with this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.evaluation.value;
022:
023: /**
024: * This LongValue represents a specific long value.
025: *
026: * @author Eric Lafortune
027: */
028: final class SpecificLongValue extends LongValue {
029: private final long value;
030:
031: /**
032: * Creates a new specific long value.
033: */
034: public SpecificLongValue(long value) {
035: this .value = value;
036: }
037:
038: // Implementations for LongValue.
039:
040: public long value() {
041: return value;
042: }
043:
044: // Implementations of binary methods of LongValue.
045:
046: // Perhaps the other value arguments are more specific than apparent
047: // in these methods, so delegate to them.
048:
049: public LongValue generalize(LongValue other) {
050: return other.generalize(this );
051: }
052:
053: public LongValue add(LongValue other) {
054: return other.add(this );
055: }
056:
057: public LongValue subtract(LongValue other) {
058: return other.subtractFrom(this );
059: }
060:
061: public LongValue subtractFrom(LongValue other) {
062: return other.subtract(this );
063: }
064:
065: public LongValue multiply(LongValue other) {
066: return other.multiply(this );
067: }
068:
069: public LongValue divide(LongValue other) {
070: return other.divideOf(this );
071: }
072:
073: public LongValue divideOf(LongValue other) {
074: return other.divide(this );
075: }
076:
077: public LongValue remainder(LongValue other) {
078: return other.remainderOf(this );
079: }
080:
081: public LongValue remainderOf(LongValue other) {
082: return other.remainder(this );
083: }
084:
085: public LongValue shiftLeft(IntegerValue other) {
086: return other.shiftLeftOf(this );
087: }
088:
089: public LongValue shiftRight(IntegerValue other) {
090: return other.shiftRightOf(this );
091: }
092:
093: public LongValue unsignedShiftRight(IntegerValue other) {
094: return other.unsignedShiftRightOf(this );
095: }
096:
097: public LongValue and(LongValue other) {
098: return other.and(this );
099: }
100:
101: public LongValue or(LongValue other) {
102: return other.or(this );
103: }
104:
105: public LongValue xor(LongValue other) {
106: return other.xor(this );
107: }
108:
109: public IntegerValue compare(LongValue other,
110: ValueFactory valueFactory) {
111: return other.compareReverse(this , valueFactory);
112: }
113:
114: // Implementations of unary methods of LongValue.
115:
116: public LongValue negate() {
117: return new SpecificLongValue(-value);
118: }
119:
120: public IntegerValue convertToInteger(ValueFactory valueFactory) {
121: return valueFactory.createIntegerValue((int) value);
122: }
123:
124: public FloatValue convertToFloat(ValueFactory valueFactory) {
125: return valueFactory.createFloatValue((float) value);
126: }
127:
128: public DoubleValue convertToDouble(ValueFactory valueFactory) {
129: return valueFactory.createDoubleValue((double) value);
130: }
131:
132: // Implementations of binary LongValue methods with SpecificLongValue
133: // arguments.
134:
135: public LongValue generalize(SpecificLongValue other) {
136: return this .value == other.value ? this
137: : ValueFactory.LONG_VALUE;
138: }
139:
140: public LongValue add(SpecificLongValue other) {
141: return new SpecificLongValue(this .value + other.value);
142: }
143:
144: public LongValue subtract(SpecificLongValue other) {
145: return new SpecificLongValue(this .value - other.value);
146: }
147:
148: public LongValue subtractFrom(SpecificLongValue other) {
149: return new SpecificLongValue(other.value - this .value);
150: }
151:
152: public LongValue multiply(SpecificLongValue other) {
153: return new SpecificLongValue(this .value * other.value);
154: }
155:
156: public LongValue divide(SpecificLongValue other) {
157: return new SpecificLongValue(this .value / other.value);
158: }
159:
160: public LongValue divideOf(SpecificLongValue other) {
161: return new SpecificLongValue(other.value / this .value);
162: }
163:
164: public LongValue remainder(SpecificLongValue other) {
165: return new SpecificLongValue(this .value % other.value);
166: }
167:
168: public LongValue remainderOf(SpecificLongValue other) {
169: return new SpecificLongValue(other.value % this .value);
170: }
171:
172: public LongValue shiftLeft(SpecificIntegerValue other) {
173: return new SpecificLongValue(this .value << other.value());
174: }
175:
176: public LongValue shiftRight(SpecificIntegerValue other) {
177: return new SpecificLongValue(this .value >> other.value());
178: }
179:
180: public LongValue unsignedShiftRight(SpecificIntegerValue other) {
181: return new SpecificLongValue(this .value >>> other.value());
182: }
183:
184: public LongValue and(SpecificLongValue other) {
185: return new SpecificLongValue(this .value & other.value);
186: }
187:
188: public LongValue or(SpecificLongValue other) {
189: return new SpecificLongValue(this .value | other.value);
190: }
191:
192: public LongValue xor(SpecificLongValue other) {
193: return new SpecificLongValue(this .value ^ other.value);
194: }
195:
196: public IntegerValue compare(SpecificLongValue other,
197: ValueFactory valueFactory) {
198: return this .value < other.value ? valueFactory
199: .createIntegerValue(-1)
200: : this .value == other.value ? valueFactory
201: .createIntegerValue(0) : valueFactory
202: .createIntegerValue(1);
203: }
204:
205: // Implementations for Value.
206:
207: public boolean isSpecific() {
208: return true;
209: }
210:
211: // Implementations for Object.
212:
213: public boolean equals(Object object) {
214: return object != null && this .getClass() == object.getClass()
215: && this .value == ((SpecificLongValue) object).value;
216: }
217:
218: public int hashCode() {
219: return this .getClass().hashCode() ^ (int) value;
220: }
221:
222: public String toString() {
223: return "l:" + value;
224: }
225: }
|