11package dotty .tools .dotc .tastyreflect
22
33import dotty .tools .dotc .ast .{Trees , tpd }
4+ import dotty .tools .dotc .core .Contexts
45import dotty .tools .dotc .core .Decorators ._
56
67trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with CoreImpl {
78
9+ def ValueDeco (value : Value ): Pattern .ValueAPI = new Pattern .ValueAPI {
10+ def value (implicit ctx : Context ): Term = ???
11+ }
12+ def BindDeco (bind : Bind ): Pattern .BindAPI = new Pattern .BindAPI {
13+ def name (implicit ctx : Context ): String = ???
14+ def pattern (implicit ctx : Context ): Pattern = ???
15+ }
16+ def UnapplyDeco (unapply : Unapply ): Pattern .UnapplyAPI = new Pattern .UnapplyAPI {
17+ def fun (implicit ctx : Context ): Term = unapply.fun
18+ def implicits (implicit ctx : Context ): List [Term ] = unapply.implicits
19+ def patterns (implicit ctx : Context ): List [Pattern ] = effectivePatterns(unapply.patterns)
20+
21+ private def effectivePatterns (patterns : List [Pattern ]): List [Pattern ] = patterns match {
22+ case patterns0 :+ Trees .SeqLiteral (elems, _) => patterns0 ::: elems
23+ case _ => patterns
24+ }
25+ }
26+ def AlternativeDeco (alternatives : Alternatives ): Pattern .AlternativesAPI = new Pattern .AlternativesAPI {
27+ def patterns (implicit ctx : Context ): List [Pattern ] = alternatives.trees
28+ }
29+ def TypeTestDeco (typeTest : TypeTest ): Pattern .TypeTestAPI = new Pattern .TypeTestAPI {
30+ def tpt (implicit ctx : Context ): TypeTree = typeTest.tpt
31+ }
32+
833 // ----- Patterns -------------------------------------------------
934
1035 def PatternDeco (pattern : Pattern ): PatternAPI = new PatternAPI {
@@ -14,42 +39,79 @@ trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with CoreImpl {
1439
1540 object Pattern extends PatternModule {
1641
17- object Value extends ValueModule {
18- def unapply (x : Pattern )(implicit ctx : Context ): Option [Term ] = x match {
42+ object IsValue extends IsValueModule {
43+ def unapply (pattern : Pattern )(implicit ctx : Context ): Option [Value ] = pattern match {
1944 case lit : tpd.Literal => Some (lit)
2045 case ref : tpd.RefTree if ref.isTerm => Some (ref)
2146 case ths : tpd.This => Some (ths)
2247 case _ => None
2348 }
2449 }
2550
51+ object Value extends ValueModule {
52+ def apply (tpt : Term ): Value = ???
53+ def copy (original : Value )(tpt : Term ): Value = ???
54+ def unapply (x : Pattern )(implicit ctx : Context ): Option [Term ] = IsValue .unapply(x)
55+ }
56+
57+ object IsBind extends IsBindModule {
58+ def unapply (x : Pattern )(implicit ctx : Context ): Option [Bind ] = x match {
59+ case x : tpd.Bind if x.name.isTermName => Some (x)
60+ case _ => None
61+ }
62+ }
63+
2664 object Bind extends BindModule {
27- def unapply (x : Pattern )(implicit ctx : Context ): Option [(String , Pattern )] = x match {
28- case x : tpd.Bind if x.name.isTermName => Some (x.name.toString, x.body)
65+ def apply (name : String , pattern : Pattern ): Bind = ???
66+ def copy (original : Bind )(name : String , pattern : Pattern ): Bind = ???
67+ def unapply (pattern : Pattern )(implicit ctx : Context ): Option [(String , Pattern )] = pattern match {
68+ case IsBind (pattern) => Some ((pattern.name.toString, pattern.body))
69+ case _ => None
70+ }
71+ }
72+
73+ object IsUnapply extends IsUnapplyModule {
74+ def unapply (pattern : Pattern )(implicit ctx : Context ): Option [Unapply ] = pattern match {
75+ case pattern @ Trees .UnApply (_, _, _) => Some (pattern)
76+ case Trees .Typed (pattern @ Trees .UnApply (_, _, _), _) => Some (pattern)
2977 case _ => None
3078 }
3179 }
3280
3381 object Unapply extends UnapplyModule {
82+ def apply (fun : Term , implicits : List [Term ], patterns : List [Pattern ]): Unapply = ???
83+ def copy (original : Unapply )(fun : Term , implicits : List [Term ], patterns : List [Pattern ]): Unapply =
84+ tpd.cpy.UnApply (original)(fun, implicits, patterns)
3485 def unapply (x : Pattern )(implicit ctx : Context ): Option [(Term , List [Term ], List [Pattern ])] = x match {
35- case Trees .UnApply (fun, implicits, patterns) => Some ((fun, implicits, effectivePatterns(patterns)))
36- case Trees .Typed (Trees .UnApply (fun, implicits, patterns), _) => Some ((fun, implicits, effectivePatterns(patterns)))
86+ case IsUnapply (x) => Some ((x.fun, x.implicits, UnapplyDeco (x).patterns))
3787 case _ => None
3888 }
39- private def effectivePatterns (patterns : List [Pattern ]): List [Pattern ] = patterns match {
40- case patterns0 :+ Trees .SeqLiteral (elems, _) => patterns0 ::: elems
41- case _ => patterns
89+ }
90+
91+ object IsAlternatives extends IsAlternativesModule {
92+ def unapply (pattern : Pattern )(implicit ctx : Context ): Option [Alternatives ] = pattern match {
93+ case pattern : tpd.Alternative => Some (pattern)
94+ case _ => None
4295 }
4396 }
4497
45- object Alternative extends AlternativeModule {
98+ object Alternatives extends AlternativesModule {
99+ def apply (patterns : List [Pattern ]): Alternatives = ???
100+ def copy (original : Alternatives )(patterns : List [Pattern ]): Alternatives =
101+ tpd.cpy.Alternative (original)(patterns)
46102 def unapply (x : Pattern )(implicit ctx : Context ): Option [List [Pattern ]] = x match {
47103 case x : tpd.Alternative => Some (x.trees)
48104 case _ => None
49105 }
50106 }
51107
108+ object IsTypeTest extends IsTypeTestModule {
109+ def unapply (pattern : Pattern )(implicit ctx : Context ): Option [TypeTest ] = ???
110+ }
111+
52112 object TypeTest extends TypeTestModule {
113+ def apply (tpt : List [TypeTree ]): TypeTest = ???
114+ def copy (original : TypeTest )(tpt : List [TypeTree ]): TypeTest = ???
53115 def unapply (x : Pattern )(implicit ctx : Context ): Option [TypeTree ] = x match {
54116 case Trees .Typed (Trees .UnApply (_, _, _), _) => None
55117 case Trees .Typed (_, tpt) => Some (tpt)
0 commit comments