Skip to content

Commit 373ab8c

Browse files
committed
More modifier lock down in Scopes.
1 parent 545e2be commit 373ab8c

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/dotty/tools/dotc/core/Scopes.scala

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object Scopes {
2929
*/
3030
private final val MaxRecursions = 1000
3131

32-
class ScopeEntry private[Scopes] (val sym: Symbol, val owner: Scope) {
32+
final class ScopeEntry private[Scopes] (val sym: Symbol, val owner: Scope) {
3333

3434
/** the next entry in the hash bucket
3535
*/
@@ -46,7 +46,7 @@ object Scopes {
4646
* This is necessary because when run from reflection every scope needs to have a
4747
* SynchronizedScope as mixin.
4848
*/
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)
5050
extends Iterable[Symbol] {
5151

5252
protected[Scopes] def this(base: Scope)(implicit ctx: Context) = {
@@ -56,12 +56,12 @@ object Scopes {
5656

5757
def this() = this(null, 0, 0)
5858

59-
private[dotc] var lastEntry: ScopeEntry = initElems
59+
private[dotc] final var lastEntry: ScopeEntry = initElems
6060

6161
/** The size of the scope */
6262
private[this] var _size = initSize
6363

64-
override def size = _size
64+
override final def size = _size
6565
private def size_= (x: Int) = _size = x
6666

6767
/** the hash table
@@ -73,10 +73,10 @@ object Scopes {
7373
private var elemsCache: List[Symbol] = null
7474

7575
/** 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: _*)
7777

7878
/** is the scope empty? */
79-
override def isEmpty: Boolean = lastEntry eq null
79+
override final def isEmpty: Boolean = lastEntry eq null
8080

8181
/** create and enter a scope entry */
8282
protected def newScopeEntry(sym: Symbol)(implicit ctx: Context): ScopeEntry = {
@@ -94,7 +94,7 @@ object Scopes {
9494
e
9595
}
9696

97-
private def enterInHash(e: ScopeEntry)(implicit ctx: Context): Unit = {
97+
private final def enterInHash(e: ScopeEntry)(implicit ctx: Context): Unit = {
9898
val i = e.sym.name.start & (hashTable.length - 1)
9999
e.tail = hashTable(i)
100100
hashTable(i) = e
@@ -104,7 +104,7 @@ object Scopes {
104104
*
105105
* @param sym ...
106106
*/
107-
def enter[T <: Symbol](sym: T)(implicit ctx: Context): T = {
107+
final def enter[T <: Symbol](sym: T)(implicit ctx: Context): T = {
108108
newScopeEntry(sym)
109109
sym
110110
}
@@ -113,7 +113,7 @@ object Scopes {
113113
*
114114
* @param sym ...
115115
*/
116-
def enterUnique(sym: Symbol)(implicit ctx: Context) {
116+
final def enterUnique(sym: Symbol)(implicit ctx: Context) {
117117
assert(lookup(sym.name) == NoSymbol, (sym.showLocated, lookup(sym.name).showLocated))
118118
enter(sym)
119119
}
@@ -146,7 +146,7 @@ object Scopes {
146146
}
147147

148148
/** remove entry from this scope. */
149-
def unlink(e: ScopeEntry)(implicit ctx: Context) {
149+
final def unlink(e: ScopeEntry)(implicit ctx: Context) {
150150
if (lastEntry == e) {
151151
lastEntry = e.prev
152152
} else {
@@ -169,7 +169,7 @@ object Scopes {
169169
}
170170

171171
/** remove symbol from this scope */
172-
def unlink(sym: Symbol)(implicit ctx: Context) {
172+
final def unlink(sym: Symbol)(implicit ctx: Context) {
173173
var e = lookupEntry(sym.name)
174174
while (e ne null) {
175175
if (e.sym == sym) unlink(e);
@@ -182,21 +182,21 @@ object Scopes {
182182
* @param name ...
183183
* @return ...
184184
*/
185-
def lookup(name: Name)(implicit ctx: Context): Symbol = {
185+
final def lookup(name: Name)(implicit ctx: Context): Symbol = {
186186
val e = lookupEntry(name)
187187
if (e eq null) NoSymbol else e.sym
188188
}
189189

190190
/** Returns an iterator yielding every symbol with given name in this scope.
191191
*/
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] {
193193
var e = lookupEntry(name)
194194
def hasNext: Boolean = e ne null
195195
def next(): Symbol = { val r = e.sym; e = lookupNextEntry(e); r }
196196
}
197197

198198
/** 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 = {
200200
var syms: DenotationSet = NoDenotation
201201
var e = lookupEntry(name)
202202
while (e != null) {
@@ -211,7 +211,7 @@ object Scopes {
211211
* in future versions of the type system. I have reverted the previous
212212
* change to use iterators as too costly.
213213
*/
214-
def lookupEntry(name: Name)(implicit ctx: Context): ScopeEntry = {
214+
final def lookupEntry(name: Name)(implicit ctx: Context): ScopeEntry = {
215215
var e: ScopeEntry = null
216216
if (hashTable ne null) {
217217
e = hashTable(name.start & (hashTable.length - 1))
@@ -228,7 +228,7 @@ object Scopes {
228228
}
229229

230230
/** 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 = {
232232
var e = entry
233233
if (hashTable ne null)
234234
do { e = e.tail } while ((e ne null) && e.sym.name != entry.sym.name)
@@ -239,7 +239,7 @@ object Scopes {
239239

240240
/** Return all symbols as a list in the order they were entered in this scope.
241241
*/
242-
override def toList: List[Symbol] = {
242+
override final def toList: List[Symbol] = {
243243
if (elemsCache eq null) {
244244
elemsCache = Nil
245245
var e = lastEntry
@@ -253,22 +253,22 @@ object Scopes {
253253

254254
/** Vanilla scope - symbols are stored in declaration order.
255255
*/
256-
def sorted: List[Symbol] = toList
256+
final def sorted: List[Symbol] = toList
257257

258258
/** Return all symbols as an iterator in the order they were entered in this scope.
259259
*/
260-
def iterator: Iterator[Symbol] = toList.iterator
260+
final def iterator: Iterator[Symbol] = toList.iterator
261261

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
263263

264-
def filteredScope(p: Symbol => Boolean)(implicit ctx: Context): Scope = {
264+
final def filteredScope(p: Symbol => Boolean)(implicit ctx: Context): Scope = {
265265
val unfiltered = toList
266266
val filtered = unfiltered filterConserve p
267267
if (filtered eq unfiltered) this
268268
else newScopeWith(filtered: _*)
269269
}
270270

271-
def show(implicit ctx: Context): String = ctx.show(this)
271+
final def show(implicit ctx: Context): String = ctx.show(this)
272272
}
273273

274274
/** Create a new scope */
@@ -302,5 +302,5 @@ object Scopes {
302302

303303
/** The error scope (mutable)
304304
*/
305-
class ErrorScope(owner: Symbol) extends Scope
305+
final class ErrorScope(owner: Symbol) extends Scope
306306
}

0 commit comments

Comments
 (0)