| Anonymous | Login | Signup for a new account | 2013-05-20 04:21 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||||
| 0004347 | OCaml | OCamldoc | public | 2007-07-18 09:54 | 2007-11-10 14:54 | ||||||
| Reporter | matt | ||||||||||
| Assigned To | guesdon | ||||||||||
| Priority | normal | Severity | feature | Reproducibility | always | ||||||
| Status | assigned | Resolution | open | ||||||||
| Platform | OS | OS Version | |||||||||
| Product Version | 3.09.3 | ||||||||||
| Target Version | Fixed in Version | ||||||||||
| Summary | 0004347: Seems not possible to comment each case of polymorphic variant types ? | ||||||||||
| Description | (** General comment already taken into account *) type my_polyvar_typ = [ `First (** comment I would like to be treated like variants comments *) | `Second (** idem *) ] | ||||||||||
| Tags | No tags attached. | ||||||||||
| Attached Files | 9fffa49e88eb0f112e4c040e6fd161b3c05265e4
diff --git a/ocamldoc/.depend b/ocamldoc/.depend
index 5e2196a..2740d81 100644
--- a/ocamldoc/.depend
+++ b/ocamldoc/.depend
@@ -1,11 +1,3 @@
-odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
- odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
- odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
- ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
-odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
- odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
- odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
- ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_analyse.cmo: ../utils/warnings.cmi ../typing/typetexp.cmi \
../typing/types.cmi ../typing/typemod.cmi ../typing/typedtree.cmi \
../typing/typedecl.cmi ../typing/typecore.cmi ../typing/typeclass.cmi \
@@ -50,18 +42,22 @@ odoc_ast.cmx: ../typing/types.cmx ../typing/typedtree.cmx \
odoc_global.cmx odoc_exception.cmx odoc_env.cmx odoc_class.cmx \
odoc_args.cmx ../utils/misc.cmx ../parsing/location.cmx \
../typing/ident.cmx ../parsing/asttypes.cmi odoc_ast.cmi
+odoc_btype.cmo: ../typing/types.cmi ../typing/path.cmi odoc_type.cmo \
+ ../typing/btype.cmi ../parsing/asttypes.cmi
+odoc_btype.cmx: ../typing/types.cmx ../typing/path.cmx odoc_type.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi
odoc_class.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_parameter.cmo odoc_name.cmi
odoc_class.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
odoc_parameter.cmx odoc_name.cmx
+odoc_comments_global.cmo: odoc_comments_global.cmi
+odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_comments.cmo: odoc_types.cmi odoc_text.cmi odoc_see_lexer.cmo \
odoc_parser.cmi odoc_misc.cmi odoc_messages.cmo odoc_lexer.cmo \
odoc_global.cmi odoc_cross.cmi odoc_comments_global.cmi odoc_comments.cmi
odoc_comments.cmx: odoc_types.cmx odoc_text.cmx odoc_see_lexer.cmx \
odoc_parser.cmx odoc_misc.cmx odoc_messages.cmx odoc_lexer.cmx \
odoc_global.cmx odoc_cross.cmx odoc_comments_global.cmx odoc_comments.cmi
-odoc_comments_global.cmo: odoc_comments_global.cmi
-odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_config.cmo: ../utils/config.cmi odoc_config.cmi
odoc_config.cmx: ../utils/config.cmx odoc_config.cmi
odoc_cross.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_search.cmi \
@@ -72,6 +68,14 @@ odoc_cross.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_search.cmx \
odoc_scan.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx odoc_class.cmx \
odoc_cross.cmi
+odoc_ctype.cmo: ../typing/types.cmi ../typing/subst.cmi ../typing/path.cmi \
+ odoc_type.cmo odoc_btype.cmo ../utils/misc.cmi ../parsing/longident.cmi \
+ ../typing/ident.cmi ../typing/env.cmi ../utils/clflags.cmi \
+ ../typing/btype.cmi ../parsing/asttypes.cmi
+odoc_ctype.cmx: ../typing/types.cmx ../typing/subst.cmx ../typing/path.cmx \
+ odoc_type.cmx odoc_btype.cmx ../utils/misc.cmx ../parsing/longident.cmx \
+ ../typing/ident.cmx ../typing/env.cmx ../utils/clflags.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi
odoc_dag2html.cmo: odoc_info.cmi odoc_dag2html.cmi
odoc_dag2html.cmx: odoc_info.cmx odoc_dag2html.cmi
odoc_dep.cmo: ../parsing/parsetree.cmi odoc_type.cmo odoc_print.cmi \
@@ -130,6 +134,14 @@ odoc_misc.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
odoc_misc.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
odoc_types.cmx odoc_messages.cmx ../parsing/longident.cmx \
../typing/ctype.cmx ../typing/btype.cmx odoc_misc.cmi
+odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
+ odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
+ odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
+ ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
+odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
+ odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
+ odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
+ ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_module.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_type.cmo odoc_name.cmi odoc_exception.cmo odoc_class.cmo
odoc_module.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
@@ -146,6 +158,8 @@ odoc_opt.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
odoc_dot.cmx odoc_args.cmx odoc_analyse.cmx ../utils/misc.cmx \
../utils/config.cmx ../utils/clflags.cmx
+odoc_outcometree.cmo: odoc_types.cmi
+odoc_outcometree.cmx: odoc_types.cmx
odoc_parameter.cmo: ../typing/types.cmi odoc_types.cmi
odoc_parameter.cmx: ../typing/types.cmx odoc_types.cmx
odoc_parser.cmo: odoc_types.cmi odoc_comments_global.cmi odoc_parser.cmi
@@ -169,15 +183,15 @@ odoc_sig.cmo: ../typing/types.cmi ../typing/typedtree.cmi ../typing/path.cmi \
odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
odoc_misc.cmi odoc_messages.cmo odoc_merge.cmi odoc_global.cmi \
odoc_exception.cmo odoc_env.cmi odoc_class.cmo odoc_args.cmi \
- ../utils/misc.cmi ../parsing/location.cmi ../typing/btype.cmi \
- ../parsing/asttypes.cmi odoc_sig.cmi
+ ../utils/misc.cmi ../parsing/longident.cmi ../parsing/location.cmi \
+ ../typing/btype.cmi ../parsing/asttypes.cmi odoc_sig.cmi
odoc_sig.cmx: ../typing/types.cmx ../typing/typedtree.cmx ../typing/path.cmx \
../parsing/parsetree.cmi odoc_value.cmx odoc_types.cmx odoc_type.cmx \
odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_merge.cmx odoc_global.cmx \
odoc_exception.cmx odoc_env.cmx odoc_class.cmx odoc_args.cmx \
- ../utils/misc.cmx ../parsing/location.cmx ../typing/btype.cmx \
- ../parsing/asttypes.cmi odoc_sig.cmi
+ ../utils/misc.cmx ../parsing/longident.cmx ../parsing/location.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi odoc_sig.cmi
odoc_str.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_value.cmo \
odoc_type.cmo odoc_print.cmi odoc_name.cmi odoc_misc.cmi \
odoc_messages.cmo odoc_exception.cmo odoc_class.cmo odoc_str.cmi
@@ -188,12 +202,12 @@ odoc_test.cmo: odoc_info.cmi
odoc_test.cmx: odoc_info.cmx
odoc_texi.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_info.cmi
odoc_texi.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_info.cmx
+odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
+odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text.cmo: odoc_types.cmi odoc_text_parser.cmi odoc_text_lexer.cmo \
odoc_text.cmi
odoc_text.cmx: odoc_types.cmx odoc_text_parser.cmx odoc_text_lexer.cmx \
odoc_text.cmi
-odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
-odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text_parser.cmo: odoc_types.cmi odoc_misc.cmi odoc_text_parser.cmi
odoc_text_parser.cmx: odoc_types.cmx odoc_misc.cmx odoc_text_parser.cmi
odoc_to_text.cmo: odoc_messages.cmo odoc_info.cmi
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index efee6ea..51e6ea8 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -939,7 +939,8 @@ module Analyser =
List.filter pred l
(** Analysis of a parse tree structure with a typed tree, to return module elements.*)
- let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree =
+ let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree
+ poly_variant_tec_htbl =
print_DEBUG "Odoc_ast:analyse_struture";
let (table, table_values) = Typedtree_search.tables typedtree in
let rec iter env last_pos = function
@@ -977,6 +978,7 @@ module Analyser =
typedtree
table
table_values
+ poly_variant_tec_htbl
in
ele_comments @ elements @ (iter new_env (item.Parsetree.pstr_loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q)
in
@@ -984,7 +986,7 @@ module Analyser =
(** Analysis of a parse tree structure item to obtain a new environment and a list of elements.*)
and analyse_structure_item env current_module_name loc pos_limit comment_opt parsetree_item_desc typedtree
- table table_values =
+ table table_values poly_variant_tec_htbl =
print_DEBUG "Odoc_ast:analyse_struture_item";
match parsetree_item_desc with
Parsetree.Pstr_eval _ ->
@@ -1115,6 +1117,10 @@ module Analyser =
new_env name_comment_list
tt_type_decl.Types.type_kind
in
+ let tec = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (Sig.get_tec poly_variant_tec_htbl ct ~current_module_name ~name
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
let new_end = loc_end + maybe_more in
let t =
{
@@ -1133,6 +1139,7 @@ module Analyser =
(match tt_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tec = tec;
ty_loc = { loc_impl = Some (!file_name, loc_start) ; loc_inter = None } ;
ty_code =
(
@@ -1220,6 +1227,7 @@ module Analyser =
comment_opt
module_expr
tt_module_expr
+ poly_variant_tec_htbl
in
let code =
if !Odoc_args.keep_code then
@@ -1269,6 +1277,7 @@ module Analyser =
None
mod_exp
tt_mod_exp
+ poly_variant_tec_htbl
in
match new_module.m_type with
Types.Tmty_signature s ->
@@ -1304,6 +1313,7 @@ module Analyser =
com_opt
mod_exp
tt_mod_exp
+ poly_variant_tec_htbl
in
let eles = f loc_end q in
ele_comments @ ((Element_module new_module) :: eles)
@@ -1319,7 +1329,7 @@ module Analyser =
raise (Failure (Odoc_messages.module_type_not_found_in_typedtree complete_name))
in
let kind = Sig.analyse_module_type_kind env complete_name
- modtype tt_module_type
+ modtype tt_module_type poly_variant_tec_htbl
in
let mt =
{
@@ -1465,7 +1475,8 @@ module Analyser =
(0, env, [ Element_included_module im ]) (* A VOIR : étendre l'environnement ? avec quoi ? *)
(** Analysis of a [Parsetree.module_expr] and a name to return a [t_module].*)
- and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr =
+ and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr
+ poly_variant_tec_htbl =
let complete_name = Name.concat current_module_name module_name in
let pos_start = p_module_expr.Parsetree.pmod_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = p_module_expr.Parsetree.pmod_loc.Location.loc_end.Lexing.pos_cnum in
@@ -1504,7 +1515,8 @@ module Analyser =
ma_module = None ; } }
| (Parsetree.Pmod_structure p_structure, Typedtree.Tmod_structure tt_structure) ->
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start
+ pos_end p_structure tt_structure poly_variant_tec_htbl in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1519,6 +1531,7 @@ module Analyser =
let mp_name = Name.from_ident ident in
let mp_kind = Sig.analyse_module_type_kind env
current_module_name pmodule_type mtyp
+ poly_variant_tec_htbl
in
let param =
{
@@ -1538,6 +1551,7 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ poly_variant_tec_htbl
in
let kind = m_base2.m_kind in
{ m_base with m_kind = Module_functor (param, kind) }
@@ -1556,6 +1570,7 @@ module Analyser =
None
p_module_expr1
tt_module_expr1
+ poly_variant_tec_htbl
in
let m2 = analyse_module
env
@@ -1564,6 +1579,7 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ poly_variant_tec_htbl
in
{ m_base with m_kind = Module_apply (m1.m_kind, m2.m_kind) }
@@ -1577,10 +1593,11 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ poly_variant_tec_htbl
in
let mtkind = Sig.analyse_module_type_kind env
(Name.concat current_module_name "??")
- p_modtype tt_modtype
+ p_modtype tt_modtype poly_variant_tec_htbl
in
let tt_modtype = Odoc_env.subst_module_type env tt_modtype in
filter_module_with_module_type_constraint m_base2 tt_modtype;
@@ -1598,7 +1615,8 @@ module Analyser =
(* needed for recursive modules *)
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_structure + Typedtree.Tmod_constraint "^module_name);
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start pos_end
+ p_structure tt_structure poly_variant_tec_htbl in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1652,7 +1670,9 @@ module Analyser =
let (len,info_opt) = My_ir.first_special !file_name !file in
(* we must complete the included modules *)
- let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file) parsetree tree_structure in
+ let poly_variant_tec_htbl = Hashtbl.create 12 in
+ let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file)
+ parsetree tree_structure poly_variant_tec_htbl in
let included_modules_from_tt = tt_get_included_module_list tree_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
let kind = Module_struct elements2 in
diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml
index f34ad5e..e59790a 100644
--- a/ocamldoc/odoc_html.ml
+++ b/ocamldoc/odoc_html.ml
@@ -1098,8 +1098,23 @@ class html =
s2
(** Print html code to display a [Types.type_expr]. *)
- method html_of_type_expr b m_name t =
- let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_type_expr t) in
+ method html_of_type_expr ?tec b m_name t =
+ let str_of_com coms =
+ let b = Buffer.create 42 in
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ bs b "<code>";
+ bs b "(*";
+ bs b "</code></td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ self#html_of_text b coms;
+ bs b "</td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
+ bs b "<code>";
+ bs b "*)";
+ bs b "</code></td>";
+ Buffer.contents b in
+ let s = Odoc_info.remove_ending_newline
+ (Odoc_info.string_of_type_expr t ?tec ~str_of_com) in
let s2 = newline_to_indented_br s in
bs b "<code class=\"type\">";
bs b (self#create_fully_qualified_idents_links m_name s2);
@@ -1371,8 +1386,10 @@ class html =
match t.ty_manifest with
None -> ()
| Some typ ->
+ (*DEBUG*)print_tec ~tab: "html: "
+ (*DEBUG*) (match t.ty_tec with Some tec -> tec | _ -> Odoc_type.Pv_l []);
bs b "= ";
- self#html_of_type_expr b father typ;
+ self#html_of_type_expr b father typ ?tec: t.ty_tec;
bs b " "
);
(match t.ty_kind with
@@ -1814,7 +1831,8 @@ class html =
(Naming.type_target
{ ty_name = c.cl_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tec = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
@@ -1861,7 +1879,8 @@ class html =
(Naming.type_target
{ ty_name = ct.clt_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tec = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
diff --git a/ocamldoc/odoc_info.ml b/ocamldoc/odoc_info.ml
index 65735fd..67c385e 100644
--- a/ocamldoc/odoc_info.ml
+++ b/ocamldoc/odoc_info.ml
@@ -117,7 +117,7 @@ let reset_type_names = Printtyp.reset
let string_of_variance t (co,cn) = Odoc_str.string_of_variance t (co, cn)
-let string_of_type_expr t = Odoc_print.string_of_type_expr t
+let string_of_type_expr = Odoc_print.string_of_type_expr
let string_of_class_params = Odoc_str.string_of_class_params
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index e3638a7..1cc7f91 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -212,6 +212,10 @@ module Type :
| Type_record of record_field list * bool
(** fields * bool *)
+ type pvht = Odoc_type.pvht
+ and buc = Odoc_type.buc = {mutable coms: Odoc_types.text; tec: tec}
+ and tec = Odoc_type.tec = Pv_ht of pvht | Pv_l of tec list
+
(** Representation of a type. *)
type t_type = Odoc_type.t_type =
{
@@ -221,10 +225,13 @@ module Type :
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind ; (** Type kind. *)
ty_manifest : Types.type_expr option; (** Type manifest. *)
+ ty_tec : tec option;
mutable ty_loc : location ;
mutable ty_code : string option;
}
+ (*DEBUG*)val print_tec : ?tab: string -> Odoc_type.tec -> unit
+
end
(** Representation and manipulation of values, class attributes and class methods. *)
@@ -599,7 +606,10 @@ val reset_type_names : unit -> unit
val string_of_variance : Type.t_type -> (bool * bool) -> string
(** This function returns a string representing a Types.type_expr. *)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ Types.type_expr -> string
(** @return a string to display the parameters of the given class,
in the same form as the compiler. *)
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index 6e4afc7..c246e47 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -36,12 +36,443 @@ let _ =
let (modtype_fmt, flush_modtype_fmt) = new_fmt ()
+module Odoc_oprint =
+ struct
+ open Format
+ open Outcometree
+ 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 rec print_list_init pr sep ppf =
+ function
+ [] -> ()
+ | a :: l -> sep ppf; pr ppf a; print_list_init pr sep ppf l
-let string_of_type_expr t =
+ let rec print_list pr sep ppf =
+ function
+ [] -> ()
+ | [a] -> pr ppf a
+ | a :: l -> pr ppf a; sep ppf; print_list pr sep ppf l
+
+ let pr_present =
+ print_list (fun ppf s -> fprintf ppf "`%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let pr_vars =
+ print_list (fun ppf s -> fprintf ppf "'%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let rec print_out_type
+ ?(tec = Odoc_type.Pv_l [])
+ ?(str_of_com = Odoc_misc.string_of_text)
+ ppf =
+ function
+ | Otyp_alias (ty, s) ->
+ (*DEBUG*)prerr_endline "print_out_type (alias)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ fprintf ppf "@[%a@ as '%s@]" (print_out_type ~tec ~str_of_com) ty s
+ | Otyp_poly (sl, ty) ->
+ (*DEBUG*)prerr_endline "print_out_type (poly)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ fprintf ppf "@[<hov 2>%a.@ %a@]"
+ pr_vars sl
+ (print_out_type ~tec ~str_of_com) ty
+ | ty ->
+ (*DEBUG*)prerr_endline "print_out_type";
+ (*DEBUG*)Odoc_type.print_tec tec ~tab: "pot: ";
+ print_out_type_1 ppf ty ~tec ~str_of_com
+
+ and print_out_type_1 ~tec ~str_of_com ppf =
+ function
+ Otyp_arrow (lab, ty1, ty2) ->
+ (*DEBUG*)prerr_endline "print_out_type_1 (arrow)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ let tec1, tec2 = match tec with
+ Odoc_type.Pv_l [x;y] -> x, y
+ | _ -> Odoc_type.Pv_l [], Odoc_type.Pv_l [] in
+ fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "")
+ (print_out_type_2 ~tec: tec1 ~str_of_com) ty1
+ (print_out_type_1 ~tec: tec2 ~str_of_com) ty2
+ | ty ->
+ (*DEBUG*)prerr_endline "print_out_type_1";
+ (*DEBUG*)Odoc_type.print_tec tec ~tab: "pot1: ";
+ print_out_type_2 ppf ty ~tec ~str_of_com
+ and print_out_type_2 ~tec ~str_of_com ppf =
+ function
+ Otyp_tuple tyl ->
+ (*DEBUG*)prerr_endline "print_out_type_2 (tuple)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Odoc_type.Pv_l (tec::t) -> tecr := Odoc_type.Pv_l t; tec
+ | _ -> Odoc_type.Pv_l [] in
+ print_simple_out_type ~tec ~str_of_com ty
+ in fprintf ppf "@[<0>%a@]" (print_typlist print_elem " *") tyl
+ | ty ->
+ (*DEBUG*)prerr_endline "print_out_type_2";
+ (*DEBUG*)Odoc_type.print_tec tec ~tab: "pot2: ";
+ print_simple_out_type ppf ty ~tec ~str_of_com
+ and print_simple_out_type ~tec ~str_of_com ppf =
+ function
+ Otyp_class (ng, id, tyl) ->
+ (*DEBUG*)prerr_endline "print_simple_out_type (class)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ fprintf ppf "@[%a%s#%a@]" (print_typargs ~tec ~str_of_com) tyl
+ (if ng then "_" else "")
+ print_ident id
+ | Otyp_constr (id, tyl) ->
+ (*DEBUG*)prerr_endline "print_simple_out_type (constr)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ fprintf ppf "@[%a%a@]" (print_typargs ~tec ~str_of_com) tyl print_ident id
+ | Otyp_object (fields, rest) ->
+ (*DEBUG*)prerr_endline "print_simple_out_type (object)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ fprintf ppf "@[<2>< %a >@]" (print_fields rest ~tec ~str_of_com) fields
+ | Otyp_stuff s -> fprintf ppf "%s" s
+ | Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s
+ | Otyp_variant (non_gen, row_fields, closed, tags) ->
+ (*DEBUG*)prerr_endline "print_simple_out_type (variant)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ let print_present ppf =
+ function
+ None | Some [] -> ()
+ | Some l -> fprintf ppf "@;<1 -2>> @[<hov>%a@]" pr_present l
+ in
+ let print_fields ~tec ~str_of_com ppf =
+ function
+ Ovar_fields fields ->
+ print_list
+ (print_row_field ~tec ~str_of_com)
+ (fun ppf -> fprintf ppf "@;<1 -2>| ")
+ ppf fields
+ | Ovar_name (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com) tyl
+ print_ident id
+ in
+ 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 "? ")
+ (print_fields ~tec ~str_of_com) row_fields
+ print_present tags
+ | Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty ->
+ (*DEBUG*)prerr_endline "print_simple_out_type (alias;poly;arrow;tuple)";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ fprintf ppf "@[<1>(%a)@]" (print_out_type ~tec ~str_of_com) ty
+ | Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> ()
+ and print_fields ~tec ~str_of_com rest ppf =
+ function
+ [] ->
+ begin match rest with
+ Some non_gen -> fprintf ppf "%s.." (if non_gen then "_" else "")
+ | None -> ()
+ end
+ | [s, t] ->
+ let tec = match tec with Odoc_type.Pv_l [h] -> h
+ | _ -> Odoc_type.Pv_l [] in
+ fprintf ppf "%s : %a" s (print_out_type ~tec ~str_of_com) t;
+ begin match rest with
+ Some _ -> fprintf ppf ";@ "
+ | None -> () end;
+ print_fields ~tec: (Odoc_type.Pv_l []) ~str_of_com rest ppf []
+ | (s, t) :: l ->
+ let tec, tec' = match tec with Odoc_type.Pv_l (h::t) -> h, Odoc_type.Pv_l t
+ | _ -> Odoc_type.Pv_l [], Odoc_type.Pv_l [] in
+ fprintf ppf "%s : %a;@ %a" s (print_out_type ~tec ~str_of_com) t
+ (print_fields rest ~tec: tec' ~str_of_com) l
+ and print_row_field ~tec ~str_of_com ppf (l, opt_amp, tyl) =
+ (*DEBUG*)prerr_endline "print_row_field";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ let pr_of ppf =
+ if opt_amp then fprintf ppf " of@ &@ "
+ else if tyl <> [] then fprintf ppf " of@ "
+ else fprintf ppf ""
+ in
+ let {Odoc_type.coms=coms; tec=tec} =
+ try match tec with
+ Odoc_type.Pv_ht ht -> Hashtbl.find ht l
+ | _ -> {Odoc_type.coms=[];tec=Odoc_type.Pv_l []}
+ with Not_found -> {Odoc_type.coms=[];tec=Odoc_type.Pv_l []} in
+ let str_coms =
+ if coms <> []
+ then str_of_com coms
+ else "" in
+ fprintf ppf "@[<hv 2>`%s%t%a%s%s@]"
+ l pr_of
+ (print_typlist (print_out_type ~tec ~str_of_com) " &") tyl
+ (if coms = [] then "" else " ")
+ str_coms
+ 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 ~tec ~str_of_com ppf =
+ (*DEBUG*)prerr_endline "print_typargs";
+ (*DEBUG*)Odoc_type.print_tec tec;
+ function
+ [] -> ()
+ | [ty1] ->
+ let tec = match tec with Odoc_type.Pv_l (h::t) -> h
+ | _ -> Odoc_type.Pv_l [] in
+ fprintf ppf "%a@ " (print_simple_out_type ~tec ~str_of_com) ty1
+ | tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Odoc_type.Pv_l (tec::t) -> tecr := Odoc_type.Pv_l t; tec
+ | _ -> Odoc_type.Pv_l [] in
+ print_out_type ~tec ~str_of_com ty
+ in fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_elem ",") tyl
+
+ let out_type = ref print_out_type
+ end
+
+module Odoc_printtyp =
+ struct
+ open Misc
+ open Ctype
+ open Format
+ open Longident
+ open Path
+ open Asttypes
+ open Types
+ open Odoc_type
+ open Btype
+ open Outcometree
+ open Printtyp
+
+let names = ref ([] : (type_expr * string) list)
+let name_counter = ref 0
+
+let reset_names () = names := []; name_counter := 0
+
+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)) ^
+ string_of_int(!name_counter / 26) in
+ incr name_counter;
+ name
+
+let name_of_type t =
+ try List.assq t !names with Not_found ->
+ let name = new_name () in
+ names := (t, name) :: !names;
+ name
+
+let check_name_of_type t = ignore(name_of_type t)
+
+let non_gen_mark sch ty =
+ if sch && ty.desc = Tvar && ty.level <> generic_level then "_" else ""
+
+let print_name_of_type sch ppf t =
+ fprintf ppf "'%s%s" (non_gen_mark sch t) (name_of_type t)
+
+let visited_objects = ref ([] : type_expr list)
+let aliased = ref ([] : type_expr list)
+let delayed = ref ([] : type_expr list)
+
+let add_delayed t =
+ if not (List.memq t !delayed) then delayed := t :: !delayed
+
+let is_aliased ty = List.memq (proxy ty) !aliased
+let add_alias ty =
+ let px = proxy ty in
+ if not (is_aliased px) then aliased := px :: !aliased
+let aliasable ty =
+ match ty.desc with Tvar | Tunivar | Tpoly _ -> false | _ -> true
+
+let namable_row row =
+ row.row_name <> None &&
+ List.for_all
+ (fun (_, f) ->
+ match row_field_repr f with
+ | Reither(c, l, _, _) ->
+ row.row_closed && if c then l = [] else List.length l = 1
+ | _ -> true)
+ row.row_fields
+
+(* Disabled in classic mode when printing an unification error *)
+let print_labels = ref true
+let print_label ppf l =
+ if !print_labels && l <> "" || is_optional l then fprintf ppf "%s:" l
+
+let rec tree_of_typexp sch ty =
+ let ty = repr ty in
+ let px = proxy ty in
+ if List.mem_assq px !names && not (List.memq px !delayed) then
+ let mark = is_non_gen sch ty in
+ Otyp_var (mark, name_of_type px) else
+
+ let pr_typ () =
+ match ty.desc with
+ | Tvar ->
+ Otyp_var (is_non_gen sch ty, name_of_type ty)
+ | Tarrow(l, ty1, ty2, _) ->
+ 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
+ | Ttuple tyl ->
+ Otyp_tuple (tree_of_typlist sch tyl)
+ | Tconstr(p, tyl, abbrev) ->
+ Otyp_constr (tree_of_path p, tree_of_typlist sch tyl)
+ | Tvariant row ->
+ let row = row_repr row in
+ let fields =
+ if row.row_closed then
+ List.filter (fun (_, f) -> row_field_repr f <> Rabsent)
+ row.row_fields
+ else row.row_fields in
+ let present =
+ List.filter
+ (fun (_, f) ->
+ match row_field_repr f with
+ | Rpresent _ -> true
+ | _ -> false)
+ fields in
+ let all_present = List.length present = List.length fields in
+ begin match row.row_name with
+ | Some(p, tyl) when namable_row row ->
+ let id = tree_of_path p in
+ let args = tree_of_typlist sch tyl in
+ if row.row_closed && all_present then
+ Otyp_constr (id, args)
+ else
+ let non_gen = is_non_gen sch px in
+ 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)
+ | _ ->
+ let non_gen =
+ not (row.row_closed && all_present) && is_non_gen sch px in
+ let fields = List.map (tree_of_row_field sch) fields in
+ let tags =
+ if all_present then None else Some (List.map fst present) in
+ Otyp_variant (non_gen, Ovar_fields fields, row.row_closed, tags)
+ end
+ | Tobject (fi, nm) ->
+ tree_of_typobject sch fi nm
+ | Tsubst ty ->
+ tree_of_typexp sch ty
+ | Tlink _ | Tnil | Tfield _ ->
+ fatal_error "Printtyp.tree_of_typexp"
+ | Tpoly (ty, []) ->
+ tree_of_typexp sch ty
+ | Tpoly (ty, tyl) ->
+ let tyl = List.map repr tyl in
+ (* let tyl = List.filter is_aliased tyl in *)
+ if tyl = [] then tree_of_typexp sch ty else begin
+ let old_delayed = !delayed in
+ List.iter add_delayed tyl;
+ let tl = List.map name_of_type tyl in
+ let tr = Otyp_poly (tl, tree_of_typexp sch ty) in
+ delayed := old_delayed; tr
+ end
+ | Tunivar ->
+ Otyp_var (false, name_of_type ty)
+ in
+ if List.memq px !delayed then delayed := List.filter ((!=) px) !delayed;
+ if is_aliased px && aliasable ty then begin
+ check_name_of_type px;
+ 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 tyl =
+ List.map (tree_of_typexp sch) tyl
+
+and tree_of_typobject sch fi nm =
+ begin match !nm with
+ | None ->
+ let pr_fields fi =
+ 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
+ tree_of_typfields sch rest sorted_fields in
+ let (fields, rest) = pr_fields fi in
+ Otyp_object (fields, rest)
+ | Some (p, ty :: tyl) ->
+ let non_gen = is_non_gen sch (repr ty) in
+ let args = tree_of_typlist sch tyl in
+ Otyp_class (non_gen, tree_of_path p, args)
+ | _ ->
+ fatal_error "Printtyp.tree_of_typobject"
+ end
+
+and is_non_gen sch ty =
+ sch && ty.desc = Tvar && ty.level <> generic_level
+
+and tree_of_typfields sch rest = function
+ | [] ->
+ let rest =
+ match rest.desc with
+ | Tvar | Tunivar -> Some (is_non_gen sch rest)
+ | Tconstr _ -> Some false
+ | 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 typexp ?tec ?str_of_com sch prio ppf ty =
+ !Odoc_oprint.out_type ?tec ?str_of_com ppf
+ (tree_of_typexp sch ty)
+
+ let type_scheme
+ ?tec ?str_of_com
+ ?(b_reset_names = true)
+ ppf ty =
+ if b_reset_names then reset_names () ;
+ typexp true 0 ppf ty ?tec ?str_of_com
+ end
+
+let type_scheme = Odoc_printtyp.type_scheme
+
+let string_of_type_expr
+ ?tec ?str_of_com t =
Printtyp.mark_loops t;
- Printtyp.type_scheme_max ~b_reset_names: false type_fmt t;
+ type_scheme type_fmt t
+ ?tec ?str_of_com
+ ~b_reset_names: false;
flush_type_fmt ()
exception Use_code of string
diff --git a/ocamldoc/odoc_print.mli b/ocamldoc/odoc_print.mli
index 3dcc8cf..dd7bfcf 100644
--- a/ocamldoc/odoc_print.mli
+++ b/ocamldoc/odoc_print.mli
@@ -11,11 +11,20 @@
(* $Id: odoc_print.mli,v 1.2 2004-03-26 09:09:50 guesdon Exp $ *)
+val type_scheme:
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?b_reset_names: bool ->
+ Format.formatter -> Types.type_expr -> unit
+
(** Printing functions. *)
(** This function takes a Types.type_expr and returns a string.
It writes in and flushes [Format.str_formatter].*)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ Types.type_expr -> string
(** This function returns a string representing a [Types.module_type].
@param complete indicates if we must print complete signatures
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index fe4e223..0fd340d 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -215,6 +215,141 @@ module Analyser =
in
(0, f name_mutable_type_list)
+ let get_tec
+ poly_variant_tec_htbl
+ ~current_module_name
+ ~name ~pos_end par_ct : tec =
+ let get_mem_tec
+ ~current_module_name ~name
+ poly_variant_tec_htbl =
+ let name = Name.concat
+ current_module_name
+ (String.concat "." (Longident.flatten name)) in
+ (*DEBUG*)try
+ Hashtbl.find poly_variant_tec_htbl name
+ (*DEBUG*)with Not_found ->
+ (*DEBUG*)prerr_endline ("name: " ^ name);
+ (*DEBUG*)prerr_endline ("hashtbl:" ^ Hashtbl.fold
+ (*DEBUG*) (fun k v a -> a ^ " " ^ k) poly_variant_tec_htbl "");
+ (*DEBUG*) raise Not_found
+ in
+ let retrieve_comments pos_end loc dlen : Odoc_types.text =
+ (* retrieve the source from the start of the current variant
+ * to the end of the current type *)
+ let s = ref (get_string_of_file
+ (loc.Location.loc_start.Lexing.pos_cnum + !dlen)
+ (min loc.Location.loc_end.Lexing.pos_cnum pos_end)) in
+ begin let idx = ref 0 (* cut just before the following variant *)
+ in let cnt = ref 0 (* of the same type, by hand, since Ptyp_variant *)
+ in while incr idx; !idx < String.length !s (* has no Location.t *)
+ do match !s.[!idx] with
+ '[' -> incr cnt
+ | '|' when !cnt = 0 -> s := String.sub !s 0 !idx
+ | ']' -> decr cnt
+ | _ -> ()
+ done end;
+ (*DEBUG*)prerr_endline ("s: " ^ !s);
+ (* try to extract a comment *)
+ let _, comment_opt =
+ My_ir.just_after_special !file_name !s in
+ dlen := !dlen + String.length !s;
+ match comment_opt with
+ Some {Odoc_types.i_desc = Some coms} -> coms
+ | _ -> []
+ in
+ let (@) l1 l2 =
+ match l2 with [] -> l1 (* no need to rebuild a list *)
+ | _ -> l1 @ l2 in
+ let rec merge_com
+ ?(glob_coms = [])
+ htbl lbl ({coms=coms; tec=tec} as buc) : unit =
+ let glob_coms = if glob_coms = [] then glob_coms
+ else Odoc_types.Raw " " (* XXX: hardcoded separator *)
+ :: glob_coms in
+ try let {coms=old_coms; tec=old_tec} as buc = Hashtbl.find htbl lbl in
+ buc.coms <- old_coms @ (coms @ glob_coms);
+ let rec f = function Pv_ht old_htbl ->
+ (function Pv_ht htbl -> Hashtbl.iter (merge_com old_htbl) htbl
+ | _ -> assert false)
+ | Pv_l old_l ->
+ (function Pv_l l -> List.iter2 f old_l l
+ | _ -> assert false) in
+ f old_tec tec
+ with Not_found ->
+ buc.coms <- buc.coms @ glob_coms;
+ Hashtbl.add htbl lbl buc
+ in
+ let rec clone_tec = function
+ Pv_ht htbl ->
+ let ht = Hashtbl.create (Hashtbl.length htbl) in
+ Hashtbl.iter begin fun lbl {coms=coms; tec=tec} ->
+ Hashtbl.add ht lbl {coms=coms; tec=clone_tec tec}
+ end htbl;
+ Pv_ht ht
+ | Pv_l l -> Pv_l (List.map clone_tec l)
+ in
+ let rec get ?(pstart = 0) ?(pdlen = ref 0) par_ct =
+ let loc = par_ct.Parsetree.ptyp_loc in
+ let dlen = ref 0 in
+ pdlen := !pdlen + loc.Location.loc_end.Lexing.pos_cnum - pstart;
+ let get ct = get ct ~pdlen: dlen
+ ~pstart: (loc.Location.loc_start.Lexing.pos_cnum + !dlen) in
+ let htbl = Hashtbl.create 12 in
+ let tec = match par_ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_any
+ | Parsetree.Ptyp_var _ -> Pv_l []
+ | Parsetree.Ptyp_arrow (lbl, ct, ct') ->
+ Pv_l [get ct; get ct']
+ | Parsetree.Ptyp_tuple l
+ | Parsetree.Ptyp_class (_, l, _) ->
+ Pv_l (List.map get l)
+ | Parsetree.Ptyp_object l ->
+ Pv_l (List.map (fun ctf ->
+ match ctf.Parsetree.pfield_desc with
+ Parsetree.Pfield_var -> Pv_l []
+ | Parsetree.Pfield (_, ct) -> get ct) l)
+ | Parsetree.Ptyp_constr (name, _) ->
+ (try clone_tec (get_mem_tec poly_variant_tec_htbl
+ ~current_module_name ~name)
+ with Not_found -> Pv_l [])
+ | Parsetree.Ptyp_alias (ct, _)
+ | Parsetree.Ptyp_poly (_, ct) -> get ct
+ | Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
+ List.iter begin function
+ Parsetree.Rtag (lbl, b, l) ->
+ (*DEBUG*)prerr_endline ("\nlabel: " ^ lbl);
+ (* map the sub-types of the current variant *)
+ let l = List.map get l in
+ let tec = match l with [tec] -> tec (* not really a tuple *)
+ | _ -> Pv_l l in
+ (*DEBUG*)prerr_endline ("l[len]: " ^ string_of_int (List.length l));
+ let coms = retrieve_comments pos_end loc dlen in
+ (*DEBUG*)print_coms coms;
+ merge_com htbl lbl ({coms=coms; tec=tec});
+ | Parsetree.Rinherit ct ->
+ let ht = match get ct with Pv_ht ht -> ht
+ | _ -> assert false in
+ let glob_coms = retrieve_comments pos_end loc dlen in
+ (*DEBUG*)prerr_endline ("glob_coms");
+ (*DEBUG*)print_coms glob_coms;
+ Hashtbl.iter (merge_com htbl ~glob_coms) ht
+ end row_field_list;
+ Pv_ht htbl
+ in
+ (*DEBUG*)print_tec tec;
+ tec
+ in
+ let tec = get par_ct in
+ Hashtbl.replace poly_variant_tec_htbl
+ (Name.concat current_module_name name) tec;
+ (* memorize the [tec] in order to retrieve it
+ * when it happens to be nested inside a following poly. variant.
+ * Note that:
+ * # type a = [`a|b] and b = [`b];;
+ * The type constructor s is not yet completely defined
+ *)
+ tec
+
let get_type_kind env name_comment_list type_kind =
match type_kind with
Types.Type_abstract ->
@@ -433,7 +568,8 @@ module Analyser =
(** Analyse of a .mli parse tree, to get the corresponding elements.
last_pos is the position of the first character which may be used to look for special comments.
*)
- let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list =
+ let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list
+ poly_variant_tec_htbl =
let table = Signature_search.table signat in
(* we look for the comment of each item then analyse the item *)
let rec f acc_eles acc_env last_pos = function
@@ -471,6 +607,7 @@ module Analyser =
)
assoc_com
ele.Parsetree.psig_desc
+ poly_variant_tec_htbl
in
f (acc_eles @ (ele_comments @ elements))
new_env
@@ -485,7 +622,8 @@ module Analyser =
(** Analyse the given signature_item_desc to create the corresponding module element
(with the given attached comment).*)
and analyse_signature_item_desc env signat table current_module_name
- pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc =
+ pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc
+ poly_variant_tec_htbl =
match sig_item_desc with
Parsetree.Psig_value (name_pre, value_desc) ->
let type_expr =
@@ -597,6 +735,10 @@ module Analyser =
let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in
let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum in
let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in
+ let tec = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (get_tec poly_variant_tec_htbl ct ~name ~current_module_name
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
(* associate the comments to each constructor and build the [Type.t_type] *)
let new_type =
{
@@ -614,6 +756,7 @@ module Analyser =
(match sig_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tec = tec;
ty_loc =
{ loc_impl = None ;
loc_inter = Some (!file_name,loc_start) ;
@@ -661,7 +804,8 @@ module Analyser =
with Not_found ->
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
- let module_kind = analyse_module_kind env complete_name module_type sig_module_type in
+ let module_kind = analyse_module_kind env complete_name module_type
+ sig_module_type poly_variant_tec_htbl in
let code_intf =
if !Odoc_args.keep_code then
let loc = module_type.Parsetree.pmty_loc in
@@ -752,7 +896,8 @@ module Analyser =
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
(* associate the comments to each constructor and build the [Type.t_type] *)
- let module_kind = analyse_module_kind new_env complete_name modtype sig_module_type in
+ let module_kind = analyse_module_kind new_env complete_name
+ modtype sig_module_type poly_variant_tec_htbl in
let code_intf =
if !Odoc_args.keep_code then
let loc = modtype.Parsetree.pmty_loc in
@@ -830,7 +975,8 @@ module Analyser =
in
let module_type_kind =
match sig_mtype_opt with
- | Some sig_mtype -> Some (analyse_module_type_kind env complete_name module_type sig_mtype)
+ | Some sig_mtype -> Some (analyse_module_type_kind env complete_name
+ module_type sig_mtype poly_variant_tec_htbl)
| None -> None
in
let mt =
@@ -1030,7 +1176,8 @@ module Analyser =
(maybe_more, new_env, eles)
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
- and analyse_module_type_kind env current_module_name module_type sig_module_type =
+ and analyse_module_type_kind env current_module_name module_type sig_module_type
+ poly_variant_tec_htbl =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
let name =
@@ -1049,7 +1196,8 @@ module Analyser =
Types.Tmty_signature signat ->
let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
- let elements = analyse_parsetree env signat current_module_name pos_start pos_end ast in
+ let elements = analyse_parsetree env signat current_module_name
+ pos_start pos_end ast poly_variant_tec_htbl in
Module_type_struct elements
| _ ->
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
@@ -1065,6 +1213,7 @@ module Analyser =
Types.Tmty_functor (ident, param_module_type, body_module_type) ->
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
+ poly_variant_tec_htbl
in
let param =
{
@@ -1078,6 +1227,7 @@ module Analyser =
current_module_name
module_type2
body_module_type
+ poly_variant_tec_htbl
in
Module_type_functor (param, k)
@@ -1092,15 +1242,18 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name
+ module_type2 sig_module_type poly_variant_tec_htbl in
Module_type_with (k, s)
)
(** Analyse of a Parsetree.module_type and a Types.module_type.*)
- and analyse_module_kind env current_module_name module_type sig_module_type =
+ and analyse_module_kind env current_module_name module_type sig_module_type
+ poly_variant_tec_htbl =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
- let k = analyse_module_type_kind env current_module_name module_type sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type
+ sig_module_type poly_variant_tec_htbl in
Module_with ( k, "" )
| Parsetree.Pmty_signature signature ->
@@ -1115,6 +1268,7 @@ module Analyser =
module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum
module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum
signature
+ poly_variant_tec_htbl
)
| _ ->
(* if we're here something's wrong *)
@@ -1130,6 +1284,7 @@ module Analyser =
print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code);
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
+ poly_variant_tec_htbl
in
let param =
{
@@ -1143,6 +1298,7 @@ module Analyser =
current_module_name
module_type2
body_module_type
+ poly_variant_tec_htbl
in
Module_functor (param, k)
@@ -1156,7 +1312,8 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type2
+ sig_module_type poly_variant_tec_htbl in
Module_with (k, s)
)
@@ -1300,8 +1457,10 @@ module Analyser =
(Filename.basename (try Filename.chop_extension source_file with _ -> source_file))
in
let (len,info_opt) = My_ir.first_special !file_name !file in
+ let poly_variant_tec_htbl = Hashtbl.create 12 in
let elements =
- analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file) ast
+ analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file)
+ ast poly_variant_tec_htbl
in
let code_intf =
if !Odoc_args.keep_code then
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index b41e913..f46a3a2 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -149,6 +149,13 @@ module Analyser :
Odoc_env.env -> (string * Odoc_types.info option) list ->
Types.type_kind -> Odoc_type.type_kind
+ val get_tec :
+ (Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
+ current_module_name: string ->
+ name: string ->
+ pos_end: int ->
+ Parsetree.core_type -> Odoc_type.tec
+
(** This function merge two optional info structures. *)
val merge_infos :
Odoc_types.info option -> Odoc_types.info option ->
@@ -156,9 +163,12 @@ module Analyser :
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
val analyse_module_type_kind :
- Odoc_env.env -> Odoc_name.t ->
- Parsetree.module_type -> Types.module_type ->
- Odoc_module.module_type_kind
+ Odoc_env.env ->
+ Odoc_name.t ->
+ Parsetree.module_type ->
+ Types.module_type ->
+ (Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
+ Odoc_module.module_type_kind
(** Analysis of a Parsetree.class_type and a Types.class_type to
return a class_type_kind.*)
diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml
index e3295eb..949d48f 100644
--- a/ocamldoc/odoc_str.ml
+++ b/ocamldoc/odoc_str.ml
@@ -51,13 +51,13 @@ let raw_string_of_type_list sep type_list =
if need_parent t then
(
Format.fprintf fmt "(%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t;
+ Odoc_print.type_scheme ~b_reset_names: false fmt t;
Format.fprintf fmt ")"
)
else
(
Format.fprintf fmt "%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t
+ Odoc_print.type_scheme ~b_reset_names: false fmt t
)
in
begin match type_list with
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 26ae47b..03905b4 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -38,6 +38,10 @@ type type_kind =
| Type_record of record_field list * bool
(** fields * bool *)
+type pvht = (string, buc) Hashtbl.t
+and buc = {mutable coms: Odoc_types.text; tec: tec}
+and tec = Pv_ht of pvht | Pv_l of tec list
+
(** Representation of a type. *)
type t_type = {
ty_name : Name.t ;
@@ -46,7 +50,25 @@ type t_type = {
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind ;
ty_manifest : Types.type_expr option; (** type manifest *)
+ ty_tec : tec option;
mutable ty_loc : Odoc_types.location ;
mutable ty_code : string option;
}
+(*DEBUG*)let print_coms ?(tab = "") =
+(*DEBUG*) List.iter (function Odoc_types.Raw com ->
+(*DEBUG*) prerr_endline (tab ^ "com: " ^ com) | _ -> ())
+(*DEBUG*)let rec print_tec ?(tab = "") = function
+(*DEBUG*) Pv_ht htbl ->
+(*DEBUG*) prerr_endline (tab ^ "Pv_ht");
+(*DEBUG*) Hashtbl.iter begin fun lbl {coms=coms; tec=tec} ->
+(*DEBUG*) prerr_endline (tab ^ "LBL: " ^ lbl);
+(*DEBUG*) print_coms coms ~tab;
+(*DEBUG*) print_tec ~tab: (tab ^ " ") tec
+(*DEBUG*) end htbl
+(*DEBUG*) | Pv_l [] -> ()
+(*DEBUG*) | Pv_l l ->
+(*DEBUG*) prerr_endline (tab ^ "Pv_l");
+(*DEBUG*) List.iter (print_tec ~tab: (tab ^ " ")) l
+
+
23707179c7cf8e892a72feb19fb62a60b19b0906
diff --git a/ocamldoc/.depend b/ocamldoc/.depend
index 2740d81..47b84e8 100644
--- a/ocamldoc/.depend
+++ b/ocamldoc/.depend
@@ -84,30 +84,30 @@ odoc_dep.cmx: ../parsing/parsetree.cmi odoc_type.cmx odoc_print.cmx \
odoc_module.cmx ../tools/depend.cmx
odoc_dot.cmo: odoc_info.cmi
odoc_dot.cmx: odoc_info.cmx
-odoc_env.cmo: ../typing/types.cmi ../typing/printtyp.cmi ../typing/predef.cmi \
- ../typing/path.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
-odoc_env.cmx: ../typing/types.cmx ../typing/printtyp.cmx ../typing/predef.cmx \
- ../typing/path.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
+odoc_env.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
+ odoc_print.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
+odoc_env.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
+ odoc_print.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
odoc_exception.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_exception.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_global.cmo: ../utils/clflags.cmi odoc_global.cmi
odoc_global.cmx: ../utils/clflags.cmx odoc_global.cmi
-odoc_html.cmo: odoc_text.cmi odoc_ocamlhtml.cmo odoc_messages.cmo \
- odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
-odoc_html.cmx: odoc_text.cmx odoc_ocamlhtml.cmx odoc_messages.cmx \
- odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
-odoc_info.cmo: ../typing/printtyp.cmi odoc_value.cmo odoc_types.cmi \
- odoc_type.cmo odoc_text.cmi odoc_str.cmi odoc_search.cmi odoc_scan.cmo \
- odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
- odoc_misc.cmi odoc_messages.cmo odoc_global.cmi odoc_exception.cmo \
- odoc_dep.cmo odoc_config.cmi odoc_comments.cmi odoc_class.cmo \
- odoc_args.cmi odoc_analyse.cmi odoc_info.cmi
-odoc_info.cmx: ../typing/printtyp.cmx odoc_value.cmx odoc_types.cmx \
- odoc_type.cmx odoc_text.cmx odoc_str.cmx odoc_search.cmx odoc_scan.cmx \
- odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
- odoc_misc.cmx odoc_messages.cmx odoc_global.cmx odoc_exception.cmx \
- odoc_dep.cmx odoc_config.cmx odoc_comments.cmx odoc_class.cmx \
- odoc_args.cmx odoc_analyse.cmx odoc_info.cmi
+odoc_html.cmo: odoc_type.cmo odoc_text.cmi odoc_ocamlhtml.cmo \
+ odoc_messages.cmo odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
+odoc_html.cmx: odoc_type.cmx odoc_text.cmx odoc_ocamlhtml.cmx \
+ odoc_messages.cmx odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
+odoc_info.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_text.cmi \
+ odoc_str.cmi odoc_search.cmi odoc_scan.cmo odoc_print.cmi \
+ odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_misc.cmi \
+ odoc_messages.cmo odoc_global.cmi odoc_exception.cmo odoc_dep.cmo \
+ odoc_config.cmi odoc_comments.cmi odoc_class.cmo odoc_args.cmi \
+ odoc_analyse.cmi odoc_info.cmi
+odoc_info.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_text.cmx \
+ odoc_str.cmx odoc_search.cmx odoc_scan.cmx odoc_print.cmx \
+ odoc_parameter.cmx odoc_name.cmx odoc_module.cmx odoc_misc.cmx \
+ odoc_messages.cmx odoc_global.cmx odoc_exception.cmx odoc_dep.cmx \
+ odoc_config.cmx odoc_comments.cmx odoc_class.cmx odoc_args.cmx \
+ odoc_analyse.cmx odoc_info.cmi
odoc_latex.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_latex_style.cmo \
odoc_info.cmi
odoc_latex.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_latex_style.cmx \
@@ -164,8 +164,16 @@ odoc_parameter.cmo: ../typing/types.cmi odoc_types.cmi
odoc_parameter.cmx: ../typing/types.cmx odoc_types.cmx
odoc_parser.cmo: odoc_types.cmi odoc_comments_global.cmi odoc_parser.cmi
odoc_parser.cmx: odoc_types.cmx odoc_comments_global.cmx odoc_parser.cmi
-odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_print.cmi
-odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_print.cmi
+odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi \
+ ../typing/predef.cmi ../typing/path.cmi ../typing/outcometree.cmi \
+ odoc_type.cmo odoc_misc.cmi ../utils/misc.cmi ../parsing/longident.cmi \
+ ../typing/env.cmi ../typing/ctype.cmi ../typing/btype.cmi \
+ ../parsing/asttypes.cmi odoc_print.cmi
+odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx \
+ ../typing/predef.cmx ../typing/path.cmx ../typing/outcometree.cmi \
+ odoc_type.cmx odoc_misc.cmx ../utils/misc.cmx ../parsing/longident.cmx \
+ ../typing/env.cmx ../typing/ctype.cmx ../typing/btype.cmx \
+ ../parsing/asttypes.cmi odoc_print.cmi
odoc_scan.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_scan.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_module.cmx \
@@ -192,12 +200,12 @@ odoc_sig.cmx: ../typing/types.cmx ../typing/typedtree.cmx ../typing/path.cmx \
odoc_exception.cmx odoc_env.cmx odoc_class.cmx odoc_args.cmx \
../utils/misc.cmx ../parsing/longident.cmx ../parsing/location.cmx \
../typing/btype.cmx ../parsing/asttypes.cmi odoc_sig.cmi
-odoc_str.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_value.cmo \
- odoc_type.cmo odoc_print.cmi odoc_name.cmi odoc_misc.cmi \
- odoc_messages.cmo odoc_exception.cmo odoc_class.cmo odoc_str.cmi
-odoc_str.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_value.cmx \
- odoc_type.cmx odoc_print.cmx odoc_name.cmx odoc_misc.cmx \
- odoc_messages.cmx odoc_exception.cmx odoc_class.cmx odoc_str.cmi
+odoc_str.cmo: ../typing/types.cmi odoc_value.cmo odoc_type.cmo odoc_print.cmi \
+ odoc_name.cmi odoc_misc.cmi odoc_messages.cmo odoc_exception.cmo \
+ odoc_class.cmo odoc_str.cmi
+odoc_str.cmx: ../typing/types.cmx odoc_value.cmx odoc_type.cmx odoc_print.cmx \
+ odoc_name.cmx odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx \
+ odoc_class.cmx odoc_str.cmi
odoc_test.cmo: odoc_info.cmi
odoc_test.cmx: odoc_info.cmx
odoc_texi.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_info.cmi
@@ -216,9 +224,9 @@ odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_types.cmo: odoc_messages.cmo odoc_types.cmi
odoc_types.cmx: odoc_messages.cmx odoc_types.cmi
-odoc_value.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_types.cmi \
+odoc_value.cmo: ../typing/types.cmi odoc_types.cmi odoc_print.cmi \
odoc_parameter.cmo odoc_name.cmi
-odoc_value.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_types.cmx \
+odoc_value.cmx: ../typing/types.cmx odoc_types.cmx odoc_print.cmx \
odoc_parameter.cmx odoc_name.cmx
odoc_analyse.cmi: odoc_module.cmo odoc_args.cmi
odoc_args.cmi: odoc_types.cmi odoc_module.cmo
@@ -236,7 +244,7 @@ odoc_misc.cmi: ../typing/types.cmi odoc_types.cmi ../parsing/longident.cmi
odoc_name.cmi: ../typing/path.cmi ../parsing/longident.cmi \
../typing/ident.cmi
odoc_parser.cmi: odoc_types.cmi
-odoc_print.cmi: ../typing/types.cmi
+odoc_print.cmi: ../typing/types.cmi odoc_types.cmi odoc_type.cmo
odoc_search.cmi: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_sig.cmi: ../typing/types.cmi ../parsing/parsetree.cmi odoc_types.cmi \
diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile
index c181142..3749001 100644
--- a/ocamldoc/Makefile
+++ b/ocamldoc/Makefile
@@ -81,12 +81,12 @@ CMOFILES= odoc_config.cmo \
odoc_text.cmo\
odoc_name.cmo\
odoc_parameter.cmo\
+ odoc_print.cmo \
odoc_value.cmo\
odoc_type.cmo\
odoc_exception.cmo\
odoc_class.cmo\
odoc_module.cmo\
- odoc_print.cmo \
odoc_str.cmo\
odoc_args.cmo\
odoc_comments_global.cmo\
diff --git a/ocamldoc/odoc_env.ml b/ocamldoc/odoc_env.ml
index ed9fb26..0865f8d 100644
--- a/ocamldoc/odoc_env.ml
+++ b/ocamldoc/odoc_env.ml
@@ -181,7 +181,7 @@ let subst_type env t =
print_env_types env ;
print_newline ();
*)
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
let deja_vu = ref [] in
let rec iter t =
if List.memq t !deja_vu then () else begin
diff --git a/ocamldoc/odoc_info.ml b/ocamldoc/odoc_info.ml
index 67c385e..3305bab 100644
--- a/ocamldoc/odoc_info.ml
+++ b/ocamldoc/odoc_info.ml
@@ -113,7 +113,7 @@ let dump_modules = Odoc_analyse.dump_modules
let load_modules = Odoc_analyse.load_modules
-let reset_type_names = Printtyp.reset
+let reset_type_names = Odoc_print.reset
let string_of_variance t (co,cn) = Odoc_str.string_of_variance t (co, cn)
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index c246e47..5432635 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -300,6 +300,69 @@ let namable_row row =
| _ -> true)
row.row_fields
+let reset_loop_marks () =
+ visited_objects := []; aliased := []; delayed := []
+
+let reset () =
+ reset_names (); reset_loop_marks ()
+
+let rec mark_loops_rec visited ty =
+ let ty = repr ty in
+ let px = proxy ty in
+ if List.memq px visited && aliasable ty then add_alias px else
+ let visited = px :: visited in
+ match ty.desc with
+ | Tvar -> ()
+ | Tarrow(_, ty1, ty2, _) ->
+ mark_loops_rec visited ty1; mark_loops_rec visited ty2
+ | Ttuple tyl -> List.iter (mark_loops_rec visited) tyl
+ | Tconstr(_, tyl, _) ->
+ List.iter (mark_loops_rec visited) tyl
+ | Tvariant row ->
+ if List.memq px !visited_objects then add_alias px else
+ begin
+ let row = row_repr row in
+ if not (static_row row) then
+ visited_objects := px :: !visited_objects;
+ match row.row_name with
+ | Some(p, tyl) when namable_row row ->
+ List.iter (mark_loops_rec visited) tyl
+ | _ ->
+ iter_row (mark_loops_rec visited) row
+ end
+ | Tobject (fi, nm) ->
+ if List.memq px !visited_objects then add_alias px else
+ begin
+ if opened_object ty then
+ visited_objects := px :: !visited_objects;
+ begin match !nm with
+ | None ->
+ let fields, _ = flatten_fields fi in
+ List.iter
+ (fun (_, kind, ty) ->
+ if field_kind_repr kind = Fpresent then
+ mark_loops_rec visited ty)
+ fields
+ | Some (_, l) ->
+ List.iter (mark_loops_rec visited) (List.tl l)
+ end
+ end
+ | Tfield(_, kind, ty1, ty2) when field_kind_repr kind = Fpresent ->
+ mark_loops_rec visited ty1; mark_loops_rec visited ty2
+ | Tfield(_, _, _, ty2) ->
+ mark_loops_rec visited ty2
+ | Tnil -> ()
+ | Tsubst ty -> mark_loops_rec visited ty
+ | Tlink _ -> fatal_error "Odoc_print.mark_loops_rec (2)"
+ | Tpoly (ty, tyl) ->
+ List.iter (fun t -> add_alias t) tyl;
+ mark_loops_rec visited ty
+ | Tunivar -> ()
+
+let mark_loops ty =
+ normalize_type Env.empty ty;
+ mark_loops_rec [] ty;;
+
(* Disabled in classic mode when printing an unification error *)
let print_labels = ref true
let print_label ppf l =
@@ -375,7 +438,7 @@ let rec tree_of_typexp sch ty =
| Tsubst ty ->
tree_of_typexp sch ty
| Tlink _ | Tnil | Tfield _ ->
- fatal_error "Printtyp.tree_of_typexp"
+ fatal_error "Odoc_print.tree_of_typexp"
| Tpoly (ty, []) ->
tree_of_typexp sch ty
| Tpoly (ty, tyl) ->
@@ -432,7 +495,7 @@ and tree_of_typobject sch fi nm =
let args = tree_of_typlist sch tyl in
Otyp_class (non_gen, tree_of_path p, args)
| _ ->
- fatal_error "Printtyp.tree_of_typobject"
+ fatal_error "Odoc_print.tree_of_typobject"
end
and is_non_gen sch ty =
@@ -461,15 +524,17 @@ and tree_of_typfields sch rest = function
?tec ?str_of_com
?(b_reset_names = true)
ppf ty =
- if b_reset_names then reset_names () ;
+ if b_reset_names then reset_names ();
typexp true 0 ppf ty ?tec ?str_of_com
end
let type_scheme = Odoc_printtyp.type_scheme
+let mark_loops = Odoc_printtyp.mark_loops
+let reset = Odoc_printtyp.reset
let string_of_type_expr
?tec ?str_of_com t =
- Printtyp.mark_loops t;
+ Odoc_printtyp.mark_loops t;
type_scheme type_fmt t
?tec ?str_of_com
~b_reset_names: false;
diff --git a/ocamldoc/odoc_print.mli b/ocamldoc/odoc_print.mli
index dd7bfcf..a39bbdd 100644
--- a/ocamldoc/odoc_print.mli
+++ b/ocamldoc/odoc_print.mli
@@ -11,12 +11,20 @@
(* $Id: odoc_print.mli,v 1.2 2004-03-26 09:09:50 guesdon Exp $ *)
+(** Customized [Printtyp.mark_loops] *)
+val mark_loops: Types.type_expr -> unit
+
+(** Customized [Printtyp.type_scheme] *)
val type_scheme:
?tec: Odoc_type.tec ->
?str_of_com: (Odoc_types.text -> string) ->
?b_reset_names: bool ->
Format.formatter -> Types.type_expr -> unit
+(** Same as [Printtyp.reset] but for the above functions *)
+val reset: unit -> unit
+
+
(** Printing functions. *)
(** This function takes a Types.type_expr and returns a string.
diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml
index 949d48f..e0c2af7 100644
--- a/ocamldoc/odoc_str.ml
+++ b/ocamldoc/odoc_str.ml
@@ -47,7 +47,7 @@ let raw_string_of_type_list sep type_list =
| Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false
in
let print_one_type variance t =
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
if need_parent t then
(
Format.fprintf fmt "(%s" variance;
diff --git a/ocamldoc/odoc_value.ml b/ocamldoc/odoc_value.ml
index 29be7c5..fb8bbc5 100644
--- a/ocamldoc/odoc_value.ml
+++ b/ocamldoc/odoc_value.ml
@@ -102,7 +102,7 @@ let dummy_parameter_list typ =
'?' -> String.sub s 1 ((String.length s) - 1)
| _ -> s
in
- Printtyp.mark_loops typ;
+ Odoc_print.mark_loops typ;
let liste_param = parameter_list_from_arrows typ in
let rec iter (label, t) =
match t.Types.desc with
ab6fe41bbb3f78864bd2cf2d9fa52b6cefc61462
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index 51e6ea8..d45280f 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -1139,7 +1139,7 @@ module Analyser =
(match tt_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
- ty_tec = tec;
+ ty_tmc = tec;
ty_loc = { loc_impl = Some (!file_name, loc_start) ; loc_inter = None } ;
ty_code =
(
diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml
index e59790a..887435b 100644
--- a/ocamldoc/odoc_html.ml
+++ b/ocamldoc/odoc_html.ml
@@ -1386,10 +1386,8 @@ class html =
match t.ty_manifest with
None -> ()
| Some typ ->
- (*DEBUG*)print_tec ~tab: "html: "
- (*DEBUG*) (match t.ty_tec with Some tec -> tec | _ -> Odoc_type.Pv_l []);
bs b "= ";
- self#html_of_type_expr b father typ ?tec: t.ty_tec;
+ self#html_of_type_expr b father typ ?tec: t.ty_tmc;
bs b " "
);
(match t.ty_kind with
@@ -1832,7 +1830,7 @@ class html =
{ ty_name = c.cl_name ;
ty_info = None ; ty_parameters = [] ;
ty_kind = Type_abstract ;
- ty_manifest = None ; ty_tec = None ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
@@ -1880,7 +1878,7 @@ class html =
{ ty_name = ct.clt_name ;
ty_info = None ; ty_parameters = [] ;
ty_kind = Type_abstract ;
- ty_manifest = None ; ty_tec = None ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index 1cc7f91..ab3636d 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -212,9 +212,11 @@ module Type :
| Type_record of record_field list * bool
(** fields * bool *)
- type pvht = Odoc_type.pvht
- and buc = Odoc_type.buc = {mutable coms: Odoc_types.text; tec: tec}
- and tec = Odoc_type.tec = Pv_ht of pvht | Pv_l of tec list
+ type tec = Odoc_type.tec =
+ Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ | Tec_list of tec list
+ and tec_variant_buc = Odoc_type.tec_variant_buc =
+ { mutable coms: Odoc_types.text; tec: tec }
(** Representation of a type. *)
type t_type = Odoc_type.t_type =
@@ -225,7 +227,7 @@ module Type :
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind ; (** Type kind. *)
ty_manifest : Types.type_expr option; (** Type manifest. *)
- ty_tec : tec option;
+ mutable ty_tmc : tec option; (** Type manifest's comments. *)
mutable ty_loc : location ;
mutable ty_code : string option;
}
diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml
index 851884a..bf07823 100644
--- a/ocamldoc/odoc_merge.ml
+++ b/ocamldoc/odoc_merge.ml
@@ -191,8 +191,13 @@ let merge_types merge_options mli ml =
mli.ty_info <- merge_info_opt merge_options mli.ty_info ml.ty_info;
mli.ty_loc <- { mli.ty_loc with loc_impl = ml.ty_loc.loc_impl } ;
mli.ty_code <- (match mli.ty_code with None -> ml.ty_code | _ -> mli.ty_code) ;
-
- match mli.ty_kind, ml.ty_kind with
+ let fail_on_different_types () =
+ if not !Odoc_args.inverse_merge_ml_mli
+ then raise (Failure (Odoc_messages.different_types mli.ty_name))
+ in
+ let has_merge_description_option =
+ List.mem Merge_description merge_options in
+ begin match mli.ty_kind, ml.ty_kind with
Type_abstract, _ ->
()
@@ -209,18 +214,13 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
cons.vc_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
@@ -237,26 +237,40 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
record.rf_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
- | _ ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ | _ -> fail_on_different_types ()
+ end;
+ begin match mli.ty_tmc, ml.ty_tmc with
+ None, None
+ | Some _, None -> ()
+ | None, Some tec -> mli.ty_tmc <- ml.ty_tmc
+ | Some mli_tec, Some ml_tec ->
+ let rec f = function
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> f (x, y)) l l'
+ | Tec_variant ht, Tec_variant ht' ->
+ Hashtbl.iter
+ begin fun lbl ({coms=coms; tec=tec} as buc) ->
+ try let {coms=coms'; tec=tec'} = Hashtbl.find ht' lbl in
+ if (coms' <> []
+ && has_merge_description_option)
+ || coms = []
+ then buc.coms <- coms @ coms';
+ f (tec, tec')
+ with Not_found -> fail_on_different_types ()
+ end ht
+ | _ -> fail_on_different_types ()
+ in f (mli_tec, ml_tec)
+ end
(** Merge of two param_info, one from a .mli, one from a .ml.
The text fields are not handled but will be recreated from the
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index 5432635..ff78fad 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -38,6 +38,8 @@ let (modtype_fmt, flush_modtype_fmt) = new_fmt ()
module Odoc_oprint =
struct
+ open Odoc_type
+
open Format
open Outcometree
@@ -66,77 +68,55 @@ module Odoc_oprint =
print_list (fun ppf s -> fprintf ppf "'%s" s) (fun ppf -> fprintf ppf "@ ")
let rec print_out_type
- ?(tec = Odoc_type.Pv_l [])
+ ?(tec = Tec_list [])
?(str_of_com = Odoc_misc.string_of_text)
ppf =
function
| Otyp_alias (ty, s) ->
- (*DEBUG*)prerr_endline "print_out_type (alias)";
- (*DEBUG*)Odoc_type.print_tec tec;
fprintf ppf "@[%a@ as '%s@]" (print_out_type ~tec ~str_of_com) ty s
| Otyp_poly (sl, ty) ->
- (*DEBUG*)prerr_endline "print_out_type (poly)";
- (*DEBUG*)Odoc_type.print_tec tec;
fprintf ppf "@[<hov 2>%a.@ %a@]"
pr_vars sl
(print_out_type ~tec ~str_of_com) ty
| ty ->
- (*DEBUG*)prerr_endline "print_out_type";
- (*DEBUG*)Odoc_type.print_tec tec ~tab: "pot: ";
print_out_type_1 ppf ty ~tec ~str_of_com
and print_out_type_1 ~tec ~str_of_com ppf =
function
Otyp_arrow (lab, ty1, ty2) ->
- (*DEBUG*)prerr_endline "print_out_type_1 (arrow)";
- (*DEBUG*)Odoc_type.print_tec tec;
let tec1, tec2 = match tec with
- Odoc_type.Pv_l [x;y] -> x, y
- | _ -> Odoc_type.Pv_l [], Odoc_type.Pv_l [] in
+ Tec_list [x;y] -> x, y
+ | _ -> Tec_list [], Tec_list [] in
fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "")
(print_out_type_2 ~tec: tec1 ~str_of_com) ty1
(print_out_type_1 ~tec: tec2 ~str_of_com) ty2
| ty ->
- (*DEBUG*)prerr_endline "print_out_type_1";
- (*DEBUG*)Odoc_type.print_tec tec ~tab: "pot1: ";
print_out_type_2 ppf ty ~tec ~str_of_com
and print_out_type_2 ~tec ~str_of_com ppf =
function
Otyp_tuple tyl ->
- (*DEBUG*)prerr_endline "print_out_type_2 (tuple)";
- (*DEBUG*)Odoc_type.print_tec tec;
let tecr = ref tec in
let print_elem ty =
let tec = match !tecr with
- Odoc_type.Pv_l (tec::t) -> tecr := Odoc_type.Pv_l t; tec
- | _ -> Odoc_type.Pv_l [] in
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
print_simple_out_type ~tec ~str_of_com ty
in fprintf ppf "@[<0>%a@]" (print_typlist print_elem " *") tyl
| ty ->
- (*DEBUG*)prerr_endline "print_out_type_2";
- (*DEBUG*)Odoc_type.print_tec tec ~tab: "pot2: ";
print_simple_out_type ppf ty ~tec ~str_of_com
and print_simple_out_type ~tec ~str_of_com ppf =
function
Otyp_class (ng, id, tyl) ->
- (*DEBUG*)prerr_endline "print_simple_out_type (class)";
- (*DEBUG*)Odoc_type.print_tec tec;
fprintf ppf "@[%a%s#%a@]" (print_typargs ~tec ~str_of_com) tyl
(if ng then "_" else "")
print_ident id
| Otyp_constr (id, tyl) ->
- (*DEBUG*)prerr_endline "print_simple_out_type (constr)";
- (*DEBUG*)Odoc_type.print_tec tec;
fprintf ppf "@[%a%a@]" (print_typargs ~tec ~str_of_com) tyl print_ident id
| Otyp_object (fields, rest) ->
- (*DEBUG*)prerr_endline "print_simple_out_type (object)";
- (*DEBUG*)Odoc_type.print_tec tec;
fprintf ppf "@[<2>< %a >@]" (print_fields rest ~tec ~str_of_com) fields
| Otyp_stuff s -> fprintf ppf "%s" s
| Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s
| Otyp_variant (non_gen, row_fields, closed, tags) ->
- (*DEBUG*)prerr_endline "print_simple_out_type (variant)";
- (*DEBUG*)Odoc_type.print_tec tec;
let print_present ppf =
function
None | Some [] -> ()
@@ -160,8 +140,6 @@ module Odoc_oprint =
(print_fields ~tec ~str_of_com) row_fields
print_present tags
| Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty ->
- (*DEBUG*)prerr_endline "print_simple_out_type (alias;poly;arrow;tuple)";
- (*DEBUG*)Odoc_type.print_tec tec;
fprintf ppf "@[<1>(%a)@]" (print_out_type ~tec ~str_of_com) ty
| Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> ()
and print_fields ~tec ~str_of_com rest ppf =
@@ -172,21 +150,19 @@ module Odoc_oprint =
| None -> ()
end
| [s, t] ->
- let tec = match tec with Odoc_type.Pv_l [h] -> h
- | _ -> Odoc_type.Pv_l [] in
+ let tec = match tec with Tec_list [h] -> h
+ | _ -> Tec_list [] in
fprintf ppf "%s : %a" s (print_out_type ~tec ~str_of_com) t;
begin match rest with
Some _ -> fprintf ppf ";@ "
| None -> () end;
- print_fields ~tec: (Odoc_type.Pv_l []) ~str_of_com rest ppf []
+ print_fields ~tec: (Tec_list []) ~str_of_com rest ppf []
| (s, t) :: l ->
- let tec, tec' = match tec with Odoc_type.Pv_l (h::t) -> h, Odoc_type.Pv_l t
- | _ -> Odoc_type.Pv_l [], Odoc_type.Pv_l [] in
+ let tec, tec' = match tec with Tec_list (h::t) -> h, Tec_list t
+ | _ -> Tec_list [], Tec_list [] in
fprintf ppf "%s : %a;@ %a" s (print_out_type ~tec ~str_of_com) t
(print_fields rest ~tec: tec' ~str_of_com) l
and print_row_field ~tec ~str_of_com ppf (l, opt_amp, tyl) =
- (*DEBUG*)prerr_endline "print_row_field";
- (*DEBUG*)Odoc_type.print_tec tec;
let pr_of ppf =
if opt_amp then fprintf ppf " of@ &@ "
else if tyl <> [] then fprintf ppf " of@ "
@@ -194,9 +170,9 @@ module Odoc_oprint =
in
let {Odoc_type.coms=coms; tec=tec} =
try match tec with
- Odoc_type.Pv_ht ht -> Hashtbl.find ht l
- | _ -> {Odoc_type.coms=[];tec=Odoc_type.Pv_l []}
- with Not_found -> {Odoc_type.coms=[];tec=Odoc_type.Pv_l []} in
+ Tec_variant ht -> Hashtbl.find ht l
+ | _ -> {Odoc_type.coms=[];tec=Tec_list []}
+ with Not_found -> {Odoc_type.coms=[];tec=Tec_list []} in
let str_coms =
if coms <> []
then str_of_com coms
@@ -214,20 +190,18 @@ module Odoc_oprint =
fprintf ppf "%a%s@ %a" print_elem ty sep
(print_typlist print_elem sep) tyl
and print_typargs ~tec ~str_of_com ppf =
- (*DEBUG*)prerr_endline "print_typargs";
- (*DEBUG*)Odoc_type.print_tec tec;
function
[] -> ()
| [ty1] ->
- let tec = match tec with Odoc_type.Pv_l (h::t) -> h
- | _ -> Odoc_type.Pv_l [] in
+ let tec = match tec with Tec_list (h::t) -> h
+ | _ -> Tec_list [] in
fprintf ppf "%a@ " (print_simple_out_type ~tec ~str_of_com) ty1
| tyl ->
let tecr = ref tec in
let print_elem ty =
let tec = match !tecr with
- Odoc_type.Pv_l (tec::t) -> tecr := Odoc_type.Pv_l t; tec
- | _ -> Odoc_type.Pv_l [] in
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
print_out_type ~tec ~str_of_com ty
in fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_elem ",") tyl
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index 0fd340d..dbc7e8e 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -215,140 +215,140 @@ module Analyser =
in
(0, f name_mutable_type_list)
- let get_tec
- poly_variant_tec_htbl
- ~current_module_name
- ~name ~pos_end par_ct : tec =
- let get_mem_tec
- ~current_module_name ~name
- poly_variant_tec_htbl =
- let name = Name.concat
- current_module_name
- (String.concat "." (Longident.flatten name)) in
- (*DEBUG*)try
- Hashtbl.find poly_variant_tec_htbl name
- (*DEBUG*)with Not_found ->
- (*DEBUG*)prerr_endline ("name: " ^ name);
- (*DEBUG*)prerr_endline ("hashtbl:" ^ Hashtbl.fold
- (*DEBUG*) (fun k v a -> a ^ " " ^ k) poly_variant_tec_htbl "");
- (*DEBUG*) raise Not_found
- in
- let retrieve_comments pos_end loc dlen : Odoc_types.text =
- (* retrieve the source from the start of the current variant
- * to the end of the current type *)
- let s = ref (get_string_of_file
- (loc.Location.loc_start.Lexing.pos_cnum + !dlen)
- (min loc.Location.loc_end.Lexing.pos_cnum pos_end)) in
- begin let idx = ref 0 (* cut just before the following variant *)
- in let cnt = ref 0 (* of the same type, by hand, since Ptyp_variant *)
- in while incr idx; !idx < String.length !s (* has no Location.t *)
- do match !s.[!idx] with
- '[' -> incr cnt
- | '|' when !cnt = 0 -> s := String.sub !s 0 !idx
- | ']' -> decr cnt
- | _ -> ()
- done end;
- (*DEBUG*)prerr_endline ("s: " ^ !s);
- (* try to extract a comment *)
- let _, comment_opt =
- My_ir.just_after_special !file_name !s in
- dlen := !dlen + String.length !s;
- match comment_opt with
- Some {Odoc_types.i_desc = Some coms} -> coms
- | _ -> []
- in
- let (@) l1 l2 =
- match l2 with [] -> l1 (* no need to rebuild a list *)
- | _ -> l1 @ l2 in
- let rec merge_com
- ?(glob_coms = [])
- htbl lbl ({coms=coms; tec=tec} as buc) : unit =
- let glob_coms = if glob_coms = [] then glob_coms
- else Odoc_types.Raw " " (* XXX: hardcoded separator *)
- :: glob_coms in
- try let {coms=old_coms; tec=old_tec} as buc = Hashtbl.find htbl lbl in
- buc.coms <- old_coms @ (coms @ glob_coms);
- let rec f = function Pv_ht old_htbl ->
- (function Pv_ht htbl -> Hashtbl.iter (merge_com old_htbl) htbl
- | _ -> assert false)
- | Pv_l old_l ->
- (function Pv_l l -> List.iter2 f old_l l
- | _ -> assert false) in
- f old_tec tec
- with Not_found ->
- buc.coms <- buc.coms @ glob_coms;
- Hashtbl.add htbl lbl buc
- in
- let rec clone_tec = function
- Pv_ht htbl ->
- let ht = Hashtbl.create (Hashtbl.length htbl) in
- Hashtbl.iter begin fun lbl {coms=coms; tec=tec} ->
- Hashtbl.add ht lbl {coms=coms; tec=clone_tec tec}
- end htbl;
- Pv_ht ht
- | Pv_l l -> Pv_l (List.map clone_tec l)
- in
- let rec get ?(pstart = 0) ?(pdlen = ref 0) par_ct =
- let loc = par_ct.Parsetree.ptyp_loc in
- let dlen = ref 0 in
- pdlen := !pdlen + loc.Location.loc_end.Lexing.pos_cnum - pstart;
- let get ct = get ct ~pdlen: dlen
- ~pstart: (loc.Location.loc_start.Lexing.pos_cnum + !dlen) in
- let htbl = Hashtbl.create 12 in
- let tec = match par_ct.Parsetree.ptyp_desc with
- Parsetree.Ptyp_any
- | Parsetree.Ptyp_var _ -> Pv_l []
- | Parsetree.Ptyp_arrow (lbl, ct, ct') ->
- Pv_l [get ct; get ct']
- | Parsetree.Ptyp_tuple l
- | Parsetree.Ptyp_class (_, l, _) ->
- Pv_l (List.map get l)
- | Parsetree.Ptyp_object l ->
- Pv_l (List.map (fun ctf ->
- match ctf.Parsetree.pfield_desc with
- Parsetree.Pfield_var -> Pv_l []
- | Parsetree.Pfield (_, ct) -> get ct) l)
- | Parsetree.Ptyp_constr (name, _) ->
- (try clone_tec (get_mem_tec poly_variant_tec_htbl
- ~current_module_name ~name)
- with Not_found -> Pv_l [])
- | Parsetree.Ptyp_alias (ct, _)
- | Parsetree.Ptyp_poly (_, ct) -> get ct
- | Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
- List.iter begin function
- Parsetree.Rtag (lbl, b, l) ->
- (*DEBUG*)prerr_endline ("\nlabel: " ^ lbl);
- (* map the sub-types of the current variant *)
- let l = List.map get l in
- let tec = match l with [tec] -> tec (* not really a tuple *)
- | _ -> Pv_l l in
- (*DEBUG*)prerr_endline ("l[len]: " ^ string_of_int (List.length l));
- let coms = retrieve_comments pos_end loc dlen in
- (*DEBUG*)print_coms coms;
- merge_com htbl lbl ({coms=coms; tec=tec});
- | Parsetree.Rinherit ct ->
- let ht = match get ct with Pv_ht ht -> ht
- | _ -> assert false in
- let glob_coms = retrieve_comments pos_end loc dlen in
- (*DEBUG*)prerr_endline ("glob_coms");
- (*DEBUG*)print_coms glob_coms;
- Hashtbl.iter (merge_com htbl ~glob_coms) ht
- end row_field_list;
- Pv_ht htbl
- in
- (*DEBUG*)print_tec tec;
- tec
- in
- let tec = get par_ct in
- Hashtbl.replace poly_variant_tec_htbl
- (Name.concat current_module_name name) tec;
- (* memorize the [tec] in order to retrieve it
- * when it happens to be nested inside a following poly. variant.
- * Note that:
- * # type a = [`a|b] and b = [`b];;
- * The type constructor s is not yet completely defined
- *)
- tec
+ let get_tec
+ poly_variant_tec_htbl
+ ~current_module_name
+ ~name ~pos_end par_ct : tec =
+ let get_mem_tec
+ ~current_module_name ~name
+ poly_variant_tec_htbl =
+ let name = Name.concat
+ current_module_name
+ (String.concat "." (Longident.flatten name)) in
+ (*DEBUG*)try
+ Hashtbl.find poly_variant_tec_htbl name
+ (*DEBUG*)with Not_found ->
+ (*DEBUG*)prerr_endline ("name: " ^ name);
+ (*DEBUG*)prerr_endline ("hashtbl:" ^ Hashtbl.fold
+ (*DEBUG*) (fun k v a -> a ^ " " ^ k) poly_variant_tec_htbl "");
+ (*DEBUG*) raise Not_found
+ in
+ let retrieve_comments pos_end loc dlen : Odoc_types.text =
+ (* retrieve the source from the start of the current variant
+ * to the end of the current type *)
+ let s = ref (get_string_of_file
+ (loc.Location.loc_start.Lexing.pos_cnum + !dlen)
+ (min loc.Location.loc_end.Lexing.pos_cnum pos_end)) in
+ begin let idx = ref 0 (* cut just before the following variant *)
+ in let cnt = ref 0 (* of the same type, by hand, since Ptyp_variant *)
+ in while incr idx; !idx < String.length !s (* has no Location.t *)
+ do match !s.[!idx] with
+ '[' -> incr cnt
+ | '|' when !cnt = 0 -> s := String.sub !s 0 !idx
+ | ']' -> decr cnt
+ | _ -> ()
+ done end;
+ (*DEBUG*)prerr_endline ("s: " ^ !s);
+ (* try to extract a comment *)
+ let _, comment_opt =
+ My_ir.just_after_special !file_name !s in
+ dlen := !dlen + String.length !s;
+ match comment_opt with
+ Some {Odoc_types.i_desc = Some coms} -> coms
+ | _ -> []
+ in
+ let (@) l1 l2 =
+ match l2 with [] -> l1 (* no need to rebuild a list *)
+ | _ -> l1 @ l2 in
+ let rec merge_com
+ ?(glob_coms = [])
+ htbl lbl ({coms=coms; tec=tec} as buc) : unit =
+ let glob_coms = if glob_coms = [] then glob_coms
+ else Odoc_types.Raw " " (* XXX: hardcoded separator *)
+ :: glob_coms in
+ try let {coms=old_coms; tec=old_tec} as buc = Hashtbl.find htbl lbl in
+ buc.coms <- old_coms @ (coms @ glob_coms);
+ let rec f = function Tec_variant old_htbl ->
+ (function Tec_variant htbl -> Hashtbl.iter (merge_com old_htbl) htbl
+ | _ -> assert false)
+ | Tec_list old_l ->
+ (function Tec_list l -> List.iter2 f old_l l
+ | _ -> assert false) in
+ f old_tec tec
+ with Not_found ->
+ buc.coms <- buc.coms @ glob_coms;
+ Hashtbl.add htbl lbl buc
+ in
+ let rec clone_tec = function
+ Tec_variant htbl ->
+ let ht = Hashtbl.create (Hashtbl.length htbl) in
+ Hashtbl.iter begin fun lbl {coms=coms; tec=tec} ->
+ Hashtbl.add ht lbl {coms=coms; tec=clone_tec tec}
+ end htbl;
+ Tec_variant ht
+ | Tec_list l -> Tec_list (List.map clone_tec l)
+ in
+ let rec get ?(pstart = 0) ?(pdlen = ref 0) par_ct =
+ let loc = par_ct.Parsetree.ptyp_loc in
+ let dlen = ref 0 in
+ pdlen := !pdlen + loc.Location.loc_end.Lexing.pos_cnum - pstart;
+ let get ct = get ct ~pdlen: dlen
+ ~pstart: (loc.Location.loc_start.Lexing.pos_cnum + !dlen) in
+ let htbl = Hashtbl.create 12 in
+ let tec = match par_ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_any
+ | Parsetree.Ptyp_var _ -> Tec_list []
+ | Parsetree.Ptyp_arrow (lbl, ct, ct') ->
+ Tec_list [get ct; get ct']
+ | Parsetree.Ptyp_tuple l
+ | Parsetree.Ptyp_class (_, l, _) ->
+ Tec_list (List.map get l)
+ | Parsetree.Ptyp_object l ->
+ Tec_list (List.map (fun ctf ->
+ match ctf.Parsetree.pfield_desc with
+ Parsetree.Pfield_var -> Tec_list []
+ | Parsetree.Pfield (_, ct) -> get ct) l)
+ | Parsetree.Ptyp_constr (name, _) ->
+ (try clone_tec (get_mem_tec poly_variant_tec_htbl
+ ~current_module_name ~name)
+ with Not_found -> Tec_list [])
+ | Parsetree.Ptyp_alias (ct, _)
+ | Parsetree.Ptyp_poly (_, ct) -> get ct
+ | Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
+ List.iter begin function
+ Parsetree.Rtag (lbl, b, l) ->
+ (*DEBUG*)prerr_endline ("\nlabel: " ^ lbl);
+ (* map the sub-types of the current variant *)
+ let l = List.map get l in
+ let tec = match l with [tec] -> tec (* not really a tuple *)
+ | _ -> Tec_list l in
+ (*DEBUG*)prerr_endline ("l[len]: " ^ string_of_int (List.length l));
+ let coms = retrieve_comments pos_end loc dlen in
+ (*DEBUG*)print_coms coms;
+ merge_com htbl lbl ({coms=coms; tec=tec});
+ | Parsetree.Rinherit ct ->
+ let ht = match get ct with Tec_variant ht -> ht
+ | _ -> assert false in
+ let glob_coms = retrieve_comments pos_end loc dlen in
+ (*DEBUG*)prerr_endline ("glob_coms");
+ (*DEBUG*)print_coms glob_coms;
+ Hashtbl.iter (merge_com htbl ~glob_coms) ht
+ end row_field_list;
+ Tec_variant htbl
+ in
+ (*DEBUG*)print_tec tec;
+ tec
+ in
+ let tec = get par_ct in
+ Hashtbl.replace poly_variant_tec_htbl
+ (Name.concat current_module_name name) tec;
+ (* memorize the [tec] in order to retrieve it
+ * when it happens to be nested inside a following poly. variant.
+ * Note that:
+ * # type a = [`a|b] and b = [`b];;
+ * The type constructor s is not yet completely defined
+ *)
+ tec
let get_type_kind env name_comment_list type_kind =
match type_kind with
@@ -735,7 +735,7 @@ module Analyser =
let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in
let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum in
let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in
- let tec = match type_decl.Parsetree.ptype_manifest
+ let tmc = match type_decl.Parsetree.ptype_manifest
with None -> None | Some ct ->
Some (get_tec poly_variant_tec_htbl ct ~name ~current_module_name
~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
@@ -756,7 +756,7 @@ module Analyser =
(match sig_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
- ty_tec = tec;
+ ty_tmc = tmc;
ty_loc =
{ loc_impl = None ;
loc_inter = Some (!file_name,loc_start) ;
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 03905b4..6fff1ed 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -38,37 +38,38 @@ type type_kind =
| Type_record of record_field list * bool
(** fields * bool *)
-type pvht = (string, buc) Hashtbl.t
-and buc = {mutable coms: Odoc_types.text; tec: tec}
-and tec = Pv_ht of pvht | Pv_l of tec list
+type tec =
+ Tec_variant of (string, tec_variant_buc) Hashtbl.t
+| Tec_list of tec list
+and tec_variant_buc = { mutable coms: Odoc_types.text; tec: tec }
(** Representation of a type. *)
type t_type = {
- ty_name : Name.t ;
- mutable ty_info : Odoc_types.info option ; (** optional user information *)
- ty_parameters : (Types.type_expr * bool * bool) list ;
+ ty_name : Name.t;
+ mutable ty_info : Odoc_types.info option; (** optional user information *)
+ ty_parameters : (Types.type_expr * bool * bool) list;
(** type parameters: (type, covariant, contravariant) *)
- ty_kind : type_kind ;
+ ty_kind : type_kind;
ty_manifest : Types.type_expr option; (** type manifest *)
- ty_tec : tec option;
- mutable ty_loc : Odoc_types.location ;
+ mutable ty_tmc : tec option; (** type manifest's comments *)
+ mutable ty_loc : Odoc_types.location;
mutable ty_code : string option;
- }
+ }
(*DEBUG*)let print_coms ?(tab = "") =
-(*DEBUG*) List.iter (function Odoc_types.Raw com ->
-(*DEBUG*) prerr_endline (tab ^ "com: " ^ com) | _ -> ())
+(*DEBUG*) List.iter (function Odoc_types.Raw com ->
+(*DEBUG*) prerr_endline (tab ^ "com: " ^ com) | _ -> ())
(*DEBUG*)let rec print_tec ?(tab = "") = function
-(*DEBUG*) Pv_ht htbl ->
-(*DEBUG*) prerr_endline (tab ^ "Pv_ht");
-(*DEBUG*) Hashtbl.iter begin fun lbl {coms=coms; tec=tec} ->
-(*DEBUG*) prerr_endline (tab ^ "LBL: " ^ lbl);
-(*DEBUG*) print_coms coms ~tab;
-(*DEBUG*) print_tec ~tab: (tab ^ " ") tec
-(*DEBUG*) end htbl
-(*DEBUG*) | Pv_l [] -> ()
-(*DEBUG*) | Pv_l l ->
-(*DEBUG*) prerr_endline (tab ^ "Pv_l");
-(*DEBUG*) List.iter (print_tec ~tab: (tab ^ " ")) l
+(*DEBUG*) Tec_variant htbl ->
+(*DEBUG*) prerr_endline (tab ^ "Tec_variant");
+(*DEBUG*) Hashtbl.iter begin fun lbl {coms=coms; tec=tec} ->
+(*DEBUG*) prerr_endline (tab ^ "LBL: " ^ lbl);
+(*DEBUG*) print_coms coms ~tab;
+(*DEBUG*) print_tec ~tab: (tab ^ " ") tec
+(*DEBUG*) end htbl
+(*DEBUG*)| Tec_list [] -> ()
+(*DEBUG*)| Tec_list l ->
+(*DEBUG*) prerr_endline (tab ^ "Tec_list");
+(*DEBUG*) List.iter (print_tec ~tab: (tab ^ " ")) l
8311ddd10756ba6e38d4607e4b76b71e5b3e177d
diff --git a/ocamldoc/odoc_cross.ml b/ocamldoc/odoc_cross.ml
index 6570e9a..6df118c 100644
--- a/ocamldoc/odoc_cross.ml
+++ b/ocamldoc/odoc_cross.ml
@@ -898,6 +898,17 @@ and assoc_comments_type module_list t =
(fun rf -> rf.rf_text <- ao (assoc_comments_text parent module_list) rf.rf_text)
fl
);
+ let rec f = function
+ Tec_list l -> List.iter f l
+ | Tec_variant ht ->
+ Hashtbl.iter
+ begin fun lbl buc ->
+ buc.tec_variant_coms <-
+ assoc_comments_text parent module_list
+ buc.tec_variant_coms;
+ f buc.tec_variant_tec
+ end ht
+ in (match t.ty_tmc with Some tec -> f tec | _ -> ());
t
and assoc_comments_attribute module_list a =
diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml
index 887435b..a96e130 100644
--- a/ocamldoc/odoc_html.ml
+++ b/ocamldoc/odoc_html.ml
@@ -1113,11 +1113,12 @@ class html =
bs b "*)";
bs b "</code></td>";
Buffer.contents b in
+ let str_of_ident =
+ self#create_fully_qualified_idents_links m_name in
let s = Odoc_info.remove_ending_newline
- (Odoc_info.string_of_type_expr t ?tec ~str_of_com) in
- let s2 = newline_to_indented_br s in
+ (Odoc_info.string_of_type_expr t ?tec ~str_of_com ~str_of_ident) in
bs b "<code class=\"type\">";
- bs b (self#create_fully_qualified_idents_links m_name s2);
+ bs b (newline_to_indented_br s);
bs b "</code>"
(** Print html code to display a [Types.type_expr list]. *)
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index ab3636d..647e45b 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -213,10 +213,11 @@ module Type :
(** fields * bool *)
type tec = Odoc_type.tec =
- Tec_variant of (string, tec_variant_buc) Hashtbl.t
- | Tec_list of tec list
+ Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ | Tec_list of tec list
and tec_variant_buc = Odoc_type.tec_variant_buc =
- { mutable coms: Odoc_types.text; tec: tec }
+ { mutable tec_variant_coms: Odoc_types.text;
+ tec_variant_tec: tec }
(** Representation of a type. *)
type t_type = Odoc_type.t_type =
@@ -232,8 +233,6 @@ module Type :
mutable ty_code : string option;
}
- (*DEBUG*)val print_tec : ?tab: string -> Odoc_type.tec -> unit
-
end
(** Representation and manipulation of values, class attributes and class methods. *)
@@ -611,6 +610,7 @@ val string_of_variance : Type.t_type -> (bool * bool) -> string
val string_of_type_expr :
?tec: Odoc_type.tec ->
?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
Types.type_expr -> string
(** @return a string to display the parameters of the given class,
diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml
index bf07823..27a5c97 100644
--- a/ocamldoc/odoc_merge.ml
+++ b/ocamldoc/odoc_merge.ml
@@ -259,12 +259,14 @@ let merge_types merge_options mli ml =
List.iter2 (fun x y -> f (x, y)) l l'
| Tec_variant ht, Tec_variant ht' ->
Hashtbl.iter
- begin fun lbl ({coms=coms; tec=tec} as buc) ->
- try let {coms=coms'; tec=tec'} = Hashtbl.find ht' lbl in
+ begin fun lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec} as buc) ->
+ try let {tec_variant_coms=coms';
+ tec_variant_tec=tec'} = Hashtbl.find ht' lbl in
if (coms' <> []
&& has_merge_description_option)
|| coms = []
- then buc.coms <- coms @ coms';
+ then buc.tec_variant_coms <- coms @ coms';
f (tec, tec')
with Not_found -> fail_on_different_types ()
end ht
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index ff78fad..7246356 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -43,12 +43,23 @@ module Odoc_oprint =
open Format
open Outcometree
- 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
+ let print_ident
+ ~str_of_ident
+ ppf x =
+ let buf = Buffer.create 12 in
+ let rec aux = function
+ Oide_ident s -> Buffer.add_string buf s
+ | Oide_dot (id, s) ->
+ aux id;
+ Buffer.add_string buf ".";
+ Buffer.add_string buf s
| Oide_apply (id1, id2) ->
- fprintf ppf "%a(%a)" print_ident id1 print_ident id2
+ aux id1;
+ Buffer.add_string buf "(";
+ aux id2;
+ Buffer.add_string buf ")"
+ in aux x;
+ fprintf ppf "%s" (str_of_ident (Buffer.contents buf))
let rec print_list_init pr sep ppf =
function
@@ -70,29 +81,31 @@ module Odoc_oprint =
let rec print_out_type
?(tec = Tec_list [])
?(str_of_com = Odoc_misc.string_of_text)
+ ?(str_of_ident = fun (x: string) -> x)
ppf =
function
| Otyp_alias (ty, s) ->
- fprintf ppf "@[%a@ as '%s@]" (print_out_type ~tec ~str_of_com) ty s
+ fprintf ppf "@[%a@ as '%s@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty s
| Otyp_poly (sl, ty) ->
fprintf ppf "@[<hov 2>%a.@ %a@]"
pr_vars sl
- (print_out_type ~tec ~str_of_com) ty
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
| ty ->
- print_out_type_1 ppf ty ~tec ~str_of_com
+ print_out_type_1 ppf ty ~tec ~str_of_com ~str_of_ident
- and print_out_type_1 ~tec ~str_of_com ppf =
+ and print_out_type_1 ~tec ~str_of_com ~str_of_ident ppf =
function
Otyp_arrow (lab, ty1, ty2) ->
let tec1, tec2 = match tec with
Tec_list [x;y] -> x, y
| _ -> Tec_list [], Tec_list [] in
fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "")
- (print_out_type_2 ~tec: tec1 ~str_of_com) ty1
- (print_out_type_1 ~tec: tec2 ~str_of_com) ty2
+ (print_out_type_2 ~tec: tec1 ~str_of_com ~str_of_ident) ty1
+ (print_out_type_1 ~tec: tec2 ~str_of_com ~str_of_ident) ty2
| ty ->
- print_out_type_2 ppf ty ~tec ~str_of_com
- and print_out_type_2 ~tec ~str_of_com ppf =
+ print_out_type_2 ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_out_type_2 ~tec ~str_of_com ~str_of_ident ppf =
function
Otyp_tuple tyl ->
let tecr = ref tec in
@@ -100,20 +113,24 @@ module Odoc_oprint =
let tec = match !tecr with
Tec_list (tec::t) -> tecr := Tec_list t; tec
| _ -> Tec_list [] in
- print_simple_out_type ~tec ~str_of_com ty
+ print_simple_out_type ~tec ~str_of_com ~str_of_ident ty
in fprintf ppf "@[<0>%a@]" (print_typlist print_elem " *") tyl
| ty ->
- print_simple_out_type ppf ty ~tec ~str_of_com
- and print_simple_out_type ~tec ~str_of_com ppf =
+ print_simple_out_type ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_simple_out_type ~tec ~str_of_com ~str_of_ident ppf =
function
Otyp_class (ng, id, tyl) ->
- fprintf ppf "@[%a%s#%a@]" (print_typargs ~tec ~str_of_com) tyl
+ fprintf ppf "@[%a%s#%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
(if ng then "_" else "")
- print_ident id
+ (print_ident ~str_of_ident) id
| Otyp_constr (id, tyl) ->
- fprintf ppf "@[%a%a@]" (print_typargs ~tec ~str_of_com) tyl print_ident id
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
| Otyp_object (fields, rest) ->
- fprintf ppf "@[<2>< %a >@]" (print_fields rest ~tec ~str_of_com) fields
+ fprintf ppf "@[<2>< %a >@]"
+ (print_fields rest ~tec ~str_of_com ~str_of_ident) fields
| Otyp_stuff s -> fprintf ppf "%s" s
| Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s
| Otyp_variant (non_gen, row_fields, closed, tags) ->
@@ -126,13 +143,13 @@ module Odoc_oprint =
function
Ovar_fields fields ->
print_list
- (print_row_field ~tec ~str_of_com)
+ (print_row_field ~tec ~str_of_com ~str_of_ident)
(fun ppf -> fprintf ppf "@;<1 -2>| ")
ppf fields
| Ovar_name (id, tyl) ->
fprintf ppf "@[%a%a@]"
- (print_typargs ~tec ~str_of_com) tyl
- print_ident id
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
in
fprintf ppf "%s[%s@[<hv>@[<hv>%a@]%a ]@]" (if non_gen then "_" else "")
(if closed then if tags = None then " " else "< "
@@ -140,9 +157,10 @@ module Odoc_oprint =
(print_fields ~tec ~str_of_com) row_fields
print_present tags
| Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty ->
- fprintf ppf "@[<1>(%a)@]" (print_out_type ~tec ~str_of_com) ty
+ fprintf ppf "@[<1>(%a)@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
| Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> ()
- and print_fields ~tec ~str_of_com rest ppf =
+ and print_fields ~tec ~str_of_com ~str_of_ident rest ppf =
function
[] ->
begin match rest with
@@ -152,34 +170,42 @@ module Odoc_oprint =
| [s, t] ->
let tec = match tec with Tec_list [h] -> h
| _ -> Tec_list [] in
- fprintf ppf "%s : %a" s (print_out_type ~tec ~str_of_com) t;
+ fprintf ppf "%s : %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t;
begin match rest with
Some _ -> fprintf ppf ";@ "
| None -> () end;
- print_fields ~tec: (Tec_list []) ~str_of_com rest ppf []
+ print_fields ~tec: (Tec_list [])
+ ~str_of_com ~str_of_ident rest ppf []
| (s, t) :: l ->
let tec, tec' = match tec with Tec_list (h::t) -> h, Tec_list t
| _ -> Tec_list [], Tec_list [] in
- fprintf ppf "%s : %a;@ %a" s (print_out_type ~tec ~str_of_com) t
- (print_fields rest ~tec: tec' ~str_of_com) l
- and print_row_field ~tec ~str_of_com ppf (l, opt_amp, tyl) =
+ fprintf ppf "%s : %a;@ %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t
+ (print_fields rest ~tec: tec' ~str_of_com ~str_of_ident) l
+ and print_row_field
+ ~tec ~str_of_com
+ ~str_of_ident 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
- let {Odoc_type.coms=coms; tec=tec} =
+ let {Odoc_type.tec_variant_coms=coms;
+ tec_variant_tec=tec} =
try match tec with
Tec_variant ht -> Hashtbl.find ht l
- | _ -> {Odoc_type.coms=[];tec=Tec_list []}
- with Not_found -> {Odoc_type.coms=[];tec=Tec_list []} in
+ | _ -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_tec=Tec_list []}
+ with Not_found -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_tec=Tec_list []} in
let str_coms =
if coms <> []
then str_of_com coms
else "" in
fprintf ppf "@[<hv 2>`%s%t%a%s%s@]"
l pr_of
- (print_typlist (print_out_type ~tec ~str_of_com) " &") tyl
+ (print_typlist (print_out_type ~tec ~str_of_com ~str_of_ident) " &") tyl
(if coms = [] then "" else " ")
str_coms
and print_typlist print_elem sep ppf =
@@ -189,328 +215,45 @@ module Odoc_oprint =
| ty :: tyl ->
fprintf ppf "%a%s@ %a" print_elem ty sep
(print_typlist print_elem sep) tyl
- and print_typargs ~tec ~str_of_com ppf =
+ and print_typargs ~tec ~str_of_com ~str_of_ident ppf =
function
[] -> ()
| [ty1] ->
let tec = match tec with Tec_list (h::t) -> h
| _ -> Tec_list [] in
- fprintf ppf "%a@ " (print_simple_out_type ~tec ~str_of_com) ty1
+ fprintf ppf "%a@ "
+ (print_simple_out_type ~tec ~str_of_com ~str_of_ident) ty1
| tyl ->
let tecr = ref tec in
let print_elem ty =
let tec = match !tecr with
Tec_list (tec::t) -> tecr := Tec_list t; tec
| _ -> Tec_list [] in
- print_out_type ~tec ~str_of_com ty
+ print_out_type ~tec ~str_of_com ~str_of_ident ty
in fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_elem ",") tyl
let out_type = ref print_out_type
end
-module Odoc_printtyp =
- struct
- open Misc
- open Ctype
- open Format
- open Longident
- open Path
- open Asttypes
- open Types
- open Odoc_type
- open Btype
- open Outcometree
- open Printtyp
-
-let names = ref ([] : (type_expr * string) list)
-let name_counter = ref 0
-
-let reset_names () = names := []; name_counter := 0
-
-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)) ^
- string_of_int(!name_counter / 26) in
- incr name_counter;
- name
-
-let name_of_type t =
- try List.assq t !names with Not_found ->
- let name = new_name () in
- names := (t, name) :: !names;
- name
-
-let check_name_of_type t = ignore(name_of_type t)
-
-let non_gen_mark sch ty =
- if sch && ty.desc = Tvar && ty.level <> generic_level then "_" else ""
-
-let print_name_of_type sch ppf t =
- fprintf ppf "'%s%s" (non_gen_mark sch t) (name_of_type t)
-
-let visited_objects = ref ([] : type_expr list)
-let aliased = ref ([] : type_expr list)
-let delayed = ref ([] : type_expr list)
-
-let add_delayed t =
- if not (List.memq t !delayed) then delayed := t :: !delayed
-
-let is_aliased ty = List.memq (proxy ty) !aliased
-let add_alias ty =
- let px = proxy ty in
- if not (is_aliased px) then aliased := px :: !aliased
-let aliasable ty =
- match ty.desc with Tvar | Tunivar | Tpoly _ -> false | _ -> true
-
-let namable_row row =
- row.row_name <> None &&
- List.for_all
- (fun (_, f) ->
- match row_field_repr f with
- | Reither(c, l, _, _) ->
- row.row_closed && if c then l = [] else List.length l = 1
- | _ -> true)
- row.row_fields
-
-let reset_loop_marks () =
- visited_objects := []; aliased := []; delayed := []
-
-let reset () =
- reset_names (); reset_loop_marks ()
-
-let rec mark_loops_rec visited ty =
- let ty = repr ty in
- let px = proxy ty in
- if List.memq px visited && aliasable ty then add_alias px else
- let visited = px :: visited in
- match ty.desc with
- | Tvar -> ()
- | Tarrow(_, ty1, ty2, _) ->
- mark_loops_rec visited ty1; mark_loops_rec visited ty2
- | Ttuple tyl -> List.iter (mark_loops_rec visited) tyl
- | Tconstr(_, tyl, _) ->
- List.iter (mark_loops_rec visited) tyl
- | Tvariant row ->
- if List.memq px !visited_objects then add_alias px else
- begin
- let row = row_repr row in
- if not (static_row row) then
- visited_objects := px :: !visited_objects;
- match row.row_name with
- | Some(p, tyl) when namable_row row ->
- List.iter (mark_loops_rec visited) tyl
- | _ ->
- iter_row (mark_loops_rec visited) row
- end
- | Tobject (fi, nm) ->
- if List.memq px !visited_objects then add_alias px else
- begin
- if opened_object ty then
- visited_objects := px :: !visited_objects;
- begin match !nm with
- | None ->
- let fields, _ = flatten_fields fi in
- List.iter
- (fun (_, kind, ty) ->
- if field_kind_repr kind = Fpresent then
- mark_loops_rec visited ty)
- fields
- | Some (_, l) ->
- List.iter (mark_loops_rec visited) (List.tl l)
- end
- end
- | Tfield(_, kind, ty1, ty2) when field_kind_repr kind = Fpresent ->
- mark_loops_rec visited ty1; mark_loops_rec visited ty2
- | Tfield(_, _, _, ty2) ->
- mark_loops_rec visited ty2
- | Tnil -> ()
- | Tsubst ty -> mark_loops_rec visited ty
- | Tlink _ -> fatal_error "Odoc_print.mark_loops_rec (2)"
- | Tpoly (ty, tyl) ->
- List.iter (fun t -> add_alias t) tyl;
- mark_loops_rec visited ty
- | Tunivar -> ()
-
-let mark_loops ty =
- normalize_type Env.empty ty;
- mark_loops_rec [] ty;;
-
-(* Disabled in classic mode when printing an unification error *)
-let print_labels = ref true
-let print_label ppf l =
- if !print_labels && l <> "" || is_optional l then fprintf ppf "%s:" l
-
-let rec tree_of_typexp sch ty =
- let ty = repr ty in
- let px = proxy ty in
- if List.mem_assq px !names && not (List.memq px !delayed) then
- let mark = is_non_gen sch ty in
- Otyp_var (mark, name_of_type px) else
-
- let pr_typ () =
- match ty.desc with
- | Tvar ->
- Otyp_var (is_non_gen sch ty, name_of_type ty)
- | Tarrow(l, ty1, ty2, _) ->
- 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
- | Ttuple tyl ->
- Otyp_tuple (tree_of_typlist sch tyl)
- | Tconstr(p, tyl, abbrev) ->
- Otyp_constr (tree_of_path p, tree_of_typlist sch tyl)
- | Tvariant row ->
- let row = row_repr row in
- let fields =
- if row.row_closed then
- List.filter (fun (_, f) -> row_field_repr f <> Rabsent)
- row.row_fields
- else row.row_fields in
- let present =
- List.filter
- (fun (_, f) ->
- match row_field_repr f with
- | Rpresent _ -> true
- | _ -> false)
- fields in
- let all_present = List.length present = List.length fields in
- begin match row.row_name with
- | Some(p, tyl) when namable_row row ->
- let id = tree_of_path p in
- let args = tree_of_typlist sch tyl in
- if row.row_closed && all_present then
- Otyp_constr (id, args)
- else
- let non_gen = is_non_gen sch px in
- 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)
- | _ ->
- let non_gen =
- not (row.row_closed && all_present) && is_non_gen sch px in
- let fields = List.map (tree_of_row_field sch) fields in
- let tags =
- if all_present then None else Some (List.map fst present) in
- Otyp_variant (non_gen, Ovar_fields fields, row.row_closed, tags)
- end
- | Tobject (fi, nm) ->
- tree_of_typobject sch fi nm
- | Tsubst ty ->
- tree_of_typexp sch ty
- | Tlink _ | Tnil | Tfield _ ->
- fatal_error "Odoc_print.tree_of_typexp"
- | Tpoly (ty, []) ->
- tree_of_typexp sch ty
- | Tpoly (ty, tyl) ->
- let tyl = List.map repr tyl in
- (* let tyl = List.filter is_aliased tyl in *)
- if tyl = [] then tree_of_typexp sch ty else begin
- let old_delayed = !delayed in
- List.iter add_delayed tyl;
- let tl = List.map name_of_type tyl in
- let tr = Otyp_poly (tl, tree_of_typexp sch ty) in
- delayed := old_delayed; tr
- end
- | Tunivar ->
- Otyp_var (false, name_of_type ty)
- in
- if List.memq px !delayed then delayed := List.filter ((!=) px) !delayed;
- if is_aliased px && aliasable ty then begin
- check_name_of_type px;
- 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 tyl =
- List.map (tree_of_typexp sch) tyl
-
-and tree_of_typobject sch fi nm =
- begin match !nm with
- | None ->
- let pr_fields fi =
- 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
- tree_of_typfields sch rest sorted_fields in
- let (fields, rest) = pr_fields fi in
- Otyp_object (fields, rest)
- | Some (p, ty :: tyl) ->
- let non_gen = is_non_gen sch (repr ty) in
- let args = tree_of_typlist sch tyl in
- Otyp_class (non_gen, tree_of_path p, args)
- | _ ->
- fatal_error "Odoc_print.tree_of_typobject"
- end
-
-and is_non_gen sch ty =
- sch && ty.desc = Tvar && ty.level <> generic_level
-
-and tree_of_typfields sch rest = function
- | [] ->
- let rest =
- match rest.desc with
- | Tvar | Tunivar -> Some (is_non_gen sch rest)
- | Tconstr _ -> Some false
- | 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 typexp ?tec ?str_of_com sch prio ppf ty =
- !Odoc_oprint.out_type ?tec ?str_of_com ppf
- (tree_of_typexp sch ty)
-
- let type_scheme
- ?tec ?str_of_com
- ?(b_reset_names = true)
- ppf ty =
- if b_reset_names then reset_names ();
- typexp true 0 ppf ty ?tec ?str_of_com
- end
+let type_scheme
+ ?tec ?str_of_com ?str_of_ident
+ ?(b_reset_names = true)
+ ppf ty =
+ if b_reset_names then Printtyp.reset_names ();
+ let out_type'save = !Oprint.out_type in
+ Oprint.out_type := !Odoc_oprint.out_type
+ ?tec ?str_of_com ?str_of_ident;
+ Printtyp.type_sch ppf ty;
+ Oprint.out_type := out_type'save
-let type_scheme = Odoc_printtyp.type_scheme
-let mark_loops = Odoc_printtyp.mark_loops
-let reset = Odoc_printtyp.reset
+let mark_loops = Printtyp.mark_loops
+let reset = Printtyp.reset
let string_of_type_expr
- ?tec ?str_of_com t =
- Odoc_printtyp.mark_loops t;
+ ?tec ?str_of_com ?str_of_ident t =
+ Printtyp.mark_loops t;
type_scheme type_fmt t
- ?tec ?str_of_com
+ ?tec ?str_of_com ?str_of_ident
~b_reset_names: false;
flush_type_fmt ()
diff --git a/ocamldoc/odoc_print.mli b/ocamldoc/odoc_print.mli
index a39bbdd..ec30d28 100644
--- a/ocamldoc/odoc_print.mli
+++ b/ocamldoc/odoc_print.mli
@@ -18,6 +18,7 @@ val mark_loops: Types.type_expr -> unit
val type_scheme:
?tec: Odoc_type.tec ->
?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
?b_reset_names: bool ->
Format.formatter -> Types.type_expr -> unit
@@ -32,6 +33,7 @@ val reset: unit -> unit
val string_of_type_expr :
?tec: Odoc_type.tec ->
?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
Types.type_expr -> string
(** This function returns a string representing a [Types.module_type].
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index dbc7e8e..a855974 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -248,7 +248,6 @@ module Analyser =
| ']' -> decr cnt
| _ -> ()
done end;
- (*DEBUG*)prerr_endline ("s: " ^ !s);
(* try to extract a comment *)
let _, comment_opt =
My_ir.just_after_special !file_name !s in
@@ -262,12 +261,14 @@ module Analyser =
| _ -> l1 @ l2 in
let rec merge_com
?(glob_coms = [])
- htbl lbl ({coms=coms; tec=tec} as buc) : unit =
+ htbl lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec} as buc) : unit =
let glob_coms = if glob_coms = [] then glob_coms
else Odoc_types.Raw " " (* XXX: hardcoded separator *)
:: glob_coms in
- try let {coms=old_coms; tec=old_tec} as buc = Hashtbl.find htbl lbl in
- buc.coms <- old_coms @ (coms @ glob_coms);
+ try let {tec_variant_coms=old_coms;
+ tec_variant_tec=old_tec} as buc = Hashtbl.find htbl lbl in
+ buc.tec_variant_coms <- old_coms @ (coms @ glob_coms);
let rec f = function Tec_variant old_htbl ->
(function Tec_variant htbl -> Hashtbl.iter (merge_com old_htbl) htbl
| _ -> assert false)
@@ -276,14 +277,16 @@ module Analyser =
| _ -> assert false) in
f old_tec tec
with Not_found ->
- buc.coms <- buc.coms @ glob_coms;
+ buc.tec_variant_coms <- buc.tec_variant_coms @ glob_coms;
Hashtbl.add htbl lbl buc
in
let rec clone_tec = function
Tec_variant htbl ->
let ht = Hashtbl.create (Hashtbl.length htbl) in
- Hashtbl.iter begin fun lbl {coms=coms; tec=tec} ->
- Hashtbl.add ht lbl {coms=coms; tec=clone_tec tec}
+ Hashtbl.iter begin fun lbl {tec_variant_coms=coms;
+ tec_variant_tec=tec} ->
+ Hashtbl.add ht lbl {tec_variant_coms=coms;
+ tec_variant_tec=clone_tec tec}
end htbl;
Tec_variant ht
| Tec_list l -> Tec_list (List.map clone_tec l)
@@ -317,26 +320,21 @@ module Analyser =
| Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
List.iter begin function
Parsetree.Rtag (lbl, b, l) ->
- (*DEBUG*)prerr_endline ("\nlabel: " ^ lbl);
(* map the sub-types of the current variant *)
let l = List.map get l in
let tec = match l with [tec] -> tec (* not really a tuple *)
| _ -> Tec_list l in
- (*DEBUG*)prerr_endline ("l[len]: " ^ string_of_int (List.length l));
let coms = retrieve_comments pos_end loc dlen in
- (*DEBUG*)print_coms coms;
- merge_com htbl lbl ({coms=coms; tec=tec});
+ merge_com htbl lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec});
| Parsetree.Rinherit ct ->
let ht = match get ct with Tec_variant ht -> ht
| _ -> assert false in
let glob_coms = retrieve_comments pos_end loc dlen in
- (*DEBUG*)prerr_endline ("glob_coms");
- (*DEBUG*)print_coms glob_coms;
Hashtbl.iter (merge_com htbl ~glob_coms) ht
end row_field_list;
Tec_variant htbl
in
- (*DEBUG*)print_tec tec;
tec
in
let tec = get par_ct in
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 6fff1ed..9240102 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -39,9 +39,11 @@ type type_kind =
(** fields * bool *)
type tec =
- Tec_variant of (string, tec_variant_buc) Hashtbl.t
-| Tec_list of tec list
-and tec_variant_buc = { mutable coms: Odoc_types.text; tec: tec }
+ Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ | Tec_list of tec list
+and tec_variant_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ tec_variant_tec: tec }
(** Representation of a type. *)
type t_type = {
@@ -56,20 +58,4 @@ type t_type = {
mutable ty_code : string option;
}
-(*DEBUG*)let print_coms ?(tab = "") =
-(*DEBUG*) List.iter (function Odoc_types.Raw com ->
-(*DEBUG*) prerr_endline (tab ^ "com: " ^ com) | _ -> ())
-(*DEBUG*)let rec print_tec ?(tab = "") = function
-(*DEBUG*) Tec_variant htbl ->
-(*DEBUG*) prerr_endline (tab ^ "Tec_variant");
-(*DEBUG*) Hashtbl.iter begin fun lbl {coms=coms; tec=tec} ->
-(*DEBUG*) prerr_endline (tab ^ "LBL: " ^ lbl);
-(*DEBUG*) print_coms coms ~tab;
-(*DEBUG*) print_tec ~tab: (tab ^ " ") tec
-(*DEBUG*) end htbl
-(*DEBUG*)| Tec_list [] -> ()
-(*DEBUG*)| Tec_list l ->
-(*DEBUG*) prerr_endline (tab ^ "Tec_list");
-(*DEBUG*) List.iter (print_tec ~tab: (tab ^ " ")) l
-
diff --git a/ocamldoc/.depend b/ocamldoc/.depend
index 5e2196a..47b84e8 100644
--- a/ocamldoc/.depend
+++ b/ocamldoc/.depend
@@ -1,11 +1,3 @@
-odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
- odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
- odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
- ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
-odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
- odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
- odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
- ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_analyse.cmo: ../utils/warnings.cmi ../typing/typetexp.cmi \
../typing/types.cmi ../typing/typemod.cmi ../typing/typedtree.cmi \
../typing/typedecl.cmi ../typing/typecore.cmi ../typing/typeclass.cmi \
@@ -50,18 +42,22 @@ odoc_ast.cmx: ../typing/types.cmx ../typing/typedtree.cmx \
odoc_global.cmx odoc_exception.cmx odoc_env.cmx odoc_class.cmx \
odoc_args.cmx ../utils/misc.cmx ../parsing/location.cmx \
../typing/ident.cmx ../parsing/asttypes.cmi odoc_ast.cmi
+odoc_btype.cmo: ../typing/types.cmi ../typing/path.cmi odoc_type.cmo \
+ ../typing/btype.cmi ../parsing/asttypes.cmi
+odoc_btype.cmx: ../typing/types.cmx ../typing/path.cmx odoc_type.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi
odoc_class.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_parameter.cmo odoc_name.cmi
odoc_class.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
odoc_parameter.cmx odoc_name.cmx
+odoc_comments_global.cmo: odoc_comments_global.cmi
+odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_comments.cmo: odoc_types.cmi odoc_text.cmi odoc_see_lexer.cmo \
odoc_parser.cmi odoc_misc.cmi odoc_messages.cmo odoc_lexer.cmo \
odoc_global.cmi odoc_cross.cmi odoc_comments_global.cmi odoc_comments.cmi
odoc_comments.cmx: odoc_types.cmx odoc_text.cmx odoc_see_lexer.cmx \
odoc_parser.cmx odoc_misc.cmx odoc_messages.cmx odoc_lexer.cmx \
odoc_global.cmx odoc_cross.cmx odoc_comments_global.cmx odoc_comments.cmi
-odoc_comments_global.cmo: odoc_comments_global.cmi
-odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_config.cmo: ../utils/config.cmi odoc_config.cmi
odoc_config.cmx: ../utils/config.cmx odoc_config.cmi
odoc_cross.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_search.cmi \
@@ -72,6 +68,14 @@ odoc_cross.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_search.cmx \
odoc_scan.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx odoc_class.cmx \
odoc_cross.cmi
+odoc_ctype.cmo: ../typing/types.cmi ../typing/subst.cmi ../typing/path.cmi \
+ odoc_type.cmo odoc_btype.cmo ../utils/misc.cmi ../parsing/longident.cmi \
+ ../typing/ident.cmi ../typing/env.cmi ../utils/clflags.cmi \
+ ../typing/btype.cmi ../parsing/asttypes.cmi
+odoc_ctype.cmx: ../typing/types.cmx ../typing/subst.cmx ../typing/path.cmx \
+ odoc_type.cmx odoc_btype.cmx ../utils/misc.cmx ../parsing/longident.cmx \
+ ../typing/ident.cmx ../typing/env.cmx ../utils/clflags.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi
odoc_dag2html.cmo: odoc_info.cmi odoc_dag2html.cmi
odoc_dag2html.cmx: odoc_info.cmx odoc_dag2html.cmi
odoc_dep.cmo: ../parsing/parsetree.cmi odoc_type.cmo odoc_print.cmi \
@@ -80,30 +84,30 @@ odoc_dep.cmx: ../parsing/parsetree.cmi odoc_type.cmx odoc_print.cmx \
odoc_module.cmx ../tools/depend.cmx
odoc_dot.cmo: odoc_info.cmi
odoc_dot.cmx: odoc_info.cmx
-odoc_env.cmo: ../typing/types.cmi ../typing/printtyp.cmi ../typing/predef.cmi \
- ../typing/path.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
-odoc_env.cmx: ../typing/types.cmx ../typing/printtyp.cmx ../typing/predef.cmx \
- ../typing/path.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
+odoc_env.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
+ odoc_print.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
+odoc_env.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
+ odoc_print.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
odoc_exception.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_exception.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_global.cmo: ../utils/clflags.cmi odoc_global.cmi
odoc_global.cmx: ../utils/clflags.cmx odoc_global.cmi
-odoc_html.cmo: odoc_text.cmi odoc_ocamlhtml.cmo odoc_messages.cmo \
- odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
-odoc_html.cmx: odoc_text.cmx odoc_ocamlhtml.cmx odoc_messages.cmx \
- odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
-odoc_info.cmo: ../typing/printtyp.cmi odoc_value.cmo odoc_types.cmi \
- odoc_type.cmo odoc_text.cmi odoc_str.cmi odoc_search.cmi odoc_scan.cmo \
- odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
- odoc_misc.cmi odoc_messages.cmo odoc_global.cmi odoc_exception.cmo \
- odoc_dep.cmo odoc_config.cmi odoc_comments.cmi odoc_class.cmo \
- odoc_args.cmi odoc_analyse.cmi odoc_info.cmi
-odoc_info.cmx: ../typing/printtyp.cmx odoc_value.cmx odoc_types.cmx \
- odoc_type.cmx odoc_text.cmx odoc_str.cmx odoc_search.cmx odoc_scan.cmx \
- odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
- odoc_misc.cmx odoc_messages.cmx odoc_global.cmx odoc_exception.cmx \
- odoc_dep.cmx odoc_config.cmx odoc_comments.cmx odoc_class.cmx \
- odoc_args.cmx odoc_analyse.cmx odoc_info.cmi
+odoc_html.cmo: odoc_type.cmo odoc_text.cmi odoc_ocamlhtml.cmo \
+ odoc_messages.cmo odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
+odoc_html.cmx: odoc_type.cmx odoc_text.cmx odoc_ocamlhtml.cmx \
+ odoc_messages.cmx odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
+odoc_info.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_text.cmi \
+ odoc_str.cmi odoc_search.cmi odoc_scan.cmo odoc_print.cmi \
+ odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_misc.cmi \
+ odoc_messages.cmo odoc_global.cmi odoc_exception.cmo odoc_dep.cmo \
+ odoc_config.cmi odoc_comments.cmi odoc_class.cmo odoc_args.cmi \
+ odoc_analyse.cmi odoc_info.cmi
+odoc_info.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_text.cmx \
+ odoc_str.cmx odoc_search.cmx odoc_scan.cmx odoc_print.cmx \
+ odoc_parameter.cmx odoc_name.cmx odoc_module.cmx odoc_misc.cmx \
+ odoc_messages.cmx odoc_global.cmx odoc_exception.cmx odoc_dep.cmx \
+ odoc_config.cmx odoc_comments.cmx odoc_class.cmx odoc_args.cmx \
+ odoc_analyse.cmx odoc_info.cmi
odoc_latex.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_latex_style.cmo \
odoc_info.cmi
odoc_latex.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_latex_style.cmx \
@@ -130,6 +134,14 @@ odoc_misc.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
odoc_misc.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
odoc_types.cmx odoc_messages.cmx ../parsing/longident.cmx \
../typing/ctype.cmx ../typing/btype.cmx odoc_misc.cmi
+odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
+ odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
+ odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
+ ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
+odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
+ odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
+ odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
+ ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_module.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_type.cmo odoc_name.cmi odoc_exception.cmo odoc_class.cmo
odoc_module.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
@@ -146,12 +158,22 @@ odoc_opt.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
odoc_dot.cmx odoc_args.cmx odoc_analyse.cmx ../utils/misc.cmx \
../utils/config.cmx ../utils/clflags.cmx
+odoc_outcometree.cmo: odoc_types.cmi
+odoc_outcometree.cmx: odoc_types.cmx
odoc_parameter.cmo: ../typing/types.cmi odoc_types.cmi
odoc_parameter.cmx: ../typing/types.cmx odoc_types.cmx
odoc_parser.cmo: odoc_types.cmi odoc_comments_global.cmi odoc_parser.cmi
odoc_parser.cmx: odoc_types.cmx odoc_comments_global.cmx odoc_parser.cmi
-odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_print.cmi
-odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_print.cmi
+odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi \
+ ../typing/predef.cmi ../typing/path.cmi ../typing/outcometree.cmi \
+ odoc_type.cmo odoc_misc.cmi ../utils/misc.cmi ../parsing/longident.cmi \
+ ../typing/env.cmi ../typing/ctype.cmi ../typing/btype.cmi \
+ ../parsing/asttypes.cmi odoc_print.cmi
+odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx \
+ ../typing/predef.cmx ../typing/path.cmx ../typing/outcometree.cmi \
+ odoc_type.cmx odoc_misc.cmx ../utils/misc.cmx ../parsing/longident.cmx \
+ ../typing/env.cmx ../typing/ctype.cmx ../typing/btype.cmx \
+ ../parsing/asttypes.cmi odoc_print.cmi
odoc_scan.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_scan.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_module.cmx \
@@ -169,31 +191,31 @@ odoc_sig.cmo: ../typing/types.cmi ../typing/typedtree.cmi ../typing/path.cmi \
odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
odoc_misc.cmi odoc_messages.cmo odoc_merge.cmi odoc_global.cmi \
odoc_exception.cmo odoc_env.cmi odoc_class.cmo odoc_args.cmi \
- ../utils/misc.cmi ../parsing/location.cmi ../typing/btype.cmi \
- ../parsing/asttypes.cmi odoc_sig.cmi
+ ../utils/misc.cmi ../parsing/longident.cmi ../parsing/location.cmi \
+ ../typing/btype.cmi ../parsing/asttypes.cmi odoc_sig.cmi
odoc_sig.cmx: ../typing/types.cmx ../typing/typedtree.cmx ../typing/path.cmx \
../parsing/parsetree.cmi odoc_value.cmx odoc_types.cmx odoc_type.cmx \
odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_merge.cmx odoc_global.cmx \
odoc_exception.cmx odoc_env.cmx odoc_class.cmx odoc_args.cmx \
- ../utils/misc.cmx ../parsing/location.cmx ../typing/btype.cmx \
- ../parsing/asttypes.cmi odoc_sig.cmi
-odoc_str.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_value.cmo \
- odoc_type.cmo odoc_print.cmi odoc_name.cmi odoc_misc.cmi \
- odoc_messages.cmo odoc_exception.cmo odoc_class.cmo odoc_str.cmi
-odoc_str.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_value.cmx \
- odoc_type.cmx odoc_print.cmx odoc_name.cmx odoc_misc.cmx \
- odoc_messages.cmx odoc_exception.cmx odoc_class.cmx odoc_str.cmi
+ ../utils/misc.cmx ../parsing/longident.cmx ../parsing/location.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi odoc_sig.cmi
+odoc_str.cmo: ../typing/types.cmi odoc_value.cmo odoc_type.cmo odoc_print.cmi \
+ odoc_name.cmi odoc_misc.cmi odoc_messages.cmo odoc_exception.cmo \
+ odoc_class.cmo odoc_str.cmi
+odoc_str.cmx: ../typing/types.cmx odoc_value.cmx odoc_type.cmx odoc_print.cmx \
+ odoc_name.cmx odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx \
+ odoc_class.cmx odoc_str.cmi
odoc_test.cmo: odoc_info.cmi
odoc_test.cmx: odoc_info.cmx
odoc_texi.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_info.cmi
odoc_texi.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_info.cmx
+odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
+odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text.cmo: odoc_types.cmi odoc_text_parser.cmi odoc_text_lexer.cmo \
odoc_text.cmi
odoc_text.cmx: odoc_types.cmx odoc_text_parser.cmx odoc_text_lexer.cmx \
odoc_text.cmi
-odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
-odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text_parser.cmo: odoc_types.cmi odoc_misc.cmi odoc_text_parser.cmi
odoc_text_parser.cmx: odoc_types.cmx odoc_misc.cmx odoc_text_parser.cmi
odoc_to_text.cmo: odoc_messages.cmo odoc_info.cmi
@@ -202,9 +224,9 @@ odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_types.cmo: odoc_messages.cmo odoc_types.cmi
odoc_types.cmx: odoc_messages.cmx odoc_types.cmi
-odoc_value.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_types.cmi \
+odoc_value.cmo: ../typing/types.cmi odoc_types.cmi odoc_print.cmi \
odoc_parameter.cmo odoc_name.cmi
-odoc_value.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_types.cmx \
+odoc_value.cmx: ../typing/types.cmx odoc_types.cmx odoc_print.cmx \
odoc_parameter.cmx odoc_name.cmx
odoc_analyse.cmi: odoc_module.cmo odoc_args.cmi
odoc_args.cmi: odoc_types.cmi odoc_module.cmo
@@ -222,7 +244,7 @@ odoc_misc.cmi: ../typing/types.cmi odoc_types.cmi ../parsing/longident.cmi
odoc_name.cmi: ../typing/path.cmi ../parsing/longident.cmi \
../typing/ident.cmi
odoc_parser.cmi: odoc_types.cmi
-odoc_print.cmi: ../typing/types.cmi
+odoc_print.cmi: ../typing/types.cmi odoc_types.cmi odoc_type.cmo
odoc_search.cmi: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_sig.cmi: ../typing/types.cmi ../parsing/parsetree.cmi odoc_types.cmi \
diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile
index c181142..3749001 100644
--- a/ocamldoc/Makefile
+++ b/ocamldoc/Makefile
@@ -81,12 +81,12 @@ CMOFILES= odoc_config.cmo \
odoc_text.cmo\
odoc_name.cmo\
odoc_parameter.cmo\
+ odoc_print.cmo \
odoc_value.cmo\
odoc_type.cmo\
odoc_exception.cmo\
odoc_class.cmo\
odoc_module.cmo\
- odoc_print.cmo \
odoc_str.cmo\
odoc_args.cmo\
odoc_comments_global.cmo\
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index efee6ea..d45280f 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -939,7 +939,8 @@ module Analyser =
List.filter pred l
(** Analysis of a parse tree structure with a typed tree, to return module elements.*)
- let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree =
+ let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree
+ poly_variant_tec_htbl =
print_DEBUG "Odoc_ast:analyse_struture";
let (table, table_values) = Typedtree_search.tables typedtree in
let rec iter env last_pos = function
@@ -977,6 +978,7 @@ module Analyser =
typedtree
table
table_values
+ poly_variant_tec_htbl
in
ele_comments @ elements @ (iter new_env (item.Parsetree.pstr_loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q)
in
@@ -984,7 +986,7 @@ module Analyser =
(** Analysis of a parse tree structure item to obtain a new environment and a list of elements.*)
and analyse_structure_item env current_module_name loc pos_limit comment_opt parsetree_item_desc typedtree
- table table_values =
+ table table_values poly_variant_tec_htbl =
print_DEBUG "Odoc_ast:analyse_struture_item";
match parsetree_item_desc with
Parsetree.Pstr_eval _ ->
@@ -1115,6 +1117,10 @@ module Analyser =
new_env name_comment_list
tt_type_decl.Types.type_kind
in
+ let tec = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (Sig.get_tec poly_variant_tec_htbl ct ~current_module_name ~name
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
let new_end = loc_end + maybe_more in
let t =
{
@@ -1133,6 +1139,7 @@ module Analyser =
(match tt_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tmc = tec;
ty_loc = { loc_impl = Some (!file_name, loc_start) ; loc_inter = None } ;
ty_code =
(
@@ -1220,6 +1227,7 @@ module Analyser =
comment_opt
module_expr
tt_module_expr
+ poly_variant_tec_htbl
in
let code =
if !Odoc_args.keep_code then
@@ -1269,6 +1277,7 @@ module Analyser =
None
mod_exp
tt_mod_exp
+ poly_variant_tec_htbl
in
match new_module.m_type with
Types.Tmty_signature s ->
@@ -1304,6 +1313,7 @@ module Analyser =
com_opt
mod_exp
tt_mod_exp
+ poly_variant_tec_htbl
in
let eles = f loc_end q in
ele_comments @ ((Element_module new_module) :: eles)
@@ -1319,7 +1329,7 @@ module Analyser =
raise (Failure (Odoc_messages.module_type_not_found_in_typedtree complete_name))
in
let kind = Sig.analyse_module_type_kind env complete_name
- modtype tt_module_type
+ modtype tt_module_type poly_variant_tec_htbl
in
let mt =
{
@@ -1465,7 +1475,8 @@ module Analyser =
(0, env, [ Element_included_module im ]) (* A VOIR : étendre l'environnement ? avec quoi ? *)
(** Analysis of a [Parsetree.module_expr] and a name to return a [t_module].*)
- and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr =
+ and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr
+ poly_variant_tec_htbl =
let complete_name = Name.concat current_module_name module_name in
let pos_start = p_module_expr.Parsetree.pmod_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = p_module_expr.Parsetree.pmod_loc.Location.loc_end.Lexing.pos_cnum in
@@ -1504,7 +1515,8 @@ module Analyser =
ma_module = None ; } }
| (Parsetree.Pmod_structure p_structure, Typedtree.Tmod_structure tt_structure) ->
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start
+ pos_end p_structure tt_structure poly_variant_tec_htbl in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1519,6 +1531,7 @@ module Analyser =
let mp_name = Name.from_ident ident in
let mp_kind = Sig.analyse_module_type_kind env
current_module_name pmodule_type mtyp
+ poly_variant_tec_htbl
in
let param =
{
@@ -1538,6 +1551,7 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ poly_variant_tec_htbl
in
let kind = m_base2.m_kind in
{ m_base with m_kind = Module_functor (param, kind) }
@@ -1556,6 +1570,7 @@ module Analyser =
None
p_module_expr1
tt_module_expr1
+ poly_variant_tec_htbl
in
let m2 = analyse_module
env
@@ -1564,6 +1579,7 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ poly_variant_tec_htbl
in
{ m_base with m_kind = Module_apply (m1.m_kind, m2.m_kind) }
@@ -1577,10 +1593,11 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ poly_variant_tec_htbl
in
let mtkind = Sig.analyse_module_type_kind env
(Name.concat current_module_name "??")
- p_modtype tt_modtype
+ p_modtype tt_modtype poly_variant_tec_htbl
in
let tt_modtype = Odoc_env.subst_module_type env tt_modtype in
filter_module_with_module_type_constraint m_base2 tt_modtype;
@@ -1598,7 +1615,8 @@ module Analyser =
(* needed for recursive modules *)
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_structure + Typedtree.Tmod_constraint "^module_name);
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start pos_end
+ p_structure tt_structure poly_variant_tec_htbl in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1652,7 +1670,9 @@ module Analyser =
let (len,info_opt) = My_ir.first_special !file_name !file in
(* we must complete the included modules *)
- let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file) parsetree tree_structure in
+ let poly_variant_tec_htbl = Hashtbl.create 12 in
+ let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file)
+ parsetree tree_structure poly_variant_tec_htbl in
let included_modules_from_tt = tt_get_included_module_list tree_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
let kind = Module_struct elements2 in
diff --git a/ocamldoc/odoc_cross.ml b/ocamldoc/odoc_cross.ml
index 6570e9a..6df118c 100644
--- a/ocamldoc/odoc_cross.ml
+++ b/ocamldoc/odoc_cross.ml
@@ -898,6 +898,17 @@ and assoc_comments_type module_list t =
(fun rf -> rf.rf_text <- ao (assoc_comments_text parent module_list) rf.rf_text)
fl
);
+ let rec f = function
+ Tec_list l -> List.iter f l
+ | Tec_variant ht ->
+ Hashtbl.iter
+ begin fun lbl buc ->
+ buc.tec_variant_coms <-
+ assoc_comments_text parent module_list
+ buc.tec_variant_coms;
+ f buc.tec_variant_tec
+ end ht
+ in (match t.ty_tmc with Some tec -> f tec | _ -> ());
t
and assoc_comments_attribute module_list a =
diff --git a/ocamldoc/odoc_env.ml b/ocamldoc/odoc_env.ml
index ed9fb26..0865f8d 100644
--- a/ocamldoc/odoc_env.ml
+++ b/ocamldoc/odoc_env.ml
@@ -181,7 +181,7 @@ let subst_type env t =
print_env_types env ;
print_newline ();
*)
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
let deja_vu = ref [] in
let rec iter t =
if List.memq t !deja_vu then () else begin
diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml
index f34ad5e..a96e130 100644
--- a/ocamldoc/odoc_html.ml
+++ b/ocamldoc/odoc_html.ml
@@ -1098,11 +1098,27 @@ class html =
s2
(** Print html code to display a [Types.type_expr]. *)
- method html_of_type_expr b m_name t =
- let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_type_expr t) in
- let s2 = newline_to_indented_br s in
+ method html_of_type_expr ?tec b m_name t =
+ let str_of_com coms =
+ let b = Buffer.create 42 in
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ bs b "<code>";
+ bs b "(*";
+ bs b "</code></td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ self#html_of_text b coms;
+ bs b "</td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
+ bs b "<code>";
+ bs b "*)";
+ bs b "</code></td>";
+ Buffer.contents b in
+ let str_of_ident =
+ self#create_fully_qualified_idents_links m_name in
+ let s = Odoc_info.remove_ending_newline
+ (Odoc_info.string_of_type_expr t ?tec ~str_of_com ~str_of_ident) in
bs b "<code class=\"type\">";
- bs b (self#create_fully_qualified_idents_links m_name s2);
+ bs b (newline_to_indented_br s);
bs b "</code>"
(** Print html code to display a [Types.type_expr list]. *)
@@ -1372,7 +1388,7 @@ class html =
None -> ()
| Some typ ->
bs b "= ";
- self#html_of_type_expr b father typ;
+ self#html_of_type_expr b father typ ?tec: t.ty_tmc;
bs b " "
);
(match t.ty_kind with
@@ -1814,7 +1830,8 @@ class html =
(Naming.type_target
{ ty_name = c.cl_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
@@ -1861,7 +1878,8 @@ class html =
(Naming.type_target
{ ty_name = ct.clt_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
diff --git a/ocamldoc/odoc_info.ml b/ocamldoc/odoc_info.ml
index 65735fd..3305bab 100644
--- a/ocamldoc/odoc_info.ml
+++ b/ocamldoc/odoc_info.ml
@@ -113,11 +113,11 @@ let dump_modules = Odoc_analyse.dump_modules
let load_modules = Odoc_analyse.load_modules
-let reset_type_names = Printtyp.reset
+let reset_type_names = Odoc_print.reset
let string_of_variance t (co,cn) = Odoc_str.string_of_variance t (co, cn)
-let string_of_type_expr t = Odoc_print.string_of_type_expr t
+let string_of_type_expr = Odoc_print.string_of_type_expr
let string_of_class_params = Odoc_str.string_of_class_params
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index e3638a7..647e45b 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -212,6 +212,13 @@ module Type :
| Type_record of record_field list * bool
(** fields * bool *)
+ type tec = Odoc_type.tec =
+ Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ | Tec_list of tec list
+ and tec_variant_buc = Odoc_type.tec_variant_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ tec_variant_tec: tec }
+
(** Representation of a type. *)
type t_type = Odoc_type.t_type =
{
@@ -221,6 +228,7 @@ module Type :
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind ; (** Type kind. *)
ty_manifest : Types.type_expr option; (** Type manifest. *)
+ mutable ty_tmc : tec option; (** Type manifest's comments. *)
mutable ty_loc : location ;
mutable ty_code : string option;
}
@@ -599,7 +607,11 @@ val reset_type_names : unit -> unit
val string_of_variance : Type.t_type -> (bool * bool) -> string
(** This function returns a string representing a Types.type_expr. *)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ Types.type_expr -> string
(** @return a string to display the parameters of the given class,
in the same form as the compiler. *)
diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml
index 851884a..27a5c97 100644
--- a/ocamldoc/odoc_merge.ml
+++ b/ocamldoc/odoc_merge.ml
@@ -191,8 +191,13 @@ let merge_types merge_options mli ml =
mli.ty_info <- merge_info_opt merge_options mli.ty_info ml.ty_info;
mli.ty_loc <- { mli.ty_loc with loc_impl = ml.ty_loc.loc_impl } ;
mli.ty_code <- (match mli.ty_code with None -> ml.ty_code | _ -> mli.ty_code) ;
-
- match mli.ty_kind, ml.ty_kind with
+ let fail_on_different_types () =
+ if not !Odoc_args.inverse_merge_ml_mli
+ then raise (Failure (Odoc_messages.different_types mli.ty_name))
+ in
+ let has_merge_description_option =
+ List.mem Merge_description merge_options in
+ begin match mli.ty_kind, ml.ty_kind with
Type_abstract, _ ->
()
@@ -209,18 +214,13 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
cons.vc_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
@@ -237,26 +237,42 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
record.rf_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
- | _ ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ | _ -> fail_on_different_types ()
+ end;
+ begin match mli.ty_tmc, ml.ty_tmc with
+ None, None
+ | Some _, None -> ()
+ | None, Some tec -> mli.ty_tmc <- ml.ty_tmc
+ | Some mli_tec, Some ml_tec ->
+ let rec f = function
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> f (x, y)) l l'
+ | Tec_variant ht, Tec_variant ht' ->
+ Hashtbl.iter
+ begin fun lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec} as buc) ->
+ try let {tec_variant_coms=coms';
+ tec_variant_tec=tec'} = Hashtbl.find ht' lbl in
+ if (coms' <> []
+ && has_merge_description_option)
+ || coms = []
+ then buc.tec_variant_coms <- coms @ coms';
+ f (tec, tec')
+ with Not_found -> fail_on_different_types ()
+ end ht
+ | _ -> fail_on_different_types ()
+ in f (mli_tec, ml_tec)
+ end
(** Merge of two param_info, one from a .mli, one from a .ml.
The text fields are not handled but will be recreated from the
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index 6e4afc7..7246356 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -36,12 +36,225 @@ let _ =
let (modtype_fmt, flush_modtype_fmt) = new_fmt ()
+module Odoc_oprint =
+ struct
+ open Odoc_type
+ open Format
+ open Outcometree
+ let print_ident
+ ~str_of_ident
+ ppf x =
+ let buf = Buffer.create 12 in
+ let rec aux = function
+ Oide_ident s -> Buffer.add_string buf s
+ | Oide_dot (id, s) ->
+ aux id;
+ Buffer.add_string buf ".";
+ Buffer.add_string buf s
+ | Oide_apply (id1, id2) ->
+ aux id1;
+ Buffer.add_string buf "(";
+ aux id2;
+ Buffer.add_string buf ")"
+ in aux x;
+ fprintf ppf "%s" (str_of_ident (Buffer.contents buf))
-let string_of_type_expr t =
+ let rec print_list_init pr sep ppf =
+ function
+ [] -> ()
+ | a :: l -> sep ppf; pr ppf a; print_list_init pr sep ppf l
+
+ let rec print_list pr sep ppf =
+ function
+ [] -> ()
+ | [a] -> pr ppf a
+ | a :: l -> pr ppf a; sep ppf; print_list pr sep ppf l
+
+ let pr_present =
+ print_list (fun ppf s -> fprintf ppf "`%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let pr_vars =
+ print_list (fun ppf s -> fprintf ppf "'%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let rec print_out_type
+ ?(tec = Tec_list [])
+ ?(str_of_com = Odoc_misc.string_of_text)
+ ?(str_of_ident = fun (x: string) -> x)
+ ppf =
+ function
+ | Otyp_alias (ty, s) ->
+ fprintf ppf "@[%a@ as '%s@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty s
+ | Otyp_poly (sl, ty) ->
+ fprintf ppf "@[<hov 2>%a.@ %a@]"
+ pr_vars sl
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
+ | ty ->
+ print_out_type_1 ppf ty ~tec ~str_of_com ~str_of_ident
+
+ and print_out_type_1 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_arrow (lab, ty1, ty2) ->
+ let tec1, tec2 = match tec with
+ Tec_list [x;y] -> x, y
+ | _ -> Tec_list [], Tec_list [] in
+ fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "")
+ (print_out_type_2 ~tec: tec1 ~str_of_com ~str_of_ident) ty1
+ (print_out_type_1 ~tec: tec2 ~str_of_com ~str_of_ident) ty2
+ | ty ->
+ print_out_type_2 ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_out_type_2 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_tuple tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
+ print_simple_out_type ~tec ~str_of_com ~str_of_ident ty
+ in fprintf ppf "@[<0>%a@]" (print_typlist print_elem " *") tyl
+ | ty ->
+ print_simple_out_type ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_simple_out_type ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_class (ng, id, tyl) ->
+ fprintf ppf "@[%a%s#%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (if ng then "_" else "")
+ (print_ident ~str_of_ident) id
+ | Otyp_constr (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
+ | Otyp_object (fields, rest) ->
+ fprintf ppf "@[<2>< %a >@]"
+ (print_fields rest ~tec ~str_of_com ~str_of_ident) fields
+ | Otyp_stuff s -> fprintf ppf "%s" s
+ | Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s
+ | 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
+ let print_fields ~tec ~str_of_com ppf =
+ function
+ Ovar_fields fields ->
+ print_list
+ (print_row_field ~tec ~str_of_com ~str_of_ident)
+ (fun ppf -> fprintf ppf "@;<1 -2>| ")
+ ppf fields
+ | Ovar_name (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
+ in
+ 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 "? ")
+ (print_fields ~tec ~str_of_com) row_fields
+ print_present tags
+ | Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty ->
+ fprintf ppf "@[<1>(%a)@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
+ | Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> ()
+ and print_fields ~tec ~str_of_com ~str_of_ident rest ppf =
+ function
+ [] ->
+ begin match rest with
+ Some non_gen -> fprintf ppf "%s.." (if non_gen then "_" else "")
+ | None -> ()
+ end
+ | [s, t] ->
+ let tec = match tec with Tec_list [h] -> h
+ | _ -> Tec_list [] in
+ fprintf ppf "%s : %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t;
+ begin match rest with
+ Some _ -> fprintf ppf ";@ "
+ | None -> () end;
+ print_fields ~tec: (Tec_list [])
+ ~str_of_com ~str_of_ident rest ppf []
+ | (s, t) :: l ->
+ let tec, tec' = match tec with Tec_list (h::t) -> h, Tec_list t
+ | _ -> Tec_list [], Tec_list [] in
+ fprintf ppf "%s : %a;@ %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t
+ (print_fields rest ~tec: tec' ~str_of_com ~str_of_ident) l
+ and print_row_field
+ ~tec ~str_of_com
+ ~str_of_ident 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
+ let {Odoc_type.tec_variant_coms=coms;
+ tec_variant_tec=tec} =
+ try match tec with
+ Tec_variant ht -> Hashtbl.find ht l
+ | _ -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_tec=Tec_list []}
+ with Not_found -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_tec=Tec_list []} in
+ let str_coms =
+ if coms <> []
+ then str_of_com coms
+ else "" in
+ fprintf ppf "@[<hv 2>`%s%t%a%s%s@]"
+ l pr_of
+ (print_typlist (print_out_type ~tec ~str_of_com ~str_of_ident) " &") tyl
+ (if coms = [] then "" else " ")
+ str_coms
+ 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 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ [] -> ()
+ | [ty1] ->
+ let tec = match tec with Tec_list (h::t) -> h
+ | _ -> Tec_list [] in
+ fprintf ppf "%a@ "
+ (print_simple_out_type ~tec ~str_of_com ~str_of_ident) ty1
+ | tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
+ print_out_type ~tec ~str_of_com ~str_of_ident ty
+ in fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_elem ",") tyl
+
+ let out_type = ref print_out_type
+ end
+
+let type_scheme
+ ?tec ?str_of_com ?str_of_ident
+ ?(b_reset_names = true)
+ ppf ty =
+ if b_reset_names then Printtyp.reset_names ();
+ let out_type'save = !Oprint.out_type in
+ Oprint.out_type := !Odoc_oprint.out_type
+ ?tec ?str_of_com ?str_of_ident;
+ Printtyp.type_sch ppf ty;
+ Oprint.out_type := out_type'save
+
+let mark_loops = Printtyp.mark_loops
+let reset = Printtyp.reset
+
+let string_of_type_expr
+ ?tec ?str_of_com ?str_of_ident t =
Printtyp.mark_loops t;
- Printtyp.type_scheme_max ~b_reset_names: false type_fmt t;
+ type_scheme type_fmt t
+ ?tec ?str_of_com ?str_of_ident
+ ~b_reset_names: false;
flush_type_fmt ()
exception Use_code of string
diff --git a/ocamldoc/odoc_print.mli b/ocamldoc/odoc_print.mli
index 3dcc8cf..ec30d28 100644
--- a/ocamldoc/odoc_print.mli
+++ b/ocamldoc/odoc_print.mli
@@ -11,11 +11,30 @@
(* $Id: odoc_print.mli,v 1.2 2004-03-26 09:09:50 guesdon Exp $ *)
+(** Customized [Printtyp.mark_loops] *)
+val mark_loops: Types.type_expr -> unit
+
+(** Customized [Printtyp.type_scheme] *)
+val type_scheme:
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ ?b_reset_names: bool ->
+ Format.formatter -> Types.type_expr -> unit
+
+(** Same as [Printtyp.reset] but for the above functions *)
+val reset: unit -> unit
+
+
(** Printing functions. *)
(** This function takes a Types.type_expr and returns a string.
It writes in and flushes [Format.str_formatter].*)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ Types.type_expr -> string
(** This function returns a string representing a [Types.module_type].
@param complete indicates if we must print complete signatures
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index fe4e223..a855974 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -215,6 +215,139 @@ module Analyser =
in
(0, f name_mutable_type_list)
+ let get_tec
+ poly_variant_tec_htbl
+ ~current_module_name
+ ~name ~pos_end par_ct : tec =
+ let get_mem_tec
+ ~current_module_name ~name
+ poly_variant_tec_htbl =
+ let name = Name.concat
+ current_module_name
+ (String.concat "." (Longident.flatten name)) in
+ (*DEBUG*)try
+ Hashtbl.find poly_variant_tec_htbl name
+ (*DEBUG*)with Not_found ->
+ (*DEBUG*)prerr_endline ("name: " ^ name);
+ (*DEBUG*)prerr_endline ("hashtbl:" ^ Hashtbl.fold
+ (*DEBUG*) (fun k v a -> a ^ " " ^ k) poly_variant_tec_htbl "");
+ (*DEBUG*) raise Not_found
+ in
+ let retrieve_comments pos_end loc dlen : Odoc_types.text =
+ (* retrieve the source from the start of the current variant
+ * to the end of the current type *)
+ let s = ref (get_string_of_file
+ (loc.Location.loc_start.Lexing.pos_cnum + !dlen)
+ (min loc.Location.loc_end.Lexing.pos_cnum pos_end)) in
+ begin let idx = ref 0 (* cut just before the following variant *)
+ in let cnt = ref 0 (* of the same type, by hand, since Ptyp_variant *)
+ in while incr idx; !idx < String.length !s (* has no Location.t *)
+ do match !s.[!idx] with
+ '[' -> incr cnt
+ | '|' when !cnt = 0 -> s := String.sub !s 0 !idx
+ | ']' -> decr cnt
+ | _ -> ()
+ done end;
+ (* try to extract a comment *)
+ let _, comment_opt =
+ My_ir.just_after_special !file_name !s in
+ dlen := !dlen + String.length !s;
+ match comment_opt with
+ Some {Odoc_types.i_desc = Some coms} -> coms
+ | _ -> []
+ in
+ let (@) l1 l2 =
+ match l2 with [] -> l1 (* no need to rebuild a list *)
+ | _ -> l1 @ l2 in
+ let rec merge_com
+ ?(glob_coms = [])
+ htbl lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec} as buc) : unit =
+ let glob_coms = if glob_coms = [] then glob_coms
+ else Odoc_types.Raw " " (* XXX: hardcoded separator *)
+ :: glob_coms in
+ try let {tec_variant_coms=old_coms;
+ tec_variant_tec=old_tec} as buc = Hashtbl.find htbl lbl in
+ buc.tec_variant_coms <- old_coms @ (coms @ glob_coms);
+ let rec f = function Tec_variant old_htbl ->
+ (function Tec_variant htbl -> Hashtbl.iter (merge_com old_htbl) htbl
+ | _ -> assert false)
+ | Tec_list old_l ->
+ (function Tec_list l -> List.iter2 f old_l l
+ | _ -> assert false) in
+ f old_tec tec
+ with Not_found ->
+ buc.tec_variant_coms <- buc.tec_variant_coms @ glob_coms;
+ Hashtbl.add htbl lbl buc
+ in
+ let rec clone_tec = function
+ Tec_variant htbl ->
+ let ht = Hashtbl.create (Hashtbl.length htbl) in
+ Hashtbl.iter begin fun lbl {tec_variant_coms=coms;
+ tec_variant_tec=tec} ->
+ Hashtbl.add ht lbl {tec_variant_coms=coms;
+ tec_variant_tec=clone_tec tec}
+ end htbl;
+ Tec_variant ht
+ | Tec_list l -> Tec_list (List.map clone_tec l)
+ in
+ let rec get ?(pstart = 0) ?(pdlen = ref 0) par_ct =
+ let loc = par_ct.Parsetree.ptyp_loc in
+ let dlen = ref 0 in
+ pdlen := !pdlen + loc.Location.loc_end.Lexing.pos_cnum - pstart;
+ let get ct = get ct ~pdlen: dlen
+ ~pstart: (loc.Location.loc_start.Lexing.pos_cnum + !dlen) in
+ let htbl = Hashtbl.create 12 in
+ let tec = match par_ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_any
+ | Parsetree.Ptyp_var _ -> Tec_list []
+ | Parsetree.Ptyp_arrow (lbl, ct, ct') ->
+ Tec_list [get ct; get ct']
+ | Parsetree.Ptyp_tuple l
+ | Parsetree.Ptyp_class (_, l, _) ->
+ Tec_list (List.map get l)
+ | Parsetree.Ptyp_object l ->
+ Tec_list (List.map (fun ctf ->
+ match ctf.Parsetree.pfield_desc with
+ Parsetree.Pfield_var -> Tec_list []
+ | Parsetree.Pfield (_, ct) -> get ct) l)
+ | Parsetree.Ptyp_constr (name, _) ->
+ (try clone_tec (get_mem_tec poly_variant_tec_htbl
+ ~current_module_name ~name)
+ with Not_found -> Tec_list [])
+ | Parsetree.Ptyp_alias (ct, _)
+ | Parsetree.Ptyp_poly (_, ct) -> get ct
+ | Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
+ List.iter begin function
+ Parsetree.Rtag (lbl, b, l) ->
+ (* map the sub-types of the current variant *)
+ let l = List.map get l in
+ let tec = match l with [tec] -> tec (* not really a tuple *)
+ | _ -> Tec_list l in
+ let coms = retrieve_comments pos_end loc dlen in
+ merge_com htbl lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec});
+ | Parsetree.Rinherit ct ->
+ let ht = match get ct with Tec_variant ht -> ht
+ | _ -> assert false in
+ let glob_coms = retrieve_comments pos_end loc dlen in
+ Hashtbl.iter (merge_com htbl ~glob_coms) ht
+ end row_field_list;
+ Tec_variant htbl
+ in
+ tec
+ in
+ let tec = get par_ct in
+ Hashtbl.replace poly_variant_tec_htbl
+ (Name.concat current_module_name name) tec;
+ (* memorize the [tec] in order to retrieve it
+ * when it happens to be nested inside a following poly. variant.
+ * Note that:
+ * # type a = [`a|b] and b = [`b];;
+ * The type constructor s is not yet completely defined
+ *)
+ tec
+
let get_type_kind env name_comment_list type_kind =
match type_kind with
Types.Type_abstract ->
@@ -433,7 +566,8 @@ module Analyser =
(** Analyse of a .mli parse tree, to get the corresponding elements.
last_pos is the position of the first character which may be used to look for special comments.
*)
- let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list =
+ let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list
+ poly_variant_tec_htbl =
let table = Signature_search.table signat in
(* we look for the comment of each item then analyse the item *)
let rec f acc_eles acc_env last_pos = function
@@ -471,6 +605,7 @@ module Analyser =
)
assoc_com
ele.Parsetree.psig_desc
+ poly_variant_tec_htbl
in
f (acc_eles @ (ele_comments @ elements))
new_env
@@ -485,7 +620,8 @@ module Analyser =
(** Analyse the given signature_item_desc to create the corresponding module element
(with the given attached comment).*)
and analyse_signature_item_desc env signat table current_module_name
- pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc =
+ pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc
+ poly_variant_tec_htbl =
match sig_item_desc with
Parsetree.Psig_value (name_pre, value_desc) ->
let type_expr =
@@ -597,6 +733,10 @@ module Analyser =
let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in
let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum in
let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in
+ let tmc = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (get_tec poly_variant_tec_htbl ct ~name ~current_module_name
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
(* associate the comments to each constructor and build the [Type.t_type] *)
let new_type =
{
@@ -614,6 +754,7 @@ module Analyser =
(match sig_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tmc = tmc;
ty_loc =
{ loc_impl = None ;
loc_inter = Some (!file_name,loc_start) ;
@@ -661,7 +802,8 @@ module Analyser =
with Not_found ->
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
- let module_kind = analyse_module_kind env complete_name module_type sig_module_type in
+ let module_kind = analyse_module_kind env complete_name module_type
+ sig_module_type poly_variant_tec_htbl in
let code_intf =
if !Odoc_args.keep_code then
let loc = module_type.Parsetree.pmty_loc in
@@ -752,7 +894,8 @@ module Analyser =
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
(* associate the comments to each constructor and build the [Type.t_type] *)
- let module_kind = analyse_module_kind new_env complete_name modtype sig_module_type in
+ let module_kind = analyse_module_kind new_env complete_name
+ modtype sig_module_type poly_variant_tec_htbl in
let code_intf =
if !Odoc_args.keep_code then
let loc = modtype.Parsetree.pmty_loc in
@@ -830,7 +973,8 @@ module Analyser =
in
let module_type_kind =
match sig_mtype_opt with
- | Some sig_mtype -> Some (analyse_module_type_kind env complete_name module_type sig_mtype)
+ | Some sig_mtype -> Some (analyse_module_type_kind env complete_name
+ module_type sig_mtype poly_variant_tec_htbl)
| None -> None
in
let mt =
@@ -1030,7 +1174,8 @@ module Analyser =
(maybe_more, new_env, eles)
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
- and analyse_module_type_kind env current_module_name module_type sig_module_type =
+ and analyse_module_type_kind env current_module_name module_type sig_module_type
+ poly_variant_tec_htbl =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
let name =
@@ -1049,7 +1194,8 @@ module Analyser =
Types.Tmty_signature signat ->
let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
- let elements = analyse_parsetree env signat current_module_name pos_start pos_end ast in
+ let elements = analyse_parsetree env signat current_module_name
+ pos_start pos_end ast poly_variant_tec_htbl in
Module_type_struct elements
| _ ->
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
@@ -1065,6 +1211,7 @@ module Analyser =
Types.Tmty_functor (ident, param_module_type, body_module_type) ->
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
+ poly_variant_tec_htbl
in
let param =
{
@@ -1078,6 +1225,7 @@ module Analyser =
current_module_name
module_type2
body_module_type
+ poly_variant_tec_htbl
in
Module_type_functor (param, k)
@@ -1092,15 +1240,18 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name
+ module_type2 sig_module_type poly_variant_tec_htbl in
Module_type_with (k, s)
)
(** Analyse of a Parsetree.module_type and a Types.module_type.*)
- and analyse_module_kind env current_module_name module_type sig_module_type =
+ and analyse_module_kind env current_module_name module_type sig_module_type
+ poly_variant_tec_htbl =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
- let k = analyse_module_type_kind env current_module_name module_type sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type
+ sig_module_type poly_variant_tec_htbl in
Module_with ( k, "" )
| Parsetree.Pmty_signature signature ->
@@ -1115,6 +1266,7 @@ module Analyser =
module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum
module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum
signature
+ poly_variant_tec_htbl
)
| _ ->
(* if we're here something's wrong *)
@@ -1130,6 +1282,7 @@ module Analyser =
print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code);
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
+ poly_variant_tec_htbl
in
let param =
{
@@ -1143,6 +1296,7 @@ module Analyser =
current_module_name
module_type2
body_module_type
+ poly_variant_tec_htbl
in
Module_functor (param, k)
@@ -1156,7 +1310,8 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type2
+ sig_module_type poly_variant_tec_htbl in
Module_with (k, s)
)
@@ -1300,8 +1455,10 @@ module Analyser =
(Filename.basename (try Filename.chop_extension source_file with _ -> source_file))
in
let (len,info_opt) = My_ir.first_special !file_name !file in
+ let poly_variant_tec_htbl = Hashtbl.create 12 in
let elements =
- analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file) ast
+ analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file)
+ ast poly_variant_tec_htbl
in
let code_intf =
if !Odoc_args.keep_code then
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index b41e913..f46a3a2 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -149,6 +149,13 @@ module Analyser :
Odoc_env.env -> (string * Odoc_types.info option) list ->
Types.type_kind -> Odoc_type.type_kind
+ val get_tec :
+ (Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
+ current_module_name: string ->
+ name: string ->
+ pos_end: int ->
+ Parsetree.core_type -> Odoc_type.tec
+
(** This function merge two optional info structures. *)
val merge_infos :
Odoc_types.info option -> Odoc_types.info option ->
@@ -156,9 +163,12 @@ module Analyser :
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
val analyse_module_type_kind :
- Odoc_env.env -> Odoc_name.t ->
- Parsetree.module_type -> Types.module_type ->
- Odoc_module.module_type_kind
+ Odoc_env.env ->
+ Odoc_name.t ->
+ Parsetree.module_type ->
+ Types.module_type ->
+ (Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
+ Odoc_module.module_type_kind
(** Analysis of a Parsetree.class_type and a Types.class_type to
return a class_type_kind.*)
diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml
index e3295eb..e0c2af7 100644
--- a/ocamldoc/odoc_str.ml
+++ b/ocamldoc/odoc_str.ml
@@ -47,17 +47,17 @@ let raw_string_of_type_list sep type_list =
| Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false
in
let print_one_type variance t =
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
if need_parent t then
(
Format.fprintf fmt "(%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t;
+ Odoc_print.type_scheme ~b_reset_names: false fmt t;
Format.fprintf fmt ")"
)
else
(
Format.fprintf fmt "%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t
+ Odoc_print.type_scheme ~b_reset_names: false fmt t
)
in
begin match type_list with
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 26ae47b..9240102 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -38,15 +38,24 @@ type type_kind =
| Type_record of record_field list * bool
(** fields * bool *)
+type tec =
+ Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ | Tec_list of tec list
+and tec_variant_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ tec_variant_tec: tec }
+
(** Representation of a type. *)
type t_type = {
- ty_name : Name.t ;
- mutable ty_info : Odoc_types.info option ; (** optional user information *)
- ty_parameters : (Types.type_expr * bool * bool) list ;
+ ty_name : Name.t;
+ mutable ty_info : Odoc_types.info option; (** optional user information *)
+ ty_parameters : (Types.type_expr * bool * bool) list;
(** type parameters: (type, covariant, contravariant) *)
- ty_kind : type_kind ;
+ ty_kind : type_kind;
ty_manifest : Types.type_expr option; (** type manifest *)
- mutable ty_loc : Odoc_types.location ;
+ mutable ty_tmc : tec option; (** type manifest's comments *)
+ mutable ty_loc : Odoc_types.location;
mutable ty_code : string option;
- }
+ }
+
diff --git a/ocamldoc/odoc_value.ml b/ocamldoc/odoc_value.ml
index 29be7c5..fb8bbc5 100644
--- a/ocamldoc/odoc_value.ml
+++ b/ocamldoc/odoc_value.ml
@@ -102,7 +102,7 @@ let dummy_parameter_list typ =
'?' -> String.sub s 1 ((String.length s) - 1)
| _ -> s
in
- Printtyp.mark_loops typ;
+ Odoc_print.mark_loops typ;
let liste_param = parameter_list_from_arrows typ in
let rec iter (label, t) =
match t.Types.desc with
diff --git a/ocamldoc/.depend b/ocamldoc/.depend
index 47b84e8..4210ab5 100644
--- a/ocamldoc/.depend
+++ b/ocamldoc/.depend
@@ -42,10 +42,6 @@ odoc_ast.cmx: ../typing/types.cmx ../typing/typedtree.cmx \
odoc_global.cmx odoc_exception.cmx odoc_env.cmx odoc_class.cmx \
odoc_args.cmx ../utils/misc.cmx ../parsing/location.cmx \
../typing/ident.cmx ../parsing/asttypes.cmi odoc_ast.cmi
-odoc_btype.cmo: ../typing/types.cmi ../typing/path.cmi odoc_type.cmo \
- ../typing/btype.cmi ../parsing/asttypes.cmi
-odoc_btype.cmx: ../typing/types.cmx ../typing/path.cmx odoc_type.cmx \
- ../typing/btype.cmx ../parsing/asttypes.cmi
odoc_class.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_parameter.cmo odoc_name.cmi
odoc_class.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
@@ -68,14 +64,6 @@ odoc_cross.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_search.cmx \
odoc_scan.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx odoc_class.cmx \
odoc_cross.cmi
-odoc_ctype.cmo: ../typing/types.cmi ../typing/subst.cmi ../typing/path.cmi \
- odoc_type.cmo odoc_btype.cmo ../utils/misc.cmi ../parsing/longident.cmi \
- ../typing/ident.cmi ../typing/env.cmi ../utils/clflags.cmi \
- ../typing/btype.cmi ../parsing/asttypes.cmi
-odoc_ctype.cmx: ../typing/types.cmx ../typing/subst.cmx ../typing/path.cmx \
- odoc_type.cmx odoc_btype.cmx ../utils/misc.cmx ../parsing/longident.cmx \
- ../typing/ident.cmx ../typing/env.cmx ../utils/clflags.cmx \
- ../typing/btype.cmx ../parsing/asttypes.cmi
odoc_dag2html.cmo: odoc_info.cmi odoc_dag2html.cmi
odoc_dag2html.cmx: odoc_info.cmx odoc_dag2html.cmi
odoc_dep.cmo: ../parsing/parsetree.cmi odoc_type.cmo odoc_print.cmi \
@@ -92,10 +80,10 @@ odoc_exception.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_exception.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_global.cmo: ../utils/clflags.cmi odoc_global.cmi
odoc_global.cmx: ../utils/clflags.cmx odoc_global.cmi
-odoc_html.cmo: odoc_type.cmo odoc_text.cmi odoc_ocamlhtml.cmo \
- odoc_messages.cmo odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
-odoc_html.cmx: odoc_type.cmx odoc_text.cmx odoc_ocamlhtml.cmx \
- odoc_messages.cmx odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
+odoc_html.cmo: odoc_text.cmi odoc_ocamlhtml.cmo odoc_messages.cmo \
+ odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
+odoc_html.cmx: odoc_text.cmx odoc_ocamlhtml.cmx odoc_messages.cmx \
+ odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
odoc_info.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_text.cmi \
odoc_str.cmi odoc_search.cmi odoc_scan.cmo odoc_print.cmi \
odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_misc.cmi \
@@ -158,22 +146,16 @@ odoc_opt.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
odoc_dot.cmx odoc_args.cmx odoc_analyse.cmx ../utils/misc.cmx \
../utils/config.cmx ../utils/clflags.cmx
-odoc_outcometree.cmo: odoc_types.cmi
-odoc_outcometree.cmx: odoc_types.cmx
odoc_parameter.cmo: ../typing/types.cmi odoc_types.cmi
odoc_parameter.cmx: ../typing/types.cmx odoc_types.cmx
odoc_parser.cmo: odoc_types.cmi odoc_comments_global.cmi odoc_parser.cmi
odoc_parser.cmx: odoc_types.cmx odoc_comments_global.cmx odoc_parser.cmi
odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi \
- ../typing/predef.cmi ../typing/path.cmi ../typing/outcometree.cmi \
- odoc_type.cmo odoc_misc.cmi ../utils/misc.cmi ../parsing/longident.cmi \
- ../typing/env.cmi ../typing/ctype.cmi ../typing/btype.cmi \
- ../parsing/asttypes.cmi odoc_print.cmi
+ ../typing/outcometree.cmi ../typing/oprint.cmi odoc_type.cmo \
+ odoc_misc.cmi odoc_print.cmi
odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx \
- ../typing/predef.cmx ../typing/path.cmx ../typing/outcometree.cmi \
- odoc_type.cmx odoc_misc.cmx ../utils/misc.cmx ../parsing/longident.cmx \
- ../typing/env.cmx ../typing/ctype.cmx ../typing/btype.cmx \
- ../parsing/asttypes.cmi odoc_print.cmi
+ ../typing/outcometree.cmi ../typing/oprint.cmx odoc_type.cmx \
+ odoc_misc.cmx odoc_print.cmi
odoc_scan.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_scan.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_module.cmx \
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index d45280f..3ff4ff8 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -940,7 +940,7 @@ module Analyser =
(** Analysis of a parse tree structure with a typed tree, to return module elements.*)
let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree
- poly_variant_tec_htbl =
+ tmc_htbl =
print_DEBUG "Odoc_ast:analyse_struture";
let (table, table_values) = Typedtree_search.tables typedtree in
let rec iter env last_pos = function
@@ -978,7 +978,7 @@ module Analyser =
typedtree
table
table_values
- poly_variant_tec_htbl
+ tmc_htbl
in
ele_comments @ elements @ (iter new_env (item.Parsetree.pstr_loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q)
in
@@ -986,7 +986,7 @@ module Analyser =
(** Analysis of a parse tree structure item to obtain a new environment and a list of elements.*)
and analyse_structure_item env current_module_name loc pos_limit comment_opt parsetree_item_desc typedtree
- table table_values poly_variant_tec_htbl =
+ table table_values tmc_htbl =
print_DEBUG "Odoc_ast:analyse_struture_item";
match parsetree_item_desc with
Parsetree.Pstr_eval _ ->
@@ -1119,7 +1119,8 @@ module Analyser =
in
let tec = match type_decl.Parsetree.ptype_manifest
with None -> None | Some ct ->
- Some (Sig.get_tec poly_variant_tec_htbl ct ~current_module_name ~name
+ Some (Sig.get_tec tmc_htbl ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
let new_end = loc_end + maybe_more in
let t =
@@ -1227,7 +1228,7 @@ module Analyser =
comment_opt
module_expr
tt_module_expr
- poly_variant_tec_htbl
+ tmc_htbl
in
let code =
if !Odoc_args.keep_code then
@@ -1277,7 +1278,7 @@ module Analyser =
None
mod_exp
tt_mod_exp
- poly_variant_tec_htbl
+ tmc_htbl
in
match new_module.m_type with
Types.Tmty_signature s ->
@@ -1313,7 +1314,7 @@ module Analyser =
com_opt
mod_exp
tt_mod_exp
- poly_variant_tec_htbl
+ tmc_htbl
in
let eles = f loc_end q in
ele_comments @ ((Element_module new_module) :: eles)
@@ -1329,7 +1330,7 @@ module Analyser =
raise (Failure (Odoc_messages.module_type_not_found_in_typedtree complete_name))
in
let kind = Sig.analyse_module_type_kind env complete_name
- modtype tt_module_type poly_variant_tec_htbl
+ modtype tt_module_type tmc_htbl
in
let mt =
{
@@ -1476,7 +1477,7 @@ module Analyser =
(** Analysis of a [Parsetree.module_expr] and a name to return a [t_module].*)
and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr
- poly_variant_tec_htbl =
+ tmc_htbl =
let complete_name = Name.concat current_module_name module_name in
let pos_start = p_module_expr.Parsetree.pmod_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = p_module_expr.Parsetree.pmod_loc.Location.loc_end.Lexing.pos_cnum in
@@ -1516,7 +1517,7 @@ module Analyser =
| (Parsetree.Pmod_structure p_structure, Typedtree.Tmod_structure tt_structure) ->
let elements = analyse_structure env complete_name pos_start
- pos_end p_structure tt_structure poly_variant_tec_htbl in
+ pos_end p_structure tt_structure tmc_htbl in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1531,7 +1532,7 @@ module Analyser =
let mp_name = Name.from_ident ident in
let mp_kind = Sig.analyse_module_type_kind env
current_module_name pmodule_type mtyp
- poly_variant_tec_htbl
+ tmc_htbl
in
let param =
{
@@ -1551,7 +1552,7 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
- poly_variant_tec_htbl
+ tmc_htbl
in
let kind = m_base2.m_kind in
{ m_base with m_kind = Module_functor (param, kind) }
@@ -1570,7 +1571,7 @@ module Analyser =
None
p_module_expr1
tt_module_expr1
- poly_variant_tec_htbl
+ tmc_htbl
in
let m2 = analyse_module
env
@@ -1579,7 +1580,7 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
- poly_variant_tec_htbl
+ tmc_htbl
in
{ m_base with m_kind = Module_apply (m1.m_kind, m2.m_kind) }
@@ -1593,11 +1594,11 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
- poly_variant_tec_htbl
+ tmc_htbl
in
let mtkind = Sig.analyse_module_type_kind env
(Name.concat current_module_name "??")
- p_modtype tt_modtype poly_variant_tec_htbl
+ p_modtype tt_modtype tmc_htbl
in
let tt_modtype = Odoc_env.subst_module_type env tt_modtype in
filter_module_with_module_type_constraint m_base2 tt_modtype;
@@ -1616,7 +1617,7 @@ module Analyser =
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_structure + Typedtree.Tmod_constraint "^module_name);
let elements = analyse_structure env complete_name pos_start pos_end
- p_structure tt_structure poly_variant_tec_htbl in
+ p_structure tt_structure tmc_htbl in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1670,9 +1671,9 @@ module Analyser =
let (len,info_opt) = My_ir.first_special !file_name !file in
(* we must complete the included modules *)
- let poly_variant_tec_htbl = Hashtbl.create 12 in
+ let tmc_htbl = Hashtbl.create 12 in
let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file)
- parsetree tree_structure poly_variant_tec_htbl in
+ parsetree tree_structure tmc_htbl in
let included_modules_from_tt = tt_get_included_module_list tree_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
let kind = Module_struct elements2 in
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index a855974..3795629 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -216,22 +216,16 @@ module Analyser =
(0, f name_mutable_type_list)
let get_tec
- poly_variant_tec_htbl
- ~current_module_name
- ~name ~pos_end par_ct : tec =
- let get_mem_tec
- ~current_module_name ~name
- poly_variant_tec_htbl =
- let name = Name.concat
- current_module_name
- (String.concat "." (Longident.flatten name)) in
+ tmc_htbl ~env ~name
+ ~pos_end par_ct : tec =
+ let get_mem_tec ~name tmc_htbl =
(*DEBUG*)try
- Hashtbl.find poly_variant_tec_htbl name
+ Hashtbl.find tmc_htbl name
(*DEBUG*)with Not_found ->
- (*DEBUG*)prerr_endline ("name: " ^ name);
- (*DEBUG*)prerr_endline ("hashtbl:" ^ Hashtbl.fold
- (*DEBUG*) (fun k v a -> a ^ " " ^ k) poly_variant_tec_htbl "");
- (*DEBUG*) raise Not_found
+ (*DEBUG*) prerr_endline ("name: " ^ name);
+ (*DEBUG*) prerr_endline ("htbl:" ^ Hashtbl.fold
+ (*DEBUG*) (fun k v a -> a ^ " " ^ k) tmc_htbl "");
+ (*DEBUG*) raise Not_found
in
let retrieve_comments pos_end loc dlen : Odoc_types.text =
(* retrieve the source from the start of the current variant
@@ -300,7 +294,8 @@ module Analyser =
let htbl = Hashtbl.create 12 in
let tec = match par_ct.Parsetree.ptyp_desc with
Parsetree.Ptyp_any
- | Parsetree.Ptyp_var _ -> Tec_list []
+ | Parsetree.Ptyp_var _
+ | Parsetree.Ptyp_constr _ -> Tec_list []
| Parsetree.Ptyp_arrow (lbl, ct, ct') ->
Tec_list [get ct; get ct']
| Parsetree.Ptyp_tuple l
@@ -311,10 +306,6 @@ module Analyser =
match ctf.Parsetree.pfield_desc with
Parsetree.Pfield_var -> Tec_list []
| Parsetree.Pfield (_, ct) -> get ct) l)
- | Parsetree.Ptyp_constr (name, _) ->
- (try clone_tec (get_mem_tec poly_variant_tec_htbl
- ~current_module_name ~name)
- with Not_found -> Tec_list [])
| Parsetree.Ptyp_alias (ct, _)
| Parsetree.Ptyp_poly (_, ct) -> get ct
| Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
@@ -328,18 +319,25 @@ module Analyser =
merge_com htbl lbl ({tec_variant_coms=coms;
tec_variant_tec=tec});
| Parsetree.Rinherit ct ->
- let ht = match get ct with Tec_variant ht -> ht
- | _ -> assert false in
- let glob_coms = retrieve_comments pos_end loc dlen in
- Hashtbl.iter (merge_com htbl ~glob_coms) ht
+ match ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_constr (id, _) ->
+ begin try let tec = clone_tec (get_mem_tec tmc_htbl
+ ~name: (Odoc_env.full_type_name env
+ (String.concat "." (Longident.flatten id))))
+ in match tec with Tec_variant ht ->
+ let glob_coms = retrieve_comments pos_end loc dlen in
+ Hashtbl.iter (merge_com htbl ~glob_coms) ht
+ | _ -> ()
+ with Not_found -> () (* raised either by [get_mem_tec]
+ * or by [Odoc_env.full_type_name] *) end
+ | _ -> ()
end row_field_list;
Tec_variant htbl
in
tec
in
let tec = get par_ct in
- Hashtbl.replace poly_variant_tec_htbl
- (Name.concat current_module_name name) tec;
+ Hashtbl.replace tmc_htbl name tec;
(* memorize the [tec] in order to retrieve it
* when it happens to be nested inside a following poly. variant.
* Note that:
@@ -567,7 +565,7 @@ module Analyser =
last_pos is the position of the first character which may be used to look for special comments.
*)
let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list
- poly_variant_tec_htbl =
+ tmc_htbl =
let table = Signature_search.table signat in
(* we look for the comment of each item then analyse the item *)
let rec f acc_eles acc_env last_pos = function
@@ -605,7 +603,7 @@ module Analyser =
)
assoc_com
ele.Parsetree.psig_desc
- poly_variant_tec_htbl
+ tmc_htbl
in
f (acc_eles @ (ele_comments @ elements))
new_env
@@ -621,7 +619,7 @@ module Analyser =
(with the given attached comment).*)
and analyse_signature_item_desc env signat table current_module_name
pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc
- poly_variant_tec_htbl =
+ tmc_htbl =
match sig_item_desc with
Parsetree.Psig_value (name_pre, value_desc) ->
let type_expr =
@@ -735,7 +733,8 @@ module Analyser =
let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in
let tmc = match type_decl.Parsetree.ptype_manifest
with None -> None | Some ct ->
- Some (get_tec poly_variant_tec_htbl ct ~name ~current_module_name
+ Some (get_tec tmc_htbl ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
(* associate the comments to each constructor and build the [Type.t_type] *)
let new_type =
@@ -803,7 +802,7 @@ module Analyser =
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
let module_kind = analyse_module_kind env complete_name module_type
- sig_module_type poly_variant_tec_htbl in
+ sig_module_type tmc_htbl in
let code_intf =
if !Odoc_args.keep_code then
let loc = module_type.Parsetree.pmty_loc in
@@ -895,7 +894,7 @@ module Analyser =
in
(* associate the comments to each constructor and build the [Type.t_type] *)
let module_kind = analyse_module_kind new_env complete_name
- modtype sig_module_type poly_variant_tec_htbl in
+ modtype sig_module_type tmc_htbl in
let code_intf =
if !Odoc_args.keep_code then
let loc = modtype.Parsetree.pmty_loc in
@@ -974,7 +973,7 @@ module Analyser =
let module_type_kind =
match sig_mtype_opt with
| Some sig_mtype -> Some (analyse_module_type_kind env complete_name
- module_type sig_mtype poly_variant_tec_htbl)
+ module_type sig_mtype tmc_htbl)
| None -> None
in
let mt =
@@ -1175,7 +1174,7 @@ module Analyser =
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
and analyse_module_type_kind env current_module_name module_type sig_module_type
- poly_variant_tec_htbl =
+ tmc_htbl =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
let name =
@@ -1195,7 +1194,7 @@ module Analyser =
let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let elements = analyse_parsetree env signat current_module_name
- pos_start pos_end ast poly_variant_tec_htbl in
+ pos_start pos_end ast tmc_htbl in
Module_type_struct elements
| _ ->
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
@@ -1211,7 +1210,7 @@ module Analyser =
Types.Tmty_functor (ident, param_module_type, body_module_type) ->
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
- poly_variant_tec_htbl
+ tmc_htbl
in
let param =
{
@@ -1225,7 +1224,7 @@ module Analyser =
current_module_name
module_type2
body_module_type
- poly_variant_tec_htbl
+ tmc_htbl
in
Module_type_functor (param, k)
@@ -1241,17 +1240,17 @@ module Analyser =
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
let k = analyse_module_type_kind env current_module_name
- module_type2 sig_module_type poly_variant_tec_htbl in
+ module_type2 sig_module_type tmc_htbl in
Module_type_with (k, s)
)
(** Analyse of a Parsetree.module_type and a Types.module_type.*)
and analyse_module_kind env current_module_name module_type sig_module_type
- poly_variant_tec_htbl =
+ tmc_htbl =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
let k = analyse_module_type_kind env current_module_name module_type
- sig_module_type poly_variant_tec_htbl in
+ sig_module_type tmc_htbl in
Module_with ( k, "" )
| Parsetree.Pmty_signature signature ->
@@ -1266,7 +1265,7 @@ module Analyser =
module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum
module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum
signature
- poly_variant_tec_htbl
+ tmc_htbl
)
| _ ->
(* if we're here something's wrong *)
@@ -1282,7 +1281,7 @@ module Analyser =
print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code);
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
- poly_variant_tec_htbl
+ tmc_htbl
in
let param =
{
@@ -1296,7 +1295,7 @@ module Analyser =
current_module_name
module_type2
body_module_type
- poly_variant_tec_htbl
+ tmc_htbl
in
Module_functor (param, k)
@@ -1311,7 +1310,7 @@ module Analyser =
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
let k = analyse_module_type_kind env current_module_name module_type2
- sig_module_type poly_variant_tec_htbl in
+ sig_module_type tmc_htbl in
Module_with (k, s)
)
@@ -1455,10 +1454,10 @@ module Analyser =
(Filename.basename (try Filename.chop_extension source_file with _ -> source_file))
in
let (len,info_opt) = My_ir.first_special !file_name !file in
- let poly_variant_tec_htbl = Hashtbl.create 12 in
+ let tmc_htbl = Hashtbl.create 12 in
let elements =
analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file)
- ast poly_variant_tec_htbl
+ ast tmc_htbl
in
let code_intf =
if !Odoc_args.keep_code then
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index f46a3a2..d13d5e4 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -149,9 +149,11 @@ module Analyser :
Odoc_env.env -> (string * Odoc_types.info option) list ->
Types.type_kind -> Odoc_type.type_kind
+ (** Fetch the comments (only in polymorphic variants currently)
+ inside a [Parsetree.core_type]. *)
val get_tec :
(Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
- current_module_name: string ->
+ env: Odoc_env.env ->
name: string ->
pos_end: int ->
Parsetree.core_type -> Odoc_type.tec
diff --git a/ocamldoc/.depend b/ocamldoc/.depend
index 5e2196a..4210ab5 100644
--- a/ocamldoc/.depend
+++ b/ocamldoc/.depend
@@ -1,11 +1,3 @@
-odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
- odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
- odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
- ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
-odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
- odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
- odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
- ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_analyse.cmo: ../utils/warnings.cmi ../typing/typetexp.cmi \
../typing/types.cmi ../typing/typemod.cmi ../typing/typedtree.cmi \
../typing/typedecl.cmi ../typing/typecore.cmi ../typing/typeclass.cmi \
@@ -54,14 +46,14 @@ odoc_class.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_parameter.cmo odoc_name.cmi
odoc_class.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
odoc_parameter.cmx odoc_name.cmx
+odoc_comments_global.cmo: odoc_comments_global.cmi
+odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_comments.cmo: odoc_types.cmi odoc_text.cmi odoc_see_lexer.cmo \
odoc_parser.cmi odoc_misc.cmi odoc_messages.cmo odoc_lexer.cmo \
odoc_global.cmi odoc_cross.cmi odoc_comments_global.cmi odoc_comments.cmi
odoc_comments.cmx: odoc_types.cmx odoc_text.cmx odoc_see_lexer.cmx \
odoc_parser.cmx odoc_misc.cmx odoc_messages.cmx odoc_lexer.cmx \
odoc_global.cmx odoc_cross.cmx odoc_comments_global.cmx odoc_comments.cmi
-odoc_comments_global.cmo: odoc_comments_global.cmi
-odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_config.cmo: ../utils/config.cmi odoc_config.cmi
odoc_config.cmx: ../utils/config.cmx odoc_config.cmi
odoc_cross.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_search.cmi \
@@ -80,10 +72,10 @@ odoc_dep.cmx: ../parsing/parsetree.cmi odoc_type.cmx odoc_print.cmx \
odoc_module.cmx ../tools/depend.cmx
odoc_dot.cmo: odoc_info.cmi
odoc_dot.cmx: odoc_info.cmx
-odoc_env.cmo: ../typing/types.cmi ../typing/printtyp.cmi ../typing/predef.cmi \
- ../typing/path.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
-odoc_env.cmx: ../typing/types.cmx ../typing/printtyp.cmx ../typing/predef.cmx \
- ../typing/path.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
+odoc_env.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
+ odoc_print.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
+odoc_env.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
+ odoc_print.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
odoc_exception.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_exception.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_global.cmo: ../utils/clflags.cmi odoc_global.cmi
@@ -92,18 +84,18 @@ odoc_html.cmo: odoc_text.cmi odoc_ocamlhtml.cmo odoc_messages.cmo \
odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
odoc_html.cmx: odoc_text.cmx odoc_ocamlhtml.cmx odoc_messages.cmx \
odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
-odoc_info.cmo: ../typing/printtyp.cmi odoc_value.cmo odoc_types.cmi \
- odoc_type.cmo odoc_text.cmi odoc_str.cmi odoc_search.cmi odoc_scan.cmo \
- odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
- odoc_misc.cmi odoc_messages.cmo odoc_global.cmi odoc_exception.cmo \
- odoc_dep.cmo odoc_config.cmi odoc_comments.cmi odoc_class.cmo \
- odoc_args.cmi odoc_analyse.cmi odoc_info.cmi
-odoc_info.cmx: ../typing/printtyp.cmx odoc_value.cmx odoc_types.cmx \
- odoc_type.cmx odoc_text.cmx odoc_str.cmx odoc_search.cmx odoc_scan.cmx \
- odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
- odoc_misc.cmx odoc_messages.cmx odoc_global.cmx odoc_exception.cmx \
- odoc_dep.cmx odoc_config.cmx odoc_comments.cmx odoc_class.cmx \
- odoc_args.cmx odoc_analyse.cmx odoc_info.cmi
+odoc_info.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_text.cmi \
+ odoc_str.cmi odoc_search.cmi odoc_scan.cmo odoc_print.cmi \
+ odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_misc.cmi \
+ odoc_messages.cmo odoc_global.cmi odoc_exception.cmo odoc_dep.cmo \
+ odoc_config.cmi odoc_comments.cmi odoc_class.cmo odoc_args.cmi \
+ odoc_analyse.cmi odoc_info.cmi
+odoc_info.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_text.cmx \
+ odoc_str.cmx odoc_search.cmx odoc_scan.cmx odoc_print.cmx \
+ odoc_parameter.cmx odoc_name.cmx odoc_module.cmx odoc_misc.cmx \
+ odoc_messages.cmx odoc_global.cmx odoc_exception.cmx odoc_dep.cmx \
+ odoc_config.cmx odoc_comments.cmx odoc_class.cmx odoc_args.cmx \
+ odoc_analyse.cmx odoc_info.cmi
odoc_latex.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_latex_style.cmo \
odoc_info.cmi
odoc_latex.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_latex_style.cmx \
@@ -130,6 +122,14 @@ odoc_misc.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
odoc_misc.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
odoc_types.cmx odoc_messages.cmx ../parsing/longident.cmx \
../typing/ctype.cmx ../typing/btype.cmx odoc_misc.cmi
+odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
+ odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
+ odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
+ ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
+odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
+ odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
+ odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
+ ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_module.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_type.cmo odoc_name.cmi odoc_exception.cmo odoc_class.cmo
odoc_module.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
@@ -150,8 +150,12 @@ odoc_parameter.cmo: ../typing/types.cmi odoc_types.cmi
odoc_parameter.cmx: ../typing/types.cmx odoc_types.cmx
odoc_parser.cmo: odoc_types.cmi odoc_comments_global.cmi odoc_parser.cmi
odoc_parser.cmx: odoc_types.cmx odoc_comments_global.cmx odoc_parser.cmi
-odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_print.cmi
-odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_print.cmi
+odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi \
+ ../typing/outcometree.cmi ../typing/oprint.cmi odoc_type.cmo \
+ odoc_misc.cmi odoc_print.cmi
+odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx \
+ ../typing/outcometree.cmi ../typing/oprint.cmx odoc_type.cmx \
+ odoc_misc.cmx odoc_print.cmi
odoc_scan.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_scan.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_module.cmx \
@@ -169,31 +173,31 @@ odoc_sig.cmo: ../typing/types.cmi ../typing/typedtree.cmi ../typing/path.cmi \
odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
odoc_misc.cmi odoc_messages.cmo odoc_merge.cmi odoc_global.cmi \
odoc_exception.cmo odoc_env.cmi odoc_class.cmo odoc_args.cmi \
- ../utils/misc.cmi ../parsing/location.cmi ../typing/btype.cmi \
- ../parsing/asttypes.cmi odoc_sig.cmi
+ ../utils/misc.cmi ../parsing/longident.cmi ../parsing/location.cmi \
+ ../typing/btype.cmi ../parsing/asttypes.cmi odoc_sig.cmi
odoc_sig.cmx: ../typing/types.cmx ../typing/typedtree.cmx ../typing/path.cmx \
../parsing/parsetree.cmi odoc_value.cmx odoc_types.cmx odoc_type.cmx \
odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_merge.cmx odoc_global.cmx \
odoc_exception.cmx odoc_env.cmx odoc_class.cmx odoc_args.cmx \
- ../utils/misc.cmx ../parsing/location.cmx ../typing/btype.cmx \
- ../parsing/asttypes.cmi odoc_sig.cmi
-odoc_str.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_value.cmo \
- odoc_type.cmo odoc_print.cmi odoc_name.cmi odoc_misc.cmi \
- odoc_messages.cmo odoc_exception.cmo odoc_class.cmo odoc_str.cmi
-odoc_str.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_value.cmx \
- odoc_type.cmx odoc_print.cmx odoc_name.cmx odoc_misc.cmx \
- odoc_messages.cmx odoc_exception.cmx odoc_class.cmx odoc_str.cmi
+ ../utils/misc.cmx ../parsing/longident.cmx ../parsing/location.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi odoc_sig.cmi
+odoc_str.cmo: ../typing/types.cmi odoc_value.cmo odoc_type.cmo odoc_print.cmi \
+ odoc_name.cmi odoc_misc.cmi odoc_messages.cmo odoc_exception.cmo \
+ odoc_class.cmo odoc_str.cmi
+odoc_str.cmx: ../typing/types.cmx odoc_value.cmx odoc_type.cmx odoc_print.cmx \
+ odoc_name.cmx odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx \
+ odoc_class.cmx odoc_str.cmi
odoc_test.cmo: odoc_info.cmi
odoc_test.cmx: odoc_info.cmx
odoc_texi.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_info.cmi
odoc_texi.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_info.cmx
+odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
+odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text.cmo: odoc_types.cmi odoc_text_parser.cmi odoc_text_lexer.cmo \
odoc_text.cmi
odoc_text.cmx: odoc_types.cmx odoc_text_parser.cmx odoc_text_lexer.cmx \
odoc_text.cmi
-odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
-odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text_parser.cmo: odoc_types.cmi odoc_misc.cmi odoc_text_parser.cmi
odoc_text_parser.cmx: odoc_types.cmx odoc_misc.cmx odoc_text_parser.cmi
odoc_to_text.cmo: odoc_messages.cmo odoc_info.cmi
@@ -202,9 +206,9 @@ odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_types.cmo: odoc_messages.cmo odoc_types.cmi
odoc_types.cmx: odoc_messages.cmx odoc_types.cmi
-odoc_value.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_types.cmi \
+odoc_value.cmo: ../typing/types.cmi odoc_types.cmi odoc_print.cmi \
odoc_parameter.cmo odoc_name.cmi
-odoc_value.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_types.cmx \
+odoc_value.cmx: ../typing/types.cmx odoc_types.cmx odoc_print.cmx \
odoc_parameter.cmx odoc_name.cmx
odoc_analyse.cmi: odoc_module.cmo odoc_args.cmi
odoc_args.cmi: odoc_types.cmi odoc_module.cmo
@@ -222,7 +226,7 @@ odoc_misc.cmi: ../typing/types.cmi odoc_types.cmi ../parsing/longident.cmi
odoc_name.cmi: ../typing/path.cmi ../parsing/longident.cmi \
../typing/ident.cmi
odoc_parser.cmi: odoc_types.cmi
-odoc_print.cmi: ../typing/types.cmi
+odoc_print.cmi: ../typing/types.cmi odoc_types.cmi odoc_type.cmo
odoc_search.cmi: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_sig.cmi: ../typing/types.cmi ../parsing/parsetree.cmi odoc_types.cmi \
diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile
index c181142..3749001 100644
--- a/ocamldoc/Makefile
+++ b/ocamldoc/Makefile
@@ -81,12 +81,12 @@ CMOFILES= odoc_config.cmo \
odoc_text.cmo\
odoc_name.cmo\
odoc_parameter.cmo\
+ odoc_print.cmo \
odoc_value.cmo\
odoc_type.cmo\
odoc_exception.cmo\
odoc_class.cmo\
odoc_module.cmo\
- odoc_print.cmo \
odoc_str.cmo\
odoc_args.cmo\
odoc_comments_global.cmo\
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index efee6ea..3ff4ff8 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -939,7 +939,8 @@ module Analyser =
List.filter pred l
(** Analysis of a parse tree structure with a typed tree, to return module elements.*)
- let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree =
+ let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree
+ tmc_htbl =
print_DEBUG "Odoc_ast:analyse_struture";
let (table, table_values) = Typedtree_search.tables typedtree in
let rec iter env last_pos = function
@@ -977,6 +978,7 @@ module Analyser =
typedtree
table
table_values
+ tmc_htbl
in
ele_comments @ elements @ (iter new_env (item.Parsetree.pstr_loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q)
in
@@ -984,7 +986,7 @@ module Analyser =
(** Analysis of a parse tree structure item to obtain a new environment and a list of elements.*)
and analyse_structure_item env current_module_name loc pos_limit comment_opt parsetree_item_desc typedtree
- table table_values =
+ table table_values tmc_htbl =
print_DEBUG "Odoc_ast:analyse_struture_item";
match parsetree_item_desc with
Parsetree.Pstr_eval _ ->
@@ -1115,6 +1117,11 @@ module Analyser =
new_env name_comment_list
tt_type_decl.Types.type_kind
in
+ let tec = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (Sig.get_tec tmc_htbl ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
let new_end = loc_end + maybe_more in
let t =
{
@@ -1133,6 +1140,7 @@ module Analyser =
(match tt_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tmc = tec;
ty_loc = { loc_impl = Some (!file_name, loc_start) ; loc_inter = None } ;
ty_code =
(
@@ -1220,6 +1228,7 @@ module Analyser =
comment_opt
module_expr
tt_module_expr
+ tmc_htbl
in
let code =
if !Odoc_args.keep_code then
@@ -1269,6 +1278,7 @@ module Analyser =
None
mod_exp
tt_mod_exp
+ tmc_htbl
in
match new_module.m_type with
Types.Tmty_signature s ->
@@ -1304,6 +1314,7 @@ module Analyser =
com_opt
mod_exp
tt_mod_exp
+ tmc_htbl
in
let eles = f loc_end q in
ele_comments @ ((Element_module new_module) :: eles)
@@ -1319,7 +1330,7 @@ module Analyser =
raise (Failure (Odoc_messages.module_type_not_found_in_typedtree complete_name))
in
let kind = Sig.analyse_module_type_kind env complete_name
- modtype tt_module_type
+ modtype tt_module_type tmc_htbl
in
let mt =
{
@@ -1465,7 +1476,8 @@ module Analyser =
(0, env, [ Element_included_module im ]) (* A VOIR : étendre l'environnement ? avec quoi ? *)
(** Analysis of a [Parsetree.module_expr] and a name to return a [t_module].*)
- and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr =
+ and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr
+ tmc_htbl =
let complete_name = Name.concat current_module_name module_name in
let pos_start = p_module_expr.Parsetree.pmod_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = p_module_expr.Parsetree.pmod_loc.Location.loc_end.Lexing.pos_cnum in
@@ -1504,7 +1516,8 @@ module Analyser =
ma_module = None ; } }
| (Parsetree.Pmod_structure p_structure, Typedtree.Tmod_structure tt_structure) ->
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start
+ pos_end p_structure tt_structure tmc_htbl in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1519,6 +1532,7 @@ module Analyser =
let mp_name = Name.from_ident ident in
let mp_kind = Sig.analyse_module_type_kind env
current_module_name pmodule_type mtyp
+ tmc_htbl
in
let param =
{
@@ -1538,6 +1552,7 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ tmc_htbl
in
let kind = m_base2.m_kind in
{ m_base with m_kind = Module_functor (param, kind) }
@@ -1556,6 +1571,7 @@ module Analyser =
None
p_module_expr1
tt_module_expr1
+ tmc_htbl
in
let m2 = analyse_module
env
@@ -1564,6 +1580,7 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ tmc_htbl
in
{ m_base with m_kind = Module_apply (m1.m_kind, m2.m_kind) }
@@ -1577,10 +1594,11 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
+ tmc_htbl
in
let mtkind = Sig.analyse_module_type_kind env
(Name.concat current_module_name "??")
- p_modtype tt_modtype
+ p_modtype tt_modtype tmc_htbl
in
let tt_modtype = Odoc_env.subst_module_type env tt_modtype in
filter_module_with_module_type_constraint m_base2 tt_modtype;
@@ -1598,7 +1616,8 @@ module Analyser =
(* needed for recursive modules *)
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_structure + Typedtree.Tmod_constraint "^module_name);
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start pos_end
+ p_structure tt_structure tmc_htbl in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1652,7 +1671,9 @@ module Analyser =
let (len,info_opt) = My_ir.first_special !file_name !file in
(* we must complete the included modules *)
- let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file) parsetree tree_structure in
+ let tmc_htbl = Hashtbl.create 12 in
+ let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file)
+ parsetree tree_structure tmc_htbl in
let included_modules_from_tt = tt_get_included_module_list tree_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
let kind = Module_struct elements2 in
diff --git a/ocamldoc/odoc_cross.ml b/ocamldoc/odoc_cross.ml
index 6570e9a..6df118c 100644
--- a/ocamldoc/odoc_cross.ml
+++ b/ocamldoc/odoc_cross.ml
@@ -898,6 +898,17 @@ and assoc_comments_type module_list t =
(fun rf -> rf.rf_text <- ao (assoc_comments_text parent module_list) rf.rf_text)
fl
);
+ let rec f = function
+ Tec_list l -> List.iter f l
+ | Tec_variant ht ->
+ Hashtbl.iter
+ begin fun lbl buc ->
+ buc.tec_variant_coms <-
+ assoc_comments_text parent module_list
+ buc.tec_variant_coms;
+ f buc.tec_variant_tec
+ end ht
+ in (match t.ty_tmc with Some tec -> f tec | _ -> ());
t
and assoc_comments_attribute module_list a =
diff --git a/ocamldoc/odoc_env.ml b/ocamldoc/odoc_env.ml
index ed9fb26..0865f8d 100644
--- a/ocamldoc/odoc_env.ml
+++ b/ocamldoc/odoc_env.ml
@@ -181,7 +181,7 @@ let subst_type env t =
print_env_types env ;
print_newline ();
*)
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
let deja_vu = ref [] in
let rec iter t =
if List.memq t !deja_vu then () else begin
diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml
index f34ad5e..a96e130 100644
--- a/ocamldoc/odoc_html.ml
+++ b/ocamldoc/odoc_html.ml
@@ -1098,11 +1098,27 @@ class html =
s2
(** Print html code to display a [Types.type_expr]. *)
- method html_of_type_expr b m_name t =
- let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_type_expr t) in
- let s2 = newline_to_indented_br s in
+ method html_of_type_expr ?tec b m_name t =
+ let str_of_com coms =
+ let b = Buffer.create 42 in
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ bs b "<code>";
+ bs b "(*";
+ bs b "</code></td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ self#html_of_text b coms;
+ bs b "</td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
+ bs b "<code>";
+ bs b "*)";
+ bs b "</code></td>";
+ Buffer.contents b in
+ let str_of_ident =
+ self#create_fully_qualified_idents_links m_name in
+ let s = Odoc_info.remove_ending_newline
+ (Odoc_info.string_of_type_expr t ?tec ~str_of_com ~str_of_ident) in
bs b "<code class=\"type\">";
- bs b (self#create_fully_qualified_idents_links m_name s2);
+ bs b (newline_to_indented_br s);
bs b "</code>"
(** Print html code to display a [Types.type_expr list]. *)
@@ -1372,7 +1388,7 @@ class html =
None -> ()
| Some typ ->
bs b "= ";
- self#html_of_type_expr b father typ;
+ self#html_of_type_expr b father typ ?tec: t.ty_tmc;
bs b " "
);
(match t.ty_kind with
@@ -1814,7 +1830,8 @@ class html =
(Naming.type_target
{ ty_name = c.cl_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
@@ -1861,7 +1878,8 @@ class html =
(Naming.type_target
{ ty_name = ct.clt_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
diff --git a/ocamldoc/odoc_info.ml b/ocamldoc/odoc_info.ml
index 65735fd..3305bab 100644
--- a/ocamldoc/odoc_info.ml
+++ b/ocamldoc/odoc_info.ml
@@ -113,11 +113,11 @@ let dump_modules = Odoc_analyse.dump_modules
let load_modules = Odoc_analyse.load_modules
-let reset_type_names = Printtyp.reset
+let reset_type_names = Odoc_print.reset
let string_of_variance t (co,cn) = Odoc_str.string_of_variance t (co, cn)
-let string_of_type_expr t = Odoc_print.string_of_type_expr t
+let string_of_type_expr = Odoc_print.string_of_type_expr
let string_of_class_params = Odoc_str.string_of_class_params
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index e3638a7..647e45b 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -212,6 +212,13 @@ module Type :
| Type_record of record_field list * bool
(** fields * bool *)
+ type tec = Odoc_type.tec =
+ Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ | Tec_list of tec list
+ and tec_variant_buc = Odoc_type.tec_variant_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ tec_variant_tec: tec }
+
(** Representation of a type. *)
type t_type = Odoc_type.t_type =
{
@@ -221,6 +228,7 @@ module Type :
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind ; (** Type kind. *)
ty_manifest : Types.type_expr option; (** Type manifest. *)
+ mutable ty_tmc : tec option; (** Type manifest's comments. *)
mutable ty_loc : location ;
mutable ty_code : string option;
}
@@ -599,7 +607,11 @@ val reset_type_names : unit -> unit
val string_of_variance : Type.t_type -> (bool * bool) -> string
(** This function returns a string representing a Types.type_expr. *)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ Types.type_expr -> string
(** @return a string to display the parameters of the given class,
in the same form as the compiler. *)
diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml
index 851884a..27a5c97 100644
--- a/ocamldoc/odoc_merge.ml
+++ b/ocamldoc/odoc_merge.ml
@@ -191,8 +191,13 @@ let merge_types merge_options mli ml =
mli.ty_info <- merge_info_opt merge_options mli.ty_info ml.ty_info;
mli.ty_loc <- { mli.ty_loc with loc_impl = ml.ty_loc.loc_impl } ;
mli.ty_code <- (match mli.ty_code with None -> ml.ty_code | _ -> mli.ty_code) ;
-
- match mli.ty_kind, ml.ty_kind with
+ let fail_on_different_types () =
+ if not !Odoc_args.inverse_merge_ml_mli
+ then raise (Failure (Odoc_messages.different_types mli.ty_name))
+ in
+ let has_merge_description_option =
+ List.mem Merge_description merge_options in
+ begin match mli.ty_kind, ml.ty_kind with
Type_abstract, _ ->
()
@@ -209,18 +214,13 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
cons.vc_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
@@ -237,26 +237,42 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
record.rf_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
- | _ ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ | _ -> fail_on_different_types ()
+ end;
+ begin match mli.ty_tmc, ml.ty_tmc with
+ None, None
+ | Some _, None -> ()
+ | None, Some tec -> mli.ty_tmc <- ml.ty_tmc
+ | Some mli_tec, Some ml_tec ->
+ let rec f = function
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> f (x, y)) l l'
+ | Tec_variant ht, Tec_variant ht' ->
+ Hashtbl.iter
+ begin fun lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec} as buc) ->
+ try let {tec_variant_coms=coms';
+ tec_variant_tec=tec'} = Hashtbl.find ht' lbl in
+ if (coms' <> []
+ && has_merge_description_option)
+ || coms = []
+ then buc.tec_variant_coms <- coms @ coms';
+ f (tec, tec')
+ with Not_found -> fail_on_different_types ()
+ end ht
+ | _ -> fail_on_different_types ()
+ in f (mli_tec, ml_tec)
+ end
(** Merge of two param_info, one from a .mli, one from a .ml.
The text fields are not handled but will be recreated from the
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index 6e4afc7..7246356 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -36,12 +36,225 @@ let _ =
let (modtype_fmt, flush_modtype_fmt) = new_fmt ()
+module Odoc_oprint =
+ struct
+ open Odoc_type
+ open Format
+ open Outcometree
+ let print_ident
+ ~str_of_ident
+ ppf x =
+ let buf = Buffer.create 12 in
+ let rec aux = function
+ Oide_ident s -> Buffer.add_string buf s
+ | Oide_dot (id, s) ->
+ aux id;
+ Buffer.add_string buf ".";
+ Buffer.add_string buf s
+ | Oide_apply (id1, id2) ->
+ aux id1;
+ Buffer.add_string buf "(";
+ aux id2;
+ Buffer.add_string buf ")"
+ in aux x;
+ fprintf ppf "%s" (str_of_ident (Buffer.contents buf))
-let string_of_type_expr t =
+ let rec print_list_init pr sep ppf =
+ function
+ [] -> ()
+ | a :: l -> sep ppf; pr ppf a; print_list_init pr sep ppf l
+
+ let rec print_list pr sep ppf =
+ function
+ [] -> ()
+ | [a] -> pr ppf a
+ | a :: l -> pr ppf a; sep ppf; print_list pr sep ppf l
+
+ let pr_present =
+ print_list (fun ppf s -> fprintf ppf "`%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let pr_vars =
+ print_list (fun ppf s -> fprintf ppf "'%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let rec print_out_type
+ ?(tec = Tec_list [])
+ ?(str_of_com = Odoc_misc.string_of_text)
+ ?(str_of_ident = fun (x: string) -> x)
+ ppf =
+ function
+ | Otyp_alias (ty, s) ->
+ fprintf ppf "@[%a@ as '%s@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty s
+ | Otyp_poly (sl, ty) ->
+ fprintf ppf "@[<hov 2>%a.@ %a@]"
+ pr_vars sl
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
+ | ty ->
+ print_out_type_1 ppf ty ~tec ~str_of_com ~str_of_ident
+
+ and print_out_type_1 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_arrow (lab, ty1, ty2) ->
+ let tec1, tec2 = match tec with
+ Tec_list [x;y] -> x, y
+ | _ -> Tec_list [], Tec_list [] in
+ fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "")
+ (print_out_type_2 ~tec: tec1 ~str_of_com ~str_of_ident) ty1
+ (print_out_type_1 ~tec: tec2 ~str_of_com ~str_of_ident) ty2
+ | ty ->
+ print_out_type_2 ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_out_type_2 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_tuple tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
+ print_simple_out_type ~tec ~str_of_com ~str_of_ident ty
+ in fprintf ppf "@[<0>%a@]" (print_typlist print_elem " *") tyl
+ | ty ->
+ print_simple_out_type ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_simple_out_type ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_class (ng, id, tyl) ->
+ fprintf ppf "@[%a%s#%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (if ng then "_" else "")
+ (print_ident ~str_of_ident) id
+ | Otyp_constr (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
+ | Otyp_object (fields, rest) ->
+ fprintf ppf "@[<2>< %a >@]"
+ (print_fields rest ~tec ~str_of_com ~str_of_ident) fields
+ | Otyp_stuff s -> fprintf ppf "%s" s
+ | Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s
+ | 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
+ let print_fields ~tec ~str_of_com ppf =
+ function
+ Ovar_fields fields ->
+ print_list
+ (print_row_field ~tec ~str_of_com ~str_of_ident)
+ (fun ppf -> fprintf ppf "@;<1 -2>| ")
+ ppf fields
+ | Ovar_name (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
+ in
+ 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 "? ")
+ (print_fields ~tec ~str_of_com) row_fields
+ print_present tags
+ | Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty ->
+ fprintf ppf "@[<1>(%a)@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
+ | Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> ()
+ and print_fields ~tec ~str_of_com ~str_of_ident rest ppf =
+ function
+ [] ->
+ begin match rest with
+ Some non_gen -> fprintf ppf "%s.." (if non_gen then "_" else "")
+ | None -> ()
+ end
+ | [s, t] ->
+ let tec = match tec with Tec_list [h] -> h
+ | _ -> Tec_list [] in
+ fprintf ppf "%s : %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t;
+ begin match rest with
+ Some _ -> fprintf ppf ";@ "
+ | None -> () end;
+ print_fields ~tec: (Tec_list [])
+ ~str_of_com ~str_of_ident rest ppf []
+ | (s, t) :: l ->
+ let tec, tec' = match tec with Tec_list (h::t) -> h, Tec_list t
+ | _ -> Tec_list [], Tec_list [] in
+ fprintf ppf "%s : %a;@ %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t
+ (print_fields rest ~tec: tec' ~str_of_com ~str_of_ident) l
+ and print_row_field
+ ~tec ~str_of_com
+ ~str_of_ident 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
+ let {Odoc_type.tec_variant_coms=coms;
+ tec_variant_tec=tec} =
+ try match tec with
+ Tec_variant ht -> Hashtbl.find ht l
+ | _ -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_tec=Tec_list []}
+ with Not_found -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_tec=Tec_list []} in
+ let str_coms =
+ if coms <> []
+ then str_of_com coms
+ else "" in
+ fprintf ppf "@[<hv 2>`%s%t%a%s%s@]"
+ l pr_of
+ (print_typlist (print_out_type ~tec ~str_of_com ~str_of_ident) " &") tyl
+ (if coms = [] then "" else " ")
+ str_coms
+ 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 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ [] -> ()
+ | [ty1] ->
+ let tec = match tec with Tec_list (h::t) -> h
+ | _ -> Tec_list [] in
+ fprintf ppf "%a@ "
+ (print_simple_out_type ~tec ~str_of_com ~str_of_ident) ty1
+ | tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
+ print_out_type ~tec ~str_of_com ~str_of_ident ty
+ in fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_elem ",") tyl
+
+ let out_type = ref print_out_type
+ end
+
+let type_scheme
+ ?tec ?str_of_com ?str_of_ident
+ ?(b_reset_names = true)
+ ppf ty =
+ if b_reset_names then Printtyp.reset_names ();
+ let out_type'save = !Oprint.out_type in
+ Oprint.out_type := !Odoc_oprint.out_type
+ ?tec ?str_of_com ?str_of_ident;
+ Printtyp.type_sch ppf ty;
+ Oprint.out_type := out_type'save
+
+let mark_loops = Printtyp.mark_loops
+let reset = Printtyp.reset
+
+let string_of_type_expr
+ ?tec ?str_of_com ?str_of_ident t =
Printtyp.mark_loops t;
- Printtyp.type_scheme_max ~b_reset_names: false type_fmt t;
+ type_scheme type_fmt t
+ ?tec ?str_of_com ?str_of_ident
+ ~b_reset_names: false;
flush_type_fmt ()
exception Use_code of string
diff --git a/ocamldoc/odoc_print.mli b/ocamldoc/odoc_print.mli
index 3dcc8cf..ec30d28 100644
--- a/ocamldoc/odoc_print.mli
+++ b/ocamldoc/odoc_print.mli
@@ -11,11 +11,30 @@
(* $Id: odoc_print.mli,v 1.2 2004-03-26 09:09:50 guesdon Exp $ *)
+(** Customized [Printtyp.mark_loops] *)
+val mark_loops: Types.type_expr -> unit
+
+(** Customized [Printtyp.type_scheme] *)
+val type_scheme:
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ ?b_reset_names: bool ->
+ Format.formatter -> Types.type_expr -> unit
+
+(** Same as [Printtyp.reset] but for the above functions *)
+val reset: unit -> unit
+
+
(** Printing functions. *)
(** This function takes a Types.type_expr and returns a string.
It writes in and flushes [Format.str_formatter].*)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ Types.type_expr -> string
(** This function returns a string representing a [Types.module_type].
@param complete indicates if we must print complete signatures
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index fe4e223..3795629 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -215,6 +215,137 @@ module Analyser =
in
(0, f name_mutable_type_list)
+ let get_tec
+ tmc_htbl ~env ~name
+ ~pos_end par_ct : tec =
+ let get_mem_tec ~name tmc_htbl =
+ (*DEBUG*)try
+ Hashtbl.find tmc_htbl name
+ (*DEBUG*)with Not_found ->
+ (*DEBUG*) prerr_endline ("name: " ^ name);
+ (*DEBUG*) prerr_endline ("htbl:" ^ Hashtbl.fold
+ (*DEBUG*) (fun k v a -> a ^ " " ^ k) tmc_htbl "");
+ (*DEBUG*) raise Not_found
+ in
+ let retrieve_comments pos_end loc dlen : Odoc_types.text =
+ (* retrieve the source from the start of the current variant
+ * to the end of the current type *)
+ let s = ref (get_string_of_file
+ (loc.Location.loc_start.Lexing.pos_cnum + !dlen)
+ (min loc.Location.loc_end.Lexing.pos_cnum pos_end)) in
+ begin let idx = ref 0 (* cut just before the following variant *)
+ in let cnt = ref 0 (* of the same type, by hand, since Ptyp_variant *)
+ in while incr idx; !idx < String.length !s (* has no Location.t *)
+ do match !s.[!idx] with
+ '[' -> incr cnt
+ | '|' when !cnt = 0 -> s := String.sub !s 0 !idx
+ | ']' -> decr cnt
+ | _ -> ()
+ done end;
+ (* try to extract a comment *)
+ let _, comment_opt =
+ My_ir.just_after_special !file_name !s in
+ dlen := !dlen + String.length !s;
+ match comment_opt with
+ Some {Odoc_types.i_desc = Some coms} -> coms
+ | _ -> []
+ in
+ let (@) l1 l2 =
+ match l2 with [] -> l1 (* no need to rebuild a list *)
+ | _ -> l1 @ l2 in
+ let rec merge_com
+ ?(glob_coms = [])
+ htbl lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec} as buc) : unit =
+ let glob_coms = if glob_coms = [] then glob_coms
+ else Odoc_types.Raw " " (* XXX: hardcoded separator *)
+ :: glob_coms in
+ try let {tec_variant_coms=old_coms;
+ tec_variant_tec=old_tec} as buc = Hashtbl.find htbl lbl in
+ buc.tec_variant_coms <- old_coms @ (coms @ glob_coms);
+ let rec f = function Tec_variant old_htbl ->
+ (function Tec_variant htbl -> Hashtbl.iter (merge_com old_htbl) htbl
+ | _ -> assert false)
+ | Tec_list old_l ->
+ (function Tec_list l -> List.iter2 f old_l l
+ | _ -> assert false) in
+ f old_tec tec
+ with Not_found ->
+ buc.tec_variant_coms <- buc.tec_variant_coms @ glob_coms;
+ Hashtbl.add htbl lbl buc
+ in
+ let rec clone_tec = function
+ Tec_variant htbl ->
+ let ht = Hashtbl.create (Hashtbl.length htbl) in
+ Hashtbl.iter begin fun lbl {tec_variant_coms=coms;
+ tec_variant_tec=tec} ->
+ Hashtbl.add ht lbl {tec_variant_coms=coms;
+ tec_variant_tec=clone_tec tec}
+ end htbl;
+ Tec_variant ht
+ | Tec_list l -> Tec_list (List.map clone_tec l)
+ in
+ let rec get ?(pstart = 0) ?(pdlen = ref 0) par_ct =
+ let loc = par_ct.Parsetree.ptyp_loc in
+ let dlen = ref 0 in
+ pdlen := !pdlen + loc.Location.loc_end.Lexing.pos_cnum - pstart;
+ let get ct = get ct ~pdlen: dlen
+ ~pstart: (loc.Location.loc_start.Lexing.pos_cnum + !dlen) in
+ let htbl = Hashtbl.create 12 in
+ let tec = match par_ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_any
+ | Parsetree.Ptyp_var _
+ | Parsetree.Ptyp_constr _ -> Tec_list []
+ | Parsetree.Ptyp_arrow (lbl, ct, ct') ->
+ Tec_list [get ct; get ct']
+ | Parsetree.Ptyp_tuple l
+ | Parsetree.Ptyp_class (_, l, _) ->
+ Tec_list (List.map get l)
+ | Parsetree.Ptyp_object l ->
+ Tec_list (List.map (fun ctf ->
+ match ctf.Parsetree.pfield_desc with
+ Parsetree.Pfield_var -> Tec_list []
+ | Parsetree.Pfield (_, ct) -> get ct) l)
+ | Parsetree.Ptyp_alias (ct, _)
+ | Parsetree.Ptyp_poly (_, ct) -> get ct
+ | Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
+ List.iter begin function
+ Parsetree.Rtag (lbl, b, l) ->
+ (* map the sub-types of the current variant *)
+ let l = List.map get l in
+ let tec = match l with [tec] -> tec (* not really a tuple *)
+ | _ -> Tec_list l in
+ let coms = retrieve_comments pos_end loc dlen in
+ merge_com htbl lbl ({tec_variant_coms=coms;
+ tec_variant_tec=tec});
+ | Parsetree.Rinherit ct ->
+ match ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_constr (id, _) ->
+ begin try let tec = clone_tec (get_mem_tec tmc_htbl
+ ~name: (Odoc_env.full_type_name env
+ (String.concat "." (Longident.flatten id))))
+ in match tec with Tec_variant ht ->
+ let glob_coms = retrieve_comments pos_end loc dlen in
+ Hashtbl.iter (merge_com htbl ~glob_coms) ht
+ | _ -> ()
+ with Not_found -> () (* raised either by [get_mem_tec]
+ * or by [Odoc_env.full_type_name] *) end
+ | _ -> ()
+ end row_field_list;
+ Tec_variant htbl
+ in
+ tec
+ in
+ let tec = get par_ct in
+ Hashtbl.replace tmc_htbl name tec;
+ (* memorize the [tec] in order to retrieve it
+ * when it happens to be nested inside a following poly. variant.
+ * Note that:
+ * # type a = [`a|b] and b = [`b];;
+ * The type constructor s is not yet completely defined
+ *)
+ tec
+
let get_type_kind env name_comment_list type_kind =
match type_kind with
Types.Type_abstract ->
@@ -433,7 +564,8 @@ module Analyser =
(** Analyse of a .mli parse tree, to get the corresponding elements.
last_pos is the position of the first character which may be used to look for special comments.
*)
- let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list =
+ let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list
+ tmc_htbl =
let table = Signature_search.table signat in
(* we look for the comment of each item then analyse the item *)
let rec f acc_eles acc_env last_pos = function
@@ -471,6 +603,7 @@ module Analyser =
)
assoc_com
ele.Parsetree.psig_desc
+ tmc_htbl
in
f (acc_eles @ (ele_comments @ elements))
new_env
@@ -485,7 +618,8 @@ module Analyser =
(** Analyse the given signature_item_desc to create the corresponding module element
(with the given attached comment).*)
and analyse_signature_item_desc env signat table current_module_name
- pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc =
+ pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc
+ tmc_htbl =
match sig_item_desc with
Parsetree.Psig_value (name_pre, value_desc) ->
let type_expr =
@@ -597,6 +731,11 @@ module Analyser =
let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in
let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum in
let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in
+ let tmc = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (get_tec tmc_htbl ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
(* associate the comments to each constructor and build the [Type.t_type] *)
let new_type =
{
@@ -614,6 +753,7 @@ module Analyser =
(match sig_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tmc = tmc;
ty_loc =
{ loc_impl = None ;
loc_inter = Some (!file_name,loc_start) ;
@@ -661,7 +801,8 @@ module Analyser =
with Not_found ->
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
- let module_kind = analyse_module_kind env complete_name module_type sig_module_type in
+ let module_kind = analyse_module_kind env complete_name module_type
+ sig_module_type tmc_htbl in
let code_intf =
if !Odoc_args.keep_code then
let loc = module_type.Parsetree.pmty_loc in
@@ -752,7 +893,8 @@ module Analyser =
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
(* associate the comments to each constructor and build the [Type.t_type] *)
- let module_kind = analyse_module_kind new_env complete_name modtype sig_module_type in
+ let module_kind = analyse_module_kind new_env complete_name
+ modtype sig_module_type tmc_htbl in
let code_intf =
if !Odoc_args.keep_code then
let loc = modtype.Parsetree.pmty_loc in
@@ -830,7 +972,8 @@ module Analyser =
in
let module_type_kind =
match sig_mtype_opt with
- | Some sig_mtype -> Some (analyse_module_type_kind env complete_name module_type sig_mtype)
+ | Some sig_mtype -> Some (analyse_module_type_kind env complete_name
+ module_type sig_mtype tmc_htbl)
| None -> None
in
let mt =
@@ -1030,7 +1173,8 @@ module Analyser =
(maybe_more, new_env, eles)
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
- and analyse_module_type_kind env current_module_name module_type sig_module_type =
+ and analyse_module_type_kind env current_module_name module_type sig_module_type
+ tmc_htbl =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
let name =
@@ -1049,7 +1193,8 @@ module Analyser =
Types.Tmty_signature signat ->
let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
- let elements = analyse_parsetree env signat current_module_name pos_start pos_end ast in
+ let elements = analyse_parsetree env signat current_module_name
+ pos_start pos_end ast tmc_htbl in
Module_type_struct elements
| _ ->
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
@@ -1065,6 +1210,7 @@ module Analyser =
Types.Tmty_functor (ident, param_module_type, body_module_type) ->
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
+ tmc_htbl
in
let param =
{
@@ -1078,6 +1224,7 @@ module Analyser =
current_module_name
module_type2
body_module_type
+ tmc_htbl
in
Module_type_functor (param, k)
@@ -1092,15 +1239,18 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name
+ module_type2 sig_module_type tmc_htbl in
Module_type_with (k, s)
)
(** Analyse of a Parsetree.module_type and a Types.module_type.*)
- and analyse_module_kind env current_module_name module_type sig_module_type =
+ and analyse_module_kind env current_module_name module_type sig_module_type
+ tmc_htbl =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
- let k = analyse_module_type_kind env current_module_name module_type sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type
+ sig_module_type tmc_htbl in
Module_with ( k, "" )
| Parsetree.Pmty_signature signature ->
@@ -1115,6 +1265,7 @@ module Analyser =
module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum
module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum
signature
+ tmc_htbl
)
| _ ->
(* if we're here something's wrong *)
@@ -1130,6 +1281,7 @@ module Analyser =
print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code);
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
+ tmc_htbl
in
let param =
{
@@ -1143,6 +1295,7 @@ module Analyser =
current_module_name
module_type2
body_module_type
+ tmc_htbl
in
Module_functor (param, k)
@@ -1156,7 +1309,8 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type2
+ sig_module_type tmc_htbl in
Module_with (k, s)
)
@@ -1300,8 +1454,10 @@ module Analyser =
(Filename.basename (try Filename.chop_extension source_file with _ -> source_file))
in
let (len,info_opt) = My_ir.first_special !file_name !file in
+ let tmc_htbl = Hashtbl.create 12 in
let elements =
- analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file) ast
+ analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file)
+ ast tmc_htbl
in
let code_intf =
if !Odoc_args.keep_code then
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index b41e913..d13d5e4 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -149,6 +149,15 @@ module Analyser :
Odoc_env.env -> (string * Odoc_types.info option) list ->
Types.type_kind -> Odoc_type.type_kind
+ (** Fetch the comments (only in polymorphic variants currently)
+ inside a [Parsetree.core_type]. *)
+ val get_tec :
+ (Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
+ env: Odoc_env.env ->
+ name: string ->
+ pos_end: int ->
+ Parsetree.core_type -> Odoc_type.tec
+
(** This function merge two optional info structures. *)
val merge_infos :
Odoc_types.info option -> Odoc_types.info option ->
@@ -156,9 +165,12 @@ module Analyser :
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
val analyse_module_type_kind :
- Odoc_env.env -> Odoc_name.t ->
- Parsetree.module_type -> Types.module_type ->
- Odoc_module.module_type_kind
+ Odoc_env.env ->
+ Odoc_name.t ->
+ Parsetree.module_type ->
+ Types.module_type ->
+ (Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
+ Odoc_module.module_type_kind
(** Analysis of a Parsetree.class_type and a Types.class_type to
return a class_type_kind.*)
diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml
index e3295eb..e0c2af7 100644
--- a/ocamldoc/odoc_str.ml
+++ b/ocamldoc/odoc_str.ml
@@ -47,17 +47,17 @@ let raw_string_of_type_list sep type_list =
| Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false
in
let print_one_type variance t =
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
if need_parent t then
(
Format.fprintf fmt "(%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t;
+ Odoc_print.type_scheme ~b_reset_names: false fmt t;
Format.fprintf fmt ")"
)
else
(
Format.fprintf fmt "%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t
+ Odoc_print.type_scheme ~b_reset_names: false fmt t
)
in
begin match type_list with
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 26ae47b..9240102 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -38,15 +38,24 @@ type type_kind =
| Type_record of record_field list * bool
(** fields * bool *)
+type tec =
+ Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ | Tec_list of tec list
+and tec_variant_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ tec_variant_tec: tec }
+
(** Representation of a type. *)
type t_type = {
- ty_name : Name.t ;
- mutable ty_info : Odoc_types.info option ; (** optional user information *)
- ty_parameters : (Types.type_expr * bool * bool) list ;
+ ty_name : Name.t;
+ mutable ty_info : Odoc_types.info option; (** optional user information *)
+ ty_parameters : (Types.type_expr * bool * bool) list;
(** type parameters: (type, covariant, contravariant) *)
- ty_kind : type_kind ;
+ ty_kind : type_kind;
ty_manifest : Types.type_expr option; (** type manifest *)
- mutable ty_loc : Odoc_types.location ;
+ mutable ty_tmc : tec option; (** type manifest's comments *)
+ mutable ty_loc : Odoc_types.location;
mutable ty_code : string option;
- }
+ }
+
diff --git a/ocamldoc/odoc_value.ml b/ocamldoc/odoc_value.ml
index 29be7c5..fb8bbc5 100644
--- a/ocamldoc/odoc_value.ml
+++ b/ocamldoc/odoc_value.ml
@@ -102,7 +102,7 @@ let dummy_parameter_list typ =
'?' -> String.sub s 1 ((String.length s) - 1)
| _ -> s
in
- Printtyp.mark_loops typ;
+ Odoc_print.mark_loops typ;
let liste_param = parameter_list_from_arrows typ in
let rec iter (label, t) =
match t.Types.desc with
32d1e7b099858682fc776a25097886f0f3341a22
diff --git a/ocamldoc/.depend b/ocamldoc/.depend
index 4210ab5..f96a754 100644
--- a/ocamldoc/.depend
+++ b/ocamldoc/.depend
@@ -33,15 +33,17 @@ odoc_ast.cmo: ../typing/types.cmi ../typing/typedtree.cmi \
odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_sig.cmi \
odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_messages.cmo \
odoc_global.cmi odoc_exception.cmo odoc_env.cmi odoc_class.cmo \
- odoc_args.cmi ../utils/misc.cmi ../parsing/location.cmi \
- ../typing/ident.cmi ../parsing/asttypes.cmi odoc_ast.cmi
+ odoc_args.cmi ../utils/misc.cmi ../parsing/longident.cmi \
+ ../parsing/location.cmi ../typing/ident.cmi ../parsing/asttypes.cmi \
+ odoc_ast.cmi
odoc_ast.cmx: ../typing/types.cmx ../typing/typedtree.cmx \
../typing/predef.cmx ../typing/path.cmx ../parsing/parsetree.cmi \
odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_sig.cmx \
odoc_parameter.cmx odoc_name.cmx odoc_module.cmx odoc_messages.cmx \
odoc_global.cmx odoc_exception.cmx odoc_env.cmx odoc_class.cmx \
- odoc_args.cmx ../utils/misc.cmx ../parsing/location.cmx \
- ../typing/ident.cmx ../parsing/asttypes.cmi odoc_ast.cmi
+ odoc_args.cmx ../utils/misc.cmx ../parsing/longident.cmx \
+ ../parsing/location.cmx ../typing/ident.cmx ../parsing/asttypes.cmi \
+ odoc_ast.cmi
odoc_class.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_parameter.cmo odoc_name.cmi
odoc_class.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
@@ -59,11 +61,11 @@ odoc_config.cmx: ../utils/config.cmx odoc_config.cmi
odoc_cross.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_search.cmi \
odoc_scan.cmo odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
odoc_misc.cmi odoc_messages.cmo odoc_exception.cmo odoc_class.cmo \
- odoc_cross.cmi
+ odoc_args.cmi odoc_cross.cmi
odoc_cross.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_search.cmx \
odoc_scan.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx odoc_class.cmx \
- odoc_cross.cmi
+ odoc_args.cmx odoc_cross.cmi
odoc_dag2html.cmo: odoc_info.cmi odoc_dag2html.cmi
odoc_dag2html.cmx: odoc_info.cmx odoc_dag2html.cmi
odoc_dep.cmo: ../parsing/parsetree.cmi odoc_type.cmo odoc_print.cmi \
@@ -151,11 +153,11 @@ odoc_parameter.cmx: ../typing/types.cmx odoc_types.cmx
odoc_parser.cmo: odoc_types.cmi odoc_comments_global.cmi odoc_parser.cmi
odoc_parser.cmx: odoc_types.cmx odoc_comments_global.cmx odoc_parser.cmi
odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi \
- ../typing/outcometree.cmi ../typing/oprint.cmi odoc_type.cmo \
- odoc_misc.cmi odoc_print.cmi
+ ../typing/outcometree.cmi ../typing/oprint.cmi odoc_types.cmi \
+ odoc_type.cmo odoc_misc.cmi odoc_print.cmi
odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx \
- ../typing/outcometree.cmi ../typing/oprint.cmx odoc_type.cmx \
- odoc_misc.cmx odoc_print.cmi
+ ../typing/outcometree.cmi ../typing/oprint.cmx odoc_types.cmx \
+ odoc_type.cmx odoc_misc.cmx odoc_print.cmi
odoc_scan.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_scan.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_module.cmx \
@@ -202,8 +204,10 @@ odoc_text_parser.cmo: odoc_types.cmi odoc_misc.cmi odoc_text_parser.cmi
odoc_text_parser.cmx: odoc_types.cmx odoc_misc.cmx odoc_text_parser.cmi
odoc_to_text.cmo: odoc_messages.cmo odoc_info.cmi
odoc_to_text.cmx: odoc_messages.cmx odoc_info.cmx
-odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
-odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
+odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi \
+ ../parsing/asttypes.cmi
+odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx \
+ ../parsing/asttypes.cmi
odoc_types.cmo: odoc_messages.cmo odoc_types.cmi
odoc_types.cmx: odoc_messages.cmx odoc_types.cmi
odoc_value.cmo: ../typing/types.cmi odoc_types.cmi odoc_print.cmi \
@@ -219,8 +223,8 @@ odoc_cross.cmi: odoc_types.cmi odoc_module.cmo
odoc_dag2html.cmi: odoc_info.cmi
odoc_env.cmi: ../typing/types.cmi odoc_name.cmi
odoc_info.cmi: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
- odoc_type.cmo odoc_search.cmi odoc_parameter.cmo odoc_module.cmo \
- odoc_exception.cmo odoc_class.cmo
+ odoc_type.cmo odoc_search.cmi odoc_parameter.cmo odoc_name.cmi \
+ odoc_module.cmo odoc_exception.cmo odoc_class.cmo ../parsing/asttypes.cmi
odoc_merge.cmi: odoc_types.cmi odoc_module.cmo
odoc_misc.cmi: ../typing/types.cmi odoc_types.cmi ../parsing/longident.cmi
odoc_name.cmi: ../typing/path.cmi ../parsing/longident.cmi \
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index 3ff4ff8..b1ebdfa 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -939,8 +939,7 @@ module Analyser =
List.filter pred l
(** Analysis of a parse tree structure with a typed tree, to return module elements.*)
- let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree
- tmc_htbl =
+ let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree =
print_DEBUG "Odoc_ast:analyse_struture";
let (table, table_values) = Typedtree_search.tables typedtree in
let rec iter env last_pos = function
@@ -978,7 +977,6 @@ module Analyser =
typedtree
table
table_values
- tmc_htbl
in
ele_comments @ elements @ (iter new_env (item.Parsetree.pstr_loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q)
in
@@ -986,7 +984,7 @@ module Analyser =
(** Analysis of a parse tree structure item to obtain a new environment and a list of elements.*)
and analyse_structure_item env current_module_name loc pos_limit comment_opt parsetree_item_desc typedtree
- table table_values tmc_htbl =
+ table table_values =
print_DEBUG "Odoc_ast:analyse_struture_item";
match parsetree_item_desc with
Parsetree.Pstr_eval _ ->
@@ -1119,9 +1117,11 @@ module Analyser =
in
let tec = match type_decl.Parsetree.ptype_manifest
with None -> None | Some ct ->
- Some (Sig.get_tec tmc_htbl ct ~env: new_env
+ Some (begin Sig.get_tec ct ~env: new_env
~name: (Name.concat current_module_name name)
- ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum
+ end, None)
+ in
let new_end = loc_end + maybe_more in
let t =
{
@@ -1228,7 +1228,6 @@ module Analyser =
comment_opt
module_expr
tt_module_expr
- tmc_htbl
in
let code =
if !Odoc_args.keep_code then
@@ -1278,7 +1277,6 @@ module Analyser =
None
mod_exp
tt_mod_exp
- tmc_htbl
in
match new_module.m_type with
Types.Tmty_signature s ->
@@ -1314,7 +1312,6 @@ module Analyser =
com_opt
mod_exp
tt_mod_exp
- tmc_htbl
in
let eles = f loc_end q in
ele_comments @ ((Element_module new_module) :: eles)
@@ -1330,7 +1327,7 @@ module Analyser =
raise (Failure (Odoc_messages.module_type_not_found_in_typedtree complete_name))
in
let kind = Sig.analyse_module_type_kind env complete_name
- modtype tt_module_type tmc_htbl
+ modtype tt_module_type
in
let mt =
{
@@ -1354,8 +1351,7 @@ module Analyser =
in
(0, new_env2, [ Element_module_type mt ])
- | Parsetree.Pstr_open longident ->
- (* A VOIR : enrichir l'environnement quand open ? *)
+ | Parsetree.Pstr_open lid ->
let ele_comments = match comment_opt with
None -> []
| Some i ->
@@ -1363,7 +1359,17 @@ module Analyser =
None -> []
| Some t -> [Element_module_comment t]
in
- (0, env, ele_comments)
+ let name = (String.concat "." (Longident.flatten lid)) in
+ begin try match (Typedtree_search.search_module table name).Typedtree.mod_type
+ with Tmty_signature signat ->
+ let full_name = Odoc_env.full_module_name env name in
+ let new_env = Odoc_env.add_signature env full_name signat in
+ (0, new_env, ele_comments)
+ | _ -> (0, env, ele_comments)
+ with Not_found -> (0, env, ele_comments)
+ (* XXX: this may be because it is an external module,
+ * so how do we get its signature? *)
+ end
| Parsetree.Pstr_class class_decl_list ->
(* we start by extending the environment *)
@@ -1476,8 +1482,7 @@ module Analyser =
(0, env, [ Element_included_module im ]) (* A VOIR : étendre l'environnement ? avec quoi ? *)
(** Analysis of a [Parsetree.module_expr] and a name to return a [t_module].*)
- and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr
- tmc_htbl =
+ and analyse_module env current_module_name module_name comment_opt p_module_expr tt_module_expr =
let complete_name = Name.concat current_module_name module_name in
let pos_start = p_module_expr.Parsetree.pmod_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = p_module_expr.Parsetree.pmod_loc.Location.loc_end.Lexing.pos_cnum in
@@ -1517,7 +1522,7 @@ module Analyser =
| (Parsetree.Pmod_structure p_structure, Typedtree.Tmod_structure tt_structure) ->
let elements = analyse_structure env complete_name pos_start
- pos_end p_structure tt_structure tmc_htbl in
+ pos_end p_structure tt_structure in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1532,7 +1537,6 @@ module Analyser =
let mp_name = Name.from_ident ident in
let mp_kind = Sig.analyse_module_type_kind env
current_module_name pmodule_type mtyp
- tmc_htbl
in
let param =
{
@@ -1552,7 +1556,6 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
- tmc_htbl
in
let kind = m_base2.m_kind in
{ m_base with m_kind = Module_functor (param, kind) }
@@ -1571,7 +1574,6 @@ module Analyser =
None
p_module_expr1
tt_module_expr1
- tmc_htbl
in
let m2 = analyse_module
env
@@ -1580,7 +1582,6 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
- tmc_htbl
in
{ m_base with m_kind = Module_apply (m1.m_kind, m2.m_kind) }
@@ -1594,11 +1595,10 @@ module Analyser =
None
p_module_expr2
tt_module_expr2
- tmc_htbl
in
let mtkind = Sig.analyse_module_type_kind env
(Name.concat current_module_name "??")
- p_modtype tt_modtype tmc_htbl
+ p_modtype tt_modtype
in
let tt_modtype = Odoc_env.subst_module_type env tt_modtype in
filter_module_with_module_type_constraint m_base2 tt_modtype;
@@ -1617,7 +1617,7 @@ module Analyser =
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_structure + Typedtree.Tmod_constraint "^module_name);
let elements = analyse_structure env complete_name pos_start pos_end
- p_structure tt_structure tmc_htbl in
+ p_structure tt_structure in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1671,9 +1671,8 @@ module Analyser =
let (len,info_opt) = My_ir.first_special !file_name !file in
(* we must complete the included modules *)
- let tmc_htbl = Hashtbl.create 12 in
let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file)
- parsetree tree_structure tmc_htbl in
+ parsetree tree_structure in
let included_modules_from_tt = tt_get_included_module_list tree_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
let kind = Module_struct elements2 in
diff --git a/ocamldoc/odoc_cross.ml b/ocamldoc/odoc_cross.ml
index 6df118c..3c37583 100644
--- a/ocamldoc/odoc_cross.ml
+++ b/ocamldoc/odoc_cross.ml
@@ -898,17 +898,137 @@ and assoc_comments_type module_list t =
(fun rf -> rf.rf_text <- ao (assoc_comments_text parent module_list) rf.rf_text)
fl
);
- let rec f = function
- Tec_list l -> List.iter f l
- | Tec_variant ht ->
+ let rec assoc_tmc = function
+ Tec_list l -> List.iter assoc_tmc l
+ | Tec_variant {tec_variant_labels=labels;
+ tec_variant_nested=nested} ->
Hashtbl.iter
begin fun lbl buc ->
buc.tec_variant_coms <-
assoc_comments_text parent module_list
buc.tec_variant_coms;
- f buc.tec_variant_tec
- end ht
- in (match t.ty_tmc with Some tec -> f tec | _ -> ());
+ assoc_tmc buc.tec_variant_tec
+ end labels
+ in
+ let fail_on_different_types () =
+ if not !Odoc_args.inverse_merge_ml_mli
+ then raise (Failure (Odoc_messages.different_types t.ty_name))
+ in
+ let has_merge_description_option =
+ List.mem Merge_description !Odoc_args.merge_options in
+ (* TIP: with Vim the debugging messages below are easily navigable
+ * with the '%' key and set fmr=[,] plus set fdm=marker *)
+ let rec merge_labels
+ ?(strict = true)
+ ?(glob_com: Odoc_types.text = [])
+ (tec, tec') =
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: [\n";
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)print_tec tec';
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ begin match tec, tec' with
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> merge_labels (x, y)) l l';
+ | (Tec_variant buc as tec),
+ (Tec_variant buc' as tec') ->
+ complete_labels tec;
+ complete_labels tec';
+ Hashtbl.iter
+ begin fun lbl buc' ->
+ let (@) l1 l2 = (* avoid useless list traversal *)
+ if l2 = [] then l1 else l1 @ l2
+ in try let buc = Hashtbl.find buc.tec_variant_labels lbl in
+ (* both types have the same label present: merge comments *)
+ let coms =
+ if has_merge_description_option
+ || buc.tec_variant_coms = []
+ then buc'.tec_variant_coms else []
+ in buc.tec_variant_coms <- buc.tec_variant_coms @ coms;
+ let glob_com =
+ if has_merge_description_option
+ || buc.tec_variant_glob_com = []
+ then buc'.tec_variant_glob_com @ glob_com else glob_com
+ in buc.tec_variant_glob_com <- buc.tec_variant_glob_com @ glob_com;
+ merge_labels (buc.tec_variant_tec, buc'.tec_variant_tec)
+ with Not_found ->
+ if strict
+ then fail_on_different_types ()
+ else begin
+ (* we are merging a nested p. v. type,
+ * which brings a new label *)
+ let buc' = {buc' with tec_variant_tec=clone_tec buc'.tec_variant_tec} in
+ buc'.tec_variant_coms <- buc'.tec_variant_coms;
+ buc'.tec_variant_glob_com <- glob_com;
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: add=%s\n" lbl;
+ Hashtbl.add buc.tec_variant_labels lbl buc'
+ end;
+ end buc'.tec_variant_labels;
+ | _ -> fail_on_different_types ()
+ end;
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)print_tec tec';
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: ]\n"
+
+ and complete_labels tec =
+ (*DEBUG*)Printf.fprintf stderr "complete_labels: [\n";
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ begin match tec with
+ Tec_list l -> ()
+ | Tec_variant buc as tec ->
+ (* merge the type expression comments pointed
+ * by [buc.tec_variant_nested] within [tec] *)
+ let q = Queue.create () in
+ Hashtbl.iter begin fun name glob_com ->
+ (*DEBUG*)Printf.fprintf stderr "fetching: [ name=%s\n" name;
+ (* Retrieve comments of nested p. v. types *)
+ ignore (List.exists
+ (function Odoc_search.Res_type t ->
+ (match t.ty_tmc with None -> true
+ | Some (tec', None) ->
+ (*DEBUG*)Printf.fprintf stderr "complete: name=%s\n" name;
+ complete_labels tec';
+ Queue.add (name, tec', glob_com) q;
+ true
+ | Some (tec', Some tec'') ->
+ (*DEBUG*)Printf.fprintf stderr "merge: trig name=%s\n" name;
+ merge_labels (tec', tec'');
+ (*DEBUG*)Printf.fprintf stderr "complete: name=%s\n" name;
+ complete_labels tec';
+ Queue.add (name, tec', glob_com) q;
+ true)
+ | _ -> false)
+ (get_known_elements name));
+ (*DEBUG*)Printf.fprintf stderr "fetching: ] name=%s\n" name;
+ end buc.tec_variant_nested;
+ Hashtbl.clear buc.tec_variant_nested;
+ (* now since the hashtable is empty,
+ * all further [complete_labels] on this tec,
+ * will return immediately. *)
+ (* still we have merges to do *)
+ Queue.iter (fun (name, tec', glob_com) ->
+ (*DEBUG*)Printf.fprintf stderr "merge: queue name=%s glob=%s\n" name
+ (*DEBUG*) (String.concat " " (List.map (function Odoc_types.Raw s -> s | _ -> "") glob_com));
+ merge_labels (tec, tec') ~glob_com ~strict: false) q;
+ end;
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)Printf.fprintf stderr "complete_labels: ]\n";
+ in
+ begin match t.ty_tmc with None -> ()
+ | Some (tec, None) ->
+ complete_labels tec;
+ assoc_tmc tec
+ | Some (tec, Some tec') ->
+ t.ty_tmc <- Some (tec, None);
+ (*DEBUG*)Printf.fprintf stderr "cross: [ name=%s\n" t.ty_name;
+ merge_labels (tec, tec');
+ assoc_tmc tec;
+ (*DEBUG*)Printf.fprintf stderr "cross: ] name=%s\n" t.ty_name;
+ end;
t
and assoc_comments_attribute module_list a =
diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml
index a96e130..2f0714c 100644
--- a/ocamldoc/odoc_html.ml
+++ b/ocamldoc/odoc_html.ml
@@ -1388,7 +1388,8 @@ class html =
None -> ()
| Some typ ->
bs b "= ";
- self#html_of_type_expr b father typ ?tec: t.ty_tmc;
+ self#html_of_type_expr b father typ
+ ?tec: (match t.ty_tmc with Some (tec, _) -> Some tec | _ -> None);
bs b " "
);
(match t.ty_kind with
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index 647e45b..0e453bf 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -212,12 +212,28 @@ module Type :
| Type_record of record_field list * bool
(** fields * bool *)
+ (** Type expression's comments *)
type tec = Odoc_type.tec =
- Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ Tec_variant of tec_variant_buc
+ (** comments for a polimorphic variant expression *)
| Tec_list of tec list
+ (** orthogonal types. Note that [Tec_list []] can be used *)
and tec_variant_buc = Odoc_type.tec_variant_buc =
+ { tec_variant_labels : (Asttypes.label, tec_variant_lbl_buc) Hashtbl.t;
+ (** the labels textually present in a p. v. type expression *)
+ mutable tec_variant_nested : (Odoc_name.t, Odoc_types.text) Hashtbl.t
+ (** the nested p. v. types textually present int a p.v. type expression,
+ and the global comments associated *) }
+ and tec_variant_lbl_buc = Odoc_type.tec_variant_lbl_buc =
{ mutable tec_variant_coms: Odoc_types.text;
- tec_variant_tec: tec }
+ (** the comments of a label *)
+ mutable tec_variant_glob_com: Odoc_types.text;
+ (** the global comment of a label *)
+ tec_variant_tec: tec
+ (** the comments of the label's data *) }
+
+ val clone_tec : tec -> tec
+ (*DEBUG*)val print_tec : ?s: string -> tec -> unit
(** Representation of a type. *)
type t_type = Odoc_type.t_type =
@@ -227,8 +243,11 @@ module Type :
ty_parameters : (Types.type_expr * bool * bool) list ;
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind ; (** Type kind. *)
- ty_manifest : Types.type_expr option; (** Type manifest. *)
- mutable ty_tmc : tec option; (** Type manifest's comments. *)
+ ty_manifest : Types.type_expr option ; (** Type manifest. *)
+ mutable ty_tmc : (tec * tec option) option;
+ (** Type manifest's comments and another one to be merge within.
+ This second [tec] is used to carry ml's [tec] between,
+ the merging time and the cross referencing time *)
mutable ty_loc : location ;
mutable ty_code : string option;
}
diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml
index 27a5c97..01ea52e 100644
--- a/ocamldoc/odoc_merge.ml
+++ b/ocamldoc/odoc_merge.ml
@@ -252,26 +252,9 @@ let merge_types merge_options mli ml =
begin match mli.ty_tmc, ml.ty_tmc with
None, None
| Some _, None -> ()
- | None, Some tec -> mli.ty_tmc <- ml.ty_tmc
- | Some mli_tec, Some ml_tec ->
- let rec f = function
- Tec_list l, Tec_list l' ->
- List.iter2 (fun x y -> f (x, y)) l l'
- | Tec_variant ht, Tec_variant ht' ->
- Hashtbl.iter
- begin fun lbl ({tec_variant_coms=coms;
- tec_variant_tec=tec} as buc) ->
- try let {tec_variant_coms=coms';
- tec_variant_tec=tec'} = Hashtbl.find ht' lbl in
- if (coms' <> []
- && has_merge_description_option)
- || coms = []
- then buc.tec_variant_coms <- coms @ coms';
- f (tec, tec')
- with Not_found -> fail_on_different_types ()
- end ht
- | _ -> fail_on_different_types ()
- in f (mli_tec, ml_tec)
+ | None, Some _ -> mli.ty_tmc <- ml.ty_tmc
+ | Some (mli_tec, _), Some (ml_tec, _) ->
+ mli.ty_tmc <- Some (mli_tec, Some ml_tec)
end
(** Merge of two param_info, one from a .mli, one from a .ml.
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index 7246356..aeb9ffe 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -192,16 +192,25 @@ module Odoc_oprint =
else fprintf ppf ""
in
let {Odoc_type.tec_variant_coms=coms;
+ tec_variant_glob_com=glob_com;
tec_variant_tec=tec} =
try match tec with
- Tec_variant ht -> Hashtbl.find ht l
+ Tec_variant {Odoc_type.tec_variant_labels=labels} ->
+ Hashtbl.find labels l
| _ -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_glob_com=[];
tec_variant_tec=Tec_list []}
with Not_found -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_glob_com=[];
tec_variant_tec=Tec_list []} in
+ let coms =
+ if glob_com <> []
+ then coms @ (Odoc_types.Raw " " :: glob_com)
+ (** XXX: hardcoded separator *)
+ else coms in
let str_coms =
if coms <> []
- then str_of_com coms
+ then str_of_com coms
else "" in
fprintf ppf "@[<hv 2>`%s%t%a%s%s@]"
l pr_of
diff --git a/ocamldoc/odoc_scan.ml b/ocamldoc/odoc_scan.ml
index b62e25b..ae49890 100644
--- a/ocamldoc/odoc_scan.ml
+++ b/ocamldoc/odoc_scan.ml
@@ -56,7 +56,7 @@ class scanner =
)
(Odoc_class.class_elements c)
- (** Scan of a class. Should not be overriden. It calls [scan_class_pre]
+ (** Scan of a class. Should not be overridden. It calls [scan_class_pre]
and if [scan_class_pre] returns [true], then it calls scan_class_elements.*)
method scan_class c = if self#scan_class_pre c then self#scan_class_elements c
@@ -82,7 +82,7 @@ class scanner =
)
(Odoc_class.class_type_elements ct)
- (** Scan of a class type. Should not be overriden. It calls [scan_class_type_pre]
+ (** Scan of a class type. Should not be overridden. It calls [scan_class_type_pre]
and if [scan_class_type_pre] returns [true], then it calls scan_class_type_elements.*)
method scan_class_type ct = if self#scan_class_type_pre ct then self#scan_class_type_elements ct
@@ -113,7 +113,7 @@ class scanner =
)
(Odoc_module.module_elements m)
- (** Scan of a module. Should not be overriden. It calls [scan_module_pre]
+ (** Scan of a module. Should not be overridden. It calls [scan_module_pre]
and if [scan_module_pre] returns [true], then it calls scan_module_elements.*)
method scan_module m = if self#scan_module_pre m then self#scan_module_elements m
@@ -144,7 +144,7 @@ class scanner =
)
(Odoc_module.module_type_elements mt)
- (** Scan of a module type. Should not be overriden. It calls [scan_module_type_pre]
+ (** Scan of a module type. Should not be overridden. It calls [scan_module_type_pre]
and if [scan_module_type_pre] returns [true], then it calls scan_module_type_elements.*)
method scan_module_type mt =
if self#scan_module_type_pre mt then self#scan_module_type_elements mt
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index 3795629..0382f17 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -216,17 +216,7 @@ module Analyser =
(0, f name_mutable_type_list)
let get_tec
- tmc_htbl ~env ~name
- ~pos_end par_ct : tec =
- let get_mem_tec ~name tmc_htbl =
- (*DEBUG*)try
- Hashtbl.find tmc_htbl name
- (*DEBUG*)with Not_found ->
- (*DEBUG*) prerr_endline ("name: " ^ name);
- (*DEBUG*) prerr_endline ("htbl:" ^ Hashtbl.fold
- (*DEBUG*) (fun k v a -> a ^ " " ^ k) tmc_htbl "");
- (*DEBUG*) raise Not_found
- in
+ ~env ~name ~pos_end par_ct : tec =
let retrieve_comments pos_end loc dlen : Odoc_types.text =
(* retrieve the source from the start of the current variant
* to the end of the current type *)
@@ -250,40 +240,24 @@ module Analyser =
Some {Odoc_types.i_desc = Some coms} -> coms
| _ -> []
in
- let (@) l1 l2 =
- match l2 with [] -> l1 (* no need to rebuild a list *)
- | _ -> l1 @ l2 in
- let rec merge_com
- ?(glob_coms = [])
- htbl lbl ({tec_variant_coms=coms;
- tec_variant_tec=tec} as buc) : unit =
- let glob_coms = if glob_coms = [] then glob_coms
- else Odoc_types.Raw " " (* XXX: hardcoded separator *)
- :: glob_coms in
- try let {tec_variant_coms=old_coms;
- tec_variant_tec=old_tec} as buc = Hashtbl.find htbl lbl in
- buc.tec_variant_coms <- old_coms @ (coms @ glob_coms);
- let rec f = function Tec_variant old_htbl ->
- (function Tec_variant htbl -> Hashtbl.iter (merge_com old_htbl) htbl
- | _ -> assert false)
- | Tec_list old_l ->
- (function Tec_list l -> List.iter2 f old_l l
- | _ -> assert false) in
- f old_tec tec
+ let rec add_label
+ labels lbl buc : unit =
+ try let buc' = Hashtbl.find labels lbl in
+ (* the label is already present: merge *)
+ if buc'.tec_variant_coms <> []
+ then buc.tec_variant_coms <-
+ buc.tec_variant_coms @ buc'.tec_variant_coms;
+ let rec f = function
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> f (x, y)) l l'
+ | Tec_variant {tec_variant_labels=labels},
+ Tec_variant {tec_variant_labels=labels'} ->
+ Hashtbl.iter (add_label labels) labels'
+ | _ -> assert false
+ in f (buc.tec_variant_tec, buc'.tec_variant_tec)
with Not_found ->
- buc.tec_variant_coms <- buc.tec_variant_coms @ glob_coms;
- Hashtbl.add htbl lbl buc
- in
- let rec clone_tec = function
- Tec_variant htbl ->
- let ht = Hashtbl.create (Hashtbl.length htbl) in
- Hashtbl.iter begin fun lbl {tec_variant_coms=coms;
- tec_variant_tec=tec} ->
- Hashtbl.add ht lbl {tec_variant_coms=coms;
- tec_variant_tec=clone_tec tec}
- end htbl;
- Tec_variant ht
- | Tec_list l -> Tec_list (List.map clone_tec l)
+ (* this is a new label: insert it *)
+ Hashtbl.add labels lbl buc
in
let rec get ?(pstart = 0) ?(pdlen = ref 0) par_ct =
let loc = par_ct.Parsetree.ptyp_loc in
@@ -291,8 +265,9 @@ module Analyser =
pdlen := !pdlen + loc.Location.loc_end.Lexing.pos_cnum - pstart;
let get ct = get ct ~pdlen: dlen
~pstart: (loc.Location.loc_start.Lexing.pos_cnum + !dlen) in
- let htbl = Hashtbl.create 12 in
- let tec = match par_ct.Parsetree.ptyp_desc with
+ let labels = Hashtbl.create 13 in
+ let nested = Hashtbl.create 13 in
+ begin match par_ct.Parsetree.ptyp_desc with
Parsetree.Ptyp_any
| Parsetree.Ptyp_var _
| Parsetree.Ptyp_constr _ -> Tec_list []
@@ -316,34 +291,27 @@ module Analyser =
let tec = match l with [tec] -> tec (* not really a tuple *)
| _ -> Tec_list l in
let coms = retrieve_comments pos_end loc dlen in
- merge_com htbl lbl ({tec_variant_coms=coms;
- tec_variant_tec=tec});
+ add_label labels lbl ({tec_variant_coms=coms;
+ tec_variant_glob_com=[];
+ (* may be updated at merging time *)
+ tec_variant_tec=tec});
| Parsetree.Rinherit ct ->
match ct.Parsetree.ptyp_desc with
- Parsetree.Ptyp_constr (id, _) ->
- begin try let tec = clone_tec (get_mem_tec tmc_htbl
- ~name: (Odoc_env.full_type_name env
- (String.concat "." (Longident.flatten id))))
- in match tec with Tec_variant ht ->
- let glob_coms = retrieve_comments pos_end loc dlen in
- Hashtbl.iter (merge_com htbl ~glob_coms) ht
- | _ -> ()
- with Not_found -> () (* raised either by [get_mem_tec]
- * or by [Odoc_env.full_type_name] *) end
+ Parsetree.Ptyp_constr (lid, _) ->
+ let glob_com = retrieve_comments pos_end loc dlen in
+ let name = Odoc_env.full_type_name env
+ (String.concat "." (Longident.flatten lid)) in
+ Hashtbl.replace nested name glob_com
| _ -> ()
end row_field_list;
- Tec_variant htbl
- in
- tec
+ Tec_variant {tec_variant_labels=labels;
+ tec_variant_nested=nested}
+ end
in
let tec = get par_ct in
- Hashtbl.replace tmc_htbl name tec;
- (* memorize the [tec] in order to retrieve it
- * when it happens to be nested inside a following poly. variant.
- * Note that:
- * # type a = [`a|b] and b = [`b];;
- * The type constructor s is not yet completely defined
- *)
+ (*DEBUG*)Printf.fprintf stderr "\nget_tec name=%s" name;
+ (*DEBUG*)print_tec tec ~s: "";
+ (*DEBUG*)Printf.fprintf stderr "\n";
tec
let get_type_kind env name_comment_list type_kind =
@@ -564,8 +532,7 @@ module Analyser =
(** Analyse of a .mli parse tree, to get the corresponding elements.
last_pos is the position of the first character which may be used to look for special comments.
*)
- let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list
- tmc_htbl =
+ let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list =
let table = Signature_search.table signat in
(* we look for the comment of each item then analyse the item *)
let rec f acc_eles acc_env last_pos = function
@@ -603,7 +570,6 @@ module Analyser =
)
assoc_com
ele.Parsetree.psig_desc
- tmc_htbl
in
f (acc_eles @ (ele_comments @ elements))
new_env
@@ -618,8 +584,7 @@ module Analyser =
(** Analyse the given signature_item_desc to create the corresponding module element
(with the given attached comment).*)
and analyse_signature_item_desc env signat table current_module_name
- pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc
- tmc_htbl =
+ pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc =
match sig_item_desc with
Parsetree.Psig_value (name_pre, value_desc) ->
let type_expr =
@@ -733,9 +698,10 @@ module Analyser =
let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in
let tmc = match type_decl.Parsetree.ptype_manifest
with None -> None | Some ct ->
- Some (get_tec tmc_htbl ct ~env: new_env
- ~name: (Name.concat current_module_name name)
- ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum) in
+ Some (begin get_tec ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum
+ end, None) in
(* associate the comments to each constructor and build the [Type.t_type] *)
let new_type =
{
@@ -783,7 +749,7 @@ module Analyser =
let (maybe_more, types) = f ~first: true 0 pos_start_ele name_type_decl_list in
(maybe_more, new_env, types)
- | Parsetree.Psig_open _ -> (* A VOIR *)
+ | Parsetree.Psig_open lid ->
let ele_comments = match comment_opt with
None -> []
| Some i ->
@@ -791,7 +757,17 @@ module Analyser =
None -> []
| Some t -> [Element_module_comment t]
in
- (0, env, ele_comments)
+ let name = (String.concat "." (Longident.flatten lid)) in
+ begin try match Signature_search.search_module table name
+ with Tmty_signature signat ->
+ let full_name = Odoc_env.full_module_name env name in
+ let new_env = Odoc_env.add_signature env full_name signat in
+ (0, new_env, ele_comments)
+ | _ -> (0, env, ele_comments)
+ with Not_found -> (0, env, ele_comments)
+ (* XXX: this may be because it is an external module,
+ * so how do we get its signature? *)
+ end
| Parsetree.Psig_module (name, module_type) ->
let complete_name = Name.concat current_module_name name in
@@ -802,7 +778,7 @@ module Analyser =
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
let module_kind = analyse_module_kind env complete_name module_type
- sig_module_type tmc_htbl in
+ sig_module_type in
let code_intf =
if !Odoc_args.keep_code then
let loc = module_type.Parsetree.pmty_loc in
@@ -894,7 +870,7 @@ module Analyser =
in
(* associate the comments to each constructor and build the [Type.t_type] *)
let module_kind = analyse_module_kind new_env complete_name
- modtype sig_module_type tmc_htbl in
+ modtype sig_module_type in
let code_intf =
if !Odoc_args.keep_code then
let loc = modtype.Parsetree.pmty_loc in
@@ -973,7 +949,7 @@ module Analyser =
let module_type_kind =
match sig_mtype_opt with
| Some sig_mtype -> Some (analyse_module_type_kind env complete_name
- module_type sig_mtype tmc_htbl)
+ module_type sig_mtype)
| None -> None
in
let mt =
@@ -1173,8 +1149,7 @@ module Analyser =
(maybe_more, new_env, eles)
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
- and analyse_module_type_kind env current_module_name module_type sig_module_type
- tmc_htbl =
+ and analyse_module_type_kind env current_module_name module_type sig_module_type =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
let name =
@@ -1194,7 +1169,7 @@ module Analyser =
let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let elements = analyse_parsetree env signat current_module_name
- pos_start pos_end ast tmc_htbl in
+ pos_start pos_end ast in
Module_type_struct elements
| _ ->
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
@@ -1210,7 +1185,6 @@ module Analyser =
Types.Tmty_functor (ident, param_module_type, body_module_type) ->
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
- tmc_htbl
in
let param =
{
@@ -1224,7 +1198,6 @@ module Analyser =
current_module_name
module_type2
body_module_type
- tmc_htbl
in
Module_type_functor (param, k)
@@ -1240,17 +1213,16 @@ module Analyser =
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
let k = analyse_module_type_kind env current_module_name
- module_type2 sig_module_type tmc_htbl in
+ module_type2 sig_module_type in
Module_type_with (k, s)
)
(** Analyse of a Parsetree.module_type and a Types.module_type.*)
- and analyse_module_kind env current_module_name module_type sig_module_type
- tmc_htbl =
+ and analyse_module_kind env current_module_name module_type sig_module_type =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
let k = analyse_module_type_kind env current_module_name module_type
- sig_module_type tmc_htbl in
+ sig_module_type in
Module_with ( k, "" )
| Parsetree.Pmty_signature signature ->
@@ -1265,7 +1237,6 @@ module Analyser =
module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum
module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum
signature
- tmc_htbl
)
| _ ->
(* if we're here something's wrong *)
@@ -1281,7 +1252,6 @@ module Analyser =
print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code);
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
- tmc_htbl
in
let param =
{
@@ -1295,7 +1265,6 @@ module Analyser =
current_module_name
module_type2
body_module_type
- tmc_htbl
in
Module_functor (param, k)
@@ -1310,7 +1279,7 @@ module Analyser =
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
let k = analyse_module_type_kind env current_module_name module_type2
- sig_module_type tmc_htbl in
+ sig_module_type in
Module_with (k, s)
)
@@ -1454,10 +1423,8 @@ module Analyser =
(Filename.basename (try Filename.chop_extension source_file with _ -> source_file))
in
let (len,info_opt) = My_ir.first_special !file_name !file in
- let tmc_htbl = Hashtbl.create 12 in
let elements =
- analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file)
- ast tmc_htbl
+ analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file) ast
in
let code_intf =
if !Odoc_args.keep_code then
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index d13d5e4..8b21d9b 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -152,9 +152,8 @@ module Analyser :
(** Fetch the comments (only in polymorphic variants currently)
inside a [Parsetree.core_type]. *)
val get_tec :
- (Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
env: Odoc_env.env ->
- name: string ->
+ name: Odoc_name.t ->
pos_end: int ->
Parsetree.core_type -> Odoc_type.tec
@@ -169,7 +168,6 @@ module Analyser :
Odoc_name.t ->
Parsetree.module_type ->
Types.module_type ->
- (Odoc_module.Name.t, Odoc_type.tec) Hashtbl.t ->
Odoc_module.module_type_kind
(** Analysis of a Parsetree.class_type and a Types.class_type to
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 9240102..784ed69 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -38,12 +38,86 @@ type type_kind =
| Type_record of record_field list * bool
(** fields * bool *)
+(** Type expression's comments *)
type tec =
- Tec_variant of (string, tec_variant_buc) Hashtbl.t
+ Tec_variant of tec_variant_buc
+ (** comments for a polimorphic variant expression *)
| Tec_list of tec list
+ (** orthogonal types. Note that [Tec_list []] can be used *)
and tec_variant_buc =
+ { tec_variant_labels : (Asttypes.label, tec_variant_lbl_buc) Hashtbl.t;
+ (** the labels textually present in a p. v. type expression *)
+ mutable tec_variant_nested : (Odoc_name.t, Odoc_types.text) Hashtbl.t
+ (** the nested p. v. types textually present int a p.v. type expression,
+ and the global comments associated *) }
+and tec_variant_lbl_buc =
{ mutable tec_variant_coms: Odoc_types.text;
- tec_variant_tec: tec }
+ (** the comments of a label *)
+ mutable tec_variant_glob_com: Odoc_types.text;
+ (** the global comment of a label *)
+ tec_variant_tec: tec
+ (** the comments of the label's data *) }
+
+let rec clone_tec =
+ function
+ Tec_list l ->
+ Tec_list (List.map clone_tec l)
+ | Tec_variant buc ->
+ let labels = Hashtbl.create
+ (Hashtbl.length buc.tec_variant_labels) in
+ Hashtbl.iter
+ (fun lbl buc -> Hashtbl.add labels lbl
+ {buc with tec_variant_tec=clone_tec buc.tec_variant_tec})
+ buc.tec_variant_labels;
+ let nested = Hashtbl.create
+ (Hashtbl.length buc.tec_variant_nested) in
+ Hashtbl.iter (Hashtbl.add nested) buc.tec_variant_nested;
+ Tec_variant
+ { tec_variant_labels=labels;
+ tec_variant_nested=nested }
+
+(*DEBUG*)open Printf
+(*DEBUG*)let rec print_tec
+(*DEBUG*) ?(s="") =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) function
+(*DEBUG*) Tec_list l ->
+(*DEBUG*) fprintf o "\n%sTec_list [" s;
+(*DEBUG*) List.iter (print_tec ~s: (s ^ " ")) l;
+(*DEBUG*) fprintf o "]"
+(*DEBUG*) | Tec_variant
+(*DEBUG*) { tec_variant_labels=labels
+(*DEBUG*) ; tec_variant_nested=nested } ->
+(*DEBUG*) fprintf o "\n%sTec_variant" s;
+(*DEBUG*) print_labels labels ~s: (s ^ " ");
+(*DEBUG*) print_nested nested ~s: (s ^ " ")
+(*DEBUG*)and print_labels ~s =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) Hashtbl.iter begin fun lbl buc ->
+(*DEBUG*) fprintf o "\n%slbl=%s" s lbl;
+(*DEBUG*) if buc.tec_variant_coms <> []
+(*DEBUG*) then fprintf o "\n%scoms=%s" s
+(*DEBUG*) (string_of_com buc.tec_variant_coms);
+(*DEBUG*) if buc.tec_variant_glob_com <> []
+(*DEBUG*) then fprintf o "\n%sglob=%s" s
+(*DEBUG*) (string_of_com buc.tec_variant_glob_com);
+(*DEBUG*) if buc.tec_variant_tec <> Tec_list []
+(*DEBUG*) then begin
+(*DEBUG*) fprintf o "\n%stec=" s;
+(*DEBUG*) print_tec buc.tec_variant_tec
+(*DEBUG*) ~s: (s ^ " ")
+(*DEBUG*) end
+(*DEBUG*) end
+(*DEBUG*)and print_nested ~s =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) Hashtbl.iter begin fun name glob_com ->
+(*DEBUG*) fprintf o "\n%sname=%s" s name;
+(*DEBUG*) if glob_com <> []
+(*DEBUG*) then fprintf o "\n%sglob=%s" s (string_of_com glob_com)
+(*DEBUG*) end
+(*DEBUG*)and string_of_com com =
+(*DEBUG*) String.concat " "
+(*DEBUG*) (List.map (function Odoc_types.Raw s -> s | _ -> "") com)
(** Representation of a type. *)
type t_type = {
@@ -53,7 +127,10 @@ type t_type = {
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind;
ty_manifest : Types.type_expr option; (** type manifest *)
- mutable ty_tmc : tec option; (** type manifest's comments *)
+ mutable ty_tmc : (tec * tec option) option;
+ (** type manifest's comments and another one to be merge within.
+ This second [tec] is used to carry ml's [tec] between,
+ the merging time and the cross referencing time *)
mutable ty_loc : Odoc_types.location;
mutable ty_code : string option;
}
diff --git a/ocamldoc/.depend b/ocamldoc/.depend
index 5e2196a..f96a754 100644
--- a/ocamldoc/.depend
+++ b/ocamldoc/.depend
@@ -1,11 +1,3 @@
-odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
- odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
- odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
- ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
-odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
- odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
- odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
- ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_analyse.cmo: ../utils/warnings.cmi ../typing/typetexp.cmi \
../typing/types.cmi ../typing/typemod.cmi ../typing/typedtree.cmi \
../typing/typedecl.cmi ../typing/typecore.cmi ../typing/typeclass.cmi \
@@ -41,37 +33,39 @@ odoc_ast.cmo: ../typing/types.cmi ../typing/typedtree.cmi \
odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_sig.cmi \
odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_messages.cmo \
odoc_global.cmi odoc_exception.cmo odoc_env.cmi odoc_class.cmo \
- odoc_args.cmi ../utils/misc.cmi ../parsing/location.cmi \
- ../typing/ident.cmi ../parsing/asttypes.cmi odoc_ast.cmi
+ odoc_args.cmi ../utils/misc.cmi ../parsing/longident.cmi \
+ ../parsing/location.cmi ../typing/ident.cmi ../parsing/asttypes.cmi \
+ odoc_ast.cmi
odoc_ast.cmx: ../typing/types.cmx ../typing/typedtree.cmx \
../typing/predef.cmx ../typing/path.cmx ../parsing/parsetree.cmi \
odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_sig.cmx \
odoc_parameter.cmx odoc_name.cmx odoc_module.cmx odoc_messages.cmx \
odoc_global.cmx odoc_exception.cmx odoc_env.cmx odoc_class.cmx \
- odoc_args.cmx ../utils/misc.cmx ../parsing/location.cmx \
- ../typing/ident.cmx ../parsing/asttypes.cmi odoc_ast.cmi
+ odoc_args.cmx ../utils/misc.cmx ../parsing/longident.cmx \
+ ../parsing/location.cmx ../typing/ident.cmx ../parsing/asttypes.cmi \
+ odoc_ast.cmi
odoc_class.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_parameter.cmo odoc_name.cmi
odoc_class.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
odoc_parameter.cmx odoc_name.cmx
+odoc_comments_global.cmo: odoc_comments_global.cmi
+odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_comments.cmo: odoc_types.cmi odoc_text.cmi odoc_see_lexer.cmo \
odoc_parser.cmi odoc_misc.cmi odoc_messages.cmo odoc_lexer.cmo \
odoc_global.cmi odoc_cross.cmi odoc_comments_global.cmi odoc_comments.cmi
odoc_comments.cmx: odoc_types.cmx odoc_text.cmx odoc_see_lexer.cmx \
odoc_parser.cmx odoc_misc.cmx odoc_messages.cmx odoc_lexer.cmx \
odoc_global.cmx odoc_cross.cmx odoc_comments_global.cmx odoc_comments.cmi
-odoc_comments_global.cmo: odoc_comments_global.cmi
-odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_config.cmo: ../utils/config.cmi odoc_config.cmi
odoc_config.cmx: ../utils/config.cmx odoc_config.cmi
odoc_cross.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_search.cmi \
odoc_scan.cmo odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
odoc_misc.cmi odoc_messages.cmo odoc_exception.cmo odoc_class.cmo \
- odoc_cross.cmi
+ odoc_args.cmi odoc_cross.cmi
odoc_cross.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_search.cmx \
odoc_scan.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx odoc_class.cmx \
- odoc_cross.cmi
+ odoc_args.cmx odoc_cross.cmi
odoc_dag2html.cmo: odoc_info.cmi odoc_dag2html.cmi
odoc_dag2html.cmx: odoc_info.cmx odoc_dag2html.cmi
odoc_dep.cmo: ../parsing/parsetree.cmi odoc_type.cmo odoc_print.cmi \
@@ -80,10 +74,10 @@ odoc_dep.cmx: ../parsing/parsetree.cmi odoc_type.cmx odoc_print.cmx \
odoc_module.cmx ../tools/depend.cmx
odoc_dot.cmo: odoc_info.cmi
odoc_dot.cmx: odoc_info.cmx
-odoc_env.cmo: ../typing/types.cmi ../typing/printtyp.cmi ../typing/predef.cmi \
- ../typing/path.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
-odoc_env.cmx: ../typing/types.cmx ../typing/printtyp.cmx ../typing/predef.cmx \
- ../typing/path.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
+odoc_env.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
+ odoc_print.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
+odoc_env.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
+ odoc_print.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
odoc_exception.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_exception.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_global.cmo: ../utils/clflags.cmi odoc_global.cmi
@@ -92,18 +86,18 @@ odoc_html.cmo: odoc_text.cmi odoc_ocamlhtml.cmo odoc_messages.cmo \
odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
odoc_html.cmx: odoc_text.cmx odoc_ocamlhtml.cmx odoc_messages.cmx \
odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
-odoc_info.cmo: ../typing/printtyp.cmi odoc_value.cmo odoc_types.cmi \
- odoc_type.cmo odoc_text.cmi odoc_str.cmi odoc_search.cmi odoc_scan.cmo \
- odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
- odoc_misc.cmi odoc_messages.cmo odoc_global.cmi odoc_exception.cmo \
- odoc_dep.cmo odoc_config.cmi odoc_comments.cmi odoc_class.cmo \
- odoc_args.cmi odoc_analyse.cmi odoc_info.cmi
-odoc_info.cmx: ../typing/printtyp.cmx odoc_value.cmx odoc_types.cmx \
- odoc_type.cmx odoc_text.cmx odoc_str.cmx odoc_search.cmx odoc_scan.cmx \
- odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
- odoc_misc.cmx odoc_messages.cmx odoc_global.cmx odoc_exception.cmx \
- odoc_dep.cmx odoc_config.cmx odoc_comments.cmx odoc_class.cmx \
- odoc_args.cmx odoc_analyse.cmx odoc_info.cmi
+odoc_info.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_text.cmi \
+ odoc_str.cmi odoc_search.cmi odoc_scan.cmo odoc_print.cmi \
+ odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_misc.cmi \
+ odoc_messages.cmo odoc_global.cmi odoc_exception.cmo odoc_dep.cmo \
+ odoc_config.cmi odoc_comments.cmi odoc_class.cmo odoc_args.cmi \
+ odoc_analyse.cmi odoc_info.cmi
+odoc_info.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_text.cmx \
+ odoc_str.cmx odoc_search.cmx odoc_scan.cmx odoc_print.cmx \
+ odoc_parameter.cmx odoc_name.cmx odoc_module.cmx odoc_misc.cmx \
+ odoc_messages.cmx odoc_global.cmx odoc_exception.cmx odoc_dep.cmx \
+ odoc_config.cmx odoc_comments.cmx odoc_class.cmx odoc_args.cmx \
+ odoc_analyse.cmx odoc_info.cmi
odoc_latex.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_latex_style.cmo \
odoc_info.cmi
odoc_latex.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_latex_style.cmx \
@@ -130,6 +124,14 @@ odoc_misc.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
odoc_misc.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
odoc_types.cmx odoc_messages.cmx ../parsing/longident.cmx \
../typing/ctype.cmx ../typing/btype.cmx odoc_misc.cmi
+odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
+ odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
+ odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
+ ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
+odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
+ odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
+ odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
+ ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_module.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_type.cmo odoc_name.cmi odoc_exception.cmo odoc_class.cmo
odoc_module.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
@@ -150,8 +152,12 @@ odoc_parameter.cmo: ../typing/types.cmi odoc_types.cmi
odoc_parameter.cmx: ../typing/types.cmx odoc_types.cmx
odoc_parser.cmo: odoc_types.cmi odoc_comments_global.cmi odoc_parser.cmi
odoc_parser.cmx: odoc_types.cmx odoc_comments_global.cmx odoc_parser.cmi
-odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_print.cmi
-odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_print.cmi
+odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi \
+ ../typing/outcometree.cmi ../typing/oprint.cmi odoc_types.cmi \
+ odoc_type.cmo odoc_misc.cmi odoc_print.cmi
+odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx \
+ ../typing/outcometree.cmi ../typing/oprint.cmx odoc_types.cmx \
+ odoc_type.cmx odoc_misc.cmx odoc_print.cmi
odoc_scan.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_scan.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_module.cmx \
@@ -169,42 +175,44 @@ odoc_sig.cmo: ../typing/types.cmi ../typing/typedtree.cmi ../typing/path.cmi \
odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
odoc_misc.cmi odoc_messages.cmo odoc_merge.cmi odoc_global.cmi \
odoc_exception.cmo odoc_env.cmi odoc_class.cmo odoc_args.cmi \
- ../utils/misc.cmi ../parsing/location.cmi ../typing/btype.cmi \
- ../parsing/asttypes.cmi odoc_sig.cmi
+ ../utils/misc.cmi ../parsing/longident.cmi ../parsing/location.cmi \
+ ../typing/btype.cmi ../parsing/asttypes.cmi odoc_sig.cmi
odoc_sig.cmx: ../typing/types.cmx ../typing/typedtree.cmx ../typing/path.cmx \
../parsing/parsetree.cmi odoc_value.cmx odoc_types.cmx odoc_type.cmx \
odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_merge.cmx odoc_global.cmx \
odoc_exception.cmx odoc_env.cmx odoc_class.cmx odoc_args.cmx \
- ../utils/misc.cmx ../parsing/location.cmx ../typing/btype.cmx \
- ../parsing/asttypes.cmi odoc_sig.cmi
-odoc_str.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_value.cmo \
- odoc_type.cmo odoc_print.cmi odoc_name.cmi odoc_misc.cmi \
- odoc_messages.cmo odoc_exception.cmo odoc_class.cmo odoc_str.cmi
-odoc_str.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_value.cmx \
- odoc_type.cmx odoc_print.cmx odoc_name.cmx odoc_misc.cmx \
- odoc_messages.cmx odoc_exception.cmx odoc_class.cmx odoc_str.cmi
+ ../utils/misc.cmx ../parsing/longident.cmx ../parsing/location.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi odoc_sig.cmi
+odoc_str.cmo: ../typing/types.cmi odoc_value.cmo odoc_type.cmo odoc_print.cmi \
+ odoc_name.cmi odoc_misc.cmi odoc_messages.cmo odoc_exception.cmo \
+ odoc_class.cmo odoc_str.cmi
+odoc_str.cmx: ../typing/types.cmx odoc_value.cmx odoc_type.cmx odoc_print.cmx \
+ odoc_name.cmx odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx \
+ odoc_class.cmx odoc_str.cmi
odoc_test.cmo: odoc_info.cmi
odoc_test.cmx: odoc_info.cmx
odoc_texi.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_info.cmi
odoc_texi.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_info.cmx
+odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
+odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text.cmo: odoc_types.cmi odoc_text_parser.cmi odoc_text_lexer.cmo \
odoc_text.cmi
odoc_text.cmx: odoc_types.cmx odoc_text_parser.cmx odoc_text_lexer.cmx \
odoc_text.cmi
-odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
-odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text_parser.cmo: odoc_types.cmi odoc_misc.cmi odoc_text_parser.cmi
odoc_text_parser.cmx: odoc_types.cmx odoc_misc.cmx odoc_text_parser.cmi
odoc_to_text.cmo: odoc_messages.cmo odoc_info.cmi
odoc_to_text.cmx: odoc_messages.cmx odoc_info.cmx
-odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
-odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
+odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi \
+ ../parsing/asttypes.cmi
+odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx \
+ ../parsing/asttypes.cmi
odoc_types.cmo: odoc_messages.cmo odoc_types.cmi
odoc_types.cmx: odoc_messages.cmx odoc_types.cmi
-odoc_value.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_types.cmi \
+odoc_value.cmo: ../typing/types.cmi odoc_types.cmi odoc_print.cmi \
odoc_parameter.cmo odoc_name.cmi
-odoc_value.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_types.cmx \
+odoc_value.cmx: ../typing/types.cmx odoc_types.cmx odoc_print.cmx \
odoc_parameter.cmx odoc_name.cmx
odoc_analyse.cmi: odoc_module.cmo odoc_args.cmi
odoc_args.cmi: odoc_types.cmi odoc_module.cmo
@@ -215,14 +223,14 @@ odoc_cross.cmi: odoc_types.cmi odoc_module.cmo
odoc_dag2html.cmi: odoc_info.cmi
odoc_env.cmi: ../typing/types.cmi odoc_name.cmi
odoc_info.cmi: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
- odoc_type.cmo odoc_search.cmi odoc_parameter.cmo odoc_module.cmo \
- odoc_exception.cmo odoc_class.cmo
+ odoc_type.cmo odoc_search.cmi odoc_parameter.cmo odoc_name.cmi \
+ odoc_module.cmo odoc_exception.cmo odoc_class.cmo ../parsing/asttypes.cmi
odoc_merge.cmi: odoc_types.cmi odoc_module.cmo
odoc_misc.cmi: ../typing/types.cmi odoc_types.cmi ../parsing/longident.cmi
odoc_name.cmi: ../typing/path.cmi ../parsing/longident.cmi \
../typing/ident.cmi
odoc_parser.cmi: odoc_types.cmi
-odoc_print.cmi: ../typing/types.cmi
+odoc_print.cmi: ../typing/types.cmi odoc_types.cmi odoc_type.cmo
odoc_search.cmi: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_sig.cmi: ../typing/types.cmi ../parsing/parsetree.cmi odoc_types.cmi \
diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile
index c181142..3749001 100644
--- a/ocamldoc/Makefile
+++ b/ocamldoc/Makefile
@@ -81,12 +81,12 @@ CMOFILES= odoc_config.cmo \
odoc_text.cmo\
odoc_name.cmo\
odoc_parameter.cmo\
+ odoc_print.cmo \
odoc_value.cmo\
odoc_type.cmo\
odoc_exception.cmo\
odoc_class.cmo\
odoc_module.cmo\
- odoc_print.cmo \
odoc_str.cmo\
odoc_args.cmo\
odoc_comments_global.cmo\
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index efee6ea..b1ebdfa 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -1115,6 +1115,13 @@ module Analyser =
new_env name_comment_list
tt_type_decl.Types.type_kind
in
+ let tec = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (begin Sig.get_tec ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum
+ end, None)
+ in
let new_end = loc_end + maybe_more in
let t =
{
@@ -1133,6 +1140,7 @@ module Analyser =
(match tt_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tmc = tec;
ty_loc = { loc_impl = Some (!file_name, loc_start) ; loc_inter = None } ;
ty_code =
(
@@ -1343,8 +1351,7 @@ module Analyser =
in
(0, new_env2, [ Element_module_type mt ])
- | Parsetree.Pstr_open longident ->
- (* A VOIR : enrichir l'environnement quand open ? *)
+ | Parsetree.Pstr_open lid ->
let ele_comments = match comment_opt with
None -> []
| Some i ->
@@ -1352,7 +1359,17 @@ module Analyser =
None -> []
| Some t -> [Element_module_comment t]
in
- (0, env, ele_comments)
+ let name = (String.concat "." (Longident.flatten lid)) in
+ begin try match (Typedtree_search.search_module table name).Typedtree.mod_type
+ with Tmty_signature signat ->
+ let full_name = Odoc_env.full_module_name env name in
+ let new_env = Odoc_env.add_signature env full_name signat in
+ (0, new_env, ele_comments)
+ | _ -> (0, env, ele_comments)
+ with Not_found -> (0, env, ele_comments)
+ (* XXX: this may be because it is an external module,
+ * so how do we get its signature? *)
+ end
| Parsetree.Pstr_class class_decl_list ->
(* we start by extending the environment *)
@@ -1504,7 +1521,8 @@ module Analyser =
ma_module = None ; } }
| (Parsetree.Pmod_structure p_structure, Typedtree.Tmod_structure tt_structure) ->
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start
+ pos_end p_structure tt_structure in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1598,7 +1616,8 @@ module Analyser =
(* needed for recursive modules *)
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_structure + Typedtree.Tmod_constraint "^module_name);
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start pos_end
+ p_structure tt_structure in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1652,7 +1671,8 @@ module Analyser =
let (len,info_opt) = My_ir.first_special !file_name !file in
(* we must complete the included modules *)
- let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file) parsetree tree_structure in
+ let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file)
+ parsetree tree_structure in
let included_modules_from_tt = tt_get_included_module_list tree_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
let kind = Module_struct elements2 in
diff --git a/ocamldoc/odoc_cross.ml b/ocamldoc/odoc_cross.ml
index 6570e9a..3c37583 100644
--- a/ocamldoc/odoc_cross.ml
+++ b/ocamldoc/odoc_cross.ml
@@ -898,6 +898,137 @@ and assoc_comments_type module_list t =
(fun rf -> rf.rf_text <- ao (assoc_comments_text parent module_list) rf.rf_text)
fl
);
+ let rec assoc_tmc = function
+ Tec_list l -> List.iter assoc_tmc l
+ | Tec_variant {tec_variant_labels=labels;
+ tec_variant_nested=nested} ->
+ Hashtbl.iter
+ begin fun lbl buc ->
+ buc.tec_variant_coms <-
+ assoc_comments_text parent module_list
+ buc.tec_variant_coms;
+ assoc_tmc buc.tec_variant_tec
+ end labels
+ in
+ let fail_on_different_types () =
+ if not !Odoc_args.inverse_merge_ml_mli
+ then raise (Failure (Odoc_messages.different_types t.ty_name))
+ in
+ let has_merge_description_option =
+ List.mem Merge_description !Odoc_args.merge_options in
+ (* TIP: with Vim the debugging messages below are easily navigable
+ * with the '%' key and set fmr=[,] plus set fdm=marker *)
+ let rec merge_labels
+ ?(strict = true)
+ ?(glob_com: Odoc_types.text = [])
+ (tec, tec') =
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: [\n";
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)print_tec tec';
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ begin match tec, tec' with
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> merge_labels (x, y)) l l';
+ | (Tec_variant buc as tec),
+ (Tec_variant buc' as tec') ->
+ complete_labels tec;
+ complete_labels tec';
+ Hashtbl.iter
+ begin fun lbl buc' ->
+ let (@) l1 l2 = (* avoid useless list traversal *)
+ if l2 = [] then l1 else l1 @ l2
+ in try let buc = Hashtbl.find buc.tec_variant_labels lbl in
+ (* both types have the same label present: merge comments *)
+ let coms =
+ if has_merge_description_option
+ || buc.tec_variant_coms = []
+ then buc'.tec_variant_coms else []
+ in buc.tec_variant_coms <- buc.tec_variant_coms @ coms;
+ let glob_com =
+ if has_merge_description_option
+ || buc.tec_variant_glob_com = []
+ then buc'.tec_variant_glob_com @ glob_com else glob_com
+ in buc.tec_variant_glob_com <- buc.tec_variant_glob_com @ glob_com;
+ merge_labels (buc.tec_variant_tec, buc'.tec_variant_tec)
+ with Not_found ->
+ if strict
+ then fail_on_different_types ()
+ else begin
+ (* we are merging a nested p. v. type,
+ * which brings a new label *)
+ let buc' = {buc' with tec_variant_tec=clone_tec buc'.tec_variant_tec} in
+ buc'.tec_variant_coms <- buc'.tec_variant_coms;
+ buc'.tec_variant_glob_com <- glob_com;
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: add=%s\n" lbl;
+ Hashtbl.add buc.tec_variant_labels lbl buc'
+ end;
+ end buc'.tec_variant_labels;
+ | _ -> fail_on_different_types ()
+ end;
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)print_tec tec';
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: ]\n"
+
+ and complete_labels tec =
+ (*DEBUG*)Printf.fprintf stderr "complete_labels: [\n";
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ begin match tec with
+ Tec_list l -> ()
+ | Tec_variant buc as tec ->
+ (* merge the type expression comments pointed
+ * by [buc.tec_variant_nested] within [tec] *)
+ let q = Queue.create () in
+ Hashtbl.iter begin fun name glob_com ->
+ (*DEBUG*)Printf.fprintf stderr "fetching: [ name=%s\n" name;
+ (* Retrieve comments of nested p. v. types *)
+ ignore (List.exists
+ (function Odoc_search.Res_type t ->
+ (match t.ty_tmc with None -> true
+ | Some (tec', None) ->
+ (*DEBUG*)Printf.fprintf stderr "complete: name=%s\n" name;
+ complete_labels tec';
+ Queue.add (name, tec', glob_com) q;
+ true
+ | Some (tec', Some tec'') ->
+ (*DEBUG*)Printf.fprintf stderr "merge: trig name=%s\n" name;
+ merge_labels (tec', tec'');
+ (*DEBUG*)Printf.fprintf stderr "complete: name=%s\n" name;
+ complete_labels tec';
+ Queue.add (name, tec', glob_com) q;
+ true)
+ | _ -> false)
+ (get_known_elements name));
+ (*DEBUG*)Printf.fprintf stderr "fetching: ] name=%s\n" name;
+ end buc.tec_variant_nested;
+ Hashtbl.clear buc.tec_variant_nested;
+ (* now since the hashtable is empty,
+ * all further [complete_labels] on this tec,
+ * will return immediately. *)
+ (* still we have merges to do *)
+ Queue.iter (fun (name, tec', glob_com) ->
+ (*DEBUG*)Printf.fprintf stderr "merge: queue name=%s glob=%s\n" name
+ (*DEBUG*) (String.concat " " (List.map (function Odoc_types.Raw s -> s | _ -> "") glob_com));
+ merge_labels (tec, tec') ~glob_com ~strict: false) q;
+ end;
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)Printf.fprintf stderr "complete_labels: ]\n";
+ in
+ begin match t.ty_tmc with None -> ()
+ | Some (tec, None) ->
+ complete_labels tec;
+ assoc_tmc tec
+ | Some (tec, Some tec') ->
+ t.ty_tmc <- Some (tec, None);
+ (*DEBUG*)Printf.fprintf stderr "cross: [ name=%s\n" t.ty_name;
+ merge_labels (tec, tec');
+ assoc_tmc tec;
+ (*DEBUG*)Printf.fprintf stderr "cross: ] name=%s\n" t.ty_name;
+ end;
t
and assoc_comments_attribute module_list a =
diff --git a/ocamldoc/odoc_env.ml b/ocamldoc/odoc_env.ml
index ed9fb26..0865f8d 100644
--- a/ocamldoc/odoc_env.ml
+++ b/ocamldoc/odoc_env.ml
@@ -181,7 +181,7 @@ let subst_type env t =
print_env_types env ;
print_newline ();
*)
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
let deja_vu = ref [] in
let rec iter t =
if List.memq t !deja_vu then () else begin
diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml
index f34ad5e..2f0714c 100644
--- a/ocamldoc/odoc_html.ml
+++ b/ocamldoc/odoc_html.ml
@@ -1098,11 +1098,27 @@ class html =
s2
(** Print html code to display a [Types.type_expr]. *)
- method html_of_type_expr b m_name t =
- let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_type_expr t) in
- let s2 = newline_to_indented_br s in
+ method html_of_type_expr ?tec b m_name t =
+ let str_of_com coms =
+ let b = Buffer.create 42 in
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ bs b "<code>";
+ bs b "(*";
+ bs b "</code></td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ self#html_of_text b coms;
+ bs b "</td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
+ bs b "<code>";
+ bs b "*)";
+ bs b "</code></td>";
+ Buffer.contents b in
+ let str_of_ident =
+ self#create_fully_qualified_idents_links m_name in
+ let s = Odoc_info.remove_ending_newline
+ (Odoc_info.string_of_type_expr t ?tec ~str_of_com ~str_of_ident) in
bs b "<code class=\"type\">";
- bs b (self#create_fully_qualified_idents_links m_name s2);
+ bs b (newline_to_indented_br s);
bs b "</code>"
(** Print html code to display a [Types.type_expr list]. *)
@@ -1372,7 +1388,8 @@ class html =
None -> ()
| Some typ ->
bs b "= ";
- self#html_of_type_expr b father typ;
+ self#html_of_type_expr b father typ
+ ?tec: (match t.ty_tmc with Some (tec, _) -> Some tec | _ -> None);
bs b " "
);
(match t.ty_kind with
@@ -1814,7 +1831,8 @@ class html =
(Naming.type_target
{ ty_name = c.cl_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
@@ -1861,7 +1879,8 @@ class html =
(Naming.type_target
{ ty_name = ct.clt_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
diff --git a/ocamldoc/odoc_info.ml b/ocamldoc/odoc_info.ml
index 65735fd..3305bab 100644
--- a/ocamldoc/odoc_info.ml
+++ b/ocamldoc/odoc_info.ml
@@ -113,11 +113,11 @@ let dump_modules = Odoc_analyse.dump_modules
let load_modules = Odoc_analyse.load_modules
-let reset_type_names = Printtyp.reset
+let reset_type_names = Odoc_print.reset
let string_of_variance t (co,cn) = Odoc_str.string_of_variance t (co, cn)
-let string_of_type_expr t = Odoc_print.string_of_type_expr t
+let string_of_type_expr = Odoc_print.string_of_type_expr
let string_of_class_params = Odoc_str.string_of_class_params
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index e3638a7..0e453bf 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -212,6 +212,29 @@ module Type :
| Type_record of record_field list * bool
(** fields * bool *)
+ (** Type expression's comments *)
+ type tec = Odoc_type.tec =
+ Tec_variant of tec_variant_buc
+ (** comments for a polimorphic variant expression *)
+ | Tec_list of tec list
+ (** orthogonal types. Note that [Tec_list []] can be used *)
+ and tec_variant_buc = Odoc_type.tec_variant_buc =
+ { tec_variant_labels : (Asttypes.label, tec_variant_lbl_buc) Hashtbl.t;
+ (** the labels textually present in a p. v. type expression *)
+ mutable tec_variant_nested : (Odoc_name.t, Odoc_types.text) Hashtbl.t
+ (** the nested p. v. types textually present int a p.v. type expression,
+ and the global comments associated *) }
+ and tec_variant_lbl_buc = Odoc_type.tec_variant_lbl_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ (** the comments of a label *)
+ mutable tec_variant_glob_com: Odoc_types.text;
+ (** the global comment of a label *)
+ tec_variant_tec: tec
+ (** the comments of the label's data *) }
+
+ val clone_tec : tec -> tec
+ (*DEBUG*)val print_tec : ?s: string -> tec -> unit
+
(** Representation of a type. *)
type t_type = Odoc_type.t_type =
{
@@ -220,7 +243,11 @@ module Type :
ty_parameters : (Types.type_expr * bool * bool) list ;
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind ; (** Type kind. *)
- ty_manifest : Types.type_expr option; (** Type manifest. *)
+ ty_manifest : Types.type_expr option ; (** Type manifest. *)
+ mutable ty_tmc : (tec * tec option) option;
+ (** Type manifest's comments and another one to be merge within.
+ This second [tec] is used to carry ml's [tec] between,
+ the merging time and the cross referencing time *)
mutable ty_loc : location ;
mutable ty_code : string option;
}
@@ -599,7 +626,11 @@ val reset_type_names : unit -> unit
val string_of_variance : Type.t_type -> (bool * bool) -> string
(** This function returns a string representing a Types.type_expr. *)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ Types.type_expr -> string
(** @return a string to display the parameters of the given class,
in the same form as the compiler. *)
diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml
index 851884a..01ea52e 100644
--- a/ocamldoc/odoc_merge.ml
+++ b/ocamldoc/odoc_merge.ml
@@ -191,8 +191,13 @@ let merge_types merge_options mli ml =
mli.ty_info <- merge_info_opt merge_options mli.ty_info ml.ty_info;
mli.ty_loc <- { mli.ty_loc with loc_impl = ml.ty_loc.loc_impl } ;
mli.ty_code <- (match mli.ty_code with None -> ml.ty_code | _ -> mli.ty_code) ;
-
- match mli.ty_kind, ml.ty_kind with
+ let fail_on_different_types () =
+ if not !Odoc_args.inverse_merge_ml_mli
+ then raise (Failure (Odoc_messages.different_types mli.ty_name))
+ in
+ let has_merge_description_option =
+ List.mem Merge_description merge_options in
+ begin match mli.ty_kind, ml.ty_kind with
Type_abstract, _ ->
()
@@ -209,18 +214,13 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
cons.vc_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
@@ -237,26 +237,25 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
record.rf_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
- | _ ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ | _ -> fail_on_different_types ()
+ end;
+ begin match mli.ty_tmc, ml.ty_tmc with
+ None, None
+ | Some _, None -> ()
+ | None, Some _ -> mli.ty_tmc <- ml.ty_tmc
+ | Some (mli_tec, _), Some (ml_tec, _) ->
+ mli.ty_tmc <- Some (mli_tec, Some ml_tec)
+ end
(** Merge of two param_info, one from a .mli, one from a .ml.
The text fields are not handled but will be recreated from the
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index 6e4afc7..aeb9ffe 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -36,12 +36,234 @@ let _ =
let (modtype_fmt, flush_modtype_fmt) = new_fmt ()
+module Odoc_oprint =
+ struct
+ open Odoc_type
+ open Format
+ open Outcometree
+ let print_ident
+ ~str_of_ident
+ ppf x =
+ let buf = Buffer.create 12 in
+ let rec aux = function
+ Oide_ident s -> Buffer.add_string buf s
+ | Oide_dot (id, s) ->
+ aux id;
+ Buffer.add_string buf ".";
+ Buffer.add_string buf s
+ | Oide_apply (id1, id2) ->
+ aux id1;
+ Buffer.add_string buf "(";
+ aux id2;
+ Buffer.add_string buf ")"
+ in aux x;
+ fprintf ppf "%s" (str_of_ident (Buffer.contents buf))
-let string_of_type_expr t =
+ let rec print_list_init pr sep ppf =
+ function
+ [] -> ()
+ | a :: l -> sep ppf; pr ppf a; print_list_init pr sep ppf l
+
+ let rec print_list pr sep ppf =
+ function
+ [] -> ()
+ | [a] -> pr ppf a
+ | a :: l -> pr ppf a; sep ppf; print_list pr sep ppf l
+
+ let pr_present =
+ print_list (fun ppf s -> fprintf ppf "`%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let pr_vars =
+ print_list (fun ppf s -> fprintf ppf "'%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let rec print_out_type
+ ?(tec = Tec_list [])
+ ?(str_of_com = Odoc_misc.string_of_text)
+ ?(str_of_ident = fun (x: string) -> x)
+ ppf =
+ function
+ | Otyp_alias (ty, s) ->
+ fprintf ppf "@[%a@ as '%s@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty s
+ | Otyp_poly (sl, ty) ->
+ fprintf ppf "@[<hov 2>%a.@ %a@]"
+ pr_vars sl
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
+ | ty ->
+ print_out_type_1 ppf ty ~tec ~str_of_com ~str_of_ident
+
+ and print_out_type_1 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_arrow (lab, ty1, ty2) ->
+ let tec1, tec2 = match tec with
+ Tec_list [x;y] -> x, y
+ | _ -> Tec_list [], Tec_list [] in
+ fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "")
+ (print_out_type_2 ~tec: tec1 ~str_of_com ~str_of_ident) ty1
+ (print_out_type_1 ~tec: tec2 ~str_of_com ~str_of_ident) ty2
+ | ty ->
+ print_out_type_2 ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_out_type_2 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_tuple tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
+ print_simple_out_type ~tec ~str_of_com ~str_of_ident ty
+ in fprintf ppf "@[<0>%a@]" (print_typlist print_elem " *") tyl
+ | ty ->
+ print_simple_out_type ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_simple_out_type ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_class (ng, id, tyl) ->
+ fprintf ppf "@[%a%s#%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (if ng then "_" else "")
+ (print_ident ~str_of_ident) id
+ | Otyp_constr (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
+ | Otyp_object (fields, rest) ->
+ fprintf ppf "@[<2>< %a >@]"
+ (print_fields rest ~tec ~str_of_com ~str_of_ident) fields
+ | Otyp_stuff s -> fprintf ppf "%s" s
+ | Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s
+ | 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
+ let print_fields ~tec ~str_of_com ppf =
+ function
+ Ovar_fields fields ->
+ print_list
+ (print_row_field ~tec ~str_of_com ~str_of_ident)
+ (fun ppf -> fprintf ppf "@;<1 -2>| ")
+ ppf fields
+ | Ovar_name (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
+ in
+ 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 "? ")
+ (print_fields ~tec ~str_of_com) row_fields
+ print_present tags
+ | Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty ->
+ fprintf ppf "@[<1>(%a)@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
+ | Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> ()
+ and print_fields ~tec ~str_of_com ~str_of_ident rest ppf =
+ function
+ [] ->
+ begin match rest with
+ Some non_gen -> fprintf ppf "%s.." (if non_gen then "_" else "")
+ | None -> ()
+ end
+ | [s, t] ->
+ let tec = match tec with Tec_list [h] -> h
+ | _ -> Tec_list [] in
+ fprintf ppf "%s : %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t;
+ begin match rest with
+ Some _ -> fprintf ppf ";@ "
+ | None -> () end;
+ print_fields ~tec: (Tec_list [])
+ ~str_of_com ~str_of_ident rest ppf []
+ | (s, t) :: l ->
+ let tec, tec' = match tec with Tec_list (h::t) -> h, Tec_list t
+ | _ -> Tec_list [], Tec_list [] in
+ fprintf ppf "%s : %a;@ %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t
+ (print_fields rest ~tec: tec' ~str_of_com ~str_of_ident) l
+ and print_row_field
+ ~tec ~str_of_com
+ ~str_of_ident 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
+ let {Odoc_type.tec_variant_coms=coms;
+ tec_variant_glob_com=glob_com;
+ tec_variant_tec=tec} =
+ try match tec with
+ Tec_variant {Odoc_type.tec_variant_labels=labels} ->
+ Hashtbl.find labels l
+ | _ -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_glob_com=[];
+ tec_variant_tec=Tec_list []}
+ with Not_found -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_glob_com=[];
+ tec_variant_tec=Tec_list []} in
+ let coms =
+ if glob_com <> []
+ then coms @ (Odoc_types.Raw " " :: glob_com)
+ (** XXX: hardcoded separator *)
+ else coms in
+ let str_coms =
+ if coms <> []
+ then str_of_com coms
+ else "" in
+ fprintf ppf "@[<hv 2>`%s%t%a%s%s@]"
+ l pr_of
+ (print_typlist (print_out_type ~tec ~str_of_com ~str_of_ident) " &") tyl
+ (if coms = [] then "" else " ")
+ str_coms
+ 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 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ [] -> ()
+ | [ty1] ->
+ let tec = match tec with Tec_list (h::t) -> h
+ | _ -> Tec_list [] in
+ fprintf ppf "%a@ "
+ (print_simple_out_type ~tec ~str_of_com ~str_of_ident) ty1
+ | tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
+ print_out_type ~tec ~str_of_com ~str_of_ident ty
+ in fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_elem ",") tyl
+
+ let out_type = ref print_out_type
+ end
+
+let type_scheme
+ ?tec ?str_of_com ?str_of_ident
+ ?(b_reset_names = true)
+ ppf ty =
+ if b_reset_names then Printtyp.reset_names ();
+ let out_type'save = !Oprint.out_type in
+ Oprint.out_type := !Odoc_oprint.out_type
+ ?tec ?str_of_com ?str_of_ident;
+ Printtyp.type_sch ppf ty;
+ Oprint.out_type := out_type'save
+
+let mark_loops = Printtyp.mark_loops
+let reset = Printtyp.reset
+
+let string_of_type_expr
+ ?tec ?str_of_com ?str_of_ident t =
Printtyp.mark_loops t;
- Printtyp.type_scheme_max ~b_reset_names: false type_fmt t;
+ type_scheme type_fmt t
+ ?tec ?str_of_com ?str_of_ident
+ ~b_reset_names: false;
flush_type_fmt ()
exception Use_code of string
diff --git a/ocamldoc/odoc_print.mli b/ocamldoc/odoc_print.mli
index 3dcc8cf..ec30d28 100644
--- a/ocamldoc/odoc_print.mli
+++ b/ocamldoc/odoc_print.mli
@@ -11,11 +11,30 @@
(* $Id: odoc_print.mli,v 1.2 2004-03-26 09:09:50 guesdon Exp $ *)
+(** Customized [Printtyp.mark_loops] *)
+val mark_loops: Types.type_expr -> unit
+
+(** Customized [Printtyp.type_scheme] *)
+val type_scheme:
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ ?b_reset_names: bool ->
+ Format.formatter -> Types.type_expr -> unit
+
+(** Same as [Printtyp.reset] but for the above functions *)
+val reset: unit -> unit
+
+
(** Printing functions. *)
(** This function takes a Types.type_expr and returns a string.
It writes in and flushes [Format.str_formatter].*)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ Types.type_expr -> string
(** This function returns a string representing a [Types.module_type].
@param complete indicates if we must print complete signatures
diff --git a/ocamldoc/odoc_scan.ml b/ocamldoc/odoc_scan.ml
index b62e25b..ae49890 100644
--- a/ocamldoc/odoc_scan.ml
+++ b/ocamldoc/odoc_scan.ml
@@ -56,7 +56,7 @@ class scanner =
)
(Odoc_class.class_elements c)
- (** Scan of a class. Should not be overriden. It calls [scan_class_pre]
+ (** Scan of a class. Should not be overridden. It calls [scan_class_pre]
and if [scan_class_pre] returns [true], then it calls scan_class_elements.*)
method scan_class c = if self#scan_class_pre c then self#scan_class_elements c
@@ -82,7 +82,7 @@ class scanner =
)
(Odoc_class.class_type_elements ct)
- (** Scan of a class type. Should not be overriden. It calls [scan_class_type_pre]
+ (** Scan of a class type. Should not be overridden. It calls [scan_class_type_pre]
and if [scan_class_type_pre] returns [true], then it calls scan_class_type_elements.*)
method scan_class_type ct = if self#scan_class_type_pre ct then self#scan_class_type_elements ct
@@ -113,7 +113,7 @@ class scanner =
)
(Odoc_module.module_elements m)
- (** Scan of a module. Should not be overriden. It calls [scan_module_pre]
+ (** Scan of a module. Should not be overridden. It calls [scan_module_pre]
and if [scan_module_pre] returns [true], then it calls scan_module_elements.*)
method scan_module m = if self#scan_module_pre m then self#scan_module_elements m
@@ -144,7 +144,7 @@ class scanner =
)
(Odoc_module.module_type_elements mt)
- (** Scan of a module type. Should not be overriden. It calls [scan_module_type_pre]
+ (** Scan of a module type. Should not be overridden. It calls [scan_module_type_pre]
and if [scan_module_type_pre] returns [true], then it calls scan_module_type_elements.*)
method scan_module_type mt =
if self#scan_module_type_pre mt then self#scan_module_type_elements mt
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index fe4e223..0382f17 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -215,6 +215,105 @@ module Analyser =
in
(0, f name_mutable_type_list)
+ let get_tec
+ ~env ~name ~pos_end par_ct : tec =
+ let retrieve_comments pos_end loc dlen : Odoc_types.text =
+ (* retrieve the source from the start of the current variant
+ * to the end of the current type *)
+ let s = ref (get_string_of_file
+ (loc.Location.loc_start.Lexing.pos_cnum + !dlen)
+ (min loc.Location.loc_end.Lexing.pos_cnum pos_end)) in
+ begin let idx = ref 0 (* cut just before the following variant *)
+ in let cnt = ref 0 (* of the same type, by hand, since Ptyp_variant *)
+ in while incr idx; !idx < String.length !s (* has no Location.t *)
+ do match !s.[!idx] with
+ '[' -> incr cnt
+ | '|' when !cnt = 0 -> s := String.sub !s 0 !idx
+ | ']' -> decr cnt
+ | _ -> ()
+ done end;
+ (* try to extract a comment *)
+ let _, comment_opt =
+ My_ir.just_after_special !file_name !s in
+ dlen := !dlen + String.length !s;
+ match comment_opt with
+ Some {Odoc_types.i_desc = Some coms} -> coms
+ | _ -> []
+ in
+ let rec add_label
+ labels lbl buc : unit =
+ try let buc' = Hashtbl.find labels lbl in
+ (* the label is already present: merge *)
+ if buc'.tec_variant_coms <> []
+ then buc.tec_variant_coms <-
+ buc.tec_variant_coms @ buc'.tec_variant_coms;
+ let rec f = function
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> f (x, y)) l l'
+ | Tec_variant {tec_variant_labels=labels},
+ Tec_variant {tec_variant_labels=labels'} ->
+ Hashtbl.iter (add_label labels) labels'
+ | _ -> assert false
+ in f (buc.tec_variant_tec, buc'.tec_variant_tec)
+ with Not_found ->
+ (* this is a new label: insert it *)
+ Hashtbl.add labels lbl buc
+ in
+ let rec get ?(pstart = 0) ?(pdlen = ref 0) par_ct =
+ let loc = par_ct.Parsetree.ptyp_loc in
+ let dlen = ref 0 in
+ pdlen := !pdlen + loc.Location.loc_end.Lexing.pos_cnum - pstart;
+ let get ct = get ct ~pdlen: dlen
+ ~pstart: (loc.Location.loc_start.Lexing.pos_cnum + !dlen) in
+ let labels = Hashtbl.create 13 in
+ let nested = Hashtbl.create 13 in
+ begin match par_ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_any
+ | Parsetree.Ptyp_var _
+ | Parsetree.Ptyp_constr _ -> Tec_list []
+ | Parsetree.Ptyp_arrow (lbl, ct, ct') ->
+ Tec_list [get ct; get ct']
+ | Parsetree.Ptyp_tuple l
+ | Parsetree.Ptyp_class (_, l, _) ->
+ Tec_list (List.map get l)
+ | Parsetree.Ptyp_object l ->
+ Tec_list (List.map (fun ctf ->
+ match ctf.Parsetree.pfield_desc with
+ Parsetree.Pfield_var -> Tec_list []
+ | Parsetree.Pfield (_, ct) -> get ct) l)
+ | Parsetree.Ptyp_alias (ct, _)
+ | Parsetree.Ptyp_poly (_, ct) -> get ct
+ | Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
+ List.iter begin function
+ Parsetree.Rtag (lbl, b, l) ->
+ (* map the sub-types of the current variant *)
+ let l = List.map get l in
+ let tec = match l with [tec] -> tec (* not really a tuple *)
+ | _ -> Tec_list l in
+ let coms = retrieve_comments pos_end loc dlen in
+ add_label labels lbl ({tec_variant_coms=coms;
+ tec_variant_glob_com=[];
+ (* may be updated at merging time *)
+ tec_variant_tec=tec});
+ | Parsetree.Rinherit ct ->
+ match ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_constr (lid, _) ->
+ let glob_com = retrieve_comments pos_end loc dlen in
+ let name = Odoc_env.full_type_name env
+ (String.concat "." (Longident.flatten lid)) in
+ Hashtbl.replace nested name glob_com
+ | _ -> ()
+ end row_field_list;
+ Tec_variant {tec_variant_labels=labels;
+ tec_variant_nested=nested}
+ end
+ in
+ let tec = get par_ct in
+ (*DEBUG*)Printf.fprintf stderr "\nget_tec name=%s" name;
+ (*DEBUG*)print_tec tec ~s: "";
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ tec
+
let get_type_kind env name_comment_list type_kind =
match type_kind with
Types.Type_abstract ->
@@ -597,6 +696,12 @@ module Analyser =
let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in
let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum in
let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in
+ let tmc = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (begin get_tec ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum
+ end, None) in
(* associate the comments to each constructor and build the [Type.t_type] *)
let new_type =
{
@@ -614,6 +719,7 @@ module Analyser =
(match sig_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tmc = tmc;
ty_loc =
{ loc_impl = None ;
loc_inter = Some (!file_name,loc_start) ;
@@ -643,7 +749,7 @@ module Analyser =
let (maybe_more, types) = f ~first: true 0 pos_start_ele name_type_decl_list in
(maybe_more, new_env, types)
- | Parsetree.Psig_open _ -> (* A VOIR *)
+ | Parsetree.Psig_open lid ->
let ele_comments = match comment_opt with
None -> []
| Some i ->
@@ -651,7 +757,17 @@ module Analyser =
None -> []
| Some t -> [Element_module_comment t]
in
- (0, env, ele_comments)
+ let name = (String.concat "." (Longident.flatten lid)) in
+ begin try match Signature_search.search_module table name
+ with Tmty_signature signat ->
+ let full_name = Odoc_env.full_module_name env name in
+ let new_env = Odoc_env.add_signature env full_name signat in
+ (0, new_env, ele_comments)
+ | _ -> (0, env, ele_comments)
+ with Not_found -> (0, env, ele_comments)
+ (* XXX: this may be because it is an external module,
+ * so how do we get its signature? *)
+ end
| Parsetree.Psig_module (name, module_type) ->
let complete_name = Name.concat current_module_name name in
@@ -661,7 +777,8 @@ module Analyser =
with Not_found ->
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
- let module_kind = analyse_module_kind env complete_name module_type sig_module_type in
+ let module_kind = analyse_module_kind env complete_name module_type
+ sig_module_type in
let code_intf =
if !Odoc_args.keep_code then
let loc = module_type.Parsetree.pmty_loc in
@@ -752,7 +869,8 @@ module Analyser =
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
(* associate the comments to each constructor and build the [Type.t_type] *)
- let module_kind = analyse_module_kind new_env complete_name modtype sig_module_type in
+ let module_kind = analyse_module_kind new_env complete_name
+ modtype sig_module_type in
let code_intf =
if !Odoc_args.keep_code then
let loc = modtype.Parsetree.pmty_loc in
@@ -830,7 +948,8 @@ module Analyser =
in
let module_type_kind =
match sig_mtype_opt with
- | Some sig_mtype -> Some (analyse_module_type_kind env complete_name module_type sig_mtype)
+ | Some sig_mtype -> Some (analyse_module_type_kind env complete_name
+ module_type sig_mtype)
| None -> None
in
let mt =
@@ -1049,7 +1168,8 @@ module Analyser =
Types.Tmty_signature signat ->
let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
- let elements = analyse_parsetree env signat current_module_name pos_start pos_end ast in
+ let elements = analyse_parsetree env signat current_module_name
+ pos_start pos_end ast in
Module_type_struct elements
| _ ->
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
@@ -1092,7 +1212,8 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name
+ module_type2 sig_module_type in
Module_type_with (k, s)
)
@@ -1100,7 +1221,8 @@ module Analyser =
and analyse_module_kind env current_module_name module_type sig_module_type =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
- let k = analyse_module_type_kind env current_module_name module_type sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type
+ sig_module_type in
Module_with ( k, "" )
| Parsetree.Pmty_signature signature ->
@@ -1156,7 +1278,8 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type2
+ sig_module_type in
Module_with (k, s)
)
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index b41e913..8b21d9b 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -149,6 +149,14 @@ module Analyser :
Odoc_env.env -> (string * Odoc_types.info option) list ->
Types.type_kind -> Odoc_type.type_kind
+ (** Fetch the comments (only in polymorphic variants currently)
+ inside a [Parsetree.core_type]. *)
+ val get_tec :
+ env: Odoc_env.env ->
+ name: Odoc_name.t ->
+ pos_end: int ->
+ Parsetree.core_type -> Odoc_type.tec
+
(** This function merge two optional info structures. *)
val merge_infos :
Odoc_types.info option -> Odoc_types.info option ->
@@ -156,9 +164,11 @@ module Analyser :
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
val analyse_module_type_kind :
- Odoc_env.env -> Odoc_name.t ->
- Parsetree.module_type -> Types.module_type ->
- Odoc_module.module_type_kind
+ Odoc_env.env ->
+ Odoc_name.t ->
+ Parsetree.module_type ->
+ Types.module_type ->
+ Odoc_module.module_type_kind
(** Analysis of a Parsetree.class_type and a Types.class_type to
return a class_type_kind.*)
diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml
index e3295eb..e0c2af7 100644
--- a/ocamldoc/odoc_str.ml
+++ b/ocamldoc/odoc_str.ml
@@ -47,17 +47,17 @@ let raw_string_of_type_list sep type_list =
| Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false
in
let print_one_type variance t =
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
if need_parent t then
(
Format.fprintf fmt "(%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t;
+ Odoc_print.type_scheme ~b_reset_names: false fmt t;
Format.fprintf fmt ")"
)
else
(
Format.fprintf fmt "%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t
+ Odoc_print.type_scheme ~b_reset_names: false fmt t
)
in
begin match type_list with
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 26ae47b..784ed69 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -38,15 +38,101 @@ type type_kind =
| Type_record of record_field list * bool
(** fields * bool *)
+(** Type expression's comments *)
+type tec =
+ Tec_variant of tec_variant_buc
+ (** comments for a polimorphic variant expression *)
+ | Tec_list of tec list
+ (** orthogonal types. Note that [Tec_list []] can be used *)
+and tec_variant_buc =
+ { tec_variant_labels : (Asttypes.label, tec_variant_lbl_buc) Hashtbl.t;
+ (** the labels textually present in a p. v. type expression *)
+ mutable tec_variant_nested : (Odoc_name.t, Odoc_types.text) Hashtbl.t
+ (** the nested p. v. types textually present int a p.v. type expression,
+ and the global comments associated *) }
+and tec_variant_lbl_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ (** the comments of a label *)
+ mutable tec_variant_glob_com: Odoc_types.text;
+ (** the global comment of a label *)
+ tec_variant_tec: tec
+ (** the comments of the label's data *) }
+
+let rec clone_tec =
+ function
+ Tec_list l ->
+ Tec_list (List.map clone_tec l)
+ | Tec_variant buc ->
+ let labels = Hashtbl.create
+ (Hashtbl.length buc.tec_variant_labels) in
+ Hashtbl.iter
+ (fun lbl buc -> Hashtbl.add labels lbl
+ {buc with tec_variant_tec=clone_tec buc.tec_variant_tec})
+ buc.tec_variant_labels;
+ let nested = Hashtbl.create
+ (Hashtbl.length buc.tec_variant_nested) in
+ Hashtbl.iter (Hashtbl.add nested) buc.tec_variant_nested;
+ Tec_variant
+ { tec_variant_labels=labels;
+ tec_variant_nested=nested }
+
+(*DEBUG*)open Printf
+(*DEBUG*)let rec print_tec
+(*DEBUG*) ?(s="") =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) function
+(*DEBUG*) Tec_list l ->
+(*DEBUG*) fprintf o "\n%sTec_list [" s;
+(*DEBUG*) List.iter (print_tec ~s: (s ^ " ")) l;
+(*DEBUG*) fprintf o "]"
+(*DEBUG*) | Tec_variant
+(*DEBUG*) { tec_variant_labels=labels
+(*DEBUG*) ; tec_variant_nested=nested } ->
+(*DEBUG*) fprintf o "\n%sTec_variant" s;
+(*DEBUG*) print_labels labels ~s: (s ^ " ");
+(*DEBUG*) print_nested nested ~s: (s ^ " ")
+(*DEBUG*)and print_labels ~s =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) Hashtbl.iter begin fun lbl buc ->
+(*DEBUG*) fprintf o "\n%slbl=%s" s lbl;
+(*DEBUG*) if buc.tec_variant_coms <> []
+(*DEBUG*) then fprintf o "\n%scoms=%s" s
+(*DEBUG*) (string_of_com buc.tec_variant_coms);
+(*DEBUG*) if buc.tec_variant_glob_com <> []
+(*DEBUG*) then fprintf o "\n%sglob=%s" s
+(*DEBUG*) (string_of_com buc.tec_variant_glob_com);
+(*DEBUG*) if buc.tec_variant_tec <> Tec_list []
+(*DEBUG*) then begin
+(*DEBUG*) fprintf o "\n%stec=" s;
+(*DEBUG*) print_tec buc.tec_variant_tec
+(*DEBUG*) ~s: (s ^ " ")
+(*DEBUG*) end
+(*DEBUG*) end
+(*DEBUG*)and print_nested ~s =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) Hashtbl.iter begin fun name glob_com ->
+(*DEBUG*) fprintf o "\n%sname=%s" s name;
+(*DEBUG*) if glob_com <> []
+(*DEBUG*) then fprintf o "\n%sglob=%s" s (string_of_com glob_com)
+(*DEBUG*) end
+(*DEBUG*)and string_of_com com =
+(*DEBUG*) String.concat " "
+(*DEBUG*) (List.map (function Odoc_types.Raw s -> s | _ -> "") com)
+
(** Representation of a type. *)
type t_type = {
- ty_name : Name.t ;
- mutable ty_info : Odoc_types.info option ; (** optional user information *)
- ty_parameters : (Types.type_expr * bool * bool) list ;
+ ty_name : Name.t;
+ mutable ty_info : Odoc_types.info option; (** optional user information *)
+ ty_parameters : (Types.type_expr * bool * bool) list;
(** type parameters: (type, covariant, contravariant) *)
- ty_kind : type_kind ;
+ ty_kind : type_kind;
ty_manifest : Types.type_expr option; (** type manifest *)
- mutable ty_loc : Odoc_types.location ;
+ mutable ty_tmc : (tec * tec option) option;
+ (** type manifest's comments and another one to be merge within.
+ This second [tec] is used to carry ml's [tec] between,
+ the merging time and the cross referencing time *)
+ mutable ty_loc : Odoc_types.location;
mutable ty_code : string option;
- }
+ }
+
diff --git a/ocamldoc/odoc_value.ml b/ocamldoc/odoc_value.ml
index 29be7c5..fb8bbc5 100644
--- a/ocamldoc/odoc_value.ml
+++ b/ocamldoc/odoc_value.ml
@@ -102,7 +102,7 @@ let dummy_parameter_list typ =
'?' -> String.sub s 1 ((String.length s) - 1)
| _ -> s
in
- Printtyp.mark_loops typ;
+ Odoc_print.mark_loops typ;
let liste_param = parameter_list_from_arrows typ in
let rec iter (label, t) =
match t.Types.desc with
600a840ec9ae875aa8cb350122d919fbd8466e3d
diff --git a/ocamldoc/odoc_cross.ml b/ocamldoc/odoc_cross.ml
index 3c37583..11f30bb 100644
--- a/ocamldoc/odoc_cross.ml
+++ b/ocamldoc/odoc_cross.ml
@@ -782,9 +782,9 @@ and assoc_comments_module_kind parent_name module_list mk =
| Module_struct eles ->
Module_struct
(List.map (assoc_comments_module_element parent_name module_list) eles)
- | Module_alias _
- | Module_functor _ ->
- mk
+ | Module_alias _ -> mk
+ | Module_functor (params, mk1) ->
+ Module_functor (params, assoc_comments_module_kind parent_name module_list mk1)
| Module_apply (mk1, mk2) ->
Module_apply (assoc_comments_module_kind parent_name module_list mk1,
assoc_comments_module_kind parent_name module_list mk2)
@@ -921,6 +921,7 @@ and assoc_comments_type module_list t =
let rec merge_labels
?(strict = true)
?(glob_com: Odoc_types.text = [])
+ ?(enforce_merge = has_merge_description_option)
(tec, tec') =
(*DEBUG*)Printf.fprintf stderr "merge_labels: [\n";
(*DEBUG*)print_tec tec;
@@ -941,12 +942,16 @@ and assoc_comments_type module_list t =
in try let buc = Hashtbl.find buc.tec_variant_labels lbl in
(* both types have the same label present: merge comments *)
let coms =
- if has_merge_description_option
+ if enforce_merge
|| buc.tec_variant_coms = []
- then buc'.tec_variant_coms else []
+ then if enforce_merge && buc'.tec_variant_coms <> []
+ then Odoc_types.Raw " " :: buc'.tec_variant_coms
+ (* XXX: hardcoded separator *)
+ else buc'.tec_variant_coms
+ else []
in buc.tec_variant_coms <- buc.tec_variant_coms @ coms;
let glob_com =
- if has_merge_description_option
+ if enforce_merge
|| buc.tec_variant_glob_com = []
then buc'.tec_variant_glob_com @ glob_com else glob_com
in buc.tec_variant_glob_com <- buc.tec_variant_glob_com @ glob_com;
@@ -973,9 +978,9 @@ and assoc_comments_type module_list t =
(*DEBUG*)Printf.fprintf stderr "merge_labels: ]\n"
and complete_labels tec =
- (*DEBUG*)Printf.fprintf stderr "complete_labels: [\n";
- (*DEBUG*)print_tec tec;
- (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)Printf.fprintf stderr "complete_labels: [\n";
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
begin match tec with
Tec_list l -> ()
| Tec_variant buc as tec ->
@@ -1012,7 +1017,7 @@ and assoc_comments_type module_list t =
Queue.iter (fun (name, tec', glob_com) ->
(*DEBUG*)Printf.fprintf stderr "merge: queue name=%s glob=%s\n" name
(*DEBUG*) (String.concat " " (List.map (function Odoc_types.Raw s -> s | _ -> "") glob_com));
- merge_labels (tec, tec') ~glob_com ~strict: false) q;
+ merge_labels (tec, tec') ~glob_com ~strict: false ~enforce_merge: true) q;
end;
(*DEBUG*)print_tec tec;
(*DEBUG*)Printf.fprintf stderr "\n";
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index 0e453bf..7d58907 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -215,7 +215,7 @@ module Type :
(** Type expression's comments *)
type tec = Odoc_type.tec =
Tec_variant of tec_variant_buc
- (** comments for a polimorphic variant expression *)
+ (** comments for a polymorphic variant expression *)
| Tec_list of tec list
(** orthogonal types. Note that [Tec_list []] can be used *)
and tec_variant_buc = Odoc_type.tec_variant_buc =
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index 0382f17..b3c8220 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -1242,7 +1242,7 @@ module Analyser =
(* if we're here something's wrong *)
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
)
- | Parsetree.Pmty_functor (_,pmodule_type2,module_type2) (* of string * module_type * module_type *) ->
+ | Parsetree.Pmty_functor (name,pmodule_type2,module_type2) (* of string * module_type * module_type *) ->
(
match sig_module_type with
Types.Tmty_functor (ident, param_module_type, body_module_type) ->
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 784ed69..d845be6 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -41,7 +41,7 @@ type type_kind =
(** Type expression's comments *)
type tec =
Tec_variant of tec_variant_buc
- (** comments for a polimorphic variant expression *)
+ (** comments for a polymorphic variant expression *)
| Tec_list of tec list
(** orthogonal types. Note that [Tec_list []] can be used *)
and tec_variant_buc =
diff --git a/ocamldoc/.depend b/ocamldoc/.depend
index 5e2196a..f96a754 100644
--- a/ocamldoc/.depend
+++ b/ocamldoc/.depend
@@ -1,11 +1,3 @@
-odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
- odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
- odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
- ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
-odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
- odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
- odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
- ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_analyse.cmo: ../utils/warnings.cmi ../typing/typetexp.cmi \
../typing/types.cmi ../typing/typemod.cmi ../typing/typedtree.cmi \
../typing/typedecl.cmi ../typing/typecore.cmi ../typing/typeclass.cmi \
@@ -41,37 +33,39 @@ odoc_ast.cmo: ../typing/types.cmi ../typing/typedtree.cmi \
odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_sig.cmi \
odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_messages.cmo \
odoc_global.cmi odoc_exception.cmo odoc_env.cmi odoc_class.cmo \
- odoc_args.cmi ../utils/misc.cmi ../parsing/location.cmi \
- ../typing/ident.cmi ../parsing/asttypes.cmi odoc_ast.cmi
+ odoc_args.cmi ../utils/misc.cmi ../parsing/longident.cmi \
+ ../parsing/location.cmi ../typing/ident.cmi ../parsing/asttypes.cmi \
+ odoc_ast.cmi
odoc_ast.cmx: ../typing/types.cmx ../typing/typedtree.cmx \
../typing/predef.cmx ../typing/path.cmx ../parsing/parsetree.cmi \
odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_sig.cmx \
odoc_parameter.cmx odoc_name.cmx odoc_module.cmx odoc_messages.cmx \
odoc_global.cmx odoc_exception.cmx odoc_env.cmx odoc_class.cmx \
- odoc_args.cmx ../utils/misc.cmx ../parsing/location.cmx \
- ../typing/ident.cmx ../parsing/asttypes.cmi odoc_ast.cmi
+ odoc_args.cmx ../utils/misc.cmx ../parsing/longident.cmx \
+ ../parsing/location.cmx ../typing/ident.cmx ../parsing/asttypes.cmi \
+ odoc_ast.cmi
odoc_class.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_parameter.cmo odoc_name.cmi
odoc_class.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
odoc_parameter.cmx odoc_name.cmx
+odoc_comments_global.cmo: odoc_comments_global.cmi
+odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_comments.cmo: odoc_types.cmi odoc_text.cmi odoc_see_lexer.cmo \
odoc_parser.cmi odoc_misc.cmi odoc_messages.cmo odoc_lexer.cmo \
odoc_global.cmi odoc_cross.cmi odoc_comments_global.cmi odoc_comments.cmi
odoc_comments.cmx: odoc_types.cmx odoc_text.cmx odoc_see_lexer.cmx \
odoc_parser.cmx odoc_misc.cmx odoc_messages.cmx odoc_lexer.cmx \
odoc_global.cmx odoc_cross.cmx odoc_comments_global.cmx odoc_comments.cmi
-odoc_comments_global.cmo: odoc_comments_global.cmi
-odoc_comments_global.cmx: odoc_comments_global.cmi
odoc_config.cmo: ../utils/config.cmi odoc_config.cmi
odoc_config.cmx: ../utils/config.cmx odoc_config.cmi
odoc_cross.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_search.cmi \
odoc_scan.cmo odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
odoc_misc.cmi odoc_messages.cmo odoc_exception.cmo odoc_class.cmo \
- odoc_cross.cmi
+ odoc_args.cmi odoc_cross.cmi
odoc_cross.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_search.cmx \
odoc_scan.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx odoc_class.cmx \
- odoc_cross.cmi
+ odoc_args.cmx odoc_cross.cmi
odoc_dag2html.cmo: odoc_info.cmi odoc_dag2html.cmi
odoc_dag2html.cmx: odoc_info.cmx odoc_dag2html.cmi
odoc_dep.cmo: ../parsing/parsetree.cmi odoc_type.cmo odoc_print.cmi \
@@ -80,10 +74,10 @@ odoc_dep.cmx: ../parsing/parsetree.cmi odoc_type.cmx odoc_print.cmx \
odoc_module.cmx ../tools/depend.cmx
odoc_dot.cmo: odoc_info.cmi
odoc_dot.cmx: odoc_info.cmx
-odoc_env.cmo: ../typing/types.cmi ../typing/printtyp.cmi ../typing/predef.cmi \
- ../typing/path.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
-odoc_env.cmx: ../typing/types.cmx ../typing/printtyp.cmx ../typing/predef.cmx \
- ../typing/path.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
+odoc_env.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
+ odoc_print.cmi odoc_name.cmi ../typing/btype.cmi odoc_env.cmi
+odoc_env.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
+ odoc_print.cmx odoc_name.cmx ../typing/btype.cmx odoc_env.cmi
odoc_exception.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
odoc_exception.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
odoc_global.cmo: ../utils/clflags.cmi odoc_global.cmi
@@ -92,18 +86,18 @@ odoc_html.cmo: odoc_text.cmi odoc_ocamlhtml.cmo odoc_messages.cmo \
odoc_info.cmi odoc_dag2html.cmi odoc_args.cmi
odoc_html.cmx: odoc_text.cmx odoc_ocamlhtml.cmx odoc_messages.cmx \
odoc_info.cmx odoc_dag2html.cmx odoc_args.cmx
-odoc_info.cmo: ../typing/printtyp.cmi odoc_value.cmo odoc_types.cmi \
- odoc_type.cmo odoc_text.cmi odoc_str.cmi odoc_search.cmi odoc_scan.cmo \
- odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
- odoc_misc.cmi odoc_messages.cmo odoc_global.cmi odoc_exception.cmo \
- odoc_dep.cmo odoc_config.cmi odoc_comments.cmi odoc_class.cmo \
- odoc_args.cmi odoc_analyse.cmi odoc_info.cmi
-odoc_info.cmx: ../typing/printtyp.cmx odoc_value.cmx odoc_types.cmx \
- odoc_type.cmx odoc_text.cmx odoc_str.cmx odoc_search.cmx odoc_scan.cmx \
- odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
- odoc_misc.cmx odoc_messages.cmx odoc_global.cmx odoc_exception.cmx \
- odoc_dep.cmx odoc_config.cmx odoc_comments.cmx odoc_class.cmx \
- odoc_args.cmx odoc_analyse.cmx odoc_info.cmi
+odoc_info.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_text.cmi \
+ odoc_str.cmi odoc_search.cmi odoc_scan.cmo odoc_print.cmi \
+ odoc_parameter.cmo odoc_name.cmi odoc_module.cmo odoc_misc.cmi \
+ odoc_messages.cmo odoc_global.cmi odoc_exception.cmo odoc_dep.cmo \
+ odoc_config.cmi odoc_comments.cmi odoc_class.cmo odoc_args.cmi \
+ odoc_analyse.cmi odoc_info.cmi
+odoc_info.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_text.cmx \
+ odoc_str.cmx odoc_search.cmx odoc_scan.cmx odoc_print.cmx \
+ odoc_parameter.cmx odoc_name.cmx odoc_module.cmx odoc_misc.cmx \
+ odoc_messages.cmx odoc_global.cmx odoc_exception.cmx odoc_dep.cmx \
+ odoc_config.cmx odoc_comments.cmx odoc_class.cmx odoc_args.cmx \
+ odoc_analyse.cmx odoc_info.cmi
odoc_latex.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_latex_style.cmo \
odoc_info.cmi
odoc_latex.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_latex_style.cmx \
@@ -130,6 +124,14 @@ odoc_misc.cmo: ../typing/types.cmi ../typing/predef.cmi ../typing/path.cmi \
odoc_misc.cmx: ../typing/types.cmx ../typing/predef.cmx ../typing/path.cmx \
odoc_types.cmx odoc_messages.cmx ../parsing/longident.cmx \
../typing/ctype.cmx ../typing/btype.cmx odoc_misc.cmi
+odoc.cmo: ../typing/typedtree.cmi odoc_texi.cmo odoc_messages.cmo \
+ odoc_man.cmo odoc_latex.cmo odoc_info.cmi odoc_html.cmo odoc_global.cmi \
+ odoc_dot.cmo odoc_config.cmi odoc_args.cmi odoc_analyse.cmi \
+ ../utils/misc.cmi ../utils/config.cmi ../utils/clflags.cmi
+odoc.cmx: ../typing/typedtree.cmx odoc_texi.cmx odoc_messages.cmx \
+ odoc_man.cmx odoc_latex.cmx odoc_info.cmx odoc_html.cmx odoc_global.cmx \
+ odoc_dot.cmx odoc_config.cmx odoc_args.cmx odoc_analyse.cmx \
+ ../utils/misc.cmx ../utils/config.cmx ../utils/clflags.cmx
odoc_module.cmo: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
odoc_type.cmo odoc_name.cmi odoc_exception.cmo odoc_class.cmo
odoc_module.cmx: ../typing/types.cmx odoc_value.cmx odoc_types.cmx \
@@ -150,8 +152,12 @@ odoc_parameter.cmo: ../typing/types.cmi odoc_types.cmi
odoc_parameter.cmx: ../typing/types.cmx odoc_types.cmx
odoc_parser.cmo: odoc_types.cmi odoc_comments_global.cmi odoc_parser.cmi
odoc_parser.cmx: odoc_types.cmx odoc_comments_global.cmx odoc_parser.cmi
-odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_print.cmi
-odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_print.cmi
+odoc_print.cmo: ../typing/types.cmi ../typing/printtyp.cmi \
+ ../typing/outcometree.cmi ../typing/oprint.cmi odoc_types.cmi \
+ odoc_type.cmo odoc_misc.cmi odoc_print.cmi
+odoc_print.cmx: ../typing/types.cmx ../typing/printtyp.cmx \
+ ../typing/outcometree.cmi ../typing/oprint.cmx odoc_types.cmx \
+ odoc_type.cmx odoc_misc.cmx odoc_print.cmi
odoc_scan.cmo: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_scan.cmx: odoc_value.cmx odoc_types.cmx odoc_type.cmx odoc_module.cmx \
@@ -169,42 +175,44 @@ odoc_sig.cmo: ../typing/types.cmi ../typing/typedtree.cmi ../typing/path.cmi \
odoc_print.cmi odoc_parameter.cmo odoc_name.cmi odoc_module.cmo \
odoc_misc.cmi odoc_messages.cmo odoc_merge.cmi odoc_global.cmi \
odoc_exception.cmo odoc_env.cmi odoc_class.cmo odoc_args.cmi \
- ../utils/misc.cmi ../parsing/location.cmi ../typing/btype.cmi \
- ../parsing/asttypes.cmi odoc_sig.cmi
+ ../utils/misc.cmi ../parsing/longident.cmi ../parsing/location.cmi \
+ ../typing/btype.cmi ../parsing/asttypes.cmi odoc_sig.cmi
odoc_sig.cmx: ../typing/types.cmx ../typing/typedtree.cmx ../typing/path.cmx \
../parsing/parsetree.cmi odoc_value.cmx odoc_types.cmx odoc_type.cmx \
odoc_print.cmx odoc_parameter.cmx odoc_name.cmx odoc_module.cmx \
odoc_misc.cmx odoc_messages.cmx odoc_merge.cmx odoc_global.cmx \
odoc_exception.cmx odoc_env.cmx odoc_class.cmx odoc_args.cmx \
- ../utils/misc.cmx ../parsing/location.cmx ../typing/btype.cmx \
- ../parsing/asttypes.cmi odoc_sig.cmi
-odoc_str.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_value.cmo \
- odoc_type.cmo odoc_print.cmi odoc_name.cmi odoc_misc.cmi \
- odoc_messages.cmo odoc_exception.cmo odoc_class.cmo odoc_str.cmi
-odoc_str.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_value.cmx \
- odoc_type.cmx odoc_print.cmx odoc_name.cmx odoc_misc.cmx \
- odoc_messages.cmx odoc_exception.cmx odoc_class.cmx odoc_str.cmi
+ ../utils/misc.cmx ../parsing/longident.cmx ../parsing/location.cmx \
+ ../typing/btype.cmx ../parsing/asttypes.cmi odoc_sig.cmi
+odoc_str.cmo: ../typing/types.cmi odoc_value.cmo odoc_type.cmo odoc_print.cmi \
+ odoc_name.cmi odoc_misc.cmi odoc_messages.cmo odoc_exception.cmo \
+ odoc_class.cmo odoc_str.cmi
+odoc_str.cmx: ../typing/types.cmx odoc_value.cmx odoc_type.cmx odoc_print.cmx \
+ odoc_name.cmx odoc_misc.cmx odoc_messages.cmx odoc_exception.cmx \
+ odoc_class.cmx odoc_str.cmi
odoc_test.cmo: odoc_info.cmi
odoc_test.cmx: odoc_info.cmx
odoc_texi.cmo: odoc_to_text.cmo odoc_messages.cmo odoc_info.cmi
odoc_texi.cmx: odoc_to_text.cmx odoc_messages.cmx odoc_info.cmx
+odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
+odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text.cmo: odoc_types.cmi odoc_text_parser.cmi odoc_text_lexer.cmo \
odoc_text.cmi
odoc_text.cmx: odoc_types.cmx odoc_text_parser.cmx odoc_text_lexer.cmx \
odoc_text.cmi
-odoc_text_lexer.cmo: odoc_text_parser.cmi odoc_misc.cmi
-odoc_text_lexer.cmx: odoc_text_parser.cmx odoc_misc.cmx
odoc_text_parser.cmo: odoc_types.cmi odoc_misc.cmi odoc_text_parser.cmi
odoc_text_parser.cmx: odoc_types.cmx odoc_misc.cmx odoc_text_parser.cmi
odoc_to_text.cmo: odoc_messages.cmo odoc_info.cmi
odoc_to_text.cmx: odoc_messages.cmx odoc_info.cmx
-odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi
-odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx
+odoc_type.cmo: ../typing/types.cmi odoc_types.cmi odoc_name.cmi \
+ ../parsing/asttypes.cmi
+odoc_type.cmx: ../typing/types.cmx odoc_types.cmx odoc_name.cmx \
+ ../parsing/asttypes.cmi
odoc_types.cmo: odoc_messages.cmo odoc_types.cmi
odoc_types.cmx: odoc_messages.cmx odoc_types.cmi
-odoc_value.cmo: ../typing/types.cmi ../typing/printtyp.cmi odoc_types.cmi \
+odoc_value.cmo: ../typing/types.cmi odoc_types.cmi odoc_print.cmi \
odoc_parameter.cmo odoc_name.cmi
-odoc_value.cmx: ../typing/types.cmx ../typing/printtyp.cmx odoc_types.cmx \
+odoc_value.cmx: ../typing/types.cmx odoc_types.cmx odoc_print.cmx \
odoc_parameter.cmx odoc_name.cmx
odoc_analyse.cmi: odoc_module.cmo odoc_args.cmi
odoc_args.cmi: odoc_types.cmi odoc_module.cmo
@@ -215,14 +223,14 @@ odoc_cross.cmi: odoc_types.cmi odoc_module.cmo
odoc_dag2html.cmi: odoc_info.cmi
odoc_env.cmi: ../typing/types.cmi odoc_name.cmi
odoc_info.cmi: ../typing/types.cmi odoc_value.cmo odoc_types.cmi \
- odoc_type.cmo odoc_search.cmi odoc_parameter.cmo odoc_module.cmo \
- odoc_exception.cmo odoc_class.cmo
+ odoc_type.cmo odoc_search.cmi odoc_parameter.cmo odoc_name.cmi \
+ odoc_module.cmo odoc_exception.cmo odoc_class.cmo ../parsing/asttypes.cmi
odoc_merge.cmi: odoc_types.cmi odoc_module.cmo
odoc_misc.cmi: ../typing/types.cmi odoc_types.cmi ../parsing/longident.cmi
odoc_name.cmi: ../typing/path.cmi ../parsing/longident.cmi \
../typing/ident.cmi
odoc_parser.cmi: odoc_types.cmi
-odoc_print.cmi: ../typing/types.cmi
+odoc_print.cmi: ../typing/types.cmi odoc_types.cmi odoc_type.cmo
odoc_search.cmi: odoc_value.cmo odoc_types.cmi odoc_type.cmo odoc_module.cmo \
odoc_exception.cmo odoc_class.cmo
odoc_sig.cmi: ../typing/types.cmi ../parsing/parsetree.cmi odoc_types.cmi \
diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile
index c181142..3749001 100644
--- a/ocamldoc/Makefile
+++ b/ocamldoc/Makefile
@@ -81,12 +81,12 @@ CMOFILES= odoc_config.cmo \
odoc_text.cmo\
odoc_name.cmo\
odoc_parameter.cmo\
+ odoc_print.cmo \
odoc_value.cmo\
odoc_type.cmo\
odoc_exception.cmo\
odoc_class.cmo\
odoc_module.cmo\
- odoc_print.cmo \
odoc_str.cmo\
odoc_args.cmo\
odoc_comments_global.cmo\
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index efee6ea..b1ebdfa 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -1115,6 +1115,13 @@ module Analyser =
new_env name_comment_list
tt_type_decl.Types.type_kind
in
+ let tec = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (begin Sig.get_tec ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum
+ end, None)
+ in
let new_end = loc_end + maybe_more in
let t =
{
@@ -1133,6 +1140,7 @@ module Analyser =
(match tt_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tmc = tec;
ty_loc = { loc_impl = Some (!file_name, loc_start) ; loc_inter = None } ;
ty_code =
(
@@ -1343,8 +1351,7 @@ module Analyser =
in
(0, new_env2, [ Element_module_type mt ])
- | Parsetree.Pstr_open longident ->
- (* A VOIR : enrichir l'environnement quand open ? *)
+ | Parsetree.Pstr_open lid ->
let ele_comments = match comment_opt with
None -> []
| Some i ->
@@ -1352,7 +1359,17 @@ module Analyser =
None -> []
| Some t -> [Element_module_comment t]
in
- (0, env, ele_comments)
+ let name = (String.concat "." (Longident.flatten lid)) in
+ begin try match (Typedtree_search.search_module table name).Typedtree.mod_type
+ with Tmty_signature signat ->
+ let full_name = Odoc_env.full_module_name env name in
+ let new_env = Odoc_env.add_signature env full_name signat in
+ (0, new_env, ele_comments)
+ | _ -> (0, env, ele_comments)
+ with Not_found -> (0, env, ele_comments)
+ (* XXX: this may be because it is an external module,
+ * so how do we get its signature? *)
+ end
| Parsetree.Pstr_class class_decl_list ->
(* we start by extending the environment *)
@@ -1504,7 +1521,8 @@ module Analyser =
ma_module = None ; } }
| (Parsetree.Pmod_structure p_structure, Typedtree.Tmod_structure tt_structure) ->
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start
+ pos_end p_structure tt_structure in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1598,7 +1616,8 @@ module Analyser =
(* needed for recursive modules *)
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_structure + Typedtree.Tmod_constraint "^module_name);
- let elements = analyse_structure env complete_name pos_start pos_end p_structure tt_structure in
+ let elements = analyse_structure env complete_name pos_start pos_end
+ p_structure tt_structure in
(* we must complete the included modules *)
let included_modules_from_tt = tt_get_included_module_list tt_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
@@ -1652,7 +1671,8 @@ module Analyser =
let (len,info_opt) = My_ir.first_special !file_name !file in
(* we must complete the included modules *)
- let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file) parsetree tree_structure in
+ let elements = analyse_structure Odoc_env.empty mod_name len (String.length !file)
+ parsetree tree_structure in
let included_modules_from_tt = tt_get_included_module_list tree_structure in
let elements2 = replace_dummy_included_modules elements included_modules_from_tt in
let kind = Module_struct elements2 in
diff --git a/ocamldoc/odoc_cross.ml b/ocamldoc/odoc_cross.ml
index 6570e9a..11f30bb 100644
--- a/ocamldoc/odoc_cross.ml
+++ b/ocamldoc/odoc_cross.ml
@@ -782,9 +782,9 @@ and assoc_comments_module_kind parent_name module_list mk =
| Module_struct eles ->
Module_struct
(List.map (assoc_comments_module_element parent_name module_list) eles)
- | Module_alias _
- | Module_functor _ ->
- mk
+ | Module_alias _ -> mk
+ | Module_functor (params, mk1) ->
+ Module_functor (params, assoc_comments_module_kind parent_name module_list mk1)
| Module_apply (mk1, mk2) ->
Module_apply (assoc_comments_module_kind parent_name module_list mk1,
assoc_comments_module_kind parent_name module_list mk2)
@@ -898,6 +898,142 @@ and assoc_comments_type module_list t =
(fun rf -> rf.rf_text <- ao (assoc_comments_text parent module_list) rf.rf_text)
fl
);
+ let rec assoc_tmc = function
+ Tec_list l -> List.iter assoc_tmc l
+ | Tec_variant {tec_variant_labels=labels;
+ tec_variant_nested=nested} ->
+ Hashtbl.iter
+ begin fun lbl buc ->
+ buc.tec_variant_coms <-
+ assoc_comments_text parent module_list
+ buc.tec_variant_coms;
+ assoc_tmc buc.tec_variant_tec
+ end labels
+ in
+ let fail_on_different_types () =
+ if not !Odoc_args.inverse_merge_ml_mli
+ then raise (Failure (Odoc_messages.different_types t.ty_name))
+ in
+ let has_merge_description_option =
+ List.mem Merge_description !Odoc_args.merge_options in
+ (* TIP: with Vim the debugging messages below are easily navigable
+ * with the '%' key and set fmr=[,] plus set fdm=marker *)
+ let rec merge_labels
+ ?(strict = true)
+ ?(glob_com: Odoc_types.text = [])
+ ?(enforce_merge = has_merge_description_option)
+ (tec, tec') =
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: [\n";
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)print_tec tec';
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ begin match tec, tec' with
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> merge_labels (x, y)) l l';
+ | (Tec_variant buc as tec),
+ (Tec_variant buc' as tec') ->
+ complete_labels tec;
+ complete_labels tec';
+ Hashtbl.iter
+ begin fun lbl buc' ->
+ let (@) l1 l2 = (* avoid useless list traversal *)
+ if l2 = [] then l1 else l1 @ l2
+ in try let buc = Hashtbl.find buc.tec_variant_labels lbl in
+ (* both types have the same label present: merge comments *)
+ let coms =
+ if enforce_merge
+ || buc.tec_variant_coms = []
+ then if enforce_merge && buc'.tec_variant_coms <> []
+ then Odoc_types.Raw " " :: buc'.tec_variant_coms
+ (* XXX: hardcoded separator *)
+ else buc'.tec_variant_coms
+ else []
+ in buc.tec_variant_coms <- buc.tec_variant_coms @ coms;
+ let glob_com =
+ if enforce_merge
+ || buc.tec_variant_glob_com = []
+ then buc'.tec_variant_glob_com @ glob_com else glob_com
+ in buc.tec_variant_glob_com <- buc.tec_variant_glob_com @ glob_com;
+ merge_labels (buc.tec_variant_tec, buc'.tec_variant_tec)
+ with Not_found ->
+ if strict
+ then fail_on_different_types ()
+ else begin
+ (* we are merging a nested p. v. type,
+ * which brings a new label *)
+ let buc' = {buc' with tec_variant_tec=clone_tec buc'.tec_variant_tec} in
+ buc'.tec_variant_coms <- buc'.tec_variant_coms;
+ buc'.tec_variant_glob_com <- glob_com;
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: add=%s\n" lbl;
+ Hashtbl.add buc.tec_variant_labels lbl buc'
+ end;
+ end buc'.tec_variant_labels;
+ | _ -> fail_on_different_types ()
+ end;
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)print_tec tec';
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)Printf.fprintf stderr "merge_labels: ]\n"
+
+ and complete_labels tec =
+ (*DEBUG*)Printf.fprintf stderr "complete_labels: [\n";
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ begin match tec with
+ Tec_list l -> ()
+ | Tec_variant buc as tec ->
+ (* merge the type expression comments pointed
+ * by [buc.tec_variant_nested] within [tec] *)
+ let q = Queue.create () in
+ Hashtbl.iter begin fun name glob_com ->
+ (*DEBUG*)Printf.fprintf stderr "fetching: [ name=%s\n" name;
+ (* Retrieve comments of nested p. v. types *)
+ ignore (List.exists
+ (function Odoc_search.Res_type t ->
+ (match t.ty_tmc with None -> true
+ | Some (tec', None) ->
+ (*DEBUG*)Printf.fprintf stderr "complete: name=%s\n" name;
+ complete_labels tec';
+ Queue.add (name, tec', glob_com) q;
+ true
+ | Some (tec', Some tec'') ->
+ (*DEBUG*)Printf.fprintf stderr "merge: trig name=%s\n" name;
+ merge_labels (tec', tec'');
+ (*DEBUG*)Printf.fprintf stderr "complete: name=%s\n" name;
+ complete_labels tec';
+ Queue.add (name, tec', glob_com) q;
+ true)
+ | _ -> false)
+ (get_known_elements name));
+ (*DEBUG*)Printf.fprintf stderr "fetching: ] name=%s\n" name;
+ end buc.tec_variant_nested;
+ Hashtbl.clear buc.tec_variant_nested;
+ (* now since the hashtable is empty,
+ * all further [complete_labels] on this tec,
+ * will return immediately. *)
+ (* still we have merges to do *)
+ Queue.iter (fun (name, tec', glob_com) ->
+ (*DEBUG*)Printf.fprintf stderr "merge: queue name=%s glob=%s\n" name
+ (*DEBUG*) (String.concat " " (List.map (function Odoc_types.Raw s -> s | _ -> "") glob_com));
+ merge_labels (tec, tec') ~glob_com ~strict: false ~enforce_merge: true) q;
+ end;
+ (*DEBUG*)print_tec tec;
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ (*DEBUG*)Printf.fprintf stderr "complete_labels: ]\n";
+ in
+ begin match t.ty_tmc with None -> ()
+ | Some (tec, None) ->
+ complete_labels tec;
+ assoc_tmc tec
+ | Some (tec, Some tec') ->
+ t.ty_tmc <- Some (tec, None);
+ (*DEBUG*)Printf.fprintf stderr "cross: [ name=%s\n" t.ty_name;
+ merge_labels (tec, tec');
+ assoc_tmc tec;
+ (*DEBUG*)Printf.fprintf stderr "cross: ] name=%s\n" t.ty_name;
+ end;
t
and assoc_comments_attribute module_list a =
diff --git a/ocamldoc/odoc_env.ml b/ocamldoc/odoc_env.ml
index ed9fb26..0865f8d 100644
--- a/ocamldoc/odoc_env.ml
+++ b/ocamldoc/odoc_env.ml
@@ -181,7 +181,7 @@ let subst_type env t =
print_env_types env ;
print_newline ();
*)
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
let deja_vu = ref [] in
let rec iter t =
if List.memq t !deja_vu then () else begin
diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml
index f34ad5e..2f0714c 100644
--- a/ocamldoc/odoc_html.ml
+++ b/ocamldoc/odoc_html.ml
@@ -1098,11 +1098,27 @@ class html =
s2
(** Print html code to display a [Types.type_expr]. *)
- method html_of_type_expr b m_name t =
- let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_type_expr t) in
- let s2 = newline_to_indented_br s in
+ method html_of_type_expr ?tec b m_name t =
+ let str_of_com coms =
+ let b = Buffer.create 42 in
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ bs b "<code>";
+ bs b "(*";
+ bs b "</code></td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"top\" >";
+ self#html_of_text b coms;
+ bs b "</td>";
+ bs b "<td class=\"typefieldcomment\" align=\"left\" valign=\"bottom\" >";
+ bs b "<code>";
+ bs b "*)";
+ bs b "</code></td>";
+ Buffer.contents b in
+ let str_of_ident =
+ self#create_fully_qualified_idents_links m_name in
+ let s = Odoc_info.remove_ending_newline
+ (Odoc_info.string_of_type_expr t ?tec ~str_of_com ~str_of_ident) in
bs b "<code class=\"type\">";
- bs b (self#create_fully_qualified_idents_links m_name s2);
+ bs b (newline_to_indented_br s);
bs b "</code>"
(** Print html code to display a [Types.type_expr list]. *)
@@ -1372,7 +1388,8 @@ class html =
None -> ()
| Some typ ->
bs b "= ";
- self#html_of_type_expr b father typ;
+ self#html_of_type_expr b father typ
+ ?tec: (match t.ty_tmc with Some (tec, _) -> Some tec | _ -> None);
bs b " "
);
(match t.ty_kind with
@@ -1814,7 +1831,8 @@ class html =
(Naming.type_target
{ ty_name = c.cl_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
@@ -1861,7 +1879,8 @@ class html =
(Naming.type_target
{ ty_name = ct.clt_name ;
ty_info = None ; ty_parameters = [] ;
- ty_kind = Type_abstract ; ty_manifest = None ;
+ ty_kind = Type_abstract ;
+ ty_manifest = None ; ty_tmc = None ;
ty_loc = Odoc_info.dummy_loc ;
ty_code = None ;
}
diff --git a/ocamldoc/odoc_info.ml b/ocamldoc/odoc_info.ml
index 65735fd..3305bab 100644
--- a/ocamldoc/odoc_info.ml
+++ b/ocamldoc/odoc_info.ml
@@ -113,11 +113,11 @@ let dump_modules = Odoc_analyse.dump_modules
let load_modules = Odoc_analyse.load_modules
-let reset_type_names = Printtyp.reset
+let reset_type_names = Odoc_print.reset
let string_of_variance t (co,cn) = Odoc_str.string_of_variance t (co, cn)
-let string_of_type_expr t = Odoc_print.string_of_type_expr t
+let string_of_type_expr = Odoc_print.string_of_type_expr
let string_of_class_params = Odoc_str.string_of_class_params
diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli
index e3638a7..7d58907 100644
--- a/ocamldoc/odoc_info.mli
+++ b/ocamldoc/odoc_info.mli
@@ -212,6 +212,29 @@ module Type :
| Type_record of record_field list * bool
(** fields * bool *)
+ (** Type expression's comments *)
+ type tec = Odoc_type.tec =
+ Tec_variant of tec_variant_buc
+ (** comments for a polymorphic variant expression *)
+ | Tec_list of tec list
+ (** orthogonal types. Note that [Tec_list []] can be used *)
+ and tec_variant_buc = Odoc_type.tec_variant_buc =
+ { tec_variant_labels : (Asttypes.label, tec_variant_lbl_buc) Hashtbl.t;
+ (** the labels textually present in a p. v. type expression *)
+ mutable tec_variant_nested : (Odoc_name.t, Odoc_types.text) Hashtbl.t
+ (** the nested p. v. types textually present int a p.v. type expression,
+ and the global comments associated *) }
+ and tec_variant_lbl_buc = Odoc_type.tec_variant_lbl_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ (** the comments of a label *)
+ mutable tec_variant_glob_com: Odoc_types.text;
+ (** the global comment of a label *)
+ tec_variant_tec: tec
+ (** the comments of the label's data *) }
+
+ val clone_tec : tec -> tec
+ (*DEBUG*)val print_tec : ?s: string -> tec -> unit
+
(** Representation of a type. *)
type t_type = Odoc_type.t_type =
{
@@ -220,7 +243,11 @@ module Type :
ty_parameters : (Types.type_expr * bool * bool) list ;
(** type parameters: (type, covariant, contravariant) *)
ty_kind : type_kind ; (** Type kind. *)
- ty_manifest : Types.type_expr option; (** Type manifest. *)
+ ty_manifest : Types.type_expr option ; (** Type manifest. *)
+ mutable ty_tmc : (tec * tec option) option;
+ (** Type manifest's comments and another one to be merge within.
+ This second [tec] is used to carry ml's [tec] between,
+ the merging time and the cross referencing time *)
mutable ty_loc : location ;
mutable ty_code : string option;
}
@@ -599,7 +626,11 @@ val reset_type_names : unit -> unit
val string_of_variance : Type.t_type -> (bool * bool) -> string
(** This function returns a string representing a Types.type_expr. *)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ Types.type_expr -> string
(** @return a string to display the parameters of the given class,
in the same form as the compiler. *)
diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml
index 851884a..01ea52e 100644
--- a/ocamldoc/odoc_merge.ml
+++ b/ocamldoc/odoc_merge.ml
@@ -191,8 +191,13 @@ let merge_types merge_options mli ml =
mli.ty_info <- merge_info_opt merge_options mli.ty_info ml.ty_info;
mli.ty_loc <- { mli.ty_loc with loc_impl = ml.ty_loc.loc_impl } ;
mli.ty_code <- (match mli.ty_code with None -> ml.ty_code | _ -> mli.ty_code) ;
-
- match mli.ty_kind, ml.ty_kind with
+ let fail_on_different_types () =
+ if not !Odoc_args.inverse_merge_ml_mli
+ then raise (Failure (Odoc_messages.different_types mli.ty_name))
+ in
+ let has_merge_description_option =
+ List.mem Merge_description merge_options in
+ begin match mli.ty_kind, ml.ty_kind with
Type_abstract, _ ->
()
@@ -209,18 +214,13 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
cons.vc_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
@@ -237,26 +237,25 @@ let merge_types merge_options mli ml =
| Some d, None
| None, Some d -> Some d
| Some d1, Some d2 ->
- if List.mem Merge_description merge_options then
+ if has_merge_description_option then
Some (d1 @ d2)
else
Some d1
in
record.rf_text <- new_desc
- with
- Not_found ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ with Not_found -> fail_on_different_types ()
in
List.iter f l1
- | _ ->
- if !Odoc_args.inverse_merge_ml_mli then
- ()
- else
- raise (Failure (Odoc_messages.different_types mli.ty_name))
+ | _ -> fail_on_different_types ()
+ end;
+ begin match mli.ty_tmc, ml.ty_tmc with
+ None, None
+ | Some _, None -> ()
+ | None, Some _ -> mli.ty_tmc <- ml.ty_tmc
+ | Some (mli_tec, _), Some (ml_tec, _) ->
+ mli.ty_tmc <- Some (mli_tec, Some ml_tec)
+ end
(** Merge of two param_info, one from a .mli, one from a .ml.
The text fields are not handled but will be recreated from the
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index 6e4afc7..aeb9ffe 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -36,12 +36,234 @@ let _ =
let (modtype_fmt, flush_modtype_fmt) = new_fmt ()
+module Odoc_oprint =
+ struct
+ open Odoc_type
+ open Format
+ open Outcometree
+ let print_ident
+ ~str_of_ident
+ ppf x =
+ let buf = Buffer.create 12 in
+ let rec aux = function
+ Oide_ident s -> Buffer.add_string buf s
+ | Oide_dot (id, s) ->
+ aux id;
+ Buffer.add_string buf ".";
+ Buffer.add_string buf s
+ | Oide_apply (id1, id2) ->
+ aux id1;
+ Buffer.add_string buf "(";
+ aux id2;
+ Buffer.add_string buf ")"
+ in aux x;
+ fprintf ppf "%s" (str_of_ident (Buffer.contents buf))
-let string_of_type_expr t =
+ let rec print_list_init pr sep ppf =
+ function
+ [] -> ()
+ | a :: l -> sep ppf; pr ppf a; print_list_init pr sep ppf l
+
+ let rec print_list pr sep ppf =
+ function
+ [] -> ()
+ | [a] -> pr ppf a
+ | a :: l -> pr ppf a; sep ppf; print_list pr sep ppf l
+
+ let pr_present =
+ print_list (fun ppf s -> fprintf ppf "`%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let pr_vars =
+ print_list (fun ppf s -> fprintf ppf "'%s" s) (fun ppf -> fprintf ppf "@ ")
+
+ let rec print_out_type
+ ?(tec = Tec_list [])
+ ?(str_of_com = Odoc_misc.string_of_text)
+ ?(str_of_ident = fun (x: string) -> x)
+ ppf =
+ function
+ | Otyp_alias (ty, s) ->
+ fprintf ppf "@[%a@ as '%s@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty s
+ | Otyp_poly (sl, ty) ->
+ fprintf ppf "@[<hov 2>%a.@ %a@]"
+ pr_vars sl
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
+ | ty ->
+ print_out_type_1 ppf ty ~tec ~str_of_com ~str_of_ident
+
+ and print_out_type_1 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_arrow (lab, ty1, ty2) ->
+ let tec1, tec2 = match tec with
+ Tec_list [x;y] -> x, y
+ | _ -> Tec_list [], Tec_list [] in
+ fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "")
+ (print_out_type_2 ~tec: tec1 ~str_of_com ~str_of_ident) ty1
+ (print_out_type_1 ~tec: tec2 ~str_of_com ~str_of_ident) ty2
+ | ty ->
+ print_out_type_2 ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_out_type_2 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_tuple tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
+ print_simple_out_type ~tec ~str_of_com ~str_of_ident ty
+ in fprintf ppf "@[<0>%a@]" (print_typlist print_elem " *") tyl
+ | ty ->
+ print_simple_out_type ppf ty ~tec ~str_of_com ~str_of_ident
+ and print_simple_out_type ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ Otyp_class (ng, id, tyl) ->
+ fprintf ppf "@[%a%s#%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (if ng then "_" else "")
+ (print_ident ~str_of_ident) id
+ | Otyp_constr (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
+ | Otyp_object (fields, rest) ->
+ fprintf ppf "@[<2>< %a >@]"
+ (print_fields rest ~tec ~str_of_com ~str_of_ident) fields
+ | Otyp_stuff s -> fprintf ppf "%s" s
+ | Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s
+ | 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
+ let print_fields ~tec ~str_of_com ppf =
+ function
+ Ovar_fields fields ->
+ print_list
+ (print_row_field ~tec ~str_of_com ~str_of_ident)
+ (fun ppf -> fprintf ppf "@;<1 -2>| ")
+ ppf fields
+ | Ovar_name (id, tyl) ->
+ fprintf ppf "@[%a%a@]"
+ (print_typargs ~tec ~str_of_com ~str_of_ident) tyl
+ (print_ident ~str_of_ident) id
+ in
+ 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 "? ")
+ (print_fields ~tec ~str_of_com) row_fields
+ print_present tags
+ | Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty ->
+ fprintf ppf "@[<1>(%a)@]"
+ (print_out_type ~tec ~str_of_com ~str_of_ident) ty
+ | Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> ()
+ and print_fields ~tec ~str_of_com ~str_of_ident rest ppf =
+ function
+ [] ->
+ begin match rest with
+ Some non_gen -> fprintf ppf "%s.." (if non_gen then "_" else "")
+ | None -> ()
+ end
+ | [s, t] ->
+ let tec = match tec with Tec_list [h] -> h
+ | _ -> Tec_list [] in
+ fprintf ppf "%s : %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t;
+ begin match rest with
+ Some _ -> fprintf ppf ";@ "
+ | None -> () end;
+ print_fields ~tec: (Tec_list [])
+ ~str_of_com ~str_of_ident rest ppf []
+ | (s, t) :: l ->
+ let tec, tec' = match tec with Tec_list (h::t) -> h, Tec_list t
+ | _ -> Tec_list [], Tec_list [] in
+ fprintf ppf "%s : %a;@ %a" s
+ (print_out_type ~tec ~str_of_com ~str_of_ident) t
+ (print_fields rest ~tec: tec' ~str_of_com ~str_of_ident) l
+ and print_row_field
+ ~tec ~str_of_com
+ ~str_of_ident 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
+ let {Odoc_type.tec_variant_coms=coms;
+ tec_variant_glob_com=glob_com;
+ tec_variant_tec=tec} =
+ try match tec with
+ Tec_variant {Odoc_type.tec_variant_labels=labels} ->
+ Hashtbl.find labels l
+ | _ -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_glob_com=[];
+ tec_variant_tec=Tec_list []}
+ with Not_found -> {Odoc_type.tec_variant_coms=[];
+ tec_variant_glob_com=[];
+ tec_variant_tec=Tec_list []} in
+ let coms =
+ if glob_com <> []
+ then coms @ (Odoc_types.Raw " " :: glob_com)
+ (** XXX: hardcoded separator *)
+ else coms in
+ let str_coms =
+ if coms <> []
+ then str_of_com coms
+ else "" in
+ fprintf ppf "@[<hv 2>`%s%t%a%s%s@]"
+ l pr_of
+ (print_typlist (print_out_type ~tec ~str_of_com ~str_of_ident) " &") tyl
+ (if coms = [] then "" else " ")
+ str_coms
+ 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 ~tec ~str_of_com ~str_of_ident ppf =
+ function
+ [] -> ()
+ | [ty1] ->
+ let tec = match tec with Tec_list (h::t) -> h
+ | _ -> Tec_list [] in
+ fprintf ppf "%a@ "
+ (print_simple_out_type ~tec ~str_of_com ~str_of_ident) ty1
+ | tyl ->
+ let tecr = ref tec in
+ let print_elem ty =
+ let tec = match !tecr with
+ Tec_list (tec::t) -> tecr := Tec_list t; tec
+ | _ -> Tec_list [] in
+ print_out_type ~tec ~str_of_com ~str_of_ident ty
+ in fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_elem ",") tyl
+
+ let out_type = ref print_out_type
+ end
+
+let type_scheme
+ ?tec ?str_of_com ?str_of_ident
+ ?(b_reset_names = true)
+ ppf ty =
+ if b_reset_names then Printtyp.reset_names ();
+ let out_type'save = !Oprint.out_type in
+ Oprint.out_type := !Odoc_oprint.out_type
+ ?tec ?str_of_com ?str_of_ident;
+ Printtyp.type_sch ppf ty;
+ Oprint.out_type := out_type'save
+
+let mark_loops = Printtyp.mark_loops
+let reset = Printtyp.reset
+
+let string_of_type_expr
+ ?tec ?str_of_com ?str_of_ident t =
Printtyp.mark_loops t;
- Printtyp.type_scheme_max ~b_reset_names: false type_fmt t;
+ type_scheme type_fmt t
+ ?tec ?str_of_com ?str_of_ident
+ ~b_reset_names: false;
flush_type_fmt ()
exception Use_code of string
diff --git a/ocamldoc/odoc_print.mli b/ocamldoc/odoc_print.mli
index 3dcc8cf..ec30d28 100644
--- a/ocamldoc/odoc_print.mli
+++ b/ocamldoc/odoc_print.mli
@@ -11,11 +11,30 @@
(* $Id: odoc_print.mli,v 1.2 2004-03-26 09:09:50 guesdon Exp $ *)
+(** Customized [Printtyp.mark_loops] *)
+val mark_loops: Types.type_expr -> unit
+
+(** Customized [Printtyp.type_scheme] *)
+val type_scheme:
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ ?b_reset_names: bool ->
+ Format.formatter -> Types.type_expr -> unit
+
+(** Same as [Printtyp.reset] but for the above functions *)
+val reset: unit -> unit
+
+
(** Printing functions. *)
(** This function takes a Types.type_expr and returns a string.
It writes in and flushes [Format.str_formatter].*)
-val string_of_type_expr : Types.type_expr -> string
+val string_of_type_expr :
+ ?tec: Odoc_type.tec ->
+ ?str_of_com: (Odoc_types.text -> string) ->
+ ?str_of_ident: (string -> string) ->
+ Types.type_expr -> string
(** This function returns a string representing a [Types.module_type].
@param complete indicates if we must print complete signatures
diff --git a/ocamldoc/odoc_scan.ml b/ocamldoc/odoc_scan.ml
index b62e25b..ae49890 100644
--- a/ocamldoc/odoc_scan.ml
+++ b/ocamldoc/odoc_scan.ml
@@ -56,7 +56,7 @@ class scanner =
)
(Odoc_class.class_elements c)
- (** Scan of a class. Should not be overriden. It calls [scan_class_pre]
+ (** Scan of a class. Should not be overridden. It calls [scan_class_pre]
and if [scan_class_pre] returns [true], then it calls scan_class_elements.*)
method scan_class c = if self#scan_class_pre c then self#scan_class_elements c
@@ -82,7 +82,7 @@ class scanner =
)
(Odoc_class.class_type_elements ct)
- (** Scan of a class type. Should not be overriden. It calls [scan_class_type_pre]
+ (** Scan of a class type. Should not be overridden. It calls [scan_class_type_pre]
and if [scan_class_type_pre] returns [true], then it calls scan_class_type_elements.*)
method scan_class_type ct = if self#scan_class_type_pre ct then self#scan_class_type_elements ct
@@ -113,7 +113,7 @@ class scanner =
)
(Odoc_module.module_elements m)
- (** Scan of a module. Should not be overriden. It calls [scan_module_pre]
+ (** Scan of a module. Should not be overridden. It calls [scan_module_pre]
and if [scan_module_pre] returns [true], then it calls scan_module_elements.*)
method scan_module m = if self#scan_module_pre m then self#scan_module_elements m
@@ -144,7 +144,7 @@ class scanner =
)
(Odoc_module.module_type_elements mt)
- (** Scan of a module type. Should not be overriden. It calls [scan_module_type_pre]
+ (** Scan of a module type. Should not be overridden. It calls [scan_module_type_pre]
and if [scan_module_type_pre] returns [true], then it calls scan_module_type_elements.*)
method scan_module_type mt =
if self#scan_module_type_pre mt then self#scan_module_type_elements mt
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index fe4e223..b3c8220 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -215,6 +215,105 @@ module Analyser =
in
(0, f name_mutable_type_list)
+ let get_tec
+ ~env ~name ~pos_end par_ct : tec =
+ let retrieve_comments pos_end loc dlen : Odoc_types.text =
+ (* retrieve the source from the start of the current variant
+ * to the end of the current type *)
+ let s = ref (get_string_of_file
+ (loc.Location.loc_start.Lexing.pos_cnum + !dlen)
+ (min loc.Location.loc_end.Lexing.pos_cnum pos_end)) in
+ begin let idx = ref 0 (* cut just before the following variant *)
+ in let cnt = ref 0 (* of the same type, by hand, since Ptyp_variant *)
+ in while incr idx; !idx < String.length !s (* has no Location.t *)
+ do match !s.[!idx] with
+ '[' -> incr cnt
+ | '|' when !cnt = 0 -> s := String.sub !s 0 !idx
+ | ']' -> decr cnt
+ | _ -> ()
+ done end;
+ (* try to extract a comment *)
+ let _, comment_opt =
+ My_ir.just_after_special !file_name !s in
+ dlen := !dlen + String.length !s;
+ match comment_opt with
+ Some {Odoc_types.i_desc = Some coms} -> coms
+ | _ -> []
+ in
+ let rec add_label
+ labels lbl buc : unit =
+ try let buc' = Hashtbl.find labels lbl in
+ (* the label is already present: merge *)
+ if buc'.tec_variant_coms <> []
+ then buc.tec_variant_coms <-
+ buc.tec_variant_coms @ buc'.tec_variant_coms;
+ let rec f = function
+ Tec_list l, Tec_list l' ->
+ List.iter2 (fun x y -> f (x, y)) l l'
+ | Tec_variant {tec_variant_labels=labels},
+ Tec_variant {tec_variant_labels=labels'} ->
+ Hashtbl.iter (add_label labels) labels'
+ | _ -> assert false
+ in f (buc.tec_variant_tec, buc'.tec_variant_tec)
+ with Not_found ->
+ (* this is a new label: insert it *)
+ Hashtbl.add labels lbl buc
+ in
+ let rec get ?(pstart = 0) ?(pdlen = ref 0) par_ct =
+ let loc = par_ct.Parsetree.ptyp_loc in
+ let dlen = ref 0 in
+ pdlen := !pdlen + loc.Location.loc_end.Lexing.pos_cnum - pstart;
+ let get ct = get ct ~pdlen: dlen
+ ~pstart: (loc.Location.loc_start.Lexing.pos_cnum + !dlen) in
+ let labels = Hashtbl.create 13 in
+ let nested = Hashtbl.create 13 in
+ begin match par_ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_any
+ | Parsetree.Ptyp_var _
+ | Parsetree.Ptyp_constr _ -> Tec_list []
+ | Parsetree.Ptyp_arrow (lbl, ct, ct') ->
+ Tec_list [get ct; get ct']
+ | Parsetree.Ptyp_tuple l
+ | Parsetree.Ptyp_class (_, l, _) ->
+ Tec_list (List.map get l)
+ | Parsetree.Ptyp_object l ->
+ Tec_list (List.map (fun ctf ->
+ match ctf.Parsetree.pfield_desc with
+ Parsetree.Pfield_var -> Tec_list []
+ | Parsetree.Pfield (_, ct) -> get ct) l)
+ | Parsetree.Ptyp_alias (ct, _)
+ | Parsetree.Ptyp_poly (_, ct) -> get ct
+ | Parsetree.Ptyp_variant (row_field_list, boo, label_list_option) ->
+ List.iter begin function
+ Parsetree.Rtag (lbl, b, l) ->
+ (* map the sub-types of the current variant *)
+ let l = List.map get l in
+ let tec = match l with [tec] -> tec (* not really a tuple *)
+ | _ -> Tec_list l in
+ let coms = retrieve_comments pos_end loc dlen in
+ add_label labels lbl ({tec_variant_coms=coms;
+ tec_variant_glob_com=[];
+ (* may be updated at merging time *)
+ tec_variant_tec=tec});
+ | Parsetree.Rinherit ct ->
+ match ct.Parsetree.ptyp_desc with
+ Parsetree.Ptyp_constr (lid, _) ->
+ let glob_com = retrieve_comments pos_end loc dlen in
+ let name = Odoc_env.full_type_name env
+ (String.concat "." (Longident.flatten lid)) in
+ Hashtbl.replace nested name glob_com
+ | _ -> ()
+ end row_field_list;
+ Tec_variant {tec_variant_labels=labels;
+ tec_variant_nested=nested}
+ end
+ in
+ let tec = get par_ct in
+ (*DEBUG*)Printf.fprintf stderr "\nget_tec name=%s" name;
+ (*DEBUG*)print_tec tec ~s: "";
+ (*DEBUG*)Printf.fprintf stderr "\n";
+ tec
+
let get_type_kind env name_comment_list type_kind =
match type_kind with
Types.Type_abstract ->
@@ -597,6 +696,12 @@ module Analyser =
let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in
let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum in
let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in
+ let tmc = match type_decl.Parsetree.ptype_manifest
+ with None -> None | Some ct ->
+ Some (begin get_tec ct ~env: new_env
+ ~name: (Name.concat current_module_name name)
+ ~pos_end: type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum
+ end, None) in
(* associate the comments to each constructor and build the [Type.t_type] *)
let new_type =
{
@@ -614,6 +719,7 @@ module Analyser =
(match sig_type_decl.Types.type_manifest with
None -> None
| Some t -> Some (Odoc_env.subst_type new_env t));
+ ty_tmc = tmc;
ty_loc =
{ loc_impl = None ;
loc_inter = Some (!file_name,loc_start) ;
@@ -643,7 +749,7 @@ module Analyser =
let (maybe_more, types) = f ~first: true 0 pos_start_ele name_type_decl_list in
(maybe_more, new_env, types)
- | Parsetree.Psig_open _ -> (* A VOIR *)
+ | Parsetree.Psig_open lid ->
let ele_comments = match comment_opt with
None -> []
| Some i ->
@@ -651,7 +757,17 @@ module Analyser =
None -> []
| Some t -> [Element_module_comment t]
in
- (0, env, ele_comments)
+ let name = (String.concat "." (Longident.flatten lid)) in
+ begin try match Signature_search.search_module table name
+ with Tmty_signature signat ->
+ let full_name = Odoc_env.full_module_name env name in
+ let new_env = Odoc_env.add_signature env full_name signat in
+ (0, new_env, ele_comments)
+ | _ -> (0, env, ele_comments)
+ with Not_found -> (0, env, ele_comments)
+ (* XXX: this may be because it is an external module,
+ * so how do we get its signature? *)
+ end
| Parsetree.Psig_module (name, module_type) ->
let complete_name = Name.concat current_module_name name in
@@ -661,7 +777,8 @@ module Analyser =
with Not_found ->
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
- let module_kind = analyse_module_kind env complete_name module_type sig_module_type in
+ let module_kind = analyse_module_kind env complete_name module_type
+ sig_module_type in
let code_intf =
if !Odoc_args.keep_code then
let loc = module_type.Parsetree.pmty_loc in
@@ -752,7 +869,8 @@ module Analyser =
raise (Failure (Odoc_messages.module_not_found current_module_name name))
in
(* associate the comments to each constructor and build the [Type.t_type] *)
- let module_kind = analyse_module_kind new_env complete_name modtype sig_module_type in
+ let module_kind = analyse_module_kind new_env complete_name
+ modtype sig_module_type in
let code_intf =
if !Odoc_args.keep_code then
let loc = modtype.Parsetree.pmty_loc in
@@ -830,7 +948,8 @@ module Analyser =
in
let module_type_kind =
match sig_mtype_opt with
- | Some sig_mtype -> Some (analyse_module_type_kind env complete_name module_type sig_mtype)
+ | Some sig_mtype -> Some (analyse_module_type_kind env complete_name
+ module_type sig_mtype)
| None -> None
in
let mt =
@@ -1049,7 +1168,8 @@ module Analyser =
Types.Tmty_signature signat ->
let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
- let elements = analyse_parsetree env signat current_module_name pos_start pos_end ast in
+ let elements = analyse_parsetree env signat current_module_name
+ pos_start pos_end ast in
Module_type_struct elements
| _ ->
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
@@ -1092,7 +1212,8 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name
+ module_type2 sig_module_type in
Module_type_with (k, s)
)
@@ -1100,7 +1221,8 @@ module Analyser =
and analyse_module_kind env current_module_name module_type sig_module_type =
match module_type.Parsetree.pmty_desc with
Parsetree.Pmty_ident longident ->
- let k = analyse_module_type_kind env current_module_name module_type sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type
+ sig_module_type in
Module_with ( k, "" )
| Parsetree.Pmty_signature signature ->
@@ -1120,7 +1242,7 @@ module Analyser =
(* if we're here something's wrong *)
raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
)
- | Parsetree.Pmty_functor (_,pmodule_type2,module_type2) (* of string * module_type * module_type *) ->
+ | Parsetree.Pmty_functor (name,pmodule_type2,module_type2) (* of string * module_type * module_type *) ->
(
match sig_module_type with
Types.Tmty_functor (ident, param_module_type, body_module_type) ->
@@ -1156,7 +1278,8 @@ module Analyser =
let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file loc_start loc_end in
- let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in
+ let k = analyse_module_type_kind env current_module_name module_type2
+ sig_module_type in
Module_with (k, s)
)
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index b41e913..8b21d9b 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -149,6 +149,14 @@ module Analyser :
Odoc_env.env -> (string * Odoc_types.info option) list ->
Types.type_kind -> Odoc_type.type_kind
+ (** Fetch the comments (only in polymorphic variants currently)
+ inside a [Parsetree.core_type]. *)
+ val get_tec :
+ env: Odoc_env.env ->
+ name: Odoc_name.t ->
+ pos_end: int ->
+ Parsetree.core_type -> Odoc_type.tec
+
(** This function merge two optional info structures. *)
val merge_infos :
Odoc_types.info option -> Odoc_types.info option ->
@@ -156,9 +164,11 @@ module Analyser :
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
val analyse_module_type_kind :
- Odoc_env.env -> Odoc_name.t ->
- Parsetree.module_type -> Types.module_type ->
- Odoc_module.module_type_kind
+ Odoc_env.env ->
+ Odoc_name.t ->
+ Parsetree.module_type ->
+ Types.module_type ->
+ Odoc_module.module_type_kind
(** Analysis of a Parsetree.class_type and a Types.class_type to
return a class_type_kind.*)
diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml
index e3295eb..e0c2af7 100644
--- a/ocamldoc/odoc_str.ml
+++ b/ocamldoc/odoc_str.ml
@@ -47,17 +47,17 @@ let raw_string_of_type_list sep type_list =
| Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false
in
let print_one_type variance t =
- Printtyp.mark_loops t;
+ Odoc_print.mark_loops t;
if need_parent t then
(
Format.fprintf fmt "(%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t;
+ Odoc_print.type_scheme ~b_reset_names: false fmt t;
Format.fprintf fmt ")"
)
else
(
Format.fprintf fmt "%s" variance;
- Printtyp.type_scheme_max ~b_reset_names: false fmt t
+ Odoc_print.type_scheme ~b_reset_names: false fmt t
)
in
begin match type_list with
diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml
index 26ae47b..d845be6 100644
--- a/ocamldoc/odoc_type.ml
+++ b/ocamldoc/odoc_type.ml
@@ -38,15 +38,101 @@ type type_kind =
| Type_record of record_field list * bool
(** fields * bool *)
+(** Type expression's comments *)
+type tec =
+ Tec_variant of tec_variant_buc
+ (** comments for a polymorphic variant expression *)
+ | Tec_list of tec list
+ (** orthogonal types. Note that [Tec_list []] can be used *)
+and tec_variant_buc =
+ { tec_variant_labels : (Asttypes.label, tec_variant_lbl_buc) Hashtbl.t;
+ (** the labels textually present in a p. v. type expression *)
+ mutable tec_variant_nested : (Odoc_name.t, Odoc_types.text) Hashtbl.t
+ (** the nested p. v. types textually present int a p.v. type expression,
+ and the global comments associated *) }
+and tec_variant_lbl_buc =
+ { mutable tec_variant_coms: Odoc_types.text;
+ (** the comments of a label *)
+ mutable tec_variant_glob_com: Odoc_types.text;
+ (** the global comment of a label *)
+ tec_variant_tec: tec
+ (** the comments of the label's data *) }
+
+let rec clone_tec =
+ function
+ Tec_list l ->
+ Tec_list (List.map clone_tec l)
+ | Tec_variant buc ->
+ let labels = Hashtbl.create
+ (Hashtbl.length buc.tec_variant_labels) in
+ Hashtbl.iter
+ (fun lbl buc -> Hashtbl.add labels lbl
+ {buc with tec_variant_tec=clone_tec buc.tec_variant_tec})
+ buc.tec_variant_labels;
+ let nested = Hashtbl.create
+ (Hashtbl.length buc.tec_variant_nested) in
+ Hashtbl.iter (Hashtbl.add nested) buc.tec_variant_nested;
+ Tec_variant
+ { tec_variant_labels=labels;
+ tec_variant_nested=nested }
+
+(*DEBUG*)open Printf
+(*DEBUG*)let rec print_tec
+(*DEBUG*) ?(s="") =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) function
+(*DEBUG*) Tec_list l ->
+(*DEBUG*) fprintf o "\n%sTec_list [" s;
+(*DEBUG*) List.iter (print_tec ~s: (s ^ " ")) l;
+(*DEBUG*) fprintf o "]"
+(*DEBUG*) | Tec_variant
+(*DEBUG*) { tec_variant_labels=labels
+(*DEBUG*) ; tec_variant_nested=nested } ->
+(*DEBUG*) fprintf o "\n%sTec_variant" s;
+(*DEBUG*) print_labels labels ~s: (s ^ " ");
+(*DEBUG*) print_nested nested ~s: (s ^ " ")
+(*DEBUG*)and print_labels ~s =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) Hashtbl.iter begin fun lbl buc ->
+(*DEBUG*) fprintf o "\n%slbl=%s" s lbl;
+(*DEBUG*) if buc.tec_variant_coms <> []
+(*DEBUG*) then fprintf o "\n%scoms=%s" s
+(*DEBUG*) (string_of_com buc.tec_variant_coms);
+(*DEBUG*) if buc.tec_variant_glob_com <> []
+(*DEBUG*) then fprintf o "\n%sglob=%s" s
+(*DEBUG*) (string_of_com buc.tec_variant_glob_com);
+(*DEBUG*) if buc.tec_variant_tec <> Tec_list []
+(*DEBUG*) then begin
+(*DEBUG*) fprintf o "\n%stec=" s;
+(*DEBUG*) print_tec buc.tec_variant_tec
+(*DEBUG*) ~s: (s ^ " ")
+(*DEBUG*) end
+(*DEBUG*) end
+(*DEBUG*)and print_nested ~s =
+(*DEBUG*) let o = stderr in
+(*DEBUG*) Hashtbl.iter begin fun name glob_com ->
+(*DEBUG*) fprintf o "\n%sname=%s" s name;
+(*DEBUG*) if glob_com <> []
+(*DEBUG*) then fprintf o "\n%sglob=%s" s (string_of_com glob_com)
+(*DEBUG*) end
+(*DEBUG*)and string_of_com com =
+(*DEBUG*) String.concat " "
+(*DEBUG*) (List.map (function Odoc_types.Raw s -> s | _ -> "") com)
+
(** Representation of a type. *)
type t_type = {
- ty_name : Name.t ;
- mutable ty_info : Odoc_types.info option ; (** optional user information *)
- ty_parameters : (Types.type_expr * bool * bool) list ;
+ ty_name : Name.t;
+ mutable ty_info : Odoc_types.info option; (** optional user information *)
+ ty_parameters : (Types.type_expr * bool * bool) list;
(** type parameters: (type, covariant, contravariant) *)
- ty_kind : type_kind ;
+ ty_kind : type_kind;
ty_manifest : Types.type_expr option; (** type manifest *)
- mutable ty_loc : Odoc_types.location ;
+ mutable ty_tmc : (tec * tec option) option;
+ (** type manifest's comments and another one to be merge within.
+ This second [tec] is used to carry ml's [tec] between,
+ the merging time and the cross referencing time *)
+ mutable ty_loc : Odoc_types.location;
mutable ty_code : string option;
- }
+ }
+
diff --git a/ocamldoc/odoc_value.ml b/ocamldoc/odoc_value.ml
index 29be7c5..fb8bbc5 100644
--- a/ocamldoc/odoc_value.ml
+++ b/ocamldoc/odoc_value.ml
@@ -102,7 +102,7 @@ let dummy_parameter_list typ =
'?' -> String.sub s 1 ((String.length s) - 1)
| _ -> s
in
- Printtyp.mark_loops typ;
+ Odoc_print.mark_loops typ;
let liste_param = parameter_list_from_arrows typ in
let rec iter (label, t) =
match t.Types.desc with
| ||||||||||
Relationships |
||||||
|
||||||
Notes |
|
|
(0004134) jm (reporter) 2007-08-13 09:22 edited on: 2007-08-14 14:12 |
Unfortunately, as I see it, if you want to do it properly/completely, this would require to wrap the ubiquitous type [Types.type_expr], to convert/wrap a lot of functions of ocamldoc/ocaml currently using this type, to retrieve the comments (not easy since the locations are not kept inside [Parsetree.core_type_desc]), to associate the comments in the wrapped type (with all the difficulty caused by the nested polymophic variant types), and finally to copy/extend Oprint and Printtyp, plus a few other modules. This task is not unfeasible, but is not easy and requires a lot of changes, increasing, to my mind, a little too much the size and complexity of ocamldoc for such a little gain. Therefore, in my humble opinion, your wish will not be fulfilled. |
|
(0004137) jm (reporter) 2007-08-16 18:44 edited on: 2007-08-16 18:55 |
Here, I've written a little patch that should do the job, but only on type declaration. NB: This patch may contain bugs, and might slow down ocamldoc; I am no ocamldoc/ocamlc expert, and I have only tested it against this example: module M0 : sig type t = [`M0tA (** com M0tA *)] end type n = [ `NA (** com NA *) | `NB (** com NB *) ] type 'a t = [ `F of ([>`A (** com FA *) | n (** com Fn *) ] as 'a ) (** com F *) | `A of int (** com A *) | `B of int (** com B *) | `C of int (** com C *) | `D of [`A (** com DA *) |`B (** com DB *) ] (** com D *) | `E of ( [`A (** com E0A *)] * [`A (** com E1A *)] * ( <m:[`A (** com E20m0A *)] -> [`A (** com E20m1A*)] -> [`A (** com E20m2A*)]> * <m:[ `A (** com E21mA *) | `B of (int * [`A (** com E21mB1A *)]) (** com E21mB *)]> ) ) (** com E *) | n (** com n *) | M0.t (** com M0.t *) ] * int By the way, [Printtyp.type_scheme_max] is not used any longer, but since it does not really belong to ocamldoc, this patch does not remove it. |
|
(0004138) jm (reporter) 2007-08-17 15:07 edited on: 2007-08-18 23:24 |
As foreseen, there are at least 4 bugs in ocamldoc_poly_var.patch: 1/ Due to my misunderstanding of ocamlc, the polymorphic symbols are not reset properly, which creates this kind of ugly thing: val f : 'a -> 'a val g : 'b -> 'b I think it is related to reset_names, but I really don't know currently. EDIT: this was indeed due to *not* resetting a few internal variables: it was done for Printtyp's vars instead of Odoc_print's ones. FIX_ocamldoc_poly_var_proxies.patch should correct this. 2/ Due to my laziness, the comments in the implementation file are not merge with the comments in the interface file. EDIT: fixed in FIX_ocamldoc_merge_of_type_manifest_comments.patch, which also brings better names and removes useless debugging calls and tabulations. 3/ Due to my bad use of git, the patch changes .depend instead of Makefile. EDIT: fixed in FIX_ocamldoc_poly_var_proxies.patch 4/ For the HTML output, the {!<name>} references are not set properly. For instance: let f () = () type t = [`A (** start {!f} between {!g} end *)] let g () = () Gives: [...] <code class="type">[ `A <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >start <code class="code">f</code> between <code class="code">g</code> end</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> ]</code> [...] "href" are missing :/ EDIT: fixed in FIX_ocamldoc_cross_referencing.patch. By the way, it removes a lot of code in Odoc_print, 'cause I was being moron when I thought Printtyp had to be copied. It also removes more useless debugging calls, and improves a few names. |
|
(0004139) jm (reporter) 2007-08-18 23:29 edited on: 2007-08-20 00:27 |
GLOBAL_ocamldoc_type_manifest_comments.patch sums up all the previous patches. 5/ Due to my lack of reflexion, nested polymorphic variant types completely mess up the comments. Example 1: module X = struct type x = [`A (** X.x A *)] end type x = [`A (** x A *)] open X type t = [ x (** t x *) | `B (** t B *)] Gives: module X : sig type x = [ `A (* X.x A *) ] end type x = [ `A (* x A *) ] type t = [ `A (* x A t x *) <--- the "x A" should be "X.x A" | `B (* t B *) ] Exemple 2: type s = [`A (** s A *)] module M = struct type u = [ s (** M.u s *) | `B (** M.u B *)] end Currently end up on an [assert false]. Should produce: module M : sig type u = [ `A (* s A M.u s *) | `B (* M.u B *) ] EDIT: fixed in FIX_ident_management.patch. It was sufficient to use the Odoc_env machinery... Besides, it improves a few names, and removes dependencies to non-existent files: odoc_outcometree.ml, odoc_btype.ml and odoc_ctype.ml, which were deprecated files in my repository I had forgotten to delete. And besides, http://caml.inria.fr/mantis/view.php?id=4366 [^] may bite too. |
|
(0004140) jm (reporter) 2007-08-20 00:29 edited on: 2007-08-21 08:19 |
Release candidate 5: ocamldoc-type_manifest_comments-rc5.patch sums up all the previous patches. 6/ nested p. v. types support is still too weak EDIT: improved in FIX_ocamldoc_nested_poly_var_types.patch but there are still problems with types in functors and [open] on an external module. |
|
(0004141) jm (reporter) 2007-08-21 08:20 |
Release candidate 6: ocamldoc-type_manifest_comments-rc6.patch sums up all the previous patches. |
|
(0004142) jm (reporter) 2007-08-22 17:27 |
So, as I read the source of ocamldoc and try to understand how it works, it seems that odoc_sig.ml and odoc_ast.ml are not aware of external modules. And that it is too much work for me to properly make them so. It's a shame because that easily allows completely wrong output. This, plus the lack of orthogonality between [module] and [module type], plus the weird/incomplete support of [open], [include] and functors make me deeply sad to the point of not using ocamldoc at all and get stuck with raw .mli/.ml, which, sure, do not have clickable-links, but which do not lie. I'll just add the last RC, which corrects a few things about comments in p. v. types and cross-referencing in functors. And wish courage to anyone desiring to improve/fix ocamldoc. |
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2007-07-18 09:54 | matt | New Issue | |
| 2007-08-13 09:22 | jm | Note Added: 0004134 | |
| 2007-08-13 09:22 | jm | Note Edited: 0004134 | |
| 2007-08-14 14:12 | jm | Note Edited: 0004134 | |
| 2007-08-16 18:33 | jm | File Added: ocamldoc_poly_var.patch | |
| 2007-08-16 18:44 | jm | Note Added: 0004137 | |
| 2007-08-16 18:55 | jm | Note Edited: 0004137 | |
| 2007-08-17 15:07 | jm | Note Added: 0004138 | |
| 2007-08-17 18:56 | jm | File Added: FIX_ocamldoc_poly_var_proxies.patch | |
| 2007-08-17 19:00 | jm | Note Edited: 0004138 | |
| 2007-08-17 19:01 | jm | Note Edited: 0004138 | |
| 2007-08-17 19:04 | jm | Note Edited: 0004138 | |
| 2007-08-18 13:41 | jm | File Added: FIX_ocamldoc_merge_of_type_manifest_comments.patch | |
| 2007-08-18 13:47 | jm | Note Edited: 0004138 | |
| 2007-08-18 18:40 | jm | Note Edited: 0004138 | |
| 2007-08-18 23:17 | jm | File Added: FIX_ocamldoc_cross_referencing.patch | |
| 2007-08-18 23:24 | jm | Note Edited: 0004138 | |
| 2007-08-18 23:25 | jm | File Added: GLOBAL_ocamldoc_type_manifest_comments.patch | |
| 2007-08-18 23:29 | jm | Note Added: 0004139 | |
| 2007-08-19 20:06 | jm | Note Edited: 0004139 | |
| 2007-08-20 00:10 | jm | File Added: FIX_ident_management.patch | |
| 2007-08-20 00:16 | jm | File Added: ocamldoc-type_manifest_comments-rc5.patch | |
| 2007-08-20 00:27 | jm | Note Edited: 0004139 | |
| 2007-08-20 00:29 | jm | Note Added: 0004140 | |
| 2007-08-21 08:14 | jm | File Added: FIX_ocamldoc_nested_poly_var_types.patch | |
| 2007-08-21 08:15 | jm | File Added: ocamldoc-type_manifest_comments-rc6.patch | |
| 2007-08-21 08:19 | jm | Note Edited: 0004140 | |
| 2007-08-21 08:20 | jm | Note Added: 0004141 | |
| 2007-08-22 17:27 | jm | Note Added: 0004142 | |
| 2007-08-22 17:28 | jm | File Added: FIX_ocamldoc_functor_cross_ref_and_merge_labels.patch | |
| 2007-08-22 17:28 | jm | File Added: ocamldoc-type_manifest_comments-rc7.patch | |
| 2007-11-10 14:54 | xleroy | Status | new => assigned |
| 2007-11-10 14:54 | xleroy | Assigned To | => guesdon |
| 2008-01-21 10:28 | guesdon | Relationship added | has duplicate 0004482 |
| Copyright © 2000 - 2011 MantisBT Group |



