@@ -12,8 +12,9 @@ import annotation.internal.sharable
12
12
import reporting .trace
13
13
import printing .{Showable , Printer }
14
14
import printing .Texts .*
15
- import util .SimpleIdentitySet
15
+ import util .{ SimpleIdentitySet , Property }
16
16
import util .common .alwaysTrue
17
+ import scala .collection .mutable
17
18
18
19
/** A class for capture sets. Capture sets can be constants or variables.
19
20
* Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -317,6 +318,7 @@ object CaptureSet:
317
318
s " $id${getClass.getSimpleName.take(1 )}$trail"
318
319
319
320
override def toText (printer : Printer ): Text = inContext(printer.printerContext) {
321
+ for vars <- ctx.property(ShownVars ) do vars += this
320
322
super .toText(printer) ~ (Str (ids) provided ! isConst && ctx.settings.YccDebug .value)
321
323
}
322
324
@@ -528,4 +530,34 @@ object CaptureSet:
528
530
empty
529
531
recur(tp)
530
532
.showing(i " capture set of $tp = $result" , capt)
533
+
534
+ private val ShownVars : Property .Key [mutable.Set [Var ]] = Property .Key ()
535
+
536
+ def withCaptureSetsExplained [T ](op : Context ?=> T )(using ctx : Context ): T =
537
+ if ctx.settings.YccDebug .value then
538
+ val shownVars = mutable.Set [Var ]()
539
+ inContext(ctx.withProperty(ShownVars , Some (shownVars))) {
540
+ try op
541
+ finally
542
+ val reachable = mutable.Set [Var ]()
543
+ val todo = mutable.Queue [Var ]() ++= shownVars
544
+ def incl (cv : Var ): Unit =
545
+ if ! reachable.contains(cv) then todo += cv
546
+ while todo.nonEmpty do
547
+ val cv = todo.dequeue()
548
+ if ! reachable.contains(cv) then
549
+ reachable += cv
550
+ cv.deps.foreach {
551
+ case cv : Var => incl(cv)
552
+ case _ =>
553
+ }
554
+ cv match
555
+ case cv : DerivedVar => incl(cv.source)
556
+ case _ =>
557
+ val allVars = reachable.toArray.sortBy(_.id)
558
+ println(i " Capture set dependencies: " )
559
+ for cv <- allVars do
560
+ println(i " ${cv.show.padTo(20 , ' ' )} :: ${cv.deps.toList}%, % " )
561
+ }
562
+ else op
531
563
end CaptureSet
0 commit comments