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.util.Hashtable;
032:
033: /**
034: * WARNING: The contents of this source file are not part of any
035: * supported API. Code that depends on them does so at its own risk:
036: * they are subject to change or removal without notice.
037: */
038: public class OrExpression extends BinaryLogicalExpression {
039: /**
040: * constructor
041: */
042: public OrExpression(long where, Expression left, Expression right) {
043: super (OR, where, left, right);
044: }
045:
046: /*
047: * Check an "or" expression.
048: *
049: * cvars is modified so that
050: * cvar.vsTrue indicates variables with a known value if
051: * either the left and right hand side isn true
052: * cvars.vsFalse indicates variables with a known value if
053: * both the left or right hand side are false
054: */
055: public void checkCondition(Environment env, Context ctx, Vset vset,
056: Hashtable exp, ConditionVars cvars) {
057: // Find out when the left side is true/false
058: left.checkCondition(env, ctx, vset, exp, cvars);
059: left = convert(env, ctx, Type.tBoolean, left);
060: Vset vsTrue = cvars.vsTrue.copy();
061: Vset vsFalse = cvars.vsFalse.copy();
062:
063: // Only look at the right side if the left side is false
064: right.checkCondition(env, ctx, vsFalse, exp, cvars);
065: right = convert(env, ctx, Type.tBoolean, right);
066:
067: // cvars.vsFalse actually reports that both returned false
068: // cvars.vsTrue must be set back to either left side or the right
069: // side returning false;
070: cvars.vsTrue = cvars.vsTrue.join(vsTrue);
071: }
072:
073: /**
074: * Evaluate
075: */
076: Expression eval(boolean a, boolean b) {
077: return new BooleanExpression(where, a || b);
078: }
079:
080: /**
081: * Simplify
082: */
083: Expression simplify() {
084: if (right.equals(false)) {
085: return left;
086: }
087: if (left.equals(true)) {
088: return left;
089: }
090: if (left.equals(false)) {
091: return right;
092: }
093: if (right.equals(true)) {
094: // Preserve effects of left argument.
095: return new CommaExpression(where, left, right).simplify();
096: }
097: return this ;
098: }
099:
100: /**
101: * Code
102: */
103: void codeBranch(Environment env, Context ctx, Assembler asm,
104: Label lbl, boolean whenTrue) {
105: if (whenTrue) {
106: left.codeBranch(env, ctx, asm, lbl, true);
107: right.codeBranch(env, ctx, asm, lbl, true);
108: } else {
109: Label lbl2 = new Label();
110: left.codeBranch(env, ctx, asm, lbl2, true);
111: right.codeBranch(env, ctx, asm, lbl, false);
112: asm.add(lbl2);
113: }
114: }
115: }
|