@@ -108,6 +108,7 @@ object Symbols:
108
108
def asType (using Context ): TypeSymbol
109
109
110
110
def isClass : Boolean
111
+ @ targetName(" Symbol_asClass" )
111
112
def asClass : ClassSymbol
112
113
113
114
def isPrivate (using Context ): Boolean
@@ -179,8 +180,17 @@ object Symbols:
179
180
* @param coord The coordinates of the symbol (a position or an index)
180
181
* @param id A unique identifier of the symbol (unique per ContextBase)
181
182
*/
182
- class SymbolImpl private [Symbols ] (private var myCoord : Coord , val id : Int )
183
- extends SymbolDecl {
183
+ class SymbolImpl private [Symbols ] (
184
+ maybeOwner : SymbolImpl ,
185
+ name : Name ,
186
+ initFlags : FlagSet ,
187
+ initInfo : Type ,
188
+ initPrivateWithin : SymbolImpl ,
189
+ private var myCoord : Coord ,
190
+ val id : Int )
191
+ extends
192
+ SymDenotation (null , maybeOwner, name, initFlags, initInfo, initPrivateWithin),
193
+ SymbolDecl {
184
194
185
195
type ThisName <: Name
186
196
@@ -234,6 +244,8 @@ object Symbols:
234
244
checkedPeriod = Nowhere
235
245
}
236
246
247
+ denot = this
248
+
237
249
/** The current denotation of this symbol */
238
250
final def denot (using Context ): SymDenotation = {
239
251
util.Stats .record(" Symbol.denot" )
@@ -305,9 +317,8 @@ object Symbols:
305
317
asInstanceOf [TypeSymbol ]
306
318
}
307
319
308
- final def isClass : Boolean = isInstanceOf [ClassSymbol @ unchecked]
309
-
310
- final def asClass : ClassSymbol = asInstanceOf [ClassSymbol ]
320
+ @ targetName(" Symbol_asClass" )
321
+ override def asClass : ClassSymbol = asInstanceOf [ClassSymbol ]
311
322
312
323
/** Test whether symbol is private. This
313
324
* conservatively returns `false` if symbol does not yet have a denotation, or denotation
@@ -324,15 +335,14 @@ object Symbols:
324
335
! isClass && this .is(Case , butNot = Enum | Module )
325
336
326
337
/** The symbol's signature if it is completed or a method, NotAMethod otherwise. */
327
- final def signature (using Context ): Signature =
328
- if (lastDenot != null && (lastDenot.isCompleted || lastDenot.is(Method )))
329
- denot.signature
330
- else
331
- Signature .NotAMethod
332
-
338
+ final override def signature (using Context ): Signature =
339
+ if denot eq this then super .signature
340
+ else denot.signature
341
+ /*
333
342
/** Special cased here, because it may be used on naked symbols in substituters */
334
343
final def isStatic(using Context): Boolean =
335
344
lastDenot != null && lastDenot.initial.isStatic
345
+ */
336
346
337
347
/** This symbol entered into owner's scope (owner must be a class). */
338
348
final def entered (using Context ): this .type = {
@@ -387,16 +397,15 @@ object Symbols:
387
397
def filter (p : Symbol => Boolean ): Symbol = if (p(this .fromSymbolImpl)) this .fromSymbolImpl else NoSymbol
388
398
389
399
/** The current name of this symbol */
390
- final def name (using Context ): ThisName = denot.name.asInstanceOf [ThisName ]
400
+ override def name (using Context ): ThisName = denot.name.asInstanceOf [ThisName ]
391
401
392
402
/** The source or class file from which this class or
393
403
* the class containing this symbol was generated, null if not applicable.
394
404
* Note that this the returned classfile might be the top-level class
395
405
* containing this symbol instead of the directly enclosing class.
396
406
* Overridden in ClassSymbol
397
407
*/
398
- def associatedFile (using Context ): AbstractFile =
399
- if (lastDenot == null ) null else lastDenot.topLevelClass.associatedFile
408
+ def associatedFile (using Context ): AbstractFile = topLevelClass.associatedFile
400
409
401
410
/** The class file from which this class was generated, null if not applicable. */
402
411
final def binaryFile (using Context ): AbstractFile = {
@@ -485,22 +494,33 @@ object Symbols:
485
494
486
495
override def toString : String =
487
496
if (lastDenot == null ) s " Naked $prefixString# $id"
488
- else lastDenot.toString // + "#" + id // !!! DEBUG
497
+ else lastDenot.denotString // + "#" + id // !!! DEBUG
489
498
490
- def toText (printer : Printer ): Text = printer.toText(this .fromSymbolImpl)
499
+ override def toText (printer : Printer ): Text = printer.toText(this .fromSymbolImpl)
491
500
492
501
def showLocated (using Context ): String = ctx.printer.locatedText(this .fromSymbolImpl).show
493
502
def showExtendedLocation (using Context ): String = ctx.printer.extendedLocationText(this .fromSymbolImpl).show
494
- def showDcl (using Context ): String = ctx.printer.dclText(this .fromSymbolImpl).show
503
+ override def showDcl (using Context ): String = ctx.printer.dclText(this .fromSymbolImpl).show
495
504
def showKind (using Context ): String = ctx.printer.kindString(this .fromSymbolImpl)
496
505
def showName (using Context ): String = ctx.printer.nameString(this .fromSymbolImpl)
497
506
def showFullName (using Context ): String = ctx.printer.fullNameString(this .fromSymbolImpl)
498
507
499
508
override def hashCode (): Int = id // for debugging.
500
509
}
501
510
502
- class ClassSymbolImpl private [Symbols ] (coord : Coord , val assocFile : AbstractFile , id : Int )
503
- extends SymbolImpl (coord, id), ClassSymbolDecl {
511
+ class ClassSymbolImpl private [Symbols ] (
512
+ maybeOwner : SymbolImpl ,
513
+ name : Name ,
514
+ initFlags : FlagSet ,
515
+ initInfo : Type ,
516
+ initPrivateWithin : SymbolImpl ,
517
+ initCoord : Coord ,
518
+ val assocFile : AbstractFile ,
519
+ id : Int )
520
+ extends SymbolImpl (
521
+ maybeOwner, name, initFlags, initInfo, initPrivateWithin, initCoord, id),
522
+ ClassSymbolDecl ,
523
+ ClassDenotation {
504
524
505
525
type ThisName = TypeName
506
526
@@ -591,14 +611,44 @@ object Symbols:
591
611
}
592
612
593
613
/** Kept separate since it keeps only PackageClassDenotation */
594
- class PackageClassSymbolImpl (id : Int ) extends ClassSymbolImpl (NoCoord , null , id)
614
+ class PackageClassSymbolImpl private [Symbols ] (
615
+ maybeOwner : SymbolImpl ,
616
+ name : Name ,
617
+ initFlags : FlagSet ,
618
+ initInfo : Type ,
619
+ initPrivateWithin : SymbolImpl ,
620
+ id : Int )
621
+ extends ClassSymbolImpl (
622
+ maybeOwner, name, initFlags, initInfo, initPrivateWithin, NoCoord , null , id),
623
+ PackageClassDenotation
595
624
596
625
@ sharable
597
- val NoSymbol : Symbol = new SymbolImpl (NoCoord , 0 ) {
598
- override def associatedFile (using Context ): AbstractFile = NoSource .file
599
- override def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation = NoDenotation
600
- }.fromSymbolImpl
601
- NoDenotation // force it in order to set `denot` field of NoSymbol
626
+ val NoSymbol : Symbol = new SymbolImpl (
627
+ null , " <none>" .toTermName, Permanent , NoType , null , NoCoord , 0 ):
628
+
629
+ override def isType : Boolean = false
630
+ override def isTerm : Boolean = false
631
+ override def exists : Boolean = false
632
+ override def owner : Symbol = throw new AssertionError (" NoDenotation.owner" )
633
+ override def computeAsSeenFrom (pre : Type )(using Context ): SingleDenotation = this
634
+ override def mapInfo (f : Type => Type )(using Context ): SingleDenotation = this
635
+
636
+ override def matches (other : SingleDenotation )(using Context ): Boolean = false
637
+ override def targetName (using Context ): Name = EmptyTermName
638
+ override def mapInherited (ownDenots : PreDenotation , prevDenots : PreDenotation , pre : Type )(using Context ): SingleDenotation = this
639
+ override def filterWithPredicate (p : SingleDenotation => Boolean ): SingleDenotation = this
640
+ override def filterDisjoint (denots : PreDenotation )(using Context ): SingleDenotation = this
641
+ override def filterWithFlags (required : FlagSet , excluded : FlagSet )(using Context ): SingleDenotation = this
642
+
643
+ validFor = Period .allInRun(NoRunId )
644
+
645
+ override def associatedFile (using Context ): AbstractFile = NoSource .file
646
+
647
+ override def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation =
648
+ NoDenotation
649
+ .fromSymbolImpl
650
+
651
+ // NoDenotation // force it in order to set `denot` field of NoSymbol
602
652
603
653
extension [N <: Name ](sym : Symbol { type ThisName = N })(using Context ) {
604
654
/** Copy a symbol, overriding selective fields.
@@ -653,12 +703,11 @@ object Symbols:
653
703
flags : FlagSet ,
654
704
info : Type ,
655
705
privateWithin : Symbol = NoSymbol ,
656
- coord : Coord = NoCoord )(using Context ): Symbol { type ThisName = N } = {
657
- val sym = new SymbolImpl (coord, ctx.base.nextSymId).asInstanceOf [Symbol { type ThisName = N }]
658
- val denot = SymDenotation (sym, owner, name, flags, info, privateWithin)
659
- sym.denot = denot
660
- sym
661
- }
706
+ coord : Coord = NoCoord )(using Context ): Symbol { type ThisName = N } =
707
+ val symi = new SymbolImpl (
708
+ owner.toSymbolImpl, name, flags, info, privateWithin.toSymbolImpl, coord, ctx.base.nextSymId)
709
+ symi.validFor = currentStablePeriod
710
+ symi.asInstanceOf [Symbol { type ThisName = N }]
662
711
663
712
/** Create a class symbol from its non-info fields and a function
664
713
* producing its info (the produced info may be lazy).
@@ -670,18 +719,18 @@ object Symbols:
670
719
infoFn : ClassSymbol => Type ,
671
720
privateWithin : Symbol = NoSymbol ,
672
721
coord : Coord = NoCoord ,
673
- assocFile : AbstractFile = null )(using Context ): ClassSymbol
674
- = {
675
- val cls = (
722
+ assocFile : AbstractFile = null )(using Context ): ClassSymbol =
723
+ val clsi =
676
724
if flags.is(Package ) then
677
- new PackageClassSymbolImpl (ctx.base.nextSymId)
725
+ new PackageClassSymbolImpl (
726
+ owner.toSymbolImpl, name, flags, NoCompleter , privateWithin.toSymbolImpl, ctx.base.nextSymId)
678
727
else
679
- new ClassSymbolImpl (coord, assocFile, ctx.base.nextSymId)
680
- ).fromSymbolImpl.asClass
681
- val denot = SymDenotation (cls, owner, name, flags, infoFn(cls), privateWithin)
682
- cls.denot = denot
728
+ new ClassSymbolImpl (
729
+ owner.toSymbolImpl, name, flags, NoCompleter , privateWithin.toSymbolImpl, coord, assocFile, ctx.base.nextSymId)
730
+ clsi.validFor = currentStablePeriod
731
+ val cls = clsi.fromSymbolImpl.asClass
732
+ cls.info = infoFn(cls)
683
733
cls
684
- }
685
734
686
735
/** Create a class symbol from its non-info fields and the fields of its info. */
687
736
def newCompleteClassSymbol (
0 commit comments