1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
1996-05-16 07:16:34 -07:00
|
|
|
(* Xavier Leroy and Jerome Vouillon, projet Cristal, INRIA Rocquencourt*)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* 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. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Printing functions *)
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
open Misc
|
|
|
|
open Ctype
|
2000-03-06 14:12:09 -08:00
|
|
|
open Format
|
1995-05-04 03:15:53 -07:00
|
|
|
open Longident
|
|
|
|
open Path
|
|
|
|
open Asttypes
|
1996-09-23 04:33:27 -07:00
|
|
|
open Types
|
1997-03-24 12:11:22 -08:00
|
|
|
open Btype
|
2001-08-04 03:08:19 -07:00
|
|
|
open Outcometree
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Print a long identifier *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec longident ppf = function
|
|
|
|
| Lident s -> fprintf ppf "%s" s
|
|
|
|
| Ldot(p, s) -> fprintf ppf "%a.%s" longident p s
|
|
|
|
| Lapply(p1, p2) -> fprintf ppf "%a(%a)" longident p1 longident p2
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Print an identifier *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let ident ppf id = fprintf ppf "%s" (Ident.name id)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Print a path *)
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let ident_pervasive = Ident.create_persistent "Pervasives"
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2001-08-04 03:08:19 -07:00
|
|
|
let rec tree_of_path = function
|
|
|
|
| Pident id ->
|
|
|
|
Oide_ident (Ident.name id)
|
|
|
|
| Pdot(Pident id, s, pos) when Ident.same id ident_pervasive ->
|
|
|
|
Oide_ident s
|
|
|
|
| Pdot(p, s, pos) ->
|
|
|
|
Oide_dot (tree_of_path p, s)
|
|
|
|
| Papply(p1, p2) ->
|
|
|
|
Oide_apply (tree_of_path p1, tree_of_path p2)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec path ppf = function
|
|
|
|
| Pident id ->
|
|
|
|
ident ppf id
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pdot(Pident id, s, pos) when Ident.same id ident_pervasive ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "%s" s
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pdot(p, s, pos) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "%a.%s" path p s
|
1995-08-23 04:55:54 -07:00
|
|
|
| Papply(p1, p2) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "%a(%a)" path p1 path p2
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Print a type expression *)
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let names = ref ([] : (type_expr * string) list)
|
|
|
|
let name_counter = ref 0
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let reset_names () = names := []; name_counter := 0
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let new_name () =
|
|
|
|
let name =
|
|
|
|
if !name_counter < 26
|
|
|
|
then String.make 1 (Char.chr(97 + !name_counter))
|
|
|
|
else String.make 1 (Char.chr(97 + !name_counter mod 26)) ^
|
2000-03-06 14:12:09 -08:00
|
|
|
string_of_int(!name_counter / 26) in
|
|
|
|
incr name_counter;
|
|
|
|
name
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let name_of_type t =
|
|
|
|
try List.assq t !names with Not_found ->
|
|
|
|
let name = new_name () in
|
|
|
|
names := (t, name) :: !names;
|
|
|
|
name
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let check_name_of_type t = ignore(name_of_type t)
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let print_name_of_type ppf t = fprintf ppf "%s" (name_of_type t)
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let visited_objects = ref ([] : type_expr list)
|
|
|
|
let aliased = ref ([] : type_expr list)
|
|
|
|
|
2000-05-10 19:22:54 -07:00
|
|
|
let is_aliased ty = List.memq ty !aliased
|
|
|
|
let add_alias ty =
|
|
|
|
if not (is_aliased ty) then aliased := ty :: !aliased
|
2000-03-06 14:12:09 -08:00
|
|
|
|
1999-11-30 08:07:38 -08:00
|
|
|
let proxy ty =
|
|
|
|
let ty = repr ty in
|
|
|
|
match ty.desc with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tvariant row -> Btype.row_more row
|
1999-11-30 08:07:38 -08:00
|
|
|
| _ -> ty
|
|
|
|
|
|
|
|
let namable_row row =
|
2001-09-25 02:54:18 -07:00
|
|
|
row.row_name <> None &&
|
1999-11-30 08:07:38 -08:00
|
|
|
List.for_all
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun (_, f) ->
|
|
|
|
match row_field_repr f with
|
2001-09-25 02:54:18 -07:00
|
|
|
| Reither(c, l, _, _) ->
|
|
|
|
row.row_closed && if c then l = [] else List.length l = 1
|
2000-03-06 14:12:09 -08:00
|
|
|
| _ -> true)
|
1999-11-30 08:07:38 -08:00
|
|
|
row.row_fields
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let rec mark_loops_rec visited ty =
|
|
|
|
let ty = repr ty in
|
1999-11-30 08:07:38 -08:00
|
|
|
let px = proxy ty in
|
2000-03-06 14:12:09 -08:00
|
|
|
if List.memq px visited then add_alias px else
|
2000-02-24 19:33:54 -08:00
|
|
|
let visited = px :: visited in
|
1997-02-20 12:39:02 -08:00
|
|
|
match ty.desc with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tvar -> ()
|
2001-04-19 01:34:21 -07:00
|
|
|
| Tarrow(_, ty1, ty2, _) ->
|
1997-02-20 12:39:02 -08:00
|
|
|
mark_loops_rec visited ty1; mark_loops_rec visited ty2
|
2000-03-06 14:12:09 -08:00
|
|
|
| Ttuple tyl -> List.iter (mark_loops_rec visited) tyl
|
|
|
|
| Tconstr(_, tyl, _) ->
|
1997-02-20 12:39:02 -08:00
|
|
|
List.iter (mark_loops_rec visited) tyl
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tvariant row ->
|
1999-11-30 08:07:38 -08:00
|
|
|
let row = row_repr row in
|
2000-03-06 14:12:09 -08:00
|
|
|
if List.memq px !visited_objects then add_alias px else
|
|
|
|
begin
|
1999-11-30 08:07:38 -08:00
|
|
|
if not (static_row row) then
|
|
|
|
visited_objects := px :: !visited_objects;
|
|
|
|
match row.row_name with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Some(p, tyl) when namable_row row ->
|
1999-11-30 08:07:38 -08:00
|
|
|
List.iter (mark_loops_rec visited) tyl
|
|
|
|
| _ ->
|
2000-05-11 20:12:19 -07:00
|
|
|
iter_row (mark_loops_rec visited) {row with row_bound = []}
|
2000-03-06 14:12:09 -08:00
|
|
|
end
|
|
|
|
| Tobject (fi, nm) ->
|
|
|
|
if List.memq px !visited_objects then add_alias px else
|
|
|
|
begin
|
1997-02-20 12:39:02 -08:00
|
|
|
if opened_object ty then
|
1999-11-30 08:07:38 -08:00
|
|
|
visited_objects := px :: !visited_objects;
|
1997-02-20 12:39:02 -08:00
|
|
|
begin match !nm with
|
2000-03-06 14:12:09 -08:00
|
|
|
| None ->
|
1997-02-20 12:39:02 -08:00
|
|
|
mark_loops_rec visited fi
|
|
|
|
| Some (_, l) ->
|
|
|
|
List.iter (mark_loops_rec visited) l
|
|
|
|
end
|
|
|
|
end
|
1997-05-11 14:48:21 -07:00
|
|
|
| Tfield(_, kind, ty1, ty2) when field_kind_repr kind = Fpresent ->
|
1997-02-20 12:39:02 -08:00
|
|
|
mark_loops_rec visited ty1; mark_loops_rec visited ty2
|
1997-11-24 04:05:55 -08:00
|
|
|
| Tfield(_, _, _, ty2) ->
|
|
|
|
mark_loops_rec visited ty2
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tnil -> ()
|
|
|
|
| Tsubst ty -> mark_loops_rec visited ty
|
|
|
|
| Tlink _ -> fatal_error "Printtyp.mark_loops_rec (2)"
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2000-02-24 02:18:25 -08:00
|
|
|
let mark_loops ty =
|
|
|
|
normalize_type Env.empty ty;
|
2000-03-06 14:12:09 -08:00
|
|
|
mark_loops_rec [] ty;;
|
1996-04-22 04:15:41 -07:00
|
|
|
|
|
|
|
let reset_loop_marks () =
|
|
|
|
visited_objects := []; aliased := []
|
|
|
|
|
|
|
|
let reset () =
|
|
|
|
reset_names (); reset_loop_marks ()
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let reset_and_mark_loops ty =
|
|
|
|
reset (); mark_loops ty;;
|
|
|
|
|
|
|
|
let reset_and_mark_loops_list tyl =
|
|
|
|
reset (); List.iter mark_loops tyl;;
|
|
|
|
|
|
|
|
(* Disabled in classic mode when printing an unification error *)
|
1999-11-30 08:07:38 -08:00
|
|
|
let print_labels = ref true
|
2000-03-06 14:12:09 -08:00
|
|
|
let print_label ppf l =
|
|
|
|
if !print_labels && l <> "" || is_optional l then fprintf ppf "%s:" l
|
1999-11-30 08:07:38 -08:00
|
|
|
|
2000-03-28 22:09:03 -08:00
|
|
|
let rec print_list_init pr sep ppf = function
|
|
|
|
| [] -> ()
|
2000-09-07 03:57:32 -07:00
|
|
|
| a :: l -> sep ppf; pr ppf a; print_list_init pr sep ppf l;;
|
2000-03-28 22:09:03 -08:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec print_list pr sep ppf = function
|
|
|
|
| [] -> ()
|
2000-03-28 22:09:03 -08:00
|
|
|
| [a] -> pr ppf a
|
2000-09-07 03:57:32 -07:00
|
|
|
| a :: l -> pr ppf a; sep ppf; print_list pr sep ppf l;;
|
1999-11-30 08:07:38 -08:00
|
|
|
|
2001-08-04 03:08:19 -07:00
|
|
|
let rec tree_of_typexp sch ty =
|
1996-04-22 04:15:41 -07:00
|
|
|
let ty = repr ty in
|
1999-11-30 08:07:38 -08:00
|
|
|
let px = proxy ty in
|
2000-03-06 14:12:09 -08:00
|
|
|
if List.mem_assq px !names then
|
2001-08-04 03:08:19 -07:00
|
|
|
let mark = if ty.desc = Tvar then is_non_gen sch px else false in
|
|
|
|
Otyp_var (mark, name_of_type px) else
|
2000-03-06 14:12:09 -08:00
|
|
|
|
2001-08-04 03:08:19 -07:00
|
|
|
let pr_typ () =
|
2000-03-06 14:12:09 -08:00
|
|
|
(match ty.desc with
|
|
|
|
| Tvar ->
|
2001-08-04 03:08:19 -07:00
|
|
|
Otyp_var (is_non_gen sch ty, name_of_type ty)
|
2001-04-19 01:34:21 -07:00
|
|
|
| Tarrow(l, ty1, ty2, _) ->
|
2001-08-04 03:08:19 -07:00
|
|
|
let pr_arrow l ty1 ty2 =
|
|
|
|
let lab =
|
|
|
|
if !print_labels && l <> "" || is_optional l then l else ""
|
|
|
|
in
|
|
|
|
let t1 =
|
|
|
|
if is_optional l then
|
|
|
|
match (repr ty1).desc with
|
|
|
|
| Tconstr(path, [ty], _)
|
|
|
|
when Path.same path Predef.path_option ->
|
|
|
|
tree_of_typexp sch ty
|
|
|
|
| _ -> Otyp_stuff "<hidden>"
|
|
|
|
else tree_of_typexp sch ty1 in
|
|
|
|
Otyp_arrow (lab, t1, tree_of_typexp sch ty2) in
|
|
|
|
pr_arrow l ty1 ty2
|
1997-02-20 12:39:02 -08:00
|
|
|
| Ttuple tyl ->
|
2001-08-04 03:08:19 -07:00
|
|
|
Otyp_tuple (tree_of_typlist sch tyl)
|
1997-02-20 12:39:02 -08:00
|
|
|
| Tconstr(p, tyl, abbrev) ->
|
2001-08-04 03:08:19 -07:00
|
|
|
Otyp_constr (tree_of_path p, tree_of_typlist sch tyl)
|
1999-11-30 08:07:38 -08:00
|
|
|
| Tvariant row ->
|
|
|
|
let row = row_repr row in
|
|
|
|
let fields =
|
|
|
|
if row.row_closed then
|
2000-03-06 14:12:09 -08:00
|
|
|
List.filter (fun (_, f) -> row_field_repr f <> Rabsent)
|
1999-11-30 08:07:38 -08:00
|
|
|
row.row_fields
|
2000-03-06 14:12:09 -08:00
|
|
|
else row.row_fields in
|
1999-11-30 08:07:38 -08:00
|
|
|
let present =
|
|
|
|
List.filter
|
2000-03-06 14:12:09 -08:00
|
|
|
(fun (_, f) ->
|
|
|
|
match row_field_repr f with
|
|
|
|
| Rpresent _ -> true
|
|
|
|
| _ -> false)
|
1999-11-30 08:07:38 -08:00
|
|
|
fields in
|
|
|
|
let all_present = List.length present = List.length fields in
|
|
|
|
begin match row.row_name with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Some(p, tyl) when namable_row row ->
|
2001-08-04 03:08:19 -07:00
|
|
|
let id = tree_of_path p in
|
|
|
|
let args = tree_of_typlist sch tyl in
|
2001-09-25 02:54:18 -07:00
|
|
|
if row.row_closed && all_present then
|
2001-08-04 03:08:19 -07:00
|
|
|
Otyp_constr (id, args)
|
|
|
|
else
|
|
|
|
let non_gen = is_non_gen sch px in
|
2001-09-25 02:54:18 -07:00
|
|
|
let tags =
|
|
|
|
if all_present then None else Some (List.map fst present) in
|
|
|
|
Otyp_variant (non_gen, Ovar_name(tree_of_path p, args),
|
|
|
|
row.row_closed, tags)
|
1999-11-30 08:07:38 -08:00
|
|
|
| _ ->
|
2001-08-04 03:08:19 -07:00
|
|
|
let non_gen =
|
2001-09-25 02:54:18 -07:00
|
|
|
not (row.row_closed && all_present) && is_non_gen sch px in
|
|
|
|
let fields = List.map (tree_of_row_field sch) fields in
|
2001-08-04 03:08:19 -07:00
|
|
|
let tags =
|
2001-09-25 02:54:18 -07:00
|
|
|
if all_present then None else Some (List.map fst present) in
|
|
|
|
Otyp_variant (non_gen, Ovar_fields fields, row.row_closed, tags)
|
1999-11-30 08:07:38 -08:00
|
|
|
end
|
1997-02-20 12:39:02 -08:00
|
|
|
| Tobject (fi, nm) ->
|
2001-08-04 03:08:19 -07:00
|
|
|
tree_of_typobject sch ty fi nm
|
1999-11-30 08:07:38 -08:00
|
|
|
| Tsubst ty ->
|
2001-08-04 03:08:19 -07:00
|
|
|
tree_of_typexp sch ty
|
2000-05-24 20:09:28 -07:00
|
|
|
| Tlink _ | Tnil | Tfield _ ->
|
2001-08-04 03:08:19 -07:00
|
|
|
fatal_error "Printtyp.tree_of_typexp"
|
2000-03-06 14:12:09 -08:00
|
|
|
) in
|
2000-05-10 19:22:54 -07:00
|
|
|
if is_aliased px then begin
|
2000-03-06 14:12:09 -08:00
|
|
|
check_name_of_type px;
|
2001-08-04 03:08:19 -07:00
|
|
|
Otyp_alias (pr_typ (), name_of_type px) end
|
|
|
|
else pr_typ ()
|
|
|
|
|
|
|
|
and tree_of_row_field sch (l, f) =
|
|
|
|
match row_field_repr f with
|
|
|
|
| Rpresent None | Reither(true, [], _, _) -> (l, false, [])
|
|
|
|
| Rpresent(Some ty) -> (l, false, [tree_of_typexp sch ty])
|
|
|
|
| Reither(c, tyl, _, _) ->
|
|
|
|
if c (* contradiction: un constructeur constant qui a un argument *)
|
|
|
|
then (l, true, tree_of_typlist sch tyl)
|
|
|
|
else (l, false, tree_of_typlist sch tyl)
|
|
|
|
| Rabsent -> (l, false, [] (* une erreur, en fait *))
|
|
|
|
|
|
|
|
and tree_of_typlist sch = function
|
|
|
|
| [] -> []
|
|
|
|
| ty :: tyl -> tree_of_typexp sch ty :: tree_of_typlist sch tyl
|
|
|
|
|
|
|
|
and tree_of_typobject sch ty fi nm =
|
1997-02-20 12:39:02 -08:00
|
|
|
begin match !nm with
|
2000-03-06 14:12:09 -08:00
|
|
|
| None ->
|
2001-08-04 03:08:19 -07:00
|
|
|
let pr_fields fi =
|
2000-03-06 14:12:09 -08:00
|
|
|
let (fields, rest) = flatten_fields fi in
|
|
|
|
let present_fields =
|
|
|
|
List.fold_right
|
|
|
|
(fun (n, k, t) l ->
|
|
|
|
match field_kind_repr k with
|
|
|
|
| Fpresent -> (n, t) :: l
|
|
|
|
| _ -> l)
|
|
|
|
fields [] in
|
|
|
|
let sorted_fields =
|
|
|
|
Sort.list (fun (n, _) (n', _) -> n <= n') present_fields in
|
2001-08-04 03:08:19 -07:00
|
|
|
tree_of_typfields sch rest sorted_fields in
|
|
|
|
let (fields, rest) = pr_fields fi in
|
|
|
|
Otyp_object (fields, rest)
|
2000-03-06 14:12:09 -08:00
|
|
|
| Some (p, {desc = Tvar} :: tyl) ->
|
2001-08-04 03:08:19 -07:00
|
|
|
let non_gen = is_non_gen sch ty in
|
|
|
|
let args = tree_of_typlist sch tyl in
|
2001-09-25 02:54:18 -07:00
|
|
|
Otyp_class (non_gen, tree_of_path p, args)
|
1997-02-20 12:39:02 -08:00
|
|
|
| _ ->
|
2001-08-04 03:08:19 -07:00
|
|
|
fatal_error "Printtyp.tree_of_typobject"
|
1997-02-20 12:39:02 -08:00
|
|
|
end
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2001-08-04 03:08:19 -07:00
|
|
|
and is_non_gen sch ty =
|
|
|
|
sch && ty.level <> generic_level
|
2000-03-06 14:12:09 -08:00
|
|
|
|
2001-08-04 03:08:19 -07:00
|
|
|
and tree_of_typfields sch rest = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| [] ->
|
2001-08-04 03:08:19 -07:00
|
|
|
let rest =
|
|
|
|
match rest.desc with
|
|
|
|
| Tvar -> Some (is_non_gen sch rest)
|
|
|
|
| Tnil -> None
|
|
|
|
| _ -> fatal_error "typfields (1)"
|
|
|
|
in
|
|
|
|
([], rest)
|
|
|
|
| (s, t) :: l ->
|
|
|
|
let field = (s, tree_of_typexp sch t) in
|
|
|
|
let (fields, rest) = tree_of_typfields sch rest l in
|
|
|
|
(field :: fields, rest)
|
|
|
|
|
|
|
|
let rec print_ident ppf =
|
|
|
|
function
|
|
|
|
| Oide_ident s -> fprintf ppf "%s" s
|
|
|
|
| Oide_dot (id, s) -> fprintf ppf "%a.%s" print_ident id s
|
|
|
|
| Oide_apply (id1, id2) ->
|
|
|
|
fprintf ppf "%a(%a)" print_ident id1 print_ident id2
|
|
|
|
|
|
|
|
let pr_present =
|
|
|
|
print_list (fun ppf s -> fprintf ppf "`%s" s) (fun ppf -> fprintf ppf "@ ")
|
|
|
|
|
|
|
|
let rec print_out_type ppf =
|
|
|
|
function
|
|
|
|
| Otyp_alias (ty, s) ->
|
|
|
|
fprintf ppf "@[%a as '%s@]" print_out_type ty s
|
|
|
|
| ty ->
|
|
|
|
print_out_type_1 ppf ty
|
|
|
|
|
|
|
|
and print_out_type_1 ppf =
|
|
|
|
function
|
|
|
|
| Otyp_arrow (lab, ty1, ty2) ->
|
|
|
|
fprintf ppf "@[%s%a ->@ %a@]"
|
|
|
|
(if lab <> "" then lab ^ ":" else "")
|
|
|
|
print_out_type_2 ty1 print_out_type_1 ty2
|
|
|
|
| ty ->
|
|
|
|
print_out_type_2 ppf ty
|
|
|
|
|
|
|
|
and print_out_type_2 ppf =
|
|
|
|
function
|
|
|
|
| Otyp_tuple tyl ->
|
|
|
|
fprintf ppf "@[<0>%a@]" (print_typlist print_simple_out_type " *") tyl
|
|
|
|
| ty ->
|
|
|
|
print_simple_out_type ppf ty
|
|
|
|
|
|
|
|
and print_simple_out_type ppf =
|
|
|
|
function
|
2001-09-25 02:54:18 -07:00
|
|
|
| Otyp_class (ng, id, tyl) ->
|
|
|
|
fprintf ppf "@[%a%s#%a@]" print_typargs tyl
|
|
|
|
(if ng then "_" else "") print_ident id
|
2001-08-04 03:08:19 -07:00
|
|
|
| Otyp_constr (id, tyl) ->
|
|
|
|
fprintf ppf "@[%a%a@]" print_typargs tyl print_ident id
|
2001-08-07 01:03:04 -07:00
|
|
|
| Otyp_object (fields, rest) ->
|
|
|
|
fprintf ppf "@[<2>< %a >@]" (print_fields rest) fields
|
2001-08-04 03:08:19 -07:00
|
|
|
| Otyp_stuff s ->
|
|
|
|
fprintf ppf "%s" s
|
2001-08-07 01:03:04 -07:00
|
|
|
| Otyp_var (ng, s) ->
|
|
|
|
fprintf ppf "'%s%s" (if ng then "_" else "") s
|
2001-08-04 03:08:19 -07:00
|
|
|
| Otyp_variant (non_gen, row_fields, closed, tags) ->
|
|
|
|
let print_present ppf =
|
|
|
|
function
|
|
|
|
| None | Some [] -> ()
|
|
|
|
| Some l -> fprintf ppf "@;<1 -2>> @[<hov>%a@]" pr_present l
|
|
|
|
in
|
2001-09-25 02:54:18 -07:00
|
|
|
let print_fields ppf = function
|
|
|
|
Ovar_fields fields ->
|
|
|
|
print_list print_row_field (fun ppf -> fprintf ppf "@;<1 -2>| ")
|
|
|
|
ppf fields
|
|
|
|
| Ovar_name (id, tyl) ->
|
|
|
|
fprintf ppf "@[%a%a@]" print_typargs tyl print_ident id
|
|
|
|
in
|
2001-08-04 03:08:19 -07:00
|
|
|
fprintf ppf "%s[%s@[<hv>@[<hv>%a@]%a]@]"
|
|
|
|
(if non_gen then "_" else "")
|
|
|
|
(if closed then if tags = None then " " else "< "
|
|
|
|
else if tags = None then "> " else "? ")
|
2001-09-25 02:54:18 -07:00
|
|
|
print_fields row_fields
|
2001-08-04 03:08:19 -07:00
|
|
|
print_present tags
|
|
|
|
| Otyp_alias (_, _) | Otyp_arrow (_, _, _) | Otyp_tuple _ as ty ->
|
|
|
|
fprintf ppf "@[<1>(%a)@]" print_out_type ty
|
2001-08-06 05:28:50 -07:00
|
|
|
| Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> ()
|
2001-08-04 03:08:19 -07:00
|
|
|
|
|
|
|
and print_fields rest ppf =
|
|
|
|
function
|
|
|
|
| [] ->
|
|
|
|
begin match rest with
|
|
|
|
| Some non_gen -> fprintf ppf "%s.." (if non_gen then "_" else "")
|
|
|
|
| None -> ()
|
1996-04-22 04:15:41 -07:00
|
|
|
end
|
|
|
|
| [(s, t)] ->
|
2001-08-04 03:08:19 -07:00
|
|
|
fprintf ppf "%s : %a" s print_out_type t;
|
|
|
|
begin match rest with
|
|
|
|
| Some _ -> fprintf ppf ";@ "
|
|
|
|
| None -> ()
|
1996-04-22 04:15:41 -07:00
|
|
|
end;
|
2001-08-04 03:08:19 -07:00
|
|
|
print_fields rest ppf []
|
2000-03-06 14:12:09 -08:00
|
|
|
| (s, t) :: l ->
|
2001-08-04 03:08:19 -07:00
|
|
|
fprintf ppf "%s : %a;@ %a" s print_out_type t (print_fields rest) l
|
|
|
|
|
|
|
|
and print_row_field ppf (l, opt_amp, tyl) =
|
|
|
|
let pr_of ppf =
|
|
|
|
if opt_amp then fprintf ppf " of@ &@ "
|
|
|
|
else if tyl <> [] then fprintf ppf " of@ "
|
|
|
|
else fprintf ppf ""
|
|
|
|
in
|
|
|
|
fprintf ppf "@[<hv 2>`%s%t%a@]" l pr_of
|
|
|
|
(print_typlist print_out_type " &") tyl
|
|
|
|
|
|
|
|
and print_typlist print_elem sep ppf = function
|
|
|
|
| [] -> ()
|
|
|
|
| [ty] -> print_elem ppf ty
|
|
|
|
| ty :: tyl ->
|
|
|
|
fprintf ppf "%a%s@ %a"
|
|
|
|
print_elem ty sep (print_typlist print_elem sep) tyl
|
|
|
|
|
|
|
|
and print_typargs ppf =
|
|
|
|
function
|
|
|
|
| [] -> ()
|
|
|
|
| [ty1] -> fprintf ppf "%a@ " print_simple_out_type ty1
|
|
|
|
| tyl -> fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_out_type ",") tyl
|
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let outcome_type = ref print_out_type
|
2001-08-04 03:08:19 -07:00
|
|
|
|
|
|
|
let typexp sch prio ppf ty =
|
2001-08-06 05:28:50 -07:00
|
|
|
!outcome_type ppf (tree_of_typexp sch ty)
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let type_expr ppf ty = typexp false 0 ppf ty
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
and type_sch ppf ty = typexp true 0 ppf ty
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
and type_scheme ppf ty = reset_and_mark_loops ty; typexp true 0 ppf ty
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let tree_of_type_scheme ty = reset_and_mark_loops ty; tree_of_typexp true ty
|
|
|
|
|
|
|
|
(* Print modules types and signatures *)
|
|
|
|
|
|
|
|
let value_ident ppf name =
|
|
|
|
if List.mem name
|
|
|
|
["or"; "mod"; "land"; "lor"; "lxor"; "lsl"; "lsr"; "asr"]
|
|
|
|
then fprintf ppf "( %s )" name
|
|
|
|
else match name.[0] with
|
|
|
|
| 'a' .. 'z' | '\223' .. '\246' | '\248' .. '\255' | '_' ->
|
|
|
|
fprintf ppf "%s" name
|
|
|
|
| _ -> fprintf ppf "( %s )" name
|
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
let print_out_class_params ppf =
|
|
|
|
function
|
|
|
|
| [] -> ()
|
|
|
|
| tyl ->
|
|
|
|
fprintf ppf "@[<1>[%a]@]@ "
|
|
|
|
(print_list (fun ppf x -> fprintf ppf "'%s" x)
|
2001-08-07 13:04:59 -07:00
|
|
|
(fun ppf -> fprintf ppf ", "))
|
2001-08-07 01:03:04 -07:00
|
|
|
tyl
|
|
|
|
|
|
|
|
let rec print_out_class_type ppf =
|
|
|
|
function
|
|
|
|
| Octy_constr (id, tyl) ->
|
|
|
|
let pr_tyl ppf = function
|
|
|
|
| [] -> ()
|
|
|
|
| tyl ->
|
|
|
|
fprintf ppf "@[<1>[%a]@]@ "
|
|
|
|
(print_typlist print_out_type ",") tyl
|
|
|
|
in
|
|
|
|
fprintf ppf "@[%a%a@]" pr_tyl tyl print_ident id
|
|
|
|
| Octy_fun (lab, ty, cty) ->
|
|
|
|
fprintf ppf "@[%s%a ->@ %a@]"
|
|
|
|
(if lab <> "" then lab ^ ":" else "")
|
|
|
|
print_out_type_2 ty print_out_class_type cty
|
|
|
|
| Octy_signature (self_ty, csil) ->
|
|
|
|
let pr_param ppf =
|
|
|
|
function
|
|
|
|
| Some ty -> fprintf ppf "@ @[(%a)@]" print_out_type ty
|
|
|
|
| None -> ()
|
|
|
|
in
|
|
|
|
fprintf ppf "@[<hv 2>@[<2>object%a@]@ %a@;<1 -2>end@]"
|
|
|
|
pr_param self_ty
|
|
|
|
(print_list print_out_class_sig_item (fun ppf -> fprintf ppf "@ "))
|
|
|
|
csil
|
|
|
|
and print_out_class_sig_item ppf =
|
|
|
|
function
|
|
|
|
| Ocsg_constraint (ty1, ty2) ->
|
|
|
|
fprintf ppf "@[<2>constraint %a =@ %a@]" !outcome_type ty1
|
|
|
|
!outcome_type ty2
|
|
|
|
| Ocsg_method (name, priv, virt, ty) ->
|
|
|
|
fprintf ppf "@[<2>method %s%s%s :@ %a@]"
|
|
|
|
(if priv then "private " else "") (if virt then "virtual " else "")
|
|
|
|
name !outcome_type ty
|
|
|
|
| Ocsg_value (name, mut, ty) ->
|
|
|
|
fprintf ppf "@[<2>val %s%s :@ %a@]" (if mut then "mutable " else "") name
|
|
|
|
!outcome_type ty
|
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let rec print_out_module_type ppf =
|
|
|
|
function
|
2001-08-07 01:03:04 -07:00
|
|
|
| Omty_abstract -> ()
|
|
|
|
| Omty_functor (name, mty_arg, mty_res) ->
|
|
|
|
fprintf ppf "@[<2>functor@ (%s : %a) ->@ %a@]" name
|
|
|
|
print_out_module_type mty_arg print_out_module_type mty_res
|
2001-08-06 05:28:50 -07:00
|
|
|
| Omty_ident id ->
|
|
|
|
fprintf ppf "%a" print_ident id
|
|
|
|
| Omty_signature sg ->
|
|
|
|
fprintf ppf "@[<hv 2>sig@ %a@;<1 -2>end@]" print_signature_body sg
|
|
|
|
and print_signature_body ppf =
|
|
|
|
function
|
|
|
|
| [] -> ()
|
|
|
|
| item :: [] -> print_out_sig_item ppf item
|
|
|
|
| item :: items ->
|
|
|
|
fprintf ppf "%a@ %a" print_out_sig_item item print_signature_body items
|
|
|
|
and print_out_sig_item ppf =
|
|
|
|
function
|
2001-08-07 01:03:04 -07:00
|
|
|
| Osig_class (vir_flag, name, params, clt) ->
|
|
|
|
fprintf ppf "@[<2>class%s@ %a%s@ :@ %a@]"
|
2001-08-07 07:23:54 -07:00
|
|
|
(if vir_flag then " virtual" else "")
|
2001-08-07 01:03:04 -07:00
|
|
|
print_out_class_params params name print_out_class_type clt
|
|
|
|
| Osig_class_type (vir_flag, name, params, clt) ->
|
|
|
|
fprintf ppf "@[<2>class type%s@ %a%s@ =@ %a@]"
|
2001-08-07 07:23:54 -07:00
|
|
|
(if vir_flag then " virtual" else "")
|
2001-08-07 01:03:04 -07:00
|
|
|
print_out_class_params params name print_out_class_type clt
|
|
|
|
| Osig_exception (id, tyl) ->
|
|
|
|
fprintf ppf "@[<2>exception %a@]" print_out_constr (id, tyl)
|
|
|
|
| Osig_modtype (name, Omty_abstract) ->
|
|
|
|
fprintf ppf "@[<2>module type %s@]" name
|
|
|
|
| Osig_modtype (name, mty) ->
|
|
|
|
fprintf ppf "@[<2>module type %s =@ %a@]" name print_out_module_type mty
|
|
|
|
| Osig_module (name, mty) ->
|
|
|
|
fprintf ppf "@[<2>module %s :@ %a@]" name print_out_module_type mty
|
|
|
|
| Osig_type tdl ->
|
|
|
|
print_out_type_decl_list ppf tdl
|
2001-08-06 05:28:50 -07:00
|
|
|
| Osig_value (name, ty, prims) ->
|
|
|
|
let kwd = if prims = [] then "val" else "external" in
|
|
|
|
let pr_prims ppf =
|
|
|
|
function
|
|
|
|
| [] -> ()
|
|
|
|
| s :: sl ->
|
|
|
|
fprintf ppf "@ = \"%s\"" s;
|
|
|
|
List.iter (fun s -> fprintf ppf "@ \"%s\"" s) sl
|
|
|
|
in
|
|
|
|
fprintf ppf "@[<2>%s %a :@ %a%a@]"
|
|
|
|
kwd value_ident name !outcome_type ty pr_prims prims
|
|
|
|
and print_out_type_decl_list ppf =
|
|
|
|
function
|
|
|
|
| [] -> ()
|
|
|
|
| [x] -> print_out_type_decl "type" ppf x
|
|
|
|
| x :: l ->
|
|
|
|
print_out_type_decl "type" ppf x;
|
|
|
|
List.iter (fun x -> fprintf ppf "@ %a" (print_out_type_decl "and") x) l
|
|
|
|
and print_out_type_decl kwd ppf (name, args, ty, constraints) =
|
|
|
|
let print_constraints ppf params =
|
2001-08-07 01:03:04 -07:00
|
|
|
List.iter
|
|
|
|
(fun (ty1, ty2) ->
|
|
|
|
fprintf ppf "@ @[<2>constraint %a =@ %a@]" !outcome_type ty1
|
|
|
|
!outcome_type ty2)
|
|
|
|
params
|
2001-08-06 05:28:50 -07:00
|
|
|
in
|
|
|
|
let type_parameter ppf (ty,(co,cn)) =
|
|
|
|
fprintf ppf "%s'%s"
|
|
|
|
(if not cn then "+" else if not co then "-" else "") ty
|
|
|
|
in
|
|
|
|
let type_defined ppf =
|
|
|
|
match args with
|
|
|
|
| [] -> fprintf ppf "%s" name
|
|
|
|
| [arg] -> fprintf ppf "%a@ %s" type_parameter arg name
|
|
|
|
| _ ->
|
|
|
|
fprintf ppf "(@[%a)@]@ %s"
|
|
|
|
(print_list type_parameter (fun ppf -> fprintf ppf ",@ "))
|
|
|
|
args name
|
|
|
|
in
|
|
|
|
let print_manifest ppf =
|
|
|
|
function
|
|
|
|
| Otyp_manifest (ty, _) -> fprintf ppf " =@ %a" !outcome_type ty
|
|
|
|
| _ -> ()
|
|
|
|
in
|
|
|
|
let print_name_args ppf =
|
|
|
|
fprintf ppf "%s %t%a" kwd type_defined print_manifest ty
|
|
|
|
in
|
|
|
|
let ty =
|
|
|
|
match ty with
|
|
|
|
| Otyp_manifest (_, ty) -> ty
|
|
|
|
| _ -> ty
|
|
|
|
in
|
|
|
|
match ty with
|
|
|
|
| Otyp_abstract ->
|
|
|
|
fprintf ppf "@[<2>@[<hv 2>%t@]%a@]"
|
|
|
|
print_name_args print_constraints constraints
|
|
|
|
| Otyp_record lbls ->
|
|
|
|
fprintf ppf "@[<2>@[<hv 2>%t = {%a@;<1 -2>}@]@ %a@]"
|
|
|
|
print_name_args
|
|
|
|
(print_list_init print_out_label (fun ppf -> fprintf ppf "@ ")) lbls
|
|
|
|
print_constraints constraints
|
2001-08-07 01:03:04 -07:00
|
|
|
| Otyp_sum constrs ->
|
|
|
|
fprintf ppf "@[<2>@[<hv 2>%t =@;<1 2>%a@]%a@]"
|
|
|
|
print_name_args
|
|
|
|
(print_list print_out_constr (fun ppf -> fprintf ppf "@ | ")) constrs
|
|
|
|
print_constraints constraints
|
2001-08-06 05:28:50 -07:00
|
|
|
| ty ->
|
|
|
|
fprintf ppf "@[<2>@[<hv 2>%t = %a@]@ %a@]"
|
|
|
|
print_name_args !outcome_type ty
|
|
|
|
print_constraints constraints
|
|
|
|
and print_out_constr ppf (name, tyl) =
|
|
|
|
match tyl with
|
|
|
|
| [] -> fprintf ppf "%s" name
|
|
|
|
| _ ->
|
|
|
|
fprintf ppf "@[<2>%s of@ %a@]" name
|
|
|
|
(print_typlist print_simple_out_type " *") tyl
|
|
|
|
and print_out_label ppf (name, mut, arg) =
|
|
|
|
fprintf ppf "@[<2>%s%s :@ %a@];"
|
|
|
|
(if mut then "mutable " else "") name !outcome_type arg
|
|
|
|
|
|
|
|
let outcome_sig_item = ref print_out_sig_item
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Print one type declaration *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let constrain ppf ty =
|
1997-02-20 12:39:02 -08:00
|
|
|
let ty' = unalias ty in
|
2000-03-06 14:12:09 -08:00
|
|
|
if ty != ty'
|
|
|
|
then fprintf ppf "@ @[<2>constraint %a =@ %a@]" type_sch ty type_sch ty'
|
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
let tree_of_constraints params =
|
|
|
|
List.fold_right
|
|
|
|
(fun ty list ->
|
|
|
|
let ty' = unalias ty in
|
|
|
|
if ty != ty' then
|
|
|
|
(tree_of_typexp true ty, tree_of_typexp true ty') :: list
|
|
|
|
else list)
|
|
|
|
params []
|
|
|
|
|
2000-05-24 20:09:28 -07:00
|
|
|
let filter_params tyl =
|
|
|
|
let params =
|
|
|
|
List.fold_left
|
|
|
|
(fun tyl ty ->
|
|
|
|
let ty = repr ty in
|
|
|
|
if List.memq ty tyl then Btype.newgenty (Tsubst ty) :: tyl
|
|
|
|
else ty :: tyl)
|
|
|
|
[] tyl
|
|
|
|
in List.rev params
|
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let string_of_mutable = function
|
|
|
|
| Immutable -> ""
|
|
|
|
| Mutable -> "mutable "
|
|
|
|
|
|
|
|
let rec tree_of_type_decl id decl =
|
1997-02-20 12:39:02 -08:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
reset();
|
1997-02-20 12:39:02 -08:00
|
|
|
|
2000-05-24 20:09:28 -07:00
|
|
|
let params = filter_params decl.type_params in
|
1997-02-20 12:39:02 -08:00
|
|
|
|
|
|
|
aliased := params @ !aliased;
|
|
|
|
List.iter mark_loops params;
|
2000-06-27 22:47:42 -07:00
|
|
|
List.iter check_name_of_type (List.map proxy params);
|
1997-02-20 12:39:02 -08:00
|
|
|
begin match decl.type_manifest with
|
2000-03-06 14:12:09 -08:00
|
|
|
| None -> ()
|
1997-02-20 12:39:02 -08:00
|
|
|
| Some ty -> mark_loops ty
|
|
|
|
end;
|
|
|
|
begin match decl.type_kind with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Type_abstract -> ()
|
1997-02-20 12:39:02 -08:00
|
|
|
| Type_variant [] -> ()
|
|
|
|
| Type_variant cstrs ->
|
|
|
|
List.iter (fun (_, args) -> List.iter mark_loops args) cstrs
|
2000-03-21 06:43:25 -08:00
|
|
|
| Type_record(l, rep) ->
|
1997-02-20 12:39:02 -08:00
|
|
|
List.iter (fun (_, _, ty) -> mark_loops ty) l
|
|
|
|
end;
|
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let type_param =
|
|
|
|
function
|
|
|
|
| Otyp_var (_, id) -> id
|
|
|
|
| _ -> "?"
|
2000-09-07 03:57:32 -07:00
|
|
|
in
|
2001-08-06 05:28:50 -07:00
|
|
|
let type_defined decl =
|
2000-09-07 03:57:32 -07:00
|
|
|
if decl.type_kind = Type_abstract && decl.type_manifest = None
|
|
|
|
&& List.exists (fun x -> x <> (true, true)) decl.type_variance then
|
2001-08-06 05:28:50 -07:00
|
|
|
(Ident.name id,
|
|
|
|
List.combine
|
|
|
|
(List.map (fun ty -> type_param (tree_of_typexp false ty)) params)
|
|
|
|
decl.type_variance)
|
2000-09-07 03:57:32 -07:00
|
|
|
else
|
2001-08-06 05:28:50 -07:00
|
|
|
let ty =
|
|
|
|
tree_of_typexp false
|
|
|
|
(Btype.newgenty (Tconstr(Pident id, params, ref Mnil)))
|
|
|
|
in
|
|
|
|
match ty with
|
|
|
|
| Otyp_constr (Oide_ident id, tyl) ->
|
|
|
|
(id, List.map (fun ty -> (type_param ty, (true, true))) tyl)
|
|
|
|
| _ -> ("?", [])
|
2000-09-07 03:57:32 -07:00
|
|
|
in
|
2001-08-06 05:28:50 -07:00
|
|
|
let tree_of_manifest decl ty1 =
|
2000-03-08 08:48:10 -08:00
|
|
|
match decl.type_manifest with
|
2001-08-06 05:28:50 -07:00
|
|
|
| None -> ty1
|
|
|
|
| Some ty -> Otyp_manifest (tree_of_typexp false ty, ty1)
|
|
|
|
in
|
|
|
|
let (name, args) = type_defined decl in
|
|
|
|
let constraints = tree_of_constraints params in
|
|
|
|
let ty =
|
|
|
|
match decl.type_kind with
|
|
|
|
| Type_abstract ->
|
|
|
|
begin match decl.type_manifest with
|
|
|
|
| None -> Otyp_abstract
|
|
|
|
| Some ty -> tree_of_typexp false ty
|
|
|
|
end
|
|
|
|
| Type_variant cstrs ->
|
|
|
|
tree_of_manifest decl (Otyp_sum (List.map tree_of_constructor cstrs))
|
|
|
|
| Type_record(lbls, rep) ->
|
|
|
|
tree_of_manifest decl (Otyp_record (List.map tree_of_label lbls))
|
|
|
|
in
|
|
|
|
(name, args, ty, constraints)
|
2000-03-08 08:48:10 -08:00
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
and tree_of_constructor (name, args) =
|
|
|
|
(name, tree_of_typlist false args)
|
2000-03-08 08:48:10 -08:00
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
and tree_of_label (name, mut, arg) =
|
|
|
|
(name, mut = Mutable, tree_of_typexp false arg)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2001-08-07 05:12:33 -07:00
|
|
|
let tree_of_type_declaration id decl =
|
|
|
|
Osig_type [tree_of_type_decl id decl]
|
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let type_declaration id ppf decl =
|
2001-08-07 05:12:33 -07:00
|
|
|
!outcome_sig_item ppf (tree_of_type_declaration id decl)
|
1998-04-14 07:48:08 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Print an exception declaration *)
|
|
|
|
|
2001-08-07 05:12:33 -07:00
|
|
|
let tree_of_exception_declaration id decl =
|
2001-08-06 05:28:50 -07:00
|
|
|
let tyl = tree_of_typlist false decl in
|
2001-08-07 05:12:33 -07:00
|
|
|
Osig_exception (Ident.name id, tyl)
|
|
|
|
|
|
|
|
let exception_declaration id ppf decl =
|
|
|
|
!outcome_sig_item ppf (tree_of_exception_declaration id decl)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1995-05-05 03:05:18 -07:00
|
|
|
(* Print a value declaration *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let tree_of_value_description id decl =
|
|
|
|
let id = Ident.name id in
|
|
|
|
let ty = tree_of_type_scheme decl.val_type in
|
|
|
|
let prims =
|
|
|
|
match decl.val_kind with
|
|
|
|
| Val_prim p -> Primitive.description_list p
|
|
|
|
| _ -> []
|
|
|
|
in
|
|
|
|
Osig_value (id, ty, prims)
|
2000-03-06 14:12:09 -08:00
|
|
|
|
|
|
|
let value_description id ppf decl =
|
2001-08-06 05:28:50 -07:00
|
|
|
!outcome_sig_item ppf (tree_of_value_description id decl)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
(* Print a class type *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let class_var sch ppf l (m, t) =
|
|
|
|
fprintf ppf
|
|
|
|
"@ @[<2>val %s%s :@ %a@]" (string_of_mutable m) l (typexp sch 0) t
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let metho sch concrete ppf (lab, kind, ty) =
|
1998-06-24 12:22:26 -07:00
|
|
|
if lab <> "*dummy method*" then begin
|
2000-03-06 14:12:09 -08:00
|
|
|
let priv =
|
|
|
|
match field_kind_repr kind with
|
|
|
|
| Fvar _ (* {contents = None} *) -> "private "
|
|
|
|
| _ (* Fpresent *) -> "" in
|
|
|
|
let virt =
|
|
|
|
if Concr.mem lab concrete then "" else "virtual " in
|
|
|
|
fprintf ppf "@ @[<2>method %s%s%s :@ %a@]" priv virt lab (typexp sch 0) ty
|
1998-06-24 12:22:26 -07:00
|
|
|
end
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
let tree_of_metho sch concrete (lab, kind, ty) csil =
|
|
|
|
if lab <> "*dummy method*" then begin
|
|
|
|
let priv =
|
|
|
|
match field_kind_repr kind with
|
|
|
|
| Fvar _ (* {contents = None} *) -> true
|
|
|
|
| _ (* Fpresent *) -> false in
|
|
|
|
let virt = not (Concr.mem lab concrete) in
|
|
|
|
Ocsg_method (lab, priv, virt, tree_of_typexp sch ty) :: csil
|
|
|
|
end
|
|
|
|
else csil
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec prepare_class_type = function
|
|
|
|
| Tcty_constr (p, tyl, cty) ->
|
1998-06-24 12:22:26 -07:00
|
|
|
let sty = Ctype.self_type cty in
|
1998-11-29 10:02:58 -08:00
|
|
|
begin try
|
|
|
|
if List.memq sty !visited_objects then raise (Unify []);
|
|
|
|
List.iter (occur Env.empty sty) tyl;
|
|
|
|
List.iter mark_loops tyl
|
|
|
|
with Unify _ ->
|
|
|
|
prepare_class_type cty
|
|
|
|
end
|
1998-06-24 12:22:26 -07:00
|
|
|
| Tcty_signature sign ->
|
|
|
|
let sty = repr sign.cty_self in
|
|
|
|
(* Self may have a name *)
|
2000-05-10 19:22:54 -07:00
|
|
|
if List.memq sty !visited_objects then add_alias sty
|
|
|
|
else visited_objects := sty :: !visited_objects;
|
1998-11-24 13:55:05 -08:00
|
|
|
let (fields, _) =
|
|
|
|
Ctype.flatten_fields (Ctype.object_fields sign.cty_self)
|
|
|
|
in
|
|
|
|
List.iter (fun (_, _, ty) -> mark_loops ty) fields;
|
1998-06-24 12:22:26 -07:00
|
|
|
Vars.iter (fun _ (_, ty) -> mark_loops ty) sign.cty_vars
|
1999-11-30 08:07:38 -08:00
|
|
|
| Tcty_fun (_, ty, cty) ->
|
1998-11-29 10:02:58 -08:00
|
|
|
mark_loops ty;
|
|
|
|
prepare_class_type cty
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
let rec tree_of_class_type sch params =
|
|
|
|
function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tcty_constr (p', tyl, cty) ->
|
1998-06-24 12:22:26 -07:00
|
|
|
let sty = Ctype.self_type cty in
|
1998-11-29 10:02:58 -08:00
|
|
|
if List.memq sty !visited_objects then
|
2001-08-07 01:03:04 -07:00
|
|
|
tree_of_class_type sch params cty
|
2000-03-06 14:12:09 -08:00
|
|
|
else
|
2001-08-07 01:03:04 -07:00
|
|
|
Octy_constr (tree_of_path p', tree_of_typlist true tyl)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Tcty_signature sign ->
|
|
|
|
let sty = repr sign.cty_self in
|
2001-08-07 01:03:04 -07:00
|
|
|
let self_ty =
|
|
|
|
if is_aliased sty then Some (Otyp_var (false, name_of_type sty))
|
|
|
|
else None
|
|
|
|
in
|
1998-06-24 12:22:26 -07:00
|
|
|
let (fields, _) =
|
2001-08-07 01:03:04 -07:00
|
|
|
Ctype.flatten_fields (Ctype.object_fields sign.cty_self)
|
|
|
|
in
|
|
|
|
let csil = [] in
|
|
|
|
let csil =
|
|
|
|
List.fold_right (tree_of_metho sch sign.cty_concr) fields csil
|
|
|
|
in
|
|
|
|
let csil =
|
|
|
|
Vars.fold
|
|
|
|
(fun l (m, t) csil ->
|
|
|
|
Ocsg_value (l, m = Mutable, tree_of_typexp sch t) :: csil)
|
|
|
|
sign.cty_vars csil
|
|
|
|
in
|
|
|
|
let csil =
|
|
|
|
List.fold_right
|
|
|
|
(fun (ty1, ty2) csil -> Ocsg_constraint (ty1, ty2) :: csil)
|
|
|
|
(tree_of_constraints params) csil
|
|
|
|
in
|
|
|
|
Octy_signature (self_ty, csil)
|
1999-11-30 08:07:38 -08:00
|
|
|
| Tcty_fun (l, ty, cty) ->
|
2001-08-07 01:03:04 -07:00
|
|
|
let lab = if !print_labels && l <> "" || is_optional l then l else "" in
|
2000-03-06 14:12:09 -08:00
|
|
|
let ty =
|
|
|
|
if is_optional l then
|
|
|
|
match (repr ty).desc with
|
2000-06-12 00:07:01 -07:00
|
|
|
| Tconstr(path, [ty], _) when Path.same path Predef.path_option -> ty
|
|
|
|
| _ -> newconstr (Path.Pident(Ident.create "<hidden>")) []
|
2000-03-06 14:12:09 -08:00
|
|
|
else ty in
|
2001-08-07 01:03:04 -07:00
|
|
|
Octy_fun (lab, tree_of_typexp sch ty, tree_of_class_type sch params cty)
|
2000-03-06 14:12:09 -08:00
|
|
|
|
|
|
|
let class_type ppf cty =
|
1998-06-24 12:22:26 -07:00
|
|
|
reset ();
|
1998-11-29 10:02:58 -08:00
|
|
|
prepare_class_type cty;
|
2001-08-07 01:03:04 -07:00
|
|
|
print_out_class_type ppf (tree_of_class_type false [] cty)
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
let tree_of_class_params = function
|
|
|
|
| [] -> []
|
2001-08-04 03:08:19 -07:00
|
|
|
| params ->
|
|
|
|
let tyl = tree_of_typlist true params in
|
2001-08-07 01:03:04 -07:00
|
|
|
List.map (function Otyp_var (_, s) -> s | _ -> "?") tyl
|
2000-03-06 14:12:09 -08:00
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
let tree_of_class_declaration id cl =
|
2000-05-24 20:09:28 -07:00
|
|
|
let params = filter_params cl.cty_params in
|
1997-02-20 12:39:02 -08:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
reset ();
|
1997-02-20 12:39:02 -08:00
|
|
|
aliased := params @ !aliased;
|
1998-11-29 10:02:58 -08:00
|
|
|
prepare_class_type cl.cty_type;
|
1998-06-24 12:22:26 -07:00
|
|
|
let sty = self_type cl.cty_type in
|
1997-02-20 12:39:02 -08:00
|
|
|
List.iter mark_loops params;
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2000-06-27 22:47:42 -07:00
|
|
|
List.iter check_name_of_type (List.map proxy params);
|
2000-05-10 19:22:54 -07:00
|
|
|
if is_aliased sty then check_name_of_type sty;
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
let vir_flag = cl.cty_new = None in
|
|
|
|
Osig_class
|
|
|
|
(vir_flag, Ident.name id, tree_of_class_params params,
|
|
|
|
tree_of_class_type true params cl.cty_type)
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
let class_declaration id ppf cl =
|
|
|
|
!outcome_sig_item ppf (tree_of_class_declaration id cl)
|
|
|
|
|
|
|
|
let tree_of_cltype_declaration id cl =
|
1998-06-24 12:22:26 -07:00
|
|
|
let params = List.map repr cl.clty_params in
|
|
|
|
|
|
|
|
reset ();
|
|
|
|
aliased := params @ !aliased;
|
1998-11-29 10:02:58 -08:00
|
|
|
prepare_class_type cl.clty_type;
|
1998-06-24 12:22:26 -07:00
|
|
|
let sty = self_type cl.clty_type in
|
|
|
|
List.iter mark_loops params;
|
|
|
|
|
2000-06-27 22:47:42 -07:00
|
|
|
List.iter check_name_of_type (List.map proxy params);
|
2000-05-10 19:22:54 -07:00
|
|
|
if is_aliased sty then check_name_of_type sty;
|
1998-06-24 12:22:26 -07:00
|
|
|
|
|
|
|
let sign = Ctype.signature_of_class_type cl.clty_type in
|
2000-03-06 14:12:09 -08:00
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
let virt =
|
|
|
|
let (fields, _) =
|
2000-03-06 14:12:09 -08:00
|
|
|
Ctype.flatten_fields (Ctype.object_fields sign.cty_self) in
|
1998-06-24 12:22:26 -07:00
|
|
|
List.exists
|
|
|
|
(fun (lab, _, ty) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
not (lab = "*dummy method*" || Concr.mem lab sign.cty_concr))
|
|
|
|
fields in
|
|
|
|
|
2001-08-07 01:03:04 -07:00
|
|
|
Osig_class_type
|
|
|
|
(virt, Ident.name id, tree_of_class_params params,
|
|
|
|
tree_of_class_type true params cl.clty_type)
|
|
|
|
|
|
|
|
let cltype_declaration id ppf cl =
|
|
|
|
!outcome_sig_item ppf (tree_of_cltype_declaration id cl)
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Print a module type *)
|
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let rec tree_of_modtype = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tmty_ident p ->
|
2001-08-06 05:28:50 -07:00
|
|
|
Omty_ident (tree_of_path p)
|
1996-05-16 07:16:34 -07:00
|
|
|
| Tmty_signature sg ->
|
2001-08-06 05:28:50 -07:00
|
|
|
Omty_signature (tree_of_signature sg)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tmty_functor(param, ty_arg, ty_res) ->
|
2001-08-06 05:28:50 -07:00
|
|
|
Omty_functor
|
|
|
|
(Ident.name param, tree_of_modtype ty_arg, tree_of_modtype ty_res)
|
2000-03-06 14:12:09 -08:00
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
and tree_of_signature = function
|
|
|
|
| [] -> []
|
1996-05-16 07:16:34 -07:00
|
|
|
| item :: rem ->
|
2001-08-06 05:28:50 -07:00
|
|
|
match item with
|
|
|
|
| Tsig_value(id, decl) ->
|
|
|
|
tree_of_value_description id decl :: tree_of_signature rem
|
|
|
|
| Tsig_type(id, decl) ->
|
|
|
|
let (type_decl_list, rem) =
|
1998-04-14 07:48:08 -07:00
|
|
|
let rec more_type_declarations = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Tsig_type(id, decl) :: rem ->
|
2001-08-06 05:28:50 -07:00
|
|
|
let (type_decl_list, rem) = more_type_declarations rem in
|
|
|
|
(id, decl) :: type_decl_list, rem
|
|
|
|
| rem -> [], rem in
|
1998-04-14 07:48:08 -07:00
|
|
|
more_type_declarations rem
|
2001-08-06 05:28:50 -07:00
|
|
|
in
|
|
|
|
let type_decl_list =
|
|
|
|
List.map (fun (id, decl) -> tree_of_type_decl id decl)
|
|
|
|
((id, decl) :: type_decl_list)
|
|
|
|
in
|
|
|
|
Osig_type type_decl_list
|
|
|
|
::
|
|
|
|
tree_of_signature rem
|
|
|
|
| Tsig_exception(id, decl) ->
|
|
|
|
Osig_exception (Ident.name id, tree_of_typlist false decl) ::
|
|
|
|
tree_of_signature rem
|
|
|
|
| Tsig_module(id, mty) ->
|
|
|
|
Osig_module (Ident.name id, tree_of_modtype mty) ::
|
|
|
|
tree_of_signature rem
|
|
|
|
| Tsig_modtype(id, decl) ->
|
|
|
|
tree_of_modtype_declaration id decl :: tree_of_signature rem
|
|
|
|
| Tsig_class(id, decl) ->
|
|
|
|
let rem =
|
|
|
|
match rem with
|
2000-03-06 14:12:09 -08:00
|
|
|
| ctydecl :: tydecl1 :: tydecl2 :: rem -> rem
|
|
|
|
| _ -> []
|
2001-08-06 05:28:50 -07:00
|
|
|
in
|
2001-08-07 01:03:04 -07:00
|
|
|
tree_of_class_declaration id decl :: tree_of_signature rem
|
2001-08-06 05:28:50 -07:00
|
|
|
| Tsig_cltype(id, decl) ->
|
|
|
|
let rem =
|
|
|
|
match rem with
|
2000-03-09 08:53:08 -08:00
|
|
|
| tydecl1 :: tydecl2 :: rem -> rem
|
|
|
|
| _ -> []
|
2001-08-06 05:28:50 -07:00
|
|
|
in
|
2001-08-07 01:03:04 -07:00
|
|
|
tree_of_cltype_declaration id decl :: tree_of_signature rem
|
2001-08-06 05:28:50 -07:00
|
|
|
|
|
|
|
and tree_of_modtype_declaration id decl =
|
|
|
|
let mty =
|
|
|
|
match decl with
|
|
|
|
| Tmodtype_abstract -> Omty_abstract
|
|
|
|
| Tmodtype_manifest mty -> tree_of_modtype mty
|
|
|
|
in
|
|
|
|
Osig_modtype (Ident.name id, mty)
|
2000-03-06 14:12:09 -08:00
|
|
|
|
2001-08-07 05:12:33 -07:00
|
|
|
let tree_of_module id mty = Osig_module (Ident.name id, tree_of_modtype mty)
|
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let modtype ppf mty = print_out_module_type ppf (tree_of_modtype mty)
|
|
|
|
let modtype_declaration id ppf decl =
|
|
|
|
!outcome_sig_item ppf (tree_of_modtype_declaration id decl)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1999-02-16 10:29:28 -08:00
|
|
|
(* Print a signature body (used by -i when compiling a .ml) *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2001-08-15 16:37:59 -07:00
|
|
|
let print_signature ppf tree =
|
|
|
|
fprintf ppf "@[<v>%a@]" print_signature_body tree
|
|
|
|
let outcome_signature = ref print_signature
|
|
|
|
|
2001-08-06 05:28:50 -07:00
|
|
|
let signature ppf sg =
|
2001-08-15 16:37:59 -07:00
|
|
|
fprintf ppf "%a" !outcome_signature (tree_of_signature sg)
|
1996-05-20 09:43:29 -07:00
|
|
|
|
|
|
|
(* Print an unification error *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let type_expansion t ppf t' =
|
|
|
|
if t == t' then type_expr ppf t
|
|
|
|
else fprintf ppf "@[<2>%a@ =@ %a@]" type_expr t type_expr t'
|
1996-05-20 09:43:29 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec trace fst txt ppf = function
|
|
|
|
| (t1, t1') :: (t2, t2') :: rem ->
|
|
|
|
if not fst then fprintf ppf "@,";
|
|
|
|
fprintf ppf "@[Type@;<1 2>%a@ %s@;<1 2>%a@] %a"
|
|
|
|
(type_expansion t1) t1' txt (type_expansion t2) t2'
|
|
|
|
(trace false txt) rem
|
|
|
|
| _ -> ()
|
1996-05-20 09:43:29 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec mismatch = function
|
|
|
|
| [(_, t); (_, t')] -> (t, t')
|
|
|
|
| _ :: _ :: rem -> mismatch rem
|
|
|
|
| _ -> assert false
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let rec filter_trace = function
|
|
|
|
| (t1, t1') :: (t2, t2') :: rem ->
|
1998-06-24 12:22:26 -07:00
|
|
|
let rem' = filter_trace rem in
|
2000-03-06 14:12:09 -08:00
|
|
|
if t1 == t1' && t2 == t2'
|
1998-06-24 12:22:26 -07:00
|
|
|
then rem'
|
2000-03-06 14:12:09 -08:00
|
|
|
else (t1, t1') :: (t2, t2') :: rem'
|
|
|
|
| _ -> []
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2001-09-25 02:54:18 -07:00
|
|
|
(* Hide variant name and var, to force printing the expanded type *)
|
1999-11-30 08:07:38 -08:00
|
|
|
let hide_variant_name t =
|
|
|
|
match repr t with
|
2000-03-06 14:12:09 -08:00
|
|
|
| {desc = Tvariant row} as t when (row_repr row).row_name <> None ->
|
2001-09-25 02:54:18 -07:00
|
|
|
newty2 t.level
|
|
|
|
(Tvariant {(row_repr row) with row_name = None;
|
|
|
|
row_more = newty2 (row_more row).level Tvar})
|
2000-03-06 14:12:09 -08:00
|
|
|
| _ -> t
|
1999-11-30 08:07:38 -08:00
|
|
|
|
|
|
|
let prepare_expansion (t, t') =
|
|
|
|
let t' = hide_variant_name t' in
|
|
|
|
mark_loops t; if t != t' then mark_loops t';
|
|
|
|
(t, t')
|
|
|
|
|
2001-08-07 23:58:58 -07:00
|
|
|
let explanation unif t3 t4 ppf =
|
|
|
|
match t3.desc, t4.desc with
|
|
|
|
| Tfield _, Tvar | Tvar, Tfield _ ->
|
|
|
|
fprintf ppf "@,Self type cannot escape its class"
|
|
|
|
| Tconstr (p, _, _), Tvar
|
|
|
|
when unif && t4.level < Path.binding_time p ->
|
|
|
|
fprintf ppf
|
|
|
|
"@,@[The type constructor@;<1 2>%a@ would escape its scope@]"
|
|
|
|
path p
|
|
|
|
| Tvar, Tconstr (p, _, _)
|
|
|
|
when unif && t3.level < Path.binding_time p ->
|
|
|
|
fprintf ppf
|
|
|
|
"@,@[The type constructor@;<1 2>%a@ would escape its scope@]"
|
|
|
|
path p
|
|
|
|
| Tfield ("*dummy method*", _, _, _), _
|
|
|
|
| _, Tfield ("*dummy method*", _, _, _) ->
|
|
|
|
fprintf ppf
|
|
|
|
"@,Self type cannot be unified with a closed object type"
|
|
|
|
| Tfield (l, _, _, _), _ ->
|
|
|
|
fprintf ppf
|
|
|
|
"@,@[Only the first object type has a method %s@]" l
|
|
|
|
| _, Tfield (l, _, _, _) ->
|
|
|
|
fprintf ppf
|
|
|
|
"@,@[Only the second object type has a method %s@]" l
|
|
|
|
| _ -> ()
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let unification_error unif tr txt1 ppf txt2 =
|
1996-05-20 09:43:29 -07:00
|
|
|
reset ();
|
1999-11-30 08:07:38 -08:00
|
|
|
let tr = List.map (fun (t, t') -> (t, hide_variant_name t')) tr in
|
1998-06-24 12:22:26 -07:00
|
|
|
let (t3, t4) = mismatch tr in
|
|
|
|
match tr with
|
2000-03-06 14:12:09 -08:00
|
|
|
| [] | _ :: [] -> assert false
|
|
|
|
| t1 :: t2 :: tr ->
|
1999-11-30 08:07:38 -08:00
|
|
|
try
|
|
|
|
let t1, t1' = prepare_expansion t1
|
|
|
|
and t2, t2' = prepare_expansion t2 in
|
|
|
|
print_labels := not !Clflags.classic;
|
1998-06-24 12:22:26 -07:00
|
|
|
let tr = filter_trace tr in
|
1999-11-30 08:07:38 -08:00
|
|
|
let tr = List.map prepare_expansion tr in
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
|
|
|
"@[<v>\
|
|
|
|
@[%t@;<1 2>%a@ \
|
|
|
|
%t@;<1 2>%a\
|
|
|
|
@]%a%t\
|
|
|
|
@]"
|
|
|
|
txt1 (type_expansion t1) t1'
|
|
|
|
txt2 (type_expansion t2) t2'
|
|
|
|
(trace false "is not compatible with type") tr
|
2001-08-07 23:58:58 -07:00
|
|
|
(explanation unif t3 t4);
|
1999-11-30 08:07:38 -08:00
|
|
|
print_labels := true
|
|
|
|
with exn ->
|
|
|
|
print_labels := true;
|
|
|
|
raise exn
|
1998-08-15 06:50:50 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let report_unification_error ppf tr txt1 txt2 =
|
|
|
|
unification_error true tr txt1 ppf txt2;;
|
|
|
|
|
|
|
|
let trace fst txt ppf tr =
|
1999-11-30 08:07:38 -08:00
|
|
|
print_labels := not !Clflags.classic;
|
2000-08-10 20:19:51 -07:00
|
|
|
try match tr with
|
2001-08-07 23:58:58 -07:00
|
|
|
t1 :: t2 :: tr' ->
|
|
|
|
if fst then trace fst txt ppf (t1 :: t2 :: filter_trace tr')
|
|
|
|
else trace fst txt ppf (filter_trace tr);
|
2000-08-10 20:19:51 -07:00
|
|
|
print_labels := true
|
|
|
|
| _ -> ()
|
1999-11-30 08:07:38 -08:00
|
|
|
with exn ->
|
|
|
|
print_labels := true;
|
|
|
|
raise exn
|
2000-03-06 14:12:09 -08:00
|
|
|
|
2001-08-07 23:58:58 -07:00
|
|
|
let report_subtyping_error ppf tr1 txt1 tr2 =
|
|
|
|
reset ();
|
|
|
|
let tr1 = List.map prepare_expansion tr1
|
|
|
|
and tr2 = List.map prepare_expansion tr2 in
|
|
|
|
trace true txt1 ppf tr1;
|
|
|
|
let t3, t4 = mismatch tr2 in
|
|
|
|
trace false "is not compatible with type" ppf tr2;
|
|
|
|
explanation true t3 t4 ppf
|