home *** CD-ROM | disk | FTP | other *** search
/ Tutto per Internet / Internet.iso / soft95 / Java / espints / espinst.exe / classes / espresso / Conditional.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-02-28  |  2.9 KB  |  123 lines

  1. package espresso;
  2.  
  3. class Conditional extends AST {
  4.    AST elsepart;
  5.    AST thenpart;
  6.    AST cond;
  7.  
  8.    void print(int var1) {
  9.       if (super.tag == 28) {
  10.          System.out.print("if (");
  11.          this.cond.print();
  12.          System.out.print(") ");
  13.          this.thenpart.print();
  14.          if (this.elsepart != null) {
  15.             System.out.print(" else ");
  16.             this.elsepart.print();
  17.          }
  18.       } else {
  19.          Pretty.open(var1, -1);
  20.          this.cond.print(-1);
  21.          System.out.print(" ? ");
  22.          this.thenpart.print(-1);
  23.          System.out.print(" : ");
  24.          this.elsepart.print(-1);
  25.          Pretty.close(var1, -1);
  26.       }
  27.  
  28.    }
  29.  
  30.    Item gen() {
  31.       if (this.elsepart != null && this.cond.isConstant()) {
  32.          ImmediateItem var1 = (ImmediateItem)this.cond.gen();
  33.          return ((Number)var1.value).intValue() != 0 ? this.thenpart.gen() : this.elsepart.gen();
  34.       } else {
  35.          if (super.tag == 28) {
  36.             Gen.statBegin(super.pos);
  37.          }
  38.  
  39.          Label var2 = null;
  40.          CondItem var3 = this.cond.gen().mkCond();
  41.          Label var4 = var3.jumpFalse();
  42.          if (var3.trueJumps != null || var3.opcode != Gen.dontgoto) {
  43.             Gen.resolve(var3.trueJumps);
  44.             if (super.tag == 28) {
  45.                this.thenpart.genDrop();
  46.             } else {
  47.                this.thenpart.gen().coerce(this.thenpart.typ, super.typ).load(super.typ);
  48.             }
  49.  
  50.             var2 = Gen.branch(167);
  51.          }
  52.  
  53.          if (this.elsepart != null) {
  54.             if (var4 != null) {
  55.                Gen.resolve(var4);
  56.                if (super.tag == 28) {
  57.                   this.elsepart.genDrop();
  58.                } else {
  59.                   this.elsepart.gen().coerce(this.elsepart.typ, super.typ).load(super.typ);
  60.                }
  61.             }
  62.  
  63.             Gen.resolve(var2);
  64.          } else {
  65.             Gen.resolve(var2);
  66.             Gen.resolve(var4);
  67.          }
  68.  
  69.          return super.tag == 28 ? Item.voidItem : Item.stackItem;
  70.       }
  71.    }
  72.  
  73.    AST simplify() {
  74.       this.cond = this.cond.simplify();
  75.       this.thenpart = this.thenpart.simplify();
  76.       if (this.elsepart != null) {
  77.          this.elsepart = this.elsepart.simplify();
  78.       }
  79.  
  80.       return this;
  81.    }
  82.  
  83.    void markCaptured(Bits var1) {
  84.       this.cond.markCaptured(var1);
  85.       Bits var2 = var1.dup();
  86.       this.thenpart.markCaptured(var1);
  87.       if (this.elsepart != null) {
  88.          this.elsepart.markCaptured(var2);
  89.          var1.orSet(var2);
  90.       }
  91.  
  92.    }
  93.  
  94.    Typ attr(Env var1, int var2, Typ var3) {
  95.       if (Attr.checkKind(super.pos, 12, var2)) {
  96.          this.cond.attr(var1, 12, Typ.booleanTyp);
  97.          super.typ = Attr.join(this.thenpart.pos, var3, this.thenpart.attr(var1, 12, var3));
  98.          if (this.elsepart != null) {
  99.             super.typ = Attr.join(this.elsepart.pos, super.typ, this.elsepart.attr(var1, 12, var3));
  100.          }
  101.       } else {
  102.          super.typ = Typ.errTyp;
  103.       }
  104.  
  105.       return super.typ;
  106.    }
  107.  
  108.    boolean isConstant() {
  109.       return this.cond.isConstant() && this.thenpart.isConstant() && this.elsepart.isConstant();
  110.    }
  111.  
  112.    boolean isExpr() {
  113.       return true;
  114.    }
  115.  
  116.    Conditional(int var1, int var2, AST var3, AST var4, AST var5) {
  117.       super(var1, var2);
  118.       this.cond = var3;
  119.       this.thenpart = var4;
  120.       this.elsepart = var5;
  121.    }
  122. }
  123.