2 * Lm_position information for debugging.
4 * ----------------------------------------------------------------
7 * Copyright (C) 2002-2005 Mojave Group, Caltech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation,
12 * version 2.1 of the License.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Additional permission is given to link this library with the
24 * OpenSSL project's "OpenSSL" library, and with the OCaml runtime,
25 * and you may distribute the linked executables. See the file
26 * LICENSE.libmojave for more details.
28 * Author: Jason Hickey
29 * @email{jyh@cs.caltech.edu}
40 debug_description
= "print verbose position information for debugging";
46 { debug_name
= "trace_pos";
47 debug_description
= "print position trace for debugging";
51 (************************************************************************
53 ************************************************************************)
56 * We include the name of the module where
57 * the position is created. The value is a location,
58 * a raw value, or a value with another position.
61 type 'a pos
= string * 'a exn_loc
66 | DebugCons
of 'a
* 'a pos
67 | DebugConsLoc
of loc
* 'a pos
68 | DebugPos
of 'a pos
* 'a pos
69 | DebugInt
of int * 'a pos
70 | DebugString
of string * 'a pos
71 | DebugSymbol
of symbol
* 'a pos
72 | DebugDel
of (out_channel
-> unit) * loc
73 | DebugDelExp
of (out_channel
-> unit) * 'a pos
77 * Module for creating positions.
78 * You have to specify the name of the module
79 * where the exception are being created: use
80 * MakePos in each file where Name.name is set
81 * to the name of the module.
87 (* Creating positions *)
88 val loc_exp_pos
: loc
-> t pos
89 val loc_pos
: loc
-> t pos
-> t pos
90 val base_pos
: t
-> t pos
91 val cons_pos
: t
-> t pos
-> t pos
92 val pos_pos
: t pos
-> t pos
-> t pos
93 val int_pos
: int -> t pos
-> t pos
94 val string_pos
: string -> t pos
-> t pos
95 val symbol_pos
: symbol
-> t pos
-> t pos
96 val del_pos
: (out_channel
-> unit) -> loc
-> t pos
97 val del_exp_pos
: (out_channel
-> unit) -> t pos
-> t pos
100 val loc_of_pos
: t pos
-> loc
101 val pp_print_pos
: formatter
-> t pos
-> unit
104 module type NameSig
=
108 (* This is the name of the module where the position info is created *)
111 (* Utilities for managing values *)
112 val loc_of_value
: t
-> loc
113 val pp_print_value
: formatter
-> t
-> unit
116 (************************************************************************
118 ************************************************************************)
120 module MakePos
(Name
: NameSig
) =
127 * Get the source location for an exception.
129 let rec loc_of_pos (_
, pos
) =
133 | DebugConsLoc
(loc
, _
) ->
140 | DebugString
(_
, pos
)
141 | DebugSymbol
(_
, pos
)
142 | DebugDelExp
(_
, pos
) ->
146 * Print debugging info.
148 let rec pp_print_pos buf
(name
, e
) =
154 fprintf buf
"@ %s.%a" name pp_print_value x
156 | DebugCons
(x
, pos
) ->
157 pp_print_pos buf pos
;
158 fprintf buf
"@ /%s.%a" name pp_print_value x
160 | DebugConsLoc
(_
, pos
) ->
163 | DebugPos
(pos1
, pos2
) ->
164 fprintf buf
"@ @[<v 3>Called from: %s%a@]%a" (**)
169 | DebugString
(s
, pos
) ->
170 pp_print_pos buf pos
;
171 fprintf buf
"@ /%s.%s" name s
173 | DebugInt
(i
, pos
) ->
174 pp_print_pos buf pos
;
175 fprintf buf
"@ %s.%d" name i
177 | DebugSymbol
(v
, pos
) ->
178 pp_print_pos buf pos
;
179 fprintf buf
"@ %s.%a" name output_symbol v
184 | DebugDelExp
(f
, pos
) ->
185 pp_print_pos buf pos
;
189 * Real error printer.
191 let pp_print_pos buf pos
=
192 fprintf buf
"@[<v 3>%a" pp_print_location
(loc_of_pos pos
);
194 pp_print_pos buf pos
;
200 let loc_exp_pos loc
=
202 eprintf
"Lm_trace: %s.%a@." name pp_print_location loc
;
205 let loc_pos loc pos
=
207 eprintf
"Lm_trace: %s.loc@." name
;
208 name
, DebugConsLoc
(loc
, pos
)
212 eprintf
"Lm_trace: %s.base@." name
;
215 let pos_pos pos1 pos2
=
217 eprintf
"Lm_trace: %s.pos@." name
;
219 name
, DebugPos
(pos1
, pos2
)
225 eprintf
"Lm_trace: %s.cons@." name
;
227 name
, DebugCons
(x
, pos
)
233 eprintf
"Lm_trace: %s.int: %d@." name i
;
235 name
, DebugInt
(i
, pos
)
239 let string_pos s pos
=
241 eprintf
"Lm_trace: %s.string: %s@." name s
;
243 name
, DebugString
(s
, pos
)
247 let symbol_pos v pos
=
249 eprintf
"Lm_trace: %s.symbol: %a@." name output_symbol v
;
251 name
, DebugSymbol
(v
, pos
)
257 eprintf
"Lm_trace: %s.delayed@." name
;
258 name
, DebugDel
(f
, loc
)
260 let del_exp_pos f pos
=
262 eprintf
"Lm_trace: %s.delayed@." name
;
264 name
, DebugDelExp
(f
, pos
)
274 * Caml-master: "compile"