01: /*
02: * Copyright 1994-2003 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.tools.tree;
27:
28: import sun.tools.java.*;
29: import sun.tools.asm.Assembler;
30: import java.util.Hashtable;
31:
32: /**
33: * WARNING: The contents of this source file are not part of any
34: * supported API. Code that depends on them does so at its own risk:
35: * they are subject to change or removal without notice.
36: */
37: public class DivideExpression extends DivRemExpression {
38: /**
39: * constructor
40: */
41: public DivideExpression(long where, Expression left,
42: Expression right) {
43: super (DIV, where, left, right);
44: }
45:
46: /**
47: * Evaluate
48: */
49: Expression eval(int a, int b) {
50: return new IntExpression(where, a / b);
51: }
52:
53: Expression eval(long a, long b) {
54: return new LongExpression(where, a / b);
55: }
56:
57: Expression eval(float a, float b) {
58: return new FloatExpression(where, a / b);
59: }
60:
61: Expression eval(double a, double b) {
62: return new DoubleExpression(where, a / b);
63: }
64:
65: /**
66: * Simplify
67: */
68: Expression simplify() {
69: // This code here was wrong. What if the expression is a float?
70: // In any case, if the expression throws an exception, we
71: // should just throw the exception at run-time. Throwing
72: // it at compile-time is not correct.
73: // (Fix for 4019300)
74: //
75: // if (right.equals(0)) {
76: // throw new ArithmeticException("/ by zero");
77: // }
78: if (right.equals(1)) {
79: return left;
80: }
81: return this ;
82: }
83:
84: /**
85: * Code
86: */
87: void codeOperation(Environment env, Context ctx, Assembler asm) {
88: asm.add(where, opc_idiv + type.getTypeCodeOffset());
89: }
90: }
|