2 (****************************************************************************)
6 (* INRIA Rocquencourt *)
8 (* Copyright 2006 Institut National de Recherche en Informatique et *)
9 (* en Automatique. All rights reserved. This file is distributed under *)
10 (* the terms of the GNU Library General Public License, with the special *)
11 (* exception on linking described in LICENSE at the top of the Objective *)
12 (* Caml source tree. *)
14 (****************************************************************************)
17 * - Nicolas Pouillard: initial version
24 value name
= "Camlp4ExceptionTracer";
25 value version
= "$Id$";
28 module Make
(AstFilters
: Camlp4.Sig.AstFilters
) = struct
32 value add_debug_expr e
=
33 (* let _loc = Loc.make_absolute (MLast.loc_of_expr e) in *)
34 let _loc = Ast.loc_of_expr e
in
35 let msg = "camlp4-debug: exc: %s at " ^
Loc.to_string
_loc ^
"@." in
39 [ Stream.Failure
| Exit
as exc
-> raise exc
41 if Debug.mode
"exc" then
42 Format.eprintf $`str
:msg$
(Printexc.to_string exc
) else ();
46 value rec map_match_case
=
48 [ <:match_case
@_loc< $m1$
| $m2$
>> ->
49 <:match_case
< $map_match_case m1$
| $map_match_case m2$
>>
50 | <:match_case
@_loc< $p$
when $w$
-> $e$
>> ->
51 <:match_case
@_loc< $p$
when $w$
-> $add_debug_expr e$
>>
55 inherit Ast.map
as super
;
57 [ <:expr
@_loc< fun [ $m$
] >> -> <:expr
< fun [ $map_match_case m$
] >>
58 | x
-> super#expr x
];
60 [ <:str_item
< module Debug
= $_$
>> as st
-> st
61 | st
-> super#str_item st
];
64 register_str_item_filter filter#str_item
;
68 let module M
= Camlp4.Register.AstFilter Id Make
in ();