home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / tools / tree / ConditionalExpression.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  5.2 KB  |  165 lines

  1. package sun.tools.tree;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.Hashtable;
  5. import sun.tools.asm.Assembler;
  6. import sun.tools.asm.Label;
  7. import sun.tools.java.ClassNotFound;
  8. import sun.tools.java.Constants;
  9. import sun.tools.java.Environment;
  10. import sun.tools.java.Type;
  11.  
  12. public class ConditionalExpression extends BinaryExpression {
  13.    Expression cond;
  14.  
  15.    public ConditionalExpression(int var1, Expression var2, Expression var3, Expression var4) {
  16.       super(13, var1, Type.tError, var3, var4);
  17.       this.cond = var2;
  18.    }
  19.  
  20.    public Expression order() {
  21.       if (((Expression)this).precedence() > this.cond.precedence()) {
  22.          UnaryExpression var1 = (UnaryExpression)this.cond;
  23.          this.cond = var1.right;
  24.          var1.right = this.order();
  25.          return var1;
  26.       } else {
  27.          return this;
  28.       }
  29.    }
  30.  
  31.    public Vset checkValue(Environment var1, Context var2, Vset var3, Hashtable var4) {
  32.       ConditionVars var5 = this.cond.checkCondition(var1, var2, var3, var4);
  33.       var3 = super.left.checkValue(var1, var2, var5.vsTrue, var4).join(super.right.checkValue(var1, var2, var5.vsFalse, var4));
  34.       this.cond = ((Node)this).convert(var1, var2, Type.tBoolean, this.cond);
  35.       int var6 = super.left.type.getTypeMask() | super.right.type.getTypeMask();
  36.       if ((var6 & 8192) != 0) {
  37.          super.type = Type.tError;
  38.          return var3;
  39.       } else {
  40.          if (super.left.type.equals(super.right.type)) {
  41.             super.type = super.left.type;
  42.          } else if ((var6 & 128) != 0) {
  43.             super.type = Type.tDouble;
  44.          } else if ((var6 & 64) != 0) {
  45.             super.type = Type.tFloat;
  46.          } else if ((var6 & 32) != 0) {
  47.             super.type = Type.tLong;
  48.          } else if ((var6 & 1792) != 0) {
  49.             try {
  50.                super.type = var1.implicitCast(super.right.type, super.left.type) ? super.left.type : super.right.type;
  51.             } catch (ClassNotFound var7) {
  52.                super.type = Type.tError;
  53.             }
  54.          } else if ((var6 & 4) != 0 && super.left.fitsType(var1, var2, Type.tChar) && super.right.fitsType(var1, var2, Type.tChar)) {
  55.             super.type = Type.tChar;
  56.          } else if ((var6 & 8) != 0 && super.left.fitsType(var1, var2, Type.tShort) && super.right.fitsType(var1, var2, Type.tShort)) {
  57.             super.type = Type.tShort;
  58.          } else if ((var6 & 2) != 0 && super.left.fitsType(var1, var2, Type.tByte) && super.right.fitsType(var1, var2, Type.tByte)) {
  59.             super.type = Type.tByte;
  60.          } else {
  61.             super.type = Type.tInt;
  62.          }
  63.  
  64.          super.left = ((Node)this).convert(var1, var2, super.type, super.left);
  65.          super.right = ((Node)this).convert(var1, var2, super.type, super.right);
  66.          return var3;
  67.       }
  68.    }
  69.  
  70.    public Vset check(Environment var1, Context var2, Vset var3, Hashtable var4) {
  71.       var3 = this.cond.checkValue(var1, var2, var3, var4);
  72.       this.cond = ((Node)this).convert(var1, var2, Type.tBoolean, this.cond);
  73.       return super.left.check(var1, var2, var3.copy(), var4).join(super.right.check(var1, var2, var3, var4));
  74.    }
  75.  
  76.    public boolean isConstant() {
  77.       return this.cond.isConstant() && super.left.isConstant() && super.right.isConstant();
  78.    }
  79.  
  80.    Expression simplify() {
  81.       if (this.cond.equals(true)) {
  82.          return super.left;
  83.       } else {
  84.          return (Expression)(this.cond.equals(false) ? super.right : this);
  85.       }
  86.    }
  87.  
  88.    public Expression inline(Environment var1, Context var2) {
  89.       super.left = super.left.inline(var1, var2);
  90.       super.right = super.right.inline(var1, var2);
  91.       if (super.left == null && super.right == null) {
  92.          return this.cond.inline(var1, var2);
  93.       } else {
  94.          if (super.left == null) {
  95.             super.left = super.right;
  96.             super.right = null;
  97.             this.cond = new NotExpression(super.where, this.cond);
  98.          }
  99.  
  100.          this.cond = this.cond.inlineValue(var1, var2);
  101.          return this.simplify();
  102.       }
  103.    }
  104.  
  105.    public Expression inlineValue(Environment var1, Context var2) {
  106.       this.cond = this.cond.inlineValue(var1, var2);
  107.       super.left = super.left.inlineValue(var1, var2);
  108.       super.right = super.right.inlineValue(var1, var2);
  109.       return this.simplify();
  110.    }
  111.  
  112.    public int costInline(int var1, Environment var2, Context var3) {
  113.       return 1 + this.cond.costInline(var1, var2, var3) + super.left.costInline(var1, var2, var3) + super.right.costInline(var1, var2, var3);
  114.    }
  115.  
  116.    public Expression copyInline(Context var1) {
  117.       ConditionalExpression var2 = (ConditionalExpression)((Node)this).clone();
  118.       var2.cond = this.cond.copyInline(var1);
  119.       var2.left = super.left.copyInline(var1);
  120.       var2.right = super.right.copyInline(var1);
  121.       return var2;
  122.    }
  123.  
  124.    public void codeValue(Environment var1, Context var2, Assembler var3) {
  125.       Label var4 = new Label();
  126.       Label var5 = new Label();
  127.       this.cond.codeBranch(var1, var2, var3, var4, false);
  128.       super.left.codeValue(var1, var2, var3);
  129.       var3.add(super.where, 167, var5);
  130.       var3.add(var4);
  131.       super.right.codeValue(var1, var2, var3);
  132.       var3.add(var5);
  133.    }
  134.  
  135.    public void code(Environment var1, Context var2, Assembler var3) {
  136.       Label var4 = new Label();
  137.       this.cond.codeBranch(var1, var2, var3, var4, false);
  138.       super.left.code(var1, var2, var3);
  139.       if (super.right != null) {
  140.          Label var5 = new Label();
  141.          var3.add(super.where, 167, var5);
  142.          var3.add(var4);
  143.          super.right.code(var1, var2, var3);
  144.          var3.add(var5);
  145.       } else {
  146.          var3.add(var4);
  147.       }
  148.    }
  149.  
  150.    public void print(PrintStream var1) {
  151.       var1.print("(" + Constants.opNames[super.op] + " ");
  152.       this.cond.print(var1);
  153.       var1.print(" ");
  154.       super.left.print(var1);
  155.       var1.print(" ");
  156.       if (super.right != null) {
  157.          super.right.print(var1);
  158.       } else {
  159.          var1.print("<null>");
  160.       }
  161.  
  162.       var1.print(")");
  163.    }
  164. }
  165.