1
1
package dotty .tools .dotc .tastyreflect
2
2
3
- import dotty .tools .dotc .ast .{Trees , tpd }
3
+ import dotty .tools .dotc .ast .{Trees , tpd , untpd }
4
4
import dotty .tools .dotc .core
5
5
import dotty .tools .dotc .core .Decorators ._
6
6
import dotty .tools .dotc .core ._
@@ -79,9 +79,9 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
79
79
def ClassDefDeco (cdef : ClassDef ): ClassDefAPI = new ClassDefAPI {
80
80
private def rhs = cdef.rhs.asInstanceOf [tpd.Template ]
81
81
def constructor (implicit ctx : Context ): DefDef = rhs.constr
82
- def parents (implicit ctx : Context ): List [tpd. Tree ] = rhs.parents
82
+ def parents (implicit ctx : Context ): List [TermOrTypeTree ] = rhs.parents
83
83
def self (implicit ctx : Context ): Option [tpd.ValDef ] = optional(rhs.self)
84
- def body (implicit ctx : Context ): List [tpd. Tree ] = rhs.body
84
+ def body (implicit ctx : Context ): List [Statement ] = rhs.body
85
85
def symbol (implicit ctx : Context ): ClassSymbol = cdef.symbol.asClass
86
86
}
87
87
@@ -209,6 +209,10 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
209
209
}
210
210
}
211
211
212
+ def IdentDeco (x : Ident ): IdentAPI = new IdentAPI {
213
+ def name (implicit ctx : Context ): String = x.name.show
214
+ }
215
+
212
216
object Ident extends IdentExtractor {
213
217
def unapply (x : Term )(implicit ctx : Context ): Option [String ] = x match {
214
218
case x : tpd.Ident if x.isTerm => Some (x.name.show)
@@ -223,6 +227,14 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
223
227
}
224
228
}
225
229
230
+ def SelectDeco (x : Select ): SelectAPI = new SelectAPI {
231
+ def qualifier (implicit ctx : Context ): Term = x.qualifier
232
+ def name (implicit ctx : Context ): String = x.name.toString
233
+ def signature (implicit ctx : Context ): Option [Signature ] =
234
+ if (x.symbol.signature == core.Signature .NotAMethod ) None
235
+ else Some (x.symbol.signature)
236
+ }
237
+
226
238
object Select extends SelectExtractor {
227
239
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , String , Option [Signature ])] = x match {
228
240
case x : tpd.Select if x.isTerm =>
@@ -241,6 +253,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
241
253
}
242
254
}
243
255
256
+
257
+ def LiteralDeco (x : Literal ): LiteralAPI = new LiteralAPI {
258
+ def constant (implicit ctx : Context ): Constant = x.const
259
+ }
260
+
244
261
object Literal extends LiteralExtractor {
245
262
def unapply (x : Term )(implicit ctx : Context ): Option [Constant ] = x match {
246
263
case Trees .Literal (const) => Some (const)
@@ -255,6 +272,10 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
255
272
}
256
273
}
257
274
275
+ def ThisDeco (x : This ): ThisAPI = new ThisAPI {
276
+ def id (implicit ctx : Context ): Option [Id ] = optional(x.qual)
277
+ }
278
+
258
279
object This extends ThisExtractor {
259
280
def unapply (x : Term )(implicit ctx : Context ): Option [Option [Id ]] = x match {
260
281
case Trees .This (qual) => Some (optional(qual))
@@ -269,6 +290,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
269
290
}
270
291
}
271
292
293
+
294
+ def NewDeco (x : New ): Term .NewAPI = new NewAPI {
295
+ def tpt (implicit ctx : Context ): TypeTree = x.tpt
296
+ }
297
+
272
298
object New extends NewExtractor {
273
299
def unapply (x : Term )(implicit ctx : Context ): Option [TypeTree ] = x match {
274
300
case x : tpd.New => Some (x.tpt)
@@ -283,6 +309,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
283
309
}
284
310
}
285
311
312
+ def NamedArgDeco (x : NamedArg ): NamedArgAPI = new NamedArgAPI {
313
+ def name (implicit ctx : Context ): String = x.name.toString
314
+ def value (implicit ctx : Context ): Term = x.arg
315
+ }
316
+
286
317
object NamedArg extends NamedArgExtractor {
287
318
def unapply (x : Term )(implicit ctx : Context ): Option [(String , Term )] = x match {
288
319
case x : tpd.NamedArg if x.name.isInstanceOf [Names .TermName ] => Some ((x.name.toString, x.arg))
@@ -297,6 +328,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
297
328
}
298
329
}
299
330
331
+ def ApplyDeco (x : Apply ): ApplyAPI = new ApplyAPI {
332
+ def fun (implicit ctx : Context ): Term = x.fun
333
+ def args (implicit ctx : Context ): List [Term ] = x.args
334
+ }
335
+
300
336
object Apply extends ApplyExtractor {
301
337
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , List [Term ])] = x match {
302
338
case x : tpd.Apply => Some ((x.fun, x.args))
@@ -311,6 +347,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
311
347
}
312
348
}
313
349
350
+ def TypeApplyDeco (x : TypeApply ): TypeApplyAPI = new TypeApplyAPI {
351
+ def fun (implicit ctx : Context ): Term = x.fun
352
+ def args (implicit ctx : Context ): List [TypeTree ] = x.args
353
+ }
354
+
314
355
object TypeApply extends TypeApplyExtractor {
315
356
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , List [TypeTree ])] = x match {
316
357
case x : tpd.TypeApply => Some ((x.fun, x.args))
@@ -325,6 +366,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
325
366
}
326
367
}
327
368
369
+ def SuperDeco (x : Super ): SuperAPI = new SuperAPI {
370
+ def qualifier (implicit ctx : Context ): Term = x.qual
371
+ def id (implicit ctx : Context ): Option [untpd.Ident ] = optional(x.mix)
372
+ }
373
+
328
374
object Super extends SuperExtractor {
329
375
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Option [Id ])] = x match {
330
376
case x : tpd.Super => Some ((x.qual, if (x.mix.isEmpty) None else Some (x.mix)))
@@ -339,6 +385,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
339
385
}
340
386
}
341
387
388
+ def TypedDeco (x : Typed ): TypedAPI = new TypedAPI {
389
+ def expr (implicit ctx : Context ): Term = x.expr
390
+ def tpt (implicit ctx : Context ): TypeTree = x.tpt
391
+ }
392
+
342
393
object Typed extends TypedExtractor {
343
394
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , TypeTree )] = x match {
344
395
case x : tpd.Typed => Some ((x.expr, x.tpt))
@@ -353,6 +404,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
353
404
}
354
405
}
355
406
407
+ def AssignDeco (x : Assign ): AssignAPI = new AssignAPI {
408
+ def lhs (implicit ctx : Context ): Term = x.lhs
409
+ def rhs (implicit ctx : Context ): Term = x.rhs
410
+ }
411
+
356
412
object Assign extends AssignExtractor {
357
413
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Term )] = x match {
358
414
case x : tpd.Assign => Some ((x.lhs, x.rhs))
@@ -396,6 +452,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
396
452
}
397
453
}
398
454
455
+ def BlockDeco (x : Block ): BlockAPI = new BlockAPI {
456
+ def statements (implicit ctx : Context ): List [Statement ] = x.stats
457
+ def expr (implicit ctx : Context ): Term = x.expr
458
+ }
459
+
399
460
object Block extends BlockExtractor {
400
461
def unapply (x : Term )(implicit ctx : Context ): Option [(List [Statement ], Term )] = x match {
401
462
case IsBlock (x) => Some ((x.stats, x.expr))
@@ -410,6 +471,12 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
410
471
}
411
472
}
412
473
474
+ def InlinedDeco (x : Inlined ): InlinedAPI = new InlinedAPI {
475
+ def call (implicit ctx : Context ): Option [Term ] = optional(x.call)
476
+ def bindings (implicit ctx : Context ): List [Definition ] = x.bindings
477
+ def body (implicit ctx : Context ): Term = x.expansion
478
+ }
479
+
413
480
object Inlined extends InlinedExtractor {
414
481
def unapply (x : Term )(implicit ctx : Context ): Option [(Option [TermOrTypeTree ], List [Statement ], Term )] = x match {
415
482
case x : tpd.Inlined =>
@@ -425,6 +492,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
425
492
}
426
493
}
427
494
495
+ def LambdaDeco (x : Lambda ): LambdaAPI = new LambdaAPI {
496
+ def meth (implicit ctx : Context ): Term = x.meth
497
+ def tptOpt (implicit ctx : Context ): Option [TypeTree ] = optional(x.tpt)
498
+ }
499
+
428
500
object Lambda extends LambdaExtractor {
429
501
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Option [TypeTree ])] = x match {
430
502
case x : tpd.Closure => Some ((x.meth, optional(x.tpt)))
@@ -439,6 +511,12 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
439
511
}
440
512
}
441
513
514
+ def IfDeco (x : If ): IfAPI = new IfAPI {
515
+ def cond (implicit ctx : Context ): Term = x.cond
516
+ def thenp (implicit ctx : Context ): Term = x.thenp
517
+ def elsep (implicit ctx : Context ): Term = x.elsep
518
+ }
519
+
442
520
object If extends IfExtractor {
443
521
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Term , Term )] = x match {
444
522
case x : tpd.If => Some ((x.cond, x.thenp, x.elsep))
@@ -453,6 +531,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
453
531
}
454
532
}
455
533
534
+ def MatchDeco (x : Match ): MatchAPI = new MatchAPI {
535
+ def scrutinee (implicit ctx : Context ): Term = x.selector
536
+ def cases (implicit ctx : Context ): List [tpd.CaseDef ] = x.cases
537
+ }
538
+
456
539
object Match extends MatchExtractor {
457
540
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , List [CaseDef ])] = x match {
458
541
case x : tpd.Match => Some ((x.selector, x.cases))
@@ -467,6 +550,12 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
467
550
}
468
551
}
469
552
553
+ def TryDeco (x : Try ): TryAPI = new TryAPI {
554
+ def body (implicit ctx : Context ): Term = x.expr
555
+ def cases (implicit ctx : Context ): List [CaseDef ] = x.cases
556
+ def finalizer (implicit ctx : Context ): Option [Term ] = optional(x.finalizer)
557
+ }
558
+
470
559
object Try extends TryExtractor {
471
560
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , List [CaseDef ], Option [Term ])] = x match {
472
561
case x : tpd.Try => Some ((x.expr, x.cases, optional(x.finalizer)))
@@ -481,6 +570,10 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
481
570
}
482
571
}
483
572
573
+ def ReturnDeco (x : Return ): ReturnAPI = new ReturnAPI {
574
+ def expr (implicit ctx : Context ): Term = x.expr
575
+ }
576
+
484
577
object Return extends ReturnExtractor {
485
578
def unapply (x : Term )(implicit ctx : Context ): Option [Term ] = x match {
486
579
case x : tpd.Return => Some (x.expr)
@@ -495,6 +588,10 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
495
588
}
496
589
}
497
590
591
+ def RepeatedDeco (x : Repeated ): RepeatedAPI = new RepeatedAPI {
592
+ def elems (implicit ctx : Context ): List [Term ] = x.elems
593
+ }
594
+
498
595
object Repeated extends RepeatedExtractor {
499
596
def unapply (x : Term )(implicit ctx : Context ): Option [List [Term ]] = x match {
500
597
case x : tpd.SeqLiteral => Some (x.elems)
@@ -513,6 +610,15 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
513
610
}
514
611
}
515
612
613
+ def SelectOuterDeco (x : SelectOuter ): SelectOuterAPI = new SelectOuterAPI {
614
+ def qualifier (implicit ctx : Context ): Term = x.qualifier
615
+ def level (implicit ctx : Context ): Int = {
616
+ val NameKinds .OuterSelectName (_, levels) = x.name
617
+ levels
618
+ }
619
+ def tpe (implicit ctx : Context ): Type = x.tpe.stripTypeVar
620
+ }
621
+
516
622
object SelectOuter extends SelectOuterExtractor {
517
623
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Int , Type )] = x match {
518
624
case x : tpd.Select =>
@@ -531,6 +637,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
531
637
}
532
638
}
533
639
640
+ def WhileDeco (x : While ): WhileAPI = new WhileAPI {
641
+ def cond (implicit ctx : Context ): Term = x.cond
642
+ def body (implicit ctx : Context ): Term = x.body
643
+ }
644
+
534
645
object While extends WhileExtractor {
535
646
def unapply (x : Term )(implicit ctx : Context ): Option [(Term , Term )] = x match {
536
647
case x : tpd.WhileDo => Some ((x.cond, x.body))
0 commit comments