KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > IntConstant


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 IntConstant extends ArithmeticConstant
37 {
38     public final int value;
39
40     protected IntConstant(int value)
41     {
42         this.value = value;
43     }
44
45     public static IntConstant v(int value)
46     {
47         return new IntConstant(value);
48     }
49
50     public boolean equals(Object JavaDoc c)
51     {
52         return c instanceof IntConstant && ((IntConstant) c).value == value;
53     }
54
55     public int hashCode()
56     {
57         return value;
58     }
59
60     // PTC 1999/06/28
61
public NumericConstant add(NumericConstant c)
62     {
63         if (!(c instanceof IntConstant))
64             throw new IllegalArgumentException JavaDoc("IntConstant expected");
65         return IntConstant.v(this.value + ((IntConstant)c).value);
66     }
67
68     public NumericConstant subtract(NumericConstant c)
69     {
70         if (!(c instanceof IntConstant))
71             throw new IllegalArgumentException JavaDoc("IntConstant expected");
72         return IntConstant.v(this.value - ((IntConstant)c).value);
73     }
74
75     public NumericConstant multiply(NumericConstant c)
76     {
77         if (!(c instanceof IntConstant))
78             throw new IllegalArgumentException JavaDoc("IntConstant expected");
79         return IntConstant.v(this.value * ((IntConstant)c).value);
80     }
81
82     public NumericConstant divide(NumericConstant c)
83     {
84         if (!(c instanceof IntConstant))
85             throw new IllegalArgumentException JavaDoc("IntConstant expected");
86         return IntConstant.v(this.value / ((IntConstant)c).value);
87     }
88
89     public NumericConstant remainder(NumericConstant c)
90     {
91         if (!(c instanceof IntConstant))
92             throw new IllegalArgumentException JavaDoc("IntConstant expected");
93         return IntConstant.v(this.value % ((IntConstant)c).value);
94     }
95
96     public NumericConstant equalEqual(NumericConstant c)
97     {
98         if (!(c instanceof IntConstant))
99             throw new IllegalArgumentException JavaDoc("IntConstant expected");
100         return IntConstant.v((this.value == ((IntConstant)c).value) ? 1 : 0);
101     }
102
103     public NumericConstant notEqual(NumericConstant c)
104     {
105         if (!(c instanceof IntConstant))
106             throw new IllegalArgumentException JavaDoc("IntConstant expected");
107         return IntConstant.v((this.value != ((IntConstant)c).value) ? 1 : 0);
108     }
109
110     public NumericConstant lessThan(NumericConstant c)
111     {
112         if (!(c instanceof IntConstant))
113             throw new IllegalArgumentException JavaDoc("IntConstant expected");
114         return IntConstant.v((this.value < ((IntConstant)c).value) ? 1 : 0);
115     }
116
117     public NumericConstant lessThanOrEqual(NumericConstant c)
118     {
119         if (!(c instanceof IntConstant))
120             throw new IllegalArgumentException JavaDoc("IntConstant expected");
121         return IntConstant.v((this.value <= ((IntConstant)c).value) ? 1 : 0);
122     }
123
124     public NumericConstant greaterThan(NumericConstant c)
125     {
126         if (!(c instanceof IntConstant))
127             throw new IllegalArgumentException JavaDoc("IntConstant expected");
128         return IntConstant.v((this.value > ((IntConstant)c).value) ? 1 : 0);
129     }
130
131     public NumericConstant greaterThanOrEqual(NumericConstant c)
132     {
133         if (!(c instanceof IntConstant))
134             throw new IllegalArgumentException JavaDoc("IntConstant expected");
135         return IntConstant.v((this.value >= ((IntConstant)c).value) ? 1 : 0);
136     }
137
138     public NumericConstant negate()
139     {
140         return IntConstant.v(-(this.value));
141     }
142
143     public ArithmeticConstant and(ArithmeticConstant c)
144     {
145         if (!(c instanceof IntConstant))
146             throw new IllegalArgumentException JavaDoc("IntConstant expected");
147         return IntConstant.v(this.value & ((IntConstant)c).value);
148     }
149
150     public ArithmeticConstant or(ArithmeticConstant c)
151     {
152         if (!(c instanceof IntConstant))
153             throw new IllegalArgumentException JavaDoc("IntConstant expected");
154         return IntConstant.v(this.value | ((IntConstant)c).value);
155     }
156
157     public ArithmeticConstant xor(ArithmeticConstant c)
158     {
159         if (!(c instanceof IntConstant))
160             throw new IllegalArgumentException JavaDoc("IntConstant expected");
161         return IntConstant.v(this.value ^ ((IntConstant)c).value);
162     }
163
164     public ArithmeticConstant shiftLeft(ArithmeticConstant c)
165     {
166         if (!(c instanceof IntConstant))
167             throw new IllegalArgumentException JavaDoc("IntConstant expected");
168         return IntConstant.v(this.value << ((IntConstant)c).value);
169     }
170
171     public ArithmeticConstant shiftRight(ArithmeticConstant c)
172     {
173         if (!(c instanceof IntConstant))
174             throw new IllegalArgumentException JavaDoc("IntConstant expected");
175         return IntConstant.v(this.value >> ((IntConstant)c).value);
176     }
177
178     public ArithmeticConstant unsignedShiftRight(ArithmeticConstant c)
179     {
180         if (!(c instanceof IntConstant))
181             throw new IllegalArgumentException JavaDoc("IntConstant expected");
182         return IntConstant.v(this.value >>> ((IntConstant)c).value);
183     }
184
185     public String JavaDoc toString()
186     {
187         return new Integer JavaDoc(value).toString();
188     }
189
190     public Type getType()
191     {
192         return IntType.v();
193     }
194
195     public void apply(Switch sw)
196     {
197         ((ConstantSwitch) sw).caseIntConstant(this);
198     }
199     
200 }
201
Popular Tags