[sledge] Add Trace.infok

Summary:
Trace.infok is like Trace.info but accepts a polymorphic printf
continuation instead of directly taking a format string and its
args. This is useful to write wrappers such as:
```
let trace k = [%Trace.infok k]
```

Reviewed By: ngorogiannis

Differential Revision: D19221883

fbshipit-source-id: 88e939b26
master
Josh Berdine 5 years ago committed by Facebook Github Bot
parent ff65bcce1c
commit 18fd68f60a

@ -88,8 +88,8 @@ let mapper =
| Pexp_extension ({txt= "debug"; loc}, PStr []) -> ebool ~loc !debug | Pexp_extension ({txt= "debug"; loc}, PStr []) -> ebool ~loc !debug
| Pexp_extension | Pexp_extension
( { txt= ( { txt=
( "Trace.info" | "Trace.printf" | "Trace.fprintf" ( "Trace.info" | "Trace.infok" | "Trace.printf"
| "Trace.kprintf" ) as txt | "Trace.fprintf" | "Trace.kprintf" ) as txt
; loc } ; loc }
, PStr [{pstr_desc= Pstr_eval (arg, []); _}] ) -> , PStr [{pstr_desc= Pstr_eval (arg, []); _}] ) ->
if not !debug then eunit ~loc:exp.pexp_loc if not !debug then eunit ~loc:exp.pexp_loc

@ -146,6 +146,9 @@ let info mod_name fun_name fmt =
Format.kfprintf (fun fs -> Format.fprintf fs "@]") fs fmt ) Format.kfprintf (fun fs -> Format.fprintf fs "@]") fs fmt )
else Format.ifprintf fs fmt else Format.ifprintf fs fmt
let infok mod_name fun_name k =
k {pf= (fun fmt -> info mod_name fun_name fmt)}
let incf mod_name fun_name fmt = let incf mod_name fun_name fmt =
if enabled mod_name fun_name then ( if enabled mod_name fun_name then (
Format.fprintf fs "@\n@[<2>@[<hv 2>( %s:@ " fun_name ; Format.fprintf fs "@\n@[<2>@[<hv 2>( %s:@ " fun_name ;

@ -51,10 +51,13 @@ val kprintf : string -> string -> (Formatter.t -> unit) -> 'a printf
val info : string -> string -> 'a printf val info : string -> string -> 'a printf
(** Emit a message at the current indentation level, if enabled. *) (** Emit a message at the current indentation level, if enabled. *)
val call : string -> string -> (pf -> 'b) -> 'b val infok : string -> string -> (pf -> 'a) -> 'a
(** Emit a message at the current indentation level, if enabled. *)
val call : string -> string -> (pf -> 'a) -> 'a
(** Increase indentation level and emit a message, if enabled. *) (** Increase indentation level and emit a message, if enabled. *)
val retn : string -> string -> (pf -> 'b -> unit) -> 'b -> 'b val retn : string -> string -> (pf -> 'a -> unit) -> 'a -> 'a
(** Decrease indentation level and emit a message, if enabled. *) (** Decrease indentation level and emit a message, if enabled. *)
val flush : unit -> unit val flush : unit -> unit

Loading…
Cancel
Save