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 GreaterOrEqualExpression extends BinaryCompareExpression {
038: /**
039: * constructor
040: */
041: public GreaterOrEqualExpression(long where, Expression left,
042: Expression right) {
043: super (GE, 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: /**
066: * Simplify
067: */
068: Expression simplify() {
069: if (left.isConstant() && !right.isConstant()) {
070: return new LessOrEqualExpression(where, right, left);
071: }
072: return this ;
073: }
074:
075: /**
076: * Code
077: */
078: void codeBranch(Environment env, Context ctx, Assembler asm,
079: Label lbl, boolean whenTrue) {
080: left.codeValue(env, ctx, asm);
081: switch (left.type.getTypeCode()) {
082: case TC_INT:
083: if (!right.equals(0)) {
084: right.codeValue(env, ctx, asm);
085: asm.add(where,
086: whenTrue ? opc_if_icmpge : opc_if_icmplt, lbl,
087: whenTrue);
088: return;
089: }
090: break;
091: case TC_LONG:
092: right.codeValue(env, ctx, asm);
093: asm.add(where, opc_lcmp);
094: break;
095: case TC_FLOAT:
096: right.codeValue(env, ctx, asm);
097: asm.add(where, opc_fcmpl);
098: break;
099: case TC_DOUBLE:
100: right.codeValue(env, ctx, asm);
101: asm.add(where, opc_dcmpl);
102: break;
103: default:
104: throw new CompilerError("Unexpected Type");
105: }
106: asm.add(where, whenTrue ? opc_ifge : opc_iflt, lbl, whenTrue);
107: }
108: }
|