[sledge] Add Trace.{printf,fprintf,kprintf}

Reviewed By: mbouaziz

Differential Revision: D10389478

fbshipit-source-id: 4fd3ff6da
master
Josh Berdine 6 years ago committed by Facebook Github Bot
parent da89fc8f95
commit cf2a985073

@ -81,15 +81,10 @@ let mapper =
match exp.pexp_desc with match exp.pexp_desc with
| Pexp_extension ({txt= "debug"; loc}, PStr []) -> ebool ~loc !debug | Pexp_extension ({txt= "debug"; loc}, PStr []) -> ebool ~loc !debug
| Pexp_extension | Pexp_extension
( {txt= "Trace.call"; loc= call_loc} ( { txt=
, PStr [{pstr_desc= Pstr_eval (call_fun, []); _}] ) -> ( "Trace.info" | "Trace.printf" | "Trace.fprintf"
if not !debug then eunit ~loc:exp.pexp_loc | "Trace.kprintf" ) as txt
else ; loc }
pexp_apply ~loc:exp.pexp_loc
(evar ~loc:call_loc "Trace.call")
(append_here_args [(Nolabel, call_fun)])
| Pexp_extension
( {txt= "Trace.info"; loc= info_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
else else
@ -98,9 +93,16 @@ let mapper =
| Pexp_apply (op, args) -> (Nolabel, op) :: args | Pexp_apply (op, args) -> (Nolabel, op) :: args
| _ -> [(Nolabel, arg)] | _ -> [(Nolabel, arg)]
in in
pexp_apply ~loc:exp.pexp_loc pexp_apply ~loc:exp.pexp_loc (evar ~loc txt)
(evar ~loc:info_loc "Trace.info")
(append_here_args args) (append_here_args args)
| Pexp_extension
( {txt= "Trace.call"; loc= call_loc}
, PStr [{pstr_desc= Pstr_eval (call_fun, []); _}] ) ->
if not !debug then eunit ~loc:exp.pexp_loc
else
pexp_apply ~loc:exp.pexp_loc
(evar ~loc:call_loc "Trace.call")
(append_here_args [(Nolabel, call_fun)])
| Pexp_extension | Pexp_extension
( {txt= "Trace.retn"; loc= retn_loc} ( {txt= "Trace.retn"; loc= retn_loc}
, PStr [{pstr_desc= Pstr_eval (retn_fun, []); _}] ) -> , PStr [{pstr_desc= Pstr_eval (retn_fun, []); _}] ) ->

@ -54,6 +54,16 @@ let enabled mod_name fun_name =
| None -> trace_all ) ) | None -> trace_all ) )
| None -> trace_all | None -> trace_all
let kprintf mod_name fun_name k fmt =
if enabled mod_name fun_name then Format.kfprintf k fs fmt
else Format.ifprintf fs fmt
let fprintf mod_name fun_name fs fmt =
if enabled mod_name fun_name then Format.fprintf fs fmt
else Format.ifprintf fs fmt
let printf mod_name fun_name fmt = fprintf mod_name fun_name fs fmt
let info mod_name fun_name fmt = let info mod_name fun_name fmt =
if enabled mod_name fun_name then ( if enabled mod_name fun_name then (
Format.fprintf fs "@\n@[<2>| " ; Format.fprintf fs "@\n@[<2>| " ;

@ -27,6 +27,15 @@ val init : ?margin:int -> config:config -> unit -> unit
type 'a printf = ('a, Formatter.t, unit) format -> 'a type 'a printf = ('a, Formatter.t, unit) format -> 'a
type pf = {pf: 'a. 'a printf} type pf = {pf: 'a. 'a printf}
val printf : string -> string -> 'a printf
(** Like [Format.printf], if enabled, otherwise like [Format.iprintf]. *)
val fprintf : string -> string -> Formatter.t -> 'a printf
(** Like [Format.fprintf], if enabled, otherwise like [Format.ifprintf]. *)
val kprintf : string -> string -> (Formatter.t -> unit) -> 'a printf
(** Like [Format.kprintf], if enabled, otherwise like [Format.ifprintf]. *)
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. *)

Loading…
Cancel
Save