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

  1. package espresso;
  2.  
  3. class Try extends AST {
  4.    Bits captured;
  5.    Bits uninits;
  6.    int excVarAdr = -1;
  7.    LocalItem excVar;
  8.    Label finalLabel = null;
  9.    int endPc;
  10.    int startPc;
  11.    AST finalizer;
  12.    FunDef[] catchers;
  13.    AST body;
  14.  
  15.    void print(int var1) {
  16.       System.out.print("try ");
  17.       this.body.print();
  18.  
  19.       for(int var2 = 0; var2 < this.catchers.length; ++var2) {
  20.          System.out.print(" catch");
  21.          this.catchers[var2].print();
  22.       }
  23.  
  24.       if (this.finalizer != null) {
  25.          System.out.print(" finally ");
  26.          this.finalizer.print();
  27.       }
  28.  
  29.    }
  30.  
  31.    Item gen() {
  32.       this.uninits = Gen.uninitSet();
  33.       this.startPc = Gen.curPc();
  34.       this.body.genDrop();
  35.       this.endPc = Gen.curPc();
  36.       this.finalisation();
  37.       Label var1 = Gen.branch(167);
  38.       if (this.catchers.length != 0 || this.finalizer != null) {
  39.          this.excVar = new LocalItem(super.pos, Gen.newLocal(Predef.throwableTyp));
  40.       }
  41.  
  42.       for(int var2 = 0; var2 < this.catchers.length; ++var2) {
  43.          this.catchers[var2].genDrop();
  44.          this.finalisation();
  45.          var1 = Gen.mergeLabels(var1, Gen.branch(167));
  46.       }
  47.  
  48.       if (this.finalizer != null) {
  49.          Gen.entryPoint(1, this.uninits);
  50.          Gen.registerCatch(this.startPc, Gen.curPc() - 3, Gen.curPc(), 0);
  51.          this.excVar.store(Predef.throwableTyp);
  52.          this.finalisation();
  53.          this.excVar.load(Predef.throwableTyp);
  54.          Gen.emitop(191);
  55.          Gen.entryPoint(1);
  56.          Gen.resolve(this.finalLabel);
  57.          LocalItem var3 = new LocalItem(super.pos, Gen.newLocal(Predef.objectTyp));
  58.          var3.store(Predef.objectTyp);
  59.          this.genFinal();
  60.          Gen.emitop1w(169, var3.disp);
  61.          Gen.alive = false;
  62.       }
  63.  
  64.       Gen.resolve(var1);
  65.       return Item.voidItem;
  66.    }
  67.  
  68.    void genFinal() {
  69.       this.finalizer.genDrop();
  70.    }
  71.  
  72.    void finalisation() {
  73.       if (this.finalizer != null && Gen.alive) {
  74.          this.finalLabel = new Label(Gen.curPc(), this.finalLabel, 1, Gen.uninitSet());
  75.          Gen.emitJump(this.finalLabel, 168);
  76.       }
  77.  
  78.    }
  79.  
  80.    AST simplify() {
  81.       this.body = this.body.simplify();
  82.  
  83.       for(int var1 = 0; var1 < this.catchers.length; ++var1) {
  84.          this.catchers[var1] = (FunDef)this.catchers[var1].simplify();
  85.       }
  86.  
  87.       if (this.finalizer != null) {
  88.          this.finalizer = this.finalizer.simplify();
  89.       }
  90.  
  91.       return this;
  92.    }
  93.  
  94.    void markCaptured(Bits var1) {
  95.       this.body.markCaptured(var1);
  96.       var1.orSet(this.captured);
  97.       Bits var2 = var1.dup();
  98.       Bits var3 = new Bits();
  99.  
  100.       for(int var4 = 0; var4 < this.catchers.length; ++var4) {
  101.          var3.assign(var2);
  102.          this.catchers[var4].markCaptured(var3);
  103.          var1.orSet(var3);
  104.       }
  105.  
  106.       if (this.finalizer != null) {
  107.          this.finalizer.markCaptured(var1);
  108.       }
  109.  
  110.    }
  111.  
  112.    Typ attr(Env var1, int var2, Typ var3) {
  113.       super.typ = var3;
  114.       Env var4 = new Env(var1, this);
  115.  
  116.       for(int var5 = 0; var5 < this.catchers.length; ++var5) {
  117.          super.typ = Attr.join(this.catchers[var5].pos, super.typ, this.catchers[var5].attr(var4, 12, var3));
  118.       }
  119.  
  120.       if (this.finalizer != null) {
  121.          super.typ = Attr.join(this.finalizer.pos, super.typ, this.finalizer.attr(var4, 12, var3));
  122.       }
  123.  
  124.       for(int var6 = 0; var6 < this.catchers.length; ++var6) {
  125.          var4.reported = TypSet.incl(var4.reported, this.catchers[var6].params[0].obj.typ);
  126.       }
  127.  
  128.       super.typ = this.body.attr(var4, 12, var3);
  129.       return super.typ;
  130.    }
  131.  
  132.    Try(int var1, AST var2, ASTS var3, AST var4) {
  133.       super(var1, 18);
  134.       this.body = var2;
  135.       this.catchers = new FunDef[var3.length];
  136.  
  137.       for(int var5 = 0; var5 < var3.length; ++var5) {
  138.          this.catchers[var5] = (FunDef)var3.elems[var5];
  139.       }
  140.  
  141.       this.finalizer = var4;
  142.       this.captured = new Bits();
  143.    }
  144. }
  145.