@@ -227,6 +227,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
227
227
end ClassDefTypeTest
228
228
229
229
object ClassDef extends ClassDefModule :
230
+ def apply (cls : Symbol , parents : List [Tree ], body : List [Statement ]): ClassDef =
231
+ val untpdCtr = untpd.DefDef (nme.CONSTRUCTOR , Nil , tpd.TypeTree (dotc.core.Symbols .defn.UnitClass .typeRef), untpd.EmptyTree )
232
+ val ctr = ctx.typeAssigner.assignType(untpdCtr, cls.primaryConstructor)
233
+ tpd.ClassDefWithParents (cls.asClass, ctr, parents, body)
234
+
230
235
def copy (original : Tree )(name : String , constr : DefDef , parents : List [Tree ], selfOpt : Option [ValDef ], body : List [Statement ]): ClassDef = {
231
236
val dotc .ast.Trees .TypeDef (_, originalImpl : tpd.Template ) = original
232
237
tpd.cpy.TypeDef (original)(name.toTypeName, tpd.cpy.Template (originalImpl)(constr, parents, derived = Nil , selfOpt.getOrElse(tpd.EmptyValDef ), body))
@@ -259,6 +264,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
259
264
260
265
object DefDef extends DefDefModule :
261
266
def apply (symbol : Symbol , rhsFn : List [List [Tree ]] => Option [Term ]): DefDef =
267
+ assert(symbol.isTerm, s " expected a term symbol but received $symbol" )
262
268
withDefaultPos(tpd.DefDef (symbol.asTerm, prefss =>
263
269
xCheckMacroedOwners(xCheckMacroValidExpr(rhsFn(prefss)), symbol).getOrElse(tpd.EmptyTree )
264
270
))
@@ -1803,7 +1809,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
1803
1809
(x.prefix, x.name.toString)
1804
1810
end TermRef
1805
1811
1806
- type TypeRef = dotc.core.Types .NamedType
1812
+ type TypeRef = dotc.core.Types .TypeRef
1807
1813
1808
1814
object TypeRefTypeTest extends TypeTest [TypeRepr , TypeRef ]:
1809
1815
def unapply (x : TypeRepr ): Option [TypeRef & x.type ] = x match
@@ -2453,6 +2459,20 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
2453
2459
def requiredModule (path : String ): Symbol = dotc.core.Symbols .requiredModule(path)
2454
2460
def requiredMethod (path : String ): Symbol = dotc.core.Symbols .requiredMethod(path)
2455
2461
def classSymbol (fullName : String ): Symbol = dotc.core.Symbols .requiredClass(fullName)
2462
+
2463
+ def newClass (owner : Symbol , name : String , parents : List [TypeRepr ], decls : Symbol => List [Symbol ], selfInfo : Option [TypeRepr ]): Symbol =
2464
+ assert(parents.nonEmpty && ! parents.head.typeSymbol.is(dotc.core.Flags .Trait ), " First parent must be a class" )
2465
+ val cls = dotc.core.Symbols .newNormalizedClassSymbol(
2466
+ owner,
2467
+ name.toTypeName,
2468
+ dotc.core.Flags .EmptyFlags ,
2469
+ parents,
2470
+ selfInfo.getOrElse(Types .NoType ),
2471
+ dotc.core.Symbols .NoSymbol )
2472
+ cls.enter(dotc.core.Symbols .newConstructor(cls, dotc.core.Flags .Synthetic , Nil , Nil ))
2473
+ for sym <- decls(cls) do cls.enter(sym)
2474
+ cls
2475
+
2456
2476
def newMethod (owner : Symbol , name : String , tpe : TypeRepr ): Symbol =
2457
2477
newMethod(owner, name, tpe, Flags .EmptyFlags , noSymbol)
2458
2478
def newMethod (owner : Symbol , name : String , tpe : TypeRepr , flags : Flags , privateWithin : Symbol ): Symbol =
@@ -2621,6 +2641,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
2621
2641
def companionClass : Symbol = self.denot.companionClass
2622
2642
def companionModule : Symbol = self.denot.companionModule
2623
2643
def children : List [Symbol ] = self.denot.children
2644
+ def typeRef : TypeRef = self.denot.typeRef
2645
+ def termRef : TermRef = self.denot.termRef
2624
2646
2625
2647
def show (using printer : Printer [Symbol ]): String = printer.show(self)
2626
2648
0 commit comments