197 Assert.check(shared == 0); |
197 Assert.check(shared == 0); |
198 enter(sym, this); |
198 enter(sym, this); |
199 } |
199 } |
200 |
200 |
201 public void enter(Symbol sym, Scope s) { |
201 public void enter(Symbol sym, Scope s) { |
202 enter(sym, s, s); |
202 enter(sym, s, s, false); |
203 } |
203 } |
204 |
204 |
205 /** |
205 /** |
206 * Enter symbol sym in this scope, but mark that it comes from |
206 * Enter symbol sym in this scope, but mark that it comes from |
207 * given scope `s' accessed through `origin'. The last two |
207 * given scope `s' accessed through `origin'. The last two |
208 * arguments are only used in import scopes. |
208 * arguments are only used in import scopes. |
209 */ |
209 */ |
210 public void enter(Symbol sym, Scope s, Scope origin) { |
210 public void enter(Symbol sym, Scope s, Scope origin, boolean staticallyImported) { |
211 Assert.check(shared == 0); |
211 Assert.check(shared == 0); |
212 if (nelems * 3 >= hashMask * 2) |
212 if (nelems * 3 >= hashMask * 2) |
213 dble(); |
213 dble(); |
214 int hash = getIndex(sym.name); |
214 int hash = getIndex(sym.name); |
215 Entry old = table[hash]; |
215 Entry old = table[hash]; |
216 if (old == null) { |
216 if (old == null) { |
217 old = sentinel; |
217 old = sentinel; |
218 nelems++; |
218 nelems++; |
219 } |
219 } |
220 Entry e = makeEntry(sym, old, elems, s, origin); |
220 Entry e = makeEntry(sym, old, elems, s, origin, staticallyImported); |
221 table[hash] = e; |
221 table[hash] = e; |
222 elems = e; |
222 elems = e; |
223 |
223 |
224 //notify listeners |
224 //notify listeners |
225 for (List<ScopeListener> l = listeners; l.nonEmpty(); l = l.tail) { |
225 for (List<ScopeListener> l = listeners; l.nonEmpty(); l = l.tail) { |
226 l.head.symbolAdded(sym, this); |
226 l.head.symbolAdded(sym, this); |
227 } |
227 } |
228 } |
228 } |
229 |
229 |
230 Entry makeEntry(Symbol sym, Entry shadowed, Entry sibling, Scope scope, Scope origin) { |
230 Entry makeEntry(Symbol sym, Entry shadowed, Entry sibling, Scope scope, Scope origin, boolean staticallyImported) { |
231 return new Entry(sym, shadowed, sibling, scope); |
231 return new Entry(sym, shadowed, sibling, scope); |
232 } |
232 } |
233 |
233 |
234 |
234 |
235 public interface ScopeListener { |
235 public interface ScopeListener { |
497 public Entry next(Filter<Symbol> sf) { |
497 public Entry next(Filter<Symbol> sf) { |
498 if (shadowed.sym == null || sf.accepts(shadowed.sym)) return shadowed; |
498 if (shadowed.sym == null || sf.accepts(shadowed.sym)) return shadowed; |
499 else return shadowed.next(sf); |
499 else return shadowed.next(sf); |
500 } |
500 } |
501 |
501 |
|
502 public boolean isStaticallyImported() { |
|
503 return false; |
|
504 } |
|
505 |
502 public Scope getOrigin() { |
506 public Scope getOrigin() { |
503 // The origin is only recorded for import scopes. For all |
507 // The origin is only recorded for import scopes. For all |
504 // other scope entries, the "enclosing" type is available |
508 // other scope entries, the "enclosing" type is available |
505 // from other sources. See Attr.visitSelect and |
509 // from other sources. See Attr.visitSelect and |
506 // Attr.visitIdent. Rather than throwing an assertion |
510 // Attr.visitIdent. Rather than throwing an assertion |
515 public ImportScope(Symbol owner) { |
519 public ImportScope(Symbol owner) { |
516 super(owner); |
520 super(owner); |
517 } |
521 } |
518 |
522 |
519 @Override |
523 @Override |
520 Entry makeEntry(Symbol sym, Entry shadowed, Entry sibling, Scope scope, Scope origin) { |
524 Entry makeEntry(Symbol sym, Entry shadowed, Entry sibling, Scope scope, |
521 return new ImportEntry(sym, shadowed, sibling, scope, origin); |
525 final Scope origin, final boolean staticallyImported) { |
522 } |
526 return new Entry(sym, shadowed, sibling, scope) { |
523 |
527 @Override |
524 static class ImportEntry extends Entry { |
528 public Scope getOrigin() { |
525 private Scope origin; |
529 return origin; |
526 |
530 } |
527 ImportEntry(Symbol sym, Entry shadowed, Entry sibling, Scope scope, Scope origin) { |
531 |
528 super(sym, shadowed, sibling, scope); |
532 @Override |
529 this.origin = origin; |
533 public boolean isStaticallyImported() { |
530 } |
534 return staticallyImported; |
531 |
535 } |
532 @Override |
536 }; |
533 public Scope getOrigin() { return origin; } |
|
534 } |
537 } |
535 } |
538 } |
536 |
539 |
537 public static class StarImportScope extends ImportScope implements ScopeListener { |
540 public static class StarImportScope extends ImportScope implements ScopeListener { |
538 |
541 |
722 public Scope dup(Symbol newOwner) { |
725 public Scope dup(Symbol newOwner) { |
723 throw new UnsupportedOperationException(); |
726 throw new UnsupportedOperationException(); |
724 } |
727 } |
725 |
728 |
726 @Override |
729 @Override |
727 public void enter(Symbol sym, Scope s, Scope origin) { |
730 public void enter(Symbol sym, Scope s, Scope origin, boolean staticallyImported) { |
728 throw new UnsupportedOperationException(); |
731 throw new UnsupportedOperationException(); |
729 } |
732 } |
730 |
733 |
731 @Override |
734 @Override |
732 public void remove(Symbol sym) { |
735 public void remove(Symbol sym) { |