@@ -144,6 +144,11 @@ object Scopes {
144144 final def toText (printer : Printer ): Text = printer.toText(this )
145145
146146 def checkConsistent ()(implicit ctx : Context ) = ()
147+
148+ /** Hook for transforming a name before it is used in a lookup or creation.
149+ * Used to mangle names in package scopes.
150+ */
151+ protected def normalize (name : Name ): Name = name
147152 }
148153
149154 /** A subclass of Scope that defines methods for entering and
@@ -155,6 +160,7 @@ object Scopes {
155160 class MutableScope protected [Scopes ](initElems : ScopeEntry , initSize : Int , val nestingLevel : Int = 0 )
156161 extends Scope {
157162
163+ /** Scope shares elements with `base` */
158164 protected [Scopes ] def this (base : Scope )(implicit ctx : Context ) = {
159165 this (base.lastEntry, base.size, base.nestingLevel + 1 )
160166 ensureCapacity(MinHash )(ctx) // WTH? it seems the implicit is not in scope for a secondary constructor call.
@@ -178,6 +184,8 @@ object Scopes {
178184 */
179185 private var elemsCache : List [Symbol ] = null
180186
187+ protected def newScopeLikeThis () = new MutableScope ()
188+
181189 /** Clone scope, taking care not to force the denotations of any symbols in the scope.
182190 */
183191 def cloneScope (implicit ctx : Context ): MutableScope = {
@@ -187,7 +195,7 @@ object Scopes {
187195 entries += e
188196 e = e.prev
189197 }
190- val scope = newScope
198+ val scope = newScopeLikeThis()
191199 for (i <- entries.length - 1 to 0 by - 1 ) {
192200 val e = entries(i)
193201 scope.newScopeEntry(e.name, e.sym)
@@ -198,7 +206,7 @@ object Scopes {
198206 /** create and enter a scope entry with given name and symbol */
199207 protected def newScopeEntry (name : Name , sym : Symbol )(implicit ctx : Context ): ScopeEntry = {
200208 ensureCapacity(if (hashTable ne null ) hashTable.length else MinHash )
201- val e = new ScopeEntry (name, sym, this )
209+ val e = new ScopeEntry (normalize( name) , sym, this )
202210 e.prev = lastEntry
203211 lastEntry = e
204212 if (hashTable ne null ) enterInHash(e)
@@ -234,7 +242,7 @@ object Scopes {
234242 enter(sym)
235243 }
236244
237- private def ensureCapacity (tableSize : Int )(implicit ctx : Context ): Unit =
245+ protected def ensureCapacity (tableSize : Int )(implicit ctx : Context ): Unit =
238246 if (size >= tableSize * FillFactor ) createHash(tableSize * 2 )
239247
240248 private def createHash (tableSize : Int )(implicit ctx : Context ): Unit =
@@ -310,15 +318,16 @@ object Scopes {
310318 /** Lookup a symbol entry matching given name.
311319 */
312320 override def lookupEntry (name : Name )(implicit ctx : Context ): ScopeEntry = {
321+ val normalized = normalize(name)
313322 var e : ScopeEntry = null
314323 if (hashTable ne null ) {
315- e = hashTable(name .hashCode & (hashTable.length - 1 ))
316- while ((e ne null ) && e.name != name ) {
324+ e = hashTable(normalized .hashCode & (hashTable.length - 1 ))
325+ while ((e ne null ) && e.name != normalized ) {
317326 e = e.tail
318327 }
319328 } else {
320329 e = lastEntry
321- while ((e ne null ) && e.name != name ) {
330+ while ((e ne null ) && e.name != normalized ) {
322331 e = e.prev
323332 }
324333 }
@@ -394,12 +403,23 @@ object Scopes {
394403 }
395404 }
396405
397- class PackageScope extends MutableScope {
398- override final def newScopeEntry (name : Name , sym : Symbol )(implicit ctx : Context ): ScopeEntry =
399- super .newScopeEntry(name.mangled, sym)
406+ /** The scope of a package. This is different from a normal scope
407+ * in that names of scope entries are kept in mangled form.
408+ */
409+ class PackageScope protected [Scopes ](initElems : ScopeEntry , initSize : Int , nestingLevel : Int )
410+ extends MutableScope (initElems, initSize, nestingLevel) {
411+
412+ /** Scope shares elements with `base` */
413+ def this (base : Scope )(implicit ctx : Context ) = {
414+ this (base.lastEntry, base.size, base.nestingLevel + 1 )
415+ ensureCapacity(MinHash )(ctx) // WTH? it seems the implicit is not in scope for a secondary constructor call.
416+ }
417+
418+ def this () = this (null , 0 , 0 )
419+
420+ override def newScopeLikeThis () = new PackageScope ()
400421
401- override final def lookupEntry (name : Name )(implicit ctx : Context ): ScopeEntry =
402- super .lookupEntry(name.mangled)
422+ override protected def normalize (name : Name ) = name.mangled
403423 }
404424
405425 /** Create a new scope */
0 commit comments