001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 1997-1999 Raja Vallee-Rai
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: /*
021: * Modified by the Sable Research Group and others 1997-1999.
022: * See the 'credits' file distributed with Soot for the complete list of
023: * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
024: */
025:
026: package soot.jimple;
027:
028: import soot.*;
029: import soot.util.*;
030:
031: public class LongConstant extends ArithmeticConstant {
032: public final long value;
033:
034: private LongConstant(long value) {
035: this .value = value;
036: }
037:
038: public static LongConstant v(long value) {
039: return new LongConstant(value);
040: }
041:
042: public boolean equals(Object c) {
043: return c instanceof LongConstant
044: && ((LongConstant) c).value == this .value;
045: }
046:
047: /** Returns a hash code for this DoubleConstant object. */
048: public int hashCode() {
049: return (int) (value ^ (value >>> 32));
050: }
051:
052: // PTC 1999/06/28
053: public NumericConstant add(NumericConstant c) {
054: if (!(c instanceof LongConstant))
055: throw new IllegalArgumentException("LongConstant expected");
056: return LongConstant.v(this .value + ((LongConstant) c).value);
057: }
058:
059: public NumericConstant subtract(NumericConstant c) {
060: if (!(c instanceof LongConstant))
061: throw new IllegalArgumentException("LongConstant expected");
062: return LongConstant.v(this .value - ((LongConstant) c).value);
063: }
064:
065: public NumericConstant multiply(NumericConstant c) {
066: if (!(c instanceof LongConstant))
067: throw new IllegalArgumentException("LongConstant expected");
068: return LongConstant.v(this .value * ((LongConstant) c).value);
069: }
070:
071: public NumericConstant divide(NumericConstant c) {
072: if (!(c instanceof LongConstant))
073: throw new IllegalArgumentException("LongConstant expected");
074: return LongConstant.v(this .value / ((LongConstant) c).value);
075: }
076:
077: public NumericConstant remainder(NumericConstant c) {
078: if (!(c instanceof LongConstant))
079: throw new IllegalArgumentException("LongConstant expected");
080: return LongConstant.v(this .value % ((LongConstant) c).value);
081: }
082:
083: public NumericConstant equalEqual(NumericConstant c) {
084: if (!(c instanceof LongConstant))
085: throw new IllegalArgumentException("LongConstant expected");
086: return IntConstant
087: .v((this .value == ((LongConstant) c).value) ? 1 : 0);
088: }
089:
090: public NumericConstant notEqual(NumericConstant c) {
091: if (!(c instanceof LongConstant))
092: throw new IllegalArgumentException("LongConstant expected");
093: return IntConstant
094: .v((this .value != ((LongConstant) c).value) ? 1 : 0);
095: }
096:
097: public NumericConstant lessThan(NumericConstant c) {
098: if (!(c instanceof LongConstant))
099: throw new IllegalArgumentException("LongConstant expected");
100: return IntConstant
101: .v((this .value < ((LongConstant) c).value) ? 1 : 0);
102: }
103:
104: public NumericConstant lessThanOrEqual(NumericConstant c) {
105: if (!(c instanceof LongConstant))
106: throw new IllegalArgumentException("LongConstant expected");
107: return IntConstant
108: .v((this .value <= ((LongConstant) c).value) ? 1 : 0);
109: }
110:
111: public NumericConstant greaterThan(NumericConstant c) {
112: if (!(c instanceof LongConstant))
113: throw new IllegalArgumentException("LongConstant expected");
114: return IntConstant
115: .v((this .value > ((LongConstant) c).value) ? 1 : 0);
116: }
117:
118: public NumericConstant greaterThanOrEqual(NumericConstant c) {
119: if (!(c instanceof LongConstant))
120: throw new IllegalArgumentException("LongConstant expected");
121: return IntConstant
122: .v((this .value >= ((LongConstant) c).value) ? 1 : 0);
123: }
124:
125: public IntConstant cmp(LongConstant c) {
126: if (this .value > c.value)
127: return IntConstant.v(1);
128: else if (this .value == c.value)
129: return IntConstant.v(0);
130: else
131: return IntConstant.v(-1);
132: }
133:
134: public NumericConstant negate() {
135: return LongConstant.v(-(this .value));
136: }
137:
138: public ArithmeticConstant and(ArithmeticConstant c) {
139: if (!(c instanceof LongConstant))
140: throw new IllegalArgumentException("LongConstant expected");
141: return LongConstant.v(this .value & ((LongConstant) c).value);
142: }
143:
144: public ArithmeticConstant or(ArithmeticConstant c) {
145: if (!(c instanceof LongConstant))
146: throw new IllegalArgumentException("LongConstant expected");
147: return LongConstant.v(this .value | ((LongConstant) c).value);
148: }
149:
150: public ArithmeticConstant xor(ArithmeticConstant c) {
151: if (!(c instanceof LongConstant))
152: throw new IllegalArgumentException("LongConstant expected");
153: return LongConstant.v(this .value ^ ((LongConstant) c).value);
154: }
155:
156: public ArithmeticConstant shiftLeft(ArithmeticConstant c) {
157: // NOTE CAREFULLY: the RHS of a shift op is not (!)
158: // of Long type. It is, in fact, an IntConstant.
159:
160: if (!(c instanceof IntConstant))
161: throw new IllegalArgumentException("IntConstant expected");
162: return LongConstant.v(this .value << ((IntConstant) c).value);
163: }
164:
165: public ArithmeticConstant shiftRight(ArithmeticConstant c) {
166: if (!(c instanceof IntConstant))
167: throw new IllegalArgumentException("IntConstant expected");
168: return LongConstant.v(this .value >> ((IntConstant) c).value);
169: }
170:
171: public ArithmeticConstant unsignedShiftRight(ArithmeticConstant c) {
172: if (!(c instanceof IntConstant))
173: throw new IllegalArgumentException("IntConstant expected");
174: return LongConstant.v(this .value >>> ((IntConstant) c).value);
175: }
176:
177: public String toString() {
178: return new Long(value).toString() + "L";
179: }
180:
181: public Type getType() {
182: return LongType.v();
183: }
184:
185: public void apply(Switch sw) {
186: ((ConstantSwitch) sw).caseLongConstant(this);
187: }
188: }
|