src/jdk.compiler/share/classes/com/sun/tools/javac/code/Scope.java
changeset 58500 03165abce4cc
parent 50374 2d0647b9ac18
equal deleted inserted replaced
58499:d62c7224d5b7 58500:03165abce4cc
   387             while (elems != null) {
   387             while (elems != null) {
   388                 int hash = getIndex(elems.sym.name);
   388                 int hash = getIndex(elems.sym.name);
   389                 Entry e = table[hash];
   389                 Entry e = table[hash];
   390                 Assert.check(e == elems, elems.sym);
   390                 Assert.check(e == elems, elems.sym);
   391                 table[hash] = elems.shadowed;
   391                 table[hash] = elems.shadowed;
   392                 elems = elems.sibling;
   392                 elems = elems.nextSibling;
   393             }
   393             }
   394             Assert.check(next.shared > 0);
   394             Assert.check(next.shared > 0);
   395             next.shared--;
   395             next.shared--;
   396             next.nelems = nelems;
   396             next.nelems = nelems;
   397             // System.out.println("====> leaving scope " + this.hashCode() + " owned by " + this.owner + " to " + next.hashCode());
   397             // System.out.println("====> leaving scope " + this.hashCode() + " owned by " + this.owner + " to " + next.hashCode());
   464                 }
   464                 }
   465                 te = te.shadowed;
   465                 te = te.shadowed;
   466             }
   466             }
   467 
   467 
   468             // remove e from elems and sibling list
   468             // remove e from elems and sibling list
   469             te = elems;
   469             if (elems == e) {
   470             if (te == e)
   470                 elems = e.nextSibling;
   471                 elems = e.sibling;
   471                 if (elems != null)
   472             else while (true) {
   472                     elems.prevSibling = null;
   473                 if (te.sibling == e) {
   473             } else {
   474                     te.sibling = e.sibling;
   474                 Assert.check(e.prevSibling != null, e.sym);
   475                     break;
   475                 e.prevSibling.nextSibling = e.nextSibling;
   476                 }
   476                 if (e.nextSibling != null)
   477                 te = te.sibling;
   477                     e.nextSibling.prevSibling = e.prevSibling;
   478             }
   478             }
   479 
   479 
   480             removeCount++;
   480             removeCount++;
   481 
   481 
   482             //notify listeners
   482             //notify listeners
   595                     return doNext();
   595                     return doNext();
   596                 }
   596                 }
   597                 private Symbol doNext() {
   597                 private Symbol doNext() {
   598                     Symbol sym = (currEntry == null ? null : currEntry.sym);
   598                     Symbol sym = (currEntry == null ? null : currEntry.sym);
   599                     if (currEntry != null) {
   599                     if (currEntry != null) {
   600                         currEntry = currEntry.sibling;
   600                         currEntry = currEntry.nextSibling;
   601                     }
   601                     }
   602                     update();
   602                     update();
   603                     return sym;
   603                     return sym;
   604                 }
   604                 }
   605 
   605 
   615                     }
   615                     }
   616                 }
   616                 }
   617 
   617 
   618                 void skipToNextMatchingEntry() {
   618                 void skipToNextMatchingEntry() {
   619                     while (currEntry != null && sf != null && !sf.accepts(currEntry.sym)) {
   619                     while (currEntry != null && sf != null && !sf.accepts(currEntry.sym)) {
   620                         currEntry = currEntry.sibling;
   620                         currEntry = currEntry.nextSibling;
   621                     }
   621                     }
   622                 }
   622                 }
   623             };
   623             };
   624         }
   624         }
   625 
   625 
   675         public String toString() {
   675         public String toString() {
   676             StringBuilder result = new StringBuilder();
   676             StringBuilder result = new StringBuilder();
   677             result.append("Scope[");
   677             result.append("Scope[");
   678             for (ScopeImpl s = this; s != null ; s = s.next) {
   678             for (ScopeImpl s = this; s != null ; s = s.next) {
   679                 if (s != this) result.append(" | ");
   679                 if (s != this) result.append(" | ");
   680                 for (Entry e = s.elems; e != null; e = e.sibling) {
   680                 for (Entry e = s.elems; e != null; e = e.nextSibling) {
   681                     if (e != s.elems) result.append(", ");
   681                     if (e != s.elems) result.append(", ");
   682                     result.append(e.sym);
   682                     result.append(e.sym);
   683                 }
   683                 }
   684             }
   684             }
   685             result.append("]");
   685             result.append("]");
   700          */
   700          */
   701         private Entry shadowed;
   701         private Entry shadowed;
   702 
   702 
   703         /** Next entry in same scope.
   703         /** Next entry in same scope.
   704          */
   704          */
   705         public Entry sibling;
   705         public Entry nextSibling;
       
   706 
       
   707         /** Prev entry in same scope.
       
   708          */
       
   709         public Entry prevSibling;
   706 
   710 
   707         /** The entry's scope.
   711         /** The entry's scope.
   708          *  scope == null   iff   this == sentinel
   712          *  scope == null   iff   this == sentinel
   709          */
   713          */
   710         public ScopeImpl scope;
   714         public ScopeImpl scope;
   711 
   715 
   712         public Entry(Symbol sym, Entry shadowed, Entry sibling, ScopeImpl scope) {
   716         public Entry(Symbol sym, Entry shadowed, Entry nextSibling, ScopeImpl scope) {
   713             this.sym = sym;
   717             this.sym = sym;
   714             this.shadowed = shadowed;
   718             this.shadowed = shadowed;
   715             this.sibling = sibling;
   719             this.nextSibling = nextSibling;
   716             this.scope = scope;
   720             this.scope = scope;
       
   721             if (nextSibling != null)
       
   722                 nextSibling.prevSibling = this;
   717         }
   723         }
   718 
   724 
   719         /** Return next entry with the same name as this entry, proceeding
   725         /** Return next entry with the same name as this entry, proceeding
   720          *  outwards if not found in this scope.
   726          *  outwards if not found in this scope.
   721          */
   727          */