From 3db933967d05b4a06c275462d4f07b61db9a462f Mon Sep 17 00:00:00 2001 From: paltherr Date: Tue, 6 May 2003 11:01:56 +0000 Subject: - Added method contains - Added second method iterator - Added assert in method enter to prevent entering two symbols with the same name --- sources/scalac/symtab/Scope.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'sources/scalac') diff --git a/sources/scalac/symtab/Scope.java b/sources/scalac/symtab/Scope.java index f1fa915c55..c205342011 100644 --- a/sources/scalac/symtab/Scope.java +++ b/sources/scalac/symtab/Scope.java @@ -178,11 +178,25 @@ public class Scope { /** enter a symbol */ public Scope enter(Symbol sym) { + assert lookupEntry(sym.name).owner != this : Debug.show(sym); return enter(new Entry(sym, this)); } public Scope enterOrOverload(Symbol sym) { Entry e = lookupEntry(sym.name); + /* !!! + if (e == Entry.NONE) { + return enter(sym); + } else { + sym = e.sym.overloadWith(sym); + if (e.owner == this) { + e.setSymbol(sym); + return this; + } else { + return enter(new Entry(sym, this)); + } + } + */ if (e.owner == this && (sym.flags & Modifiers.PRIVATE) == 0) { e.setSymbol(e.sym.overloadWith(sym)); return this; @@ -229,6 +243,17 @@ public class Scope { elemsCache = null; } + public boolean contains(Symbol sym) { + Entry e = lookupEntry(sym.name); + if (e.sym == sym) return true; + switch (e.sym.type()) { + case OverloadedType(Symbol[] alts, _): + for (int i = 0; i < alts.length; i++) + if (alts[i] == sym) return true; + } + return false; + } + /** lookup a symbol */ public Symbol lookup(Name name) { @@ -267,6 +292,11 @@ public class Scope { */ public SymbolIterator iterator() { return new MySymbols(); } + public SymbolIterator iterator(boolean unload) { + SymbolIterator iterator = iterator(); + return unload ? new UnloadIterator(iterator) : iterator; + } + class MySymbols extends SymbolIterator { private int index; -- cgit v1.2.3