@@ -3,48 +3,53 @@ package tasty
3
3
4
4
import scala .quoted ._
5
5
6
- trait SyntheticsSupport :
7
- self : TastyParser =>
6
+ object SyntheticsSupport :
8
7
9
- import qctx .reflect ._
8
+ extension (using Quotes )(t : quotes.reflect.TypeRepr )
9
+ def isTupleType : Boolean = t.hackIsTupleType(t)
10
10
11
- extension (t : TypeRepr )
12
- def isTupleType : Boolean = hackIsTupleType(using qctx)(t)
11
+ def isCompiletimeAppliedType : Boolean = t.hackIsCompiletimeAppliedType(t)
13
12
14
- def isCompiletimeAppliedType : Boolean = hackIsCompiletimeAppliedType(using qctx)(t)
15
-
16
- def hackIsTupleType (using Quotes )(rtpe : qctx.reflect.TypeRepr ): Boolean =
13
+ private def hackIsTupleType (rtpe : quotes.reflect.TypeRepr ): Boolean =
17
14
import dotty .tools .dotc
18
- given ctx : dotc.core.Contexts .Context = qctx .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
15
+ given ctx : dotc.core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
19
16
val tpe = rtpe.asInstanceOf [dotc.core.Types .Type ]
20
17
ctx.definitions.isTupleType(tpe)
21
18
22
- def hackIsCompiletimeAppliedType (using Quotes )( rtpe : qctx .reflect.TypeRepr ): Boolean =
19
+ private def hackIsCompiletimeAppliedType (rtpe : quotes .reflect.TypeRepr ): Boolean =
23
20
import dotty .tools .dotc
24
- given ctx : dotc.core.Contexts .Context = qctx .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
21
+ given ctx : dotc.core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
25
22
val tpe = rtpe.asInstanceOf [dotc.core.Types .Type ]
26
23
ctx.definitions.isCompiletimeAppliedType(tpe.typeSymbol)
24
+ end extension
27
25
28
- extension (s : Symbol )
29
- def isSyntheticFunc : Boolean = s.flags.is(Flags .Synthetic ) || s.flags.is(Flags .FieldAccessor ) || isDefaultHelperMethod
26
+ extension (using Quotes )(s : quotes.reflect.Symbol )
27
+ def isSyntheticFunc : Boolean =
28
+ import quotes .reflect ._
29
+ s.flags.is(Flags .Synthetic ) || s.flags.is(Flags .FieldAccessor ) || s.isDefaultHelperMethod
30
30
31
31
def isSuperBridgeMethod : Boolean = s.name.contains(" $super$" )
32
32
33
33
def isDefaultHelperMethod : Boolean = " .*\\ $default\\ $\\ d+$" .r.matches(s.name)
34
34
35
- def isOpaque : Boolean = s.flags.is(Flags .Opaque )
35
+ def isOpaque : Boolean =
36
+ import quotes .reflect ._
37
+ s.flags.is(Flags .Opaque )
38
+
39
+ def isInfix : Boolean = hackIsInfix(s)
36
40
37
- def isInfix : Boolean = hackIsInfix( using qctx) (s)
41
+ def getmembers : List [quotes.reflect. Symbol ] = hackGetmembers (s)
38
42
39
- def getmembers : List [ Symbol ] = hackGetmembers( using qctx)(s)
43
+ end extension
40
44
41
- def isValidPos (pos : Position ) =
42
- if hackExists(using qctx)( pos) then pos.start != pos.end else false
45
+ def isValidPos (using Quotes )( pos : quotes.reflect. Position ) =
46
+ if hackExists(pos) then pos.start != pos.end else false
43
47
44
- def isSyntheticField (c : Symbol ) =
48
+ def isSyntheticField (using Quotes )(c : quotes.reflect.Symbol ) =
49
+ import quotes .reflect ._
45
50
c.flags.is(Flags .CaseAccessor ) || (c.flags.is(Flags .Module ) && ! c.flags.is(Flags .Given ))
46
51
47
- def constructorWithoutParamLists (c : ClassDef ): Boolean =
52
+ def constructorWithoutParamLists (using Quotes )( c : quotes.reflect. ClassDef ): Boolean =
48
53
! isValidPos(c.constructor.pos) || {
49
54
val end = c.constructor.pos.end
50
55
val typesEnd = c.constructor.leadingTypeParams.lastOption.fold(end - 1 )(_.pos.end)
@@ -53,21 +58,21 @@ trait SyntheticsSupport:
53
58
}
54
59
55
60
// TODO: #49 Remove it after TASTY-Reflect release with published flag Extension
56
- def hackIsInfix (using Quotes )(rsym : qctx .reflect.Symbol ): Boolean = {
57
- import qctx .reflect ._
61
+ private def hackIsInfix (using Quotes )(rsym : quotes .reflect.Symbol ): Boolean = {
62
+ import quotes .reflect ._
58
63
import dotty .tools .dotc
59
- given ctx : dotc.core.Contexts .Context = qctx .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
64
+ given ctx : dotc.core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
60
65
val sym = rsym.asInstanceOf [dotc.core.Symbols .Symbol ]
61
66
ctx.definitions.isInfix(sym)
62
67
}
63
68
/* We need there to filter out symbols with certain flagsets, because these symbols come from compiler and TASTY can't handle them well.
64
69
They are valdefs that describe case companion objects and cases from enum.
65
70
TASTY crashed when calling _.tree on them.
66
71
*/
67
- def hackGetmembers (using Quotes )(rsym : qctx .reflect.Symbol ): List [qctx .reflect.Symbol ] = {
68
- import qctx .reflect ._
72
+ private def hackGetmembers (using Quotes )(rsym : quotes .reflect.Symbol ): List [quotes .reflect.Symbol ] = {
73
+ import quotes .reflect ._
69
74
import dotty .tools .dotc
70
- given ctx : dotc.core.Contexts .Context = qctx .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
75
+ given ctx : dotc.core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
71
76
val sym = rsym.asInstanceOf [dotc.core.Symbols .Symbol ]
72
77
sym.typeRef.appliedTo(sym.typeParams.map(_.typeRef)).allMembers.iterator.map(_.symbol)
73
78
.collect {
@@ -78,39 +83,39 @@ trait SyntheticsSupport:
78
83
}.toList
79
84
}
80
85
81
- def hackGetSupertypes (using Quotes )(rdef : qctx .reflect.ClassDef ) = {
82
- import qctx .reflect ._
86
+ private def hackGetSupertypes (using Quotes )(rdef : quotes .reflect.ClassDef ) = {
87
+ import quotes .reflect ._
83
88
import dotty .tools .dotc
84
- given dotc .core.Contexts .Context = qctx .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
89
+ given dotc .core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
85
90
val classdef = rdef.asInstanceOf [dotc.ast.tpd.TypeDef ]
86
91
val ref = classdef.symbol.info.asInstanceOf [dotc.core.Types .ClassInfo ].appliedRef
87
92
val baseTypes : List [(dotc.core.Symbols .Symbol , dotc.core.Types .Type )] =
88
93
ref.baseClasses.map(b => b -> ref.baseType(b))
89
94
baseTypes.asInstanceOf [List [(Symbol , TypeRepr )]]
90
95
}
91
96
92
- def hackExists (using Quotes )(rpos : qctx .reflect.Position ) = {
93
- import qctx .reflect ._
97
+ private def hackExists (using Quotes )(rpos : quotes .reflect.Position ) = {
98
+ import quotes .reflect ._
94
99
import dotty .tools .dotc
95
100
import dotty .tools .dotc .util .Spans ._
96
- given dotc .core.Contexts .Context = qctx .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
101
+ given dotc .core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
97
102
val pos = rpos.asInstanceOf [dotc.util.SourcePosition ]
98
103
pos.exists
99
104
}
100
105
101
- def getSupertypes (using Quotes )(c : ClassDef ) = hackGetSupertypes(c).tail
106
+ def getSupertypes (using Quotes )(c : quotes.reflect. ClassDef ) = hackGetSupertypes(c).tail
102
107
103
- def typeForClass (c : ClassDef ): TypeRepr =
104
- import qctx .reflect ._
108
+ def typeForClass (using Quotes )( c : quotes.reflect. ClassDef ): quotes.reflect. TypeRepr =
109
+ import quotes .reflect ._
105
110
import dotty .tools .dotc
106
- given dotc .core.Contexts .Context = qctx .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
111
+ given dotc .core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
107
112
val cSym = c.symbol.asInstanceOf [dotc.core.Symbols .Symbol ]
108
113
cSym.typeRef.appliedTo(cSym.typeParams.map(_.typeRef)).asInstanceOf [TypeRepr ]
109
114
110
- def memberInfo (c : ClassDef , symbol : Symbol ): TypeRepr =
111
- import qctx .reflect ._
115
+ def memberInfo (using Quotes )( c : quotes.reflect. ClassDef , symbol : quotes.reflect. Symbol ): quotes.reflect. TypeRepr =
116
+ import quotes .reflect ._
112
117
import dotty .tools .dotc
113
- given dotc .core.Contexts .Context = qctx .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
118
+ given dotc .core.Contexts .Context = quotes .asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
114
119
typeForClass(c).asInstanceOf [dotc.core.Types .Type ]
115
120
.memberInfo(symbol.asInstanceOf [dotc.core.Symbols .Symbol ])
116
121
.asInstanceOf [TypeRepr ]
0 commit comments