home *** CD-ROM | disk | FTP | other *** search
- package sun.tools.tree;
-
- import java.io.PrintStream;
- import java.util.Hashtable;
- import sun.tools.asm.Assembler;
- import sun.tools.asm.Label;
- import sun.tools.java.ClassNotFound;
- import sun.tools.java.Constants;
- import sun.tools.java.Environment;
- import sun.tools.java.Type;
-
- public class ConditionalExpression extends BinaryExpression {
- Expression cond;
-
- public ConditionalExpression(int var1, Expression var2, Expression var3, Expression var4) {
- super(13, var1, Type.tError, var3, var4);
- this.cond = var2;
- }
-
- public Expression order() {
- if (((Expression)this).precedence() > this.cond.precedence()) {
- UnaryExpression var1 = (UnaryExpression)this.cond;
- this.cond = var1.right;
- var1.right = this.order();
- return var1;
- } else {
- return this;
- }
- }
-
- public Vset checkValue(Environment var1, Context var2, Vset var3, Hashtable var4) {
- ConditionVars var5 = this.cond.checkCondition(var1, var2, var3, var4);
- var3 = super.left.checkValue(var1, var2, var5.vsTrue, var4).join(super.right.checkValue(var1, var2, var5.vsFalse, var4));
- this.cond = ((Node)this).convert(var1, var2, Type.tBoolean, this.cond);
- int var6 = super.left.type.getTypeMask() | super.right.type.getTypeMask();
- if ((var6 & 8192) != 0) {
- super.type = Type.tError;
- return var3;
- } else {
- if (super.left.type.equals(super.right.type)) {
- super.type = super.left.type;
- } else if ((var6 & 128) != 0) {
- super.type = Type.tDouble;
- } else if ((var6 & 64) != 0) {
- super.type = Type.tFloat;
- } else if ((var6 & 32) != 0) {
- super.type = Type.tLong;
- } else if ((var6 & 1792) != 0) {
- try {
- super.type = var1.implicitCast(super.right.type, super.left.type) ? super.left.type : super.right.type;
- } catch (ClassNotFound var7) {
- super.type = Type.tError;
- }
- } else if ((var6 & 4) != 0 && super.left.fitsType(var1, var2, Type.tChar) && super.right.fitsType(var1, var2, Type.tChar)) {
- super.type = Type.tChar;
- } else if ((var6 & 8) != 0 && super.left.fitsType(var1, var2, Type.tShort) && super.right.fitsType(var1, var2, Type.tShort)) {
- super.type = Type.tShort;
- } else if ((var6 & 2) != 0 && super.left.fitsType(var1, var2, Type.tByte) && super.right.fitsType(var1, var2, Type.tByte)) {
- super.type = Type.tByte;
- } else {
- super.type = Type.tInt;
- }
-
- super.left = ((Node)this).convert(var1, var2, super.type, super.left);
- super.right = ((Node)this).convert(var1, var2, super.type, super.right);
- return var3;
- }
- }
-
- public Vset check(Environment var1, Context var2, Vset var3, Hashtable var4) {
- var3 = this.cond.checkValue(var1, var2, var3, var4);
- this.cond = ((Node)this).convert(var1, var2, Type.tBoolean, this.cond);
- return super.left.check(var1, var2, var3.copy(), var4).join(super.right.check(var1, var2, var3, var4));
- }
-
- public boolean isConstant() {
- return this.cond.isConstant() && super.left.isConstant() && super.right.isConstant();
- }
-
- Expression simplify() {
- if (this.cond.equals(true)) {
- return super.left;
- } else {
- return (Expression)(this.cond.equals(false) ? super.right : this);
- }
- }
-
- public Expression inline(Environment var1, Context var2) {
- super.left = super.left.inline(var1, var2);
- super.right = super.right.inline(var1, var2);
- if (super.left == null && super.right == null) {
- return this.cond.inline(var1, var2);
- } else {
- if (super.left == null) {
- super.left = super.right;
- super.right = null;
- this.cond = new NotExpression(super.where, this.cond);
- }
-
- this.cond = this.cond.inlineValue(var1, var2);
- return this.simplify();
- }
- }
-
- public Expression inlineValue(Environment var1, Context var2) {
- this.cond = this.cond.inlineValue(var1, var2);
- super.left = super.left.inlineValue(var1, var2);
- super.right = super.right.inlineValue(var1, var2);
- return this.simplify();
- }
-
- public int costInline(int var1, Environment var2, Context var3) {
- return 1 + this.cond.costInline(var1, var2, var3) + super.left.costInline(var1, var2, var3) + super.right.costInline(var1, var2, var3);
- }
-
- public Expression copyInline(Context var1) {
- ConditionalExpression var2 = (ConditionalExpression)((Node)this).clone();
- var2.cond = this.cond.copyInline(var1);
- var2.left = super.left.copyInline(var1);
- var2.right = super.right.copyInline(var1);
- return var2;
- }
-
- public void codeValue(Environment var1, Context var2, Assembler var3) {
- Label var4 = new Label();
- Label var5 = new Label();
- this.cond.codeBranch(var1, var2, var3, var4, false);
- super.left.codeValue(var1, var2, var3);
- var3.add(super.where, 167, var5);
- var3.add(var4);
- super.right.codeValue(var1, var2, var3);
- var3.add(var5);
- }
-
- public void code(Environment var1, Context var2, Assembler var3) {
- Label var4 = new Label();
- this.cond.codeBranch(var1, var2, var3, var4, false);
- super.left.code(var1, var2, var3);
- if (super.right != null) {
- Label var5 = new Label();
- var3.add(super.where, 167, var5);
- var3.add(var4);
- super.right.code(var1, var2, var3);
- var3.add(var5);
- } else {
- var3.add(var4);
- }
- }
-
- public void print(PrintStream var1) {
- var1.print("(" + Constants.opNames[super.op] + " ");
- this.cond.print(var1);
- var1.print(" ");
- super.left.print(var1);
- var1.print(" ");
- if (super.right != null) {
- super.right.print(var1);
- } else {
- var1.print("<null>");
- }
-
- var1.print(")");
- }
- }
-