Skip to content

Commit 98e5af4

Browse files
committed
Add missing types to TASTy reflect
1 parent 0a1aed2 commit 98e5af4

File tree

6 files changed

+176
-19
lines changed

6 files changed

+176
-19
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ trait CoreImpl extends scala.tasty.reflect.Core {
2424
type DefDef = tpd.DefDef
2525
type ValDef = tpd.ValDef
2626
type Term = tpd.Tree
27+
val Term: TermCoreModuleImpl
28+
trait TermCoreModuleImpl extends TermCoreModule {
29+
type Ident = tpd.Ident
30+
type Select = tpd.Select
31+
type Literal = tpd.Literal
32+
type This = tpd.This
33+
type New = tpd.New
34+
type NamedArg = tpd.NamedArg
35+
type Apply = tpd.Apply
36+
type TypeApply = tpd.TypeApply
37+
type Super = tpd.Super
38+
type Typed = tpd.Typed
39+
type Assign = tpd.Assign
40+
type Block = tpd.Block
41+
type Lambda = tpd.Closure
42+
type If = tpd.If
43+
type Match = tpd.Match
44+
type Try = tpd.Try
45+
type Return = tpd.Return
46+
type Repeated = tpd.SeqLiteral
47+
type Inlined = tpd.Inlined
48+
type SelectOuter = tpd.Select
49+
type While = tpd.WhileDo
50+
}
51+
2752

2853
type CaseDef = tpd.CaseDef
2954
type TypeCaseDef = tpd.CaseDef
@@ -37,6 +62,23 @@ trait CoreImpl extends scala.tasty.reflect.Core {
3762

3863
type TypeOrBoundsTree = tpd.Tree
3964
type TypeTree = tpd.Tree
65+
val TypeTree: TypeTreeCoreModuleImpl
66+
trait TypeTreeCoreModuleImpl extends TypeTreeCoreModule {
67+
type Synthetic = tpd.TypeTree
68+
type Ident = tpd.Ident
69+
type Select = tpd.Select
70+
type Project = tpd.Select
71+
type Singleton = tpd.SingletonTypeTree
72+
type Refined = tpd.RefinedTypeTree
73+
type Applied = tpd.AppliedTypeTree
74+
type Annotated = tpd.Annotated
75+
type And = tpd.AndTypeTree
76+
type Or = tpd.OrTypeTree
77+
type MatchType = tpd.MatchTypeTree
78+
type ByName = tpd.ByNameTypeTree
79+
type LambdaTypeTree = tpd.LambdaTypeTree
80+
type Bind = tpd.Bind
81+
}
4082
type TypeBoundsTree = tpd.Tree
4183

4284
type TypeOrBounds = Types.Type

compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
200200
if (termOrTypeTree.isTerm) Some(termOrTypeTree) else None
201201
}
202202

203-
object Term extends TermModule {
203+
object Term extends TermModule with TermCoreModuleImpl {
204204

205205
object Ident extends IdentExtractor {
206206
def unapply(x: Term)(implicit ctx: Context): Option[String] = x match {

compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
2929
if (termOrTypeTree.isType) Some(termOrTypeTree) else None
3030
}
3131

32-
object TypeTree extends TypeTreeModule {
32+
object TypeTree extends TypeTreeModule with TypeTreeCoreModuleImpl {
3333

3434
object Synthetic extends SyntheticExtractor {
3535
def unapply(x: TypeTree)(implicit ctx: Context): Boolean = x match {

library/src/scala/tasty/reflect/Core.scala

Lines changed: 130 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ package scala.tasty.reflect
4848
* | +- Or
4949
* | +- MatchType
5050
* | +- ByName
51-
* | +- TypeLambdaTree
51+
* | +- LambdaTypeTree
5252
* | +- Bind
5353
* |
5454
* +- TypeBoundsTree
@@ -136,29 +136,97 @@ trait Core {
136136
/** Tree representing an import in the source code */
137137
type Import <: Statement
138138

139-
/** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef`*/
139+
/** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */
140140
type Definition <: Statement
141141

142-
/** Tree representing a package definition. This includes definitions in all source files. */
142+
/** Tree representing a package definition. This includes definitions in all source files */
143143
type PackageDef <: Definition
144144

145-
/** Tree representing a class definition. This includes annonymus class definitions and the class of a module object. */
145+
/** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */
146146
type ClassDef <: Definition
147147

148-
/** Tree representing a type (paramter or member) definition in the source code. */
148+
/** Tree representing a type (paramter or member) definition in the source code */
149149
type TypeDef <: Definition
150150

151-
/** Tree representing a method definition in the source code. */
151+
/** Tree representing a method definition in the source code */
152152
type DefDef <: Definition
153153

154-
/** Tree representing a value definition in the source code. This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */
154+
/** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */
155155
type ValDef <: Definition
156156

157-
/** Tree representing an expression in the source code. */
157+
/** Tree representing an expression in the source code */
158158
type Term <: Statement
159159

160-
// TODO Add subtype types of Term for documentation? Or support refined bindings and add the types.
160+
/** Trees representing an expression in the source code */
161+
val Term: TermCoreModule
161162

163+
/** Trees representing an expression in the source code */
164+
trait TermCoreModule {
165+
166+
/** Tree representing a reference to definition with a given name */
167+
type Ident <: Term
168+
169+
/** Tree representing a selection of definition with a given name on a given prefix */
170+
type Select <: Term
171+
172+
/** Tree representing a literal value in the source code */
173+
type Literal <: Term
174+
175+
/** Tree representing `this` in the source code */
176+
type This <: Term
177+
178+
/** Tree representing `new` in the source code */
179+
type New <: Term
180+
181+
/** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */
182+
type NamedArg <: Term
183+
184+
/** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */
185+
type Apply <: Term
186+
187+
/** Tree an application of type arguments */
188+
type TypeApply <: Term
189+
190+
/** Tree representing `super` in the source code */
191+
type Super <: Term
192+
193+
/** Tree representing a type ascription `x: T` in the source code */
194+
type Typed <: Term
195+
196+
/** Tree representing an assignment `x = y` in the source code */
197+
type Assign <: Term
198+
199+
/** Tree representing a block `{ ... }` in the source code */
200+
type Block <: Term
201+
202+
/** Tree representing a lambda `(...) => ...` in the source code */
203+
type Lambda <: Term
204+
205+
/** Tree representing an if/then/else `if (...) ... else ...` in the source code */
206+
type If <: Term
207+
208+
/** Tree representing a pattern match `x match { ... }` in the source code */
209+
type Match <: Term
210+
211+
/** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */
212+
type Try <: Term
213+
214+
/** Tree representing a `return` in the source code */
215+
type Return <: Term
216+
217+
/** Tree representing a variable argument list in the source code */
218+
type Repeated <: Term
219+
220+
/** Tree representing the scope of an inlined tree */
221+
type Inlined <: Term
222+
223+
/** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */
224+
type SelectOuter <: Term
225+
226+
/** Tree representing a while loop */
227+
type While <: Term
228+
229+
}
162230

163231
/** Branch of a pattern match or catch clause */
164232
type CaseDef <: AnyRef
@@ -190,8 +258,55 @@ trait Core {
190258
/** Type tree representing a type written in the source */
191259
type TypeTree <: TypeOrBoundsTree
192260

193-
// TODO Add subtype types of TypeTree for documentation? Or support refined bindings and add the types.
261+
/** Type trees representing a type written in the source */
262+
val TypeTree: TypeTreeCoreModule
263+
264+
/** Type trees representing a type written in the source */
265+
abstract class TypeTreeCoreModule {
266+
267+
/** Type tree representing an inferred type */
268+
type Synthetic <: TypeTree
269+
270+
/** Type tree representing a reference to definition with a given name */
271+
type Ident <: TypeTree
272+
273+
/** Type tree representing a selection of definition with a given name on a given term prefix */
274+
type Select <: TypeTree
275+
276+
/** Type tree representing a selection of definition with a given name on a given type prefix */
277+
type Project <: TypeTree
278+
279+
/** Type tree representing a singleton type */
280+
type Singleton <: TypeTree
281+
282+
/** Type tree representing a type refinement */
283+
type Refined <: TypeTree
284+
285+
/** Type tree representing a type application */
286+
type Applied <: TypeTree
287+
288+
/** Type tree representing an annotated type */
289+
type Annotated <: TypeTree
290+
291+
/** Type tree representing an intersection type */
292+
type And <: TypeTree
293+
294+
/** Type tree representing a union type */
295+
type Or <: TypeTree
296+
297+
/** Type tree representing a type match */
298+
type MatchType <: TypeTree
299+
300+
/** Type tree representing a by name parameter */
301+
type ByName <: TypeTree
302+
303+
/** Type tree representing a lambda abstraction type */
304+
type LambdaTypeTree <: TypeTree
305+
306+
/** Type tree representing a type binding */
307+
type Bind <: TypeTree
194308

309+
}
195310

196311
/** Type tree representing a type bound written in the source */
197312
type TypeBoundsTree <: TypeOrBoundsTree
@@ -250,25 +365,25 @@ trait Core {
250365
*/
251366
type Symbol <: AnyRef
252367

253-
/** Symbol of a package defnition */
368+
/** Symbol of a package definition */
254369
type PackageSymbol <: Symbol
255370

256-
/** Symbol of a class defnition. This includes annonymus class definitions and the class of a module object. */
371+
/** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */
257372
type ClassSymbol <: Symbol
258373

259-
/** Symbol of a type (paramter or member) definition. */
374+
/** Symbol of a type (parameter or member) definition. */
260375
type TypeSymbol <: Symbol
261376

262377
/** Symbol representing a method definition. */
263378
type DefSymbol <: Symbol
264379

265-
/** Symbol representing a value definition. This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */
380+
/** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */
266381
type ValSymbol <: Symbol
267382

268383
/** Symbol representing a bind definition. */
269384
type BindSymbol <: Symbol
270385

271-
/** No symbol availabe. */
386+
/** No symbol available. */
272387
type NoSymbol <: Symbol
273388

274389
}

library/src/scala/tasty/reflect/TreeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ trait TreeOps extends Core {
172172

173173
/** Scala term. Any tree that can go in expression position. */
174174
val Term: TermModule
175-
abstract class TermModule {
175+
abstract class TermModule extends TermCoreModule {
176176

177177
/** Scala term identifier */
178178
val Ident: IdentExtractor

library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait TypeOrBoundsTreeOps extends Core {
2626
}
2727

2828
val TypeTree: TypeTreeModule
29-
abstract class TypeTreeModule {
29+
abstract class TypeTreeModule extends TypeTreeCoreModule {
3030

3131
/** TypeTree containing an inferred type */
3232
val Synthetic: SyntheticExtractor

0 commit comments

Comments
 (0)