@@ -7,34 +7,35 @@ import config.Config
7
7
import config .Printers
8
8
import core .Mode
9
9
10
- object trace {
10
+ abstract class TraceSyntax {
11
+ val isForced : Boolean
11
12
12
13
@ forceInline
13
14
def onDebug [TD ](question : => String )(op : => TD )(implicit ctx : Context ): TD =
14
15
conditionally(ctx.settings.YdebugTrace .value, question, false )(op)
15
16
16
17
@ forceInline
17
18
def conditionally [TC ](cond : Boolean , question : => String , show : Boolean )(op : => TC )(implicit ctx : Context ): TC =
18
- if (Config .tracingEnabled) {
19
+ if (isForced || Config .tracingEnabled) {
19
20
def op1 = op
20
21
if (cond) apply[TC ](question, Printers .default, show)(op1)
21
22
else op1
22
23
} else op
23
24
24
25
@ forceInline
25
26
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) {
27
28
def op1 = op
28
- if (printer.eq(config.Printers .noPrinter)) op1
29
+ if (! isForced && printer.eq(config.Printers .noPrinter)) op1
29
30
else doTrace[T ](question, printer, showOp)(op1)
30
31
}
31
32
else op
32
33
33
34
@ forceInline
34
35
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) {
36
37
def op1 = op
37
- if (printer.eq(config.Printers .noPrinter)) op1
38
+ if (! isForced && printer.eq(config.Printers .noPrinter)) op1
38
39
else doTrace[T ](question, printer, if (show) showShowable(_) else alwaysToString)(op1)
39
40
}
40
41
else op
@@ -68,20 +69,27 @@ object trace {
68
69
apply[T ](s " ==> $q? " , (res : Any ) => s " <== $q = ${showOp(res)}" )(op)
69
70
}
70
71
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 =
72
82
if (ctx.mode.is(Mode .Printing )) op
73
83
else {
74
84
var finalized = false
75
- var logctx = ctx
76
- while (logctx.reporter.isInstanceOf [StoreReporter ]) logctx = logctx.outer
77
85
def finalize (result : Any , note : String ) =
78
86
if (! finalized) {
79
87
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" )
81
89
finalized = true
82
90
}
83
91
try {
84
- logctx. log(s " ${ctx.base.indentTab * ctx.base.indent}$leading" )
92
+ log(s " ${ctx.base.indentTab * ctx.base.indent}$leading" )
85
93
ctx.base.indent += 1
86
94
val res = op
87
95
finalize(res, " " )
@@ -92,4 +100,11 @@ object trace {
92
100
throw ex
93
101
}
94
102
}
103
+ }
104
+
105
+ object trace extends TraceSyntax {
106
+ final val isForced = false
107
+ object force extends TraceSyntax {
108
+ final val isForced = true
109
+ }
95
110
}
0 commit comments