@@ -29,7 +29,7 @@ object Scopes {
29
29
*/
30
30
private final val MaxRecursions = 1000
31
31
32
- class ScopeEntry private [Scopes ] (val sym : Symbol , val owner : Scope ) {
32
+ final class ScopeEntry private [Scopes ] (val sym : Symbol , val owner : Scope ) {
33
33
34
34
/** the next entry in the hash bucket
35
35
*/
@@ -46,7 +46,7 @@ object Scopes {
46
46
* This is necessary because when run from reflection every scope needs to have a
47
47
* SynchronizedScope as mixin.
48
48
*/
49
- class Scope protected [Scopes ](initElems : ScopeEntry , initSize : Int , val nestingLevel : Int = 0 )
49
+ sealed class Scope protected [Scopes ](initElems : ScopeEntry , initSize : Int , val nestingLevel : Int = 0 )
50
50
extends Iterable [Symbol ] {
51
51
52
52
protected [Scopes ] def this (base : Scope )(implicit ctx : Context ) = {
@@ -56,12 +56,12 @@ object Scopes {
56
56
57
57
def this () = this (null , 0 , 0 )
58
58
59
- private [dotc] var lastEntry : ScopeEntry = initElems
59
+ private [dotc] final var lastEntry : ScopeEntry = initElems
60
60
61
61
/** The size of the scope */
62
62
private [this ] var _size = initSize
63
63
64
- override def size = _size
64
+ override final def size = _size
65
65
private def size_= (x : Int ) = _size = x
66
66
67
67
/** the hash table
@@ -73,10 +73,10 @@ object Scopes {
73
73
private var elemsCache : List [Symbol ] = null
74
74
75
75
/** Returns a new scope with the same content as this one. */
76
- def cloneScope (implicit ctx : Context ): Scope = newScopeWith(this .toList: _* )
76
+ final def cloneScope (implicit ctx : Context ): Scope = newScopeWith(this .toList: _* )
77
77
78
78
/** is the scope empty? */
79
- override def isEmpty : Boolean = lastEntry eq null
79
+ override final def isEmpty : Boolean = lastEntry eq null
80
80
81
81
/** create and enter a scope entry */
82
82
protected def newScopeEntry (sym : Symbol )(implicit ctx : Context ): ScopeEntry = {
@@ -94,7 +94,7 @@ object Scopes {
94
94
e
95
95
}
96
96
97
- private def enterInHash (e : ScopeEntry )(implicit ctx : Context ): Unit = {
97
+ private final def enterInHash (e : ScopeEntry )(implicit ctx : Context ): Unit = {
98
98
val i = e.sym.name.start & (hashTable.length - 1 )
99
99
e.tail = hashTable(i)
100
100
hashTable(i) = e
@@ -104,7 +104,7 @@ object Scopes {
104
104
*
105
105
* @param sym ...
106
106
*/
107
- def enter [T <: Symbol ](sym : T )(implicit ctx : Context ): T = {
107
+ final def enter [T <: Symbol ](sym : T )(implicit ctx : Context ): T = {
108
108
newScopeEntry(sym)
109
109
sym
110
110
}
@@ -113,7 +113,7 @@ object Scopes {
113
113
*
114
114
* @param sym ...
115
115
*/
116
- def enterUnique (sym : Symbol )(implicit ctx : Context ) {
116
+ final def enterUnique (sym : Symbol )(implicit ctx : Context ) {
117
117
assert(lookup(sym.name) == NoSymbol , (sym.showLocated, lookup(sym.name).showLocated))
118
118
enter(sym)
119
119
}
@@ -146,7 +146,7 @@ object Scopes {
146
146
}
147
147
148
148
/** remove entry from this scope. */
149
- def unlink (e : ScopeEntry )(implicit ctx : Context ) {
149
+ final def unlink (e : ScopeEntry )(implicit ctx : Context ) {
150
150
if (lastEntry == e) {
151
151
lastEntry = e.prev
152
152
} else {
@@ -169,7 +169,7 @@ object Scopes {
169
169
}
170
170
171
171
/** remove symbol from this scope */
172
- def unlink (sym : Symbol )(implicit ctx : Context ) {
172
+ final def unlink (sym : Symbol )(implicit ctx : Context ) {
173
173
var e = lookupEntry(sym.name)
174
174
while (e ne null ) {
175
175
if (e.sym == sym) unlink(e);
@@ -182,21 +182,21 @@ object Scopes {
182
182
* @param name ...
183
183
* @return ...
184
184
*/
185
- def lookup (name : Name )(implicit ctx : Context ): Symbol = {
185
+ final def lookup (name : Name )(implicit ctx : Context ): Symbol = {
186
186
val e = lookupEntry(name)
187
187
if (e eq null ) NoSymbol else e.sym
188
188
}
189
189
190
190
/** Returns an iterator yielding every symbol with given name in this scope.
191
191
*/
192
- def lookupAll (name : Name )(implicit ctx : Context ): Iterator [Symbol ] = new Iterator [Symbol ] {
192
+ final def lookupAll (name : Name )(implicit ctx : Context ): Iterator [Symbol ] = new Iterator [Symbol ] {
193
193
var e = lookupEntry(name)
194
194
def hasNext : Boolean = e ne null
195
195
def next (): Symbol = { val r = e.sym; e = lookupNextEntry(e); r }
196
196
}
197
197
198
198
/** The denotation set of all the symbols with given name in this scope */
199
- def denotsNamed (name : Name )(implicit ctx : Context ): DenotationSet = {
199
+ final def denotsNamed (name : Name )(implicit ctx : Context ): DenotationSet = {
200
200
var syms : DenotationSet = NoDenotation
201
201
var e = lookupEntry(name)
202
202
while (e != null ) {
@@ -211,7 +211,7 @@ object Scopes {
211
211
* in future versions of the type system. I have reverted the previous
212
212
* change to use iterators as too costly.
213
213
*/
214
- def lookupEntry (name : Name )(implicit ctx : Context ): ScopeEntry = {
214
+ final def lookupEntry (name : Name )(implicit ctx : Context ): ScopeEntry = {
215
215
var e : ScopeEntry = null
216
216
if (hashTable ne null ) {
217
217
e = hashTable(name.start & (hashTable.length - 1 ))
@@ -228,7 +228,7 @@ object Scopes {
228
228
}
229
229
230
230
/** lookup next entry with same name as this one */
231
- def lookupNextEntry (entry : ScopeEntry )(implicit ctx : Context ): ScopeEntry = {
231
+ final def lookupNextEntry (entry : ScopeEntry )(implicit ctx : Context ): ScopeEntry = {
232
232
var e = entry
233
233
if (hashTable ne null )
234
234
do { e = e.tail } while ((e ne null ) && e.sym.name != entry.sym.name)
@@ -239,7 +239,7 @@ object Scopes {
239
239
240
240
/** Return all symbols as a list in the order they were entered in this scope.
241
241
*/
242
- override def toList : List [Symbol ] = {
242
+ override final def toList : List [Symbol ] = {
243
243
if (elemsCache eq null ) {
244
244
elemsCache = Nil
245
245
var e = lastEntry
@@ -253,22 +253,22 @@ object Scopes {
253
253
254
254
/** Vanilla scope - symbols are stored in declaration order.
255
255
*/
256
- def sorted : List [Symbol ] = toList
256
+ final def sorted : List [Symbol ] = toList
257
257
258
258
/** Return all symbols as an iterator in the order they were entered in this scope.
259
259
*/
260
- def iterator : Iterator [Symbol ] = toList.iterator
260
+ final def iterator : Iterator [Symbol ] = toList.iterator
261
261
262
- override def foreach [U ](p : Symbol => U ): Unit = toList foreach p
262
+ override final def foreach [U ](p : Symbol => U ): Unit = toList foreach p
263
263
264
- def filteredScope (p : Symbol => Boolean )(implicit ctx : Context ): Scope = {
264
+ final def filteredScope (p : Symbol => Boolean )(implicit ctx : Context ): Scope = {
265
265
val unfiltered = toList
266
266
val filtered = unfiltered filterConserve p
267
267
if (filtered eq unfiltered) this
268
268
else newScopeWith(filtered : _* )
269
269
}
270
270
271
- def show (implicit ctx : Context ): String = ctx.show(this )
271
+ final def show (implicit ctx : Context ): String = ctx.show(this )
272
272
}
273
273
274
274
/** Create a new scope */
@@ -302,5 +302,5 @@ object Scopes {
302
302
303
303
/** The error scope (mutable)
304
304
*/
305
- class ErrorScope (owner : Symbol ) extends Scope
305
+ final class ErrorScope (owner : Symbol ) extends Scope
306
306
}
0 commit comments