1997-03-22 12:16:52 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy and Jerome Vouillon, projet Cristal, INRIA Rocquencourt*)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1997-03-22 12:16:52 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* To print values *)
|
|
|
|
|
|
|
|
open Misc
|
2000-03-06 14:12:09 -08:00
|
|
|
open Format
|
1997-03-22 12:16:52 -08:00
|
|
|
open Longident
|
|
|
|
open Path
|
|
|
|
open Types
|
|
|
|
|
1998-10-01 05:34:32 -07:00
|
|
|
module type OBJ =
|
1997-03-22 12:16:52 -08:00
|
|
|
sig
|
|
|
|
type t
|
|
|
|
val obj : t -> 'a
|
|
|
|
val is_block : t -> bool
|
|
|
|
val tag : t -> int
|
|
|
|
val size : t -> int
|
|
|
|
val field : t -> int -> t
|
|
|
|
end
|
|
|
|
|
2000-03-25 10:55:45 -08:00
|
|
|
module type EVALPATH =
|
|
|
|
sig
|
|
|
|
type value
|
|
|
|
val eval_path: Path.t -> value
|
|
|
|
exception Error
|
2000-03-26 04:11:10 -08:00
|
|
|
val same_value: value -> value -> bool
|
2000-03-25 10:55:45 -08:00
|
|
|
end
|
|
|
|
|
1997-03-22 12:16:52 -08:00
|
|
|
module type S =
|
|
|
|
sig
|
|
|
|
type t
|
|
|
|
val install_printer : Path.t -> Types.type_expr -> (t -> unit) -> unit
|
|
|
|
val remove_printer : Path.t -> unit
|
2000-03-25 10:55:45 -08:00
|
|
|
val print_untyped_exception : formatter -> t -> unit
|
1997-03-22 12:16:52 -08:00
|
|
|
val print_value :
|
|
|
|
int -> int -> (int -> t -> Types.type_expr -> bool) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
Env.t -> t -> formatter -> type_expr -> unit
|
1997-03-22 12:16:52 -08:00
|
|
|
end
|
|
|
|
|
2000-03-25 10:55:45 -08:00
|
|
|
module Make(O : OBJ)(EVP : EVALPATH with type value = O.t) = struct
|
1997-03-22 12:16:52 -08:00
|
|
|
|
1998-10-01 05:34:32 -07:00
|
|
|
type t = O.t
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
(* Given an exception value, we cannot recover its type,
|
|
|
|
hence we cannot print its arguments in general.
|
|
|
|
Here, we do a feeble attempt to print
|
|
|
|
integer, string and float arguments... *)
|
|
|
|
|
2000-03-25 10:55:45 -08:00
|
|
|
let print_untyped_exception_args obj ppf start_offset =
|
1998-10-01 05:34:32 -07:00
|
|
|
if O.size obj > start_offset then begin
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "@[<1>(";
|
1998-10-01 05:34:32 -07:00
|
|
|
for i = start_offset to O.size obj - 1 do
|
2000-03-06 14:12:09 -08:00
|
|
|
if i > start_offset then fprintf ppf ",@ ";
|
1998-10-01 05:34:32 -07:00
|
|
|
let arg = O.field obj i in
|
|
|
|
if not (O.is_block arg) then
|
2000-03-25 10:55:45 -08:00
|
|
|
fprintf ppf "%i" (O.obj arg : int)
|
|
|
|
(* Note: this could be a char or a constant constructor... *)
|
2000-03-06 14:12:09 -08:00
|
|
|
else if O.tag arg = Obj.string_tag then
|
|
|
|
fprintf ppf "\"%s\"" (String.escaped (O.obj arg : string))
|
|
|
|
else if O.tag arg = Obj.double_tag then
|
|
|
|
fprintf ppf "%f" (O.obj arg : float)
|
1997-03-22 12:16:52 -08:00
|
|
|
else
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "_"
|
1997-03-22 12:16:52 -08:00
|
|
|
done;
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf ")@]"
|
1997-03-22 12:16:52 -08:00
|
|
|
end
|
|
|
|
|
2000-03-25 10:55:45 -08:00
|
|
|
let print_untyped_exception ppf bucket =
|
1998-10-01 05:34:32 -07:00
|
|
|
let name = (O.obj(O.field(O.field bucket 0) 0) : string) in
|
1997-12-09 01:12:30 -08:00
|
|
|
if (name = "Match_failure" || name = "Assert_failure")
|
1998-10-01 05:34:32 -07:00
|
|
|
&& O.size bucket = 2
|
|
|
|
&& O.tag(O.field bucket 1) = 0
|
2000-03-25 10:55:45 -08:00
|
|
|
then fprintf ppf "%s%a" name
|
|
|
|
(print_untyped_exception_args (O.field bucket 1)) 0
|
|
|
|
else fprintf ppf "%s%a" name
|
|
|
|
(print_untyped_exception_args bucket) 1
|
1997-12-09 01:12:30 -08:00
|
|
|
|
1997-03-22 12:16:52 -08:00
|
|
|
(* The user-defined printers. Also used for some builtin types. *)
|
|
|
|
|
|
|
|
let printers = ref ([
|
|
|
|
Pident(Ident.create "print_int"), Predef.type_int,
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun ppf x -> fprintf ppf "%i" (O.obj x : int));
|
1997-03-22 12:16:52 -08:00
|
|
|
Pident(Ident.create "print_float"), Predef.type_float,
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun ppf x -> fprintf ppf "%f" (O.obj x : float));
|
1997-03-22 12:16:52 -08:00
|
|
|
Pident(Ident.create "print_char"), Predef.type_char,
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun ppf x ->
|
|
|
|
fprintf ppf "'%s'" (Char.escaped (O.obj x : char)));
|
1997-03-22 12:16:52 -08:00
|
|
|
Pident(Ident.create "print_string"), Predef.type_string,
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun ppf x ->
|
|
|
|
fprintf ppf "\"%s\"" (String.escaped (O.obj x : string)));
|
2000-03-05 11:18:50 -08:00
|
|
|
Pident(Ident.create "print_int32"), Predef.type_int32,
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun ppf x ->
|
|
|
|
fprintf ppf "<int32 %s>" (Int32.to_string (O.obj x : int32)));
|
2000-03-05 11:18:50 -08:00
|
|
|
Pident(Ident.create "print_nativeint"), Predef.type_nativeint,
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun ppf x ->
|
|
|
|
fprintf ppf "<nativeint %s>"
|
|
|
|
(Nativeint.to_string (O.obj x : nativeint)));
|
2000-03-05 11:18:50 -08:00
|
|
|
Pident(Ident.create "print_int64"), Predef.type_int64,
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun ppf x ->
|
|
|
|
fprintf ppf "<int64 %s>" (Int64.to_string (O.obj x : int64)));
|
|
|
|
] : (Path.t * type_expr * (Format.formatter -> O.t -> unit)) list)
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let install_printer path ty fn =
|
2000-03-06 14:12:09 -08:00
|
|
|
let print_val ppf obj =
|
1997-03-22 12:16:52 -08:00
|
|
|
try fn obj with
|
2000-03-06 14:12:09 -08:00
|
|
|
| exn ->
|
|
|
|
fprintf ppf "<printer %a raised an exception>" Printtyp.path path in
|
1997-03-22 12:16:52 -08:00
|
|
|
printers := (path, ty, print_val) :: !printers
|
|
|
|
|
|
|
|
let remove_printer path =
|
|
|
|
let rec remove = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| [] -> raise Not_found
|
1997-03-22 12:16:52 -08:00
|
|
|
| (p, ty, fn as printer) :: rem ->
|
|
|
|
if Path.same p path then rem else printer :: remove rem in
|
|
|
|
printers := remove !printers
|
|
|
|
|
|
|
|
let find_printer env ty =
|
|
|
|
let rec find = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| [] -> raise Not_found
|
1997-03-22 12:16:52 -08:00
|
|
|
| (name, sch, printer) :: remainder ->
|
1997-04-01 12:52:36 -08:00
|
|
|
if Ctype.moregeneral env false sch ty
|
1997-03-22 12:16:52 -08:00
|
|
|
then printer
|
|
|
|
else find remainder
|
|
|
|
in find !printers
|
|
|
|
|
|
|
|
(* Print a constructor or label, giving it the same prefix as the type
|
|
|
|
it comes from. Attempt to omit the prefix if the type comes from
|
|
|
|
a module that has been opened. *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let print_qualified lookup_fun env ty_path ppf name =
|
1997-03-22 12:16:52 -08:00
|
|
|
match ty_path with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Pident id ->
|
|
|
|
fprintf ppf "%s" name
|
1997-03-22 12:16:52 -08:00
|
|
|
| Pdot(p, s, pos) ->
|
|
|
|
if try
|
|
|
|
match (lookup_fun (Lident name) env).desc with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tconstr(ty_path', _, _) -> Path.same ty_path ty_path'
|
1997-03-22 12:16:52 -08:00
|
|
|
| _ -> false
|
|
|
|
with Not_found -> false
|
2000-03-06 14:12:09 -08:00
|
|
|
then fprintf ppf "%s" name
|
|
|
|
else fprintf ppf "%a.%s" Printtyp.path p name
|
1997-03-22 12:16:52 -08:00
|
|
|
| Papply(p1, p2) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
Printtyp.path ppf ty_path
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let print_constr =
|
|
|
|
print_qualified
|
|
|
|
(fun lid env -> (Env.lookup_constructor lid env).cstr_res)
|
|
|
|
|
|
|
|
and print_label =
|
|
|
|
print_qualified (fun lid env -> (Env.lookup_label lid env).lbl_res)
|
|
|
|
|
|
|
|
(* An abstract type *)
|
|
|
|
|
|
|
|
let abstract_type =
|
|
|
|
Ctype.newty (Tconstr (Pident (Ident.create "abstract"), [], ref Mnil))
|
|
|
|
|
|
|
|
(* The main printing function *)
|
|
|
|
|
|
|
|
exception Ellipsis
|
|
|
|
|
2000-03-07 11:33:06 -08:00
|
|
|
let cautious f ppf arg = try f arg with Ellipsis -> fprintf ppf "..."
|
1997-03-22 12:16:52 -08:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let print_value max_steps max_depth check_depth env obj ppf ty =
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let printer_steps = ref max_steps in
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec print_val prio depth obj ppf ty =
|
1997-03-22 12:16:52 -08:00
|
|
|
decr printer_steps;
|
|
|
|
if !printer_steps < 0 or depth < 0 then raise Ellipsis;
|
|
|
|
try
|
2000-03-06 14:12:09 -08:00
|
|
|
find_printer env ty ppf obj
|
1997-03-22 12:16:52 -08:00
|
|
|
with Not_found ->
|
|
|
|
match (Ctype.repr ty).desc with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tvar ->
|
|
|
|
fprintf ppf "<poly>"
|
1999-11-30 08:07:38 -08:00
|
|
|
| Tarrow(_, ty1, ty2) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "<fun>"
|
1997-03-22 12:16:52 -08:00
|
|
|
| Ttuple(ty_list) ->
|
|
|
|
if check_depth depth obj ty then begin
|
|
|
|
if prio > 0
|
2000-03-06 14:12:09 -08:00
|
|
|
then
|
2000-03-25 10:55:45 -08:00
|
|
|
fprintf ppf "@[<1>(%a)@]"
|
|
|
|
(print_val_list 1 0 depth obj) ty_list
|
|
|
|
else fprintf ppf "@[%a@]"
|
|
|
|
(print_val_list 1 0 depth obj) ty_list
|
1997-03-22 12:16:52 -08:00
|
|
|
end
|
|
|
|
| Tconstr(path, [], _) when Path.same path Predef.path_exn ->
|
2000-03-25 10:55:45 -08:00
|
|
|
print_exception prio depth ppf obj
|
1997-03-22 12:16:52 -08:00
|
|
|
| Tconstr(path, [ty_arg], _) when Path.same path Predef.path_list ->
|
1998-10-01 05:34:32 -07:00
|
|
|
if O.is_block obj then begin
|
1997-03-22 12:16:52 -08:00
|
|
|
if check_depth depth obj ty then begin
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec print_conses ppf cons =
|
|
|
|
print_val 0 (depth - 1) (O.field cons 0) ppf ty_arg;
|
1998-10-01 05:34:32 -07:00
|
|
|
let next_obj = O.field cons 1 in
|
2000-03-06 14:12:09 -08:00
|
|
|
if O.is_block next_obj then
|
|
|
|
fprintf ppf ";@ %a" print_conses next_obj
|
1997-03-22 12:16:52 -08:00
|
|
|
in
|
2000-03-07 11:33:06 -08:00
|
|
|
fprintf ppf "@[<1>[%a]@]" (cautious (print_conses ppf)) obj
|
1997-03-22 12:16:52 -08:00
|
|
|
end
|
|
|
|
end else
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "[]"
|
1997-03-22 12:16:52 -08:00
|
|
|
| Tconstr(path, [ty_arg], _) when Path.same path Predef.path_array ->
|
1998-10-01 05:34:32 -07:00
|
|
|
let length = O.size obj in
|
1997-03-22 12:16:52 -08:00
|
|
|
if length = 0 then
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "[||]"
|
1997-03-22 12:16:52 -08:00
|
|
|
else if check_depth depth obj ty then begin
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec print_items ppf i =
|
1997-03-22 12:16:52 -08:00
|
|
|
if i < length then begin
|
2000-03-06 14:12:09 -08:00
|
|
|
if i > 0 then fprintf ppf ";@ ";
|
|
|
|
print_val 0 (depth - 1) (O.field obj i) ppf ty_arg;
|
|
|
|
print_items ppf (i + 1)
|
1997-03-22 12:16:52 -08:00
|
|
|
end in
|
2000-03-07 11:33:06 -08:00
|
|
|
fprintf ppf "@[<2>[|%a|]@]" (cautious (print_items ppf)) 0;
|
1997-03-22 12:16:52 -08:00
|
|
|
end
|
|
|
|
| Tconstr(path, ty_list, _) ->
|
|
|
|
begin try
|
|
|
|
let decl = Env.find_type path env in
|
|
|
|
match decl with
|
2000-03-06 14:12:09 -08:00
|
|
|
| {type_kind = Type_abstract; type_manifest = None} ->
|
|
|
|
fprintf ppf "<abstr>"
|
1997-03-22 12:16:52 -08:00
|
|
|
| {type_kind = Type_abstract; type_manifest = Some body} ->
|
2000-03-06 14:12:09 -08:00
|
|
|
print_val prio depth obj ppf
|
1997-03-22 12:16:52 -08:00
|
|
|
(try Ctype.apply env decl.type_params body ty_list with
|
|
|
|
Ctype.Cannot_apply -> abstract_type)
|
|
|
|
| {type_kind = Type_variant constr_list} ->
|
|
|
|
let tag =
|
1998-10-01 05:34:32 -07:00
|
|
|
if O.is_block obj
|
|
|
|
then Cstr_block(O.tag obj)
|
|
|
|
else Cstr_constant(O.obj obj) in
|
1997-03-22 12:16:52 -08:00
|
|
|
let (constr_name, constr_args) =
|
1999-10-29 07:42:37 -07:00
|
|
|
Datarepr.find_constr_by_tag tag constr_list in
|
1997-03-22 12:16:52 -08:00
|
|
|
let ty_args =
|
|
|
|
List.map
|
|
|
|
(function ty ->
|
|
|
|
try Ctype.apply env decl.type_params ty ty_list with
|
|
|
|
Ctype.Cannot_apply -> abstract_type)
|
|
|
|
constr_args in
|
2000-03-25 10:55:45 -08:00
|
|
|
print_constr_with_args (print_constr env path) constr_name
|
|
|
|
prio 0 depth obj ppf ty_args
|
2000-03-21 06:43:25 -08:00
|
|
|
| {type_kind = Type_record(lbl_list, rep)} ->
|
1997-03-22 12:16:52 -08:00
|
|
|
if check_depth depth obj ty then begin
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec print_fields pos ppf = function
|
|
|
|
| [] -> ()
|
1997-03-22 12:16:52 -08:00
|
|
|
| (lbl_name, _, lbl_arg) :: remainder ->
|
|
|
|
let ty_arg =
|
|
|
|
try
|
|
|
|
Ctype.apply env decl.type_params lbl_arg ty_list
|
|
|
|
with
|
2000-03-06 14:12:09 -08:00
|
|
|
Ctype.Cannot_apply -> abstract_type in
|
|
|
|
if pos > 0 then fprintf ppf ";@ ";
|
|
|
|
fprintf ppf "@[<1>%a=@,%a@]"
|
|
|
|
(print_label env path) lbl_name
|
2000-03-07 11:33:06 -08:00
|
|
|
(cautious (print_val 0 (depth - 1)
|
|
|
|
(O.field obj pos) ppf))
|
|
|
|
ty_arg;
|
2000-03-06 14:12:09 -08:00
|
|
|
(print_fields (pos + 1)) ppf remainder in
|
|
|
|
|
|
|
|
fprintf ppf "@[<1>{%a}@]"
|
2000-03-07 11:33:06 -08:00
|
|
|
(cautious (print_fields 0 ppf)) lbl_list;
|
1997-03-22 12:16:52 -08:00
|
|
|
end
|
|
|
|
with
|
|
|
|
Not_found -> (* raised by Env.find_type *)
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "<abstr>"
|
1999-10-29 07:42:37 -07:00
|
|
|
| Datarepr.Constr_not_found -> (* raised by find_constr_by_tag *)
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "<unknown constructor>"
|
1997-03-22 12:16:52 -08:00
|
|
|
end
|
2000-01-07 08:47:25 -08:00
|
|
|
| Tvariant row ->
|
|
|
|
let row = Btype.row_repr row in
|
|
|
|
if O.is_block obj then begin
|
|
|
|
let tag : int = O.obj (O.field obj 0) in
|
2000-03-06 14:12:09 -08:00
|
|
|
(if prio > 1
|
|
|
|
then fprintf ppf "@[<2>(`%a)@]"
|
|
|
|
else fprintf ppf "`%a")
|
|
|
|
(fun ppf ->
|
|
|
|
List.iter
|
|
|
|
(fun (l, f) -> if Btype.hash_variant l = tag then
|
|
|
|
match Btype.row_field_repr f with
|
|
|
|
| Rpresent(Some ty) ->
|
2000-03-07 11:33:06 -08:00
|
|
|
fprintf ppf "%s@ %a" l
|
|
|
|
(cautious (print_val 2 (depth - 1) (O.field obj 1) ppf))
|
|
|
|
ty
|
2000-03-06 14:12:09 -08:00
|
|
|
| _ -> ()))
|
2000-01-07 08:47:25 -08:00
|
|
|
row.row_fields;
|
|
|
|
end else begin
|
|
|
|
let tag : int = O.obj obj in
|
2000-03-07 11:33:06 -08:00
|
|
|
let pr_rows ppf =
|
|
|
|
List.iter
|
|
|
|
(fun (l, _) ->
|
|
|
|
if Btype.hash_variant l = tag then fprintf ppf "%s" l) in
|
|
|
|
fprintf ppf "`%a" pr_rows row.row_fields
|
2000-01-07 08:47:25 -08:00
|
|
|
end
|
1997-03-22 12:16:52 -08:00
|
|
|
| Tobject (_, _) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "<obj>"
|
2000-01-07 08:47:25 -08:00
|
|
|
| Tsubst ty ->
|
2000-03-06 14:12:09 -08:00
|
|
|
print_val prio (depth - 1) obj ppf ty
|
1997-05-11 14:48:21 -07:00
|
|
|
| Tfield(_, _, _, _) | Tnil | Tlink _ ->
|
1997-03-22 12:16:52 -08:00
|
|
|
fatal_error "Printval.print_value"
|
|
|
|
|
2000-03-25 10:55:45 -08:00
|
|
|
and print_val_list prio start depth obj ppf ty_list =
|
1997-03-22 12:16:52 -08:00
|
|
|
let rec print_list i = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| [] -> ()
|
|
|
|
| ty :: ty_list ->
|
2000-03-25 10:55:45 -08:00
|
|
|
if i > start then fprintf ppf ",@ ";
|
2000-03-06 14:12:09 -08:00
|
|
|
print_val prio (depth - 1) (O.field obj i) ppf ty;
|
|
|
|
print_list (i + 1) ty_list in
|
2000-03-25 10:55:45 -08:00
|
|
|
cautious (print_list start) ppf ty_list
|
|
|
|
|
|
|
|
and print_constr_with_args
|
|
|
|
print_cstr cstr_name prio start depth obj ppf ty_args =
|
|
|
|
match ty_args with
|
|
|
|
[] ->
|
|
|
|
print_cstr ppf cstr_name
|
|
|
|
| [ty1] ->
|
|
|
|
if check_depth depth obj ty then
|
|
|
|
(if prio > 1
|
|
|
|
then fprintf ppf "@[<2>(%a@ %a)@]"
|
|
|
|
else fprintf ppf "@[<1>%a@ %a@]")
|
|
|
|
print_cstr cstr_name
|
|
|
|
(cautious
|
|
|
|
(print_val 2 (depth - 1) (O.field obj start) ppf))
|
|
|
|
ty1;
|
|
|
|
| tyl ->
|
|
|
|
if check_depth depth obj ty then
|
|
|
|
(if prio > 1
|
|
|
|
then fprintf ppf "@[<2>(%a@ @[<1>(%a)@])@]"
|
|
|
|
else fprintf ppf "@[<1>%a@ @[<1>(%a)@]@]")
|
|
|
|
print_cstr cstr_name
|
|
|
|
(print_val_list 1 start depth obj) tyl;
|
|
|
|
|
|
|
|
and print_exception prio depth ppf bucket =
|
|
|
|
let name = (O.obj(O.field(O.field bucket 0) 0) : string) in
|
|
|
|
let lid = Longident.parse name in
|
|
|
|
try
|
|
|
|
(* Attempt to recover the constructor description for the exn
|
|
|
|
from its name *)
|
|
|
|
let cstr = Env.lookup_constructor lid env in
|
|
|
|
let path =
|
|
|
|
match cstr.cstr_tag with
|
|
|
|
Cstr_exception p -> p | _ -> raise Not_found in
|
|
|
|
(* Make sure this is the right exception and not an homonym,
|
|
|
|
by evaluating the exception found and comparing with the identifier
|
|
|
|
contained in the exception bucket *)
|
2000-03-26 04:11:10 -08:00
|
|
|
if not (EVP.same_value (O.field bucket 0) (EVP.eval_path path))
|
|
|
|
then raise Not_found;
|
2000-03-25 10:55:45 -08:00
|
|
|
print_constr_with_args
|
|
|
|
pp_print_string name prio 1 depth bucket ppf cstr.cstr_args
|
|
|
|
with Not_found | EVP.Error ->
|
|
|
|
if check_depth depth obj ty then begin
|
|
|
|
if prio > 1
|
|
|
|
then fprintf ppf "@[<2>(%a)@]" print_untyped_exception obj
|
|
|
|
else fprintf ppf "@[<1>%a@]" print_untyped_exception obj
|
|
|
|
end
|
1997-03-22 12:16:52 -08:00
|
|
|
|
2000-03-07 11:33:06 -08:00
|
|
|
in cautious (print_val 0 max_depth obj ppf) ppf ty
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
end
|