home *** CD-ROM | disk | FTP | other *** search
- package espresso;
-
- class Subscript extends AST {
- boolean alloc;
- AST index;
- AST struc;
-
- void print(int var1) {
- this.struc.print(11);
- System.out.print("[");
- if (this.index != null) {
- this.index.print();
- }
-
- System.out.print("]");
- }
-
- Item gen() {
- if (this.alloc) {
- Item var1 = this.struc.gen();
- if (var1.mode == 6) {
- this.index.genLoad();
- return new NewArrayItem(1);
- } else if (var1.mode == 10) {
- int var2 = ((NewArrayItem)var1).dim;
- if (this.index != null) {
- this.index.genLoad();
- ++var2;
- }
-
- return new NewArrayItem(var2);
- } else {
- throw new CompilerError("gen");
- }
- } else {
- this.struc.genLoad();
- this.index.genLoad();
- return Item.indexedItem;
- }
- }
-
- AST simplify() {
- this.struc = this.struc.simplify();
- if (this.index != null) {
- this.index = this.index.simplify();
- }
-
- return this;
- }
-
- void markCaptured(Bits var1) {
- this.struc.markCaptured(var1);
- if (this.index != null) {
- this.index.markCaptured(var1);
- }
-
- }
-
- Typ attr(Env var1, int var2, Typ var3) {
- if (var2 == 2) {
- this.alloc = true;
- if (this.index == null) {
- super.typ = new ArrayTyp(Attr.checkNonVoid(this.struc.pos, this.struc.attr(var1, 2, Typ.anyTyp)));
- } else {
- Typ var4 = Attr.checkNonVoid(this.struc.pos, this.struc.attr(var1, 2, Typ.anyTyp));
- this.index.attr(var1, 12, Typ.intTyp);
- super.typ = new ArrayTyp(var4);
- }
- } else if (Attr.checkKind(super.pos, 4, var2)) {
- this.alloc = false;
- Typ var6 = this.struc.attr(var1, 12, new ArrayTyp(Typ.anyTyp));
- this.index.attr(var1, 12, Typ.intTyp);
- if (var6.tag == 13) {
- super.typ = Attr.checkTyp(super.pos, ((ArrayTyp)var6).elemtyp, var3);
- } else if (var6.tag == 15) {
- Report.error(super.pos, "null cannot be dereferenced");
- super.typ = Typ.errTyp;
- } else {
- super.typ = Typ.errTyp;
- }
- } else {
- super.typ = Typ.errTyp;
- }
-
- return super.typ;
- }
-
- boolean isType() {
- return this.index == null || this.struc.isType() && this.index.isType();
- }
-
- boolean isExpr() {
- return this.index != null && this.struc.isExpr() && this.index.isExpr();
- }
-
- Subscript(int var1, AST var2, AST var3) {
- super(var1, 6);
- this.struc = var2;
- this.index = var3;
- }
- }
-