108 case ineg: // unary -
109 return syms.intType.constType(-intValue(od));
110 case ixor: // ~
111 return syms.intType.constType(~intValue(od));
112 case bool_not: // !
113 return syms.booleanType.constType(b2i(intValue(od) == 0));
114 case ifeq:
115 return syms.booleanType.constType(b2i(intValue(od) == 0));
116 case ifne:
117 return syms.booleanType.constType(b2i(intValue(od) != 0));
118 case iflt:
119 return syms.booleanType.constType(b2i(intValue(od) < 0));
120 case ifgt:
121 return syms.booleanType.constType(b2i(intValue(od) > 0));
122 case ifle:
123 return syms.booleanType.constType(b2i(intValue(od) <= 0));
124 case ifge:
125 return syms.booleanType.constType(b2i(intValue(od) >= 0));
126
127 case lneg: // unary -
128 return syms.longType.constType(new Long(-longValue(od)));
129 case lxor: // ~
130 return syms.longType.constType(new Long(~longValue(od)));
131
132 case fneg: // unary -
133 return syms.floatType.constType(new Float(-floatValue(od)));
134
135 case dneg: // ~
136 return syms.doubleType.constType(new Double(-doubleValue(od)));
137
138 default:
139 return null;
140 }
141 } catch (ArithmeticException e) {
142 return null;
143 }
144 }
145
146 /** Fold binary operation.
147 * @param opcode The operation's opcode instruction (usually a byte code),
148 * as entered by class Symtab.
149 * opcode's ifeq to ifge are for postprocessing
150 * xcmp; ifxx pairs of instructions.
151 * @param left The type of the operation's left operand.
152 * @param right The type of the operation's right operand.
153 */
154 Type fold2(int opcode, Type left, Type right) {
155 try {
156 if (opcode > ByteCodes.preMask) {
199 return syms.booleanType.constType(
200 b2i(intValue(l) == intValue(r)));
201 case if_icmpne:
202 return syms.booleanType.constType(
203 b2i(intValue(l) != intValue(r)));
204 case if_icmplt:
205 return syms.booleanType.constType(
206 b2i(intValue(l) < intValue(r)));
207 case if_icmpgt:
208 return syms.booleanType.constType(
209 b2i(intValue(l) > intValue(r)));
210 case if_icmple:
211 return syms.booleanType.constType(
212 b2i(intValue(l) <= intValue(r)));
213 case if_icmpge:
214 return syms.booleanType.constType(
215 b2i(intValue(l) >= intValue(r)));
216
217 case ladd:
218 return syms.longType.constType(
219 new Long(longValue(l) + longValue(r)));
220 case lsub:
221 return syms.longType.constType(
222 new Long(longValue(l) - longValue(r)));
223 case lmul:
224 return syms.longType.constType(
225 new Long(longValue(l) * longValue(r)));
226 case ldiv:
227 return syms.longType.constType(
228 new Long(longValue(l) / longValue(r)));
229 case lmod:
230 return syms.longType.constType(
231 new Long(longValue(l) % longValue(r)));
232 case land:
233 return syms.longType.constType(
234 new Long(longValue(l) & longValue(r)));
235 case lor:
236 return syms.longType.constType(
237 new Long(longValue(l) | longValue(r)));
238 case lxor:
239 return syms.longType.constType(
240 new Long(longValue(l) ^ longValue(r)));
241 case lshl: case lshll:
242 return syms.longType.constType(
243 new Long(longValue(l) << intValue(r)));
244 case lshr: case lshrl:
245 return syms.longType.constType(
246 new Long(longValue(l) >> intValue(r)));
247 case lushr:
248 return syms.longType.constType(
249 new Long(longValue(l) >>> intValue(r)));
250 case lcmp:
251 if (longValue(l) < longValue(r))
252 return syms.intType.constType(minusOne);
253 else if (longValue(l) > longValue(r))
254 return syms.intType.constType(one);
255 else
256 return syms.intType.constType(zero);
257 case fadd:
258 return syms.floatType.constType(
259 new Float(floatValue(l) + floatValue(r)));
260 case fsub:
261 return syms.floatType.constType(
262 new Float(floatValue(l) - floatValue(r)));
263 case fmul:
264 return syms.floatType.constType(
265 new Float(floatValue(l) * floatValue(r)));
266 case fdiv:
267 return syms.floatType.constType(
268 new Float(floatValue(l) / floatValue(r)));
269 case fmod:
270 return syms.floatType.constType(
271 new Float(floatValue(l) % floatValue(r)));
272 case fcmpg: case fcmpl:
273 if (floatValue(l) < floatValue(r))
274 return syms.intType.constType(minusOne);
275 else if (floatValue(l) > floatValue(r))
276 return syms.intType.constType(one);
277 else if (floatValue(l) == floatValue(r))
278 return syms.intType.constType(zero);
279 else if (opcode == fcmpg)
280 return syms.intType.constType(one);
281 else
282 return syms.intType.constType(minusOne);
283 case dadd:
284 return syms.doubleType.constType(
285 new Double(doubleValue(l) + doubleValue(r)));
286 case dsub:
287 return syms.doubleType.constType(
288 new Double(doubleValue(l) - doubleValue(r)));
289 case dmul:
290 return syms.doubleType.constType(
291 new Double(doubleValue(l) * doubleValue(r)));
292 case ddiv:
293 return syms.doubleType.constType(
294 new Double(doubleValue(l) / doubleValue(r)));
295 case dmod:
296 return syms.doubleType.constType(
297 new Double(doubleValue(l) % doubleValue(r)));
298 case dcmpg: case dcmpl:
299 if (doubleValue(l) < doubleValue(r))
300 return syms.intType.constType(minusOne);
301 else if (doubleValue(l) > doubleValue(r))
302 return syms.intType.constType(one);
303 else if (doubleValue(l) == doubleValue(r))
304 return syms.intType.constType(zero);
305 else if (opcode == dcmpg)
306 return syms.intType.constType(one);
307 else
308 return syms.intType.constType(minusOne);
309 case if_acmpeq:
310 return syms.booleanType.constType(b2i(l.equals(r)));
311 case if_acmpne:
312 return syms.booleanType.constType(b2i(!l.equals(r)));
313 case string_add:
314 return syms.stringType.constType(
315 left.stringValue() + right.stringValue());
316 default:
317 return null;
|
108 case ineg: // unary -
109 return syms.intType.constType(-intValue(od));
110 case ixor: // ~
111 return syms.intType.constType(~intValue(od));
112 case bool_not: // !
113 return syms.booleanType.constType(b2i(intValue(od) == 0));
114 case ifeq:
115 return syms.booleanType.constType(b2i(intValue(od) == 0));
116 case ifne:
117 return syms.booleanType.constType(b2i(intValue(od) != 0));
118 case iflt:
119 return syms.booleanType.constType(b2i(intValue(od) < 0));
120 case ifgt:
121 return syms.booleanType.constType(b2i(intValue(od) > 0));
122 case ifle:
123 return syms.booleanType.constType(b2i(intValue(od) <= 0));
124 case ifge:
125 return syms.booleanType.constType(b2i(intValue(od) >= 0));
126
127 case lneg: // unary -
128 return syms.longType.constType(Long.valueOf(-longValue(od)));
129 case lxor: // ~
130 return syms.longType.constType(Long.valueOf(~longValue(od)));
131
132 case fneg: // unary -
133 return syms.floatType.constType(Float.valueOf(-floatValue(od)));
134
135 case dneg: // ~
136 return syms.doubleType.constType(Double.valueOf(-doubleValue(od)));
137
138 default:
139 return null;
140 }
141 } catch (ArithmeticException e) {
142 return null;
143 }
144 }
145
146 /** Fold binary operation.
147 * @param opcode The operation's opcode instruction (usually a byte code),
148 * as entered by class Symtab.
149 * opcode's ifeq to ifge are for postprocessing
150 * xcmp; ifxx pairs of instructions.
151 * @param left The type of the operation's left operand.
152 * @param right The type of the operation's right operand.
153 */
154 Type fold2(int opcode, Type left, Type right) {
155 try {
156 if (opcode > ByteCodes.preMask) {
199 return syms.booleanType.constType(
200 b2i(intValue(l) == intValue(r)));
201 case if_icmpne:
202 return syms.booleanType.constType(
203 b2i(intValue(l) != intValue(r)));
204 case if_icmplt:
205 return syms.booleanType.constType(
206 b2i(intValue(l) < intValue(r)));
207 case if_icmpgt:
208 return syms.booleanType.constType(
209 b2i(intValue(l) > intValue(r)));
210 case if_icmple:
211 return syms.booleanType.constType(
212 b2i(intValue(l) <= intValue(r)));
213 case if_icmpge:
214 return syms.booleanType.constType(
215 b2i(intValue(l) >= intValue(r)));
216
217 case ladd:
218 return syms.longType.constType(
219 Long.valueOf(longValue(l) + longValue(r)));
220 case lsub:
221 return syms.longType.constType(
222 Long.valueOf(longValue(l) - longValue(r)));
223 case lmul:
224 return syms.longType.constType(
225 Long.valueOf(longValue(l) * longValue(r)));
226 case ldiv:
227 return syms.longType.constType(
228 Long.valueOf(longValue(l) / longValue(r)));
229 case lmod:
230 return syms.longType.constType(
231 Long.valueOf(longValue(l) % longValue(r)));
232 case land:
233 return syms.longType.constType(
234 Long.valueOf(longValue(l) & longValue(r)));
235 case lor:
236 return syms.longType.constType(
237 Long.valueOf(longValue(l) | longValue(r)));
238 case lxor:
239 return syms.longType.constType(
240 Long.valueOf(longValue(l) ^ longValue(r)));
241 case lshl: case lshll:
242 return syms.longType.constType(
243 Long.valueOf(longValue(l) << intValue(r)));
244 case lshr: case lshrl:
245 return syms.longType.constType(
246 Long.valueOf(longValue(l) >> intValue(r)));
247 case lushr:
248 return syms.longType.constType(
249 Long.valueOf(longValue(l) >>> intValue(r)));
250 case lcmp:
251 if (longValue(l) < longValue(r))
252 return syms.intType.constType(minusOne);
253 else if (longValue(l) > longValue(r))
254 return syms.intType.constType(one);
255 else
256 return syms.intType.constType(zero);
257 case fadd:
258 return syms.floatType.constType(
259 Float.valueOf(floatValue(l) + floatValue(r)));
260 case fsub:
261 return syms.floatType.constType(
262 Float.valueOf(floatValue(l) - floatValue(r)));
263 case fmul:
264 return syms.floatType.constType(
265 Float.valueOf(floatValue(l) * floatValue(r)));
266 case fdiv:
267 return syms.floatType.constType(
268 Float.valueOf(floatValue(l) / floatValue(r)));
269 case fmod:
270 return syms.floatType.constType(
271 Float.valueOf(floatValue(l) % floatValue(r)));
272 case fcmpg: case fcmpl:
273 if (floatValue(l) < floatValue(r))
274 return syms.intType.constType(minusOne);
275 else if (floatValue(l) > floatValue(r))
276 return syms.intType.constType(one);
277 else if (floatValue(l) == floatValue(r))
278 return syms.intType.constType(zero);
279 else if (opcode == fcmpg)
280 return syms.intType.constType(one);
281 else
282 return syms.intType.constType(minusOne);
283 case dadd:
284 return syms.doubleType.constType(
285 Double.valueOf(doubleValue(l) + doubleValue(r)));
286 case dsub:
287 return syms.doubleType.constType(
288 Double.valueOf(doubleValue(l) - doubleValue(r)));
289 case dmul:
290 return syms.doubleType.constType(
291 Double.valueOf(doubleValue(l) * doubleValue(r)));
292 case ddiv:
293 return syms.doubleType.constType(
294 Double.valueOf(doubleValue(l) / doubleValue(r)));
295 case dmod:
296 return syms.doubleType.constType(
297 Double.valueOf(doubleValue(l) % doubleValue(r)));
298 case dcmpg: case dcmpl:
299 if (doubleValue(l) < doubleValue(r))
300 return syms.intType.constType(minusOne);
301 else if (doubleValue(l) > doubleValue(r))
302 return syms.intType.constType(one);
303 else if (doubleValue(l) == doubleValue(r))
304 return syms.intType.constType(zero);
305 else if (opcode == dcmpg)
306 return syms.intType.constType(one);
307 else
308 return syms.intType.constType(minusOne);
309 case if_acmpeq:
310 return syms.booleanType.constType(b2i(l.equals(r)));
311 case if_acmpne:
312 return syms.booleanType.constType(b2i(!l.equals(r)));
313 case string_add:
314 return syms.stringType.constType(
315 left.stringValue() + right.stringValue());
316 default:
317 return null;
|