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