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

  1. package espresso;
  2.  
  3. class Subscript extends AST {
  4.    boolean alloc;
  5.    AST index;
  6.    AST struc;
  7.  
  8.    void print(int var1) {
  9.       this.struc.print(11);
  10.       System.out.print("[");
  11.       if (this.index != null) {
  12.          this.index.print();
  13.       }
  14.  
  15.       System.out.print("]");
  16.    }
  17.  
  18.    Item gen() {
  19.       if (this.alloc) {
  20.          Item var1 = this.struc.gen();
  21.          if (var1.mode == 6) {
  22.             this.index.genLoad();
  23.             return new NewArrayItem(1);
  24.          } else if (var1.mode == 10) {
  25.             int var2 = ((NewArrayItem)var1).dim;
  26.             if (this.index != null) {
  27.                this.index.genLoad();
  28.                ++var2;
  29.             }
  30.  
  31.             return new NewArrayItem(var2);
  32.          } else {
  33.             throw new CompilerError("gen");
  34.          }
  35.       } else {
  36.          this.struc.genLoad();
  37.          this.index.genLoad();
  38.          return Item.indexedItem;
  39.       }
  40.    }
  41.  
  42.    AST simplify() {
  43.       this.struc = this.struc.simplify();
  44.       if (this.index != null) {
  45.          this.index = this.index.simplify();
  46.       }
  47.  
  48.       return this;
  49.    }
  50.  
  51.    void markCaptured(Bits var1) {
  52.       this.struc.markCaptured(var1);
  53.       if (this.index != null) {
  54.          this.index.markCaptured(var1);
  55.       }
  56.  
  57.    }
  58.  
  59.    Typ attr(Env var1, int var2, Typ var3) {
  60.       if (var2 == 2) {
  61.          this.alloc = true;
  62.          if (this.index == null) {
  63.             super.typ = new ArrayTyp(Attr.checkNonVoid(this.struc.pos, this.struc.attr(var1, 2, Typ.anyTyp)));
  64.          } else {
  65.             Typ var4 = Attr.checkNonVoid(this.struc.pos, this.struc.attr(var1, 2, Typ.anyTyp));
  66.             this.index.attr(var1, 12, Typ.intTyp);
  67.             super.typ = new ArrayTyp(var4);
  68.          }
  69.       } else if (Attr.checkKind(super.pos, 4, var2)) {
  70.          this.alloc = false;
  71.          Typ var6 = this.struc.attr(var1, 12, new ArrayTyp(Typ.anyTyp));
  72.          this.index.attr(var1, 12, Typ.intTyp);
  73.          if (var6.tag == 13) {
  74.             super.typ = Attr.checkTyp(super.pos, ((ArrayTyp)var6).elemtyp, var3);
  75.          } else if (var6.tag == 15) {
  76.             Report.error(super.pos, "null cannot be dereferenced");
  77.             super.typ = Typ.errTyp;
  78.          } else {
  79.             super.typ = Typ.errTyp;
  80.          }
  81.       } else {
  82.          super.typ = Typ.errTyp;
  83.       }
  84.  
  85.       return super.typ;
  86.    }
  87.  
  88.    boolean isType() {
  89.       return this.index == null || this.struc.isType() && this.index.isType();
  90.    }
  91.  
  92.    boolean isExpr() {
  93.       return this.index != null && this.struc.isExpr() && this.index.isExpr();
  94.    }
  95.  
  96.    Subscript(int var1, AST var2, AST var3) {
  97.       super(var1, 6);
  98.       this.struc = var2;
  99.       this.index = var3;
  100.    }
  101. }
  102.