1
1
package scala .internal .quoted
2
2
3
3
import scala .annotation .internal .sharable
4
+ import scala .annotation .{Annotation , compileTimeOnly }
4
5
5
6
import scala .quoted ._
6
7
@@ -94,7 +95,36 @@ import scala.quoted._
94
95
*
95
96
* ```
96
97
*/
97
- private [quoted] object Matcher {
98
+ object Matcher {
99
+
100
+ // TODO move to internal.Quoted.Matcher
101
+ /** A splice in a quoted pattern is desugared by the compiler into a call to this method */
102
+ @ compileTimeOnly(" Illegal reference to `scala.internal.quoted.CompileTime.patternHole`" )
103
+ def patternHole [T ]: T = ???
104
+
105
+ @ compileTimeOnly(" Illegal reference to `scala.internal.quoted.CompileTime.patternHigherOrderHole`" )
106
+ /** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method */
107
+ def patternHigherOrderHole [U ](pat : Any , args : Any * ): U = ???
108
+
109
+ // TODO move to internal.Quoted.Matcher
110
+ @ compileTimeOnly(" Illegal reference to `scala.internal.quoted.CompileTime.higherOrderHole`" )
111
+ /** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method */
112
+ def higherOrderHole [U ](args : Any * ): U = ???
113
+
114
+ // TODO remove
115
+ /** A splice of a name in a quoted pattern is desugared by wrapping getting this annotation */
116
+ @ compileTimeOnly(" Illegal reference to `scala.internal.quoted.CompileTime.patternBindHole`" )
117
+ class patternBindHole extends Annotation
118
+
119
+ // TODO move to internal.Quoted.Matcher
120
+ /** A splice of a name in a quoted pattern is that marks the definition of a type splice */
121
+ @ compileTimeOnly(" Illegal reference to `scala.internal.quoted.CompileTime.patternType`" )
122
+ class patternType extends Annotation
123
+
124
+ // TODO move to internal.Quoted.Matcher
125
+ /** A type pattern that must be aproximated from above */
126
+ @ compileTimeOnly(" Illegal reference to `scala.internal.quoted.CompileTime.fromAbove`" )
127
+ class fromAbove extends Annotation
98
128
99
129
class QuoteMatcher [QCtx <: QuoteContext & Singleton ](using val qctx : QCtx ) {
100
130
// TODO improve performance
@@ -164,13 +194,13 @@ private[quoted] object Matcher {
164
194
private def hasFromAboveAnnotation (sym : Symbol ) = sym.annots.exists(isFromAboveAnnotation)
165
195
166
196
private def isPatternTypeAnnotation (tree : Tree ): Boolean = tree match {
167
- case New (tpt) => tpt.symbol == internal.Definitions_InternalQuoted_patternTypeAnnot
168
- case annot => annot.symbol.owner == internal.Definitions_InternalQuoted_patternTypeAnnot
197
+ case New (tpt) => tpt.symbol == internal.Definitions_InternalQuotedMatcher_patternTypeAnnot
198
+ case annot => annot.symbol.owner == internal.Definitions_InternalQuotedMatcher_patternTypeAnnot
169
199
}
170
200
171
201
private def isFromAboveAnnotation (tree : Tree ): Boolean = tree match {
172
- case New (tpt) => tpt.symbol == internal.Definitions_InternalQuoted_fromAboveAnnot
173
- case annot => annot.symbol.owner == internal.Definitions_InternalQuoted_fromAboveAnnot
202
+ case New (tpt) => tpt.symbol == internal.Definitions_InternalQuotedMatcher_fromAboveAnnot
203
+ case annot => annot.symbol.owner == internal.Definitions_InternalQuotedMatcher_fromAboveAnnot
174
204
}
175
205
176
206
/** Check that all trees match with `mtch` and concatenate the results with &&& */
@@ -226,15 +256,15 @@ private[quoted] object Matcher {
226
256
/* Term hole */
227
257
// Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree
228
258
case (scrutinee @ Typed (s, tpt1), Typed (TypeApply (patternHole, tpt :: Nil ), tpt2))
229
- if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole &&
259
+ if patternHole.symbol == internal.Definitions_InternalQuotedMatcher_patternHole &&
230
260
s.tpe <:< tpt.tpe &&
231
261
tpt2.tpe.derivesFrom(defn.RepeatedParamClass ) =>
232
262
matched(scrutinee.seal)
233
263
234
264
/* Term hole */
235
265
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
236
266
case (ClosedPatternTerm (scrutinee), TypeApply (patternHole, tpt :: Nil ))
237
- if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole &&
267
+ if patternHole.symbol == internal.Definitions_InternalQuotedMatcher_patternHole &&
238
268
scrutinee.tpe <:< tpt.tpe =>
239
269
matched(scrutinee.seal)
240
270
@@ -243,7 +273,7 @@ private[quoted] object Matcher {
243
273
// DEPRECATED: replaced with `higherOrderHole`
244
274
// TODO: remove case
245
275
case (scrutinee, pattern @ Apply (Select (TypeApply (patternHole, List (Inferred ())), " apply" ), args0 @ IdentArgs (args)))
246
- if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole =>
276
+ if patternHole.symbol == internal.Definitions_InternalQuotedMatcher_patternHole =>
247
277
def bodyFn (lambdaArgs : List [Tree ]): Tree = {
248
278
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf [List [Term ]]).toMap
249
279
new TreeMap {
@@ -262,7 +292,7 @@ private[quoted] object Matcher {
262
292
/* Higher order term hole */
263
293
// Matches an open term and wraps it into a lambda that provides the free variables
264
294
case (scrutinee, pattern @ Apply (TypeApply (Ident (" higherOrderHole" ), List (Inferred ())), Repeated (args, _) :: Nil ))
265
- if pattern.symbol == internal.Definitions_InternalQuoted_higherOrderHole =>
295
+ if pattern.symbol == internal.Definitions_InternalQuotedMatcher_higherOrderHole =>
266
296
267
297
def bodyFn (lambdaArgs : List [Tree ]): Tree = {
268
298
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf [List [Term ]]).toMap
0 commit comments