678N/A/*
3909N/A * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
678N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
678N/A *
678N/A * This code is free software; you can redistribute it and/or modify it
678N/A * under the terms of the GNU General Public License version 2 only, as
678N/A * published by the Free Software Foundation. Oracle designates this
678N/A * particular file as subject to the "Classpath" exception as provided
678N/A * by Oracle in the LICENSE file that accompanied this code.
678N/A *
678N/A * This code is distributed in the hope that it will be useful, but WITHOUT
678N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
678N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
678N/A * version 2 for more details (a copy is included in the LICENSE file that
678N/A * accompanied this code).
678N/A *
678N/A * You should have received a copy of the GNU General Public License version
678N/A * 2 along with this work; if not, write to the Free Software Foundation,
2362N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2362N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
678N/A * or visit www.oracle.com if you need additional information or have any
678N/A * questions.
678N/A */
1535N/A
678N/Apackage sun.tools.tree;
678N/A
678N/Aimport sun.tools.java.*;
678N/Aimport sun.tools.asm.Assembler;
678N/Aimport sun.tools.asm.Label;
678N/Aimport java.util.Hashtable;
678N/A
678N/A/**
678N/A * WARNING: The contents of this source file are not part of any
678N/A * supported API. Code that depends on them does so at its own risk:
678N/A * they are subject to change or removal without notice.
678N/A */
678N/Apublic
678N/Aclass AndExpression extends BinaryLogicalExpression {
678N/A /**
678N/A * constructor
1535N/A */
1535N/A public AndExpression(long where, Expression left, Expression right) {
1536N/A super(AND, where, left, right);
3321N/A }
3321N/A
4102N/A /*
678N/A * Check an "and" expression.
678N/A *
678N/A * cvars is modified so that
678N/A * cvar.vsTrue indicates variables with a known value if
678N/A * both the left and right hand side are true
678N/A * cvars.vsFalse indicates variables with a known value
678N/A * either the left or right hand side is false
678N/A */
678N/A public void checkCondition(Environment env, Context ctx, Vset vset,
678N/A Hashtable exp, ConditionVars cvars) {
678N/A // Find out when the left side is true/false
678N/A left.checkCondition(env, ctx, vset, exp, cvars);
678N/A left = convert(env, ctx, Type.tBoolean, left);
678N/A Vset vsTrue = cvars.vsTrue.copy();
678N/A Vset vsFalse = cvars.vsFalse.copy();
678N/A
678N/A // Only look at the right side if the left side is true
678N/A right.checkCondition(env, ctx, vsTrue, exp, cvars);
678N/A right = convert(env, ctx, Type.tBoolean, right);
678N/A
678N/A // cvars.vsTrue already reports when both returned true
678N/A // cvars.vsFalse must be set to either the left or right side
678N/A // returning false
678N/A cvars.vsFalse = cvars.vsFalse.join(vsFalse);
678N/A }
678N/A
678N/A /**
678N/A * Evaluate
678N/A */
678N/A Expression eval(boolean a, boolean b) {
1941N/A return new BooleanExpression(where, a && b);
678N/A }
678N/A
678N/A /**
678N/A * Simplify
3321N/A */
3321N/A Expression simplify() {
678N/A if (left.equals(true)) {
678N/A return right;
678N/A }
678N/A if (right.equals(false)) {
678N/A // Preserve effects of left argument.
678N/A return new CommaExpression(where, left, right).simplify();
678N/A }
678N/A if (right.equals(true)) {
678N/A return left;
678N/A }
678N/A if (left.equals(false)) {
678N/A return left;
678N/A }
678N/A return this;
678N/A }
678N/A
678N/A /**
678N/A * Code
678N/A */
678N/A void codeBranch(Environment env, Context ctx, Assembler asm, Label lbl, boolean whenTrue) {
678N/A if (whenTrue) {
678N/A Label lbl2 = new Label();
678N/A left.codeBranch(env, ctx, asm, lbl2, false);
678N/A right.codeBranch(env, ctx, asm, lbl, true);
678N/A asm.add(lbl2);
678N/A } else {
4102N/A left.codeBranch(env, ctx, asm, lbl, false);
4102N/A right.codeBranch(env, ctx, asm, lbl, false);
4102N/A }
4102N/A }
678N/A}
678N/A