summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Frisch <alain@frisch.fr>2012-07-24 09:53:48 +0000
committerAlain Frisch <alain@frisch.fr>2012-07-24 09:53:48 +0000
commitc0634a67accb0ed249e40fe4d27cf245b0f176c7 (patch)
tree5e37de7fed88eee83ca27693385ae13b64919a8e
parent504f620fc700c241b437dce87cf935c8b4f52592 (diff)
One more example: instrument method calls.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12764 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--experimental/frisch/test_trace.ml9
-rw-r--r--experimental/frisch/tracer.ml14
2 files changed, 20 insertions, 3 deletions
diff --git a/experimental/frisch/test_trace.ml b/experimental/frisch/test_trace.ml
index 3d785e142..fc4f1ec2a 100644
--- a/experimental/frisch/test_trace.ml
+++ b/experimental/frisch/test_trace.ml
@@ -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)
diff --git a/experimental/frisch/tracer.ml b/experimental/frisch/tracer.ml
index f19776f70..095dd2e73 100644
--- a/experimental/frisch/tracer.ml
+++ b/experimental/frisch/tracer.ml
@@ -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