Skip to content

Commit d6d2236

Browse files
committed
Add missing Term extension methods
1 parent 4c90350 commit d6d2236

File tree

2 files changed

+241
-5
lines changed

2 files changed

+241
-5
lines changed

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

+114-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.dotc.tastyreflect
22

3-
import dotty.tools.dotc.ast.{Trees, tpd}
3+
import dotty.tools.dotc.ast.{Trees, tpd, untpd}
44
import dotty.tools.dotc.core
55
import dotty.tools.dotc.core.Decorators._
66
import dotty.tools.dotc.core._
@@ -79,9 +79,9 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
7979
def ClassDefDeco(cdef: ClassDef): ClassDefAPI = new ClassDefAPI {
8080
private def rhs = cdef.rhs.asInstanceOf[tpd.Template]
8181
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
8383
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
8585
def symbol(implicit ctx: Context): ClassSymbol = cdef.symbol.asClass
8686
}
8787

@@ -209,6 +209,10 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
209209
}
210210
}
211211

212+
def IdentDeco(x: Ident): IdentAPI = new IdentAPI {
213+
def name(implicit ctx: Context): String = x.name.show
214+
}
215+
212216
object Ident extends IdentExtractor {
213217
def unapply(x: Term)(implicit ctx: Context): Option[String] = x match {
214218
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
223227
}
224228
}
225229

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+
226238
object Select extends SelectExtractor {
227239
def unapply(x: Term)(implicit ctx: Context): Option[(Term, String, Option[Signature])] = x match {
228240
case x: tpd.Select if x.isTerm =>
@@ -241,6 +253,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
241253
}
242254
}
243255

256+
257+
def LiteralDeco(x: Literal): LiteralAPI = new LiteralAPI {
258+
def constant(implicit ctx: Context): Constant = x.const
259+
}
260+
244261
object Literal extends LiteralExtractor {
245262
def unapply(x: Term)(implicit ctx: Context): Option[Constant] = x match {
246263
case Trees.Literal(const) => Some(const)
@@ -255,6 +272,10 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
255272
}
256273
}
257274

275+
def ThisDeco(x: This): ThisAPI = new ThisAPI {
276+
def id(implicit ctx: Context): Option[Id] = optional(x.qual)
277+
}
278+
258279
object This extends ThisExtractor {
259280
def unapply(x: Term)(implicit ctx: Context): Option[Option[Id]] = x match {
260281
case Trees.This(qual) => Some(optional(qual))
@@ -269,6 +290,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
269290
}
270291
}
271292

293+
294+
def NewDeco(x: New): Term.NewAPI = new NewAPI {
295+
def tpt(implicit ctx: Context): TypeTree = x.tpt
296+
}
297+
272298
object New extends NewExtractor {
273299
def unapply(x: Term)(implicit ctx: Context): Option[TypeTree] = x match {
274300
case x: tpd.New => Some(x.tpt)
@@ -283,6 +309,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
283309
}
284310
}
285311

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+
286317
object NamedArg extends NamedArgExtractor {
287318
def unapply(x: Term)(implicit ctx: Context): Option[(String, Term)] = x match {
288319
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
297328
}
298329
}
299330

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+
300336
object Apply extends ApplyExtractor {
301337
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[Term])] = x match {
302338
case x: tpd.Apply => Some((x.fun, x.args))
@@ -311,6 +347,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
311347
}
312348
}
313349

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+
314355
object TypeApply extends TypeApplyExtractor {
315356
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[TypeTree])] = x match {
316357
case x: tpd.TypeApply => Some((x.fun, x.args))
@@ -325,6 +366,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
325366
}
326367
}
327368

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+
328374
object Super extends SuperExtractor {
329375
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Option[Id])] = x match {
330376
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
339385
}
340386
}
341387

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+
342393
object Typed extends TypedExtractor {
343394
def unapply(x: Term)(implicit ctx: Context): Option[(Term, TypeTree)] = x match {
344395
case x: tpd.Typed => Some((x.expr, x.tpt))
@@ -353,6 +404,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
353404
}
354405
}
355406

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+
356412
object Assign extends AssignExtractor {
357413
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Term)] = x match {
358414
case x: tpd.Assign => Some((x.lhs, x.rhs))
@@ -396,6 +452,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
396452
}
397453
}
398454

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+
399460
object Block extends BlockExtractor {
400461
def unapply(x: Term)(implicit ctx: Context): Option[(List[Statement], Term)] = x match {
401462
case IsBlock(x) => Some((x.stats, x.expr))
@@ -410,6 +471,12 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
410471
}
411472
}
412473

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+
413480
object Inlined extends InlinedExtractor {
414481
def unapply(x: Term)(implicit ctx: Context): Option[(Option[TermOrTypeTree], List[Statement], Term)] = x match {
415482
case x: tpd.Inlined =>
@@ -425,6 +492,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
425492
}
426493
}
427494

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+
428500
object Lambda extends LambdaExtractor {
429501
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Option[TypeTree])] = x match {
430502
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
439511
}
440512
}
441513

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+
442520
object If extends IfExtractor {
443521
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Term, Term)] = x match {
444522
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
453531
}
454532
}
455533

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+
456539
object Match extends MatchExtractor {
457540
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[CaseDef])] = x match {
458541
case x: tpd.Match => Some((x.selector, x.cases))
@@ -467,6 +550,12 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
467550
}
468551
}
469552

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+
470559
object Try extends TryExtractor {
471560
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[CaseDef], Option[Term])] = x match {
472561
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
481570
}
482571
}
483572

573+
def ReturnDeco(x: Return): ReturnAPI = new ReturnAPI {
574+
def expr(implicit ctx: Context): Term = x.expr
575+
}
576+
484577
object Return extends ReturnExtractor {
485578
def unapply(x: Term)(implicit ctx: Context): Option[Term] = x match {
486579
case x: tpd.Return => Some(x.expr)
@@ -495,6 +588,10 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
495588
}
496589
}
497590

591+
def RepeatedDeco(x: Repeated): RepeatedAPI = new RepeatedAPI {
592+
def elems(implicit ctx: Context): List[Term] = x.elems
593+
}
594+
498595
object Repeated extends RepeatedExtractor {
499596
def unapply(x: Term)(implicit ctx: Context): Option[List[Term]] = x match {
500597
case x: tpd.SeqLiteral => Some(x.elems)
@@ -513,6 +610,15 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
513610
}
514611
}
515612

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+
516622
object SelectOuter extends SelectOuterExtractor {
517623
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Int, Type)] = x match {
518624
case x: tpd.Select =>
@@ -531,6 +637,11 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
531637
}
532638
}
533639

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+
534645
object While extends WhileExtractor {
535646
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Term)] = x match {
536647
case x: tpd.WhileDo => Some((x.cond, x.body))

0 commit comments

Comments
 (0)