001: /*
002: * Copyright 1994-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.tools.tree;
027:
028: import sun.tools.java.*;
029: import sun.tools.asm.Assembler;
030: import sun.tools.asm.Label;
031:
032: /**
033: * WARNING: The contents of this source file are not part of any
034: * supported API. Code that depends on them does so at its own risk:
035: * they are subject to change or removal without notice.
036: */
037: public class EqualExpression extends BinaryEqualityExpression {
038: /**
039: * constructor
040: */
041: public EqualExpression(long where, Expression left, Expression right) {
042: super (EQ, where, left, right);
043: }
044:
045: /**
046: * Evaluate
047: */
048: Expression eval(int a, int b) {
049: return new BooleanExpression(where, a == b);
050: }
051:
052: Expression eval(long a, long b) {
053: return new BooleanExpression(where, a == b);
054: }
055:
056: Expression eval(float a, float b) {
057: return new BooleanExpression(where, a == b);
058: }
059:
060: Expression eval(double a, double b) {
061: return new BooleanExpression(where, a == b);
062: }
063:
064: Expression eval(boolean a, boolean b) {
065: return new BooleanExpression(where, a == b);
066: }
067:
068: /**
069: * Simplify
070: */
071: Expression simplify() {
072: if (left.isConstant() && !right.isConstant()) {
073: return new EqualExpression(where, right, left);
074: }
075: return this ;
076: }
077:
078: /**
079: * Code
080: */
081: void codeBranch(Environment env, Context ctx, Assembler asm,
082: Label lbl, boolean whenTrue) {
083: left.codeValue(env, ctx, asm);
084: switch (left.type.getTypeCode()) {
085: case TC_BOOLEAN:
086: case TC_INT:
087: if (!right.equals(0)) {
088: right.codeValue(env, ctx, asm);
089: asm.add(where,
090: whenTrue ? opc_if_icmpeq : opc_if_icmpne, lbl,
091: whenTrue);
092: return;
093: }
094: break;
095: case TC_LONG:
096: right.codeValue(env, ctx, asm);
097: asm.add(where, opc_lcmp);
098: break;
099: case TC_FLOAT:
100: right.codeValue(env, ctx, asm);
101: asm.add(where, opc_fcmpl);
102: break;
103: case TC_DOUBLE:
104: right.codeValue(env, ctx, asm);
105: asm.add(where, opc_dcmpl);
106: break;
107: case TC_ARRAY:
108: case TC_CLASS:
109: case TC_NULL:
110: if (right.equals(0)) {
111: asm.add(where, whenTrue ? opc_ifnull : opc_ifnonnull,
112: lbl, whenTrue);
113: } else {
114: right.codeValue(env, ctx, asm);
115: asm.add(where,
116: whenTrue ? opc_if_acmpeq : opc_if_acmpne, lbl,
117: whenTrue);
118: }
119: return;
120:
121: default:
122: throw new CompilerError("Unexpected Type");
123: }
124: asm.add(where, whenTrue ? opc_ifeq : opc_ifne, lbl, whenTrue);
125: }
126: }
|