@@ -16,12 +16,13 @@ object SymbolOps:
16
16
extension (sym : Symbol )
17
17
def sig (using LinkMode , Context ): s.Signature =
18
18
import TypeOps ._
19
+ println(" " )
20
+ println(sym.toString)
21
+ println(s " =========sym.info================ " )
22
+ pprint.pprintln(sym.info)
19
23
val sig = sym.info.toSemanticSig(sym)
20
- // println("")
21
- // println(sym.toString)
22
- // println(s"=========sym.info================")
23
- // pprint.pprintln(sym.info)
24
- // pprint.pprintln(sig)
24
+ println(s " =========sig================ " )
25
+ pprint.pprintln(sig)
25
26
sig
26
27
27
28
object TypeOps :
@@ -35,16 +36,16 @@ object TypeOps:
35
36
s.MethodSignature (
36
37
stparams,
37
38
sparamss,
38
- mt.resType.toSemanticType
39
+ mt.resType.toSemanticType(sym)
39
40
)
40
41
41
42
case cls : ClassInfo =>
42
43
val stparams =
43
44
if (cls.cls.typeParams.nonEmpty)
44
45
Some (cls.cls.typeParams.sscope)
45
46
else None
46
- val sparents = cls.parents.map(_.toSemanticType)
47
- val sself = cls.selfType.toSemanticType
47
+ val sparents = cls.parents.map(_.toSemanticType(sym) )
48
+ val sself = cls.selfType.toSemanticType(sym)
48
49
val decls = cls.decls.toList.sscope(using LinkMode .HardlinkChildren )
49
50
s.ClassSignature (stparams, sparents, sself, Some (decls))
50
51
@@ -53,8 +54,8 @@ object TypeOps:
53
54
// type Poly[T] = List[T] is equivalent with
54
55
// type Poly = [T] =>> List[T]
55
56
val stparams = Some (s.Scope ())
56
- val slo = lo.toSemanticType
57
- val shi = hi.toSemanticType
57
+ val slo = lo.toSemanticType(sym)
58
+ val shi = hi.toSemanticType(sym)
58
59
s.TypeSignature (stparams, slo, shi)
59
60
60
61
case pt : PolyType =>
@@ -72,12 +73,12 @@ object TypeOps:
72
73
73
74
case other =>
74
75
s.ValueSignature (
75
- other.toSemanticType
76
+ other.toSemanticType(sym)
76
77
)
77
78
}
78
79
loop(tpe)
79
80
80
- private def toSemanticType (using LinkMode , Context ): s.Type =
81
+ private def toSemanticType (using LinkMode )( using ctx : Context )( sym : Symbol ): s.Type =
81
82
import ConstantOps ._
82
83
def loop (tpe : Type ): s.Type = tpe match {
83
84
case ExprType (tpe) =>
@@ -94,9 +95,22 @@ object TypeOps:
94
95
val ssym = symbolName(desig.asInstanceOf [Symbol ])
95
96
s.SingleType (spre, ssym)
96
97
97
- // TODO: TypeParamRef and TermParamRef
98
- // but how can we retrieve their symbols? (for representing them as TypeRef and TermRef on Semanticdb)
99
- // or should we add new types to Semanticdb
98
+ case tref : TypeParamRef =>
99
+ // println(s"rawParamss: ${sym.rawParamss}")
100
+ // println(s"num: ${tref.paramNum}, name: ${tref.paramName}")
101
+ val paramref = sym.rawParamss.flatMap { params =>
102
+ if (params.length > tref.paramNum) Some (params(tref.paramNum))
103
+ else None
104
+ }.find(p => p.name == tref.paramName)
105
+ paramref match {
106
+ case Some (ref) =>
107
+ val ssym = symbolName(ref)
108
+ s.TypeRef (s.Type .Empty , ssym, Seq .empty)
109
+ case None => // shouldn't happen
110
+ s.Type .Empty
111
+ }
112
+
113
+ // TODO: TermParamRef
100
114
101
115
case ThisType (TypeRef (_, desig)) if desig.isInstanceOf [Symbol ] =>
102
116
val ssym = symbolName(desig.asInstanceOf [Symbol ])
@@ -125,22 +139,41 @@ object TypeOps:
125
139
// refinedName = x
126
140
// refinedInfo = TypeRef(..., Int)
127
141
// )
128
- def getParent (parent : Type ): Type = parent match {
129
- case RefinedType (p, _, _) => getParent(p)
130
- case _ => parent
142
+
143
+ type RefinedInfo = (core.Names .Name , Type )
144
+ def flatten (tpe : Type , acc : List [RefinedInfo ]): (Type , List [RefinedInfo ]) = tpe match {
145
+ case RefinedType (parent, name, info) =>
146
+ flatten(parent, acc :+ (name, info))
147
+ case _ =>
148
+ (tpe, acc)
131
149
}
150
+ val (parent, refinedInfos) = flatten(rt, List .empty)
132
151
133
- val realParent = getParent(parent)
134
- val stpe = realParent match {
152
+ val stpe = parent match {
135
153
// val tp: M with N { def k: Int } = ???
136
154
case AndType (x, y) =>
137
155
s.WithType (Seq (loop(x), loop(y))) // TODO: for M with N with L
138
156
case _ =>
139
157
s.WithType (Seq (loop(parent)))
140
158
}
141
- // TODO: collect all refinement symbols
142
- // val sdecls = decls.sscope(using LinkMode.HardlinkChildren)
143
- s.StructuralType (stpe, None )
159
+ val decls = for {
160
+ (name, info) <- refinedInfos
161
+ } yield {
162
+ // do we need this?
163
+ // isLegalPrefix returns true outside in typer
164
+ val pre = ctx.typeAssigner.maybeSkolemizePrefix(rt, name)
165
+ val denot = rt.findMember(name, pre)
166
+ // assert(denot.info eq info, s"(${denot.info.show}) is not eq to (${info.show})")
167
+ println(s " denot.info: ${denot.info}, info: ${info}, sym: ${denot.symbol}" )
168
+ val sym =
169
+ if denot.symbol.exists then
170
+ println(s " refined ${denot.symbol.show} with ${info.show}" )
171
+ denot.symbol
172
+ else ???
173
+ sym
174
+ }
175
+ val sdecls = decls.sscope(using LinkMode .HardlinkChildren )
176
+ s.StructuralType (stpe, Some (sdecls))
144
177
145
178
case rec : RecType =>
146
179
loop(rec.parent) // should be handled as RefinedType
0 commit comments