@@ -474,9 +474,9 @@ object Inlines:
474
474
475
475
def expandDefs (): List [Tree ] =
476
476
val tpd .Block (stats, _) = Inlines .bodyToInline(parentSym): @ unchecked
477
- val stats1 = stats.filterNot(isMemberOverridden )
477
+ val stats1 = stats.filterNot(isStatAlreadyOverridden )
478
478
val inlinedSymbols = stats1.map(stat => inlinedMember(stat.symbol))
479
- stats1.zip(inlinedSymbols).map(expandStat)// .map(inlined(_)._2)
479
+ stats1.zip(inlinedSymbols).map(expandStat)
480
480
end expandDefs
481
481
482
482
protected class InlineTraitTypeMap extends InlinerTypeMap {
@@ -488,27 +488,26 @@ object Inlines:
488
488
489
489
override protected val inlinerTypeMap : InlinerTypeMap = InlineTraitTypeMap ()
490
490
491
- private val argsMap : Map [Name , Tree ] =
491
+ private val paramAccessorsValueOf : Map [Name , Tree ] =
492
492
def allArgs (tree : Tree ): List [List [Tree ]] = tree match
493
493
case Apply (fun, args) => args :: allArgs(fun)
494
- case TypeApply (fun, targs) => targs :: allArgs(fun)
495
- case AppliedTypeTree (_, targs) => targs :: Nil
494
+ case TypeApply (fun, _) => allArgs(fun)
496
495
case _ => Nil
497
496
def allParams (info : Type ): List [List [Name ]] = info match
498
497
case mt : MethodType => mt.paramNames :: allParams(mt.resultType)
499
- case pt : PolyType => pt.paramNames :: allParams(pt.resultType)
498
+ case pt : PolyType => allParams(pt.resultType)
500
499
case _ => Nil
501
500
val info =
502
501
if parent.symbol.isClass then parent.symbol.primaryConstructor.info
503
502
else parent.symbol.info
504
503
allParams(info).flatten.zip(allArgs(parent).reverse.flatten).toMap
505
504
506
- private def isMemberOverridden (stat : Tree ): Boolean =
505
+ private def isStatAlreadyOverridden (stat : Tree ): Boolean =
507
506
overriddenDecls.flatMap(_.allOverriddenSymbols).toSet.contains(stat.symbol)
508
507
509
508
private def expandStat (stat : tpd.Tree , inlinedSym : Symbol ): tpd.Tree = stat match
510
509
case stat : ValDef if stat.symbol.is(ParamAccessor ) =>
511
- tpd.ValDef (inlinedSym.asTerm, argsMap(inlinedSym.name.asTermName )).withSpan(parent.span)
510
+ tpd.ValDef (inlinedSym.asTerm, paramAccessorsValueOf(stat.symbol.name )).withSpan(parent.span)
512
511
case stat : ValDef =>
513
512
inlinedValDef(stat, inlinedSym)
514
513
case stat : DefDef if stat.symbol.isSetter =>
@@ -521,19 +520,26 @@ object Inlines:
521
520
inlinedTypeDef(stat, inlinedSym)
522
521
523
522
private def inlinedMember (sym : Symbol )(using Context ): Symbol =
524
- if sym.isClass then
525
- val ClassInfo (prefix, cls, declaredParents, scope, selfInfo) = sym.info: @ unchecked
526
- val inlinedInfo = ClassInfo (prefix, cls, declaredParents, Scopes .newScope, selfInfo) // TODO adapt parents
527
- sym.copy(owner = ctx.owner, info = inlinedInfo, coord = spanCoord(parent.span)).entered.asClass
528
- else
529
- var flags = sym.flags | Synthetic
530
- if sym.isType || ! sym.is(Private ) then flags |= Override
531
- if ! sym.isType && sym.is(ParamAccessor ) then flags &~= ParamAccessor
532
- sym.copy(
533
- owner = ctx.owner,
534
- flags = flags,
535
- info = inlinerTypeMap(sym.info),
536
- coord = spanCoord(parent.span)).entered
523
+ sym.info match {
524
+ case ClassInfo (prefix, cls, declaredParents, scope, selfInfo) =>
525
+ val inlinedInfo = ClassInfo (prefix, cls, declaredParents, Scopes .newScope, selfInfo) // TODO adapt parents
526
+ sym.copy(owner = ctx.owner, info = inlinedInfo, coord = spanCoord(parent.span)).entered.asClass
527
+ case _ =>
528
+ var flags = sym.flags | Synthetic
529
+ if sym.isType || ! sym.is(Private ) then flags |= Override
530
+ if ! sym.isType && sym.is(ParamAccessor ) then flags &~= ParamAccessor
531
+ sym.copy(
532
+ owner = ctx.owner,
533
+ flags = flags,
534
+ info = inlinerTypeMap(sym.info),
535
+ coord = spanCoord(parent.span)).entered
536
+ }
537
+
538
+ private def inlinedStat (stat : Tree )(using Context ): Tree = stat match {
539
+ // TODO check if symbols must be copied
540
+ case tree : DefDef => inlinedDefDef(tree, tree.symbol)
541
+ case tree : ValDef => inlinedValDef(tree, tree.symbol)
542
+ }
537
543
538
544
private def inlinedValDef (vdef : ValDef , inlinedSym : Symbol )(using Context ): ValDef =
539
545
tpd.ValDef (inlinedSym.asTerm, inlinedRhs(vdef.rhs.changeOwner(vdef.symbol, inlinedSym))).withSpan(parent.span)
@@ -545,55 +551,23 @@ object Inlines:
545
551
inlinedRhs(ddef.rhs.subst(oldParamSyms, newParamSyms).changeOwner(ddef.symbol, inlinedSym))
546
552
tpd.DefDef (inlinedSym.asTerm, rhsFun).withSpan(parent.span)
547
553
554
+ private def inlinedPrimaryConstructorDefDef (ddef : DefDef )(using Context ): DefDef =
555
+ // TODO check if symbol must be copied
556
+ val constr = inlinedDefDef(ddef, ddef.symbol)
557
+ cpy.DefDef (constr)(tpt = TypeTree (defn.UnitType ), rhs = EmptyTree )
558
+
548
559
private def inlinedClassDef (clDef : TypeDef , impl : Template , inlinedCls : ClassSymbol )(using Context ): Tree =
549
560
val (constr, body) = inContext(ctx.withOwner(inlinedCls)) {
550
- (clonePrimaryConstructorDefDef (impl.constr), impl.body.map(cloneStat ))
561
+ (inlinedPrimaryConstructorDefDef (impl.constr), impl.body.map(inlinedStat ))
551
562
}
552
563
inlined(tpd.ClassDefWithParents (inlinedCls, constr, impl.parents, body))._2.withSpan(clDef.span) // TODO adapt parents
553
564
554
565
private def inlinedTypeDef (tdef : TypeDef , inlinedSym : Symbol )(using Context ): TypeDef =
555
566
tpd.TypeDef (inlinedSym.asType).withSpan(parent.span)
556
567
557
568
private def inlinedRhs (rhs : Tree ): Inlined =
558
- val (bindings, inlinedRhs) = inlined(rhs)
559
- // assert(bindings.isEmpty)
569
+ val inlinedRhs = inlined(rhs)._2
560
570
Inlined (tpd.ref(parentSym), Nil , inlinedRhs).withSpan(parent.span)
561
571
562
- private def cloneClass (clDef : untpd.TypeDef , impl : Template )(using Context ): TypeDef =
563
- val inlinedCls : ClassSymbol =
564
- val ClassInfo (prefix, cls, declaredParents, scope, selfInfo) = clDef.symbol.info: @ unchecked
565
- val inlinedInfo = ClassInfo (prefix, cls, declaredParents, Scopes .newScope, selfInfo) // TODO adapt parents
566
- clDef.symbol.copy(owner = ctx.owner, info = inlinedInfo, coord = spanCoord(parent.span)).entered.asClass
567
- val (constr, body) = inContext(ctx.withOwner(inlinedCls)) {
568
- (clonePrimaryConstructorDefDef(impl.constr), impl.body.map(cloneStat))
569
- }
570
- tpd.ClassDefWithParents (inlinedCls, constr, impl.parents, body).withSpan(clDef.span) // TODO adapt parents
571
-
572
- private def cloneStat (tree : Tree )(using Context ): Tree = tree match
573
- case tree : DefDef => cloneDefDef(tree)
574
- case tree : ValDef => cloneValDef(tree)
575
- // TODO case stat @ TypeDef(_, impl: Template) => cloneClass(stat, impl)
576
- // TODO case tree: TypeDef => cloneTypeDef(tree)
577
-
578
- private def cloneDefDef (ddef : DefDef )(using Context ): DefDef =
579
- val inlinedSym = ddef.symbol.copy(owner = ctx.owner, info = inlinerTypeMap(ddef.symbol.info), coord = spanCoord(parent.span)).entered
580
- def rhsFun (paramss : List [List [Tree ]]): Tree =
581
- val oldParamSyms = ddef.paramss.flatten.map(_.symbol)
582
- val newParamSyms = paramss.flatten.map(_.symbol)
583
- inlinedRhs(ddef.rhs.subst(oldParamSyms, newParamSyms).changeOwner(ddef.symbol, inlinedSym)) // TODO clone local classes?
584
- tpd.DefDef (inlinedSym.asTerm, rhsFun).withSpan(parent.span)
585
-
586
- private def clonePrimaryConstructorDefDef (ddef : DefDef )(using Context ): DefDef =
587
- val constr = cloneDefDef(ddef)
588
- cpy.DefDef (constr)(tpt = TypeTree (defn.UnitType ), rhs = EmptyTree )
589
-
590
- private def cloneValDef (vdef : ValDef )(using Context ): ValDef =
591
- val inlinedSym = vdef.symbol.copy(owner = ctx.owner, info = inlinerTypeMap(vdef.symbol.info), coord = spanCoord(parent.span)).entered
592
- tpd.ValDef (inlinedSym.asTerm, inlinedRhs(vdef.rhs.changeOwner(vdef.symbol, inlinedSym))).withSpan(parent.span) // TODO clone local classes?
593
-
594
- private def cloneTypeDef (tdef : TypeDef )(using Context ): TypeDef =
595
- val inlinedSym = tdef.symbol.copy(owner = ctx.owner, coord = spanCoord(parent.span)).entered
596
- tpd.TypeDef (inlinedSym.asType).withSpan(parent.span)
597
-
598
572
end InlineParentTrait
599
573
end Inlines
0 commit comments