@@ -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
@@ -116,7 +117,6 @@ object Symbols:
116
117
def isStatic (using Context ): Boolean
117
118
118
119
def symName (using Context ): ThisName
119
- def signature (using Context ): Signature
120
120
121
121
def span : Span
122
122
def sourcePos (using Context ): SourcePosition
@@ -179,8 +179,17 @@ object Symbols:
179
179
* @param coord The coordinates of the symbol (a position or an index)
180
180
* @param id A unique identifier of the symbol (unique per ContextBase)
181
181
*/
182
- class SymbolImpl private [Symbols ] (private var myCoord : Coord , val id : Int )
183
- extends SymbolDecl {
182
+ class SymbolImpl private [Symbols ] (
183
+ maybeOwner : SymbolImpl ,
184
+ name : Name ,
185
+ initFlags : FlagSet ,
186
+ initInfo : Type ,
187
+ initPrivateWithin : SymbolImpl ,
188
+ private var myCoord : Coord ,
189
+ val id : Int )
190
+ extends
191
+ SymDenotation (null , maybeOwner, name, initFlags, initInfo, initPrivateWithin),
192
+ SymbolDecl {
184
193
185
194
type ThisName <: Name
186
195
@@ -234,6 +243,8 @@ object Symbols:
234
243
checkedPeriod = Nowhere
235
244
}
236
245
246
+ denot = this
247
+
237
248
/** The current denotation of this symbol */
238
249
final def denot (using Context ): SymDenotation = {
239
250
util.Stats .record(" Symbol.denot" )
@@ -305,9 +316,8 @@ object Symbols:
305
316
asInstanceOf [TypeSymbol ]
306
317
}
307
318
308
- final def isClass : Boolean = isInstanceOf [ClassSymbol @ unchecked]
309
-
310
- final def asClass : ClassSymbol = asInstanceOf [ClassSymbol ]
319
+ @ targetName(" Symbol_asClass" )
320
+ override def asClass : ClassSymbol = asInstanceOf [ClassSymbol ]
311
321
312
322
/** Test whether symbol is private. This
313
323
* conservatively returns `false` if symbol does not yet have a denotation, or denotation
@@ -323,17 +333,6 @@ object Symbols:
323
333
final def isPatternBound (using Context ): Boolean =
324
334
! isClass && this .is(Case , butNot = Enum | Module )
325
335
326
- /** 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
-
333
- /** Special cased here, because it may be used on naked symbols in substituters */
334
- final def isStatic (using Context ): Boolean =
335
- lastDenot != null && lastDenot.initial.isStatic
336
-
337
336
/** This symbol entered into owner's scope (owner must be a class). */
338
337
final def entered (using Context ): this .type = {
339
338
if (this .owner.isClass) {
@@ -395,8 +394,7 @@ object Symbols:
395
394
* containing this symbol instead of the directly enclosing class.
396
395
* Overridden in ClassSymbol
397
396
*/
398
- def associatedFile (using Context ): AbstractFile =
399
- if (lastDenot == null ) null else lastDenot.topLevelClass.associatedFile
397
+ def associatedFile (using Context ): AbstractFile = topLevelClass.associatedFile
400
398
401
399
/** The class file from which this class was generated, null if not applicable. */
402
400
final def binaryFile (using Context ): AbstractFile = {
@@ -485,22 +483,33 @@ object Symbols:
485
483
486
484
override def toString : String =
487
485
if (lastDenot == null ) s " Naked $prefixString# $id"
488
- else lastDenot.toString // + "#" + id // !!! DEBUG
486
+ else lastDenot.denotString // + "#" + id // !!! DEBUG
489
487
490
- def toText (printer : Printer ): Text = printer.toText(this .fromSymbolImpl)
488
+ override def toText (printer : Printer ): Text = printer.toText(this .fromSymbolImpl)
491
489
492
490
def showLocated (using Context ): String = ctx.printer.locatedText(this .fromSymbolImpl).show
493
491
def showExtendedLocation (using Context ): String = ctx.printer.extendedLocationText(this .fromSymbolImpl).show
494
- def showDcl (using Context ): String = ctx.printer.dclText(this .fromSymbolImpl).show
492
+ override def showDcl (using Context ): String = ctx.printer.dclText(this .fromSymbolImpl).show
495
493
def showKind (using Context ): String = ctx.printer.kindString(this .fromSymbolImpl)
496
494
def showName (using Context ): String = ctx.printer.nameString(this .fromSymbolImpl)
497
495
def showFullName (using Context ): String = ctx.printer.fullNameString(this .fromSymbolImpl)
498
496
499
497
override def hashCode (): Int = id // for debugging.
500
498
}
501
499
502
- class ClassSymbolImpl private [Symbols ] (coord : Coord , val assocFile : AbstractFile , id : Int )
503
- extends SymbolImpl (coord, id), ClassSymbolDecl {
500
+ class ClassSymbolImpl private [Symbols ] (
501
+ maybeOwner : SymbolImpl ,
502
+ name : Name ,
503
+ initFlags : FlagSet ,
504
+ initInfo : Type ,
505
+ initPrivateWithin : SymbolImpl ,
506
+ initCoord : Coord ,
507
+ val assocFile : AbstractFile ,
508
+ id : Int )
509
+ extends SymbolImpl (
510
+ maybeOwner, name, initFlags, initInfo, initPrivateWithin, initCoord, id),
511
+ ClassSymbolDecl ,
512
+ ClassDenotation {
504
513
505
514
type ThisName = TypeName
506
515
@@ -591,14 +600,44 @@ object Symbols:
591
600
}
592
601
593
602
/** Kept separate since it keeps only PackageClassDenotation */
594
- class PackageClassSymbolImpl (id : Int ) extends ClassSymbolImpl (NoCoord , null , id)
603
+ class PackageClassSymbolImpl private [Symbols ] (
604
+ maybeOwner : SymbolImpl ,
605
+ name : Name ,
606
+ initFlags : FlagSet ,
607
+ initInfo : Type ,
608
+ initPrivateWithin : SymbolImpl ,
609
+ id : Int )
610
+ extends ClassSymbolImpl (
611
+ maybeOwner, name, initFlags, initInfo, initPrivateWithin, NoCoord , null , id),
612
+ PackageClassDenotation
595
613
596
614
@ 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
615
+ val NoSymbol : Symbol = new SymbolImpl (
616
+ null , " <none>" .toTermName, Permanent , NoType , null , NoCoord , 0 ):
617
+
618
+ override def isType : Boolean = false
619
+ override def isTerm : Boolean = false
620
+ override def exists : Boolean = false
621
+ override def owner : Symbol = throw new AssertionError (" NoDenotation.owner" )
622
+ override def computeAsSeenFrom (pre : Type )(using Context ): SingleDenotation = this
623
+ override def mapInfo (f : Type => Type )(using Context ): SingleDenotation = this
624
+
625
+ override def matches (other : SingleDenotation )(using Context ): Boolean = false
626
+ override def targetName (using Context ): Name = EmptyTermName
627
+ override def mapInherited (ownDenots : PreDenotation , prevDenots : PreDenotation , pre : Type )(using Context ): SingleDenotation = this
628
+ override def filterWithPredicate (p : SingleDenotation => Boolean ): SingleDenotation = this
629
+ override def filterDisjoint (denots : PreDenotation )(using Context ): SingleDenotation = this
630
+ override def filterWithFlags (required : FlagSet , excluded : FlagSet )(using Context ): SingleDenotation = this
631
+
632
+ validFor = Period .allInRun(NoRunId )
633
+
634
+ override def associatedFile (using Context ): AbstractFile = NoSource .file
635
+
636
+ override def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation =
637
+ NoDenotation
638
+ .fromSymbolImpl
639
+
640
+ // NoDenotation // force it in order to set `denot` field of NoSymbol
602
641
603
642
extension [N <: Name ](sym : Symbol { type ThisName = N })(using Context ) {
604
643
/** Copy a symbol, overriding selective fields.
@@ -653,12 +692,11 @@ object Symbols:
653
692
flags : FlagSet ,
654
693
info : Type ,
655
694
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
- }
695
+ coord : Coord = NoCoord )(using Context ): Symbol { type ThisName = N } =
696
+ val symi = new SymbolImpl (
697
+ owner.toSymbolImpl, name, flags, info, privateWithin.toSymbolImpl, coord, ctx.base.nextSymId)
698
+ symi.validFor = currentStablePeriod
699
+ symi.asInstanceOf [Symbol { type ThisName = N }]
662
700
663
701
/** Create a class symbol from its non-info fields and a function
664
702
* producing its info (the produced info may be lazy).
@@ -670,18 +708,18 @@ object Symbols:
670
708
infoFn : ClassSymbol => Type ,
671
709
privateWithin : Symbol = NoSymbol ,
672
710
coord : Coord = NoCoord ,
673
- assocFile : AbstractFile = null )(using Context ): ClassSymbol
674
- = {
675
- val cls = (
711
+ assocFile : AbstractFile = null )(using Context ): ClassSymbol =
712
+ val clsi =
676
713
if flags.is(Package ) then
677
- new PackageClassSymbolImpl (ctx.base.nextSymId)
714
+ new PackageClassSymbolImpl (
715
+ owner.toSymbolImpl, name, flags, NoCompleter , privateWithin.toSymbolImpl, ctx.base.nextSymId)
678
716
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
717
+ new ClassSymbolImpl (
718
+ owner.toSymbolImpl, name, flags, NoCompleter , privateWithin.toSymbolImpl, coord, assocFile, ctx.base.nextSymId)
719
+ clsi.validFor = currentStablePeriod
720
+ val cls = clsi.fromSymbolImpl.asClass
721
+ cls.info = infoFn(cls)
683
722
cls
684
- }
685
723
686
724
/** Create a class symbol from its non-info fields and the fields of its info. */
687
725
def newCompleteClassSymbol (
0 commit comments