home *** CD-ROM | disk | FTP | other *** search
Wrap
package espresso; class VarDef extends Def { AST init; AST dcltyp; void print(int var1) { System.out.print(Obj.modNames(super.mods)); this.dcltyp.print(); System.out.print(String.valueOf(" ").concat(String.valueOf(super.name))); if (this.init != null) { System.out.print(" = "); this.init.print(); } } Item gen() { VarObj var1 = (VarObj)super.obj; if (super.localEnv.parent.tag == 16) { ClassDef var2 = super.localEnv.enclClass; if ((var1.modifiers & 8) != 0) { Gen.useCode(var2.clinitcode); } else { Gen.useCode(var2.initcode); } Gen.entryPoint(0); } if (this.init != null) { if (var1.isConstant()) { Object var3 = var1.constValue(); } else { AST var4 = this.init; Gen.statBegin(super.pos); Object var5; if (var1.owner instanceof FunObj) { Gen.adrLocal(var1, Gen.newLocal(var1.typ)); var5 = new LocalItem(super.pos, var1.adr); } else { Gen.adrGlobal(var1); var5 = new BasedItem(super.pos, Item.thisItem, var1); } Item var6 = var4.gen().coerce(var4.typ, var1.typ); var6.load(var1.typ); ((Item)var5).store(var1.typ); } } else if (var1.owner instanceof FunObj) { Gen.adrLocal(var1, Gen.newLocal(var1.typ)); Gen.letUninit(var1.adr); } else { Gen.adrGlobal(var1); Gen.letInit(var1.adr); } return Item.voidItem; } AST simplify() { if (this.init != null) { this.init = this.init.simplify(); } this.dcltyp = Simplify.annot(this.dcltyp.simplify(), super.obj.typ); if (((VarObj)super.obj).passByRef) { if (this.init != null) { this.init = new Aggregate(this.init.pos, new ASTS(this.init)); } else { this.init = new New(super.pos, new Subscript(super.pos, this.dcltyp, new Literal(super.pos, 90, new Integer(1)))); } this.dcltyp = Simplify.annot(new Subscript(this.dcltyp.pos, Simplify.strip(this.dcltyp), (AST)null), new ArrayTyp(super.obj.typ)); } super.obj = null; return this; } void markCaptured(Bits var1) { if (this.init != null) { this.init.markCaptured(var1); } var1.excl(((VarObj)super.obj).vnum); } Typ attr(Env var1, int var2, Typ var3) { super.localEnv = var1; if (super.obj == null) { this.enter(var1); } if (this.init != null) { if ((super.mods & 8) != 0) { var1 = new Env(var1, this); var1.isStatic = true; } this.init.attr(var1, 12, super.obj.typ); } if ((super.obj.modifiers & 16) != 0) { if (this.init == null) { Report.error(super.pos, "final variable needs an initializer"); } else if (var1.isInterface() && !this.init.isConstant()) { Report.error(this.init.pos, "variable initializer in interface should be a constant expression"); } } super.typ = var3; return super.typ; } void enter(Env var1) { int var2 = Attr.completeMods(super.pos, super.mods, var1, 223, 25); if ((var2 & 16) != 0) { var2 |= 8; } Typ var3 = Attr.checkNonVoid(this.dcltyp.pos, this.dcltyp.attr(var1, 2, Typ.anyTyp)); VarObj var4 = new VarObj(var2, super.name, var3); var4.alttyp = Simplify.alternateType(this.dcltyp); if ((var4.modifiers & 16) != 0) { var4.initializer = this.init; } Env var5; for(var5 = var1; var5 != null && (!(var5.scope.owner instanceof FunObj) || var5.scope.owner.name == null); var5 = var5.next) { } if (var5 != null) { var4.vnum = ((FunObj)var1.scope.owner).nlocals++; } super.obj = var4; var4.owner = var1.scope.owner; if (this.checkUnique(var1.scope)) { var1.scope.enter(var4); this.checkUnshadowed(var1.scope); } } private boolean checkUnshadowed(Scope var1) { for(ScopeEntry var2 = var1.lookup(super.name); var2.scope != null && (var2.scope.owner == null || !(var2.scope.owner instanceof ClassObj)); var2 = var2.next()) { if (var2.obj != super.obj) { Report.error(super.pos, String.valueOf(String.valueOf(super.obj).concat(String.valueOf(" already defined"))).concat(String.valueOf(Attr.location(var2.scope)))); return false; } } return true; } private boolean checkUnique(Scope var1) { for(ScopeEntry var2 = var1.lookup(super.name); var2.scope == var1; var2 = var2.next()) { if (var2.obj != super.obj && !Attr.isError(var2.obj.typ)) { Report.error(super.pos, String.valueOf(String.valueOf("duplicate definition of ").concat(String.valueOf(super.obj))).concat(String.valueOf(Attr.location(var2.scope)))); return false; } } return true; } VarDef(int var1, Name var2, int var3, AST var4, AST var5) { super(var1, 3, var2, var3); this.dcltyp = var4; this.init = var5; } }