One more example: instrument method calls.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12764 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2012-07-24 09:53:48 +00:00
parent 504f620fc7
commit c0634a67ac
2 changed files with 20 additions and 3 deletions

View File

@ -13,3 +13,12 @@ module B =
struct
end
end
let () =
let o = object
method x = 1
method y = 2
end
in
ignore (o # x + o # y)

View File

@ -9,7 +9,7 @@ open Parsetree
the compilation unit. *)
let trace s =
SI.eval E.(apply (lid "Pervasives.print_endline") [strconst s])
E.(apply (lid "Pervasives.print_endline") [strconst s])
let tracer =
object(this)
@ -27,9 +27,17 @@ let tracer =
[ SI.map this si ]
method! structure l =
trace (Printf.sprintf "Entering module %s" path) ::
SI.eval (trace (Printf.sprintf "Entering module %s" path)) ::
(super # structure l) @
[ trace (Printf.sprintf "Leaving module %s" path) ]
[ SI.eval (trace (Printf.sprintf "Leaving module %s" path)) ]
method! expr e =
match e.pexp_desc with
| Pexp_send (_, s) ->
E.sequence (trace (Printf.sprintf "calling method %s" s)) (super # expr e)
| _ ->
super # expr e
end
let () = tracer # main