home *** CD-ROM | disk | FTP | other *** search
- package espresso;
-
- class Conditional extends AST {
- AST elsepart;
- AST thenpart;
- AST cond;
-
- void print(int var1) {
- if (super.tag == 28) {
- System.out.print("if (");
- this.cond.print();
- System.out.print(") ");
- this.thenpart.print();
- if (this.elsepart != null) {
- System.out.print(" else ");
- this.elsepart.print();
- }
- } else {
- Pretty.open(var1, -1);
- this.cond.print(-1);
- System.out.print(" ? ");
- this.thenpart.print(-1);
- System.out.print(" : ");
- this.elsepart.print(-1);
- Pretty.close(var1, -1);
- }
-
- }
-
- Item gen() {
- if (this.elsepart != null && this.cond.isConstant()) {
- ImmediateItem var1 = (ImmediateItem)this.cond.gen();
- return ((Number)var1.value).intValue() != 0 ? this.thenpart.gen() : this.elsepart.gen();
- } else {
- if (super.tag == 28) {
- Gen.statBegin(super.pos);
- }
-
- Label var2 = null;
- CondItem var3 = this.cond.gen().mkCond();
- Label var4 = var3.jumpFalse();
- if (var3.trueJumps != null || var3.opcode != Gen.dontgoto) {
- Gen.resolve(var3.trueJumps);
- if (super.tag == 28) {
- this.thenpart.genDrop();
- } else {
- this.thenpart.gen().coerce(this.thenpart.typ, super.typ).load(super.typ);
- }
-
- var2 = Gen.branch(167);
- }
-
- if (this.elsepart != null) {
- if (var4 != null) {
- Gen.resolve(var4);
- if (super.tag == 28) {
- this.elsepart.genDrop();
- } else {
- this.elsepart.gen().coerce(this.elsepart.typ, super.typ).load(super.typ);
- }
- }
-
- Gen.resolve(var2);
- } else {
- Gen.resolve(var2);
- Gen.resolve(var4);
- }
-
- return super.tag == 28 ? Item.voidItem : Item.stackItem;
- }
- }
-
- AST simplify() {
- this.cond = this.cond.simplify();
- this.thenpart = this.thenpart.simplify();
- if (this.elsepart != null) {
- this.elsepart = this.elsepart.simplify();
- }
-
- return this;
- }
-
- void markCaptured(Bits var1) {
- this.cond.markCaptured(var1);
- Bits var2 = var1.dup();
- this.thenpart.markCaptured(var1);
- if (this.elsepart != null) {
- this.elsepart.markCaptured(var2);
- var1.orSet(var2);
- }
-
- }
-
- Typ attr(Env var1, int var2, Typ var3) {
- if (Attr.checkKind(super.pos, 12, var2)) {
- this.cond.attr(var1, 12, Typ.booleanTyp);
- super.typ = Attr.join(this.thenpart.pos, var3, this.thenpart.attr(var1, 12, var3));
- if (this.elsepart != null) {
- super.typ = Attr.join(this.elsepart.pos, super.typ, this.elsepart.attr(var1, 12, var3));
- }
- } else {
- super.typ = Typ.errTyp;
- }
-
- return super.typ;
- }
-
- boolean isConstant() {
- return this.cond.isConstant() && this.thenpart.isConstant() && this.elsepart.isConstant();
- }
-
- boolean isExpr() {
- return true;
- }
-
- Conditional(int var1, int var2, AST var3, AST var4, AST var5) {
- super(var1, var2);
- this.cond = var3;
- this.thenpart = var4;
- this.elsepart = var5;
- }
- }
-