KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > LongConstant


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-1999 Raja Vallee-Rai
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29
30 package soot.jimple;
31
32 import soot.*;
33 import soot.util.*;
34 import java.util.*;
35
36 public class LongConstant extends ArithmeticConstant
37 {
38     public final long value;
39
40     private LongConstant(long value)
41     {
42         this.value = value;
43     }
44
45     public static LongConstant v(long value)
46     {
47         return new LongConstant(value);
48     }
49
50     public boolean equals(Object JavaDoc c)
51     {
52         return c instanceof LongConstant && ((LongConstant) c).value == this.value;
53     }
54
55     /** Returns a hash code for this DoubleConstant object. */
56     public int hashCode()
57     {
58         return (int)(value^(value>>>32));
59     }
60
61     // PTC 1999/06/28
62
public NumericConstant add(NumericConstant c)
63     {
64         if (!(c instanceof LongConstant))
65             throw new IllegalArgumentException JavaDoc("LongConstant expected");
66         return LongConstant.v(this.value + ((LongConstant)c).value);
67     }
68
69     public NumericConstant subtract(NumericConstant c)
70     {
71         if (!(c instanceof LongConstant))
72             throw new IllegalArgumentException JavaDoc("LongConstant expected");
73         return LongConstant.v(this.value - ((LongConstant)c).value);
74     }
75
76     public NumericConstant multiply(NumericConstant c)
77     {
78         if (!(c instanceof LongConstant))
79             throw new IllegalArgumentException JavaDoc("LongConstant expected");
80         return LongConstant.v(this.value * ((LongConstant)c).value);
81     }
82
83     public NumericConstant divide(NumericConstant c)
84     {
85         if (!(c instanceof LongConstant))
86             throw new IllegalArgumentException JavaDoc("LongConstant expected");
87         return LongConstant.v(this.value / ((LongConstant)c).value);
88     }
89
90     public NumericConstant remainder(NumericConstant c)
91     {
92         if (!(c instanceof LongConstant))
93             throw new IllegalArgumentException JavaDoc("LongConstant expected");
94         return LongConstant.v(this.value % ((LongConstant)c).value);
95     }
96
97     public NumericConstant equalEqual(NumericConstant c)
98     {
99         if (!(c instanceof LongConstant))
100             throw new IllegalArgumentException JavaDoc("LongConstant expected");
101         return IntConstant.v((this.value == ((LongConstant)c).value) ? 1 : 0);
102     }
103
104     public NumericConstant notEqual(NumericConstant c)
105     {
106         if (!(c instanceof LongConstant))
107             throw new IllegalArgumentException JavaDoc("LongConstant expected");
108         return IntConstant.v((this.value != ((LongConstant)c).value) ? 1 : 0);
109     }
110
111     public NumericConstant lessThan(NumericConstant c)
112     {
113         if (!(c instanceof LongConstant))
114             throw new IllegalArgumentException JavaDoc("LongConstant expected");
115         return IntConstant.v((this.value < ((LongConstant)c).value) ? 1 : 0);
116     }
117
118     public NumericConstant lessThanOrEqual(NumericConstant c)
119     {
120         if (!(c instanceof LongConstant))
121             throw new IllegalArgumentException JavaDoc("LongConstant expected");
122         return IntConstant.v((this.value <= ((LongConstant)c).value) ? 1 : 0);
123     }
124
125     public NumericConstant greaterThan(NumericConstant c)
126     {
127         if (!(c instanceof LongConstant))
128             throw new IllegalArgumentException JavaDoc("LongConstant expected");
129         return IntConstant.v((this.value > ((LongConstant)c).value) ? 1 : 0);
130     }
131
132     public NumericConstant greaterThanOrEqual(NumericConstant c)
133     {
134         if (!(c instanceof LongConstant))
135             throw new IllegalArgumentException JavaDoc("LongConstant expected");
136         return IntConstant.v((this.value >= ((LongConstant)c).value) ? 1 : 0);
137     }
138
139     public IntConstant cmp(LongConstant c) {
140         if (this.value > c.value)
141             return IntConstant.v(1);
142         else if (this.value == c.value)
143             return IntConstant.v(0);
144         else
145             return IntConstant.v(-1);
146     }
147
148     public NumericConstant negate()
149     {
150         return LongConstant.v(-(this.value));
151     }
152
153     public ArithmeticConstant and(ArithmeticConstant c)
154     {
155         if (!(c instanceof LongConstant))
156             throw new IllegalArgumentException JavaDoc("LongConstant expected");
157         return LongConstant.v(this.value & ((LongConstant)c).value);
158     }
159
160     public ArithmeticConstant or(ArithmeticConstant c)
161     {
162         if (!(c instanceof LongConstant))
163             throw new IllegalArgumentException JavaDoc("LongConstant expected");
164         return LongConstant.v(this.value | ((LongConstant)c).value);
165     }
166
167     public ArithmeticConstant xor(ArithmeticConstant c)
168     {
169         if (!(c instanceof LongConstant))
170             throw new IllegalArgumentException JavaDoc("LongConstant expected");
171         return LongConstant.v(this.value ^ ((LongConstant)c).value);
172     }
173
174     public ArithmeticConstant shiftLeft(ArithmeticConstant c)
175     {
176         // NOTE CAREFULLY: the RHS of a shift op is not (!)
177
// of Long type. It is, in fact, an IntConstant.
178

179         if (!(c instanceof IntConstant))
180             throw new IllegalArgumentException JavaDoc("IntConstant expected");
181         return LongConstant.v(this.value << ((IntConstant)c).value);
182     }
183
184     public ArithmeticConstant shiftRight(ArithmeticConstant c)
185     {
186         if (!(c instanceof IntConstant))
187             throw new IllegalArgumentException JavaDoc("IntConstant expected");
188         return LongConstant.v(this.value >> ((IntConstant)c).value);
189     }
190
191     public ArithmeticConstant unsignedShiftRight(ArithmeticConstant c)
192     {
193         if (!(c instanceof IntConstant))
194             throw new IllegalArgumentException JavaDoc("IntConstant expected");
195         return LongConstant.v(this.value >>> ((IntConstant)c).value);
196     }
197
198     public String JavaDoc toString()
199     {
200         return new Long JavaDoc(value).toString() + "L";
201     }
202
203     public Type getType()
204     {
205         return LongType.v();
206     }
207
208     public void apply(Switch sw)
209     {
210         ((ConstantSwitch) sw).caseLongConstant(this);
211     }
212 }
213
214
215
Popular Tags