Skip to content

Commit e52a3c9

Browse files
committed
implement SymDenotation ParamInfo, SrcPos in SymDenotation
1 parent 8b5154d commit e52a3c9

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import Trees.Literal
1717
import Variances.Variance
1818
import annotation.tailrec
1919
import util.SimpleIdentityMap
20-
import util.Stats
20+
import util.{SrcPos, SourcePosition, Stats}
21+
import util.Spans.*
2122
import java.util.WeakHashMap
2223
import scala.util.control.NonFatal
2324
import config.Config
@@ -39,7 +40,8 @@ object SymDenotations {
3940
final val name: Name,
4041
initFlags: FlagSet,
4142
initInfo: Type,
42-
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol, initInfo, name.isTypeName) {
43+
initPrivateWithin: Symbol = NoSymbol)
44+
extends SingleDenotation(symbol, initInfo, name.isTypeName), ParamInfo, SrcPos {
4345

4446
//assert(symbol.id != 4940, name)
4547

@@ -1744,6 +1746,31 @@ object SymDenotations {
17441746
/** Same as `sealedStrictDescendants` but prepends this symbol as well.
17451747
*/
17461748
final def sealedDescendants(using Context): List[Symbol] = this.symbol :: sealedStrictDescendants
1749+
1750+
// ---- ParamInfo bindings -------------------------------------
1751+
1752+
type ThisName <: Name
1753+
1754+
def isTypeParam(using Context): Boolean = is(TypeParam)
1755+
def paramName(using Context): ThisName = name.asInstanceOf[ThisName]
1756+
def paramInfo(using Context): Type = info
1757+
def paramInfoAsSeenFrom(pre: Type)(using Context): Type = pre.memberInfo(symbol)
1758+
def paramInfoOrCompleter(using Context): Type = infoOrCompleter
1759+
def paramVariance(using Context): Variance = variance
1760+
def paramRef(using Context): TypeRef = typeRef
1761+
1762+
// ---- SrcPos bindings -------------------------------------
1763+
1764+
/** The position of this symbol, or NoSpan if the symbol was not loaded
1765+
* from source or from TASTY. This is always a zero-extent position.
1766+
*/
1767+
final def span: Span = if symbol.coord.isSpan then symbol.coord.toSpan else NoSpan
1768+
1769+
final def sourcePos(using Context): SourcePosition = {
1770+
val src = symbol.source
1771+
(if src.exists then src else ctx.source).atSpan(span)
1772+
}
1773+
17471774
}
17481775

17491776
/** The contents of a class definition during a period
@@ -1759,6 +1786,8 @@ object SymDenotations {
17591786

17601787
import util.EqHashMap
17611788

1789+
type ThisName = TypeName
1790+
17621791
// ----- caches -------------------------------------------------------
17631792

17641793
private var myTypeParams: List[TypeSymbol] | Null = null

0 commit comments

Comments
 (0)