Showing the changes to java/pkg/sun/tools/tree/BooleanExpression.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,118 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package sun.tools.tree; | ||
| 27 | |||
| 28 | import sun.tools.java.*; | ||
| 29 | import sun.tools.asm.Assembler; | ||
| 30 | import sun.tools.asm.Label; | ||
| 31 | import java.io.PrintStream; | ||
| 32 | import java.util.Hashtable; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * WARNING: The contents of this source file are not part of any | ||
| 36 | * supported API. Code that depends on them does so at its own risk: | ||
| 37 | * they are subject to change or removal without notice. | ||
| 38 | */ | ||
| 39 | public | ||
| 40 | class BooleanExpression extends ConstantExpression { | ||
| 41 | boolean value; | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Constructor | ||
| 45 | */ | ||
| 46 | public BooleanExpression(long where, boolean value) { | ||
| 47 | super(BOOLEANVAL, where, Type.tBoolean); | ||
| 48 | this.value = value; | ||
| 49 | } | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Get the value | ||
| 53 | */ | ||
| 54 | public Object getValue() { | ||
| 55 | return new Integer(value ? 1 : 0); | ||
| 56 | } | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Check if the expression is equal to a value | ||
| 60 | */ | ||
| 61 | public boolean equals(boolean b) { | ||
| 62 | return value == b; | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | /** | ||
| 67 | * Check if the expression is equal to its default static value | ||
| 68 | */ | ||
| 69 | public boolean equalsDefault() { | ||
| 70 | return !value; | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | /* | ||
| 75 | * Check a "not" expression. | ||
| 76 | * | ||
| 77 | * cvars is modified so that | ||
| 78 | * cvar.vsTrue indicates variables with a known value if | ||
| 79 | * the expression is true. | ||
| 80 | * cvars.vsFalse indicates variables with a known value if | ||
| 81 | * the expression is false | ||
| 82 | * | ||
| 83 | * For constant expressions, set the side that corresponds to our | ||
| 84 | * already known value to vset. Set the side that corresponds to the | ||
| 85 | * other way to "impossible" | ||
| 86 | */ | ||
| 87 | |||
| 88 | public void checkCondition(Environment env, Context ctx, | ||
| 89 | Vset vset, Hashtable exp, ConditionVars cvars) { | ||
| 90 | if (value) { | ||
| 91 | cvars.vsFalse = Vset.DEAD_END; | ||
| 92 | cvars.vsTrue = vset; | ||
| 93 | } else { | ||
| 94 | cvars.vsFalse = vset; | ||
| 95 | cvars.vsTrue = Vset.DEAD_END; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | /** | ||
| 101 | * Code | ||
| 102 | */ | ||
| 103 | void codeBranch(Environment env, Context ctx, Assembler asm, Label lbl, boolean whenTrue) { | ||
| 104 | if (value == whenTrue) { | ||
| 105 | asm.add(where, opc_goto, lbl); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | public void codeValue(Environment env, Context ctx, Assembler asm) { | ||
| 109 | asm.add(where, opc_ldc, new Integer(value ? 1 : 0)); | ||
| 110 | } | ||
| 111 | |||
| 112 | /** | ||
| 113 | |||
| 114 | */ | ||
| 115 | public void print(PrintStream out) { | ||
| 116 | out.print(value ? "true" : "false"); | ||
| 117 | } | ||
| 118 | } | ||