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: import java.io.PrintStream;
032: import java.util.Hashtable;
033:
034: /**
035: * WARNING: The contents of this source file are not part of any
036: * supported API. Code that depends on them does so at its own risk:
037: * they are subject to change or removal without notice.
038: */
039: public class BooleanExpression extends ConstantExpression {
040: boolean value;
041:
042: /**
043: * Constructor
044: */
045: public BooleanExpression(long where, boolean value) {
046: super (BOOLEANVAL, where, Type.tBoolean);
047: this .value = value;
048: }
049:
050: /**
051: * Get the value
052: */
053: public Object getValue() {
054: return new Integer(value ? 1 : 0);
055: }
056:
057: /**
058: * Check if the expression is equal to a value
059: */
060: public boolean equals(boolean b) {
061: return value == b;
062: }
063:
064: /**
065: * Check if the expression is equal to its default static value
066: */
067: public boolean equalsDefault() {
068: return !value;
069: }
070:
071: /*
072: * Check a "not" expression.
073: *
074: * cvars is modified so that
075: * cvar.vsTrue indicates variables with a known value if
076: * the expression is true.
077: * cvars.vsFalse indicates variables with a known value if
078: * the expression is false
079: *
080: * For constant expressions, set the side that corresponds to our
081: * already known value to vset. Set the side that corresponds to the
082: * other way to "impossible"
083: */
084:
085: public void checkCondition(Environment env, Context ctx, Vset vset,
086: Hashtable exp, ConditionVars cvars) {
087: if (value) {
088: cvars.vsFalse = Vset.DEAD_END;
089: cvars.vsTrue = vset;
090: } else {
091: cvars.vsFalse = vset;
092: cvars.vsTrue = Vset.DEAD_END;
093: }
094: }
095:
096: /**
097: * Code
098: */
099: void codeBranch(Environment env, Context ctx, Assembler asm,
100: Label lbl, boolean whenTrue) {
101: if (value == whenTrue) {
102: asm.add(where, opc_goto, lbl);
103: }
104: }
105:
106: public void codeValue(Environment env, Context ctx, Assembler asm) {
107: asm.add(where, opc_ldc, new Integer(value ? 1 : 0));
108: }
109:
110: /**
111: * Print
112: */
113: public void print(PrintStream out) {
114: out.print(value ? "true" : "false");
115: }
116: }
|