One more example: instrument method calls.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12764 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
504f620fc7
commit
c0634a67ac
|
@ -13,3 +13,12 @@ module B =
|
||||||
struct
|
struct
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
let () =
|
||||||
|
let o = object
|
||||||
|
method x = 1
|
||||||
|
method y = 2
|
||||||
|
end
|
||||||
|
in
|
||||||
|
ignore (o # x + o # y)
|
||||||
|
|
|
@ -9,7 +9,7 @@ open Parsetree
|
||||||
the compilation unit. *)
|
the compilation unit. *)
|
||||||
|
|
||||||
let trace s =
|
let trace s =
|
||||||
SI.eval E.(apply (lid "Pervasives.print_endline") [strconst s])
|
E.(apply (lid "Pervasives.print_endline") [strconst s])
|
||||||
|
|
||||||
let tracer =
|
let tracer =
|
||||||
object(this)
|
object(this)
|
||||||
|
@ -27,9 +27,17 @@ let tracer =
|
||||||
[ SI.map this si ]
|
[ SI.map this si ]
|
||||||
|
|
||||||
method! structure l =
|
method! structure l =
|
||||||
trace (Printf.sprintf "Entering module %s" path) ::
|
SI.eval (trace (Printf.sprintf "Entering module %s" path)) ::
|
||||||
(super # structure l) @
|
(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
|
end
|
||||||
|
|
||||||
let () = tracer # main
|
let () = tracer # main
|
||||||
|
|
Loading…
Reference in New Issue