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 NotEqualExpression extends BinaryEqualityExpression {
038: /**
039: * constructor
040: */
041: public NotEqualExpression(long where, Expression left,
042: Expression right) {
043: super (NE, where, left, right);
044: }
045:
046: /**
047: * Evaluate
048: */
049: Expression eval(int a, int b) {
050: return new BooleanExpression(where, a != b);
051: }
052:
053: Expression eval(long a, long b) {
054: return new BooleanExpression(where, a != b);
055: }
056:
057: Expression eval(float a, float b) {
058: return new BooleanExpression(where, a != b);
059: }
060:
061: Expression eval(double a, double b) {
062: return new BooleanExpression(where, a != b);
063: }
064:
065: Expression eval(boolean a, boolean b) {
066: return new BooleanExpression(where, a != b);
067: }
068:
069: /**
070: * Simplify
071: */
072: Expression simplify() {
073: if (left.isConstant() && !right.isConstant()) {
074: return new NotEqualExpression(where, right, left);
075: }
076: return this ;
077: }
078:
079: /**
080: * Code
081: */
082: void codeBranch(Environment env, Context ctx, Assembler asm,
083: Label lbl, boolean whenTrue) {
084: left.codeValue(env, ctx, asm);
085: switch (left.type.getTypeCode()) {
086: case TC_BOOLEAN:
087: case TC_INT:
088: if (!right.equals(0)) {
089: right.codeValue(env, ctx, asm);
090: asm.add(where,
091: whenTrue ? opc_if_icmpne : opc_if_icmpeq, lbl,
092: whenTrue);
093: return;
094: }
095: break;
096: case TC_LONG:
097: right.codeValue(env, ctx, asm);
098: asm.add(where, opc_lcmp);
099: break;
100: case TC_FLOAT:
101: right.codeValue(env, ctx, asm);
102: asm.add(where, opc_fcmpl);
103: break;
104: case TC_DOUBLE:
105: right.codeValue(env, ctx, asm);
106: asm.add(where, opc_dcmpl);
107: break;
108: case TC_ARRAY:
109: case TC_CLASS:
110: case TC_NULL:
111: if (right.equals(0)) {
112: asm.add(where, whenTrue ? opc_ifnonnull : opc_ifnull,
113: lbl, whenTrue);
114: } else {
115: right.codeValue(env, ctx, asm);
116: asm.add(where,
117: whenTrue ? opc_if_acmpne : opc_if_acmpeq, lbl,
118: whenTrue);
119: }
120: return;
121: default:
122: throw new CompilerError("Unexpected Type");
123: }
124: asm.add(where, whenTrue ? opc_ifne : opc_ifeq, lbl, whenTrue);
125: }
126: }
|