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 |
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 */ |