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

  1. package espresso;
  2.  
  3. class VarDef extends Def {
  4.    AST init;
  5.    AST dcltyp;
  6.  
  7.    void print(int var1) {
  8.       System.out.print(Obj.modNames(super.mods));
  9.       this.dcltyp.print();
  10.       System.out.print(String.valueOf(" ").concat(String.valueOf(super.name)));
  11.       if (this.init != null) {
  12.          System.out.print(" = ");
  13.          this.init.print();
  14.       }
  15.  
  16.    }
  17.  
  18.    Item gen() {
  19.       VarObj var1 = (VarObj)super.obj;
  20.       if (super.localEnv.parent.tag == 16) {
  21.          ClassDef var2 = super.localEnv.enclClass;
  22.          if ((var1.modifiers & 8) != 0) {
  23.             Gen.useCode(var2.clinitcode);
  24.          } else {
  25.             Gen.useCode(var2.initcode);
  26.          }
  27.  
  28.          Gen.entryPoint(0);
  29.       }
  30.  
  31.       if (this.init != null) {
  32.          if (var1.isConstant()) {
  33.             Object var3 = var1.constValue();
  34.          } else {
  35.             AST var4 = this.init;
  36.             Gen.statBegin(super.pos);
  37.             Object var5;
  38.             if (var1.owner instanceof FunObj) {
  39.                Gen.adrLocal(var1, Gen.newLocal(var1.typ));
  40.                var5 = new LocalItem(super.pos, var1.adr);
  41.             } else {
  42.                Gen.adrGlobal(var1);
  43.                var5 = new BasedItem(super.pos, Item.thisItem, var1);
  44.             }
  45.  
  46.             Item var6 = var4.gen().coerce(var4.typ, var1.typ);
  47.             var6.load(var1.typ);
  48.             ((Item)var5).store(var1.typ);
  49.          }
  50.       } else if (var1.owner instanceof FunObj) {
  51.          Gen.adrLocal(var1, Gen.newLocal(var1.typ));
  52.          Gen.letUninit(var1.adr);
  53.       } else {
  54.          Gen.adrGlobal(var1);
  55.          Gen.letInit(var1.adr);
  56.       }
  57.  
  58.       return Item.voidItem;
  59.    }
  60.  
  61.    AST simplify() {
  62.       if (this.init != null) {
  63.          this.init = this.init.simplify();
  64.       }
  65.  
  66.       this.dcltyp = Simplify.annot(this.dcltyp.simplify(), super.obj.typ);
  67.       if (((VarObj)super.obj).passByRef) {
  68.          if (this.init != null) {
  69.             this.init = new Aggregate(this.init.pos, new ASTS(this.init));
  70.          } else {
  71.             this.init = new New(super.pos, new Subscript(super.pos, this.dcltyp, new Literal(super.pos, 90, new Integer(1))));
  72.          }
  73.  
  74.          this.dcltyp = Simplify.annot(new Subscript(this.dcltyp.pos, Simplify.strip(this.dcltyp), (AST)null), new ArrayTyp(super.obj.typ));
  75.       }
  76.  
  77.       super.obj = null;
  78.       return this;
  79.    }
  80.  
  81.    void markCaptured(Bits var1) {
  82.       if (this.init != null) {
  83.          this.init.markCaptured(var1);
  84.       }
  85.  
  86.       var1.excl(((VarObj)super.obj).vnum);
  87.    }
  88.  
  89.    Typ attr(Env var1, int var2, Typ var3) {
  90.       super.localEnv = var1;
  91.       if (super.obj == null) {
  92.          this.enter(var1);
  93.       }
  94.  
  95.       if (this.init != null) {
  96.          if ((super.mods & 8) != 0) {
  97.             var1 = new Env(var1, this);
  98.             var1.isStatic = true;
  99.          }
  100.  
  101.          this.init.attr(var1, 12, super.obj.typ);
  102.       }
  103.  
  104.       if ((super.obj.modifiers & 16) != 0) {
  105.          if (this.init == null) {
  106.             Report.error(super.pos, "final variable needs an initializer");
  107.          } else if (var1.isInterface() && !this.init.isConstant()) {
  108.             Report.error(this.init.pos, "variable initializer in interface should be a constant expression");
  109.          }
  110.       }
  111.  
  112.       super.typ = var3;
  113.       return super.typ;
  114.    }
  115.  
  116.    void enter(Env var1) {
  117.       int var2 = Attr.completeMods(super.pos, super.mods, var1, 223, 25);
  118.       if ((var2 & 16) != 0) {
  119.          var2 |= 8;
  120.       }
  121.  
  122.       Typ var3 = Attr.checkNonVoid(this.dcltyp.pos, this.dcltyp.attr(var1, 2, Typ.anyTyp));
  123.       VarObj var4 = new VarObj(var2, super.name, var3);
  124.       var4.alttyp = Simplify.alternateType(this.dcltyp);
  125.       if ((var4.modifiers & 16) != 0) {
  126.          var4.initializer = this.init;
  127.       }
  128.  
  129.       Env var5;
  130.       for(var5 = var1; var5 != null && (!(var5.scope.owner instanceof FunObj) || var5.scope.owner.name == null); var5 = var5.next) {
  131.       }
  132.  
  133.       if (var5 != null) {
  134.          var4.vnum = ((FunObj)var1.scope.owner).nlocals++;
  135.       }
  136.  
  137.       super.obj = var4;
  138.       var4.owner = var1.scope.owner;
  139.       if (this.checkUnique(var1.scope)) {
  140.          var1.scope.enter(var4);
  141.          this.checkUnshadowed(var1.scope);
  142.       }
  143.  
  144.    }
  145.  
  146.    private boolean checkUnshadowed(Scope var1) {
  147.       for(ScopeEntry var2 = var1.lookup(super.name); var2.scope != null && (var2.scope.owner == null || !(var2.scope.owner instanceof ClassObj)); var2 = var2.next()) {
  148.          if (var2.obj != super.obj) {
  149.             Report.error(super.pos, String.valueOf(String.valueOf(super.obj).concat(String.valueOf(" already defined"))).concat(String.valueOf(Attr.location(var2.scope))));
  150.             return false;
  151.          }
  152.       }
  153.  
  154.       return true;
  155.    }
  156.  
  157.    private boolean checkUnique(Scope var1) {
  158.       for(ScopeEntry var2 = var1.lookup(super.name); var2.scope == var1; var2 = var2.next()) {
  159.          if (var2.obj != super.obj && !Attr.isError(var2.obj.typ)) {
  160.             Report.error(super.pos, String.valueOf(String.valueOf("duplicate definition of ").concat(String.valueOf(super.obj))).concat(String.valueOf(Attr.location(var2.scope))));
  161.             return false;
  162.          }
  163.       }
  164.  
  165.       return true;
  166.    }
  167.  
  168.    VarDef(int var1, Name var2, int var3, AST var4, AST var5) {
  169.       super(var1, 3, var2, var3);
  170.       this.dcltyp = var4;
  171.       this.init = var5;
  172.    }
  173. }
  174.