@@ -3,48 +3,53 @@ package tasty
33
44import scala .quoted ._
55
6- trait SyntheticsSupport :
7- self : TastyParser =>
6+ object SyntheticsSupport :
87
9- import qctx .reflect ._
8+ extension (using Quotes )(t : quotes.reflect.TypeRepr )
9+ def isTupleType : Boolean = t.hackIsTupleType(t)
1010
11- extension (t : TypeRepr )
12- def isTupleType : Boolean = hackIsTupleType(using qctx)(t)
11+ def isCompiletimeAppliedType : Boolean = t.hackIsCompiletimeAppliedType(t)
1312
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 =
1714 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
1916 val tpe = rtpe.asInstanceOf [dotc.core.Types .Type ]
2017 ctx.definitions.isTupleType(tpe)
2118
22- def hackIsCompiletimeAppliedType (using Quotes )( rtpe : qctx .reflect.TypeRepr ): Boolean =
19+ private def hackIsCompiletimeAppliedType (rtpe : quotes .reflect.TypeRepr ): Boolean =
2320 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
2522 val tpe = rtpe.asInstanceOf [dotc.core.Types .Type ]
2623 ctx.definitions.isCompiletimeAppliedType(tpe.typeSymbol)
24+ end extension
2725
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
3030
3131 def isSuperBridgeMethod : Boolean = s.name.contains(" $super$" )
3232
3333 def isDefaultHelperMethod : Boolean = " .*\\ $default\\ $\\ d+$" .r.matches(s.name)
3434
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)
3640
37- def isInfix : Boolean = hackIsInfix( using qctx) (s)
41+ def getmembers : List [quotes.reflect. Symbol ] = hackGetmembers (s)
3842
39- def getmembers : List [ Symbol ] = hackGetmembers( using qctx)(s)
43+ end extension
4044
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
4347
44- def isSyntheticField (c : Symbol ) =
48+ def isSyntheticField (using Quotes )(c : quotes.reflect.Symbol ) =
49+ import quotes .reflect ._
4550 c.flags.is(Flags .CaseAccessor ) || (c.flags.is(Flags .Module ) && ! c.flags.is(Flags .Given ))
4651
47- def constructorWithoutParamLists (c : ClassDef ): Boolean =
52+ def constructorWithoutParamLists (using Quotes )( c : quotes.reflect. ClassDef ): Boolean =
4853 ! isValidPos(c.constructor.pos) || {
4954 val end = c.constructor.pos.end
5055 val typesEnd = c.constructor.leadingTypeParams.lastOption.fold(end - 1 )(_.pos.end)
@@ -53,21 +58,21 @@ trait SyntheticsSupport:
5358 }
5459
5560 // 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 ._
5863 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
6065 val sym = rsym.asInstanceOf [dotc.core.Symbols .Symbol ]
6166 ctx.definitions.isInfix(sym)
6267 }
6368 /* We need there to filter out symbols with certain flagsets, because these symbols come from compiler and TASTY can't handle them well.
6469 They are valdefs that describe case companion objects and cases from enum.
6570 TASTY crashed when calling _.tree on them.
6671 */
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 ._
6974 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
7176 val sym = rsym.asInstanceOf [dotc.core.Symbols .Symbol ]
7277 sym.typeRef.appliedTo(sym.typeParams.map(_.typeRef)).allMembers.iterator.map(_.symbol)
7378 .collect {
@@ -78,39 +83,39 @@ trait SyntheticsSupport:
7883 }.toList
7984 }
8085
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 ._
8388 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
8590 val classdef = rdef.asInstanceOf [dotc.ast.tpd.TypeDef ]
8691 val ref = classdef.symbol.info.asInstanceOf [dotc.core.Types .ClassInfo ].appliedRef
8792 val baseTypes : List [(dotc.core.Symbols .Symbol , dotc.core.Types .Type )] =
8893 ref.baseClasses.map(b => b -> ref.baseType(b))
8994 baseTypes.asInstanceOf [List [(Symbol , TypeRepr )]]
9095 }
9196
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 ._
9499 import dotty .tools .dotc
95100 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
97102 val pos = rpos.asInstanceOf [dotc.util.SourcePosition ]
98103 pos.exists
99104 }
100105
101- def getSupertypes (using Quotes )(c : ClassDef ) = hackGetSupertypes(c).tail
106+ def getSupertypes (using Quotes )(c : quotes.reflect. ClassDef ) = hackGetSupertypes(c).tail
102107
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 ._
105110 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
107112 val cSym = c.symbol.asInstanceOf [dotc.core.Symbols .Symbol ]
108113 cSym.typeRef.appliedTo(cSym.typeParams.map(_.typeRef)).asInstanceOf [TypeRepr ]
109114
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 ._
112117 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
114119 typeForClass(c).asInstanceOf [dotc.core.Types .Type ]
115120 .memberInfo(symbol.asInstanceOf [dotc.core.Symbols .Symbol ])
116121 .asInstanceOf [TypeRepr ]
0 commit comments