@@ -7,34 +7,35 @@ import config.Config
77import config .Printers
88import core .Mode
99
10- object trace {
10+ abstract class TraceSyntax {
11+ val isForced : Boolean
1112
1213 @ forceInline
1314 def onDebug [TD ](question : => String )(op : => TD )(implicit ctx : Context ): TD =
1415 conditionally(ctx.settings.YdebugTrace .value, question, false )(op)
1516
1617 @ forceInline
1718 def conditionally [TC ](cond : Boolean , question : => String , show : Boolean )(op : => TC )(implicit ctx : Context ): TC =
18- if (Config .tracingEnabled) {
19+ if (isForced || Config .tracingEnabled) {
1920 def op1 = op
2021 if (cond) apply[TC ](question, Printers .default, show)(op1)
2122 else op1
2223 } else op
2324
2425 @ forceInline
2526 def apply [T ](question : => String , printer : Printers .Printer , showOp : Any => String )(op : => T )(implicit ctx : Context ): T =
26- if (Config .tracingEnabled) {
27+ if (isForced || Config .tracingEnabled) {
2728 def op1 = op
28- if (printer.eq(config.Printers .noPrinter)) op1
29+ if (! isForced && printer.eq(config.Printers .noPrinter)) op1
2930 else doTrace[T ](question, printer, showOp)(op1)
3031 }
3132 else op
3233
3334 @ forceInline
3435 def apply [T ](question : => String , printer : Printers .Printer , show : Boolean )(op : => T )(implicit ctx : Context ): T =
35- if (Config .tracingEnabled) {
36+ if (isForced || Config .tracingEnabled) {
3637 def op1 = op
37- if (printer.eq(config.Printers .noPrinter)) op1
38+ if (! isForced && printer.eq(config.Printers .noPrinter)) op1
3839 else doTrace[T ](question, printer, if (show) showShowable(_) else alwaysToString)(op1)
3940 }
4041 else op
@@ -68,20 +69,27 @@ object trace {
6869 apply[T ](s " ==> $q? " , (res : Any ) => s " <== $q = ${showOp(res)}" )(op)
6970 }
7071
71- def apply [T ](leading : => String , trailing : Any => String )(op : => T )(implicit ctx : Context ): T =
72+ def apply [T ](leading : => String , trailing : Any => String )(op : => T )(implicit ctx : Context ): T = {
73+ val log : String => Unit = if (isForced) Console .println else {
74+ var logctx = ctx
75+ while (logctx.reporter.isInstanceOf [StoreReporter ]) logctx = logctx.outer
76+ logctx.log(_)
77+ }
78+ doApply(leading, trailing, log)(op)
79+ }
80+
81+ def doApply [T ](leading : => String , trailing : Any => String , log : String => Unit )(op : => T )(implicit ctx : Context ): T =
7282 if (ctx.mode.is(Mode .Printing )) op
7383 else {
7484 var finalized = false
75- var logctx = ctx
76- while (logctx.reporter.isInstanceOf [StoreReporter ]) logctx = logctx.outer
7785 def finalize (result : Any , note : String ) =
7886 if (! finalized) {
7987 ctx.base.indent -= 1
80- logctx. log(s " ${ctx.base.indentTab * ctx.base.indent}${trailing(result)}$note" )
88+ log(s " ${ctx.base.indentTab * ctx.base.indent}${trailing(result)}$note" )
8189 finalized = true
8290 }
8391 try {
84- logctx. log(s " ${ctx.base.indentTab * ctx.base.indent}$leading" )
92+ log(s " ${ctx.base.indentTab * ctx.base.indent}$leading" )
8593 ctx.base.indent += 1
8694 val res = op
8795 finalize(res, " " )
@@ -92,4 +100,11 @@ object trace {
92100 throw ex
93101 }
94102 }
103+ }
104+
105+ object trace extends TraceSyntax {
106+ final val isForced = false
107+ object force extends TraceSyntax {
108+ final val isForced = true
109+ }
95110}
0 commit comments