@@ -38,12 +38,12 @@ trait Symbols { this: Context =>
38
38
* Note this uses a cast instead of a direct type refinement because
39
39
* it's debug-friendlier not to create an anonymous class here.
40
40
*/
41
- def newNakedSymbol [N <: Name ](coord : Coord = NoCoord ): Symbol { type ThisName = N } =
42
- new Symbol (coord).asInstanceOf [Symbol { type ThisName = N }]
41
+ def newNakedSymbol [N <: Name ](coord : Coord = NoCoord )( implicit ctx : Context ) : Symbol { type ThisName = N } =
42
+ new Symbol (coord, ctx.nextId ).asInstanceOf [Symbol { type ThisName = N }]
43
43
44
44
/** Create a class symbol without a denotation. */
45
- def newNakedClassSymbol (coord : Coord = NoCoord , assocFile : AbstractFile = null ) =
46
- new ClassSymbol (coord, assocFile)
45
+ def newNakedClassSymbol (coord : Coord = NoCoord , assocFile : AbstractFile = null )( implicit ctx : Context ) =
46
+ new ClassSymbol (coord, assocFile, ctx.nextId )
47
47
48
48
// ---- Symbol creation methods ----------------------------------
49
49
@@ -364,22 +364,16 @@ trait Symbols { this: Context =>
364
364
365
365
object Symbols {
366
366
367
- var _nextId = 0 // !!! DEBUG, use global counter instead
368
- def nextId = { _nextId += 1 ; _nextId }
369
-
370
-
371
367
/** A Symbol represents a Scala definition/declaration or a package.
368
+ * @param coord The coordinates of the symbol (a position or an index)
369
+ * @param id A unique identifier of the symbol (unique per ContextBase)
372
370
*/
373
- class Symbol private [Symbols ] (val coord : Coord ) extends DotClass with printing.Showable {
371
+ class Symbol private [Symbols ] (val coord : Coord , val id : Int ) extends DotClass with printing.Showable {
374
372
375
373
type ThisName <: Name
376
374
377
- private [this ] var _id : Int = nextId
378
375
// assert(_id != 30214)
379
376
380
- /** The unique id of this symbol */
381
- def id = _id
382
-
383
377
/** The last denotation of this symbol */
384
378
private [this ] var lastDenot : SymDenotation = _
385
379
@@ -514,8 +508,8 @@ object Symbols {
514
508
type TermSymbol = Symbol { type ThisName = TermName }
515
509
type TypeSymbol = Symbol { type ThisName = TypeName }
516
510
517
- class ClassSymbol private [Symbols ] (coord : Coord , val assocFile : AbstractFile )
518
- extends Symbol (coord) {
511
+ class ClassSymbol private [Symbols ] (coord : Coord , val assocFile : AbstractFile , id : Int )
512
+ extends Symbol (coord, id ) {
519
513
520
514
type ThisName = TypeName
521
515
@@ -551,12 +545,12 @@ object Symbols {
551
545
override protected def prefixString = " ClassSymbol"
552
546
}
553
547
554
- class ErrorSymbol (val underlying : Symbol , msg : => String )(implicit ctx : Context ) extends Symbol (NoCoord ) {
548
+ class ErrorSymbol (val underlying : Symbol , msg : => String )(implicit ctx : Context ) extends Symbol (NoCoord , ctx.nextId ) {
555
549
type ThisName = underlying.ThisName
556
550
denot = underlying.denot
557
551
}
558
552
559
- object NoSymbol extends Symbol (NoCoord ) {
553
+ @ sharable object NoSymbol extends Symbol (NoCoord , 0 ) {
560
554
denot = NoDenotation
561
555
562
556
override def associatedFile (implicit ctx : Context ): AbstractFile = NoSource .file
@@ -590,5 +584,5 @@ object Symbols {
590
584
/** The current class */
591
585
def currentClass (implicit ctx : Context ): ClassSymbol = ctx.owner.enclosingClass.asClass
592
586
593
- var stubs : List [Symbol ] = Nil // diagnostic
587
+ @ sharable var stubs : List [Symbol ] = Nil // diagnostic only
594
588
}
0 commit comments