diff options
Diffstat (limited to 'ocamldoc')
45 files changed, 7463 insertions, 7463 deletions
diff --git a/ocamldoc/odoc.ml b/ocamldoc/odoc.ml index dba04f6e2..04bdedfd3 100644 --- a/ocamldoc/odoc.ml +++ b/ocamldoc/odoc.ml @@ -26,14 +26,14 @@ let (cmo_or_cma_opt, paths) = let rec iter (f_opt, inc) = function [] | _ :: [] -> (f_opt, inc) | "-g" :: file :: q when - ((Filename.check_suffix file "cmo") or - (Filename.check_suffix file "cma")) & - (f_opt = None) -> - iter (Some file, inc) q + ((Filename.check_suffix file "cmo") or + (Filename.check_suffix file "cma")) & + (f_opt = None) -> + iter (Some file, inc) q | "-i" :: dir :: q -> - iter (f_opt, inc @ [dir]) q + iter (f_opt, inc @ [dir]) q | _ :: q -> - iter (f_opt, inc) q + iter (f_opt, inc) q in iter (None, []) arg_list @@ -48,19 +48,19 @@ let _ = Dynlink.init (); Dynlink.allow_unsafe_modules true; try - Dynlink.add_available_units Odoc_crc.crc_unit_list ; - let _ = Dynlink.loadfile file in - () + Dynlink.add_available_units Odoc_crc.crc_unit_list ; + let _ = Dynlink.loadfile file in + () with - Dynlink.Error e -> - prerr_endline (Odoc_messages.load_file_error file (Dynlink.error_message e)) ; - exit 1 - | Not_found -> - prerr_endline (Odoc_messages.load_file_error file "Not_found"); - exit 1 - | Sys_error s -> - prerr_endline (Odoc_messages.load_file_error file s); - exit 1 + Dynlink.Error e -> + prerr_endline (Odoc_messages.load_file_error file (Dynlink.error_message e)) ; + exit 1 + | Not_found -> + prerr_endline (Odoc_messages.load_file_error file "Not_found"); + exit 1 + | Sys_error s -> + prerr_endline (Odoc_messages.load_file_error file s); + exit 1 let _ = print_DEBUG "Fin du chargement dynamique �ventuel" @@ -81,15 +81,15 @@ let loaded_modules = List.flatten (List.map (fun f -> - Odoc_info.verbose (Odoc_messages.loading f); - try - let l = Odoc_analyse.load_modules f in - Odoc_info.verbose Odoc_messages.ok; - l - with Failure s -> - prerr_endline s ; - incr Odoc_global.errors ; - [] + Odoc_info.verbose (Odoc_messages.loading f); + try + let l = Odoc_analyse.load_modules f in + Odoc_info.verbose Odoc_messages.ok; + l + with Failure s -> + prerr_endline s ; + incr Odoc_global.errors ; + [] ) !Odoc_args.load ) @@ -102,8 +102,8 @@ let _ = | Some f -> try Odoc_analyse.dump_modules f modules with Failure s -> - prerr_endline s ; - incr Odoc_global.errors + prerr_endline s ; + incr Odoc_global.errors let _ = match !Odoc_args.doc_generator with diff --git a/ocamldoc/odoc_analyse.ml b/ocamldoc/odoc_analyse.ml index c0d0faf7a..071e7c192 100644 --- a/ocamldoc/odoc_analyse.ml +++ b/ocamldoc/odoc_analyse.ml @@ -118,16 +118,16 @@ let process_implementation_file ppf sourcefile = with e -> match e with - Syntaxerr.Error err -> - fprintf Format.err_formatter "@[%a@]@." + Syntaxerr.Error err -> + fprintf Format.err_formatter "@[%a@]@." Syntaxerr.report_error err; - None, inputfile + None, inputfile | Failure s -> - prerr_endline s; - incr Odoc_global.errors ; - None, inputfile + prerr_endline s; + incr Odoc_global.errors ; + None, inputfile | e -> - raise e + raise e (** Analysis of an interface file. Returns (Some signature) if no error occured, else None and an error message is printed.*) @@ -204,57 +204,57 @@ let process_file ppf sourcefile = try let (parsetree_typedtree_opt, input_file) = process_implementation_file ppf sourcefile in match parsetree_typedtree_opt with - None -> - None + None -> + None | Some (parsetree, typedtree) -> - let file_module = Ast_analyser.analyse_typed_tree sourcefile !Location.input_name parsetree typedtree in + let file_module = Ast_analyser.analyse_typed_tree sourcefile !Location.input_name parsetree typedtree in - file_module.Odoc_module.m_top_deps <- Odoc_dep.impl_dependencies parsetree ; + file_module.Odoc_module.m_top_deps <- Odoc_dep.impl_dependencies parsetree ; - if !Odoc_args.verbose then - ( - print_string Odoc_messages.ok; - print_newline () - ); - remove_preprocessed input_file; - Some file_module + if !Odoc_args.verbose then + ( + print_string Odoc_messages.ok; + print_newline () + ); + remove_preprocessed input_file; + Some file_module with | Sys_error s | Failure s -> - prerr_endline s ; - incr Odoc_global.errors ; - None + prerr_endline s ; + incr Odoc_global.errors ; + None | e -> - process_error e ; - incr Odoc_global.errors ; - None + process_error e ; + incr Odoc_global.errors ; + None ) else if Filename.check_suffix sourcefile "mli" then ( try - let (ast, signat, input_file) = process_interface_file ppf sourcefile in - let file_module = Sig_analyser.analyse_signature sourcefile !Location.input_name ast signat in - - file_module.Odoc_module.m_top_deps <- Odoc_dep.intf_dependencies ast ; - - if !Odoc_args.verbose then - ( - print_string Odoc_messages.ok; - print_newline () - ); - remove_preprocessed input_file; - Some file_module + let (ast, signat, input_file) = process_interface_file ppf sourcefile in + let file_module = Sig_analyser.analyse_signature sourcefile !Location.input_name ast signat in + + file_module.Odoc_module.m_top_deps <- Odoc_dep.intf_dependencies ast ; + + if !Odoc_args.verbose then + ( + print_string Odoc_messages.ok; + print_newline () + ); + remove_preprocessed input_file; + Some file_module with | Sys_error s | Failure s -> - prerr_endline s; - incr Odoc_global.errors ; - None + prerr_endline s; + incr Odoc_global.errors ; + None | e -> - process_error e ; - incr Odoc_global.errors ; - None + process_error e ; + incr Odoc_global.errors ; + None ) else ( @@ -267,10 +267,10 @@ let rec remove_class_elements_after_stop eles = [] -> [] | ele :: q -> match ele with - Odoc_class.Class_comment [ Odoc_types.Raw "/*" ] -> [] - | Odoc_class.Class_attribute _ - | Odoc_class.Class_method _ - | Odoc_class.Class_comment _ -> ele :: (remove_class_elements_after_stop q) + Odoc_class.Class_comment [ Odoc_types.Raw "/*" ] -> [] + | Odoc_class.Class_attribute _ + | Odoc_class.Class_method _ + | Odoc_class.Class_comment _ -> ele :: (remove_class_elements_after_stop q) (** Remove the class elements after the stop special comment in a class kind. *) let rec remove_class_elements_after_stop_in_class_kind k = @@ -281,7 +281,7 @@ let rec remove_class_elements_after_stop_in_class_kind k = | Odoc_class.Class_constr _ -> k | Odoc_class.Class_constraint (k1, ctk) -> Odoc_class.Class_constraint (remove_class_elements_after_stop_in_class_kind k1, - remove_class_elements_after_stop_in_class_type_kind ctk) + remove_class_elements_after_stop_in_class_type_kind ctk) (** Remove the class elements after the stop special comment in a class type kind. *) and remove_class_elements_after_stop_in_class_type_kind tk = @@ -298,28 +298,28 @@ let rec remove_module_elements_after_stop eles = [] -> [] | ele :: q -> match ele with - Odoc_module.Element_module_comment [ Odoc_types.Raw "/*" ] -> [] - | Odoc_module.Element_module_comment _ -> - ele :: (f q) - | Odoc_module.Element_module m -> - m.Odoc_module.m_kind <- remove_module_elements_after_stop_in_module_kind m.Odoc_module.m_kind ; - (Odoc_module.Element_module m) :: (f q) - | Odoc_module.Element_module_type mt -> - mt.Odoc_module.mt_kind <- Odoc_misc.apply_opt - remove_module_elements_after_stop_in_module_type_kind mt.Odoc_module.mt_kind ; - (Odoc_module.Element_module_type mt) :: (f q) + Odoc_module.Element_module_comment [ Odoc_types.Raw "/*" ] -> [] + | Odoc_module.Element_module_comment _ -> + ele :: (f q) + | Odoc_module.Element_module m -> + m.Odoc_module.m_kind <- remove_module_elements_after_stop_in_module_kind m.Odoc_module.m_kind ; + (Odoc_module.Element_module m) :: (f q) + | Odoc_module.Element_module_type mt -> + mt.Odoc_module.mt_kind <- Odoc_misc.apply_opt + remove_module_elements_after_stop_in_module_type_kind mt.Odoc_module.mt_kind ; + (Odoc_module.Element_module_type mt) :: (f q) | Odoc_module.Element_included_module _ -> - ele :: (f q) + ele :: (f q) | Odoc_module.Element_class c -> - c.Odoc_class.cl_kind <- remove_class_elements_after_stop_in_class_kind c.Odoc_class.cl_kind ; - (Odoc_module.Element_class c) :: (f q) + c.Odoc_class.cl_kind <- remove_class_elements_after_stop_in_class_kind c.Odoc_class.cl_kind ; + (Odoc_module.Element_class c) :: (f q) | Odoc_module.Element_class_type ct -> - ct.Odoc_class.clt_kind <- remove_class_elements_after_stop_in_class_type_kind ct.Odoc_class.clt_kind ; - (Odoc_module.Element_class_type ct) :: (f q) + ct.Odoc_class.clt_kind <- remove_class_elements_after_stop_in_class_type_kind ct.Odoc_class.clt_kind ; + (Odoc_module.Element_class_type ct) :: (f q) | Odoc_module.Element_value _ | Odoc_module.Element_exception _ | Odoc_module.Element_type _ -> - ele :: (f q) + ele :: (f q) (** Remove the module elements after the stop special comment, in the given module kind. *) @@ -331,12 +331,12 @@ and remove_module_elements_after_stop_in_module_kind k = Odoc_module.Module_functor (params, remove_module_elements_after_stop_in_module_kind k2) | Odoc_module.Module_apply (k1, k2) -> Odoc_module.Module_apply (remove_module_elements_after_stop_in_module_kind k1, - remove_module_elements_after_stop_in_module_kind k2) + remove_module_elements_after_stop_in_module_kind k2) | Odoc_module.Module_with (mtkind, s) -> Odoc_module.Module_with (remove_module_elements_after_stop_in_module_type_kind mtkind, s) | Odoc_module.Module_constraint (k2, mtkind) -> Odoc_module.Module_constraint (remove_module_elements_after_stop_in_module_kind k2, - remove_module_elements_after_stop_in_module_type_kind mtkind) + remove_module_elements_after_stop_in_module_type_kind mtkind) (** Remove the module elements after the stop special comment, in the given module type kind. *) and remove_module_elements_after_stop_in_module_type_kind tk = @@ -364,17 +364,17 @@ let analyse_files ?(init=[]) files = init @ (List.fold_left (fun acc -> fun file -> - try - match process_file Format.err_formatter file with - None -> - acc - | Some m -> - acc @ [ m ] - with - Failure s -> - prerr_endline s ; - incr Odoc_global.errors ; - acc + try + match process_file Format.err_formatter file with + None -> + acc + | Some m -> + acc @ [ m ] + with + Failure s -> + prerr_endline s ; + incr Odoc_global.errors ; + acc ) [] files diff --git a/ocamldoc/odoc_analyse.mli b/ocamldoc/odoc_analyse.mli index 845b1c4d8..4b1254b8d 100644 --- a/ocamldoc/odoc_analyse.mli +++ b/ocamldoc/odoc_analyse.mli @@ -19,7 +19,7 @@ val analyse_files : ?init: Odoc_module.t_module list -> string list -> - Odoc_module.t_module list + Odoc_module.t_module list (** Dump of a list of modules into a file. @raise Failure if an error occurs.*) diff --git a/ocamldoc/odoc_args.ml b/ocamldoc/odoc_args.ml index b78f8bf12..fb3e159ec 100644 --- a/ocamldoc/odoc_args.ml +++ b/ocamldoc/odoc_args.ml @@ -45,9 +45,9 @@ let analyse_option_string l s = List.fold_left (fun acc -> fun ((c,_), v) -> if String.contains s c then - acc @ v + acc @ v else - acc) + acc) [] l @@ -152,13 +152,13 @@ let add_hidden_modules s = (fun n -> let name = Str.global_replace (Str.regexp "[ \n\r\t]+") "" n in match name with - "" -> () - | _ -> - match name.[0] with - 'A'..'Z' -> hidden_modules := name :: !hidden_modules - | _ -> - incr Odoc_global.errors; - prerr_endline (Odoc_messages.not_a_module_name name) + "" -> () + | _ -> + match name.[0] with + 'A'..'Z' -> hidden_modules := name :: !hidden_modules + | _ -> + incr Odoc_global.errors; + prerr_endline (Odoc_messages.not_a_module_name name) ) l @@ -265,10 +265,10 @@ let add_option o = let rec iter = function [] -> [o] | (s2,f,m) :: q -> - if s = s2 then - o :: q - else - (s2,f,m) :: (iter q) + if s = s2 then + o :: q + else + (s2,f,m) :: (iter q) in options := iter !options diff --git a/ocamldoc/odoc_args.mli b/ocamldoc/odoc_args.mli index de4948857..4f660854c 100644 --- a/ocamldoc/odoc_args.mli +++ b/ocamldoc/odoc_args.mli @@ -159,8 +159,8 @@ val add_option : string * Arg.spec * string -> unit val parse : html_generator:doc_generator -> latex_generator:doc_generator -> - texi_generator:doc_generator -> - man_generator:doc_generator -> - dot_generator:doc_generator -> - unit + texi_generator:doc_generator -> + man_generator:doc_generator -> + dot_generator:doc_generator -> + unit diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml index 466fc6e71..c10d771e6 100644 --- a/ocamldoc/odoc_ast.ml +++ b/ocamldoc/odoc_ast.ml @@ -43,15 +43,15 @@ let simple_blank = "[ \013\009\012]" module Typedtree_search = struct type ele = - | M of string - | MT of string - | T of string - | C of string - | CT of string - | E of string - | ER of string - | P of string - | IM of string + | M of string + | MT of string + | T of string + | C of string + | CT of string + | E of string + | ER of string + | P of string + | IM of string type tab = (ele, Typedtree.structure_item) Hashtbl.t type tab_values = (Odoc_module.Name.t, Typedtree.pattern * Typedtree.expression) Hashtbl.t @@ -65,45 +65,45 @@ module Typedtree_search = let add_to_hashes table table_values tt = match tt with | Typedtree.Tstr_module (ident, _) -> - Hashtbl.add table (M (Name.from_ident ident)) tt - | Typedtree.Tstr_modtype (ident, _) -> - Hashtbl.add table (MT (Name.from_ident ident)) tt - | Typedtree.Tstr_exception (ident, _) -> - Hashtbl.add table (E (Name.from_ident ident)) tt - | Typedtree.Tstr_exn_rebind (ident, _) -> - Hashtbl.add table (ER (Name.from_ident ident)) tt - | Typedtree.Tstr_type ident_type_decl_list -> - List.iter - (fun (id, e) -> - Hashtbl.add table (T (Name.from_ident id)) - (Typedtree.Tstr_type [(id,e)])) - ident_type_decl_list - | Typedtree.Tstr_class info_list -> - List.iter - (fun ((id,_,_,_) as ci) -> - Hashtbl.add table (C (Name.from_ident id)) - (Typedtree.Tstr_class [ci])) - info_list - | Typedtree.Tstr_cltype info_list -> - List.iter - (fun ((id,_) as ci) -> - Hashtbl.add table - (CT (Name.from_ident id)) - (Typedtree.Tstr_cltype [ci])) - info_list - | Typedtree.Tstr_value (_, pat_exp_list) -> - List.iter - (fun (pat,exp) -> - match iter_val_pattern pat.Typedtree.pat_desc with - None -> () - | Some n -> Hashtbl.add table_values n (pat,exp) - ) - pat_exp_list - | Typedtree.Tstr_primitive (ident, _) -> - Hashtbl.add table (P (Name.from_ident ident)) tt - | Typedtree.Tstr_open _ -> () - | Typedtree.Tstr_include _ -> () - | Typedtree.Tstr_eval _ -> () + Hashtbl.add table (M (Name.from_ident ident)) tt + | Typedtree.Tstr_modtype (ident, _) -> + Hashtbl.add table (MT (Name.from_ident ident)) tt + | Typedtree.Tstr_exception (ident, _) -> + Hashtbl.add table (E (Name.from_ident ident)) tt + | Typedtree.Tstr_exn_rebind (ident, _) -> + Hashtbl.add table (ER (Name.from_ident ident)) tt + | Typedtree.Tstr_type ident_type_decl_list -> + List.iter + (fun (id, e) -> + Hashtbl.add table (T (Name.from_ident id)) + (Typedtree.Tstr_type [(id,e)])) + ident_type_decl_list + | Typedtree.Tstr_class info_list -> + List.iter + (fun ((id,_,_,_) as ci) -> + Hashtbl.add table (C (Name.from_ident id)) + (Typedtree.Tstr_class [ci])) + info_list + | Typedtree.Tstr_cltype info_list -> + List.iter + (fun ((id,_) as ci) -> + Hashtbl.add table + (CT (Name.from_ident id)) + (Typedtree.Tstr_cltype [ci])) + info_list + | Typedtree.Tstr_value (_, pat_exp_list) -> + List.iter + (fun (pat,exp) -> + match iter_val_pattern pat.Typedtree.pat_desc with + None -> () + | Some n -> Hashtbl.add table_values n (pat,exp) + ) + pat_exp_list + | Typedtree.Tstr_primitive (ident, _) -> + Hashtbl.add table (P (Name.from_ident ident)) tt + | Typedtree.Tstr_open _ -> () + | Typedtree.Tstr_include _ -> () + | Typedtree.Tstr_eval _ -> () let tables typedtree = let t = Hashtbl.create 13 in @@ -113,8 +113,8 @@ module Typedtree_search = let search_module table name = match Hashtbl.find table (M name) with - (Typedtree.Tstr_module (_, module_expr)) -> module_expr - | _ -> assert false + (Typedtree.Tstr_module (_, module_expr)) -> module_expr + | _ -> assert false let search_module_type table name = match Hashtbl.find table (MT name) with @@ -129,69 +129,69 @@ module Typedtree_search = let search_exception_rebind table name = match Hashtbl.find table (ER name) with | (Typedtree.Tstr_exn_rebind (_, p)) -> p - | _ -> assert false + | _ -> assert false let search_type_declaration table name = match Hashtbl.find table (T name) with | (Typedtree.Tstr_type [(_,decl)]) -> decl - | _ -> assert false + | _ -> assert false let search_class_exp table name = match Hashtbl.find table (C name) with | (Typedtree.Tstr_class [(_,_,_,ce)]) -> - ( - try - let type_decl = search_type_declaration table name in - (ce, type_decl.Types.type_params) - with - Not_found -> - (ce, []) - ) - | _ -> assert false + ( + try + let type_decl = search_type_declaration table name in + (ce, type_decl.Types.type_params) + with + Not_found -> + (ce, []) + ) + | _ -> assert false let search_class_type_declaration table name = match Hashtbl.find table (CT name) with | (Typedtree.Tstr_cltype [(_,cltype_decl)]) -> cltype_decl - | _ -> assert false + | _ -> assert false let search_value table name = Hashtbl.find table name let search_primitive table name = match Hashtbl.find table (P name) with - Tstr_primitive (ident, val_desc) -> val_desc.Types.val_type - | _ -> assert false + Tstr_primitive (ident, val_desc) -> val_desc.Types.val_type + | _ -> assert false let get_nth_inherit_class_expr cls n = let rec iter cpt = function - | [] -> - raise Not_found - | Typedtree.Cf_inher (clexp, _, _) :: q -> - if n = cpt then clexp else iter (cpt+1) q - | _ :: q -> - iter cpt q + | [] -> + raise Not_found + | Typedtree.Cf_inher (clexp, _, _) :: q -> + if n = cpt then clexp else iter (cpt+1) q + | _ :: q -> + iter cpt q in iter 0 cls.Typedtree.cl_field let search_attribute_type cls name = let rec iter = function - | [] -> - raise Not_found - | Typedtree.Cf_val (_, ident, exp) :: q - when Name.from_ident ident = name -> - exp.Typedtree.exp_type - | _ :: q -> - iter q + | [] -> + raise Not_found + | Typedtree.Cf_val (_, ident, exp) :: q + when Name.from_ident ident = name -> + exp.Typedtree.exp_type + | _ :: q -> + iter q in iter cls.Typedtree.cl_field let search_method_expression cls name = let rec iter = function - | [] -> - raise Not_found - | Typedtree.Cf_meth (label, exp) :: q when label = name -> - exp - | _ :: q -> - iter q + | [] -> + raise Not_found + | Typedtree.Cf_meth (label, exp) :: q when label = name -> + exp + | _ :: q -> + iter q in iter cls.Typedtree.cl_field end @@ -230,42 +230,42 @@ module Analyser = *) let tt_param_info_from_pattern env f_desc pat = let rec iter_pattern pat = - match pat.pat_desc with - Typedtree.Tpat_var ident -> - let name = Name.from_ident ident in - Simple_name { sn_name = name ; - sn_text = f_desc name ; - sn_type = Odoc_env.subst_type env pat.pat_type - } - - | Typedtree.Tpat_alias (pat, _) -> - iter_pattern pat - - | Typedtree.Tpat_tuple patlist -> - Tuple - (List.map iter_pattern patlist, - Odoc_env.subst_type env pat.pat_type) - - | Typedtree.Tpat_construct (cons_desc, _) when - (* we give a name to the parameter only if it unit *) - (match cons_desc.cstr_res.desc with - Tconstr (p, _, _) -> - Path.same p Predef.path_unit - | _ -> - false) - -> - (* a () argument, it never has description *) - Simple_name { sn_name = "()" ; - sn_text = None ; - sn_type = Odoc_env.subst_type env pat.pat_type - } - - | _ -> + match pat.pat_desc with + Typedtree.Tpat_var ident -> + let name = Name.from_ident ident in + Simple_name { sn_name = name ; + sn_text = f_desc name ; + sn_type = Odoc_env.subst_type env pat.pat_type + } + + | Typedtree.Tpat_alias (pat, _) -> + iter_pattern pat + + | Typedtree.Tpat_tuple patlist -> + Tuple + (List.map iter_pattern patlist, + Odoc_env.subst_type env pat.pat_type) + + | Typedtree.Tpat_construct (cons_desc, _) when + (* we give a name to the parameter only if it unit *) + (match cons_desc.cstr_res.desc with + Tconstr (p, _, _) -> + Path.same p Predef.path_unit + | _ -> + false) + -> + (* a () argument, it never has description *) + Simple_name { sn_name = "()" ; + sn_text = None ; + sn_type = Odoc_env.subst_type env pat.pat_type + } + + | _ -> (* implicit pattern matching -> anonymous parameter *) - Simple_name { sn_name = "()" ; - sn_text = None ; - sn_type = Odoc_env.subst_type env pat.pat_type - } + Simple_name { sn_name = "()" ; + sn_text = None ; + sn_type = Odoc_env.subst_type env pat.pat_type + } in iter_pattern pat @@ -273,119 +273,119 @@ module Analyser = the (pattern, expression) structures encountered. *) let rec tt_analyse_function_parameters env current_comment_opt pat_exp_list = match pat_exp_list with - [] -> - (* This case means we have a 'function' without pattern, that's impossible *) - raise (Failure "tt_analyse_function_parameters: 'function' without pattern") + [] -> + (* This case means we have a 'function' without pattern, that's impossible *) + raise (Failure "tt_analyse_function_parameters: 'function' without pattern") - | (pattern_param, exp) :: second_ele :: q -> + | (pattern_param, exp) :: second_ele :: q -> (* implicit pattern matching -> anonymous parameter and no more parameter *) - (* A VOIR : le label ? *) - let parameter = Odoc_parameter.Tuple ([], Odoc_env.subst_type env pattern_param.pat_type) in - [ parameter ] + (* A VOIR : le label ? *) + let parameter = Odoc_parameter.Tuple ([], Odoc_env.subst_type env pattern_param.pat_type) in + [ parameter ] | (pattern_param, func_body) :: [] -> - let parameter = - tt_param_info_from_pattern - env - (Odoc_parameter.desc_from_info_opt current_comment_opt) - pattern_param + let parameter = + tt_param_info_from_pattern + env + (Odoc_parameter.desc_from_info_opt current_comment_opt) + pattern_param - in + in (* For optional parameters with a default value, a special treatment is required *) (* we look if the name of the parameter we just add is "*opt*", which means - that there is a let param_name = ... in ... just right now *) - let (p, next_exp) = - match parameter with - Simple_name { sn_name = "*opt*" } -> - ( - ( - match func_body.exp_desc with - Typedtree.Texp_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, func_body2) -> - let name = Name.from_ident id in - let new_param = Simple_name - { sn_name = name ; - sn_text = Odoc_parameter.desc_from_info_opt current_comment_opt name ; - sn_type = Odoc_env.subst_type env exp.exp_type - } - in - (new_param, func_body2) - | _ -> - print_DEBUG3 "Pas le bon filtre pour le param�tre optionnel avec valeur par d�faut."; - (parameter, func_body) - ) - ) - | _ -> - (parameter, func_body) - in + that there is a let param_name = ... in ... just right now *) + let (p, next_exp) = + match parameter with + Simple_name { sn_name = "*opt*" } -> + ( + ( + match func_body.exp_desc with + Typedtree.Texp_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, func_body2) -> + let name = Name.from_ident id in + let new_param = Simple_name + { sn_name = name ; + sn_text = Odoc_parameter.desc_from_info_opt current_comment_opt name ; + sn_type = Odoc_env.subst_type env exp.exp_type + } + in + (new_param, func_body2) + | _ -> + print_DEBUG3 "Pas le bon filtre pour le param�tre optionnel avec valeur par d�faut."; + (parameter, func_body) + ) + ) + | _ -> + (parameter, func_body) + in (* continue if the body is still a function *) - match next_exp.exp_desc with - Texp_function (pat_exp_list, _) -> - p :: (tt_analyse_function_parameters env current_comment_opt pat_exp_list) - | _ -> + match next_exp.exp_desc with + Texp_function (pat_exp_list, _) -> + p :: (tt_analyse_function_parameters env current_comment_opt pat_exp_list) + | _ -> (* something else ; no more parameter *) - [ p ] + [ p ] (** Analysis of a Tstr_value from the typedtree. Create and return a list of [t_value]. - @raise Failure if an error occurs.*) + @raise Failure if an error occurs.*) let tt_analyse_value env current_module_name comment_opt loc pat_exp rec_flag = let (pat, exp) = pat_exp in match (pat.pat_desc, exp.exp_desc) with - (Typedtree.Tpat_var ident, Typedtree.Texp_function (pat_exp_list2, partial)) -> + (Typedtree.Tpat_var ident, Typedtree.Texp_function (pat_exp_list2, partial)) -> (* a new function is defined *) - let name_pre = Name.from_ident ident in - let name = Name.parens_if_infix name_pre in - let complete_name = Name.concat current_module_name name in - (* create the value *) - let new_value = { - val_name = complete_name ; - val_info = comment_opt ; - val_type = Odoc_env.subst_type env pat.Typedtree.pat_type ; - val_recursive = rec_flag = Asttypes.Recursive ; - val_parameters = tt_analyse_function_parameters env comment_opt pat_exp_list2 ; - val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; - val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } - in - [ new_value ] - + let name_pre = Name.from_ident ident in + let name = Name.parens_if_infix name_pre in + let complete_name = Name.concat current_module_name name in + (* create the value *) + let new_value = { + val_name = complete_name ; + val_info = comment_opt ; + val_type = Odoc_env.subst_type env pat.Typedtree.pat_type ; + val_recursive = rec_flag = Asttypes.Recursive ; + val_parameters = tt_analyse_function_parameters env comment_opt pat_exp_list2 ; + val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; + val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } + in + [ new_value ] + | (Typedtree.Tpat_var ident, _) -> - (* a new value is defined *) - let name_pre = Name.from_ident ident in - let name = Name.parens_if_infix name_pre in - let complete_name = Name.concat current_module_name name in - let new_value = { - val_name = complete_name ; - val_info = comment_opt ; - val_type = Odoc_env.subst_type env pat.Typedtree.pat_type ; - val_recursive = rec_flag = Asttypes.Recursive ; - val_parameters = [] ; - val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; - val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } - in - [ new_value ] - + (* a new value is defined *) + let name_pre = Name.from_ident ident in + let name = Name.parens_if_infix name_pre in + let complete_name = Name.concat current_module_name name in + let new_value = { + val_name = complete_name ; + val_info = comment_opt ; + val_type = Odoc_env.subst_type env pat.Typedtree.pat_type ; + val_recursive = rec_flag = Asttypes.Recursive ; + val_parameters = [] ; + val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; + val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } + in + [ new_value ] + | (Typedtree.Tpat_tuple lpat, _) -> - (* new identifiers are defined *) - (* A VOIR : by now we don't accept to have global variables defined in tuples *) - [] - + (* new identifiers are defined *) + (* A VOIR : by now we don't accept to have global variables defined in tuples *) + [] + | _ -> - (* something else, we don't care ? A VOIR *) - [] + (* something else, we don't care ? A VOIR *) + [] (** This function takes a Typedtree.class_expr and returns a string which can stand for the class name. The name can be "object ... end" if the class expression is not an ident or a class constraint or a class apply. *) let rec tt_name_of_class_expr clexp = match clexp.Typedtree.cl_desc with - Typedtree.Tclass_ident p -> Name.from_path p - | Typedtree.Tclass_constraint (class_expr, _, _, _) - | Typedtree.Tclass_apply (class_expr, _) -> tt_name_of_class_expr class_expr + Typedtree.Tclass_ident p -> Name.from_path p + | Typedtree.Tclass_constraint (class_expr, _, _, _) + | Typedtree.Tclass_apply (class_expr, _) -> tt_name_of_class_expr class_expr (* - | Typedtree.Tclass_fun (_, _, class_expr, _) -> tt_name_of_class_expr class_expr - | Typedtree.Tclass_let (_,_,_, class_expr) -> tt_name_of_class_expr class_expr + | Typedtree.Tclass_fun (_, _, class_expr, _) -> tt_name_of_class_expr class_expr + | Typedtree.Tclass_let (_,_,_, class_expr) -> tt_name_of_class_expr class_expr *) - | _ -> Odoc_messages.object_end + | _ -> Odoc_messages.object_end (** Analysis of a method expression to get the method parameters. @param first indicates if we're analysing the method for @@ -394,358 +394,358 @@ module Analyser = *) let rec tt_analyse_method_expression env current_method_name comment_opt ?(first=true) exp = match exp.Typedtree.exp_desc with - Typedtree.Texp_function (pat_exp_list, _) -> - ( - match pat_exp_list with - [] -> - (* it is not a function since there are no parameters *) - (* we can't get here normally *) - raise (Failure (Odoc_messages.bad_tree^" "^(Odoc_messages.method_without_param current_method_name))) - | l -> - match l with - [] -> - (* cas impossible, on l'a filtr� avant *) - assert false - | (pattern_param, exp) :: second_ele :: q -> + Typedtree.Texp_function (pat_exp_list, _) -> + ( + match pat_exp_list with + [] -> + (* it is not a function since there are no parameters *) + (* we can't get here normally *) + raise (Failure (Odoc_messages.bad_tree^" "^(Odoc_messages.method_without_param current_method_name))) + | l -> + match l with + [] -> + (* cas impossible, on l'a filtr� avant *) + assert false + | (pattern_param, exp) :: second_ele :: q -> (* implicit pattern matching -> anonymous parameter *) - (* Note : We can't match this pattern if it is the first call to the function. *) - let new_param = Simple_name - { sn_name = "??" ; sn_text = None; - sn_type = Odoc_env.subst_type env pattern_param.Typedtree.pat_type } - in - [ new_param ] - - | (pattern_param, body) :: [] -> - (* if this is the first call to the function, this is the first parameter and we skip it *) - if not first then - ( - let parameter = - tt_param_info_from_pattern - env - (Odoc_parameter.desc_from_info_opt comment_opt) - pattern_param - in + (* Note : We can't match this pattern if it is the first call to the function. *) + let new_param = Simple_name + { sn_name = "??" ; sn_text = None; + sn_type = Odoc_env.subst_type env pattern_param.Typedtree.pat_type } + in + [ new_param ] + + | (pattern_param, body) :: [] -> + (* if this is the first call to the function, this is the first parameter and we skip it *) + if not first then + ( + let parameter = + tt_param_info_from_pattern + env + (Odoc_parameter.desc_from_info_opt comment_opt) + pattern_param + in (* For optional parameters with a default value, a special treatment is required. *) (* We look if the name of the parameter we just add is "*opt*", which means - that there is a let param_name = ... in ... just right now. *) - let (current_param, next_exp) = - match parameter with - Simple_name { sn_name = "*opt*"} -> - ( - ( - match body.exp_desc with - Typedtree.Texp_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, body2) -> - let name = Name.from_ident id in - let new_param = Simple_name - { sn_name = name ; - sn_text = Odoc_parameter.desc_from_info_opt comment_opt name ; - sn_type = Odoc_env.subst_type env exp.Typedtree.exp_type ; - } - in - (new_param, body2) - | _ -> - print_DEBUG3 "Pas le bon filtre pour le param�tre optionnel avec valeur par d�faut."; - (parameter, body) - ) - ) - | _ -> - (* no *opt* parameter, we add the parameter then continue *) - (parameter, body) - in - current_param :: (tt_analyse_method_expression env current_method_name comment_opt ~first: false next_exp) - ) - else - tt_analyse_method_expression env current_method_name comment_opt ~first: false body - ) + that there is a let param_name = ... in ... just right now. *) + let (current_param, next_exp) = + match parameter with + Simple_name { sn_name = "*opt*"} -> + ( + ( + match body.exp_desc with + Typedtree.Texp_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, body2) -> + let name = Name.from_ident id in + let new_param = Simple_name + { sn_name = name ; + sn_text = Odoc_parameter.desc_from_info_opt comment_opt name ; + sn_type = Odoc_env.subst_type env exp.Typedtree.exp_type ; + } + in + (new_param, body2) + | _ -> + print_DEBUG3 "Pas le bon filtre pour le param�tre optionnel avec valeur par d�faut."; + (parameter, body) + ) + ) + | _ -> + (* no *opt* parameter, we add the parameter then continue *) + (parameter, body) + in + current_param :: (tt_analyse_method_expression env current_method_name comment_opt ~first: false next_exp) + ) + else + tt_analyse_method_expression env current_method_name comment_opt ~first: false body + ) | _ -> - (* no more parameter *) - [] + (* no more parameter *) + [] (** Analysis of a [Parsetree.class_struture] and a [Typedtree.class_structure] to get a couple (inherited classes, class elements). *) let analyse_class_structure env current_class_name tt_class_sig last_pos pos_limit p_cls tt_cls = let rec iter acc_inher acc_fields last_pos = function - | [] -> - let s = get_string_of_file last_pos pos_limit in - let (_, ele_coms) = My_ir.all_special !file_name s in - let ele_comments = - List.fold_left - (fun acc -> fun sc -> - match sc.Odoc_types.i_desc with - None -> - acc - | Some t -> - acc @ [Class_comment t]) - [] - ele_coms - in - (acc_inher, acc_fields @ ele_comments) - - | (Parsetree.Pcf_inher (p_clexp, _)) :: q -> - let tt_clexp = - let n = List.length acc_inher in - try Typedtree_search.get_nth_inherit_class_expr tt_cls n - with Not_found -> raise (Failure (Odoc_messages.inherit_classexp_not_found_in_typedtree n)) - in - let (info_opt, ele_comments) = get_comments_in_class last_pos p_clexp.Parsetree.pcl_loc.Location.loc_start in - let text_opt = match info_opt with None -> None | Some i -> i.Odoc_types.i_desc in - let name = tt_name_of_class_expr tt_clexp in - let inher = { ic_name = Odoc_env.full_class_or_class_type_name env name ; ic_class = None ; ic_text = text_opt } in - iter (acc_inher @ [ inher ]) (acc_fields @ ele_comments) - p_clexp.Parsetree.pcl_loc.Location.loc_end - q - - | (Parsetree.Pcf_val (label, mutable_flag, expression, loc)) :: q -> - let complete_name = Name.concat current_class_name label in - let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start in - let type_exp = - try Typedtree_search.search_attribute_type tt_cls label - with Not_found -> raise (Failure (Odoc_messages.attribute_not_found_in_typedtree complete_name)) - in - let att = - { - att_value = { val_name = complete_name ; - val_info = info_opt ; - val_type = Odoc_env.subst_type env type_exp ; - val_recursive = false ; - val_parameters = [] ; - val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; - val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } ; - att_mutable = mutable_flag = Asttypes.Mutable ; - } - in - iter acc_inher (acc_fields @ ele_comments @ [ Class_attribute att ]) loc.Location.loc_end q + | [] -> + let s = get_string_of_file last_pos pos_limit in + let (_, ele_coms) = My_ir.all_special !file_name s in + let ele_comments = + List.fold_left + (fun acc -> fun sc -> + match sc.Odoc_types.i_desc with + None -> + acc + | Some t -> + acc @ [Class_comment t]) + [] + ele_coms + in + (acc_inher, acc_fields @ ele_comments) + + | (Parsetree.Pcf_inher (p_clexp, _)) :: q -> + let tt_clexp = + let n = List.length acc_inher in + try Typedtree_search.get_nth_inherit_class_expr tt_cls n + with Not_found -> raise (Failure (Odoc_messages.inherit_classexp_not_found_in_typedtree n)) + in + let (info_opt, ele_comments) = get_comments_in_class last_pos p_clexp.Parsetree.pcl_loc.Location.loc_start in + let text_opt = match info_opt with None -> None | Some i -> i.Odoc_types.i_desc in + let name = tt_name_of_class_expr tt_clexp in + let inher = { ic_name = Odoc_env.full_class_or_class_type_name env name ; ic_class = None ; ic_text = text_opt } in + iter (acc_inher @ [ inher ]) (acc_fields @ ele_comments) + p_clexp.Parsetree.pcl_loc.Location.loc_end + q + + | (Parsetree.Pcf_val (label, mutable_flag, expression, loc)) :: q -> + let complete_name = Name.concat current_class_name label in + let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start in + let type_exp = + try Typedtree_search.search_attribute_type tt_cls label + with Not_found -> raise (Failure (Odoc_messages.attribute_not_found_in_typedtree complete_name)) + in + let att = + { + att_value = { val_name = complete_name ; + val_info = info_opt ; + val_type = Odoc_env.subst_type env type_exp ; + val_recursive = false ; + val_parameters = [] ; + val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; + val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } ; + att_mutable = mutable_flag = Asttypes.Mutable ; + } + in + iter acc_inher (acc_fields @ ele_comments @ [ Class_attribute att ]) loc.Location.loc_end q - | (Parsetree.Pcf_virt (label, private_flag, _, loc)) :: q -> - let complete_name = Name.concat current_class_name label in - let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start in - let met_type = - try Odoc_sig.Signature_search.search_method_type label tt_class_sig - with Not_found -> raise (Failure (Odoc_messages.method_type_not_found current_class_name label)) - in - let real_type = - match met_type.Types.desc with - Tarrow (_, _, t, _) -> - t - | _ -> - (* ?!? : not an arrow type ! return the original type *) - met_type - in - let met = - { - met_value = { val_name = complete_name ; - val_info = info_opt ; - val_type = Odoc_env.subst_type env real_type ; - val_recursive = false ; - val_parameters = [] ; - val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; - val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } ; - met_private = private_flag = Asttypes.Private ; - met_virtual = true ; - } - in - (* update the parameter description *) - Odoc_value.update_value_parameters_text met.met_value; - - iter acc_inher (acc_fields @ ele_comments @ [ Class_method met ]) loc.Location.loc_end q - - | (Parsetree.Pcf_meth (label, private_flag, _, loc)) :: q -> - let complete_name = Name.concat current_class_name label in - let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start in - let exp = - try Typedtree_search.search_method_expression tt_cls label - with Not_found -> raise (Failure (Odoc_messages.method_not_found_in_typedtree complete_name)) - in - let real_type = - match exp.exp_type.desc with - Tarrow (_, _, t,_) -> - t - | _ -> - (* ?!? : not an arrow type ! return the original type *) - exp.Typedtree.exp_type - in - let met = - { - met_value = { val_name = complete_name ; - val_info = info_opt ; - val_type = Odoc_env.subst_type env real_type ; - val_recursive = false ; - val_parameters = tt_analyse_method_expression env complete_name info_opt exp ; - val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; - val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } ; - met_private = private_flag = Asttypes.Private ; - met_virtual = false ; - } - in - (* update the parameter description *) - Odoc_value.update_value_parameters_text met.met_value; - - iter acc_inher (acc_fields @ ele_comments @ [ Class_method met ]) loc.Location.loc_end q - - | Parsetree.Pcf_cstr (_, _, loc) :: q -> - (* don't give a $*%@ ! *) - iter acc_inher acc_fields loc.Location.loc_end q - - | Parsetree.Pcf_let (_, _, loc) :: q -> - (* don't give a $*%@ ! *) - iter acc_inher acc_fields loc.Location.loc_end q - - | (Parsetree.Pcf_init exp) :: q -> - iter acc_inher acc_fields exp.Parsetree.pexp_loc.Location.loc_end q + | (Parsetree.Pcf_virt (label, private_flag, _, loc)) :: q -> + let complete_name = Name.concat current_class_name label in + let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start in + let met_type = + try Odoc_sig.Signature_search.search_method_type label tt_class_sig + with Not_found -> raise (Failure (Odoc_messages.method_type_not_found current_class_name label)) + in + let real_type = + match met_type.Types.desc with + Tarrow (_, _, t, _) -> + t + | _ -> + (* ?!? : not an arrow type ! return the original type *) + met_type + in + let met = + { + met_value = { val_name = complete_name ; + val_info = info_opt ; + val_type = Odoc_env.subst_type env real_type ; + val_recursive = false ; + val_parameters = [] ; + val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; + val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } ; + met_private = private_flag = Asttypes.Private ; + met_virtual = true ; + } + in + (* update the parameter description *) + Odoc_value.update_value_parameters_text met.met_value; + + iter acc_inher (acc_fields @ ele_comments @ [ Class_method met ]) loc.Location.loc_end q + + | (Parsetree.Pcf_meth (label, private_flag, _, loc)) :: q -> + let complete_name = Name.concat current_class_name label in + let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start in + let exp = + try Typedtree_search.search_method_expression tt_cls label + with Not_found -> raise (Failure (Odoc_messages.method_not_found_in_typedtree complete_name)) + in + let real_type = + match exp.exp_type.desc with + Tarrow (_, _, t,_) -> + t + | _ -> + (* ?!? : not an arrow type ! return the original type *) + exp.Typedtree.exp_type + in + let met = + { + met_value = { val_name = complete_name ; + val_info = info_opt ; + val_type = Odoc_env.subst_type env real_type ; + val_recursive = false ; + val_parameters = tt_analyse_method_expression env complete_name info_opt exp ; + val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; + val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } ; + met_private = private_flag = Asttypes.Private ; + met_virtual = false ; + } + in + (* update the parameter description *) + Odoc_value.update_value_parameters_text met.met_value; + + iter acc_inher (acc_fields @ ele_comments @ [ Class_method met ]) loc.Location.loc_end q + + | Parsetree.Pcf_cstr (_, _, loc) :: q -> + (* don't give a $*%@ ! *) + iter acc_inher acc_fields loc.Location.loc_end q + + | Parsetree.Pcf_let (_, _, loc) :: q -> + (* don't give a $*%@ ! *) + iter acc_inher acc_fields loc.Location.loc_end q + + | (Parsetree.Pcf_init exp) :: q -> + iter acc_inher acc_fields exp.Parsetree.pexp_loc.Location.loc_end q in iter [] [] last_pos (snd p_cls) - + (** Analysis of a [Parsetree.class_expr] and a [Typedtree.class_expr] to get a a couple (class parameters, class kind). *) let rec analyse_class_kind env current_class_name comment_opt last_pos p_class_expr tt_class_exp = match (p_class_expr.Parsetree.pcl_desc, tt_class_exp.Typedtree.cl_desc) with - (Parsetree.Pcl_constr (lid, _), tt_class_exp_desc ) -> - let name = - match tt_class_exp_desc with - Typedtree.Tclass_ident p -> Name.from_path p - | _ -> - (* we try to get the name from the environment. *) + (Parsetree.Pcl_constr (lid, _), tt_class_exp_desc ) -> + let name = + match tt_class_exp_desc with + Typedtree.Tclass_ident p -> Name.from_path p + | _ -> + (* we try to get the name from the environment. *) (* A VOIR : dommage qu'on n'ait pas un Tclass_ident :-( m�me quand on a class tutu = toto *) - Name.from_longident lid - in - (* On n'a pas ici les param�tres de type sous forme de Types.type_expr, - par contre on peut les trouver dans le class_type *) - let params = - match tt_class_exp.Typedtree.cl_type with - Types.Tcty_constr (p2, type_exp_list, cltyp) -> - (* cltyp is the class type for [type_exp_list] p *) - type_exp_list - | _ -> - [] - in - ([], - Class_constr - { - cco_name = Odoc_env.full_class_name env name ; - cco_class = None ; - cco_type_parameters = List.map (Odoc_env.subst_type env) params ; - } ) + Name.from_longident lid + in + (* On n'a pas ici les param�tres de type sous forme de Types.type_expr, + par contre on peut les trouver dans le class_type *) + let params = + match tt_class_exp.Typedtree.cl_type with + Types.Tcty_constr (p2, type_exp_list, cltyp) -> + (* cltyp is the class type for [type_exp_list] p *) + type_exp_list + | _ -> + [] + in + ([], + Class_constr + { + cco_name = Odoc_env.full_class_name env name ; + cco_class = None ; + cco_type_parameters = List.map (Odoc_env.subst_type env) params ; + } ) | (Parsetree.Pcl_structure p_class_structure, Typedtree.Tclass_structure tt_class_structure) -> - (* we need the class signature to get the type of methods in analyse_class_structure *) - let tt_class_sig = - match tt_class_exp.Typedtree.cl_type with - Types.Tcty_signature class_sig -> class_sig - | _ -> raise (Failure "analyse_class_kind: no class signature for a class structure.") - in - let (inherited_classes, class_elements) = analyse_class_structure - env - current_class_name - tt_class_sig - last_pos - p_class_expr.Parsetree.pcl_loc.Location.loc_end - p_class_structure - tt_class_structure - in - ([], - Class_structure (inherited_classes, class_elements) ) - + (* we need the class signature to get the type of methods in analyse_class_structure *) + let tt_class_sig = + match tt_class_exp.Typedtree.cl_type with + Types.Tcty_signature class_sig -> class_sig + | _ -> raise (Failure "analyse_class_kind: no class signature for a class structure.") + in + let (inherited_classes, class_elements) = analyse_class_structure + env + current_class_name + tt_class_sig + last_pos + p_class_expr.Parsetree.pcl_loc.Location.loc_end + p_class_structure + tt_class_structure + in + ([], + Class_structure (inherited_classes, class_elements) ) + | (Parsetree.Pcl_fun (label, expression_opt, pattern, p_class_expr2), - Typedtree.Tclass_fun (pat, ident_exp_list, tt_class_expr2, partial)) -> - (* we check that this is not an optional parameter with - a default value. In this case, we look for the good parameter pattern *) - let (parameter, next_tt_class_exp) = - match pat.Typedtree.pat_desc with - Typedtree.Tpat_var ident when Name.from_ident ident = "*opt*" -> - ( - (* there must be a Tclass_let just after *) - match tt_class_expr2.Typedtree.cl_desc with - Typedtree.Tclass_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, _, tt_class_expr3) -> - let name = Name.from_ident id in - let new_param = Simple_name - { sn_name = name ; - sn_text = Odoc_parameter.desc_from_info_opt comment_opt name ; - sn_type = Odoc_env.subst_type env exp.exp_type - } - in - (new_param, tt_class_expr3) - | _ -> - (* strange case *) - (* we create the parameter and add it to the class *) - raise (Failure "analyse_class_kind: strange case") - ) + Typedtree.Tclass_fun (pat, ident_exp_list, tt_class_expr2, partial)) -> + (* we check that this is not an optional parameter with + a default value. In this case, we look for the good parameter pattern *) + let (parameter, next_tt_class_exp) = + match pat.Typedtree.pat_desc with + Typedtree.Tpat_var ident when Name.from_ident ident = "*opt*" -> + ( + (* there must be a Tclass_let just after *) + match tt_class_expr2.Typedtree.cl_desc with + Typedtree.Tclass_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, _, tt_class_expr3) -> + let name = Name.from_ident id in + let new_param = Simple_name + { sn_name = name ; + sn_text = Odoc_parameter.desc_from_info_opt comment_opt name ; + sn_type = Odoc_env.subst_type env exp.exp_type + } + in + (new_param, tt_class_expr3) + | _ -> + (* strange case *) + (* we create the parameter and add it to the class *) + raise (Failure "analyse_class_kind: strange case") + ) | _ -> - (* no optional parameter with default value, we create the parameter *) - let new_param = - tt_param_info_from_pattern - env - (Odoc_parameter.desc_from_info_opt comment_opt) - pat - in - (new_param, tt_class_expr2) - in - let (params, k) = analyse_class_kind env current_class_name comment_opt last_pos p_class_expr2 next_tt_class_exp in - (parameter :: params, k) + (* no optional parameter with default value, we create the parameter *) + let new_param = + tt_param_info_from_pattern + env + (Odoc_parameter.desc_from_info_opt comment_opt) + pat + in + (new_param, tt_class_expr2) + in + let (params, k) = analyse_class_kind env current_class_name comment_opt last_pos p_class_expr2 next_tt_class_exp in + (parameter :: params, k) | (Parsetree.Pcl_apply (p_class_expr2, _), Tclass_apply (tt_class_expr2, exp_opt_optional_list)) -> - let applied_name = + let applied_name = (* we want an ident, or else the class applied will appear in the form object ... end, - because if the class applied has no name, the code is kinda ugly, isn't it ? *) - match tt_class_expr2.Typedtree.cl_desc with - Typedtree.Tclass_ident p -> Name.from_path p (* A VOIR : obtenir le nom complet *) - | _ -> + because if the class applied has no name, the code is kinda ugly, isn't it ? *) + match tt_class_expr2.Typedtree.cl_desc with + Typedtree.Tclass_ident p -> Name.from_path p (* A VOIR : obtenir le nom complet *) + | _ -> (* A VOIR : dommage qu'on n'ait pas un Tclass_ident :-( m�me quand on a class tutu = toto *) - match p_class_expr2.Parsetree.pcl_desc with - Parsetree.Pcl_constr (lid, _) -> - (* we try to get the name from the environment. *) - Name.from_longident lid - | _ -> - Odoc_messages.object_end - in - let param_exps = List.fold_left - (fun acc -> fun (exp_opt, _) -> - match exp_opt with - None -> acc - | Some e -> acc @ [e]) - [] - exp_opt_optional_list - in - let param_types = List.map (fun e -> e.Typedtree.exp_type) param_exps in - let params_code = - List.map - (fun e -> get_string_of_file - e.exp_loc.Location.loc_start - e.exp_loc.Location.loc_end) - param_exps - in - ([], - Class_apply - { capp_name = Odoc_env.full_class_name env applied_name ; - capp_class = None ; - capp_params = param_types ; - capp_params_code = params_code ; - } ) + match p_class_expr2.Parsetree.pcl_desc with + Parsetree.Pcl_constr (lid, _) -> + (* we try to get the name from the environment. *) + Name.from_longident lid + | _ -> + Odoc_messages.object_end + in + let param_exps = List.fold_left + (fun acc -> fun (exp_opt, _) -> + match exp_opt with + None -> acc + | Some e -> acc @ [e]) + [] + exp_opt_optional_list + in + let param_types = List.map (fun e -> e.Typedtree.exp_type) param_exps in + let params_code = + List.map + (fun e -> get_string_of_file + e.exp_loc.Location.loc_start + e.exp_loc.Location.loc_end) + param_exps + in + ([], + Class_apply + { capp_name = Odoc_env.full_class_name env applied_name ; + capp_class = None ; + capp_params = param_types ; + capp_params_code = params_code ; + } ) | (Parsetree.Pcl_let (_, _, p_class_expr2), Typedtree.Tclass_let (_, _, _, tt_class_expr2)) -> - (* we don't care about these lets *) - analyse_class_kind env current_class_name comment_opt last_pos p_class_expr2 tt_class_expr2 + (* we don't care about these lets *) + analyse_class_kind env current_class_name comment_opt last_pos p_class_expr2 tt_class_expr2 | (Parsetree.Pcl_constraint (p_class_expr2, p_class_type2), - Typedtree.Tclass_constraint (tt_class_expr2, _, _, _)) -> - let (l, class_kind) = analyse_class_kind env current_class_name comment_opt last_pos p_class_expr2 tt_class_expr2 in - (* A VOIR : analyse du class type ? on n'a pas toutes les infos. cf. Odoc_sig.analyse_class_type_kind *) - let class_type_kind = - (*Sig.analyse_class_type_kind - env - "" - p_class_type2.Parsetree.pcty_loc.Location.loc_start - p_class_type2 - tt_class_expr2.Typedtree.cl_type - *) - Class_type { cta_name = Odoc_messages.object_end ; - cta_class = None ; cta_type_parameters = [] } - in - (l, Class_constraint (class_kind, class_type_kind)) - - | _ -> - raise (Failure "analyse_class_kind: Parsetree and typedtree don't match.") + Typedtree.Tclass_constraint (tt_class_expr2, _, _, _)) -> + let (l, class_kind) = analyse_class_kind env current_class_name comment_opt last_pos p_class_expr2 tt_class_expr2 in + (* A VOIR : analyse du class type ? on n'a pas toutes les infos. cf. Odoc_sig.analyse_class_type_kind *) + let class_type_kind = + (*Sig.analyse_class_type_kind + env + "" + p_class_type2.Parsetree.pcty_loc.Location.loc_start + p_class_type2 + tt_class_expr2.Typedtree.cl_type + *) + Class_type { cta_name = Odoc_messages.object_end ; + cta_class = None ; cta_type_parameters = [] } + in + (l, Class_constraint (class_kind, class_type_kind)) + + | _ -> + raise (Failure "analyse_class_kind: Parsetree and typedtree don't match.") (** Analysis of a [Parsetree.class_declaration] and a [Typedtree.class_expr] to return a [t_class].*) let analyse_class env current_module_name comment_opt p_class_decl tt_type_params tt_class_exp = @@ -756,24 +756,24 @@ module Analyser = let virt = p_class_decl.Parsetree.pci_virt = Asttypes.Virtual in let cltype = Odoc_env.subst_class_type env tt_class_exp.Typedtree.cl_type in let (parameters, kind) = analyse_class_kind - env - complete_name - comment_opt - pos_start - p_class_decl.Parsetree.pci_expr - tt_class_exp + env + complete_name + comment_opt + pos_start + p_class_decl.Parsetree.pci_expr + tt_class_exp in let cl = - { - cl_name = complete_name ; - cl_info = comment_opt ; - cl_type = cltype ; - cl_virtual = virt ; - cl_type_parameters = type_parameters ; - cl_kind = kind ; - cl_parameters = parameters ; - cl_loc = { loc_impl = Some (!file_name, pos_start) ; loc_inter = None } ; - } + { + cl_name = complete_name ; + cl_info = comment_opt ; + cl_type = cltype ; + cl_virtual = virt ; + cl_type_parameters = type_parameters ; + cl_kind = kind ; + cl_parameters = parameters ; + cl_loc = { loc_impl = Some (!file_name, pos_start) ; loc_inter = None } ; + } in cl @@ -781,26 +781,26 @@ module Analyser = is not an ident of a constraint on an ident. *) let rec tt_name_from_module_expr mod_expr = match mod_expr.Typedtree.mod_desc with - Typedtree.Tmod_ident p -> Name.from_path p + Typedtree.Tmod_ident p -> Name.from_path p | Typedtree.Tmod_constraint (m_exp, _, _) -> tt_name_from_module_expr m_exp | Typedtree.Tmod_structure _ | Typedtree.Tmod_functor _ | Typedtree.Tmod_apply _ -> - Odoc_messages.struct_end + Odoc_messages.struct_end (** Get the list of included modules in a module structure of a typed tree. *) let tt_get_included_module_list tt_structure = let f acc item = - match item with - Typedtree.Tstr_include (mod_expr, _) -> - acc @ [ - { (* A VOIR : chercher dans les modules et les module types, avec quel env ? *) - im_name = tt_name_from_module_expr mod_expr ; - im_module = None ; - } - ] - | _ -> - acc + match item with + Typedtree.Tstr_include (mod_expr, _) -> + acc @ [ + { (* A VOIR : chercher dans les modules et les module types, avec quel env ? *) + im_name = tt_name_from_module_expr mod_expr ; + im_module = None ; + } + ] + | _ -> + acc in List.fold_left f [] tt_structure @@ -808,14 +808,14 @@ module Analyser = the ones found in typed tree structure of the module. *) let replace_dummy_included_modules module_elements included_modules = let rec f = function - | ([], _) -> - [] - | ((Element_included_module im) :: q, (im_repl :: im_q)) -> - (Element_included_module im_repl) :: (f (q, im_q)) - | ((Element_included_module im) :: q, []) -> - (Element_included_module im) :: q - | (ele :: q, l) -> - ele :: (f (q, l)) + | ([], _) -> + [] + | ((Element_included_module im) :: q, (im_repl :: im_q)) -> + (Element_included_module im_repl) :: (f (q, im_q)) + | ((Element_included_module im) :: q, []) -> + (Element_included_module im) :: q + | (ele :: q, l) -> + ele :: (f (q, l)) in f (module_elements, included_modules) @@ -824,430 +824,430 @@ module Analyser = print_DEBUG "Odoc_ast:analyse_struture"; let (table, table_values) = Typedtree_search.tables typedtree in let rec iter env last_pos = function - [] -> - let s = get_string_of_file last_pos pos_limit in - let (_, ele_coms) = My_ir.all_special !file_name s in - let ele_comments = - List.fold_left - (fun acc -> fun sc -> - match sc.Odoc_types.i_desc with - None -> - acc - | Some t -> - acc @ [Element_module_comment t]) - [] - ele_coms - in - ele_comments - | item :: q -> - let (comment_opt, ele_comments) = - get_comments_in_module last_pos item.Parsetree.pstr_loc.Location.loc_start - in - let pos_limit2 = - match q with - [] -> pos_limit - | item2 :: _ -> item2.Parsetree.pstr_loc.Location.loc_start - in - let (maybe_more, new_env, elements) = analyse_structure_item - env - current_module_name - item.Parsetree.pstr_loc - pos_limit2 - comment_opt - item.Parsetree.pstr_desc - typedtree - table - table_values - in - ele_comments @ elements @ (iter new_env (item.Parsetree.pstr_loc.Location.loc_end + maybe_more) q) + [] -> + let s = get_string_of_file last_pos pos_limit in + let (_, ele_coms) = My_ir.all_special !file_name s in + let ele_comments = + List.fold_left + (fun acc -> fun sc -> + match sc.Odoc_types.i_desc with + None -> + acc + | Some t -> + acc @ [Element_module_comment t]) + [] + ele_coms + in + ele_comments + | item :: q -> + let (comment_opt, ele_comments) = + get_comments_in_module last_pos item.Parsetree.pstr_loc.Location.loc_start + in + let pos_limit2 = + match q with + [] -> pos_limit + | item2 :: _ -> item2.Parsetree.pstr_loc.Location.loc_start + in + let (maybe_more, new_env, elements) = analyse_structure_item + env + current_module_name + item.Parsetree.pstr_loc + pos_limit2 + comment_opt + item.Parsetree.pstr_desc + typedtree + table + table_values + in + ele_comments @ elements @ (iter new_env (item.Parsetree.pstr_loc.Location.loc_end + maybe_more) q) in iter env last_pos parsetree (** 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 = print_DEBUG "Odoc_ast:analyse_struture_item"; match parsetree_item_desc with - Parsetree.Pstr_eval _ -> - (* don't care *) - (0, env, []) + Parsetree.Pstr_eval _ -> + (* don't care *) + (0, env, []) | Parsetree.Pstr_value (rec_flag, pat_exp_list) -> - (* of rec_flag * (pattern * expression) list *) - (* For each value, look for the value name, then look in the - typedtree for the corresponding information, - at last analyse this information to build the value *) - let rec iter_pat = function - | Parsetree.Ppat_any -> None - | Parsetree.Ppat_var name -> Some name - | Parsetree.Ppat_tuple _ -> None (* A VOIR quand on traitera les tuples *) - | Parsetree.Ppat_constraint (pat, _) -> iter_pat pat.Parsetree.ppat_desc - | _ -> None - in - let rec iter ?(first=false) last_pos acc_env acc p_e_list = - match p_e_list with - [] -> - (acc_env, acc) - | (pat, exp) :: q -> - let value_name_opt = iter_pat pat.Parsetree.ppat_desc in - let new_last_pos = exp.Parsetree.pexp_loc.Location.loc_end in - match value_name_opt with - None -> - iter new_last_pos acc_env acc q - | Some name -> - try - let pat_exp = Typedtree_search.search_value table_values name in - let (info_opt, ele_comments) = - (* we already have the optional comment for the first value. *) - if first then - (comment_opt, []) - else - get_comments_in_module - last_pos - pat.Parsetree.ppat_loc.Location.loc_start - in - let l_values = tt_analyse_value - env - current_module_name - info_opt - loc - pat_exp - rec_flag - in - let new_env = List.fold_left - (fun e -> fun v -> - Odoc_env.add_value e v.val_name - ) - acc_env - l_values - in - let l_ele = List.map (fun v -> Element_value v) l_values in - iter - new_last_pos - new_env - (acc @ ele_comments @ l_ele) - q - with - Not_found -> - iter new_last_pos acc_env acc q - in - let (new_env, l_ele) = iter ~first: true loc.Location.loc_start env [] pat_exp_list in - (0, new_env, l_ele) + (* of rec_flag * (pattern * expression) list *) + (* For each value, look for the value name, then look in the + typedtree for the corresponding information, + at last analyse this information to build the value *) + let rec iter_pat = function + | Parsetree.Ppat_any -> None + | Parsetree.Ppat_var name -> Some name + | Parsetree.Ppat_tuple _ -> None (* A VOIR quand on traitera les tuples *) + | Parsetree.Ppat_constraint (pat, _) -> iter_pat pat.Parsetree.ppat_desc + | _ -> None + in + let rec iter ?(first=false) last_pos acc_env acc p_e_list = + match p_e_list with + [] -> + (acc_env, acc) + | (pat, exp) :: q -> + let value_name_opt = iter_pat pat.Parsetree.ppat_desc in + let new_last_pos = exp.Parsetree.pexp_loc.Location.loc_end in + match value_name_opt with + None -> + iter new_last_pos acc_env acc q + | Some name -> + try + let pat_exp = Typedtree_search.search_value table_values name in + let (info_opt, ele_comments) = + (* we already have the optional comment for the first value. *) + if first then + (comment_opt, []) + else + get_comments_in_module + last_pos + pat.Parsetree.ppat_loc.Location.loc_start + in + let l_values = tt_analyse_value + env + current_module_name + info_opt + loc + pat_exp + rec_flag + in + let new_env = List.fold_left + (fun e -> fun v -> + Odoc_env.add_value e v.val_name + ) + acc_env + l_values + in + let l_ele = List.map (fun v -> Element_value v) l_values in + iter + new_last_pos + new_env + (acc @ ele_comments @ l_ele) + q + with + Not_found -> + iter new_last_pos acc_env acc q + in + let (new_env, l_ele) = iter ~first: true loc.Location.loc_start env [] pat_exp_list in + (0, new_env, l_ele) | Parsetree.Pstr_primitive (name_pre, val_desc) -> - (* of string * value_description *) - print_DEBUG ("Parsetree.Pstr_primitive ("^name_pre^", ["^(String.concat ", " val_desc.Parsetree.pval_prim)^"]"); - let typ = Typedtree_search.search_primitive table name_pre in - let name = Name.parens_if_infix name_pre in - let complete_name = Name.concat current_module_name name in - let new_value = { - val_name = complete_name ; - val_info = comment_opt ; - val_type = Odoc_env.subst_type env typ ; - val_recursive = false ; - val_parameters = [] ; - val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; - val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } - in - let new_env = Odoc_env.add_value env new_value.val_name in - (0, new_env, [Element_value new_value]) + (* of string * value_description *) + print_DEBUG ("Parsetree.Pstr_primitive ("^name_pre^", ["^(String.concat ", " val_desc.Parsetree.pval_prim)^"]"); + let typ = Typedtree_search.search_primitive table name_pre in + let name = Name.parens_if_infix name_pre in + let complete_name = Name.concat current_module_name name in + let new_value = { + val_name = complete_name ; + val_info = comment_opt ; + val_type = Odoc_env.subst_type env typ ; + val_recursive = false ; + val_parameters = [] ; + val_code = Some (get_string_of_file loc.Location.loc_start loc.Location.loc_end) ; + val_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } + in + let new_env = Odoc_env.add_value env new_value.val_name in + (0, new_env, [Element_value new_value]) | Parsetree.Pstr_type name_typedecl_list -> - (* of (string * type_declaration) list *) - (* we start by extending the environment *) - let new_env = - List.fold_left - (fun acc_env -> fun (name, _) -> - let complete_name = Name.concat current_module_name name in - Odoc_env.add_type acc_env complete_name - ) - env - name_typedecl_list - in - let rec f ?(first=false) maybe_more_acc last_pos name_type_decl_list = - match name_type_decl_list with - [] -> (maybe_more_acc, []) - | (name, type_decl) :: q -> - let complete_name = Name.concat current_module_name name in - let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start in - let loc_end = type_decl.Parsetree.ptype_loc.Location.loc_end in - let pos_limit2 = - match q with - [] -> pos_limit - | (_, td) :: _ -> td.Parsetree.ptype_loc.Location.loc_start - in - let (maybe_more, name_comment_list) = - Sig.name_comment_from_type_kind - loc_start loc_end - pos_limit2 - type_decl.Parsetree.ptype_kind - in - let tt_type_decl = - try Typedtree_search.search_type_declaration table name - with Not_found -> raise (Failure (Odoc_messages.type_not_found_in_typedtree complete_name)) - in - let (com_opt, ele_comments) = (* the comment for the first type was already retrieved *) - if first then - (comment_opt , []) - else - get_comments_in_module last_pos loc_start - in - let kind = Sig.get_type_kind - new_env name_comment_list - tt_type_decl.Types.type_kind - in - let t = - { - ty_name = complete_name ; - ty_info = com_opt ; - ty_parameters = List.map - (Odoc_env.subst_type new_env) - tt_type_decl.Types.type_params ; - ty_kind = kind ; - ty_manifest = - (match tt_type_decl.Types.type_manifest with - None -> None - | Some t -> Some (Odoc_env.subst_type new_env t)); - ty_loc = { loc_impl = Some (!file_name, loc_start) ; loc_inter = None } ; - } - in - let new_end = loc_end + maybe_more in - let (maybe_more2, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file new_end pos_limit2) - in - t.ty_info <- Sig.merge_infos t.ty_info info_after_opt ; - let (maybe_more3, eles) = f (maybe_more + maybe_more2) (new_end + maybe_more2) q in - (maybe_more3, ele_comments @ ((Element_type t) :: eles)) - in - let (maybe_more, eles) = f ~first: true 0 loc.Location.loc_start name_typedecl_list in - (maybe_more, new_env, eles) + (* of (string * type_declaration) list *) + (* we start by extending the environment *) + let new_env = + List.fold_left + (fun acc_env -> fun (name, _) -> + let complete_name = Name.concat current_module_name name in + Odoc_env.add_type acc_env complete_name + ) + env + name_typedecl_list + in + let rec f ?(first=false) maybe_more_acc last_pos name_type_decl_list = + match name_type_decl_list with + [] -> (maybe_more_acc, []) + | (name, type_decl) :: q -> + let complete_name = Name.concat current_module_name name in + let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start in + let loc_end = type_decl.Parsetree.ptype_loc.Location.loc_end in + let pos_limit2 = + match q with + [] -> pos_limit + | (_, td) :: _ -> td.Parsetree.ptype_loc.Location.loc_start + in + let (maybe_more, name_comment_list) = + Sig.name_comment_from_type_kind + loc_start loc_end + pos_limit2 + type_decl.Parsetree.ptype_kind + in + let tt_type_decl = + try Typedtree_search.search_type_declaration table name + with Not_found -> raise (Failure (Odoc_messages.type_not_found_in_typedtree complete_name)) + in + let (com_opt, ele_comments) = (* the comment for the first type was already retrieved *) + if first then + (comment_opt , []) + else + get_comments_in_module last_pos loc_start + in + let kind = Sig.get_type_kind + new_env name_comment_list + tt_type_decl.Types.type_kind + in + let t = + { + ty_name = complete_name ; + ty_info = com_opt ; + ty_parameters = List.map + (Odoc_env.subst_type new_env) + tt_type_decl.Types.type_params ; + ty_kind = kind ; + ty_manifest = + (match tt_type_decl.Types.type_manifest with + None -> None + | Some t -> Some (Odoc_env.subst_type new_env t)); + ty_loc = { loc_impl = Some (!file_name, loc_start) ; loc_inter = None } ; + } + in + let new_end = loc_end + maybe_more in + let (maybe_more2, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file new_end pos_limit2) + in + t.ty_info <- Sig.merge_infos t.ty_info info_after_opt ; + let (maybe_more3, eles) = f (maybe_more + maybe_more2) (new_end + maybe_more2) q in + (maybe_more3, ele_comments @ ((Element_type t) :: eles)) + in + let (maybe_more, eles) = f ~first: true 0 loc.Location.loc_start name_typedecl_list in + (maybe_more, new_env, eles) | Parsetree.Pstr_exception (name, excep_decl) -> - (* a new exception is defined *) - let complete_name = Name.concat current_module_name name in - (* we get the exception declaration in the typed tree *) - let tt_excep_decl = - try Typedtree_search.search_exception table name - with Not_found -> - raise (Failure (Odoc_messages.exception_not_found_in_typedtree complete_name)) - in - let new_env = Odoc_env.add_exception env complete_name in - let new_ex = - { - ex_name = complete_name ; - ex_info = comment_opt ; - ex_args = List.map (Odoc_env.subst_type new_env) tt_excep_decl ; - ex_alias = None ; - ex_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } - in - (0, new_env, [ Element_exception new_ex ]) + (* a new exception is defined *) + let complete_name = Name.concat current_module_name name in + (* we get the exception declaration in the typed tree *) + let tt_excep_decl = + try Typedtree_search.search_exception table name + with Not_found -> + raise (Failure (Odoc_messages.exception_not_found_in_typedtree complete_name)) + in + let new_env = Odoc_env.add_exception env complete_name in + let new_ex = + { + ex_name = complete_name ; + ex_info = comment_opt ; + ex_args = List.map (Odoc_env.subst_type new_env) tt_excep_decl ; + ex_alias = None ; + ex_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } + in + (0, new_env, [ Element_exception new_ex ]) | Parsetree.Pstr_exn_rebind (name, _) -> - (* a new exception is defined *) - let complete_name = Name.concat current_module_name name in - (* we get the exception rebind in the typed tree *) - let tt_path = - try Typedtree_search.search_exception_rebind table name - with Not_found -> - raise (Failure (Odoc_messages.exception_not_found_in_typedtree complete_name)) - in - let new_env = Odoc_env.add_exception env complete_name in - let new_ex = - { - ex_name = complete_name ; - ex_info = comment_opt ; - ex_args = [] ; - ex_alias = Some { ea_name = (Odoc_env.full_exception_name env (Name.from_path tt_path)) ; - ea_ex = None ; } ; - ex_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } - in - (0, new_env, [ Element_exception new_ex ]) + (* a new exception is defined *) + let complete_name = Name.concat current_module_name name in + (* we get the exception rebind in the typed tree *) + let tt_path = + try Typedtree_search.search_exception_rebind table name + with Not_found -> + raise (Failure (Odoc_messages.exception_not_found_in_typedtree complete_name)) + in + let new_env = Odoc_env.add_exception env complete_name in + let new_ex = + { + ex_name = complete_name ; + ex_info = comment_opt ; + ex_args = [] ; + ex_alias = Some { ea_name = (Odoc_env.full_exception_name env (Name.from_path tt_path)) ; + ea_ex = None ; } ; + ex_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } + in + (0, new_env, [ Element_exception new_ex ]) | Parsetree.Pstr_module (name, module_expr) -> - ( - (* of string * module_expr *) - try - let tt_module_expr = Typedtree_search.search_module table name in - let new_module = analyse_module - env - current_module_name - name - comment_opt - module_expr - tt_module_expr - in - let new_env = Odoc_env.add_module env new_module.m_name in - let new_env2 = - match new_module.m_type with + ( + (* of string * module_expr *) + try + let tt_module_expr = Typedtree_search.search_module table name in + let new_module = analyse_module + env + current_module_name + name + comment_opt + module_expr + tt_module_expr + in + let new_env = Odoc_env.add_module env new_module.m_name in + let new_env2 = + match new_module.m_type with (* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *) - Types.Tmty_signature s -> - Odoc_env.add_signature new_env new_module.m_name - ~rel: (Name.simple new_module.m_name) s - | _ -> - new_env - in - (0, new_env2, [ Element_module new_module ]) - with - Not_found -> - let complete_name = Name.concat current_module_name name in - raise (Failure (Odoc_messages.module_not_found_in_typedtree complete_name)) - ) + Types.Tmty_signature s -> + Odoc_env.add_signature new_env new_module.m_name + ~rel: (Name.simple new_module.m_name) s + | _ -> + new_env + in + (0, new_env2, [ Element_module new_module ]) + with + Not_found -> + let complete_name = Name.concat current_module_name name in + raise (Failure (Odoc_messages.module_not_found_in_typedtree complete_name)) + ) | Parsetree.Pstr_modtype (name, modtype) -> - let complete_name = Name.concat current_module_name name in - let tt_module_type = - try Typedtree_search.search_module_type table name - with Not_found -> - 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 - in - let mt = - { - mt_name = complete_name ; - mt_info = comment_opt ; - mt_type = Some tt_module_type ; - mt_is_interface = false ; - mt_file = !file_name ; - mt_kind = Some kind ; - mt_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; - } - in - let new_env = Odoc_env.add_module_type env mt.mt_name in - let new_env2 = - match tt_module_type with + let complete_name = Name.concat current_module_name name in + let tt_module_type = + try Typedtree_search.search_module_type table name + with Not_found -> + 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 + in + let mt = + { + mt_name = complete_name ; + mt_info = comment_opt ; + mt_type = Some tt_module_type ; + mt_is_interface = false ; + mt_file = !file_name ; + mt_kind = Some kind ; + mt_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; loc_inter = None } ; + } + in + let new_env = Odoc_env.add_module_type env mt.mt_name in + let new_env2 = + match tt_module_type with (* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on n'aurait pas la signature *) - Types.Tmty_signature s -> - Odoc_env.add_signature new_env mt.mt_name ~rel: (Name.simple mt.mt_name) s - | _ -> - new_env - in - (0, new_env2, [ Element_module_type mt ]) + Types.Tmty_signature s -> + Odoc_env.add_signature new_env mt.mt_name ~rel: (Name.simple mt.mt_name) s + | _ -> + new_env + in + (0, new_env2, [ Element_module_type mt ]) | Parsetree.Pstr_open longident -> - (* A VOIR : enrichir l'environnement quand open ? *) - let ele_comments = match comment_opt with - None -> [] - | Some i -> - match i.i_desc with - None -> [] - | Some t -> [Element_module_comment t] - in - (0, env, ele_comments) + (* A VOIR : enrichir l'environnement quand open ? *) + let ele_comments = match comment_opt with + None -> [] + | Some i -> + match i.i_desc with + None -> [] + | Some t -> [Element_module_comment t] + in + (0, env, ele_comments) | Parsetree.Pstr_class class_decl_list -> (* we start by extending the environment *) - let new_env = - List.fold_left - (fun acc_env -> fun class_decl -> - let complete_name = Name.concat current_module_name class_decl.Parsetree.pci_name in - Odoc_env.add_class acc_env complete_name - ) - env - class_decl_list - in - let rec f ?(first=false) last_pos class_decl_list = - match class_decl_list with - [] -> - [] - | class_decl :: q -> - let (tt_class_exp, tt_type_params) = - try Typedtree_search.search_class_exp table class_decl.Parsetree.pci_name - with Not_found -> - let complete_name = Name.concat current_module_name class_decl.Parsetree.pci_name in - raise (Failure (Odoc_messages.class_not_found_in_typedtree complete_name)) - in - let (com_opt, ele_comments) = - if first then - (comment_opt, []) - else - get_comments_in_module last_pos class_decl.Parsetree.pci_loc.Location.loc_start - in - let last_pos2 = class_decl.Parsetree.pci_loc.Location.loc_end in - let new_class = analyse_class - new_env - current_module_name - com_opt - class_decl - tt_type_params - tt_class_exp - in - ele_comments @ ((Element_class new_class) :: (f last_pos2 q)) - in - (0, new_env, f ~first: true loc.Location.loc_start class_decl_list) + let new_env = + List.fold_left + (fun acc_env -> fun class_decl -> + let complete_name = Name.concat current_module_name class_decl.Parsetree.pci_name in + Odoc_env.add_class acc_env complete_name + ) + env + class_decl_list + in + let rec f ?(first=false) last_pos class_decl_list = + match class_decl_list with + [] -> + [] + | class_decl :: q -> + let (tt_class_exp, tt_type_params) = + try Typedtree_search.search_class_exp table class_decl.Parsetree.pci_name + with Not_found -> + let complete_name = Name.concat current_module_name class_decl.Parsetree.pci_name in + raise (Failure (Odoc_messages.class_not_found_in_typedtree complete_name)) + in + let (com_opt, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module last_pos class_decl.Parsetree.pci_loc.Location.loc_start + in + let last_pos2 = class_decl.Parsetree.pci_loc.Location.loc_end in + let new_class = analyse_class + new_env + current_module_name + com_opt + class_decl + tt_type_params + tt_class_exp + in + ele_comments @ ((Element_class new_class) :: (f last_pos2 q)) + in + (0, new_env, f ~first: true loc.Location.loc_start class_decl_list) | Parsetree.Pstr_class_type class_type_decl_list -> - (* we start by extending the environment *) - let new_env = - List.fold_left - (fun acc_env -> fun class_type_decl -> - let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name in - Odoc_env.add_class_type acc_env complete_name - ) - env - class_type_decl_list - in - let rec f ?(first=false) last_pos class_type_decl_list = - match class_type_decl_list with - [] -> - [] - | class_type_decl :: q -> - let name = class_type_decl.Parsetree.pci_name in - let complete_name = Name.concat current_module_name name in - let virt = class_type_decl.Parsetree.pci_virt = Asttypes.Virtual in - let tt_cltype_declaration = - try Typedtree_search.search_class_type_declaration table name - with Not_found -> - raise (Failure (Odoc_messages.class_type_not_found_in_typedtree complete_name)) - in - let type_params = tt_cltype_declaration.Types.clty_params in - let kind = Sig.analyse_class_type_kind - new_env - complete_name - class_type_decl.Parsetree.pci_loc.Location.loc_start - class_type_decl.Parsetree.pci_expr - tt_cltype_declaration.Types.clty_type - in - let (com_opt, ele_comments) = - if first then - (comment_opt, []) - else - get_comments_in_module last_pos class_type_decl.Parsetree.pci_loc.Location.loc_start - in - let last_pos2 = class_type_decl.Parsetree.pci_loc.Location.loc_end in - let new_ele = - Element_class_type - { - clt_name = complete_name ; - clt_info = com_opt ; - clt_type = Odoc_env.subst_class_type env tt_cltype_declaration.Types.clty_type ; - clt_type_parameters = List.map (Odoc_env.subst_type new_env) type_params ; - clt_virtual = virt ; - clt_kind = kind ; - clt_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; - loc_inter = None } ; - } - in - ele_comments @ (new_ele :: (f last_pos2 q)) - in - (0, new_env, f ~first: true loc.Location.loc_start class_type_decl_list) + (* we start by extending the environment *) + let new_env = + List.fold_left + (fun acc_env -> fun class_type_decl -> + let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name in + Odoc_env.add_class_type acc_env complete_name + ) + env + class_type_decl_list + in + let rec f ?(first=false) last_pos class_type_decl_list = + match class_type_decl_list with + [] -> + [] + | class_type_decl :: q -> + let name = class_type_decl.Parsetree.pci_name in + let complete_name = Name.concat current_module_name name in + let virt = class_type_decl.Parsetree.pci_virt = Asttypes.Virtual in + let tt_cltype_declaration = + try Typedtree_search.search_class_type_declaration table name + with Not_found -> + raise (Failure (Odoc_messages.class_type_not_found_in_typedtree complete_name)) + in + let type_params = tt_cltype_declaration.Types.clty_params in + let kind = Sig.analyse_class_type_kind + new_env + complete_name + class_type_decl.Parsetree.pci_loc.Location.loc_start + class_type_decl.Parsetree.pci_expr + tt_cltype_declaration.Types.clty_type + in + let (com_opt, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module last_pos class_type_decl.Parsetree.pci_loc.Location.loc_start + in + let last_pos2 = class_type_decl.Parsetree.pci_loc.Location.loc_end in + let new_ele = + Element_class_type + { + clt_name = complete_name ; + clt_info = com_opt ; + clt_type = Odoc_env.subst_class_type env tt_cltype_declaration.Types.clty_type ; + clt_type_parameters = List.map (Odoc_env.subst_type new_env) type_params ; + clt_virtual = virt ; + clt_kind = kind ; + clt_loc = { loc_impl = Some (!file_name, loc.Location.loc_start) ; + loc_inter = None } ; + } + in + ele_comments @ (new_ele :: (f last_pos2 q)) + in + (0, new_env, f ~first: true loc.Location.loc_start class_type_decl_list) | Parsetree.Pstr_include module_expr -> - (* we add a dummy included module which will be replaced by a correct - one at the end of the module analysis, - to use the Path.t of the included modules in the typdtree. *) - let im = - { - im_name = "dummy" ; - im_module = None ; - } - in - (0, env, [ Element_included_module im ]) (* A VOIR : �tendre l'environnement ? avec quoi ? *) + (* we add a dummy included module which will be replaced by a correct + one at the end of the module analysis, + to use the Path.t of the included modules in the typdtree. *) + let im = + { + im_name = "dummy" ; + im_module = None ; + } + in + (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 = @@ -1256,124 +1256,124 @@ module Analyser = let pos_end = p_module_expr.Parsetree.pmod_loc.Location.loc_end in let modtype = tt_module_expr.Typedtree.mod_type in let m_base = - { - m_name = complete_name ; - m_type = tt_module_expr.Typedtree.mod_type ; - m_info = comment_opt ; - m_is_interface = false ; - m_file = !file_name ; - m_kind = Module_struct [] ; - m_loc = { loc_impl = Some (!file_name, pos_start) ; loc_inter = None } ; - m_top_deps = [] ; - } + { + m_name = complete_name ; + m_type = tt_module_expr.Typedtree.mod_type ; + m_info = comment_opt ; + m_is_interface = false ; + m_file = !file_name ; + m_kind = Module_struct [] ; + m_loc = { loc_impl = Some (!file_name, pos_start) ; loc_inter = None } ; + m_top_deps = [] ; + } in match (p_module_expr.Parsetree.pmod_desc, tt_module_expr.Typedtree.mod_desc) with - (Parsetree.Pmod_ident longident, Typedtree.Tmod_ident path) -> - let alias_name = Odoc_env.full_module_name env (Name.from_path path) in - { m_base with m_kind = Module_alias { ma_name = alias_name ; - ma_module = None ; } } - + (Parsetree.Pmod_ident longident, Typedtree.Tmod_ident path) -> + let alias_name = Odoc_env.full_module_name env (Name.from_path path) in + { m_base with m_kind = Module_alias { ma_name = alias_name ; + 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 - (* 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 - { m_base with m_kind = Module_struct elements2 } + 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 + { m_base with m_kind = Module_struct elements2 } | (Parsetree.Pmod_functor (_, _, p_module_expr2), - Typedtree.Tmod_functor (ident, mtyp, tt_module_expr2)) -> - let param = - { - mp_name = Name.from_ident ident ; - mp_type = Odoc_env.subst_module_type env mtyp ; - } - in - let dummy_complete_name = Name.concat "__" param.mp_name in - let new_env = Odoc_env.add_module env dummy_complete_name in - let m_base2 = analyse_module - new_env - current_module_name - module_name - None - p_module_expr2 - tt_module_expr2 - in - let kind = - match m_base2.m_kind with - Module_functor (params, k) -> Module_functor (param :: params, m_base2.m_kind) - | k -> Module_functor ([param], k) - in - { m_base with m_kind = kind } + Typedtree.Tmod_functor (ident, mtyp, tt_module_expr2)) -> + let param = + { + mp_name = Name.from_ident ident ; + mp_type = Odoc_env.subst_module_type env mtyp ; + } + in + let dummy_complete_name = Name.concat "__" param.mp_name in + let new_env = Odoc_env.add_module env dummy_complete_name in + let m_base2 = analyse_module + new_env + current_module_name + module_name + None + p_module_expr2 + tt_module_expr2 + in + let kind = + match m_base2.m_kind with + Module_functor (params, k) -> Module_functor (param :: params, m_base2.m_kind) + | k -> Module_functor ([param], k) + in + { m_base with m_kind = kind } | (Parsetree.Pmod_apply (p_module_expr1, p_module_expr2), - Typedtree.Tmod_apply (tt_module_expr1, tt_module_expr2, _)) -> - let m1 = analyse_module - env - current_module_name - module_name - None - p_module_expr1 - tt_module_expr1 - in - let m2 = analyse_module - env - current_module_name - module_name - None - p_module_expr2 - tt_module_expr2 - in - { m_base with m_kind = Module_apply (m1.m_kind, m2.m_kind) } + Typedtree.Tmod_apply (tt_module_expr1, tt_module_expr2, _)) -> + let m1 = analyse_module + env + current_module_name + module_name + None + p_module_expr1 + tt_module_expr1 + in + let m2 = analyse_module + env + current_module_name + module_name + None + p_module_expr2 + tt_module_expr2 + in + { m_base with m_kind = Module_apply (m1.m_kind, m2.m_kind) } | (Parsetree.Pmod_constraint (p_module_expr2, p_modtype), - Typedtree.Tmod_constraint (tt_module_expr2, tt_modtype, _)) -> - (* we create the module with p_module_expr2 and tt_module_expr2 - but we change its type according to the constraint. - A VOIR : est-ce que c'est bien ? - *) - let m_base2 = analyse_module - env - current_module_name - module_name - None - p_module_expr2 - tt_module_expr2 - in - let mtkind = Sig.analyse_module_type_kind - env - (Name.concat current_module_name "??") - p_modtype tt_modtype - in - { - m_base with - m_type = tt_modtype ; - m_kind = Module_constraint (m_base2.m_kind, - mtkind) - -(* Module_type_alias { mta_name = "Not analyzed" ; - mta_module = None }) + Typedtree.Tmod_constraint (tt_module_expr2, tt_modtype, _)) -> + (* we create the module with p_module_expr2 and tt_module_expr2 + but we change its type according to the constraint. + A VOIR : est-ce que c'est bien ? + *) + let m_base2 = analyse_module + env + current_module_name + module_name + None + p_module_expr2 + tt_module_expr2 + in + let mtkind = Sig.analyse_module_type_kind + env + (Name.concat current_module_name "??") + p_modtype tt_modtype + in + { + m_base with + m_type = tt_modtype ; + m_kind = Module_constraint (m_base2.m_kind, + mtkind) + +(* Module_type_alias { mta_name = "Not analyzed" ; + mta_module = None }) *) - } + } - | _ -> - raise (Failure "analyse_module: parsetree and typedtree don't match.") + | _ -> + raise (Failure "analyse_module: parsetree and typedtree don't match.") let analyse_typed_tree source_file input_file - (parsetree : Parsetree.structure) (typedtree : typedtree) = + (parsetree : Parsetree.structure) (typedtree : typedtree) = let (tree_structure, _) = typedtree in let complete_source_file = - try - let curdir = Sys.getcwd () in - let (dirname, basename) = (Filename.dirname source_file, Filename.basename source_file) in - Sys.chdir dirname ; - let complete = Filename.concat (Sys.getcwd ()) basename in - Sys.chdir curdir ; - complete - with - Sys_error s -> - prerr_endline s ; - incr Odoc_global.errors ; - source_file + try + let curdir = Sys.getcwd () in + let (dirname, basename) = (Filename.dirname source_file, Filename.basename source_file) in + Sys.chdir dirname ; + let complete = Filename.concat (Sys.getcwd ()) basename in + Sys.chdir curdir ; + complete + with + Sys_error s -> + prerr_endline s ; + incr Odoc_global.errors ; + source_file in prepare_file complete_source_file input_file; (* We create the t_module for this file. *) @@ -1386,16 +1386,16 @@ module Analyser = let elements2 = replace_dummy_included_modules elements included_modules_from_tt in let kind = Module_struct elements2 in let m = - { - m_name = mod_name ; - m_type = Types.Tmty_signature [] ; - m_info = info_opt ; - m_is_interface = false ; - m_file = !file_name ; - m_kind = kind ; - m_loc = { loc_impl = Some (!file_name, 0) ; loc_inter = None } ; - m_top_deps = [] ; - } + { + m_name = mod_name ; + m_type = Types.Tmty_signature [] ; + m_info = info_opt ; + m_is_interface = false ; + m_file = !file_name ; + m_kind = kind ; + m_loc = { loc_impl = Some (!file_name, 0) ; loc_inter = None } ; + m_top_deps = [] ; + } in m end diff --git a/ocamldoc/odoc_ast.mli b/ocamldoc/odoc_ast.mli index 53d1105cb..458365b09 100644 --- a/ocamldoc/odoc_ast.mli +++ b/ocamldoc/odoc_ast.mli @@ -26,66 +26,66 @@ module Typedtree_search : val tables : Typedtree.structure_item list -> tab * tab_values (** This function returns the [Typedtree.module_expr] associated to the given module name, - in the given table. - @raise Not_found if the module was not found.*) + in the given table. + @raise Not_found if the module was not found.*) val search_module : tab -> string -> Typedtree.module_expr (** This function returns the [Types.module_type] associated to the given module type name, - in the given table. - @raise Not_found if the module type was not found.*) + in the given table. + @raise Not_found if the module type was not found.*) val search_module_type : tab -> string -> Types.module_type (** This function returns the [Types.exception_declaration] associated to the given exception name, - in the given table. - @raise Not_found if the exception was not found.*) + in the given table. + @raise Not_found if the exception was not found.*) val search_exception : tab -> string -> Types.exception_declaration (** This function returns the [Path.t] associated to the given exception rebind name, - in the table. - @raise Not_found if the exception rebind was not found.*) + in the table. + @raise Not_found if the exception rebind was not found.*) val search_exception_rebind : tab -> string -> Path.t (** This function returns the [Typedtree.type_declaration] associated to the given type name, - in the given table. - @raise Not_found if the type was not found. *) + in the given table. + @raise Not_found if the type was not found. *) val search_type_declaration : tab -> string -> Types.type_declaration (** This function returns the [Typedtree.class_expr] and type parameters - associated to the given class name, in the given table. - @raise Not_found if the class was not found. *) + associated to the given class name, in the given table. + @raise Not_found if the class was not found. *) val search_class_exp : tab -> string -> (Typedtree.class_expr * (Types.type_expr list)) (** This function returns the [Types.cltype_declaration] associated to the given class type name, - in the given table. - @raise Not_found if the class type was not found. *) + in the given table. + @raise Not_found if the class type was not found. *) val search_class_type_declaration : tab -> string -> Types.cltype_declaration (** This function returns the couple (pat, exp) for the given value name, in the - given table of values. - @raise Not found if no value matches the name.*) + given table of values. + @raise Not found if no value matches the name.*) val search_value : tab_values -> string -> Typedtree.pattern * Typedtree.expression (** This function returns the [type_expr] for the given primitive name, in the - given table. - @raise Not found if no value matches the name.*) + given table. + @raise Not found if no value matches the name.*) val search_primitive : tab -> string -> Types.type_expr (** This function returns the [Typedtree.class_expr] associated to - the n'th inherit in the given class structure of typed tree. - @raise Not_found if the class expression could not be found.*) + the n'th inherit in the given class structure of typed tree. + @raise Not_found if the class expression could not be found.*) val get_nth_inherit_class_expr : - Typedtree.class_structure -> int -> Typedtree.class_expr + Typedtree.class_structure -> int -> Typedtree.class_expr (** This function returns the [Types.type_expr] of the attribute - whose name is given, in a given class structure. - @raise Not_found if the class attribute could not be found.*) + whose name is given, in a given class structure. + @raise Not_found if the class attribute could not be found.*) val search_attribute_type : - Typedtree.class_structure -> string -> Types.type_expr + Typedtree.class_structure -> string -> Types.type_expr (** This function returns the [Types.expression] of the method whose name is given, in a given class structure. - @raise Not_found if the class method could not be found.*) + @raise Not_found if the class method could not be found.*) val search_method_expression : - Typedtree.class_structure -> string -> Typedtree.expression + Typedtree.class_structure -> string -> Typedtree.expression end (** The module which performs the analysis of a typed tree. @@ -95,9 +95,9 @@ module Analyser : functor (My_ir : Odoc_sig.Info_retriever) -> sig (** This function takes a file name, a file containg the code and - the typed tree obtained from the compiler. - It goes through the tree, creating values for encountered - functions, modules, ..., and looking in the source file for comments.*) + the typed tree obtained from the compiler. + It goes through the tree, creating values for encountered + functions, modules, ..., and looking in the source file for comments.*) val analyse_typed_tree : string -> string -> Parsetree.structure -> typedtree -> Odoc_module.t_module end diff --git a/ocamldoc/odoc_class.ml b/ocamldoc/odoc_class.ml index 3992c387a..fc367765b 100644 --- a/ocamldoc/odoc_class.ml +++ b/ocamldoc/odoc_class.ml @@ -47,15 +47,15 @@ and class_constr = { and class_kind = Class_structure of inherited_class list * class_element list - (** an explicit class structure, used in implementation and interface *) + (** an explicit class structure, used in implementation and interface *) | Class_apply of class_apply (** application/alias of a class, used in implementation only *) | Class_constr of class_constr (** a class used to give the type of the defined class, - instead of a structure, used in interface only. - For example, it will be used with the name "M1.M2....tutu" - when the class to is defined like this : - class toto : int -> tutu *) + instead of a structure, used in interface only. + For example, it will be used with the name "M1.M2....tutu" + when the class to is defined like this : + class toto : int -> tutu *) | Class_constraint of class_kind * class_type_kind - (** A class definition with a constraint. *) + (** A class definition with a constraint. *) (** Representation of a class. *) and t_class = { @@ -100,11 +100,11 @@ let class_parameter_text_by_name cl label = None -> None | Some i -> try - let t = List.assoc label i.Odoc_types.i_params in - Some t + let t = List.assoc label i.Odoc_types.i_params in + Some t with - Not_found -> - None + Not_found -> + None (** Returns the list of elements of a t_class. *) let rec class_elements ?(trans=true) cl = @@ -112,29 +112,29 @@ let rec class_elements ?(trans=true) cl = match k with Class_structure (_, elements) -> elements | Class_constraint (c_kind, ct_kind) -> - iter_kind c_kind + iter_kind c_kind (* A VOIR : utiliser le c_kind ou le ct_kind ? - Pour l'instant, comme le ct_kind n'est pas analys�, - on cherche dans le c_kind - class_type_elements ~trans: trans - { clt_name = "" ; clt_info = None ; - clt_type_parameters = [] ; - clt_virtual = false ; - clt_kind = ct_kind } + Pour l'instant, comme le ct_kind n'est pas analys�, + on cherche dans le c_kind + class_type_elements ~trans: trans + { clt_name = "" ; clt_info = None ; + clt_type_parameters = [] ; + clt_virtual = false ; + clt_kind = ct_kind } *) | Class_apply capp -> - ( - match capp.capp_class with - Some c when trans -> class_elements ~trans: trans c - | _ -> [] - ) + ( + match capp.capp_class with + Some c when trans -> class_elements ~trans: trans c + | _ -> [] + ) | Class_constr cco -> - ( - match cco.cco_class with - Some (Cl c) when trans -> class_elements ~trans: trans c - | Some (Cltype (ct,_)) when trans -> class_type_elements ~trans: trans ct - | _ -> [] - ) + ( + match cco.cco_class with + Some (Cl c) when trans -> class_elements ~trans: trans c + | Some (Cltype (ct,_)) when trans -> class_type_elements ~trans: trans ct + | _ -> [] + ) in iter_kind cl.cl_kind @@ -154,10 +154,10 @@ let class_attributes ?(trans=true) cl = List.fold_left (fun acc -> fun ele -> match ele with - Class_attribute a -> - acc @ [ a ] + Class_attribute a -> + acc @ [ a ] | _ -> - acc + acc ) [] (class_elements ~trans cl) @@ -167,10 +167,10 @@ let class_methods ?(trans=true) cl = List.fold_left (fun acc -> fun ele -> match ele with - Class_method m -> - acc @ [ m ] + Class_method m -> + acc @ [ m ] | _ -> - acc + acc ) [] (class_elements ~trans cl) @@ -180,10 +180,10 @@ let class_comments ?(trans=true) cl = List.fold_left (fun acc -> fun ele -> match ele with - Class_comment t -> - acc @ [ t ] + Class_comment t -> + acc @ [ t ] | _ -> - acc + acc ) [] (class_elements ~trans cl) @@ -201,10 +201,10 @@ let class_type_attributes ?(trans=true) clt = List.fold_left (fun acc -> fun ele -> match ele with - Class_attribute a -> - acc @ [ a ] + Class_attribute a -> + acc @ [ a ] | _ -> - acc + acc ) [] (class_type_elements ~trans clt) @@ -214,10 +214,10 @@ let class_type_methods ?(trans=true) clt = List.fold_left (fun acc -> fun ele -> match ele with - Class_method m -> - acc @ [ m ] + Class_method m -> + acc @ [ m ] | _ -> - acc + acc ) [] (class_type_elements ~trans clt) @@ -227,10 +227,10 @@ let class_type_comments ?(trans=true) clt = List.fold_left (fun acc -> fun ele -> match ele with - Class_comment m -> - acc @ [ m ] + Class_comment m -> + acc @ [ m ] | _ -> - acc + acc ) [] (class_type_elements ~trans clt) @@ -242,10 +242,10 @@ let class_type_parameter_text_by_name clt label = None -> None | Some i -> try - let t = List.assoc label i.Odoc_types.i_params in - Some t + let t = List.assoc label i.Odoc_types.i_params in + Some t with - Not_found -> - None + Not_found -> + None - + diff --git a/ocamldoc/odoc_comments.ml b/ocamldoc/odoc_comments.ml index be3d17f9d..2b1d1f6fd 100644 --- a/ocamldoc/odoc_comments.ml +++ b/ocamldoc/odoc_comments.ml @@ -30,72 +30,72 @@ module Info_retriever = struct let create_see s = try - let lexbuf = Lexing.from_string s in - let (see_ref, s) = Odoc_parser.see_info Odoc_see_lexer.main lexbuf in - (see_ref, MyTexter.text_of_string s) + let lexbuf = Lexing.from_string s in + let (see_ref, s) = Odoc_parser.see_info Odoc_see_lexer.main lexbuf in + (see_ref, MyTexter.text_of_string s) with - | Odoc_text.Text_syntax (l, c, s) -> - raise (Failure (Odoc_messages.text_parse_error l c s)) - | _ -> - raise (Failure ("Erreur inconnue lors du parse de see : "^s)) + | Odoc_text.Text_syntax (l, c, s) -> + raise (Failure (Odoc_messages.text_parse_error l c s)) + | _ -> + raise (Failure ("Erreur inconnue lors du parse de see : "^s)) let retrieve_info fun_lex file (s : string) = try - let _ = Odoc_comments_global.init () in - Odoc_lexer.comments_level := 0; - let lexbuf = Lexing.from_string s in - match Odoc_parser.main fun_lex lexbuf with - None -> - (0, None) - | Some (desc, remain_opt) -> - let mem_nb_chars = !Odoc_comments_global.nb_chars in - let _ = - match remain_opt with - None -> - () - | Some s -> - (*DEBUG*)print_string ("remain: "^s); print_newline(); - let lexbuf2 = Lexing.from_string s in - Odoc_parser.info_part2 Odoc_lexer.elements lexbuf2 - in - (mem_nb_chars, - Some - { - i_desc = (match desc with "" -> None | _ -> Some (MyTexter.text_of_string desc)); - i_authors = !Odoc_comments_global.authors; - i_version = !Odoc_comments_global.version; - i_sees = (List.map create_see !Odoc_comments_global.sees) ; - i_since = !Odoc_comments_global.since; - i_deprecated = - (match !Odoc_comments_global.deprecated with - None -> None | Some s -> Some (MyTexter.text_of_string s)); - i_params = - (List.map (fun (n, s) -> - (n, MyTexter.text_of_string s)) !Odoc_comments_global.params); - i_raised_exceptions = - (List.map (fun (n, s) -> - (n, MyTexter.text_of_string s)) !Odoc_comments_global.raised_exceptions); - i_return_value = - (match !Odoc_comments_global.return_value with - None -> None | Some s -> Some (MyTexter.text_of_string s)) ; - i_custom = (List.map - (fun (tag, s) -> (tag, MyTexter.text_of_string s)) - !Odoc_comments_global.customs) - } - ) - with - Failure s -> - incr Odoc_global.errors ; - prerr_endline (file^" : "^s^"\n"); - (0, None) - | Odoc_text.Text_syntax (l, c, s) -> - incr Odoc_global.errors ; - prerr_endline (file^" : "^(Odoc_messages.text_parse_error l c s)); - (0, None) - | _ -> - incr Odoc_global.errors ; - prerr_endline (file^" : "^Odoc_messages.parse_error^"\n"); - (0, None) + let _ = Odoc_comments_global.init () in + Odoc_lexer.comments_level := 0; + let lexbuf = Lexing.from_string s in + match Odoc_parser.main fun_lex lexbuf with + None -> + (0, None) + | Some (desc, remain_opt) -> + let mem_nb_chars = !Odoc_comments_global.nb_chars in + let _ = + match remain_opt with + None -> + () + | Some s -> + (*DEBUG*)print_string ("remain: "^s); print_newline(); + let lexbuf2 = Lexing.from_string s in + Odoc_parser.info_part2 Odoc_lexer.elements lexbuf2 + in + (mem_nb_chars, + Some + { + i_desc = (match desc with "" -> None | _ -> Some (MyTexter.text_of_string desc)); + i_authors = !Odoc_comments_global.authors; + i_version = !Odoc_comments_global.version; + i_sees = (List.map create_see !Odoc_comments_global.sees) ; + i_since = !Odoc_comments_global.since; + i_deprecated = + (match !Odoc_comments_global.deprecated with + None -> None | Some s -> Some (MyTexter.text_of_string s)); + i_params = + (List.map (fun (n, s) -> + (n, MyTexter.text_of_string s)) !Odoc_comments_global.params); + i_raised_exceptions = + (List.map (fun (n, s) -> + (n, MyTexter.text_of_string s)) !Odoc_comments_global.raised_exceptions); + i_return_value = + (match !Odoc_comments_global.return_value with + None -> None | Some s -> Some (MyTexter.text_of_string s)) ; + i_custom = (List.map + (fun (tag, s) -> (tag, MyTexter.text_of_string s)) + !Odoc_comments_global.customs) + } + ) + with + Failure s -> + incr Odoc_global.errors ; + prerr_endline (file^" : "^s^"\n"); + (0, None) + | Odoc_text.Text_syntax (l, c, s) -> + incr Odoc_global.errors ; + prerr_endline (file^" : "^(Odoc_messages.text_parse_error l c s)); + (0, None) + | _ -> + incr Odoc_global.errors ; + prerr_endline (file^" : "^Odoc_messages.parse_error^"\n"); + (0, None) (** This function takes a string where a simple comment may has been found. It returns false if there is a blank line or the first comment is a special one, or if there is @@ -103,36 +103,36 @@ module Info_retriever = let nothing_before_simple_comment s = (* get the position of the first "(*" *) try - print_DEBUG ("comment_is_attached: "^s); - let pos = Str.search_forward (Str.regexp "(\\*") s 0 in - let next_char = if (String.length s) >= (pos + 1) then s.[pos + 2] else '_' in - (next_char <> '*') && - ( + print_DEBUG ("comment_is_attached: "^s); + let pos = Str.search_forward (Str.regexp "(\\*") s 0 in + let next_char = if (String.length s) >= (pos + 1) then s.[pos + 2] else '_' in + (next_char <> '*') && + ( (* there is no special comment between the constructor and the coment we got *) - let s2 = String.sub s 0 pos in - print_DEBUG ("s2="^s2); - try - let _ = Str.search_forward (Str.regexp ("['\n']"^simple_blank^"*['\n']")) s2 0 in + let s2 = String.sub s 0 pos in + print_DEBUG ("s2="^s2); + try + let _ = Str.search_forward (Str.regexp ("['\n']"^simple_blank^"*['\n']")) s2 0 in (* a blank line was before the comment *) - false - with - Not_found -> - true - ) + false + with + Not_found -> + true + ) with - Not_found -> - false + Not_found -> + false (** Return true if the given string contains a blank line. *) let blank_line s = try - let _ = Str.search_forward (Str.regexp ("['\n']"^simple_blank^"*['\n']")) s 0 in + let _ = Str.search_forward (Str.regexp ("['\n']"^simple_blank^"*['\n']")) s 0 in (* a blank line was before the comment *) - true + true with - Not_found -> - false - + Not_found -> + false + let retrieve_info_special file (s : string) = retrieve_info Odoc_lexer.main file s @@ -141,27 +141,27 @@ module Info_retriever = Odoc_lexer.comments_level := 0; let lexbuf = Lexing.from_string s in match Odoc_parser.main Odoc_lexer.simple lexbuf with - None -> - (0, None) + None -> + (0, None) | Some (desc, remain_opt) -> - (!Odoc_comments_global.nb_chars, Some Odoc_types.dummy_info) + (!Odoc_comments_global.nb_chars, Some Odoc_types.dummy_info) (** Return true if the given string contains a blank line outside a simple comment. *) let blank_line_outside_simple file s = let rec iter s2 = - match retrieve_info_simple file s2 with - (_, None) -> - blank_line s2 - | (len, Some _) -> - try - let pos = Str.search_forward (Str.regexp_string "(*") s2 0 in - let s_before = String.sub s2 0 pos in - let s_after = String.sub s2 len ((String.length s2) - len) in - (blank_line s_before) || (iter s_after) - with - Not_found -> - (* we shouldn't get here *) - false + match retrieve_info_simple file s2 with + (_, None) -> + blank_line s2 + | (len, Some _) -> + try + let pos = Str.search_forward (Str.regexp_string "(*") s2 0 in + let s_before = String.sub s2 0 pos in + let s_after = String.sub s2 len ((String.length s2) - len) in + (blank_line s_before) || (iter s_after) + with + Not_found -> + (* we shouldn't get here *) + false in iter s @@ -171,72 +171,72 @@ module Info_retriever = comment is found before the simple comment. *) let retrieve_first_info_simple ?(strict=true) file (s : string) = match retrieve_info_simple file s with - (_, None) -> - (0, None) - | (len, Some d) -> - (* we check if the comment we got was really attached to the constructor, - i.e. that there was no blank line or any special comment "(**" before *) - if (not strict) or (nothing_before_simple_comment s) then - (* ok, we attach the comment to the constructor *) - (len, Some d) - else - (* a blank line or special comment was before the comment, - so we must not attach this comment to the constructor. *) - (0, None) + (_, None) -> + (0, None) + | (len, Some d) -> + (* we check if the comment we got was really attached to the constructor, + i.e. that there was no blank line or any special comment "(**" before *) + if (not strict) or (nothing_before_simple_comment s) then + (* ok, we attach the comment to the constructor *) + (len, Some d) + else + (* a blank line or special comment was before the comment, + so we must not attach this comment to the constructor. *) + (0, None) let retrieve_last_info_simple file (s : string) = print_DEBUG ("retrieve_last_info_simple:"^s); let rec f cur_len cur_d = - try - let s2 = String.sub s cur_len ((String.length s) - cur_len) in - print_DEBUG ("retrieve_last_info_simple.f:"^s2); - match retrieve_info_simple file s2 with - (len, None) -> - print_DEBUG "retrieve_last_info_simple: None"; - (cur_len + len, cur_d) - | (len, Some d) -> - print_DEBUG "retrieve_last_info_simple: Some"; - f (len + cur_len) (Some d) - with - _ -> - print_DEBUG "retrieve_last_info_simple : Erreur String.sub"; - (cur_len, cur_d) + try + let s2 = String.sub s cur_len ((String.length s) - cur_len) in + print_DEBUG ("retrieve_last_info_simple.f:"^s2); + match retrieve_info_simple file s2 with + (len, None) -> + print_DEBUG "retrieve_last_info_simple: None"; + (cur_len + len, cur_d) + | (len, Some d) -> + print_DEBUG "retrieve_last_info_simple: Some"; + f (len + cur_len) (Some d) + with + _ -> + print_DEBUG "retrieve_last_info_simple : Erreur String.sub"; + (cur_len, cur_d) in f 0 None let retrieve_last_special_no_blank_after file (s : string) = print_DEBUG ("retrieve_last_special_no_blank_after:"^s); let rec f cur_len cur_d = - try - let s2 = String.sub s cur_len ((String.length s) - cur_len) in - print_DEBUG ("retrieve_last_special_no_blank_after.f:"^s2); - match retrieve_info_special file s2 with - (len, None) -> - print_DEBUG "retrieve_last_special_no_blank_after: None"; - (cur_len + len, cur_d) - | (len, Some d) -> - print_DEBUG "retrieve_last_special_no_blank_after: Some"; - f (len + cur_len) (Some d) - with - _ -> - print_DEBUG "retrieve_last_special_no_blank_after : Erreur String.sub"; - (cur_len, cur_d) + try + let s2 = String.sub s cur_len ((String.length s) - cur_len) in + print_DEBUG ("retrieve_last_special_no_blank_after.f:"^s2); + match retrieve_info_special file s2 with + (len, None) -> + print_DEBUG "retrieve_last_special_no_blank_after: None"; + (cur_len + len, cur_d) + | (len, Some d) -> + print_DEBUG "retrieve_last_special_no_blank_after: Some"; + f (len + cur_len) (Some d) + with + _ -> + print_DEBUG "retrieve_last_special_no_blank_after : Erreur String.sub"; + (cur_len, cur_d) in f 0 None let all_special file s = print_DEBUG ("all_special: "^s); let rec iter acc n s2 = - match retrieve_info_special file s2 with - (_, None) -> - (n, acc) - | (n2, Some i) -> - print_DEBUG ("all_special: avant String.sub new_s="^s2); - print_DEBUG ("n2="^(string_of_int n2)) ; - print_DEBUG ("len(s2)="^(string_of_int (String.length s2))) ; - let new_s = String.sub s2 n2 ((String.length s2) - n2) in - print_DEBUG ("all_special: apres String.sub new_s="^new_s); - iter (acc @ [i]) (n + n2) new_s + match retrieve_info_special file s2 with + (_, None) -> + (n, acc) + | (n2, Some i) -> + print_DEBUG ("all_special: avant String.sub new_s="^s2); + print_DEBUG ("n2="^(string_of_int n2)) ; + print_DEBUG ("len(s2)="^(string_of_int (String.length s2))) ; + let new_s = String.sub s2 n2 ((String.length s2) - n2) in + print_DEBUG ("all_special: apres String.sub new_s="^new_s); + iter (acc @ [i]) (n + n2) new_s in let res = iter [] 0 s in print_DEBUG ("all_special: end"); @@ -245,30 +245,30 @@ module Info_retriever = let just_after_special file s = print_DEBUG ("just_after_special: "^s); let res = match retrieve_info_special file s with - (_, None) -> - (0, None) - | (len, Some d) -> - (* we must not have a simple comment or a blank line before. *) - match retrieve_info_simple file (String.sub s 0 len) with - (_, None) -> - ( - try - (* if the special comment is the stop comment (**/**), - then we must not associate it. *) - let pos = Str.search_forward (Str.regexp_string "(**") s 0 in - if blank_line (String.sub s 0 pos) or - d.Odoc_types.i_desc = Some [Odoc_types.Raw "/*"] - then - (0, None) - else - (len, Some d) - with - Not_found -> - (* should not occur *) - (0, None) - ) - | (len2, Some d2) -> - (0, None) + (_, None) -> + (0, None) + | (len, Some d) -> + (* we must not have a simple comment or a blank line before. *) + match retrieve_info_simple file (String.sub s 0 len) with + (_, None) -> + ( + try + (* if the special comment is the stop comment (**/**), + then we must not associate it. *) + let pos = Str.search_forward (Str.regexp_string "(**") s 0 in + if blank_line (String.sub s 0 pos) or + d.Odoc_types.i_desc = Some [Odoc_types.Raw "/*"] + then + (0, None) + else + (len, Some d) + with + Not_found -> + (* should not occur *) + (0, None) + ) + | (len2, Some d2) -> + (0, None) in print_DEBUG ("just_after_special:end"); res @@ -279,32 +279,32 @@ module Info_retriever = let get_comments f_create_ele file s = let (assoc_com, ele_coms) = (* get the comments *) - let (len, special_coms) = all_special file s in - (* if there is no blank line after the special comments, and - if the last special comment is not the stop special comment, then the - last special comments must be associated to the element. *) - match List.rev special_coms with - [] -> - (None, []) - | h :: q -> - if (blank_line_outside_simple file - (String.sub s len ((String.length s) - len)) ) - or h.Odoc_types.i_desc = Some [Odoc_types.Raw "/*"] - then - (None, special_coms) - else - (Some h, List.rev q) + let (len, special_coms) = all_special file s in + (* if there is no blank line after the special comments, and + if the last special comment is not the stop special comment, then the + last special comments must be associated to the element. *) + match List.rev special_coms with + [] -> + (None, []) + | h :: q -> + if (blank_line_outside_simple file + (String.sub s len ((String.length s) - len)) ) + or h.Odoc_types.i_desc = Some [Odoc_types.Raw "/*"] + then + (None, special_coms) + else + (Some h, List.rev q) in let ele_comments = - List.fold_left - (fun acc -> fun sc -> - match sc.Odoc_types.i_desc with - None -> - acc - | Some t -> - acc @ [f_create_ele t]) - [] - ele_coms + List.fold_left + (fun acc -> fun sc -> + match sc.Odoc_types.i_desc with + None -> + acc + | Some t -> + acc @ [f_create_ele t]) + [] + ele_coms in (assoc_com, ele_comments) end diff --git a/ocamldoc/odoc_comments.mli b/ocamldoc/odoc_comments.mli index 50e891cdc..349ccaf96 100644 --- a/ocamldoc/odoc_comments.mli +++ b/ocamldoc/odoc_comments.mli @@ -44,7 +44,7 @@ module Basic_info_retriever : [str] to the end of the special comment. *) val first_special : string -> string -> int * Odoc_types.info option - + (** Return a pair [(comment_opt, element_comment_list)], where [comment_opt] is the last special comment found in the given string and not followed by a blank line, and [element_comment_list] the list of values built from the other diff --git a/ocamldoc/odoc_cross.ml b/ocamldoc/odoc_cross.ml index d422ba7c0..dda37d8ea 100644 --- a/ocamldoc/odoc_cross.ml +++ b/ocamldoc/odoc_cross.ml @@ -32,13 +32,13 @@ module P_alias = let p_module m _ = (true, match m.m_kind with - Module_alias _ -> true + Module_alias _ -> true | _ -> false ) let p_module_type mt _ = (true, match mt.mt_kind with - Some (Module_type_alias _) -> true + Some (Module_type_alias _) -> true | _ -> false ) let p_class c _ = (false, false) @@ -59,23 +59,23 @@ let rec build_alias_list (acc_m, acc_mt, acc_ex) = function (acc_m, acc_mt, acc_ex) | (Odoc_search.Res_module m) :: q -> let new_acc_m = - match m.m_kind with - Module_alias ma -> (m.m_name, ma.ma_name) :: acc_m - | _ -> acc_m + match m.m_kind with + Module_alias ma -> (m.m_name, ma.ma_name) :: acc_m + | _ -> acc_m in build_alias_list (new_acc_m, acc_mt, acc_ex) q | (Odoc_search.Res_module_type mt) :: q -> let new_acc_mt = - match mt.mt_kind with - Some (Module_type_alias mta) -> (mt.mt_name, mta.mta_name) :: acc_mt - | _ -> acc_mt + match mt.mt_kind with + Some (Module_type_alias mta) -> (mt.mt_name, mta.mta_name) :: acc_mt + | _ -> acc_mt in build_alias_list (acc_m, new_acc_mt, acc_ex) q | (Odoc_search.Res_exception e) :: q -> let new_acc_ex = - match e.ex_alias with - None -> acc_ex - | Some ea -> (e.ex_name, ea.ea_name) :: acc_ex + match e.ex_alias with + None -> acc_ex + | Some ea -> (e.ex_name, ea.ea_name) :: acc_ex in build_alias_list (acc_m, acc_mt, new_acc_ex) q | _ :: q -> @@ -124,9 +124,9 @@ module Search_by_complete_name = Odoc_search.Search (P_lookup) let rec lookup_module module_list name = let l = List.filter (fun res -> - match res with - Odoc_search.Res_module _ -> true - | _ -> false + match res with + Odoc_search.Res_module _ -> true + | _ -> false ) (Search_by_complete_name.search module_list name) in @@ -137,9 +137,9 @@ let rec lookup_module module_list name = let rec lookup_module_type module_list name = let l = List.filter (fun res -> - match res with - Odoc_search.Res_module_type _ -> true - | _ -> false + match res with + Odoc_search.Res_module_type _ -> true + | _ -> false ) (Search_by_complete_name.search module_list name) in @@ -150,9 +150,9 @@ let rec lookup_module_type module_list name = let rec lookup_class module_list name = let l = List.filter (fun res -> - match res with - Odoc_search.Res_class _ -> true - | _ -> false + match res with + Odoc_search.Res_class _ -> true + | _ -> false ) (Search_by_complete_name.search module_list name) in @@ -163,9 +163,9 @@ let rec lookup_class module_list name = let rec lookup_class_type module_list name = let l = List.filter (fun res -> - match res with - Odoc_search.Res_class_type _ -> true - | _ -> false + match res with + Odoc_search.Res_class_type _ -> true + | _ -> false ) (Search_by_complete_name.search module_list name) in @@ -176,9 +176,9 @@ let rec lookup_class_type module_list name = let rec lookup_exception module_list name = let l = List.filter (fun res -> - match res with - Odoc_search.Res_exception _ -> true - | _ -> false + match res with + Odoc_search.Res_exception _ -> true + | _ -> false ) (Search_by_complete_name.search module_list name) in @@ -202,97 +202,97 @@ let rec associate_in_module module_list (acc_b_modif, acc_incomplete_top_module_ let rec iter_kind (acc_b, acc_inc, acc_names) k = match k with Module_struct elements -> - List.fold_left - (associate_in_module_element module_list m.m_name) - (acc_b, acc_inc, acc_names) - elements - + List.fold_left + (associate_in_module_element module_list m.m_name) + (acc_b, acc_inc, acc_names) + elements + | Module_alias ma -> - ( - match ma.ma_module with - Some _ -> - (acc_b, acc_inc, acc_names) - | None -> - let mmt_opt = - try Some (Mod (lookup_module module_list ma.ma_name)) - with Not_found -> - try Some (Modtype (lookup_module_type module_list ma.ma_name)) - with Not_found -> None - in - match mmt_opt with - None -> (acc_b, (Name.head m.m_name) :: acc_inc, - (* we don't want to output warning messages for - "sig ... end" or "struct ... end" modules not found *) - (if ma.ma_name = Odoc_messages.struct_end or - ma.ma_name = Odoc_messages.sig_end then - acc_names - else - (NF_mmt ma.ma_name) :: acc_names) - ) - | Some mmt -> - ma.ma_module <- Some mmt ; - (true, acc_inc, acc_names) - ) + ( + match ma.ma_module with + Some _ -> + (acc_b, acc_inc, acc_names) + | None -> + let mmt_opt = + try Some (Mod (lookup_module module_list ma.ma_name)) + with Not_found -> + try Some (Modtype (lookup_module_type module_list ma.ma_name)) + with Not_found -> None + in + match mmt_opt with + None -> (acc_b, (Name.head m.m_name) :: acc_inc, + (* we don't want to output warning messages for + "sig ... end" or "struct ... end" modules not found *) + (if ma.ma_name = Odoc_messages.struct_end or + ma.ma_name = Odoc_messages.sig_end then + acc_names + else + (NF_mmt ma.ma_name) :: acc_names) + ) + | Some mmt -> + ma.ma_module <- Some mmt ; + (true, acc_inc, acc_names) + ) | Module_functor (_, k) -> - iter_kind (acc_b, acc_inc, acc_names) k + iter_kind (acc_b, acc_inc, acc_names) k | Module_with (tk, _) -> - associate_in_module_type module_list (acc_b, acc_inc, acc_names) - { mt_name = "" ; mt_info = None ; mt_type = None ; - mt_is_interface = false ; mt_file = ""; mt_kind = Some tk ; - mt_loc = Odoc_types.dummy_loc } - + associate_in_module_type module_list (acc_b, acc_inc, acc_names) + { mt_name = "" ; mt_info = None ; mt_type = None ; + mt_is_interface = false ; mt_file = ""; mt_kind = Some tk ; + mt_loc = Odoc_types.dummy_loc } + | Module_apply (k1, k2) -> - let (acc_b2, acc_inc2, acc_names2) = iter_kind (acc_b, acc_inc, acc_names) k1 in - iter_kind (acc_b2, acc_inc2, acc_names2) k2 + let (acc_b2, acc_inc2, acc_names2) = iter_kind (acc_b, acc_inc, acc_names) k1 in + iter_kind (acc_b2, acc_inc2, acc_names2) k2 | Module_constraint (k, tk) -> - let (acc_b2, acc_inc2, acc_names2) = iter_kind (acc_b, acc_inc, acc_names) k in - associate_in_module_type module_list (acc_b2, acc_inc2, acc_names2) - { mt_name = "" ; mt_info = None ; mt_type = None ; - mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; - mt_loc = Odoc_types.dummy_loc } + let (acc_b2, acc_inc2, acc_names2) = iter_kind (acc_b, acc_inc, acc_names) k in + associate_in_module_type module_list (acc_b2, acc_inc2, acc_names2) + { mt_name = "" ; mt_info = None ; mt_type = None ; + mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; + mt_loc = Odoc_types.dummy_loc } in iter_kind (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) m.m_kind - + and associate_in_module_type module_list (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) mt = let rec iter_kind (acc_b, acc_inc, acc_names) k = match k with Module_type_struct elements -> - List.fold_left - (associate_in_module_element module_list mt.mt_name) - (acc_b, acc_inc, acc_names) - elements + List.fold_left + (associate_in_module_element module_list mt.mt_name) + (acc_b, acc_inc, acc_names) + elements | Module_type_functor (_, k) -> - iter_kind (acc_b, acc_inc, acc_names) k + iter_kind (acc_b, acc_inc, acc_names) k | Module_type_with (k, _) -> - iter_kind (acc_b, acc_inc, acc_names) k + iter_kind (acc_b, acc_inc, acc_names) k | Module_type_alias mta -> - match mta.mta_module with - Some _ -> - (acc_b, acc_inc, acc_names) - | None -> - let mt_opt = - try Some (lookup_module_type module_list mta.mta_name) - with Not_found -> None - in - match mt_opt with - None -> (acc_b, (Name.head mt.mt_name) :: acc_inc, - (* we don't want to output warning messages for - "sig ... end" or "struct ... end" modules not found *) - (if mta.mta_name = Odoc_messages.struct_end or - mta.mta_name = Odoc_messages.sig_end then - acc_names - else - (NF_mt mta.mta_name) :: acc_names) - ) - | Some mt -> - mta.mta_module <- Some mt ; - (true, acc_inc, acc_names) + match mta.mta_module with + Some _ -> + (acc_b, acc_inc, acc_names) + | None -> + let mt_opt = + try Some (lookup_module_type module_list mta.mta_name) + with Not_found -> None + in + match mt_opt with + None -> (acc_b, (Name.head mt.mt_name) :: acc_inc, + (* we don't want to output warning messages for + "sig ... end" or "struct ... end" modules not found *) + (if mta.mta_name = Odoc_messages.struct_end or + mta.mta_name = Odoc_messages.sig_end then + acc_names + else + (NF_mt mta.mta_name) :: acc_names) + ) + | Some mt -> + mta.mta_module <- Some mt ; + (true, acc_inc, acc_names) in match mt.mt_kind with None -> (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) @@ -304,50 +304,50 @@ and associate_in_module_element module_list m_name (acc_b_modif, acc_incomplete_ | Element_module_type mt -> associate_in_module_type module_list (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) mt | Element_included_module im -> ( - match im.im_module with - Some _ -> (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) - | None -> - let mmt_opt = - try Some (Mod (lookup_module module_list im.im_name)) - with Not_found -> - try Some (Modtype (lookup_module_type module_list im.im_name)) - with Not_found -> None - in - match mmt_opt with - None -> (acc_b_modif, (Name.head m_name) :: acc_incomplete_top_module_names, - (* we don't want to output warning messages for - "sig ... end" or "struct ... end" modules not found *) - (if im.im_name = Odoc_messages.struct_end or - im.im_name = Odoc_messages.sig_end then - acc_names_not_found - else - (NF_mmt im.im_name) :: acc_names_not_found) - ) - | Some mmt -> - im.im_module <- Some mmt ; - (true, acc_incomplete_top_module_names, acc_names_not_found) + match im.im_module with + Some _ -> (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) + | None -> + let mmt_opt = + try Some (Mod (lookup_module module_list im.im_name)) + with Not_found -> + try Some (Modtype (lookup_module_type module_list im.im_name)) + with Not_found -> None + in + match mmt_opt with + None -> (acc_b_modif, (Name.head m_name) :: acc_incomplete_top_module_names, + (* we don't want to output warning messages for + "sig ... end" or "struct ... end" modules not found *) + (if im.im_name = Odoc_messages.struct_end or + im.im_name = Odoc_messages.sig_end then + acc_names_not_found + else + (NF_mmt im.im_name) :: acc_names_not_found) + ) + | Some mmt -> + im.im_module <- Some mmt ; + (true, acc_incomplete_top_module_names, acc_names_not_found) ) | Element_class cl -> associate_in_class module_list (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) cl | Element_class_type ct -> associate_in_class_type module_list (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) ct | Element_value _ -> (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) | Element_exception ex -> ( - match ex.ex_alias with - None -> (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) - | Some ea -> - match ea.ea_ex with - Some _ -> - (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) - | None -> - let ex_opt = - try Some (lookup_exception module_list ea.ea_name) - with Not_found -> None - in - match ex_opt with - None -> (acc_b_modif, (Name.head m_name) :: acc_incomplete_top_module_names, (NF_ex ea.ea_name) :: acc_names_not_found) - | Some e -> - ea.ea_ex <- Some e ; - (true, acc_incomplete_top_module_names, acc_names_not_found) + match ex.ex_alias with + None -> (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) + | Some ea -> + match ea.ea_ex with + Some _ -> + (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) + | None -> + let ex_opt = + try Some (lookup_exception module_list ea.ea_name) + with Not_found -> None + in + match ex_opt with + None -> (acc_b_modif, (Name.head m_name) :: acc_incomplete_top_module_names, (NF_ex ea.ea_name) :: acc_names_not_found) + | Some e -> + ea.ea_ex <- Some e ; + (true, acc_incomplete_top_module_names, acc_names_not_found) ) | Element_type _ -> (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) | Element_module_comment _ -> (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) @@ -356,82 +356,82 @@ and associate_in_class module_list (acc_b_modif, acc_incomplete_top_module_names let rec iter_kind (acc_b, acc_inc, acc_names) k = match k with Class_structure (inher_l, _) -> - let f (acc_b2, acc_inc2, acc_names2) ic = - match ic.ic_class with - Some _ -> (acc_b2, acc_inc2, acc_names2) - | None -> - let cct_opt = - try Some (Cl (lookup_class module_list ic.ic_name)) - with Not_found -> - try Some (Cltype (lookup_class_type module_list ic.ic_name, [])) - with Not_found -> None - in - match cct_opt with - None -> (acc_b2, (Name.head c.cl_name) :: acc_inc2, - (* we don't want to output warning messages for "object ... end" classes not found *) - (if ic.ic_name = Odoc_messages.object_end then acc_names2 else (NF_cct ic.ic_name) :: acc_names2)) - | Some cct -> - ic.ic_class <- Some cct ; - (true, acc_inc2, acc_names2) - in - List.fold_left f (acc_b, acc_inc, acc_names) inher_l + let f (acc_b2, acc_inc2, acc_names2) ic = + match ic.ic_class with + Some _ -> (acc_b2, acc_inc2, acc_names2) + | None -> + let cct_opt = + try Some (Cl (lookup_class module_list ic.ic_name)) + with Not_found -> + try Some (Cltype (lookup_class_type module_list ic.ic_name, [])) + with Not_found -> None + in + match cct_opt with + None -> (acc_b2, (Name.head c.cl_name) :: acc_inc2, + (* we don't want to output warning messages for "object ... end" classes not found *) + (if ic.ic_name = Odoc_messages.object_end then acc_names2 else (NF_cct ic.ic_name) :: acc_names2)) + | Some cct -> + ic.ic_class <- Some cct ; + (true, acc_inc2, acc_names2) + in + List.fold_left f (acc_b, acc_inc, acc_names) inher_l | Class_apply capp -> - ( - match capp.capp_class with - Some _ -> (acc_b, acc_inc, acc_names) - | None -> - let cl_opt = - try Some (lookup_class module_list capp.capp_name) - with Not_found -> None - in - match cl_opt with - None -> (acc_b, (Name.head c.cl_name) :: acc_inc, - (* we don't want to output warning messages for "object ... end" classes not found *) - (if capp.capp_name = Odoc_messages.object_end then acc_names else (NF_c capp.capp_name) :: acc_names)) - | Some c -> - capp.capp_class <- Some c ; - (true, acc_inc, acc_names) - ) + ( + match capp.capp_class with + Some _ -> (acc_b, acc_inc, acc_names) + | None -> + let cl_opt = + try Some (lookup_class module_list capp.capp_name) + with Not_found -> None + in + match cl_opt with + None -> (acc_b, (Name.head c.cl_name) :: acc_inc, + (* we don't want to output warning messages for "object ... end" classes not found *) + (if capp.capp_name = Odoc_messages.object_end then acc_names else (NF_c capp.capp_name) :: acc_names)) + | Some c -> + capp.capp_class <- Some c ; + (true, acc_inc, acc_names) + ) | Class_constr cco -> - ( - match cco.cco_class with - Some _ -> (acc_b, acc_inc, acc_names) - | None -> - let cl_opt = - try Some (lookup_class module_list cco.cco_name) - with Not_found -> None - in - match cl_opt with - None -> - ( - let clt_opt = - try Some (lookup_class_type module_list cco.cco_name) - with Not_found -> None - in - match clt_opt with - None -> - (acc_b, (Name.head c.cl_name) :: acc_inc, - (* we don't want to output warning messages for "object ... end" classes not found *) - (if cco.cco_name = Odoc_messages.object_end then acc_names else (NF_cct cco.cco_name) :: acc_names)) - | Some ct -> - cco.cco_class <- Some (Cltype (ct, [])) ; - (true, acc_inc, acc_names) - ) - | Some c -> - cco.cco_class <- Some (Cl c) ; - (true, acc_inc, acc_names) - ) + ( + match cco.cco_class with + Some _ -> (acc_b, acc_inc, acc_names) + | None -> + let cl_opt = + try Some (lookup_class module_list cco.cco_name) + with Not_found -> None + in + match cl_opt with + None -> + ( + let clt_opt = + try Some (lookup_class_type module_list cco.cco_name) + with Not_found -> None + in + match clt_opt with + None -> + (acc_b, (Name.head c.cl_name) :: acc_inc, + (* we don't want to output warning messages for "object ... end" classes not found *) + (if cco.cco_name = Odoc_messages.object_end then acc_names else (NF_cct cco.cco_name) :: acc_names)) + | Some ct -> + cco.cco_class <- Some (Cltype (ct, [])) ; + (true, acc_inc, acc_names) + ) + | Some c -> + cco.cco_class <- Some (Cl c) ; + (true, acc_inc, acc_names) + ) | Class_constraint (ckind, ctkind) -> - let (acc_b2, acc_inc2, acc_names2) = iter_kind (acc_b, acc_inc, acc_names) ckind in - associate_in_class_type module_list (acc_b2, acc_inc2, acc_names2) - { clt_name = "" ; clt_info = None ; - clt_type = c.cl_type ; (* should be ok *) - clt_type_parameters = [] ; - clt_virtual = false ; - clt_kind = ctkind ; - clt_loc = Odoc_types.dummy_loc } + let (acc_b2, acc_inc2, acc_names2) = iter_kind (acc_b, acc_inc, acc_names) ckind in + associate_in_class_type module_list (acc_b2, acc_inc2, acc_names2) + { clt_name = "" ; clt_info = None ; + clt_type = c.cl_type ; (* should be ok *) + clt_type_parameters = [] ; + clt_virtual = false ; + clt_kind = ctkind ; + clt_loc = Odoc_types.dummy_loc } in iter_kind (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) c.cl_kind @@ -439,45 +439,45 @@ and associate_in_class_type module_list (acc_b_modif, acc_incomplete_top_module_ let rec iter_kind (acc_b, acc_inc, acc_names) k = match k with Class_signature (inher_l, _) -> - let f (acc_b2, acc_inc2, acc_names2) ic = - match ic.ic_class with - Some _ -> (acc_b2, acc_inc2, acc_names2) - | None -> - let cct_opt = - try Some (Cltype (lookup_class_type module_list ic.ic_name, [])) - with Not_found -> - try Some (Cl (lookup_class module_list ic.ic_name)) - with Not_found -> None - in - match cct_opt with - None -> (acc_b2, (Name.head ct.clt_name) :: acc_inc2, - (* we don't want to output warning messages for "object ... end" class types not found *) - (if ic.ic_name = Odoc_messages.object_end then acc_names2 else (NF_cct ic.ic_name) :: acc_names2)) - | Some cct -> - ic.ic_class <- Some cct ; - (true, acc_inc2, acc_names2) - in - List.fold_left f (acc_b, acc_inc, acc_names) inher_l + let f (acc_b2, acc_inc2, acc_names2) ic = + match ic.ic_class with + Some _ -> (acc_b2, acc_inc2, acc_names2) + | None -> + let cct_opt = + try Some (Cltype (lookup_class_type module_list ic.ic_name, [])) + with Not_found -> + try Some (Cl (lookup_class module_list ic.ic_name)) + with Not_found -> None + in + match cct_opt with + None -> (acc_b2, (Name.head ct.clt_name) :: acc_inc2, + (* we don't want to output warning messages for "object ... end" class types not found *) + (if ic.ic_name = Odoc_messages.object_end then acc_names2 else (NF_cct ic.ic_name) :: acc_names2)) + | Some cct -> + ic.ic_class <- Some cct ; + (true, acc_inc2, acc_names2) + in + List.fold_left f (acc_b, acc_inc, acc_names) inher_l | Class_type cta -> - ( - match cta.cta_class with - Some _ -> (acc_b, acc_inc, acc_names) - | None -> - let cct_opt = - try Some (Cltype (lookup_class_type module_list cta.cta_name, [])) - with Not_found -> - try Some (Cl (lookup_class module_list cta.cta_name)) - with Not_found -> None - in - match cct_opt with - None -> (acc_b, (Name.head ct.clt_name) :: acc_inc, - (* we don't want to output warning messages for "object ... end" class types not found *) - (if cta.cta_name = Odoc_messages.object_end then acc_names else (NF_cct cta.cta_name) :: acc_names)) - | Some c -> - cta.cta_class <- Some c ; - (true, acc_inc, acc_names) - ) + ( + match cta.cta_class with + Some _ -> (acc_b, acc_inc, acc_names) + | None -> + let cct_opt = + try Some (Cltype (lookup_class_type module_list cta.cta_name, [])) + with Not_found -> + try Some (Cl (lookup_class module_list cta.cta_name)) + with Not_found -> None + in + match cct_opt with + None -> (acc_b, (Name.head ct.clt_name) :: acc_inc, + (* we don't want to output warning messages for "object ... end" class types not found *) + (if cta.cta_name = Odoc_messages.object_end then acc_names else (NF_cct cta.cta_name) :: acc_names)) + | Some c -> + cta.cta_class <- Some c ; + (true, acc_inc, acc_names) + ) in iter_kind (acc_b_modif, acc_incomplete_top_module_names, acc_names_not_found) ct.clt_kind @@ -500,8 +500,8 @@ let rec assoc_comments_text_elements module_list t_ele = | Left t -> Left (assoc_comments_text module_list t) | Right t -> Right (assoc_comments_text module_list t) | Emphasize t -> Emphasize (assoc_comments_text module_list t) - | List l -> List (List.map (assoc_comments_text module_list) l) - | Enum l -> Enum (List.map (assoc_comments_text module_list) l) + | List l -> List (List.map (assoc_comments_text module_list) l) + | Enum l -> Enum (List.map (assoc_comments_text module_list) l) | Newline -> Newline | Block t -> Block (assoc_comments_text module_list t) | Superscript t -> Superscript (assoc_comments_text module_list t) @@ -509,27 +509,27 @@ let rec assoc_comments_text_elements module_list t_ele = | Title (n, l_opt, t) -> Title (n, l_opt, (assoc_comments_text module_list t)) | Link (s, t) -> Link (s, (assoc_comments_text module_list t)) | Ref (name, None) -> - let re = Str.regexp ("^"^(Str.quote name)^"$") in - let res = Odoc_search.Search_by_name.search module_list re in - match res with - [] -> - Odoc_messages.pwarning (Odoc_messages.cross_element_not_found name); - t_ele - | ele :: _ -> - let kind = - match ele with - Odoc_search.Res_module _ -> RK_module - | Odoc_search.Res_module_type _ -> RK_module_type - | Odoc_search.Res_class _ -> RK_class - | Odoc_search.Res_class_type _ -> RK_class_type - | Odoc_search.Res_value _ -> RK_value - | Odoc_search.Res_type _ -> RK_type - | Odoc_search.Res_exception _ -> RK_exception - | Odoc_search.Res_attribute _ -> RK_attribute - | Odoc_search.Res_method _ -> RK_method - | Odoc_search.Res_section _ -> RK_section - in - Ref (name, Some kind) + let re = Str.regexp ("^"^(Str.quote name)^"$") in + let res = Odoc_search.Search_by_name.search module_list re in + match res with + [] -> + Odoc_messages.pwarning (Odoc_messages.cross_element_not_found name); + t_ele + | ele :: _ -> + let kind = + match ele with + Odoc_search.Res_module _ -> RK_module + | Odoc_search.Res_module_type _ -> RK_module_type + | Odoc_search.Res_class _ -> RK_class + | Odoc_search.Res_class_type _ -> RK_class_type + | Odoc_search.Res_value _ -> RK_value + | Odoc_search.Res_type _ -> RK_type + | Odoc_search.Res_exception _ -> RK_exception + | Odoc_search.Res_attribute _ -> RK_attribute + | Odoc_search.Res_method _ -> RK_method + | Odoc_search.Res_section _ -> RK_section + in + Ref (name, Some kind) and assoc_comments_text module_list text = List.map (assoc_comments_text_elements module_list) text @@ -574,12 +574,12 @@ and assoc_comments_module_kind module_list mk = mk | Module_apply (mk1, mk2) -> Module_apply (assoc_comments_module_kind module_list mk1, - assoc_comments_module_kind module_list mk2) + assoc_comments_module_kind module_list mk2) | Module_with (mtk, s) -> Module_with (assoc_comments_module_type_kind module_list mtk, s) | Module_constraint (mk1, mtk) -> Module_constraint (assoc_comments_module_kind module_list mk1, - assoc_comments_module_type_kind module_list mtk) + assoc_comments_module_type_kind module_list mtk) and assoc_comments_module_type_kind module_list mtk = match mtk with @@ -596,10 +596,10 @@ and assoc_comments_class_kind module_list ck = match ck with Class_structure (inher, eles) -> let inher2 = - List.map - (fun ic -> { ic with - ic_text = ao (assoc_comments_text module_list) ic.ic_text }) - inher + List.map + (fun ic -> { ic with + ic_text = ao (assoc_comments_text module_list) ic.ic_text }) + inher in Class_structure (inher2, List.map (assoc_comments_class_element module_list) eles) @@ -607,16 +607,16 @@ and assoc_comments_class_kind module_list ck = | Class_constr _ -> ck | Class_constraint (ck1, ctk) -> Class_constraint (assoc_comments_class_kind module_list ck1, - assoc_comments_class_type_kind module_list ctk) + assoc_comments_class_type_kind module_list ctk) and assoc_comments_class_type_kind module_list ctk = match ctk with Class_signature (inher, eles) -> let inher2 = - List.map - (fun ic -> { ic with - ic_text = ao (assoc_comments_text module_list) ic.ic_text }) - inher + List.map + (fun ic -> { ic with + ic_text = ao (assoc_comments_text module_list) ic.ic_text }) + inher in Class_signature (inher2, List.map (assoc_comments_class_element module_list) eles) @@ -669,12 +669,12 @@ and assoc_comments_type module_list t = Type_abstract -> () | Type_variant vl -> List.iter - (fun vc -> vc.vc_text <- ao (assoc_comments_text module_list) vc.vc_text) - vl + (fun vc -> vc.vc_text <- ao (assoc_comments_text module_list) vc.vc_text) + vl | Type_record fl -> List.iter - (fun rf -> rf.rf_text <- ao (assoc_comments_text module_list) rf.rf_text) - fl + (fun rf -> rf.rf_text <- ao (assoc_comments_text module_list) rf.rf_text) + fl ); t @@ -699,8 +699,8 @@ let associate module_list = let rec remove_doubles acc = function [] -> acc | h :: q -> - if List.mem h acc then remove_doubles acc q - else remove_doubles (h :: acc) q + if List.mem h acc then remove_doubles acc q + else remove_doubles (h :: acc) q in let rec iter incomplete_modules = let (b_modif, remaining_inc_modules, acc_names_not_found) = @@ -708,8 +708,8 @@ let associate module_list = in let remaining_no_doubles = remove_doubles [] remaining_inc_modules in let remaining_modules = List.filter - (fun m -> List.mem m.m_name remaining_no_doubles) - incomplete_modules + (fun m -> List.mem m.m_name remaining_no_doubles) + incomplete_modules in if b_modif then (* we may be able to associate something else *) @@ -725,23 +725,23 @@ let associate module_list = () | l -> List.iter - (fun nf -> - Odoc_messages.pwarning - ( - match nf with - NF_m n -> Odoc_messages.cross_module_not_found n - | NF_mt n -> Odoc_messages.cross_module_type_not_found n - | NF_mmt n -> Odoc_messages.cross_module_or_module_type_not_found n - | NF_c n -> Odoc_messages.cross_class_not_found n - | NF_ct n -> Odoc_messages.cross_class_type_not_found n - | NF_cct n -> Odoc_messages.cross_class_or_class_type_not_found n - | NF_ex n -> Odoc_messages.cross_exception_not_found n - ); - ) - l + (fun nf -> + Odoc_messages.pwarning + ( + match nf with + NF_m n -> Odoc_messages.cross_module_not_found n + | NF_mt n -> Odoc_messages.cross_module_type_not_found n + | NF_mmt n -> Odoc_messages.cross_module_or_module_type_not_found n + | NF_c n -> Odoc_messages.cross_class_not_found n + | NF_ct n -> Odoc_messages.cross_class_type_not_found n + | NF_cct n -> Odoc_messages.cross_class_or_class_type_not_found n + | NF_ex n -> Odoc_messages.cross_exception_not_found n + ); + ) + l ) ; (* Find a type for each name of element which is referenced in comments. *) let _ = associate_type_of_elements_in_comments module_list in () - + diff --git a/ocamldoc/odoc_dag2html.ml b/ocamldoc/odoc_dag2html.ml index 7ddf4d57c..4231bab00 100644 --- a/ocamldoc/odoc_dag2html.ml +++ b/ocamldoc/odoc_dag2html.ml @@ -1661,54 +1661,54 @@ let create_class_dag cl_list clt_list = let all_classes = let rec iter list2 = List.fold_left - (fun acc -> fun (name, cct_opt) -> - let l = - match cct_opt with - None -> [] - | Some (M.Cl c) -> - iter - (List.map - (fun inh ->(inh.M.ic_name, inh.M.ic_class)) - (match c.M.cl_kind with - M.Class_structure (inher_l, _) -> - inher_l - | _ -> - [] - ) - ) - | Some (M.Cltype (ct, _)) -> - iter - (List.map - (fun inh ->(inh.M.ic_name, inh.M.ic_class)) - (match ct.M.clt_kind with - M.Class_signature (inher_l, _) -> - inher_l - | _ -> - [] - ) - ) - in - (name, cct_opt) :: (acc @ l) - ) - [] - list2 + (fun acc -> fun (name, cct_opt) -> + let l = + match cct_opt with + None -> [] + | Some (M.Cl c) -> + iter + (List.map + (fun inh ->(inh.M.ic_name, inh.M.ic_class)) + (match c.M.cl_kind with + M.Class_structure (inher_l, _) -> + inher_l + | _ -> + [] + ) + ) + | Some (M.Cltype (ct, _)) -> + iter + (List.map + (fun inh ->(inh.M.ic_name, inh.M.ic_class)) + (match ct.M.clt_kind with + M.Class_signature (inher_l, _) -> + inher_l + | _ -> + [] + ) + ) + in + (name, cct_opt) :: (acc @ l) + ) + [] + list2 in iter list in let rec distinct acc = function [] -> acc - | (name, cct_opt) :: q -> - if List.exists (fun (name2, _) -> name = name2) acc then - distinct acc q - else - distinct ((name, cct_opt) :: acc) q + | (name, cct_opt) :: q -> + if List.exists (fun (name2, _) -> name = name2) acc then + distinct acc q + else + distinct ((name, cct_opt) :: acc) q in let distinct_classes = distinct [] all_classes in let liste_index = let rec f n = function - [] -> [] - | (name, _) :: q -> (name, n) :: (f (n+1) q) + [] -> [] + | (name, _) :: q -> (name, n) :: (f (n+1) q) in f 0 distinct_classes in @@ -1716,24 +1716,24 @@ let create_class_dag cl_list clt_list = (* create the dag array, filling parents and values *) let fmap (name, cct_opt) = { pare = List.map - (fun inh -> List.assoc inh.M.ic_name liste_index ) - (match cct_opt with - None -> [] - | Some (M.Cl c) -> - (match c.M.cl_kind with - M.Class_structure (inher_l, _) -> - inher_l - | _ -> - [] - ) - | Some (M.Cltype (ct, _)) -> - (match ct.M.clt_kind with - M.Class_signature (inher_l, _) -> - inher_l - | _ -> - [] - ) - ); + (fun inh -> List.assoc inh.M.ic_name liste_index ) + (match cct_opt with + None -> [] + | Some (M.Cl c) -> + (match c.M.cl_kind with + M.Class_structure (inher_l, _) -> + inher_l + | _ -> + [] + ) + | Some (M.Cltype (ct, _)) -> + (match ct.M.clt_kind with + M.Class_signature (inher_l, _) -> + inher_l + | _ -> + [] + ) + ); valu = (name, cct_opt) ; chil = [] } @@ -1743,7 +1743,7 @@ let create_class_dag cl_list clt_list = let fiter i node = let l = Array.to_list dag.dag in let l2 = List.map (fun n -> n.valu) - (List.filter (fun n -> List.mem i n.pare) l) + (List.filter (fun n -> List.mem i n.pare) l) in node.chil <- List.map (fun (name,_) -> List.assoc name liste_index) l2 in @@ -1752,4 +1752,4 @@ let create_class_dag cl_list clt_list = - + diff --git a/ocamldoc/odoc_dag2html.mli b/ocamldoc/odoc_dag2html.mli index 96d44affa..b66de064c 100644 --- a/ocamldoc/odoc_dag2html.mli +++ b/ocamldoc/odoc_dag2html.mli @@ -25,6 +25,6 @@ val html_of_dag : string dag -> string val create_class_dag : Odoc_info.Class.t_class list -> Odoc_info.Class.t_class_type list -> - (Odoc_info.Name.t * Odoc_info.Class.cct option) dag + (Odoc_info.Name.t * Odoc_info.Class.cct option) dag diff --git a/ocamldoc/odoc_dep.ml b/ocamldoc/odoc_dep.ml index ad8d94f4c..c87423f21 100644 --- a/ocamldoc/odoc_dep.ml +++ b/ocamldoc/odoc_dep.ml @@ -49,50 +49,50 @@ module Dep = !l type node = { - id : id ; - mutable near : S.t ; (** fils directs *) - mutable far : (id * S.t) list ; (** fils indirects, par quel fils *) - reflex : bool ; (** reflexive or not, we keep - information here to remove the node itself from its direct children *) + id : id ; + mutable near : S.t ; (** fils directs *) + mutable far : (id * S.t) list ; (** fils indirects, par quel fils *) + reflex : bool ; (** reflexive or not, we keep + information here to remove the node itself from its direct children *) } type graph = node list let make_node s children = let set = List.fold_right - S.add - children - S.empty + S.add + children + S.empty in { id = s; - near = S.remove s set ; - far = [] ; - reflex = List.mem s children ; + near = S.remove s set ; + far = [] ; + reflex = List.mem s children ; } let get_node graph s = try List.find (fun n -> n.id = s) graph with Not_found -> - make_node s [] + make_node s [] let rec trans_closure graph acc n = if S.mem n.id acc then - acc + acc else - (* optimisation plus tard : utiliser le champ far si non vide ? *) - S.fold - (fun child -> fun acc2 -> - trans_closure graph acc2 (get_node graph child)) - n.near - (S.add n.id acc) + (* optimisation plus tard : utiliser le champ far si non vide ? *) + S.fold + (fun child -> fun acc2 -> + trans_closure graph acc2 (get_node graph child)) + n.near + (S.add n.id acc) let node_trans_closure graph n = let far = List.map - (fun child -> - let set = trans_closure graph S.empty (get_node graph child) in - (child, set) - ) - (set_to_list n.near) + (fun child -> + let set = trans_closure graph S.empty (get_node graph child) in + (child, set) + ) + (set_to_list n.near) in n.far <- far @@ -101,31 +101,31 @@ module Dep = let prune_node graph node = S.iter - (fun child -> - let set_reachables = List.fold_left - (fun acc -> fun (ch, reachables) -> - if child = ch then - acc - else - S.union acc reachables - ) - S.empty - node.far - in - let set = S.remove node.id set_reachables in - if S.exists (fun n2 -> S.mem child (get_node graph n2).near) set then - ( - node.near <- S.remove child node.near ; - node.far <- List.filter (fun (ch,_) -> ch <> child) node.far - ) - else - () - ) - node.near; + (fun child -> + let set_reachables = List.fold_left + (fun acc -> fun (ch, reachables) -> + if child = ch then + acc + else + S.union acc reachables + ) + S.empty + node.far + in + let set = S.remove node.id set_reachables in + if S.exists (fun n2 -> S.mem child (get_node graph n2).near) set then + ( + node.near <- S.remove child node.near ; + node.far <- List.filter (fun (ch,_) -> ch <> child) node.far + ) + else + () + ) + node.near; if node.reflex then - node.near <- S.add node.id node.near + node.near <- S.add node.id node.near else - () + () let kernel graph = (* compute transitive closure *) @@ -153,22 +153,22 @@ let type_deps t = T.Type_abstract -> () | T.Type_variant cl -> List.iter - (fun c -> - List.iter - (fun e -> - let s = Odoc_misc.string_of_type_expr e in - ignore (Str.global_substitute re f s) - ) - c.T.vc_args - ) - cl + (fun c -> + List.iter + (fun e -> + let s = Odoc_misc.string_of_type_expr e in + ignore (Str.global_substitute re f s) + ) + c.T.vc_args + ) + cl | T.Type_record rl -> List.iter - (fun r -> - let s = Odoc_misc.string_of_type_expr r.T.rf_type in - ignore (Str.global_substitute re f s) - ) - rl + (fun r -> + let s = Odoc_misc.string_of_type_expr r.T.rf_type in + ignore (Str.global_substitute re f s) + ) + rl ); (match t.T.ty_manifest with @@ -192,7 +192,7 @@ let kernel_deps_of_modules modules = (fun m -> let node = Dep.get_node k m.Module.m_name in m.Module.m_top_deps <- - List.filter (fun m2 -> Dep.S.mem m2 node.Dep.near) m.Module.m_top_deps) + List.filter (fun m2 -> Dep.S.mem m2 node.Dep.near) m.Module.m_top_deps) modules (** Return the list of dependencies between the given types, @@ -206,16 +206,16 @@ let deps_of_types ?(kernel=false) types = if kernel then ( let graph = List.map - (fun (t, names) -> Dep.make_node t.Type.ty_name names) - deps_pre + (fun (t, names) -> Dep.make_node t.Type.ty_name names) + deps_pre in let k = Dep.kernel graph in List.map - (fun t -> - let node = Dep.get_node k t.Type.ty_name in - (t, Dep.set_to_list node.Dep.near) - ) - types + (fun t -> + let node = Dep.get_node k t.Type.ty_name in + (t, Dep.set_to_list node.Dep.near) + ) + types ) else deps_pre diff --git a/ocamldoc/odoc_dot.ml b/ocamldoc/odoc_dot.ml index 55a900426..2a5366f47 100644 --- a/ocamldoc/odoc_dot.ml +++ b/ocamldoc/odoc_dot.ml @@ -42,40 +42,40 @@ class dot = method get_one_color = match colors with - [] -> None - | h :: q -> - colors <- q ; - Some h + [] -> None + | h :: q -> + colors <- q ; + Some h method node_color s = try Some (List.assoc s loc_colors) with - Not_found -> - match self#get_one_color with - None -> None - | Some c -> - loc_colors <- (s, c) :: loc_colors ; - Some c + Not_found -> + match self#get_one_color with + None -> None + | Some c -> + loc_colors <- (s, c) :: loc_colors ; + Some c method print_module_atts fmt m = match self#node_color (Filename.dirname m.Module.m_file) with - None -> () - | Some col -> F.fprintf fmt "\"%s\" [style=filled, color=%s];\n" m.Module.m_name col + None -> () + | Some col -> F.fprintf fmt "\"%s\" [style=filled, color=%s];\n" m.Module.m_name col method print_type_atts fmt t = match self#node_color (Name.father t.Type.ty_name) with - None -> () - | Some col -> F.fprintf fmt "\"%s\" [style=filled, color=%s];\n" t.Type.ty_name col + None -> () + | Some col -> F.fprintf fmt "\"%s\" [style=filled, color=%s];\n" t.Type.ty_name col method print_one_dep fmt src dest = F.fprintf fmt "\"%s\" -> \"%s\";\n" src dest method generate_for_module fmt m = let l = List.filter - (fun n -> - !Odoc_args.dot_include_all or - (List.exists (fun m -> m.Module.m_name = n) modules)) - m.Module.m_top_deps + (fun n -> + !Odoc_args.dot_include_all or + (List.exists (fun m -> m.Module.m_name = n) modules)) + m.Module.m_top_deps in self#print_module_atts fmt m; List.iter (self#print_one_dep fmt m.Module.m_name) l @@ -83,48 +83,48 @@ class dot = method generate_for_type fmt (t, l) = self#print_type_atts fmt t; List.iter - (self#print_one_dep fmt t.Type.ty_name) - l + (self#print_one_dep fmt t.Type.ty_name) + l method generate_types types = try - let oc = open_out !Odoc_args.out_file in - let fmt = F.formatter_of_out_channel oc in - F.fprintf fmt "%s" self#header; - let graph = Odoc_info.Dep.deps_of_types - ~kernel: !Odoc_args.dot_reduce - types - in - List.iter (self#generate_for_type fmt) graph; - F.fprintf fmt "}\n" ; - F.pp_print_flush fmt (); - close_out oc + let oc = open_out !Odoc_args.out_file in + let fmt = F.formatter_of_out_channel oc in + F.fprintf fmt "%s" self#header; + let graph = Odoc_info.Dep.deps_of_types + ~kernel: !Odoc_args.dot_reduce + types + in + List.iter (self#generate_for_type fmt) graph; + F.fprintf fmt "}\n" ; + F.pp_print_flush fmt (); + close_out oc with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) method generate_modules modules_list = try - modules <- modules_list ; - let oc = open_out !Odoc_args.out_file in - let fmt = F.formatter_of_out_channel oc in - F.fprintf fmt "%s" self#header; - - if !Odoc_args.dot_reduce then - Odoc_info.Dep.kernel_deps_of_modules modules_list; - - List.iter (self#generate_for_module fmt) modules_list; - F.fprintf fmt "}\n" ; - F.pp_print_flush fmt (); - close_out oc + modules <- modules_list ; + let oc = open_out !Odoc_args.out_file in + let fmt = F.formatter_of_out_channel oc in + F.fprintf fmt "%s" self#header; + + if !Odoc_args.dot_reduce then + Odoc_info.Dep.kernel_deps_of_modules modules_list; + + List.iter (self#generate_for_module fmt) modules_list; + F.fprintf fmt "}\n" ; + F.pp_print_flush fmt (); + close_out oc with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) (** Generate the dot code in the file {!Odoc_args.out_file}. *) method generate (modules_list : Odoc_info.Module.t_module list) = if !Odoc_args.dot_types then - self#generate_types (Odoc_info.Search.types modules_list) + self#generate_types (Odoc_info.Search.types modules_list) else - self#generate_modules modules_list + self#generate_modules modules_list end diff --git a/ocamldoc/odoc_env.ml b/ocamldoc/odoc_env.ml index 4eb5cf02a..a9432a5af 100644 --- a/ocamldoc/odoc_env.ml +++ b/ocamldoc/odoc_env.ml @@ -54,24 +54,24 @@ let rec add_signature env root ?rel signat = | Types.Tsig_type (ident,_ ) -> { env with env_types = (rel_name ident, qualify ident) :: env.env_types } | Types.Tsig_exception (ident, _) -> { env with env_exceptions = (rel_name ident, qualify ident) :: env.env_exceptions } | Types.Tsig_module (ident, modtype) -> - let env2 = - match modtype with (* A VOIR : le cas o� c'est un identificateur, dans ce cas on n'a pas de signature *) - Types.Tmty_signature s -> add_signature env (qualify ident) ~rel: (rel_name ident) s - | _ -> env - in - { env2 with env_modules = (rel_name ident, qualify ident) :: env2.env_modules } + let env2 = + match modtype with (* A VOIR : le cas o� c'est un identificateur, dans ce cas on n'a pas de signature *) + Types.Tmty_signature s -> add_signature env (qualify ident) ~rel: (rel_name ident) s + | _ -> env + in + { env2 with env_modules = (rel_name ident, qualify ident) :: env2.env_modules } | Types.Tsig_modtype (ident, modtype_decl) -> - let env2 = - match modtype_decl with - Types.Tmodtype_abstract -> - env - | Types.Tmodtype_manifest modtype -> - match modtype with - (* A VOIR : le cas o� c'est un identificateur, dans ce cas on n'a pas de signature *) - Types.Tmty_signature s -> add_signature env (qualify ident) ~rel: (rel_name ident) s - | _ -> env - in - { env2 with env_module_types = (rel_name ident, qualify ident) :: env2.env_module_types } + let env2 = + match modtype_decl with + Types.Tmodtype_abstract -> + env + | Types.Tmodtype_manifest modtype -> + match modtype with + (* A VOIR : le cas o� c'est un identificateur, dans ce cas on n'a pas de signature *) + Types.Tmty_signature s -> add_signature env (qualify ident) ~rel: (rel_name ident) s + | _ -> env + in + { env2 with env_module_types = (rel_name ident, qualify ident) :: env2.env_module_types } | Types.Tsig_class (ident, _) -> { env with env_classes = (rel_name ident, qualify ident) :: env.env_classes } | Types.Tsig_cltype (ident, _) -> { env with env_class_types = (rel_name ident, qualify ident) :: env.env_class_types } in @@ -183,19 +183,19 @@ let subst_type env t = Btype.iter_type_expr iter t; match t.Types.desc with | Types.Tconstr (p, [ty], a) when Path.same p Predef.path_option -> - () + () | Types.Tconstr (p, l, a) -> - let new_p = + let new_p = Odoc_name.to_path (full_type_name env (Odoc_name.from_path p)) in - t.Types.desc <- Types.Tconstr (new_p, l, a) + t.Types.desc <- Types.Tconstr (new_p, l, a) | Types.Tobject (_, ({contents=Some(p,tyl)} as r)) -> - let new_p = + let new_p = Odoc_name.to_path (full_type_name env (Odoc_name.from_path p)) in r := Some (new_p, tyl) | Types.Tvariant ({Types.row_name=Some(p, tyl)} as row) -> - let new_p = + let new_p = Odoc_name.to_path (full_type_name env (Odoc_name.from_path p)) in - t.Types.desc <- + t.Types.desc <- Types.Tvariant {row with Types.row_name=Some(new_p, tyl)} | _ -> () @@ -209,12 +209,12 @@ let subst_module_type env t = let rec iter t = match t with Types.Tmty_ident p -> - let new_p = Odoc_name.to_path (full_module_type_name env (Odoc_name.from_path p)) in - Types.Tmty_ident new_p + let new_p = Odoc_name.to_path (full_module_type_name env (Odoc_name.from_path p)) in + Types.Tmty_ident new_p | Types.Tmty_signature _ -> - t + t | Types.Tmty_functor (id, mt1, mt2) -> - Types.Tmty_functor (id, iter mt1, iter mt2) + Types.Tmty_functor (id, iter mt1, iter mt2) in iter t @@ -222,16 +222,16 @@ let subst_class_type env t = let rec iter t = match t with Types.Tcty_constr (p,texp_list,ct) -> - let new_p = Odoc_name.to_path (full_type_name env (Odoc_name.from_path p)) in - let new_texp_list = List.map (subst_type env) texp_list in - let new_ct = iter ct in - Types.Tcty_constr (new_p, new_texp_list, new_ct) + let new_p = Odoc_name.to_path (full_type_name env (Odoc_name.from_path p)) in + let new_texp_list = List.map (subst_type env) texp_list in + let new_ct = iter ct in + Types.Tcty_constr (new_p, new_texp_list, new_ct) | Types.Tcty_signature cs -> - (* on ne s'occupe pas des vals et methods *) - t + (* on ne s'occupe pas des vals et methods *) + t | Types.Tcty_fun (l, texp, ct) -> - let new_texp = subst_type env texp in - let new_ct = iter ct in - Types.Tcty_fun (l, new_texp, new_ct) + let new_texp = subst_type env texp in + let new_ct = iter ct in + Types.Tcty_fun (l, new_texp, new_ct) in iter t diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml index c5b610db9..995d77c9c 100644 --- a/ocamldoc/odoc_html.ml +++ b/ocamldoc/odoc_html.ml @@ -56,8 +56,8 @@ module Naming = let complete_target pref complete_name = let simple_name = Name.simple complete_name in let module_name = - let s = Name.father complete_name in - if s = "" then simple_name else s + let s = Name.father complete_name in + if s = "" then simple_name else s in let (html_file, _) = html_files module_name in html_file^"#"^(target pref simple_name) @@ -140,9 +140,9 @@ class text = let len = String.length s in let buf = Buffer.create len in for i = 0 to len - 1 do - match s.[i] with - 'a'..'z' | 'A'..'Z' | '0'..'9' -> Buffer.add_char buf s.[i] - | _ -> () + match s.[i] with + 'a'..'z' | 'A'..'Z' | '0'..'9' -> Buffer.add_char buf s.[i] + | _ -> () done; Buffer.contents buf @@ -151,12 +151,12 @@ class text = from the title level and the first sentence of the title.*) method create_title_label (n,label_opt,t) = match label_opt with - Some s -> s - | None -> - let t2 = Odoc_info.first_sentence_of_text t in - let s = Odoc_info.string_of_text t2 in - let s2 = self#keep_alpha_num s in - Printf.sprintf "%d%s" n s2 + Some s -> s + | None -> + let t2 = Odoc_info.first_sentence_of_text t in + let s = Odoc_info.string_of_text t2 in + let s2 = self#keep_alpha_num s in + Printf.sprintf "%d%s" n s2 (** Return the html code corresponding to the [text] parameter. *) method html_of_text t = String.concat "" (List.map self#html_of_text_element t) @@ -165,40 +165,40 @@ class text = method html_of_text_element te = print_DEBUG "text::html_of_text_element"; match te with - | Odoc_info.Raw s -> self#html_of_Raw s - | Odoc_info.Code s -> self#html_of_Code s - | Odoc_info.CodePre s -> self#html_of_CodePre s - | Odoc_info.Verbatim s -> self#html_of_Verbatim s - | Odoc_info.Bold t -> self#html_of_Bold t - | Odoc_info.Italic t -> self#html_of_Italic t - | Odoc_info.Emphasize t -> self#html_of_Emphasize t - | Odoc_info.Center t -> self#html_of_Center t - | Odoc_info.Left t -> self#html_of_Left t - | Odoc_info.Right t -> self#html_of_Right t - | Odoc_info.List tl -> self#html_of_List tl - | Odoc_info.Enum tl -> self#html_of_Enum tl - | Odoc_info.Newline -> self#html_of_Newline - | Odoc_info.Block t -> self#html_of_Block t - | Odoc_info.Title (n, l_opt, t) -> self#html_of_Title n l_opt t - | Odoc_info.Latex s -> self#html_of_Latex s - | Odoc_info.Link (s, t) -> self#html_of_Link s t - | Odoc_info.Ref (name, ref_opt) -> self#html_of_Ref name ref_opt - | Odoc_info.Superscript t -> self#html_of_Superscript t - | Odoc_info.Subscript t -> self#html_of_Subscript t + | Odoc_info.Raw s -> self#html_of_Raw s + | Odoc_info.Code s -> self#html_of_Code s + | Odoc_info.CodePre s -> self#html_of_CodePre s + | Odoc_info.Verbatim s -> self#html_of_Verbatim s + | Odoc_info.Bold t -> self#html_of_Bold t + | Odoc_info.Italic t -> self#html_of_Italic t + | Odoc_info.Emphasize t -> self#html_of_Emphasize t + | Odoc_info.Center t -> self#html_of_Center t + | Odoc_info.Left t -> self#html_of_Left t + | Odoc_info.Right t -> self#html_of_Right t + | Odoc_info.List tl -> self#html_of_List tl + | Odoc_info.Enum tl -> self#html_of_Enum tl + | Odoc_info.Newline -> self#html_of_Newline + | Odoc_info.Block t -> self#html_of_Block t + | Odoc_info.Title (n, l_opt, t) -> self#html_of_Title n l_opt t + | Odoc_info.Latex s -> self#html_of_Latex s + | Odoc_info.Link (s, t) -> self#html_of_Link s t + | Odoc_info.Ref (name, ref_opt) -> self#html_of_Ref name ref_opt + | Odoc_info.Superscript t -> self#html_of_Superscript t + | Odoc_info.Subscript t -> self#html_of_Subscript t method html_of_Raw s = self#escape s method html_of_Code s = if !Odoc_args.colorize_code then - self#html_of_code ~with_pre: false s + self#html_of_code ~with_pre: false s else - "<code class=\""^Odoc_ocamlhtml.code_class^"\">"^(self#escape s)^"</code>" + "<code class=\""^Odoc_ocamlhtml.code_class^"\">"^(self#escape s)^"</code>" method html_of_CodePre s = if !Odoc_args.colorize_code then - "<pre></pre>"^(self#html_of_code s)^"<pre></pre>" + "<pre></pre>"^(self#html_of_code s)^"<pre></pre>" else - "<pre><code class=\""^Odoc_ocamlhtml.code_class^"\">"^(self#escape s)^"</code></pre>" + "<pre><code class=\""^Odoc_ocamlhtml.code_class^"\">"^(self#escape s)^"</code></pre>" method html_of_Verbatim s = "<pre>"^(self#escape s)^"</pre>" method html_of_Bold t = "<b>"^(self#html_of_text t)^"</b>" @@ -211,13 +211,13 @@ class text = method html_of_List tl = "<ul>\n"^ (String.concat "" - (List.map (fun t -> "<li>"^(self#html_of_text t)^"</li>\n") tl))^ + (List.map (fun t -> "<li>"^(self#html_of_text t)^"</li>\n") tl))^ "</ul>\n" method html_of_Enum tl = "<OL>\n"^ (String.concat "" - (List.map (fun t -> "<li>"^(self#html_of_text t)^"</li>\n") tl))^ + (List.map (fun t -> "<li>"^(self#html_of_text t)^"</li>\n") tl))^ "</OL>\n" method html_of_Newline = "\n<p>\n" @@ -242,26 +242,26 @@ class text = method html_of_Ref name ref_opt = match ref_opt with - None -> - self#html_of_text_element (Odoc_info.Code name) - | Some kind -> - let target = - match kind with - Odoc_info.RK_module - | Odoc_info.RK_module_type - | Odoc_info.RK_class - | Odoc_info.RK_class_type -> - let (html_file, _) = Naming.html_files name in - html_file - | Odoc_info.RK_value -> Naming.complete_target Naming.mark_value name - | Odoc_info.RK_type -> Naming.complete_target Naming.mark_type name - | Odoc_info.RK_exception -> Naming.complete_target Naming.mark_exception name - | Odoc_info.RK_attribute -> Naming.complete_target Naming.mark_attribute name - | Odoc_info.RK_method -> Naming.complete_target Naming.mark_method name - | Odoc_info.RK_section -> Naming.complete_label_target name - in - "<a href=\""^target^"\">"^ - (self#html_of_text_element (Odoc_info.Code (Odoc_info.use_hidden_modules name)))^"</a>" + None -> + self#html_of_text_element (Odoc_info.Code name) + | Some kind -> + let target = + match kind with + Odoc_info.RK_module + | Odoc_info.RK_module_type + | Odoc_info.RK_class + | Odoc_info.RK_class_type -> + let (html_file, _) = Naming.html_files name in + html_file + | Odoc_info.RK_value -> Naming.complete_target Naming.mark_value name + | Odoc_info.RK_type -> Naming.complete_target Naming.mark_type name + | Odoc_info.RK_exception -> Naming.complete_target Naming.mark_exception name + | Odoc_info.RK_attribute -> Naming.complete_target Naming.mark_attribute name + | Odoc_info.RK_method -> Naming.complete_target Naming.mark_method name + | Odoc_info.RK_section -> Naming.complete_label_target name + in + "<a href=\""^target^"\">"^ + (self#html_of_text_element (Odoc_info.Code (Odoc_info.use_hidden_modules name)))^"</a>" method html_of_Superscript t = "<sup class=\"superscript\">"^(self#html_of_text t)^"</sup>" @@ -285,132 +285,132 @@ class virtual info = (** Return html for an author list. *) method html_of_author_list l = match l with - [] -> - "" + [] -> + "" | _ -> - "<b>"^Odoc_messages.authors^": </b>"^ - (String.concat ", " l)^ - "<br>\n" + "<b>"^Odoc_messages.authors^": </b>"^ + (String.concat ", " l)^ + "<br>\n" (** Return html code for the given optional version information.*) method html_of_version_opt v_opt = match v_opt with - None -> "" + None -> "" | Some v -> "<b>"^Odoc_messages.version^": </b>"^v^"<br>\n" (** Return html code for the given optional since information.*) method html_of_since_opt s_opt = match s_opt with - None -> "" + None -> "" | Some s -> "<b>"^Odoc_messages.since^"</b> "^s^"<br>\n" (** Return html code for the given list of raised exceptions.*) method html_of_raised_exceptions l = match l with - [] -> "" + [] -> "" | (s, t) :: [] -> "<b>"^Odoc_messages.raises^"</b> <code>"^s^"</code> "^(self#html_of_text t)^"<br>\n" | _ -> - "<b>"^Odoc_messages.raises^"</b><ul>"^ - (String.concat "" - (List.map - (fun (ex, desc) -> "<li><code>"^ex^"</code> "^(self#html_of_text desc)^"</li>\n") - l - ) - )^"</ul>\n" + "<b>"^Odoc_messages.raises^"</b><ul>"^ + (String.concat "" + (List.map + (fun (ex, desc) -> "<li><code>"^ex^"</code> "^(self#html_of_text desc)^"</li>\n") + l + ) + )^"</ul>\n" (** Return html code for the given "see also" reference. *) method html_of_see (see_ref, t) = let t_ref = - match see_ref with - Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] - | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t - | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t + match see_ref with + Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] + | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t + | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t in self#html_of_text t_ref (** Return html code for the given list of "see also" references.*) method html_of_sees l = match l with - [] -> "" + [] -> "" | see :: [] -> "<b>"^Odoc_messages.see_also^"</b> "^(self#html_of_see see)^"<br>\n" | _ -> - "<b>"^Odoc_messages.see_also^"</b><ul>"^ - (String.concat "" - (List.map - (fun see -> "<li>"^(self#html_of_see see)^"</li>\n") - l - ) - )^"</ul>\n" + "<b>"^Odoc_messages.see_also^"</b><ul>"^ + (String.concat "" + (List.map + (fun see -> "<li>"^(self#html_of_see see)^"</li>\n") + l + ) + )^"</ul>\n" (** Return html code for the given optional return information.*) method html_of_return_opt return_opt = match return_opt with - None -> "" + None -> "" | Some s -> "<b>"^Odoc_messages.returns^"</b> "^(self#html_of_text s)^"<br>\n" (** Return html code for the given list of custom tagged texts. *) method html_of_custom l = let buf = Buffer.create 50 in List.iter - (fun (tag, text) -> - try - let f = List.assoc tag tag_functions in - Buffer.add_string buf (f text) - with - Not_found -> - Odoc_info.warning (Odoc_messages.tag_not_handled tag) - ) - l; + (fun (tag, text) -> + try + let f = List.assoc tag tag_functions in + Buffer.add_string buf (f text) + with + Not_found -> + Odoc_info.warning (Odoc_messages.tag_not_handled tag) + ) + l; Buffer.contents buf (** Return html code for a description, except for the [i_params] field. *) method html_of_info info_opt = match info_opt with - None -> - "" + None -> + "" | Some info -> - let module M = Odoc_info in - "<div class=\"info\">\n"^ - (match info.M.i_deprecated with - None -> "" - | Some d -> - "<span class=\"warning\">"^Odoc_messages.deprecated^"</span> "^ - (self#html_of_text d)^ - "<br>\n" - )^ - (match info.M.i_desc with - None -> "" - | Some d when d = [Odoc_info.Raw ""] -> "" - | Some d -> (self#html_of_text d)^"<br>\n" - )^ - (self#html_of_author_list info.M.i_authors)^ - (self#html_of_version_opt info.M.i_version)^ - (self#html_of_since_opt info.M.i_since)^ - (self#html_of_raised_exceptions info.M.i_raised_exceptions)^ - (self#html_of_return_opt info.M.i_return_value)^ - (self#html_of_sees info.M.i_sees)^ - (self#html_of_custom info.M.i_custom)^ - "</div>\n" + let module M = Odoc_info in + "<div class=\"info\">\n"^ + (match info.M.i_deprecated with + None -> "" + | Some d -> + "<span class=\"warning\">"^Odoc_messages.deprecated^"</span> "^ + (self#html_of_text d)^ + "<br>\n" + )^ + (match info.M.i_desc with + None -> "" + | Some d when d = [Odoc_info.Raw ""] -> "" + | Some d -> (self#html_of_text d)^"<br>\n" + )^ + (self#html_of_author_list info.M.i_authors)^ + (self#html_of_version_opt info.M.i_version)^ + (self#html_of_since_opt info.M.i_since)^ + (self#html_of_raised_exceptions info.M.i_raised_exceptions)^ + (self#html_of_return_opt info.M.i_return_value)^ + (self#html_of_sees info.M.i_sees)^ + (self#html_of_custom info.M.i_custom)^ + "</div>\n" (** Return html code for the first sentence of a description. The titles and lists in this first sentence has been removed.*) method html_of_info_first_sentence info_opt = match info_opt with - None -> "" + None -> "" | Some info -> - let module M = Odoc_info in - let dep = info.M.i_deprecated <> None in - "<div class=\"info\">\n"^ - (if dep then "<font color=\"#CCCCCC\">" else "") ^ - (match info.M.i_desc with - None -> "" - | Some d when d = [Odoc_info.Raw ""] -> "" - | Some d -> (self#html_of_text - (Odoc_info.text_no_title_no_list - (Odoc_info.first_sentence_of_text d)))^"\n" - )^ - (if dep then "</font>" else "") ^ - "</div>\n" + let module M = Odoc_info in + let dep = info.M.i_deprecated <> None in + "<div class=\"info\">\n"^ + (if dep then "<font color=\"#CCCCCC\">" else "") ^ + (match info.M.i_desc with + None -> "" + | Some d when d = [Odoc_info.Raw ""] -> "" + | Some d -> (self#html_of_text + (Odoc_info.text_no_title_no_list + (Odoc_info.first_sentence_of_text d)))^"\n" + )^ + (if dep then "</font>" else "") ^ + "</div>\n" end @@ -427,29 +427,29 @@ class html = (** The default style options. *) val mutable default_style_options = ["a:visited {color : #416DFF; text-decoration : none; }" ; - "a:link {color : #416DFF; text-decoration : none;}" ; - "a:hover {color : Red; text-decoration : none; background-color: #5FFF88}" ; - "a:active {color : Red; text-decoration : underline; }" ; - ".keyword { font-weight : bold ; color : Red }" ; - ".keywordsign { color : #C04600 }" ; - ".superscript { font-size : 4 }" ; - ".subscript { font-size : 4 }" ; - ".comment { color : Green }" ; - ".constructor { color : Blue }" ; - ".type { color : #5C6585 }" ; - ".string { color : Maroon }" ; - ".warning { color : Red ; font-weight : bold }" ; - ".info { margin-left : 3em; margin-right : 3em }" ; - ".code { color : #465F91 ; }" ; - ".title1 { font-size : 20pt ; background-color : #909DFF }" ; - ".title2 { font-size : 20pt ; background-color : #90BDFF }" ; - ".title3 { font-size : 20pt ; background-color : #90DDFF }" ; - ".title4 { font-size : 20pt ; background-color : #90EDFF }" ; - ".title5 { font-size : 20pt ; background-color : #90FDFF }" ; - ".title6 { font-size : 20pt ; background-color : #C0FFFF }" ; - "body { background-color : White }" ; - "tr { background-color : White }" ; - ] + "a:link {color : #416DFF; text-decoration : none;}" ; + "a:hover {color : Red; text-decoration : none; background-color: #5FFF88}" ; + "a:active {color : Red; text-decoration : underline; }" ; + ".keyword { font-weight : bold ; color : Red }" ; + ".keywordsign { color : #C04600 }" ; + ".superscript { font-size : 4 }" ; + ".subscript { font-size : 4 }" ; + ".comment { color : Green }" ; + ".constructor { color : Blue }" ; + ".type { color : #5C6585 }" ; + ".string { color : Maroon }" ; + ".warning { color : Red ; font-weight : bold }" ; + ".info { margin-left : 3em; margin-right : 3em }" ; + ".code { color : #465F91 ; }" ; + ".title1 { font-size : 20pt ; background-color : #909DFF }" ; + ".title2 { font-size : 20pt ; background-color : #90BDFF }" ; + ".title3 { font-size : 20pt ; background-color : #90DDFF }" ; + ".title4 { font-size : 20pt ; background-color : #90EDFF }" ; + ".title5 { font-size : 20pt ; background-color : #90FDFF }" ; + ".title6 { font-size : 20pt ; background-color : #C0FFFF }" ; + "body { background-color : White }" ; + "tr { background-color : White }" ; + ] (** The style file for all pages. *) val mutable style_file = "style.css" @@ -519,21 +519,21 @@ class html = (** Init the style. *) method init_style = (match !Odoc_args.css_style with - None -> - let default_style = String.concat "\n" default_style_options in - ( - try - let chanout = open_out (Filename.concat !Odoc_args.target_dir style_file) in - output_string chanout default_style ; - flush chanout ; - close_out chanout - with - Sys_error s -> - prerr_endline s ; - incr Odoc_info.errors ; - ) + None -> + let default_style = String.concat "\n" default_style_options in + ( + try + let chanout = open_out (Filename.concat !Odoc_args.target_dir style_file) in + output_string chanout default_style ; + flush chanout ; + close_out chanout + with + Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors ; + ) | Some f -> - style_file <- f + style_file <- f ); style <- "<link rel=\"stylesheet\" href=\""^style_file^"\" type=\"text/css\">\n" @@ -551,56 +551,56 @@ class html = (** A function to build the header of pages. *) method prepare_header module_list = let f ?(nav=None) ?(comments=[]) t = - let link_if_not_empty l m url = - match l with - [] -> "" - | _ -> "<link title=\""^m^"\" rel=Appendix href=\""^url^"\">\n" - in - "<head>\n"^ - style^ - "<link rel=\"Start\" href=\""^index^"\">\n"^ - ( - match nav with - None -> "" - | Some (pre_opt, post_opt, name) -> - (match pre_opt with - None -> "" - | Some name -> - "<link rel=\"previous\" href=\""^(fst (Naming.html_files name))^"\">\n" - )^ - (match post_opt with - None -> "" - | Some name -> - "<link rel=\"next\" href=\""^(fst (Naming.html_files name))^"\">\n" - )^ - ( - let father = Name.father name in - let href = if father = "" then index else fst (Naming.html_files father) in - "<link rel=\"Up\" href=\""^href^"\">\n" - ) - )^ - (link_if_not_empty list_types Odoc_messages.index_of_types index_types)^ - (link_if_not_empty list_exceptions Odoc_messages.index_of_exceptions index_exceptions)^ - (link_if_not_empty list_values Odoc_messages.index_of_values index_values)^ - (link_if_not_empty list_attributes Odoc_messages.index_of_attributes index_attributes)^ - (link_if_not_empty list_methods Odoc_messages.index_of_methods index_methods)^ - (link_if_not_empty list_classes Odoc_messages.index_of_classes index_classes)^ - (link_if_not_empty list_class_types Odoc_messages.index_of_class_types index_class_types)^ - (link_if_not_empty list_modules Odoc_messages.index_of_modules index_modules)^ - (link_if_not_empty list_module_types Odoc_messages.index_of_module_types index_module_types)^ - (String.concat "\n" - (List.map - (fun m -> - let html_file = fst (Naming.html_files m.m_name) in - "<link title=\""^m.m_name^"\" rel=\"Chapter\" href=\""^html_file^"\">" - ) - module_list - ) - )^ - (self#html_sections_links comments)^ - "<title>"^ - t^ - "</title>\n</head>\n" + let link_if_not_empty l m url = + match l with + [] -> "" + | _ -> "<link title=\""^m^"\" rel=Appendix href=\""^url^"\">\n" + in + "<head>\n"^ + style^ + "<link rel=\"Start\" href=\""^index^"\">\n"^ + ( + match nav with + None -> "" + | Some (pre_opt, post_opt, name) -> + (match pre_opt with + None -> "" + | Some name -> + "<link rel=\"previous\" href=\""^(fst (Naming.html_files name))^"\">\n" + )^ + (match post_opt with + None -> "" + | Some name -> + "<link rel=\"next\" href=\""^(fst (Naming.html_files name))^"\">\n" + )^ + ( + let father = Name.father name in + let href = if father = "" then index else fst (Naming.html_files father) in + "<link rel=\"Up\" href=\""^href^"\">\n" + ) + )^ + (link_if_not_empty list_types Odoc_messages.index_of_types index_types)^ + (link_if_not_empty list_exceptions Odoc_messages.index_of_exceptions index_exceptions)^ + (link_if_not_empty list_values Odoc_messages.index_of_values index_values)^ + (link_if_not_empty list_attributes Odoc_messages.index_of_attributes index_attributes)^ + (link_if_not_empty list_methods Odoc_messages.index_of_methods index_methods)^ + (link_if_not_empty list_classes Odoc_messages.index_of_classes index_classes)^ + (link_if_not_empty list_class_types Odoc_messages.index_of_class_types index_class_types)^ + (link_if_not_empty list_modules Odoc_messages.index_of_modules index_modules)^ + (link_if_not_empty list_module_types Odoc_messages.index_of_module_types index_module_types)^ + (String.concat "\n" + (List.map + (fun m -> + let html_file = fst (Naming.html_files m.m_name) in + "<link title=\""^m.m_name^"\" rel=\"Chapter\" href=\""^html_file^"\">" + ) + module_list + ) + )^ + (self#html_sections_links comments)^ + "<title>"^ + t^ + "</title>\n</head>\n" in header <- f @@ -609,37 +609,37 @@ class html = method html_sections_links comments = let titles = List.flatten (List.map Odoc_info.get_titles_in_text comments) in let levels = - let rec iter acc l = - match l with - [] -> acc - | (n,_,_) :: q -> - if List.mem n acc - then iter acc q - else iter (n::acc) q - in - iter [] titles + let rec iter acc l = + match l with + [] -> acc + | (n,_,_) :: q -> + if List.mem n acc + then iter acc q + else iter (n::acc) q + in + iter [] titles in let sorted_levels = List.sort compare levels in let (section_level, subsection_level) = - match sorted_levels with - [] -> (None, None) - | [n] -> (Some n, None) - | n :: m :: _ -> (Some n, Some m) + match sorted_levels with + [] -> (None, None) + | [n] -> (Some n, None) + | n :: m :: _ -> (Some n, Some m) in let titles_per_level level_opt = - match level_opt with - None -> [] - | Some n -> List.filter (fun (m,_,_) -> m = n) titles + match level_opt with + None -> [] + | Some n -> List.filter (fun (m,_,_) -> m = n) titles in let section_titles = titles_per_level section_level in let subsection_titles = titles_per_level subsection_level in let create_lines s_rel titles = - List.map - (fun (n,lopt,t) -> - let s = Odoc_info.string_of_text t in - let label = self#create_title_label (n,lopt,t) in - Printf.sprintf "<link title=\"%s\" rel=\"%s\" href=\"#%s\">\n" s s_rel label) - titles + List.map + (fun (n,lopt,t) -> + let s = Odoc_info.string_of_text t in + let label = self#create_title_label (n,lopt,t) in + Printf.sprintf "<link title=\"%s\" rel=\"%s\" href=\"#%s\">\n" s s_rel label) + titles in let section_lines = create_lines "Section" section_titles in let subsection_lines = create_lines "Subsection" subsection_titles in @@ -652,9 +652,9 @@ class html = method navbar pre post name = "<div class=\"navbar\">"^ (match pre with - None -> "" + None -> "" | Some name -> - "<a href=\""^(fst (Naming.html_files name))^"\">"^Odoc_messages.previous^"</a>\n" + "<a href=\""^(fst (Naming.html_files name))^"\">"^Odoc_messages.previous^"</a>\n" )^ " "^ ( @@ -664,9 +664,9 @@ class html = )^ " "^ (match post with - None -> "" + None -> "" | Some name -> - "<a href=\""^(fst (Naming.html_files name))^"\">"^Odoc_messages.next^"</a>\n" + "<a href=\""^(fst (Naming.html_files name))^"\">"^Odoc_messages.next^"</a>\n" )^ "</div>\n" @@ -680,44 +680,44 @@ class html = (** Output the given ocaml code to the given file name. *) method private output_code in_title file code = try - let chanout = open_out file in - let html_code = self#html_of_code code in - output_string chanout ("<html>"^(self#header (self#inner_title in_title))^"<body>\n"); - output_string chanout html_code; - output_string chanout "</body></html>"; - close_out chanout + let chanout = open_out file in + let html_code = self#html_of_code code in + output_string chanout ("<html>"^(self#header (self#inner_title in_title))^"<body>\n"); + output_string chanout html_code; + output_string chanout "</body></html>"; + close_out chanout with - Sys_error s -> - incr Odoc_info.errors ; - prerr_endline s + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s (** Take a string and return the string where fully qualified type (or class or class type) idents have been replaced by links to the type referenced by the ident.*) method create_fully_qualified_idents_links m_name s = let f str_t = - let match_s = Str.matched_string str_t in - let rel = Name.get_relative m_name match_s in - let s_final = Odoc_info.apply_if_equal - Odoc_info.use_hidden_modules - match_s - rel - in - if List.mem match_s known_types_names then - "<a href=\""^(Naming.complete_target Naming.mark_type match_s)^"\">"^ - s_final^ - "</a>" - else - if List.mem match_s known_classes_names then - let (html_file, _) = Naming.html_files match_s in - "<a href=\""^html_file^"\">"^s_final^"</a>" - else - s_final + let match_s = Str.matched_string str_t in + let rel = Name.get_relative m_name match_s in + let s_final = Odoc_info.apply_if_equal + Odoc_info.use_hidden_modules + match_s + rel + in + if List.mem match_s known_types_names then + "<a href=\""^(Naming.complete_target Naming.mark_type match_s)^"\">"^ + s_final^ + "</a>" + else + if List.mem match_s known_classes_names then + let (html_file, _) = Naming.html_files match_s in + "<a href=\""^html_file^"\">"^s_final^"</a>" + else + s_final in let s2 = Str.global_substitute - (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") - f - s + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") + f + s in s2 @@ -725,24 +725,24 @@ class html = have been replaced by links to the module referenced by the ident.*) method create_fully_qualified_module_idents_links m_name s = let f str_t = - let match_s = Str.matched_string str_t in - if List.mem match_s known_modules_names then - let (html_file, _) = Naming.html_files match_s in - "<a href=\""^html_file^"\">"^(Name.get_relative m_name match_s)^"</a>" - else - match_s + let match_s = Str.matched_string str_t in + if List.mem match_s known_modules_names then + let (html_file, _) = Naming.html_files match_s in + "<a href=\""^html_file^"\">"^(Name.get_relative m_name match_s)^"</a>" + else + match_s in let s2 = Str.global_substitute - (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([A-Z][a-zA-Z_'0-9]*\\)") - f - s + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([A-Z][a-zA-Z_'0-9]*\\)") + f + s in s2 (** Return html code to display a [Types.type_expr].*) method html_of_type_expr m_name t = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_info.string_of_type_expr t)) + (Str.split (Str.regexp "\n") (Odoc_info.string_of_type_expr t)) in let s2 = Str.global_replace (Str.regexp "\n") "<br> " s in "<code class=\"type\">"^(self#create_fully_qualified_idents_links m_name s2)^"</code>" @@ -751,7 +751,7 @@ class html = (** Return html code to display a [Types.class_type].*) method html_of_class_type_expr m_name t = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_info.string_of_class_type t)) + (Str.split (Str.regexp "\n") (Odoc_info.string_of_class_type t)) in let s2 = Str.global_replace (Str.regexp "\n") "<br> " s in "<code class=\"type\">"^(self#create_fully_qualified_idents_links m_name s2)^"</code>" @@ -768,22 +768,22 @@ class html = (** Return html code to display a [Types.module_type]. *) method html_of_module_type m_name t = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_info.string_of_module_type t)) + (Str.split (Str.regexp "\n") (Odoc_info.string_of_module_type t)) in let s2 = Str.global_replace (Str.regexp "\n") "<br> " s in "<code class=\"type\">"^(self#create_fully_qualified_module_idents_links m_name s2)^"</code>" - + (** Generate a file containing the module type in the given file name. *) method output_module_type in_title file mtyp = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_info.string_of_module_type ~complete: true mtyp)) + (Str.split (Str.regexp "\n") (Odoc_info.string_of_module_type ~complete: true mtyp)) in self#output_code in_title file s (** Generate a file containing the class type in the given file name. *) method output_class_type in_title file ctyp = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_info.string_of_class_type ~complete: true ctyp)) + (Str.split (Str.regexp "\n") (Odoc_info.string_of_class_type ~complete: true ctyp)) in self#output_code in_title file s @@ -795,18 +795,18 @@ class html = (* html mark *) "<a name=\""^(Naming.value_target v)^"\"></a>"^ (match v.val_code with - None -> Name.simple v.val_name + None -> Name.simple v.val_name | Some c -> - let file = Naming.file_code_value_complete_target v in - self#output_code v.val_name (Filename.concat !Odoc_args.target_dir file) c; - "<a href=\""^file^"\">"^(Name.simple v.val_name)^"</a>" + let file = Naming.file_code_value_complete_target v in + self#output_code v.val_name (Filename.concat !Odoc_args.target_dir file) c; + "<a href=\""^file^"\">"^(Name.simple v.val_name)^"</a>" )^" : "^ (self#html_of_type_expr (Name.father v.val_name) v.val_type)^"</pre>"^ (self#html_of_info v.val_info)^ (if !Odoc_args.with_parameter_list then - self#html_of_parameter_list (Name.father v.val_name) v.val_parameters + self#html_of_parameter_list (Name.father v.val_name) v.val_parameters else - self#html_of_described_parameter_list (Name.father v.val_name) v.val_parameters + self#html_of_described_parameter_list (Name.father v.val_name) v.val_parameters ) (** Return html code for an exception. *) @@ -817,19 +817,19 @@ class html = "<a name=\""^(Naming.exception_target e)^"\"></a>"^ (Name.simple e.ex_name)^ (match e.ex_args with - [] -> "" - | _ -> - " "^(self#keyword "of")^" "^ - (self#html_of_type_expr_list (Name.father e.ex_name) " * " e.ex_args) + [] -> "" + | _ -> + " "^(self#keyword "of")^" "^ + (self#html_of_type_expr_list (Name.father e.ex_name) " * " e.ex_args) )^ (match e.ex_alias with - None -> "" + None -> "" | Some ea -> " = "^ - ( - match ea.ea_ex with - None -> ea.ea_name - | Some e -> "<a href=\""^(Naming.complete_exception_target e)^"\">"^e.ex_name^"</a>" - ) + ( + match ea.ea_ex with + None -> ea.ea_name + | Some e -> "<a href=\""^(Naming.complete_exception_target e)^"\">"^e.ex_name^"</a>" + ) )^ "</pre>\n"^ (self#html_of_info e.ex_info) @@ -842,95 +842,95 @@ class html = (* html mark *) "<a name=\""^(Naming.type_target t)^"\"></a>"^ (match t.ty_parameters with - [] -> "" - | tp :: [] -> (self#html_of_type_expr father tp)^" " - | l -> "("^(self#html_of_type_expr_list father ", " l)^") " + [] -> "" + | tp :: [] -> (self#html_of_type_expr father tp)^" " + | l -> "("^(self#html_of_type_expr_list father ", " l)^") " )^ (Name.simple t.ty_name)^" "^ (match t.ty_manifest with None -> "" | Some typ -> "= "^(self#html_of_type_expr father typ)^" ")^ (match t.ty_kind with - Type_abstract -> "</code>" - | Type_variant l -> - "=<br>"^ - "</code><table border=\"0\" cellpadding=\"1\">\n"^ - (String.concat "\n" - (List.map - (fun constr -> - "<tr>\n"^ - "<td align=\"left\" valign=\"top\" >\n"^ - "<code>"^ - (self#keyword "|")^ - "</code></td>\n"^ - "<td align=\"left\" valign=\"top\" >\n"^ - "<code>"^ - (self#constructor constr.vc_name)^ - (match constr.vc_args with - [] -> "" - | l -> - " "^(self#keyword "of")^" "^ - (self#html_of_type_expr_list father " * " l) - )^ - "</code></td>\n"^ - (match constr.vc_text with - None -> "" - | Some t -> - "<td align=\"left\" valign=\"top\" >"^ - "<code>"^ - "(*"^ - "</code></td>"^ - "<td align=\"left\" valign=\"top\" >"^ - "<code>"^ - (self#html_of_text t)^ - "</code></td>"^ - "<td align=\"left\" valign=\"bottom\" >"^ - "<code>"^ - "*)"^ - "</code></td>" - )^ - "\n</tr>" - ) - l - ) - )^ - "</table>\n" - - | Type_record l -> - "= {<br>"^ - "</code><table border=\"0\" cellpadding=\"1\">\n"^ - (String.concat "\n" - (List.map - (fun r -> - "<tr>\n"^ - "<td align=\"left\" valign=\"top\" >\n"^ - "<code> </code>"^ - "</td>\n"^ - "<td align=\"left\" valign=\"top\" >\n"^ - "<code>"^(if r.rf_mutable then self#keyword "mutable " else "")^ - r.rf_name^" : "^(self#html_of_type_expr father r.rf_type)^";"^ - "</code></td>\n"^ - (match r.rf_text with - None -> "" - | Some t -> - "<td align=\"left\" valign=\"top\" >"^ - "<code>"^ - "(*"^ - "</code></td>"^ - "<td align=\"left\" valign=\"top\" >"^ - "<code>"^ - (self#html_of_text t)^ - "</code></td>"^ - "<td align=\"left\" valign=\"bottom\" >"^ - "<code>"^ - "*)"^ - "</code></td>" - )^ - "\n</tr>" - ) - l - ) - )^ - "</table>\n"^ - "}\n" + Type_abstract -> "</code>" + | Type_variant l -> + "=<br>"^ + "</code><table border=\"0\" cellpadding=\"1\">\n"^ + (String.concat "\n" + (List.map + (fun constr -> + "<tr>\n"^ + "<td align=\"left\" valign=\"top\" >\n"^ + "<code>"^ + (self#keyword "|")^ + "</code></td>\n"^ + "<td align=\"left\" valign=\"top\" >\n"^ + "<code>"^ + (self#constructor constr.vc_name)^ + (match constr.vc_args with + [] -> "" + | l -> + " "^(self#keyword "of")^" "^ + (self#html_of_type_expr_list father " * " l) + )^ + "</code></td>\n"^ + (match constr.vc_text with + None -> "" + | Some t -> + "<td align=\"left\" valign=\"top\" >"^ + "<code>"^ + "(*"^ + "</code></td>"^ + "<td align=\"left\" valign=\"top\" >"^ + "<code>"^ + (self#html_of_text t)^ + "</code></td>"^ + "<td align=\"left\" valign=\"bottom\" >"^ + "<code>"^ + "*)"^ + "</code></td>" + )^ + "\n</tr>" + ) + l + ) + )^ + "</table>\n" + + | Type_record l -> + "= {<br>"^ + "</code><table border=\"0\" cellpadding=\"1\">\n"^ + (String.concat "\n" + (List.map + (fun r -> + "<tr>\n"^ + "<td align=\"left\" valign=\"top\" >\n"^ + "<code> </code>"^ + "</td>\n"^ + "<td align=\"left\" valign=\"top\" >\n"^ + "<code>"^(if r.rf_mutable then self#keyword "mutable " else "")^ + r.rf_name^" : "^(self#html_of_type_expr father r.rf_type)^";"^ + "</code></td>\n"^ + (match r.rf_text with + None -> "" + | Some t -> + "<td align=\"left\" valign=\"top\" >"^ + "<code>"^ + "(*"^ + "</code></td>"^ + "<td align=\"left\" valign=\"top\" >"^ + "<code>"^ + (self#html_of_text t)^ + "</code></td>"^ + "<td align=\"left\" valign=\"bottom\" >"^ + "<code>"^ + "*)"^ + "</code></td>" + )^ + "\n</tr>" + ) + l + ) + )^ + "</table>\n"^ + "}\n" )^"\n"^ (self#html_of_info t.ty_info)^ "<br>\n" @@ -943,11 +943,11 @@ class html = "<a name=\""^(Naming.attribute_target a)^"\"></a>"^ (if a.att_mutable then (self#keyword Odoc_messages.mutab)^" " else "")^ (match a.att_value.val_code with - None -> Name.simple a.att_value.val_name + None -> Name.simple a.att_value.val_name | Some c -> - let file = Naming.file_code_attribute_complete_target a in - self#output_code a.att_value.val_name (Filename.concat !Odoc_args.target_dir file) c; - "<a href=\""^file^"\">"^(Name.simple a.att_value.val_name)^"</a>" + let file = Naming.file_code_attribute_complete_target a in + self#output_code a.att_value.val_name (Filename.concat !Odoc_args.target_dir file) c; + "<a href=\""^file^"\">"^(Name.simple a.att_value.val_name)^"</a>" )^" : "^ (self#html_of_type_expr module_name a.att_value.val_type)^"</pre>"^ (self#html_of_info a.att_value.val_info) @@ -961,127 +961,127 @@ class html = (if m.met_private then (self#keyword "private")^" " else "")^ (if m.met_virtual then (self#keyword "virtual")^" " else "")^ (match m.met_value.val_code with - None -> Name.simple m.met_value.val_name + None -> Name.simple m.met_value.val_name | Some c -> - let file = Naming.file_code_method_complete_target m in - self#output_code m.met_value.val_name (Filename.concat !Odoc_args.target_dir file) c; - "<a href=\""^file^"\">"^(Name.simple m.met_value.val_name)^"</a>" + let file = Naming.file_code_method_complete_target m in + self#output_code m.met_value.val_name (Filename.concat !Odoc_args.target_dir file) c; + "<a href=\""^file^"\">"^(Name.simple m.met_value.val_name)^"</a>" )^" : "^ (self#html_of_type_expr module_name m.met_value.val_type)^"</pre>"^ (self#html_of_info m.met_value.val_info)^ (if !Odoc_args.with_parameter_list then - self#html_of_parameter_list module_name m.met_value.val_parameters + self#html_of_parameter_list module_name m.met_value.val_parameters else - self#html_of_described_parameter_list module_name m.met_value.val_parameters + self#html_of_described_parameter_list module_name m.met_value.val_parameters ) (** Return html code for the description of a function parameter. *) method html_of_parameter_description p = match Parameter.names p with - [] -> - "" + [] -> + "" | name :: [] -> - ( + ( (* Only one name, no need for label for the description. *) - match Parameter.desc_by_name p name with - None -> "" - | Some t -> self#html_of_text t - ) + match Parameter.desc_by_name p name with + None -> "" + | Some t -> self#html_of_text t + ) | l -> (* A list of names, we display those with a description. *) - let l2 = List.filter (fun n -> (Parameter.desc_by_name p n) <> None) l in - String.concat "<br>\n" - (List.map - (fun n -> - match Parameter.desc_by_name p n with - None -> "" - | Some t -> "<code>"^n^"</code> : "^(self#html_of_text t) - ) - l2 - ) + let l2 = List.filter (fun n -> (Parameter.desc_by_name p n) <> None) l in + String.concat "<br>\n" + (List.map + (fun n -> + match Parameter.desc_by_name p n with + None -> "" + | Some t -> "<code>"^n^"</code> : "^(self#html_of_text t) + ) + l2 + ) (** Return html code for a list of parameters. *) method html_of_parameter_list m_name l = match l with - [] -> - "" + [] -> + "" | _ -> - "<div class=\"info\">"^ - "<table border=\"0\" cellpadding=\"3\" width=\"100%\">\n"^ - "<tr>\n"^ - "<td align=\"left\" valign=\"top\" width=\"1%\"><b>"^Odoc_messages.parameters^": </b></td>\n"^ - "<td>\n"^ - "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n"^ - (String.concat "" - (List.map - (fun p -> - "<tr>\n"^ - "<td align=\"center\" valign=\"top\" width=\"15%\" class=\"code\">\n"^ - (match Parameter.complete_name p with - "" -> "?" - | s -> s - )^"</td>\n"^ - "<td align=\"center\" valign=\"top\">:</td>\n"^ - "<td>"^(self#html_of_type_expr m_name (Parameter.typ p))^"<br>\n"^ - (self#html_of_parameter_description p)^"\n"^ - "</tr>\n" - ) - l - ) - )^"</table>\n"^ - "</td>\n"^ - "</tr>\n"^ - "</table></div>\n" + "<div class=\"info\">"^ + "<table border=\"0\" cellpadding=\"3\" width=\"100%\">\n"^ + "<tr>\n"^ + "<td align=\"left\" valign=\"top\" width=\"1%\"><b>"^Odoc_messages.parameters^": </b></td>\n"^ + "<td>\n"^ + "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n"^ + (String.concat "" + (List.map + (fun p -> + "<tr>\n"^ + "<td align=\"center\" valign=\"top\" width=\"15%\" class=\"code\">\n"^ + (match Parameter.complete_name p with + "" -> "?" + | s -> s + )^"</td>\n"^ + "<td align=\"center\" valign=\"top\">:</td>\n"^ + "<td>"^(self#html_of_type_expr m_name (Parameter.typ p))^"<br>\n"^ + (self#html_of_parameter_description p)^"\n"^ + "</tr>\n" + ) + l + ) + )^"</table>\n"^ + "</td>\n"^ + "</tr>\n"^ + "</table></div>\n" (** Return html code for the parameters which have a name and description. *) method html_of_described_parameter_list m_name l = (* get the params which have a name, and at least one name described. *) let l2 = List.filter - (fun p -> - List.exists - (fun n -> (Parameter.desc_by_name p n) <> None) - (Parameter.names p)) - l + (fun p -> + List.exists + (fun n -> (Parameter.desc_by_name p n) <> None) + (Parameter.names p)) + l in let f p = - "<div class=\"info\"><code class=\"code\">"^(Parameter.complete_name p)^"</code> : "^ - (self#html_of_parameter_description p)^"</div>\n" + "<div class=\"info\"><code class=\"code\">"^(Parameter.complete_name p)^"</code> : "^ + (self#html_of_parameter_description p)^"</div>\n" in match l2 with - [] -> "" - | _ -> "<br>"^(String.concat "" (List.map f l2)) + [] -> "" + | _ -> "<br>"^(String.concat "" (List.map f l2)) (** Return html code for a list of module parameters. *) method html_of_module_parameter_list m_name l = match l with - [] -> - "" + [] -> + "" | _ -> - "<table border=\"0\" cellpadding=\"3\" width=\"100%\">\n"^ - "<tr>\n"^ - "<td align=\"left\" valign=\"top\" width=\"1%\"><b>"^Odoc_messages.parameters^": </b></td>\n"^ - "<td>\n"^ - "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n"^ - (String.concat "" - (List.map - (fun (p, desc_opt) -> - "<tr>\n"^ - "<td align=\"center\" valign=\"top\" width=\"15%\">\n"^ - "<code>"^p.mp_name^"</code></td>\n"^ - "<td align=\"center\" valign=\"top\">:</td>\n"^ - "<td>"^(self#html_of_module_type m_name p.mp_type)^"\n"^ - (match desc_opt with - None -> "" - | Some t -> "<br>"^(self#html_of_text t))^ - "\n"^ - "</tr>\n" - ) - l - ) - )^"</table>\n"^ - "</td>\n"^ - "</tr>\n"^ - "</table>\n" + "<table border=\"0\" cellpadding=\"3\" width=\"100%\">\n"^ + "<tr>\n"^ + "<td align=\"left\" valign=\"top\" width=\"1%\"><b>"^Odoc_messages.parameters^": </b></td>\n"^ + "<td>\n"^ + "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n"^ + (String.concat "" + (List.map + (fun (p, desc_opt) -> + "<tr>\n"^ + "<td align=\"center\" valign=\"top\" width=\"15%\">\n"^ + "<code>"^p.mp_name^"</code></td>\n"^ + "<td align=\"center\" valign=\"top\">:</td>\n"^ + "<td>"^(self#html_of_module_type m_name p.mp_type)^"\n"^ + (match desc_opt with + None -> "" + | Some t -> "<br>"^(self#html_of_text t))^ + "\n"^ + "</tr>\n" + ) + l + ) + )^"</table>\n"^ + "</td>\n"^ + "</tr>\n"^ + "</table>\n" (** Return html code for a module. *) method html_of_module ?(info=true) ?(complete=true) ?(with_link=true) m = @@ -1092,15 +1092,15 @@ class html = p buf "<pre>%s " (self#keyword "module"); ( if with_link then - p buf "<a href=\"%s\">%s</a>" html_file (Name.simple m.m_name) + p buf "<a href=\"%s\">%s</a>" html_file (Name.simple m.m_name) else - p buf "%s" (Name.simple m.m_name) + p buf "%s" (Name.simple m.m_name) ); p buf ": %s</pre>" (self#html_of_module_type father m.m_type); if info then - p buf "%s" ((if complete then self#html_of_info else self#html_of_info_first_sentence) m.m_info) + p buf "%s" ((if complete then self#html_of_info else self#html_of_info_first_sentence) m.m_info) else - (); + (); Buffer.contents buf (** Return html code for a module type. *) @@ -1112,19 +1112,19 @@ class html = p buf "<pre>%s " (self#keyword "module type"); ( if with_link then - p buf "<a href=\"%s\">%s</a>" html_file (Name.simple mt.mt_name) - else - p buf "%s" (Name.simple mt.mt_name) + p buf "<a href=\"%s\">%s</a>" html_file (Name.simple mt.mt_name) + else + p buf "%s" (Name.simple mt.mt_name) ); (match mt.mt_type with - None -> () - | Some mtyp -> p buf " = %s" (self#html_of_module_type father mtyp) + None -> () + | Some mtyp -> p buf " = %s" (self#html_of_module_type father mtyp) ); Buffer.add_string buf "</pre>"; if info then - p buf "%s" ((if complete then self#html_of_info else self#html_of_info_first_sentence) mt.mt_info) + p buf "%s" ((if complete then self#html_of_info else self#html_of_info_first_sentence) mt.mt_info) else - (); + (); Buffer.contents buf (** Return html code for an included module. *) @@ -1132,19 +1132,19 @@ class html = "<pre>"^(self#keyword "include")^" "^ ( match im.im_module with - None -> - im.im_name + None -> + im.im_name | Some mmt -> - let (file, name) = - match mmt with - Mod m -> - let (html_file, _) = Naming.html_files m.m_name in - (html_file, m.m_name) - | Modtype mt -> - let (html_file, _) = Naming.html_files mt.mt_name in - (html_file, mt.mt_name) - in - "<a href=\""^file^"\">"^(Name.simple name)^"</a>" + let (file, name) = + match mmt with + Mod m -> + let (html_file, _) = Naming.html_files m.m_name in + (html_file, m.m_name) + | Modtype mt -> + let (html_file, _) = Naming.html_files mt.mt_name in + (html_file, mt.mt_name) + in + "<a href=\""^file^"\">"^(Name.simple name)^"</a>" )^ "</pre>\n" @@ -1157,28 +1157,28 @@ class html = let p = Printf.bprintf in p buf "<pre>%s " (self#keyword "class"); (* we add a html tag, the same as for a type so we can - go directly here when the class name is used as a type name *) + go directly here when the class name is used as a type name *) p buf "<a name=\"%s\"></a>" - (Naming.type_target - { ty_name = c.cl_name ; - ty_info = None ; ty_parameters = [] ; - ty_kind = Type_abstract ; ty_manifest = None ; - ty_loc = Odoc_info.dummy_loc }); + (Naming.type_target + { ty_name = c.cl_name ; + ty_info = None ; ty_parameters = [] ; + ty_kind = Type_abstract ; ty_manifest = None ; + ty_loc = Odoc_info.dummy_loc }); print_DEBUG "html#html_of_class : virtual or not" ; if c.cl_virtual then p buf "%s " (self#keyword "virtual") else (); ( match c.cl_type_parameters with - [] -> () + [] -> () | l -> - p buf "[%s] " - (self#html_of_type_expr_list father ", " l) + p buf "[%s] " + (self#html_of_type_expr_list father ", " l) ); print_DEBUG "html#html_of_class : with link or not" ; ( if with_link then - p buf "<a href=\"%s\">%s</a>" html_file (Name.simple c.cl_name) + p buf "<a href=\"%s\">%s</a>" html_file (Name.simple c.cl_name) else - p buf "%s" (Name.simple c.cl_name) + p buf "%s" (Name.simple c.cl_name) ); Buffer.add_string buf " : " ; @@ -1186,7 +1186,7 @@ class html = Buffer.add_string buf "</pre>" ; print_DEBUG "html#html_of_class : info" ; Buffer.add_string buf - ((if complete then self#html_of_info else self#html_of_info_first_sentence) c.cl_info); + ((if complete then self#html_of_info else self#html_of_info_first_sentence) c.cl_info); Buffer.contents buf (** Return html code for a class type. *) @@ -1198,24 +1198,24 @@ class html = let (html_file, _) = Naming.html_files ct.clt_name in p buf "<pre>%s " (self#keyword "class type"); (* we add a html tag, the same as for a type so we can - go directly here when the class type name is used as a type name *) + go directly here when the class type name is used as a type name *) p buf "<a name=\"%s\"></a>" - (Naming.type_target - { ty_name = ct.clt_name ; - ty_info = None ; ty_parameters = [] ; - ty_kind = Type_abstract ; ty_manifest = None ; - ty_loc = Odoc_info.dummy_loc }); + (Naming.type_target + { ty_name = ct.clt_name ; + ty_info = None ; ty_parameters = [] ; + ty_kind = Type_abstract ; ty_manifest = None ; + ty_loc = Odoc_info.dummy_loc }); if ct.clt_virtual then p buf "%s "(self#keyword "virtual") else (); ( match ct.clt_type_parameters with - [] -> () - | l -> p buf "[%s] " (self#html_of_type_expr_list father ", " l) + [] -> () + | l -> p buf "[%s] " (self#html_of_type_expr_list father ", " l) ); if with_link then - p buf "<a href=\"%s\">%s</a>" html_file (Name.simple ct.clt_name) + p buf "<a href=\"%s\">%s</a>" html_file (Name.simple ct.clt_name) else - p buf "%s" (Name.simple ct.clt_name); + p buf "%s" (Name.simple ct.clt_name); Buffer.add_string buf " = "; Buffer.add_string buf (self#html_of_class_type_expr father ct.clt_type); @@ -1227,21 +1227,21 @@ class html = (** Return html code to represent a dag, represented as in Odoc_dag2html. *) method html_of_dag dag = let f n = - let (name, cct_opt) = n.Odoc_dag2html.valu in - (* if we have a c_opt = Some class then we take its information - because we are sure the name is complete. *) - let (name2, html_file) = - match cct_opt with - None -> (name, fst (Naming.html_files name)) - | Some (Cl c) -> (c.cl_name, fst (Naming.html_files c.cl_name)) - | Some (Cltype (ct, _)) -> (ct.clt_name, fst (Naming.html_files ct.clt_name)) - in - let new_v = - "<table border=1>\n<tr><td>"^ - "<a href=\""^html_file^"\">"^name2^"</a>"^ - "</td></tr>\n</table>\n" - in - { n with Odoc_dag2html.valu = new_v } + let (name, cct_opt) = n.Odoc_dag2html.valu in + (* if we have a c_opt = Some class then we take its information + because we are sure the name is complete. *) + let (name2, html_file) = + match cct_opt with + None -> (name, fst (Naming.html_files name)) + | Some (Cl c) -> (c.cl_name, fst (Naming.html_files c.cl_name)) + | Some (Cltype (ct, _)) -> (ct.clt_name, fst (Naming.html_files ct.clt_name)) + in + let new_v = + "<table border=1>\n<tr><td>"^ + "<a href=\""^html_file^"\">"^name2^"</a>"^ + "</td></tr>\n</table>\n" + in + { n with Odoc_dag2html.valu = new_v } in let a = Array.map f dag.Odoc_dag2html.dag in Odoc_dag2html.html_of_dag { Odoc_dag2html.dag = a } @@ -1254,38 +1254,38 @@ class html = method html_of_class_comment text = (* Add some style if there is no style for the first part of the text. *) let text2 = - match text with - | (Odoc_info.Raw s) :: q -> - (Odoc_info.Title (2, None, [Odoc_info.Raw s])) :: q - | _ -> text + match text with + | (Odoc_info.Raw s) :: q -> + (Odoc_info.Title (2, None, [Odoc_info.Raw s])) :: q + | _ -> text in self#html_of_text text2 (** Generate html code for the given list of inherited classes.*) method generate_inheritance_info chanout inher_l = let f inh = - match inh.ic_class with - None -> (* we can't make the link. *) - (Odoc_info.Code inh.ic_name) :: - (match inh.ic_text with - None -> [] - | Some t -> (Odoc_info.Raw " ") :: t) - | Some cct -> - (* we can create the link. *) - let real_name = (* even if it should be the same *) - match cct with - Cl c -> c.cl_name - | Cltype (ct, _) -> ct.clt_name - in - let (class_file, _) = Naming.html_files real_name in - (Odoc_info.Link (class_file, [Odoc_info.Code real_name])) :: - (match inh.ic_text with - None -> [] - | Some t -> (Odoc_info.Raw " ") :: t) + match inh.ic_class with + None -> (* we can't make the link. *) + (Odoc_info.Code inh.ic_name) :: + (match inh.ic_text with + None -> [] + | Some t -> (Odoc_info.Raw " ") :: t) + | Some cct -> + (* we can create the link. *) + let real_name = (* even if it should be the same *) + match cct with + Cl c -> c.cl_name + | Cltype (ct, _) -> ct.clt_name + in + let (class_file, _) = Naming.html_files real_name in + (Odoc_info.Link (class_file, [Odoc_info.Code real_name])) :: + (match inh.ic_text with + None -> [] + | Some t -> (Odoc_info.Raw " ") :: t) in let text = [ - Odoc_info.Bold [Odoc_info.Raw Odoc_messages.inherits] ; - Odoc_info.List (List.map f inher_l) + Odoc_info.Bold [Odoc_info.Raw Odoc_messages.inherits] ; + Odoc_info.List (List.map f inher_l) ] in let html = self#html_of_text text in @@ -1294,98 +1294,98 @@ class html = (** Generate html code for the inherited classes of the given class. *) method generate_class_inheritance_info chanout cl = let rec iter_kind k = - match k with - Class_structure ([], _) -> - () - | Class_structure (l, _) -> - self#generate_inheritance_info chanout l - | Class_constraint (k, ct) -> - iter_kind k - | Class_apply _ - | Class_constr _ -> - () + match k with + Class_structure ([], _) -> + () + | Class_structure (l, _) -> + self#generate_inheritance_info chanout l + | Class_constraint (k, ct) -> + iter_kind k + | Class_apply _ + | Class_constr _ -> + () in iter_kind cl.cl_kind (** Generate html code for the inherited classes of the given class type. *) method generate_class_type_inheritance_info chanout clt = match clt.clt_kind with - Class_signature ([], _) -> - () - | Class_signature (l, _) -> - self#generate_inheritance_info chanout l - | Class_type _ -> - () + Class_signature ([], _) -> + () + | Class_signature (l, _) -> + self#generate_inheritance_info chanout l + | Class_type _ -> + () (** A method to create index files. *) method generate_elements_index : - 'a. - 'a list -> - ('a -> Odoc_info.Name.t) -> - ('a -> Odoc_info.info option) -> - ('a -> string) -> string -> string -> unit = + 'a. + 'a list -> + ('a -> Odoc_info.Name.t) -> + ('a -> Odoc_info.info option) -> + ('a -> string) -> string -> string -> unit = fun elements name info target title simple_file -> try - let chanout = open_out (Filename.concat !Odoc_args.target_dir simple_file) in - output_string chanout - ( - "<html>\n"^ - (self#header (self#inner_title title)) ^ - "<body>\n"^ - "<center><h1>"^title^"</h1></center>\n"); - - let sorted_elements = List.sort - (fun e1 -> fun e2 -> compare (Name.simple (name e1)) (Name.simple (name e2))) - elements - in - let groups = Odoc_info.create_index_lists sorted_elements (fun e -> Name.simple (name e)) in - let f_ele e = - let simple_name = Name.simple (name e) in - let father_name = Name.father (name e) in - output_string chanout - ("<tr><td><a href=\""^(target e)^"\">"^simple_name^"</a> "^ - (if simple_name <> father_name then - "["^"<a href=\""^(fst (Naming.html_files father_name))^"\">"^father_name^"</a>]" - else - "" - )^ - "</td>\n"^ - "<td>"^(self#html_of_info_first_sentence (info e))^"</td></tr>\n" - ) - in - let f_group l = - match l with - [] -> () - | e :: _ -> - let s = - match (Char.uppercase (Name.simple (name e)).[0]) with - 'A'..'Z' as c -> String.make 1 c - | _ -> "" - in - output_string chanout ("<tr><td align=\"left\"><br>"^s^"</td></tr>\n"); - List.iter f_ele l - in - output_string chanout "<table>\n"; - List.iter f_group groups ; - output_string chanout "</table><br>\n" ; - output_string chanout "</body>\n</html>"; - close_out chanout + let chanout = open_out (Filename.concat !Odoc_args.target_dir simple_file) in + output_string chanout + ( + "<html>\n"^ + (self#header (self#inner_title title)) ^ + "<body>\n"^ + "<center><h1>"^title^"</h1></center>\n"); + + let sorted_elements = List.sort + (fun e1 -> fun e2 -> compare (Name.simple (name e1)) (Name.simple (name e2))) + elements + in + let groups = Odoc_info.create_index_lists sorted_elements (fun e -> Name.simple (name e)) in + let f_ele e = + let simple_name = Name.simple (name e) in + let father_name = Name.father (name e) in + output_string chanout + ("<tr><td><a href=\""^(target e)^"\">"^simple_name^"</a> "^ + (if simple_name <> father_name then + "["^"<a href=\""^(fst (Naming.html_files father_name))^"\">"^father_name^"</a>]" + else + "" + )^ + "</td>\n"^ + "<td>"^(self#html_of_info_first_sentence (info e))^"</td></tr>\n" + ) + in + let f_group l = + match l with + [] -> () + | e :: _ -> + let s = + match (Char.uppercase (Name.simple (name e)).[0]) with + 'A'..'Z' as c -> String.make 1 c + | _ -> "" + in + output_string chanout ("<tr><td align=\"left\"><br>"^s^"</td></tr>\n"); + List.iter f_ele l + in + output_string chanout "<table>\n"; + List.iter f_group groups ; + output_string chanout "</table><br>\n" ; + output_string chanout "</body>\n</html>"; + close_out chanout with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) (** A method to generate a list of module/class files. *) method generate_elements : - 'a. ('a option -> 'a option -> 'a -> unit) -> 'a list -> unit = + 'a. ('a option -> 'a option -> 'a -> unit) -> 'a list -> unit = fun f_generate l -> - let rec iter pre_opt = function - [] -> () - | ele :: [] -> f_generate pre_opt None ele - | ele1 :: ele2 :: q -> - f_generate pre_opt (Some ele2) ele1 ; - iter (Some ele1) (ele2 :: q) - in - iter None l + let rec iter pre_opt = function + [] -> () + | ele :: [] -> f_generate pre_opt None ele + | ele1 :: ele2 :: q -> + f_generate pre_opt (Some ele2) ele1 ; + iter (Some ele1) (ele2 :: q) + in + iter None l (** Generate the code of the html page for the given class.*) method generate_for_class pre post cl = @@ -1393,55 +1393,55 @@ class html = let (html_file, _) = Naming.html_files cl.cl_name in let type_file = Naming.file_type_class_complete_target cl.cl_name in try - let chanout = open_out (Filename.concat !Odoc_args.target_dir html_file) in - let pre_name = opt (fun c -> c.cl_name) pre in - let post_name = opt (fun c -> c.cl_name) post in - output_string chanout - ("<html>\n"^ - (self#header - ~nav: (Some (pre_name, post_name, cl.cl_name)) - ~comments: (Class.class_comments cl) - (self#inner_title cl.cl_name) - )^ - "<body>\n"^ - (self#navbar pre_name post_name cl.cl_name)^ - "<center><h1>"^Odoc_messages.clas^" "^ - (if cl.cl_virtual then "virtual " else "")^ - "<a href=\""^type_file^"\">"^cl.cl_name^"</a>"^ - "</h1></center>\n"^ - "<br>\n"^ - (self#html_of_class ~with_link: false cl) - ); - (* parameters *) - output_string chanout - (self#html_of_described_parameter_list (Name.father cl.cl_name) cl.cl_parameters); + let chanout = open_out (Filename.concat !Odoc_args.target_dir html_file) in + let pre_name = opt (fun c -> c.cl_name) pre in + let post_name = opt (fun c -> c.cl_name) post in + output_string chanout + ("<html>\n"^ + (self#header + ~nav: (Some (pre_name, post_name, cl.cl_name)) + ~comments: (Class.class_comments cl) + (self#inner_title cl.cl_name) + )^ + "<body>\n"^ + (self#navbar pre_name post_name cl.cl_name)^ + "<center><h1>"^Odoc_messages.clas^" "^ + (if cl.cl_virtual then "virtual " else "")^ + "<a href=\""^type_file^"\">"^cl.cl_name^"</a>"^ + "</h1></center>\n"^ + "<br>\n"^ + (self#html_of_class ~with_link: false cl) + ); + (* parameters *) + output_string chanout + (self#html_of_described_parameter_list (Name.father cl.cl_name) cl.cl_parameters); (* class inheritance *) - self#generate_class_inheritance_info chanout cl; - (* a horizontal line *) - output_string chanout "<hr width=\"100%\">\n"; - (* the various elements *) - List.iter - (fun element -> - match element with - Class_attribute a -> - output_string chanout (self#html_of_attribute a) - | Class_method m -> - output_string chanout (self#html_of_method m) - | Class_comment t -> - output_string chanout (self#html_of_class_comment t) - ) - (Class.class_elements ~trans:false cl); - output_string chanout "</body></html>"; - close_out chanout; + self#generate_class_inheritance_info chanout cl; + (* a horizontal line *) + output_string chanout "<hr width=\"100%\">\n"; + (* the various elements *) + List.iter + (fun element -> + match element with + Class_attribute a -> + output_string chanout (self#html_of_attribute a) + | Class_method m -> + output_string chanout (self#html_of_method m) + | Class_comment t -> + output_string chanout (self#html_of_class_comment t) + ) + (Class.class_elements ~trans:false cl); + output_string chanout "</body></html>"; + close_out chanout; (* generate the file with the complete class type *) - self#output_class_type - cl.cl_name - (Filename.concat !Odoc_args.target_dir type_file) - cl.cl_type + self#output_class_type + cl.cl_name + (Filename.concat !Odoc_args.target_dir type_file) + cl.cl_type with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) (** Generate the code of the html page for the given class type.*) method generate_for_class_type pre post clt = @@ -1449,348 +1449,348 @@ class html = let (html_file, _) = Naming.html_files clt.clt_name in let type_file = Naming.file_type_class_complete_target clt.clt_name in try - let chanout = open_out (Filename.concat !Odoc_args.target_dir html_file) in - let pre_name = opt (fun ct -> ct.clt_name) pre in - let post_name = opt (fun ct -> ct.clt_name) post in - output_string chanout - ("<html>\n"^ - (self#header - ~nav: (Some (pre_name, post_name, clt.clt_name)) - ~comments: (Class.class_type_comments clt) - (self#inner_title clt.clt_name) - )^ - "<body>\n"^ - (self#navbar pre_name post_name clt.clt_name)^ - "<center><h1>"^Odoc_messages.class_type^" "^ - (if clt.clt_virtual then "virtual " else "")^ - "<a href=\""^type_file^"\">"^clt.clt_name^"</a>"^ - "</h1></center>\n"^ - "<br>\n"^ - (self#html_of_class_type ~with_link: false clt) - ); + let chanout = open_out (Filename.concat !Odoc_args.target_dir html_file) in + let pre_name = opt (fun ct -> ct.clt_name) pre in + let post_name = opt (fun ct -> ct.clt_name) post in + output_string chanout + ("<html>\n"^ + (self#header + ~nav: (Some (pre_name, post_name, clt.clt_name)) + ~comments: (Class.class_type_comments clt) + (self#inner_title clt.clt_name) + )^ + "<body>\n"^ + (self#navbar pre_name post_name clt.clt_name)^ + "<center><h1>"^Odoc_messages.class_type^" "^ + (if clt.clt_virtual then "virtual " else "")^ + "<a href=\""^type_file^"\">"^clt.clt_name^"</a>"^ + "</h1></center>\n"^ + "<br>\n"^ + (self#html_of_class_type ~with_link: false clt) + ); (* class inheritance *) - self#generate_class_type_inheritance_info chanout clt; - (* a horizontal line *) - output_string chanout "<hr width=\"100%\">\n"; - (* the various elements *) - List.iter - (fun element -> - match element with - Class_attribute a -> - output_string chanout (self#html_of_attribute a) - | Class_method m -> - output_string chanout (self#html_of_method m) - | Class_comment t -> - output_string chanout (self#html_of_class_comment t) - ) - (Class.class_type_elements ~trans: false clt); - output_string chanout "</body></html>"; - close_out chanout; + self#generate_class_type_inheritance_info chanout clt; + (* a horizontal line *) + output_string chanout "<hr width=\"100%\">\n"; + (* the various elements *) + List.iter + (fun element -> + match element with + Class_attribute a -> + output_string chanout (self#html_of_attribute a) + | Class_method m -> + output_string chanout (self#html_of_method m) + | Class_comment t -> + output_string chanout (self#html_of_class_comment t) + ) + (Class.class_type_elements ~trans: false clt); + output_string chanout "</body></html>"; + close_out chanout; (* generate the file with the complete class type *) - self#output_class_type - clt.clt_name - (Filename.concat !Odoc_args.target_dir type_file) - clt.clt_type + self#output_class_type + clt.clt_name + (Filename.concat !Odoc_args.target_dir type_file) + clt.clt_type with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) (** Generate the html file for the given module type. @raise Failure if an error occurs.*) method generate_for_module_type pre post mt = try - let (html_file, _) = Naming.html_files mt.mt_name in - let type_file = Naming.file_type_module_complete_target mt.mt_name in - let chanout = open_out (Filename.concat !Odoc_args.target_dir html_file) in - let pre_name = opt (fun mt -> mt.mt_name) pre in - let post_name = opt (fun mt -> mt.mt_name) post in - output_string chanout - ("<html>\n"^ - (self#header - ~nav: (Some (pre_name, post_name, mt.mt_name)) - ~comments: (Module.module_type_comments mt) - (self#inner_title mt.mt_name) - )^ - "<body>\n"^ - (self#navbar pre_name post_name mt.mt_name)^ - "<center><h1>"^Odoc_messages.module_type^ - " "^ - (match mt.mt_type with - Some _ -> "<a href=\""^type_file^"\">"^mt.mt_name^"</a>" - | None-> mt.mt_name - )^ - "</h1></center>\n"^ - "<br>\n"^ - (self#html_of_modtype ~with_link: false mt) - ); - (* parameters for functors *) - output_string chanout (self#html_of_module_parameter_list "" (Module.module_type_parameters mt)); - (* a horizontal line *) - output_string chanout "<hr width=\"100%\">\n"; - (* module elements *) - List.iter - (fun ele -> - match ele with - Element_module m -> - output_string chanout (self#html_of_module ~complete: false m) - | Element_module_type mt -> - output_string chanout (self#html_of_modtype ~complete: false mt) - | Element_included_module im -> - output_string chanout (self#html_of_included_module im) - | Element_class c -> - output_string chanout (self#html_of_class ~complete: false c) - | Element_class_type ct -> - output_string chanout (self#html_of_class_type ~complete: false ct) - | Element_value v -> - output_string chanout (self#html_of_value v) - | Element_exception e -> - output_string chanout (self#html_of_exception e) - | Element_type t -> - output_string chanout (self#html_of_type t) - | Element_module_comment text -> - output_string chanout (self#html_of_module_comment text) - ) - (Module.module_type_elements mt); - - output_string chanout "</body></html>"; - close_out chanout; + let (html_file, _) = Naming.html_files mt.mt_name in + let type_file = Naming.file_type_module_complete_target mt.mt_name in + let chanout = open_out (Filename.concat !Odoc_args.target_dir html_file) in + let pre_name = opt (fun mt -> mt.mt_name) pre in + let post_name = opt (fun mt -> mt.mt_name) post in + output_string chanout + ("<html>\n"^ + (self#header + ~nav: (Some (pre_name, post_name, mt.mt_name)) + ~comments: (Module.module_type_comments mt) + (self#inner_title mt.mt_name) + )^ + "<body>\n"^ + (self#navbar pre_name post_name mt.mt_name)^ + "<center><h1>"^Odoc_messages.module_type^ + " "^ + (match mt.mt_type with + Some _ -> "<a href=\""^type_file^"\">"^mt.mt_name^"</a>" + | None-> mt.mt_name + )^ + "</h1></center>\n"^ + "<br>\n"^ + (self#html_of_modtype ~with_link: false mt) + ); + (* parameters for functors *) + output_string chanout (self#html_of_module_parameter_list "" (Module.module_type_parameters mt)); + (* a horizontal line *) + output_string chanout "<hr width=\"100%\">\n"; + (* module elements *) + List.iter + (fun ele -> + match ele with + Element_module m -> + output_string chanout (self#html_of_module ~complete: false m) + | Element_module_type mt -> + output_string chanout (self#html_of_modtype ~complete: false mt) + | Element_included_module im -> + output_string chanout (self#html_of_included_module im) + | Element_class c -> + output_string chanout (self#html_of_class ~complete: false c) + | Element_class_type ct -> + output_string chanout (self#html_of_class_type ~complete: false ct) + | Element_value v -> + output_string chanout (self#html_of_value v) + | Element_exception e -> + output_string chanout (self#html_of_exception e) + | Element_type t -> + output_string chanout (self#html_of_type t) + | Element_module_comment text -> + output_string chanout (self#html_of_module_comment text) + ) + (Module.module_type_elements mt); + + output_string chanout "</body></html>"; + close_out chanout; (* generate html files for submodules *) - self#generate_elements self#generate_for_module (Module.module_type_modules mt); + self#generate_elements self#generate_for_module (Module.module_type_modules mt); (* generate html files for module types *) - self#generate_elements self#generate_for_module_type (Module.module_type_module_types mt); + self#generate_elements self#generate_for_module_type (Module.module_type_module_types mt); (* generate html files for classes *) - self#generate_elements self#generate_for_class (Module.module_type_classes mt); + self#generate_elements self#generate_for_class (Module.module_type_classes mt); (* generate html files for class types *) - self#generate_elements self#generate_for_class_type (Module.module_type_class_types mt); + self#generate_elements self#generate_for_class_type (Module.module_type_class_types mt); (* generate the file with the complete module type *) - ( - match mt.mt_type with - None -> () - | Some mty -> self#output_module_type - mt.mt_name - (Filename.concat !Odoc_args.target_dir type_file) - mty - ) + ( + match mt.mt_type with + None -> () + | Some mty -> self#output_module_type + mt.mt_name + (Filename.concat !Odoc_args.target_dir type_file) + mty + ) with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) (** Generate the html file for the given module. @raise Failure if an error occurs.*) method generate_for_module pre post modu = try - Odoc_info.verbose ("Generate for module "^modu.m_name); - let (html_file, _) = Naming.html_files modu.m_name in - let type_file = Naming.file_type_module_complete_target modu.m_name in - let chanout = open_out (Filename.concat !Odoc_args.target_dir html_file) in - let pre_name = opt (fun m -> m.m_name) pre in - let post_name = opt (fun m -> m.m_name) post in - output_string chanout - ("<html>\n"^ - (self#header - ~nav: (Some (pre_name, post_name, modu.m_name)) - ~comments: (Module.module_comments modu) - (self#inner_title modu.m_name) - ) ^ - "<body>\n"^ - (self#navbar pre_name post_name modu.m_name)^ - "<center><h1>"^(if Module.module_is_functor modu then Odoc_messages.functo else Odoc_messages.modul)^ - " "^ - "<a href=\""^type_file^"\">"^modu.m_name^"</a>"^ - "</h1></center>\n"^ - "<br>\n"^ - (self#html_of_module ~with_link: false modu) - ); - (* parameters for functors *) - output_string chanout (self#html_of_module_parameter_list "" (Module.module_parameters modu)); - (* a horizontal line *) - output_string chanout "<hr width=\"100%\">\n"; - (* module elements *) - List.iter - (fun ele -> - print_DEBUG "html#generate_for_module : ele ->"; - match ele with - Element_module m -> - output_string chanout (self#html_of_module ~complete: false m) - | Element_module_type mt -> - output_string chanout (self#html_of_modtype ~complete: false mt) - | Element_included_module im -> - output_string chanout (self#html_of_included_module im) - | Element_class c -> - output_string chanout (self#html_of_class ~complete: false c) - | Element_class_type ct -> - output_string chanout (self#html_of_class_type ~complete: false ct) - | Element_value v -> - output_string chanout (self#html_of_value v) - | Element_exception e -> - output_string chanout (self#html_of_exception e) - | Element_type t -> - output_string chanout (self#html_of_type t) - | Element_module_comment text -> - output_string chanout (self#html_of_module_comment text) - ) - (Module.module_elements modu); - - output_string chanout "</body></html>"; - close_out chanout; + Odoc_info.verbose ("Generate for module "^modu.m_name); + let (html_file, _) = Naming.html_files modu.m_name in + let type_file = Naming.file_type_module_complete_target modu.m_name in + let chanout = open_out (Filename.concat !Odoc_args.target_dir html_file) in + let pre_name = opt (fun m -> m.m_name) pre in + let post_name = opt (fun m -> m.m_name) post in + output_string chanout + ("<html>\n"^ + (self#header + ~nav: (Some (pre_name, post_name, modu.m_name)) + ~comments: (Module.module_comments modu) + (self#inner_title modu.m_name) + ) ^ + "<body>\n"^ + (self#navbar pre_name post_name modu.m_name)^ + "<center><h1>"^(if Module.module_is_functor modu then Odoc_messages.functo else Odoc_messages.modul)^ + " "^ + "<a href=\""^type_file^"\">"^modu.m_name^"</a>"^ + "</h1></center>\n"^ + "<br>\n"^ + (self#html_of_module ~with_link: false modu) + ); + (* parameters for functors *) + output_string chanout (self#html_of_module_parameter_list "" (Module.module_parameters modu)); + (* a horizontal line *) + output_string chanout "<hr width=\"100%\">\n"; + (* module elements *) + List.iter + (fun ele -> + print_DEBUG "html#generate_for_module : ele ->"; + match ele with + Element_module m -> + output_string chanout (self#html_of_module ~complete: false m) + | Element_module_type mt -> + output_string chanout (self#html_of_modtype ~complete: false mt) + | Element_included_module im -> + output_string chanout (self#html_of_included_module im) + | Element_class c -> + output_string chanout (self#html_of_class ~complete: false c) + | Element_class_type ct -> + output_string chanout (self#html_of_class_type ~complete: false ct) + | Element_value v -> + output_string chanout (self#html_of_value v) + | Element_exception e -> + output_string chanout (self#html_of_exception e) + | Element_type t -> + output_string chanout (self#html_of_type t) + | Element_module_comment text -> + output_string chanout (self#html_of_module_comment text) + ) + (Module.module_elements modu); + + output_string chanout "</body></html>"; + close_out chanout; (* generate html files for submodules *) - self#generate_elements self#generate_for_module (Module.module_modules modu); + self#generate_elements self#generate_for_module (Module.module_modules modu); (* generate html files for module types *) - self#generate_elements self#generate_for_module_type (Module.module_module_types modu); + self#generate_elements self#generate_for_module_type (Module.module_module_types modu); (* generate html files for classes *) - self#generate_elements self#generate_for_class (Module.module_classes modu); + self#generate_elements self#generate_for_class (Module.module_classes modu); (* generate html files for class types *) - self#generate_elements self#generate_for_class_type (Module.module_class_types modu); + self#generate_elements self#generate_for_class_type (Module.module_class_types modu); (* generate the file with the complete module type *) - self#output_module_type - modu.m_name - (Filename.concat !Odoc_args.target_dir type_file) - modu.m_type + self#output_module_type + modu.m_name + (Filename.concat !Odoc_args.target_dir type_file) + modu.m_type with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) (** Generate the [index.html] file corresponding to the given module list. @raise Failure if an error occurs.*) method generate_index module_list = try - let title = match !Odoc_args.title with None -> "" | Some t -> self#escape t in - let index_if_not_empty l url m = - match l with - [] -> "" - | _ -> "<a href=\""^url^"\">"^m^"</a><br>\n" - in - let chanout = open_out (Filename.concat !Odoc_args.target_dir index) in - output_string chanout - ( - "<html>\n"^ - (self#header self#title) ^ - "<body>\n"^ - "<center><h1>"^title^"</h1></center>\n"^ - (index_if_not_empty list_types index_types Odoc_messages.index_of_types)^ - (index_if_not_empty list_exceptions index_exceptions Odoc_messages.index_of_exceptions)^ - (index_if_not_empty list_values index_values Odoc_messages.index_of_values)^ - (index_if_not_empty list_attributes index_attributes Odoc_messages.index_of_attributes)^ - (index_if_not_empty list_methods index_methods Odoc_messages.index_of_methods)^ - (index_if_not_empty list_classes index_classes Odoc_messages.index_of_classes)^ - (index_if_not_empty list_class_types index_class_types Odoc_messages.index_of_class_types)^ - (index_if_not_empty list_modules index_modules Odoc_messages.index_of_modules)^ - (index_if_not_empty list_module_types index_module_types Odoc_messages.index_of_module_types)^ - "<br>\n"^ - "<table border=\"0\">\n"^ - (String.concat "" - (List.map - (fun m -> - let (html, _) = Naming.html_files m.m_name in - "<tr><td><a href=\""^html^"\">"^m.m_name^"</a></td>"^ - "<td>"^(self#html_of_info_first_sentence m.m_info)^"</td></tr>\n") - module_list - ) - )^ - "</table>\n"^ - "</body>\n"^ - "</html>" - ); - close_out chanout + let title = match !Odoc_args.title with None -> "" | Some t -> self#escape t in + let index_if_not_empty l url m = + match l with + [] -> "" + | _ -> "<a href=\""^url^"\">"^m^"</a><br>\n" + in + let chanout = open_out (Filename.concat !Odoc_args.target_dir index) in + output_string chanout + ( + "<html>\n"^ + (self#header self#title) ^ + "<body>\n"^ + "<center><h1>"^title^"</h1></center>\n"^ + (index_if_not_empty list_types index_types Odoc_messages.index_of_types)^ + (index_if_not_empty list_exceptions index_exceptions Odoc_messages.index_of_exceptions)^ + (index_if_not_empty list_values index_values Odoc_messages.index_of_values)^ + (index_if_not_empty list_attributes index_attributes Odoc_messages.index_of_attributes)^ + (index_if_not_empty list_methods index_methods Odoc_messages.index_of_methods)^ + (index_if_not_empty list_classes index_classes Odoc_messages.index_of_classes)^ + (index_if_not_empty list_class_types index_class_types Odoc_messages.index_of_class_types)^ + (index_if_not_empty list_modules index_modules Odoc_messages.index_of_modules)^ + (index_if_not_empty list_module_types index_module_types Odoc_messages.index_of_module_types)^ + "<br>\n"^ + "<table border=\"0\">\n"^ + (String.concat "" + (List.map + (fun m -> + let (html, _) = Naming.html_files m.m_name in + "<tr><td><a href=\""^html^"\">"^m.m_name^"</a></td>"^ + "<td>"^(self#html_of_info_first_sentence m.m_info)^"</td></tr>\n") + module_list + ) + )^ + "</table>\n"^ + "</body>\n"^ + "</html>" + ); + close_out chanout with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) (** Generate the values index in the file [index_values.html]. *) method generate_values_index module_list = self#generate_elements_index - list_values - (fun v -> v.val_name) - (fun v -> v.val_info) - Naming.complete_value_target - Odoc_messages.index_of_values - index_values + list_values + (fun v -> v.val_name) + (fun v -> v.val_info) + Naming.complete_value_target + Odoc_messages.index_of_values + index_values (** Generate the exceptions index in the file [index_exceptions.html]. *) method generate_exceptions_index module_list = self#generate_elements_index - list_exceptions - (fun e -> e.ex_name) - (fun e -> e.ex_info) - Naming.complete_exception_target - Odoc_messages.index_of_exceptions - index_exceptions + list_exceptions + (fun e -> e.ex_name) + (fun e -> e.ex_info) + Naming.complete_exception_target + Odoc_messages.index_of_exceptions + index_exceptions (** Generate the types index in the file [index_types.html]. *) method generate_types_index module_list = self#generate_elements_index - list_types - (fun t -> t.ty_name) - (fun t -> t.ty_info) - Naming.complete_type_target - Odoc_messages.index_of_types - index_types + list_types + (fun t -> t.ty_name) + (fun t -> t.ty_info) + Naming.complete_type_target + Odoc_messages.index_of_types + index_types (** Generate the attributes index in the file [index_attributes.html]. *) method generate_attributes_index module_list = self#generate_elements_index - list_attributes - (fun a -> a.att_value.val_name) - (fun a -> a.att_value.val_info) - Naming.complete_attribute_target - Odoc_messages.index_of_attributes - index_attributes + list_attributes + (fun a -> a.att_value.val_name) + (fun a -> a.att_value.val_info) + Naming.complete_attribute_target + Odoc_messages.index_of_attributes + index_attributes (** Generate the methods index in the file [index_methods.html]. *) method generate_methods_index module_list = self#generate_elements_index - list_methods - (fun m -> m.met_value.val_name) - (fun m -> m.met_value.val_info) - Naming.complete_method_target - Odoc_messages.index_of_methods - index_methods + list_methods + (fun m -> m.met_value.val_name) + (fun m -> m.met_value.val_info) + Naming.complete_method_target + Odoc_messages.index_of_methods + index_methods (** Generate the classes index in the file [index_classes.html]. *) method generate_classes_index module_list = self#generate_elements_index - list_classes - (fun c -> c.cl_name) - (fun c -> c.cl_info) - (fun c -> fst (Naming.html_files c.cl_name)) - Odoc_messages.index_of_classes - index_classes + list_classes + (fun c -> c.cl_name) + (fun c -> c.cl_info) + (fun c -> fst (Naming.html_files c.cl_name)) + Odoc_messages.index_of_classes + index_classes (** Generate the class types index in the file [index_class_types.html]. *) method generate_class_types_index module_list = self#generate_elements_index - list_class_types - (fun ct -> ct.clt_name) - (fun ct -> ct.clt_info) - (fun ct -> fst (Naming.html_files ct.clt_name)) - Odoc_messages.index_of_class_types - index_class_types + list_class_types + (fun ct -> ct.clt_name) + (fun ct -> ct.clt_info) + (fun ct -> fst (Naming.html_files ct.clt_name)) + Odoc_messages.index_of_class_types + index_class_types (** Generate the modules index in the file [index_modules.html]. *) method generate_modules_index module_list = self#generate_elements_index - list_modules - (fun m -> m.m_name) - (fun m -> m.m_info) - (fun m -> fst (Naming.html_files m.m_name)) - Odoc_messages.index_of_modules - index_modules + list_modules + (fun m -> m.m_name) + (fun m -> m.m_info) + (fun m -> fst (Naming.html_files m.m_name)) + Odoc_messages.index_of_modules + index_modules (** Generate the module types index in the file [index_module_types.html]. *) method generate_module_types_index module_list = let module_types = Odoc_info.Search.module_types module_list in self#generate_elements_index - list_module_types - (fun mt -> mt.mt_name) - (fun mt -> mt.mt_info) - (fun mt -> fst (Naming.html_files mt.mt_name)) - Odoc_messages.index_of_module_types - index_module_types + list_module_types + (fun mt -> mt.mt_name) + (fun mt -> mt.mt_info) + (fun mt -> fst (Naming.html_files mt.mt_name)) + Odoc_messages.index_of_module_types + index_module_types (** Generate all the html files from a module list. The main file is [index.html]. *) @@ -1828,28 +1828,28 @@ class html = known_modules_names <- module_type_names @ module_names ; (* generate html for each module *) if not !Odoc_args.index_only then - self#generate_elements self#generate_for_module module_list ; + self#generate_elements self#generate_for_module module_list ; try - self#generate_index module_list; - self#generate_values_index module_list ; - self#generate_exceptions_index module_list ; - self#generate_types_index module_list ; - self#generate_attributes_index module_list ; - self#generate_methods_index module_list ; - self#generate_classes_index module_list ; - self#generate_class_types_index module_list ; - self#generate_modules_index module_list ; - self#generate_module_types_index module_list ; + self#generate_index module_list; + self#generate_values_index module_list ; + self#generate_exceptions_index module_list ; + self#generate_types_index module_list ; + self#generate_attributes_index module_list ; + self#generate_methods_index module_list ; + self#generate_classes_index module_list ; + self#generate_class_types_index module_list ; + self#generate_modules_index module_list ; + self#generate_module_types_index module_list ; with - Failure s -> - prerr_endline s ; - incr Odoc_info.errors + Failure s -> + prerr_endline s ; + incr Odoc_info.errors initializer Odoc_ocamlhtml.html_of_comment := - (fun s -> self#html_of_text (Odoc_text.Texter.text_of_string s)) + (fun s -> self#html_of_text (Odoc_text.Texter.text_of_string s)) end - + diff --git a/ocamldoc/odoc_info.ml b/ocamldoc/odoc_info.ml index 6ced0503f..1ad74d4e7 100644 --- a/ocamldoc/odoc_info.ml +++ b/ocamldoc/odoc_info.ml @@ -175,15 +175,15 @@ module Search = struct type result_element = Odoc_search.result_element = Res_module of Module.t_module - | Res_module_type of Module.t_module_type - | Res_class of Class.t_class - | Res_class_type of Class.t_class_type - | Res_value of Value.t_value - | Res_type of Type.t_type - | Res_exception of Exception.t_exception - | Res_attribute of Value.t_attribute - | Res_method of Value.t_method - | Res_section of string + | Res_module_type of Module.t_module_type + | Res_class of Class.t_class + | Res_class_type of Class.t_class_type + | Res_value of Value.t_value + | Res_type of Type.t_type + | Res_exception of Exception.t_exception + | Res_attribute of Value.t_attribute + | Res_method of Value.t_method + | Res_section of string type search_result = result_element list diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli index cb7be3ff4..934b80275 100644 --- a/ocamldoc/odoc_info.mli +++ b/ocamldoc/odoc_info.mli @@ -98,7 +98,7 @@ module Name : (** [concat t1 t2] returns the concatenation of [t1] and [t2].*) val concat : t -> t -> t (** Return the depth of the name, i.e. the numer of levels to the root. - Example : [depth "Toto.Tutu.name"] = [3]. *) + Example : [depth "Toto.Tutu.name"] = [3]. *) val depth : t -> int (** Take two names n1 and n2 = n3.n4 and return n4 if n3=n1 or else n2. *) val get_relative : t -> t -> t @@ -113,15 +113,15 @@ module Parameter : (** Representation of a simple parameter name *) type simple_name = Odoc_parameter.simple_name = { - sn_name : string ; - sn_type : Types.type_expr ; - mutable sn_text : text option ; - } + sn_name : string ; + sn_type : Types.type_expr ; + mutable sn_text : text option ; + } (** Representation of parameter names. We need it to represent parameter names in tuples. The value [Tuple ([], t)] stands for an anonymous parameter.*) type param_info = Odoc_parameter.param_info = - Simple_name of simple_name + Simple_name of simple_name | Tuple of param_info list * Types.type_expr (** A parameter is just a param_info.*) @@ -129,10 +129,10 @@ module Parameter : (** A module parameter is just a name and a module type.*) type module_parameter = Odoc_parameter.module_parameter = - { - mp_name : string ; - mp_type : Types.module_type ; - } + { + mp_name : string ; + mp_type : Types.module_type ; + } (** {3 Functions} *) (** Acces to the name as a string. For tuples, parenthesis and commas are added. *) @@ -160,19 +160,19 @@ module Exception : (** Used when the exception is a rebind of another exception, when we have [exception Ex = Target_ex].*) type exception_alias = Odoc_exception.exception_alias = - { - ea_name : Name.t ; (** The complete name of the target exception. *) - mutable ea_ex : t_exception option ; (** The target exception, if we found it.*) - } - + { + ea_name : Name.t ; (** The complete name of the target exception. *) + mutable ea_ex : t_exception option ; (** The target exception, if we found it.*) + } + and t_exception = Odoc_exception.t_exception = - { - ex_name : Name.t ; - mutable ex_info : info option ; (** Information found in the optional associated comment. *) - ex_args : Types.type_expr list ; (** The types of the parameters. *) - ex_alias : exception_alias option ; (** [None] when the exception is not a rebind. *) - mutable ex_loc : location ; - } + { + ex_name : Name.t ; + mutable ex_info : info option ; (** Information found in the optional associated comment. *) + ex_args : Types.type_expr list ; (** The types of the parameters. *) + ex_alias : exception_alias option ; (** [None] when the exception is not a rebind. *) + mutable ex_loc : location ; + } end (** Representation and manipulation of types.*) @@ -180,37 +180,37 @@ module Type : sig (** Description of a variant type constructor. *) type variant_constructor = Odoc_type.variant_constructor = - { - vc_name : string ; (** Name of the constructor. *) - vc_args : Types.type_expr list ; (** Arguments of the constructor. *) - mutable vc_text : text option ; (** Optional description in the associated comment. *) - } + { + vc_name : string ; (** Name of the constructor. *) + vc_args : Types.type_expr list ; (** Arguments of the constructor. *) + mutable vc_text : text option ; (** Optional description in the associated comment. *) + } (** Description of a record type field. *) type record_field = Odoc_type.record_field = - { - rf_name : string ; (** Name of the field. *) - rf_mutable : bool ; (** [true] if mutable. *) - rf_type : Types.type_expr ; (** Type of the field. *) - mutable rf_text : text option ; (** Optional description in the associated comment.*) - } + { + rf_name : string ; (** Name of the field. *) + rf_mutable : bool ; (** [true] if mutable. *) + rf_type : Types.type_expr ; (** Type of the field. *) + mutable rf_text : text option ; (** Optional description in the associated comment.*) + } (** The various kinds of a type. *) type type_kind = Odoc_type.type_kind = - Type_abstract (** Type is abstract, for example [type t]. *) + Type_abstract (** Type is abstract, for example [type t]. *) | Type_variant of variant_constructor list | Type_record of record_field list (** Representation of a type. *) type t_type = Odoc_type.t_type = - { - ty_name : Name.t ; (** Complete name of the type. *) - mutable ty_info : info option ; (** Information found in the optional associated comment. *) - ty_parameters : Types.type_expr list ; (** Type parameters. *) - ty_kind : type_kind ; (** Type kind. *) - ty_manifest : Types.type_expr option; (** Type manifest. *) - mutable ty_loc : location ; - } + { + ty_name : Name.t ; (** Complete name of the type. *) + mutable ty_info : info option ; (** Information found in the optional associated comment. *) + ty_parameters : Types.type_expr list ; (** Type parameters. *) + ty_kind : type_kind ; (** Type kind. *) + ty_manifest : Types.type_expr option; (** Type manifest. *) + mutable ty_loc : location ; + } end (** Representation and manipulation of values, class attributes and class methods. *) @@ -218,31 +218,31 @@ module Value : sig (** Representation of a value. *) type t_value = Odoc_value.t_value = - { - val_name : Name.t ; (** Complete name of the value. *) - mutable val_info : info option ; (** Information found in the optional associated comment. *) - val_type : Types.type_expr ; (** Type of the value. *) - val_recursive : bool ; (** [true] if the value is recursive. *) - mutable val_parameters : Odoc_parameter.parameter list ; (** The parameters, if any. *) - mutable val_code : string option ; (** The code of the value, if we had the only the implementation file. *) - mutable val_loc : location ; - } + { + val_name : Name.t ; (** Complete name of the value. *) + mutable val_info : info option ; (** Information found in the optional associated comment. *) + val_type : Types.type_expr ; (** Type of the value. *) + val_recursive : bool ; (** [true] if the value is recursive. *) + mutable val_parameters : Odoc_parameter.parameter list ; (** The parameters, if any. *) + mutable val_code : string option ; (** The code of the value, if we had the only the implementation file. *) + mutable val_loc : location ; + } (** Representation of a class attribute. *) type t_attribute = Odoc_value.t_attribute = - { - att_value : t_value ; (** an attribute has almost all the same information as a value *) - att_mutable : bool ; (** [true] if the attribute is mutable. *) - } + { + att_value : t_value ; (** an attribute has almost all the same information as a value *) + att_mutable : bool ; (** [true] if the attribute is mutable. *) + } (** Representation of a class method. *) type t_method = Odoc_value.t_method = - { - met_value : t_value ; (** a method has almost all the same information as a value *) - met_private : bool ; (** [true] if the method is private.*) - met_virtual : bool ; (** [true] if the method is virtual. *) - } - + { + met_value : t_value ; (** a method has almost all the same information as a value *) + met_private : bool ; (** [true] if the method is private.*) + met_virtual : bool ; (** [true] if the method is virtual. *) + } + (** Return [true] if the value is a function, i.e. it has a functional type. *) val is_function : t_value -> bool @@ -256,87 +256,87 @@ module Class : (** {3 Types} *) (** To keep the order of elements in a class. *) type class_element = Odoc_class.class_element = - Class_attribute of Value.t_attribute + Class_attribute of Value.t_attribute | Class_method of Value.t_method | Class_comment of text (** Used when we can reference a t_class or a t_class_type. *) type cct = Odoc_class.cct = - Cl of t_class + Cl of t_class | Cltype of t_class_type * Types.type_expr list (** Class type and type parameters. *) and inherited_class = Odoc_class.inherited_class = - { - ic_name : Name.t ; (** Complete name of the inherited class. *) - mutable ic_class : cct option ; (** The associated t_class or t_class_type. *) - ic_text : text option ; (** The inheritance description, if any. *) - } + { + ic_name : Name.t ; (** Complete name of the inherited class. *) + mutable ic_class : cct option ; (** The associated t_class or t_class_type. *) + ic_text : text option ; (** The inheritance description, if any. *) + } and class_apply = Odoc_class.class_apply = - { - capp_name : Name.t ; (** The complete name of the applied class. *) - mutable capp_class : t_class option; (** The associated t_class if we found it. *) - capp_params : Types.type_expr list; (** The type of expressions the class is applied to. *) - capp_params_code : string list ; (** The code of these exprssions. *) - } - + { + capp_name : Name.t ; (** The complete name of the applied class. *) + mutable capp_class : t_class option; (** The associated t_class if we found it. *) + capp_params : Types.type_expr list; (** The type of expressions the class is applied to. *) + capp_params_code : string list ; (** The code of these exprssions. *) + } + and class_constr = Odoc_class.class_constr = - { - cco_name : Name.t ; (** The complete name of the applied class. *) - mutable cco_class : cct option; + { + cco_name : Name.t ; (** The complete name of the applied class. *) + mutable cco_class : cct option; (** The associated class or class type if we found it. *) - cco_type_parameters : Types.type_expr list; (** The type parameters of the class, if needed. *) - } + cco_type_parameters : Types.type_expr list; (** The type parameters of the class, if needed. *) + } and class_kind = Odoc_class.class_kind = - Class_structure of inherited_class list * class_element list - (** An explicit class structure, used in implementation and interface. *) + Class_structure of inherited_class list * class_element list + (** An explicit class structure, used in implementation and interface. *) | Class_apply of class_apply (** Application/alias of a class, used in implementation only. *) | Class_constr of class_constr (** A class used to give the type of the defined class, - instead of a structure, used in interface only. - For example, it will be used with the name [M1.M2....bar] - when the class foo is defined like this : - [class foo : int -> bar] *) + instead of a structure, used in interface only. + For example, it will be used with the name [M1.M2....bar] + when the class foo is defined like this : + [class foo : int -> bar] *) | Class_constraint of class_kind * class_type_kind - (** A class definition with a constraint. *) + (** A class definition with a constraint. *) (** Representation of a class. *) and t_class = Odoc_class.t_class = - { - cl_name : Name.t ; (** Complete name of the class. *) - mutable cl_info : info option ; (** Information found in the optional associated comment. *) - cl_type : Types.class_type ; (** Type of the class. *) - cl_type_parameters : Types.type_expr list ; (** Type parameters. *) - cl_virtual : bool ; (** [true] when the class is virtual. *) - mutable cl_kind : class_kind ; (** The way the class is defined. *) - mutable cl_parameters : Parameter.parameter list ; (** The parameters of the class. *) - mutable cl_loc : location ; - } + { + cl_name : Name.t ; (** Complete name of the class. *) + mutable cl_info : info option ; (** Information found in the optional associated comment. *) + cl_type : Types.class_type ; (** Type of the class. *) + cl_type_parameters : Types.type_expr list ; (** Type parameters. *) + cl_virtual : bool ; (** [true] when the class is virtual. *) + mutable cl_kind : class_kind ; (** The way the class is defined. *) + mutable cl_parameters : Parameter.parameter list ; (** The parameters of the class. *) + mutable cl_loc : location ; + } and class_type_alias = Odoc_class.class_type_alias = - { - cta_name : Name.t ; (** Complete name of the target class type. *) - mutable cta_class : cct option ; (** The target t_class or t_class_type, if we found it.*) - cta_type_parameters : Types.type_expr list ; (** The type parameters. A VOIR : mettre des string ? *) - } + { + cta_name : Name.t ; (** Complete name of the target class type. *) + mutable cta_class : cct option ; (** The target t_class or t_class_type, if we found it.*) + cta_type_parameters : Types.type_expr list ; (** The type parameters. A VOIR : mettre des string ? *) + } and class_type_kind = Odoc_class.class_type_kind = - Class_signature of inherited_class list * class_element list + Class_signature of inherited_class list * class_element list | Class_type of class_type_alias (** A class type eventually applied to type args. *) - + (** Representation of a class type. *) and t_class_type = Odoc_class.t_class_type = - { - clt_name : Name.t ; (** Complete name of the type. *) - mutable clt_info : info option ; (** Information found in the optional associated comment. *) - clt_type : Types.class_type ; - clt_type_parameters : Types.type_expr list ; (** Type parameters. *) - clt_virtual : bool ; (** [true] if the class type is virtual *) - mutable clt_kind : class_type_kind ; (** The way the class type is defined. *) - mutable clt_loc : location ; - } + { + clt_name : Name.t ; (** Complete name of the type. *) + mutable clt_info : info option ; (** Information found in the optional associated comment. *) + clt_type : Types.class_type ; + clt_type_parameters : Types.type_expr list ; (** Type parameters. *) + clt_virtual : bool ; (** [true] if the class type is virtual *) + mutable clt_kind : class_type_kind ; (** The way the class type is defined. *) + mutable clt_loc : location ; + } (** {3 Functions} *) @@ -377,7 +377,7 @@ module Module : (** {3 Types} *) (** To keep the order of elements in a module. *) type module_element = Odoc_module.module_element = - Element_module of t_module + Element_module of t_module | Element_module_type of t_module_type | Element_included_module of included_module | Element_class of Class.t_class @@ -393,16 +393,16 @@ module Module : | Modtype of t_module_type and included_module = Odoc_module.included_module = - { - im_name : Name.t ; (** Complete name of the included module. *) - mutable im_module : mmt option ; (** The included module or module type, if we found it. *) - } - + { + im_name : Name.t ; (** Complete name of the included module. *) + mutable im_module : mmt option ; (** The included module or module type, if we found it. *) + } + and module_alias = Odoc_module.module_alias = - { - ma_name : Name.t ; (** Complete name of the target module. *) - mutable ma_module : mmt option ; (** The real module or module type if we could associate it. *) - } + { + ma_name : Name.t ; (** Complete name of the target module. *) + mutable ma_module : mmt option ; (** The real module or module type if we could associate it. *) + } (** Different kinds of a module. *) and module_kind = Odoc_module.module_kind = @@ -411,37 +411,37 @@ module Module : | Module_functor of (Parameter.module_parameter list) * module_kind (** A functor, with {e all} its parameters and the rest of its definition *) | Module_apply of module_kind * module_kind - (** A module defined by application of a functor. *) - | Module_with of module_type_kind * string - (** A module whose type is a with ... constraint. - Should appear in interface files only. *) - | Module_constraint of module_kind * module_type_kind - (** A module constraint by a module type. *) + (** A module defined by application of a functor. *) + | Module_with of module_type_kind * string + (** A module whose type is a with ... constraint. + Should appear in interface files only. *) + | Module_constraint of module_kind * module_type_kind + (** A module constraint by a module type. *) (** Representation of a module. *) and t_module = Odoc_module.t_module = - { - m_name : Name.t ; (** Complete name of the module. *) - m_type : Types.module_type ; (** The type of the module. *) - mutable m_info : info option ; (** Information found in the optional associated comment. *) - m_is_interface : bool ; (** [true] for modules read from interface files *) - m_file : string ; (** The file the module is defined in. *) - mutable m_kind : module_kind ; (** The way the module is defined. *) - mutable m_loc : location ; - mutable m_top_deps : Name.t list ; (** The toplevels module names this module depends on. *) - } + { + m_name : Name.t ; (** Complete name of the module. *) + m_type : Types.module_type ; (** The type of the module. *) + mutable m_info : info option ; (** Information found in the optional associated comment. *) + m_is_interface : bool ; (** [true] for modules read from interface files *) + m_file : string ; (** The file the module is defined in. *) + mutable m_kind : module_kind ; (** The way the module is defined. *) + mutable m_loc : location ; + mutable m_top_deps : Name.t list ; (** The toplevels module names this module depends on. *) + } and module_type_alias = Odoc_module.module_type_alias = - { - mta_name : Name.t ; (** Complete name of the target module type. *) - mutable mta_module : t_module_type option ; (** The real module type if we could associate it. *) - } + { + mta_name : Name.t ; (** Complete name of the target module type. *) + mutable mta_module : t_module_type option ; (** The real module type if we could associate it. *) + } (** Different kinds of module type. *) and module_type_kind = Odoc_module.module_type_kind = | Module_type_struct of module_element list (** A complete module signature. *) | Module_type_functor of (Odoc_parameter.module_parameter list) * module_type_kind - (** A functor, with {e all} its parameters and the rest of its definition *) + (** A functor, with {e all} its parameters and the rest of its definition *) | Module_type_alias of module_type_alias (** Complete alias name and corresponding module type if we found it. *) | Module_type_with of module_type_kind * string @@ -449,18 +449,18 @@ module Module : (** Representation of a module type. *) and t_module_type = Odoc_module.t_module_type = - { - mt_name : Name.t ; (** Complete name of the module type. *) - mutable mt_info : info option ; (** Information found in the optional associated comment. *) - mt_type : Types.module_type option ; (** [None] means that the module type is abstract. *) - mt_is_interface : bool ; (** [true] for modules read from interface files. *) - mt_file : string ; (** The file the module type is defined in. *) - mutable mt_kind : module_type_kind option ; + { + mt_name : Name.t ; (** Complete name of the module type. *) + mutable mt_info : info option ; (** Information found in the optional associated comment. *) + mt_type : Types.module_type option ; (** [None] means that the module type is abstract. *) + mt_is_interface : bool ; (** [true] for modules read from interface files. *) + mt_file : string ; (** The file the module type is defined in. *) + mutable mt_kind : module_type_kind option ; (** The way the module is defined. [None] means that module type is abstract. - It is always [None] when the module type was extracted from the implementation file. - That means module types are only analysed in interface files. *) - mutable mt_loc : location ; - } + It is always [None] when the module type was extracted from the implementation file. + That means module types are only analysed in interface files. *) + mutable mt_loc : location ; + } (** {3 Functions for modules} *) @@ -563,12 +563,12 @@ module Module : val analyse_files : ?merge_options:Odoc_types.merge_option list -> ?include_dirs:string list -> - ?labels:bool -> - ?sort_modules:bool -> - ?no_stop:bool -> - ?init: Odoc_module.t_module list -> - string list -> - Module.t_module list + ?labels:bool -> + ?sort_modules:bool -> + ?no_stop:bool -> + ?init: Odoc_module.t_module list -> + string list -> + Module.t_module list (** Dump of a list of modules into a file. @raise Failure if an error occurs.*) @@ -700,15 +700,15 @@ module Search : sig type result_element = Odoc_search.result_element = Res_module of Module.t_module - | Res_module_type of Module.t_module_type - | Res_class of Class.t_class - | Res_class_type of Class.t_class_type - | Res_value of Value.t_value - | Res_type of Type.t_type - | Res_exception of Exception.t_exception - | Res_attribute of Value.t_attribute - | Res_method of Value.t_method - | Res_section of string + | Res_module_type of Module.t_module_type + | Res_class of Class.t_class + | Res_class_type of Class.t_class_type + | Res_value of Value.t_value + | Res_type of Type.t_type + | Res_exception of Exception.t_exception + | Res_attribute of Value.t_attribute + | Res_method of Value.t_method + | Res_section of string (** The type representing a research result.*) type search_result = result_element list @@ -752,85 +752,85 @@ module Scan : object (** Scan of 'leaf elements'. *) - method scan_value : Value.t_value -> unit - method scan_type : Type.t_type -> unit - method scan_exception : Exception.t_exception -> unit - method scan_attribute : Value.t_attribute -> unit - method scan_method : Value.t_method -> unit - method scan_included_module : Module.included_module -> unit - + method scan_value : Value.t_value -> unit + method scan_type : Type.t_type -> unit + method scan_exception : Exception.t_exception -> unit + method scan_attribute : Value.t_attribute -> unit + method scan_method : Value.t_method -> unit + method scan_included_module : Module.included_module -> unit + (** Scan of a class. *) (** Scan of a comment inside a class. *) - method scan_class_comment : text -> unit + method scan_class_comment : text -> unit (** Override this method to perform controls on the class comment - and params. This method is called before scanning the class elements. - @return true if the class elements must be scanned.*) - method scan_class_pre : Class.t_class -> bool + and params. This method is called before scanning the class elements. + @return true if the class elements must be scanned.*) + method scan_class_pre : Class.t_class -> bool (** This method scan the elements of the given class. *) - method scan_class_elements : Class.t_class -> unit + method scan_class_elements : Class.t_class -> unit (** Scan of a class. Should not be overriden. It calls [scan_class_pre] - and if [scan_class_pre] returns [true], then it calls scan_class_elements.*) - method scan_class : Class.t_class -> unit + and if [scan_class_pre] returns [true], then it calls scan_class_elements.*) + method scan_class : Class.t_class -> unit (** Scan of a class type. *) (** Scan of a comment inside a class type. *) - method scan_class_type_comment : text -> unit + method scan_class_type_comment : text -> unit (** Override this method to perform controls on the class type comment - and form. This method is called before scanning the class type elements. - @return true if the class type elements must be scanned.*) - method scan_class_type_pre : Class.t_class_type -> bool + and form. This method is called before scanning the class type elements. + @return true if the class type elements must be scanned.*) + method scan_class_type_pre : Class.t_class_type -> bool (** This method scan the elements of the given class type. *) - method scan_class_type_elements : Class.t_class_type -> unit + method scan_class_type_elements : Class.t_class_type -> unit (** Scan of a class type. Should not be overriden. 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 : Class.t_class_type -> unit + and if [scan_class_type_pre] returns [true], then it calls scan_class_type_elements.*) + method scan_class_type : Class.t_class_type -> unit (** Scan of modules. *) (** Scan of a comment inside a module. *) - method scan_module_comment : text -> unit + method scan_module_comment : text -> unit (** Override this method to perform controls on the module comment - and form. This method is called before scanning the module elements. - @return true if the module elements must be scanned.*) - method scan_module_pre : Module.t_module -> bool + and form. This method is called before scanning the module elements. + @return true if the module elements must be scanned.*) + method scan_module_pre : Module.t_module -> bool (** This method scan the elements of the given module. *) - method scan_module_elements : Module.t_module -> unit + method scan_module_elements : Module.t_module -> unit (** Scan of a module. Should not be overriden. It calls [scan_module_pre] - and if [scan_module_pre] returns [true], then it calls scan_module_elements.*) - method scan_module : Module.t_module -> unit + and if [scan_module_pre] returns [true], then it calls scan_module_elements.*) + method scan_module : Module.t_module -> unit (** Scan of module types. *) (** Scan of a comment inside a module type. *) - method scan_module_type_comment : text -> unit + method scan_module_type_comment : text -> unit (** Override this method to perform controls on the module type comment - and form. This method is called before scanning the module type elements. - @return true if the module type elements must be scanned. *) - method scan_module_type_pre : Module.t_module_type -> bool + and form. This method is called before scanning the module type elements. + @return true if the module type elements must be scanned. *) + method scan_module_type_pre : Module.t_module_type -> bool (** This method scan the elements of the given module type. *) - method scan_module_type_elements : Module.t_module_type -> unit + method scan_module_type_elements : Module.t_module_type -> unit (** Scan of a module type. Should not be overriden. 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 : Module.t_module_type -> unit + and if [scan_module_type_pre] returns [true], then it calls scan_module_type_elements.*) + method scan_module_type : Module.t_module_type -> unit (** Main scanning method. *) (** Scan a list of modules. *) - method scan_module_list : Module.t_module list -> unit + method scan_module_list : Module.t_module list -> unit end end diff --git a/ocamldoc/odoc_latex.ml b/ocamldoc/odoc_latex.ml index 12f935d68..9e313f9d8 100644 --- a/ocamldoc/odoc_latex.ml +++ b/ocamldoc/odoc_latex.ml @@ -30,8 +30,8 @@ class text = and with the given latex code. *) method section_style level s = try - let sec = List.assoc level !Odoc_args.latex_titles in - "\\"^sec^"{"^s^"}\n" + let sec = List.assoc level !Odoc_args.latex_titles in + "\\"^sec^"{"^s^"}\n" with Not_found -> s (** Associations of strings to subsitute in latex code. *) @@ -77,10 +77,10 @@ class text = val mutable subst_strings_simple = [ - ("MAXENCE"^"XXX", "{\\textbackslash}") ; - "}", "\\}" ; - "{", "\\{" ; - ("\\\\", "MAXENCE"^"XXX") ; + ("MAXENCE"^"XXX", "{\\textbackslash}") ; + "}", "\\}" ; + "{", "\\{" ; + ("\\\\", "MAXENCE"^"XXX") ; ] val mutable subst_strings_code = [ @@ -102,9 +102,9 @@ class text = method subst l s = List.fold_right - (fun (s, s2) -> fun acc -> Str.global_replace (Str.regexp s) s2 acc) - l - s + (fun (s, s2) -> fun acc -> Str.global_replace (Str.regexp s) s2 acc) + l + s (** Escape the strings which would clash with LaTeX syntax. *) method escape s = self#subst subst_strings s @@ -114,19 +114,19 @@ class text = (** Escape some characters for the code style. *) method escape_code s = self#subst subst_strings_code s - + (** Make a correct latex label from a name. *) method label ?(no_=true) name = let len = String.length name in let buf = Buffer.create len in for i = 0 to len - 1 do - match name.[i] with - '_' -> if no_ then () else Buffer.add_char buf '_' - | '~' -> if no_ then () else Buffer.add_char buf '~' - | '@' -> Buffer.add_string buf "\"@" - | '!' -> Buffer.add_string buf "\"!" - | '|' -> Buffer.add_string buf "\"|" - | c -> Buffer.add_char buf c + match name.[i] with + '_' -> if no_ then () else Buffer.add_char buf '_' + | '~' -> if no_ then () else Buffer.add_char buf '~' + | '@' -> Buffer.add_string buf "\"@" + | '!' -> Buffer.add_string buf "\"!" + | '|' -> Buffer.add_string buf "\"|" + | c -> Buffer.add_char buf c done; Buffer.contents buf @@ -165,31 +165,31 @@ class text = (** Return the LaTeX code corresponding to the [text] parameter.*) method latex_of_text t = String.concat "" (List.map self#latex_of_text_element t) - + (** Return the LaTeX code for the [text_element] in parameter. *) method latex_of_text_element te = match te with - | Odoc_info.Raw s -> self#latex_of_Raw s - | Odoc_info.Code s -> self#latex_of_Code s - | Odoc_info.CodePre s -> self#latex_of_CodePre s - | Odoc_info.Verbatim s -> self#latex_of_Verbatim s - | Odoc_info.Bold t -> self#latex_of_Bold t - | Odoc_info.Italic t -> self#latex_of_Italic t - | Odoc_info.Emphasize t -> self#latex_of_Emphasize t - | Odoc_info.Center t -> self#latex_of_Center t - | Odoc_info.Left t -> self#latex_of_Left t - | Odoc_info.Right t -> self#latex_of_Right t - | Odoc_info.List tl -> self#latex_of_List tl - | Odoc_info.Enum tl -> self#latex_of_Enum tl - | Odoc_info.Newline -> self#latex_of_Newline - | Odoc_info.Block t -> self#latex_of_Block t - | Odoc_info.Title (n, l_opt, t) -> self#latex_of_Title n l_opt t - | Odoc_info.Latex s -> self#latex_of_Latex s - | Odoc_info.Link (s, t) -> self#latex_of_Link s t - | Odoc_info.Ref (name, ref_opt) -> self#latex_of_Ref name ref_opt - | Odoc_info.Superscript t -> self#latex_of_Superscript t - | Odoc_info.Subscript t -> self#latex_of_Subscript t - + | Odoc_info.Raw s -> self#latex_of_Raw s + | Odoc_info.Code s -> self#latex_of_Code s + | Odoc_info.CodePre s -> self#latex_of_CodePre s + | Odoc_info.Verbatim s -> self#latex_of_Verbatim s + | Odoc_info.Bold t -> self#latex_of_Bold t + | Odoc_info.Italic t -> self#latex_of_Italic t + | Odoc_info.Emphasize t -> self#latex_of_Emphasize t + | Odoc_info.Center t -> self#latex_of_Center t + | Odoc_info.Left t -> self#latex_of_Left t + | Odoc_info.Right t -> self#latex_of_Right t + | Odoc_info.List tl -> self#latex_of_List tl + | Odoc_info.Enum tl -> self#latex_of_Enum tl + | Odoc_info.Newline -> self#latex_of_Newline + | Odoc_info.Block t -> self#latex_of_Block t + | Odoc_info.Title (n, l_opt, t) -> self#latex_of_Title n l_opt t + | Odoc_info.Latex s -> self#latex_of_Latex s + | Odoc_info.Link (s, t) -> self#latex_of_Link s t + | Odoc_info.Ref (name, ref_opt) -> self#latex_of_Ref name ref_opt + | Odoc_info.Superscript t -> self#latex_of_Superscript t + | Odoc_info.Subscript t -> self#latex_of_Subscript t + method latex_of_Raw s = self#escape s method latex_of_Code s = @@ -229,13 +229,13 @@ class text = method latex_of_List tl = "\\begin{itemize}"^ (String.concat "" - (List.map (fun t -> "\\item "^(self#latex_of_text t)^"\n") tl))^ + (List.map (fun t -> "\\item "^(self#latex_of_text t)^"\n") tl))^ "\\end{itemize}\n" method latex_of_Enum tl = "\\begin{enumerate}"^ (String.concat "" - (List.map (fun t -> "\\item "^(self#latex_of_text t)^"\n") tl))^ + (List.map (fun t -> "\\item "^(self#latex_of_text t)^"\n") tl))^ "\\end{enumerate}\n" method latex_of_Newline = "\n\n" @@ -249,8 +249,8 @@ class text = let s_title2 = self#section_style n s_title in s_title2^ (match label_opt with - None -> "" - | Some l -> self#make_label (self#label ~no_: false l)) + None -> "" + | Some l -> self#make_label (self#label ~no_: false l)) method latex_of_Latex s = s @@ -261,32 +261,32 @@ class text = method latex_of_Ref name ref_opt = match ref_opt with - None -> - self#latex_of_text_element - (Odoc_info.Code (Odoc_info.use_hidden_modules name)) - | Some kind when kind = RK_section -> - self#latex_of_text_element - (Latex ("["^(self#make_ref (self#label ~no_:false (Name.simple name)))^"]")) - | Some kind -> - let f_label = - match kind with - Odoc_info.RK_module -> self#module_label - | Odoc_info.RK_module_type -> self#module_type_label - | Odoc_info.RK_class -> self#class_label - | Odoc_info.RK_class_type -> self#class_type_label - | Odoc_info.RK_value -> self#value_label - | Odoc_info.RK_type -> self#type_label - | Odoc_info.RK_exception -> self#exception_label - | Odoc_info.RK_attribute -> self#attribute_label - | Odoc_info.RK_method -> self#method_label - | Odoc_info.RK_section -> assert false - in - (self#latex_of_text - [ - Odoc_info.Code (Odoc_info.use_hidden_modules name) ; - Latex ("["^(self#make_ref (f_label name))^"]") - ] - ) + None -> + self#latex_of_text_element + (Odoc_info.Code (Odoc_info.use_hidden_modules name)) + | Some kind when kind = RK_section -> + self#latex_of_text_element + (Latex ("["^(self#make_ref (self#label ~no_:false (Name.simple name)))^"]")) + | Some kind -> + let f_label = + match kind with + Odoc_info.RK_module -> self#module_label + | Odoc_info.RK_module_type -> self#module_type_label + | Odoc_info.RK_class -> self#class_label + | Odoc_info.RK_class_type -> self#class_type_label + | Odoc_info.RK_value -> self#value_label + | Odoc_info.RK_type -> self#type_label + | Odoc_info.RK_exception -> self#exception_label + | Odoc_info.RK_attribute -> self#attribute_label + | Odoc_info.RK_method -> self#method_label + | Odoc_info.RK_section -> assert false + in + (self#latex_of_text + [ + Odoc_info.Code (Odoc_info.use_hidden_modules name) ; + Latex ("["^(self#make_ref (f_label name))^"]") + ] + ) method latex_of_Superscript t = "$^{"^(self#latex_of_text t)^"}$" @@ -306,7 +306,7 @@ class virtual info = (** Return LaTeX code for a description, except for the [i_params] field. *) method latex_of_info info_opt = self#latex_of_text - (self#text_of_info ~block: false info_opt) + (self#text_of_info ~block: false info_opt) end (** This class is used to create objects which can generate a simple LaTeX documentation. *) @@ -325,153 +325,153 @@ class latex = *) method first_and_rest_of_info i_opt = match i_opt with - None -> ([], []) + None -> ([], []) | Some i -> - match i.Odoc_info.i_desc with - None -> ([], self#text_of_info ~block: true i_opt) - | Some t -> - let (first,_) = Odoc_info.first_sentence_and_rest_of_text t in - let (_, rest) = Odoc_info.first_sentence_and_rest_of_text (self#text_of_info ~block: false i_opt) in - (Odoc_info.text_no_title_no_list first, rest) + match i.Odoc_info.i_desc with + None -> ([], self#text_of_info ~block: true i_opt) + | Some t -> + let (first,_) = Odoc_info.first_sentence_and_rest_of_text t in + let (_, rest) = Odoc_info.first_sentence_and_rest_of_text (self#text_of_info ~block: false i_opt) in + (Odoc_info.text_no_title_no_list first, rest) (** Return LaTeX code for a value. *) method latex_of_value v = Odoc_info.reset_type_names () ; self#latex_of_text - ((Latex (self#make_label (self#value_label v.val_name))) :: - (to_text#text_of_value v)) + ((Latex (self#make_label (self#value_label v.val_name))) :: + (to_text#text_of_value v)) (** Return LaTeX code for a class attribute. *) method latex_of_attribute a = self#latex_of_text - ((Latex (self#make_label (self#attribute_label a.att_value.val_name))) :: - (to_text#text_of_attribute a)) + ((Latex (self#make_label (self#attribute_label a.att_value.val_name))) :: + (to_text#text_of_attribute a)) (** Return LaTeX code for a class method. *) method latex_of_method m = self#latex_of_text - ((Latex (self#make_label (self#method_label m.met_value.val_name))) :: - (to_text#text_of_method m)) + ((Latex (self#make_label (self#method_label m.met_value.val_name))) :: + (to_text#text_of_method m)) (** Return LaTeX code for a type. *) method latex_of_type t = let s_name = Name.simple t.ty_name in let text = - Odoc_info.reset_type_names () ; - let mod_name = Name.father t.ty_name in - let s_type1 = - Format.fprintf Format.str_formatter - "@[<hov 2>type "; - match t.ty_parameters with - [] -> Format.flush_str_formatter () - | [p] -> self#normal_type mod_name p - | l -> - Format.fprintf Format.str_formatter "(" ; - let s = self#normal_type_list mod_name ", " l in - s^")" - in - Format.fprintf Format.str_formatter - ("@[<hov 2>%s %s") - s_type1 - s_name; - let s_type2 = - match t.ty_manifest with - None -> Format.flush_str_formatter () - | Some typ -> - Format.fprintf Format.str_formatter " = "; - self#normal_type mod_name typ - in - let s_type3 = - Format.fprintf Format.str_formatter - ("%s %s") - s_type2 - (match t.ty_kind with - Type_abstract -> "" - | Type_variant _ -> "=" - | Type_record _ -> "= {" ) ; - Format.flush_str_formatter () - in - - let defs = - match t.ty_kind with - Type_abstract -> [] - | Type_variant l -> - (List.flatten - (List.map - (fun constr -> - let s_cons = - Format.fprintf Format.str_formatter - "@[<hov 6> | %s" - constr.vc_name; - match constr.vc_args with - [] -> Format.flush_str_formatter () - | l -> - Format.fprintf Format.str_formatter " %s@ " "of"; - self#normal_type_list mod_name " * " l - in - [ CodePre s_cons ] @ - (match constr.vc_text with - None -> [] - | Some t -> - [ Latex - ("\\begin{ocamldoccomment}\n"^ - (self#latex_of_text t)^ - "\n\\end{ocamldoccomment}\n") - ] - ) - ) - l - ) - ) - | Type_record l -> - (List.flatten - (List.map - (fun r -> - let s_field = - Format.fprintf Format.str_formatter - "@[<hov 6> %s%s :@ " - (if r.rf_mutable then "mutable " else "") - r.rf_name; - (self#normal_type mod_name r.rf_type)^" ;" - in - [ CodePre s_field ] @ - (match r.rf_text with - None -> [] - | Some t -> - [ Latex - ("\\begin{ocamldoccomment}\n"^ - (self#latex_of_text t)^ - "\n\\end{ocamldoccomment}\n") - ] - ) - ) - l - ) - ) @ - [ CodePre "}" ] - in - let defs2 = (CodePre s_type3) :: defs in - let rec iter = function - [] -> [] - | [e] -> [e] - | (CodePre s1) :: (CodePre s2) :: q -> - iter ((CodePre (s1^"\n"^s2)) :: q) - | e :: q -> - e :: (iter q) - in - (iter defs2) @ - [Latex ("\\index{"^(self#type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ - (self#text_of_info t.ty_info) + Odoc_info.reset_type_names () ; + let mod_name = Name.father t.ty_name in + let s_type1 = + Format.fprintf Format.str_formatter + "@[<hov 2>type "; + match t.ty_parameters with + [] -> Format.flush_str_formatter () + | [p] -> self#normal_type mod_name p + | l -> + Format.fprintf Format.str_formatter "(" ; + let s = self#normal_type_list mod_name ", " l in + s^")" + in + Format.fprintf Format.str_formatter + ("@[<hov 2>%s %s") + s_type1 + s_name; + let s_type2 = + match t.ty_manifest with + None -> Format.flush_str_formatter () + | Some typ -> + Format.fprintf Format.str_formatter " = "; + self#normal_type mod_name typ + in + let s_type3 = + Format.fprintf Format.str_formatter + ("%s %s") + s_type2 + (match t.ty_kind with + Type_abstract -> "" + | Type_variant _ -> "=" + | Type_record _ -> "= {" ) ; + Format.flush_str_formatter () + in + + let defs = + match t.ty_kind with + Type_abstract -> [] + | Type_variant l -> + (List.flatten + (List.map + (fun constr -> + let s_cons = + Format.fprintf Format.str_formatter + "@[<hov 6> | %s" + constr.vc_name; + match constr.vc_args with + [] -> Format.flush_str_formatter () + | l -> + Format.fprintf Format.str_formatter " %s@ " "of"; + self#normal_type_list mod_name " * " l + in + [ CodePre s_cons ] @ + (match constr.vc_text with + None -> [] + | Some t -> + [ Latex + ("\\begin{ocamldoccomment}\n"^ + (self#latex_of_text t)^ + "\n\\end{ocamldoccomment}\n") + ] + ) + ) + l + ) + ) + | Type_record l -> + (List.flatten + (List.map + (fun r -> + let s_field = + Format.fprintf Format.str_formatter + "@[<hov 6> %s%s :@ " + (if r.rf_mutable then "mutable " else "") + r.rf_name; + (self#normal_type mod_name r.rf_type)^" ;" + in + [ CodePre s_field ] @ + (match r.rf_text with + None -> [] + | Some t -> + [ Latex + ("\\begin{ocamldoccomment}\n"^ + (self#latex_of_text t)^ + "\n\\end{ocamldoccomment}\n") + ] + ) + ) + l + ) + ) @ + [ CodePre "}" ] + in + let defs2 = (CodePre s_type3) :: defs in + let rec iter = function + [] -> [] + | [e] -> [e] + | (CodePre s1) :: (CodePre s2) :: q -> + iter ((CodePre (s1^"\n"^s2)) :: q) + | e :: q -> + e :: (iter q) + in + (iter defs2) @ + [Latex ("\\index{"^(self#type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ + (self#text_of_info t.ty_info) in self#latex_of_text - ((Latex (self#make_label (self#type_label t.ty_name))) :: text) + ((Latex (self#make_label (self#type_label t.ty_name))) :: text) (** Return LaTeX code for an exception. *) method latex_of_exception e = Odoc_info.reset_type_names () ; self#latex_of_text - ((Latex (self#make_label (self#exception_label e.ex_name))) :: - (to_text#text_of_exception e)) + ((Latex (self#make_label (self#exception_label e.ex_name))) :: + (to_text#text_of_exception e)) (** Return the LaTeX code for the given module. *) method latex_of_module ?(with_link=true) m = @@ -479,17 +479,17 @@ class latex = let f = Format.formatter_of_buffer buf in let father = Name.father m.m_name in let t = - Format.fprintf f "module %s" (Name.simple m.m_name); - Format.fprintf f " = %s" - (self#normal_module_type father m.m_type); - Format.pp_print_flush f (); - - (CodePre (Buffer.contents buf)) :: - ( - if with_link - then [Odoc_info.Latex ("\\\n["^(self#make_ref (self#module_label m.m_name))^"]")] - else [] - ) + Format.fprintf f "module %s" (Name.simple m.m_name); + Format.fprintf f " = %s" + (self#normal_module_type father m.m_type); + Format.pp_print_flush f (); + + (CodePre (Buffer.contents buf)) :: + ( + if with_link + then [Odoc_info.Latex ("\\\n["^(self#make_ref (self#module_label m.m_name))^"]")] + else [] + ) in self#latex_of_text t @@ -499,34 +499,34 @@ class latex = let f = Format.formatter_of_buffer buf in let father = Name.father mt.mt_name in let t = - Format.fprintf f "module type %s" (Name.simple mt.mt_name); - (match mt.mt_type with - None -> () - | Some mtyp -> - Format.fprintf f " = %s" - (self#normal_module_type father mtyp) - ); - - Format.pp_print_flush f (); - - (CodePre (Buffer.contents buf)) :: - ( - if with_link - then [Odoc_info.Latex ("\\\n["^(self#make_ref (self#module_type_label mt.mt_name))^"]")] - else [] - ) + Format.fprintf f "module type %s" (Name.simple mt.mt_name); + (match mt.mt_type with + None -> () + | Some mtyp -> + Format.fprintf f " = %s" + (self#normal_module_type father mtyp) + ); + + Format.pp_print_flush f (); + + (CodePre (Buffer.contents buf)) :: + ( + if with_link + then [Odoc_info.Latex ("\\\n["^(self#make_ref (self#module_type_label mt.mt_name))^"]")] + else [] + ) in self#latex_of_text t (** Return the LaTeX code for the given included module. *) method latex_of_included_module im = (self#latex_of_text [ Code "include module " ; - Code - (match im.im_module with - None -> im.im_name - | Some (Mod m) -> m.m_name - | Some (Modtype mt) -> mt.mt_name) - ] ) + Code + (match im.im_module with + None -> im.im_name + | Some (Mod m) -> m.m_name + | Some (Modtype mt) -> mt.mt_name) + ] ) (** Return the LaTeX code for the given class. *) method latex_of_class ?(with_link=true) c = @@ -535,27 +535,27 @@ class latex = let f = Format.formatter_of_buffer buf in let father = Name.father c.cl_name in let t = - Format.fprintf f "class %s" - (if c.cl_virtual then "virtual " else ""); - ( - match c.cl_type_parameters with - [] -> () - | l -> - Format.fprintf f "[" ; - let s1 = self#normal_type_list father ", " l in - Format.fprintf f "%s] " s1 - ); - Format.fprintf f "%s : " (Name.simple c.cl_name); - Format.fprintf f "%s" (self#normal_class_type father c.cl_type); - - Format.pp_print_flush f (); - - (CodePre (Buffer.contents buf)) :: - ( - if with_link - then [Odoc_info.Latex (" ["^(self#make_ref (self#class_label c.cl_name))^"]")] - else [] - ) + Format.fprintf f "class %s" + (if c.cl_virtual then "virtual " else ""); + ( + match c.cl_type_parameters with + [] -> () + | l -> + Format.fprintf f "[" ; + let s1 = self#normal_type_list father ", " l in + Format.fprintf f "%s] " s1 + ); + Format.fprintf f "%s : " (Name.simple c.cl_name); + Format.fprintf f "%s" (self#normal_class_type father c.cl_type); + + Format.pp_print_flush f (); + + (CodePre (Buffer.contents buf)) :: + ( + if with_link + then [Odoc_info.Latex (" ["^(self#make_ref (self#class_label c.cl_name))^"]")] + else [] + ) in self#latex_of_text t @@ -566,26 +566,26 @@ class latex = let f = Format.formatter_of_buffer buf in let father = Name.father ct.clt_name in let t = - Format.fprintf f "class type %s" - (if ct.clt_virtual then "virtual " else ""); - ( - match ct.clt_type_parameters with - [] -> () - | l -> - Format.fprintf f "[" ; - let s1 = self#normal_type_list father ", " l in - Format.fprintf f "%s] " s1 - ); - Format.fprintf f "%s = " (Name.simple ct.clt_name); - Format.fprintf f "%s" (self#normal_class_type father ct.clt_type); - - Format.pp_print_flush f (); - (CodePre (Buffer.contents buf)) :: - ( - if with_link - then [Odoc_info.Latex (" ["^(self#make_ref (self#class_type_label ct.clt_name))^"]")] - else [] - ) + Format.fprintf f "class type %s" + (if ct.clt_virtual then "virtual " else ""); + ( + match ct.clt_type_parameters with + [] -> () + | l -> + Format.fprintf f "[" ; + let s1 = self#normal_type_list father ", " l in + Format.fprintf f "%s] " s1 + ); + Format.fprintf f "%s = " (Name.simple ct.clt_name); + Format.fprintf f "%s" (self#normal_class_type father ct.clt_type); + + Format.pp_print_flush f (); + (CodePre (Buffer.contents buf)) :: + ( + if with_link + then [Odoc_info.Latex (" ["^(self#make_ref (self#class_type_label ct.clt_name))^"]")] + else [] + ) in self#latex_of_text t @@ -594,13 +594,13 @@ class latex = (self#latex_of_text [Newline])^ ( match class_ele with - Class_attribute att -> self#latex_of_attribute att + Class_attribute att -> self#latex_of_attribute att | Class_method met -> self#latex_of_method met | Class_comment t -> - match t with - | [] -> "" - | (Title (_,_,_)) :: _ -> self#latex_of_text t - | _ -> self#latex_of_text [ Title ((Name.depth class_name) + 2, None, t) ] + match t with + | [] -> "" + | (Title (_,_,_)) :: _ -> self#latex_of_text t + | _ -> self#latex_of_text [ Title ((Name.depth class_name) + 2, None, t) ] ) (** Return the LaTeX code for the given module element. *) @@ -608,7 +608,7 @@ class latex = (self#latex_of_text [Newline])^ ( match module_ele with - Element_module m -> self#latex_of_module m + Element_module m -> self#latex_of_module m | Element_module_type mt -> self#latex_of_module_type mt | Element_included_module im -> self#latex_of_included_module im | Element_class c -> self#latex_of_class c @@ -622,30 +622,30 @@ class latex = (** Generate the LaTeX code for the given list of inherited classes.*) method generate_inheritance_info chanout inher_l = let f inh = - match inh.ic_class with - None -> (* we can't make the reference *) - (Odoc_info.Code inh.ic_name) :: - (match inh.ic_text with - None -> [] - | Some t -> Newline :: t - ) - | Some cct -> - let label = - match cct with - Cl _ -> self#class_label inh.ic_name - | Cltype _ -> self#class_type_label inh.ic_name - in - (* we can create the reference *) - (Odoc_info.Code inh.ic_name) :: - (Odoc_info.Latex (" ["^(self#make_ref label)^"]")) :: - (match inh.ic_text with - None -> [] - | Some t -> Newline :: t - ) + match inh.ic_class with + None -> (* we can't make the reference *) + (Odoc_info.Code inh.ic_name) :: + (match inh.ic_text with + None -> [] + | Some t -> Newline :: t + ) + | Some cct -> + let label = + match cct with + Cl _ -> self#class_label inh.ic_name + | Cltype _ -> self#class_type_label inh.ic_name + in + (* we can create the reference *) + (Odoc_info.Code inh.ic_name) :: + (Odoc_info.Latex (" ["^(self#make_ref label)^"]")) :: + (match inh.ic_text with + None -> [] + | Some t -> Newline :: t + ) in let text = [ - Odoc_info.Bold [Odoc_info.Raw Odoc_messages.inherits ]; - Odoc_info.List (List.map f inher_l) + Odoc_info.Bold [Odoc_info.Raw Odoc_messages.inherits ]; + Odoc_info.List (List.map f inher_l) ] in let s = self#latex_of_text text in @@ -654,28 +654,28 @@ class latex = (** Generate the LaTeX code for the inherited classes of the given class. *) method generate_class_inheritance_info chanout cl = let rec iter_kind k = - match k with - Class_structure ([], _) -> - () - | Class_structure (l, _) -> - self#generate_inheritance_info chanout l - | Class_constraint (k, _) -> - iter_kind k - | Class_apply _ - | Class_constr _ -> - () + match k with + Class_structure ([], _) -> + () + | Class_structure (l, _) -> + self#generate_inheritance_info chanout l + | Class_constraint (k, _) -> + iter_kind k + | Class_apply _ + | Class_constr _ -> + () in iter_kind cl.cl_kind (** Generate the LaTeX code for the inherited classes of the given class type. *) method generate_class_type_inheritance_info chanout clt = match clt.clt_kind with - Class_signature ([], _) -> - () - | Class_signature (l, _) -> - self#generate_inheritance_info chanout l - | Class_type _ -> - () + Class_signature ([], _) -> + () + | Class_signature (l, _) -> + self#generate_inheritance_info chanout l + | Class_type _ -> + () (** Generate the LaTeX code for the given class, in the given out channel. *) method generate_for_class chanout c = @@ -683,29 +683,29 @@ class latex = let depth = Name.depth c.cl_name in let (first_t, rest_t) = self#first_and_rest_of_info c.cl_info in let text = [ Title (depth, None, [ Raw (Odoc_messages.clas^" ") ; Code c.cl_name ] @ - (match first_t with - [] -> [] - | t -> (Raw " : ") :: t)) ; - Latex (self#make_label (self#class_label c.cl_name)) ; - ] + (match first_t with + [] -> [] + | t -> (Raw " : ") :: t)) ; + Latex (self#make_label (self#class_label c.cl_name)) ; + ] in output_string chanout (self#latex_of_text text); output_string chanout ((self#latex_of_class ~with_link: false c)^"\n\n") ; let s_name = Name.simple c.cl_name in output_string chanout - (self#latex_of_text [Latex ("\\index{"^(self#class_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); + (self#latex_of_text [Latex ("\\index{"^(self#class_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); output_string chanout (self#latex_of_text rest_t) ; (* parameters *) output_string chanout - (self#latex_of_text (self#text_of_parameter_list (Name.father c.cl_name) c.cl_parameters)); + (self#latex_of_text (self#text_of_parameter_list (Name.father c.cl_name) c.cl_parameters)); output_string chanout (self#latex_of_text [ Newline ] ); output_string chanout ("\\vspace{0.5cm}\n\n"); self#generate_class_inheritance_info chanout c; List.iter - (fun ele -> output_string chanout ((self#latex_of_class_element c.cl_name ele)^"\\vspace{0.1cm}\n\n")) - (Class.class_elements ~trans: false c) + (fun ele -> output_string chanout ((self#latex_of_class_element c.cl_name ele)^"\\vspace{0.1cm}\n\n")) + (Class.class_elements ~trans: false c) (** Generate the LaTeX code for the given class type, in the given out channel. *) method generate_for_class_type chanout ct = @@ -713,65 +713,65 @@ class latex = let depth = Name.depth ct.clt_name in let (first_t, rest_t) = self#first_and_rest_of_info ct.clt_info in let text = [ Title (depth, None, [ Raw (Odoc_messages.class_type^" ") ; Code ct.clt_name ] @ - (match first_t with - [] -> [] - | t -> (Raw " : ") :: t)) ; - Latex (self#make_label (self#class_type_label ct.clt_name)) ; - ] + (match first_t with + [] -> [] + | t -> (Raw " : ") :: t)) ; + Latex (self#make_label (self#class_type_label ct.clt_name)) ; + ] in output_string chanout (self#latex_of_text text); output_string chanout ((self#latex_of_class_type ~with_link: false ct)^"\n\n") ; let s_name = Name.simple ct.clt_name in output_string chanout - (self#latex_of_text [Latex ("\\index{"^(self#class_type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); + (self#latex_of_text [Latex ("\\index{"^(self#class_type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); output_string chanout ((self#latex_of_text rest_t)) ; output_string chanout (self#latex_of_text [ Newline]) ; output_string chanout ("\\vspace{0.5cm}\n\n"); self#generate_class_type_inheritance_info chanout ct; List.iter - (fun ele -> output_string chanout ((self#latex_of_class_element ct.clt_name ele)^"\\vspace{0.1cm}\n\n")) - (Class.class_type_elements ~trans: false ct) + (fun ele -> output_string chanout ((self#latex_of_class_element ct.clt_name ele)^"\\vspace{0.1cm}\n\n")) + (Class.class_type_elements ~trans: false ct) (** Generate the LaTeX code for the given module type, in the given out channel. *) method generate_for_module_type chanout mt = let depth = Name.depth mt.mt_name in let (first_t, rest_t) = self#first_and_rest_of_info mt.mt_info in let text = [ Title (depth, None, - [ Raw (Odoc_messages.module_type^" ") ; Code mt.mt_name ] @ - (match first_t with - [] -> [] - | t -> (Raw " : ") :: t)) ; - Latex (self#make_label (self#module_type_label mt.mt_name)) ; - ] + [ Raw (Odoc_messages.module_type^" ") ; Code mt.mt_name ] @ + (match first_t with + [] -> [] + | t -> (Raw " : ") :: t)) ; + Latex (self#make_label (self#module_type_label mt.mt_name)) ; + ] in output_string chanout (self#latex_of_text text); if depth > 1 then - output_string chanout ((self#latex_of_module_type ~with_link: false mt)^"\n\n"); + output_string chanout ((self#latex_of_module_type ~with_link: false mt)^"\n\n"); let s_name = Name.simple mt.mt_name in output_string chanout - (self#latex_of_text [Latex ("\\index{"^(self#module_type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); + (self#latex_of_text [Latex ("\\index{"^(self#module_type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); output_string chanout (self#latex_of_text rest_t) ; (* parameters *) output_string chanout - (self#latex_of_text - (self#text_of_module_parameter_list - (Module.module_type_parameters mt))); + (self#latex_of_text + (self#text_of_module_parameter_list + (Module.module_type_parameters mt))); output_string chanout (self#latex_of_text [ Newline ] ); output_string chanout ("\\vspace{0.5cm}\n\n"); List.iter - (fun ele -> output_string chanout ((self#latex_of_module_element mt.mt_name ele)^"\\vspace{0.1cm}\n\n")) - (Module.module_type_elements ~trans: false mt); + (fun ele -> output_string chanout ((self#latex_of_module_element mt.mt_name ele)^"\\vspace{0.1cm}\n\n")) + (Module.module_type_elements ~trans: false mt); (* create sub parts for modules, module types, classes and class types *) let rec iter ele = - match ele with - Element_module m -> self#generate_for_module chanout m - | Element_module_type mt -> self#generate_for_module_type chanout mt - | Element_class c -> self#generate_for_class chanout c - | Element_class_type ct -> self#generate_for_class_type chanout ct - | _ -> () + match ele with + Element_module m -> self#generate_for_module chanout m + | Element_module_type mt -> self#generate_for_module_type chanout mt + | Element_class c -> self#generate_for_class chanout c + | Element_class_type ct -> self#generate_for_class_type chanout ct + | _ -> () in List.iter iter (Module.module_type_elements ~trans: false mt) @@ -780,39 +780,39 @@ class latex = let depth = Name.depth m.m_name in let (first_t, rest_t) = self#first_and_rest_of_info m.m_info in let text = [ Title (depth, None, - [ Raw (Odoc_messages.modul^" ") ; Code m.m_name ] @ - (match first_t with - [] -> [] - | t -> (Raw " : ") :: t)) ; - Latex (self#make_label (self#module_label m.m_name)) ; - ] + [ Raw (Odoc_messages.modul^" ") ; Code m.m_name ] @ + (match first_t with + [] -> [] + | t -> (Raw " : ") :: t)) ; + Latex (self#make_label (self#module_label m.m_name)) ; + ] in output_string chanout (self#latex_of_text text); if depth > 1 then - output_string chanout ((self#latex_of_module ~with_link: false m)^"\n\n"); + output_string chanout ((self#latex_of_module ~with_link: false m)^"\n\n"); let s_name = Name.simple m.m_name in output_string chanout - (self#latex_of_text [Latex ("\\index{"^(self#module_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); + (self#latex_of_text [Latex ("\\index{"^(self#module_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); output_string chanout (self#latex_of_text rest_t) ; (* parameters *) output_string chanout - (self#latex_of_text - (self#text_of_module_parameter_list - (Module.module_parameters m))); + (self#latex_of_text + (self#text_of_module_parameter_list + (Module.module_parameters m))); output_string chanout (self#latex_of_text [ Newline ]) ; output_string chanout ("\\vspace{0.5cm}\n\n"); List.iter - (fun ele -> output_string chanout ((self#latex_of_module_element m.m_name ele)^"\\vspace{0.1cm}\n\n")) - (Module.module_elements ~trans: false m); + (fun ele -> output_string chanout ((self#latex_of_module_element m.m_name ele)^"\\vspace{0.1cm}\n\n")) + (Module.module_elements ~trans: false m); (* create sub parts for modules, module types, classes and class types *) let rec iter ele = - match ele with - Element_module m -> self#generate_for_module chanout m - | Element_module_type mt -> self#generate_for_module_type chanout mt - | Element_class c -> self#generate_for_class chanout c - | Element_class_type ct -> self#generate_for_class_type chanout ct - | _ -> () + match ele with + Element_module m -> self#generate_for_module chanout m + | Element_module_type mt -> self#generate_for_module_type chanout mt + | Element_class c -> self#generate_for_class chanout c + | Element_class_type ct -> self#generate_for_class_type chanout ct + | _ -> () in List.iter iter (Module.module_elements ~trans: false m) @@ -826,7 +826,7 @@ class latex = "\\usepackage{ocamldoc}\n"^ ( match !Odoc_args.title with - None -> "" + None -> "" | Some s -> "\\title{"^(self#escape s)^"}\n" )^ "\\begin{document}\n"^ @@ -836,38 +836,38 @@ class latex = (** Generate the LaTeX file from a module list, in the {!Odoc_args.out_file} file. *) method generate module_list = if !Odoc_args.separate_files then - ( - let f m = - try - let chanout = - open_out ((Filename.concat !Odoc_args.target_dir (Name.simple m.m_name))^".tex") - in - self#generate_for_module chanout m ; - close_out chanout - with - Failure s - | Sys_error s -> - prerr_endline s ; - incr Odoc_info.errors - in - List.iter f module_list - ); + ( + let f m = + try + let chanout = + open_out ((Filename.concat !Odoc_args.target_dir (Name.simple m.m_name))^".tex") + in + self#generate_for_module chanout m ; + close_out chanout + with + Failure s + | Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors + in + List.iter f module_list + ); try - let chanout = open_out (Filename.concat !Odoc_args.target_dir !Odoc_args.out_file) in - let _ = if !Odoc_args.with_header then output_string chanout self#latex_header else () in - List.iter - (fun m -> if !Odoc_args.separate_files then - output_string chanout ("\\input{"^((Name.simple m.m_name))^".tex}\n") - else - self#generate_for_module chanout m - ) - module_list ; - let _ = if !Odoc_args.with_trailer then output_string chanout "\\end{document}" else () in - close_out chanout + let chanout = open_out (Filename.concat !Odoc_args.target_dir !Odoc_args.out_file) in + let _ = if !Odoc_args.with_header then output_string chanout self#latex_header else () in + List.iter + (fun m -> if !Odoc_args.separate_files then + output_string chanout ("\\input{"^((Name.simple m.m_name))^".tex}\n") + else + self#generate_for_module chanout m + ) + module_list ; + let _ = if !Odoc_args.with_trailer then output_string chanout "\\end{document}" else () in + close_out chanout with - Failure s + Failure s | Sys_error s -> - prerr_endline s ; - incr Odoc_info.errors + prerr_endline s ; + incr Odoc_info.errors end diff --git a/ocamldoc/odoc_lexer.mll b/ocamldoc/odoc_lexer.mll index 3d34f2789..7f06d933a 100644 --- a/ocamldoc/odoc_lexer.mll +++ b/ocamldoc/odoc_lexer.mll @@ -49,37 +49,37 @@ let remove_blanks s = let l2 = let rec iter liste = match liste with - h :: q -> - let h2 = Str.global_replace (Str.regexp ("^"^blank^"+")) "" h in - if h2 = "" then - ( - print_DEBUG2 (h^" n'a que des blancs"); - (* we remove this line and must remove leading blanks of the next one *) - iter q - ) - else - (* we don't remove leading blanks in the remaining lines *) - h2 :: q + h :: q -> + let h2 = Str.global_replace (Str.regexp ("^"^blank^"+")) "" h in + if h2 = "" then + ( + print_DEBUG2 (h^" n'a que des blancs"); + (* we remove this line and must remove leading blanks of the next one *) + iter q + ) + else + (* we don't remove leading blanks in the remaining lines *) + h2 :: q | _ -> - [] + [] in iter l in let l3 = let rec iter liste = match liste with - h :: q -> - let h2 = Str.global_replace (Str.regexp (blank^"+$")) "" h in - if h2 = "" then - ( - print_DEBUG2 (h^" n'a que des blancs"); - (* we remove this line and must remove trailing blanks of the next one *) - iter q - ) - else - (* we don't remove trailing blanks in the remaining lines *) - h2 :: q + h :: q -> + let h2 = Str.global_replace (Str.regexp (blank^"+$")) "" h in + if h2 = "" then + ( + print_DEBUG2 (h^" n'a que des blancs"); + (* we remove this line and must remove trailing blanks of the next one *) + iter q + ) + else + (* we don't remove trailing blanks in the remaining lines *) + h2 :: q | _ -> - [] + [] in List.rev (iter (List.rev l2)) in @@ -99,47 +99,47 @@ let identchar = rule main = parse [' ' '\013' '\009' '\012'] + { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - main lexbuf + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + main lexbuf } | [ '\010' ] { - incr line_number; - incr Odoc_comments_global.nb_chars; + incr line_number; + incr Odoc_comments_global.nb_chars; main lexbuf } | "(**)" { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - Description ("", None) - } + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + Description ("", None) + } | "(**"("*"+)")" { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - main lexbuf - } + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + main lexbuf + } | "(***" { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - incr comments_level; - main lexbuf - } + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + incr comments_level; + main lexbuf + } | "(**" { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - incr comments_level; - if !comments_level = 1 then - ( - reset_string_buffer (); - description := ""; - special_comment lexbuf - ) - else - main lexbuf + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + incr comments_level; + if !comments_level = 1 then + ( + reset_string_buffer (); + description := ""; + special_comment lexbuf + ) + else + main lexbuf } | eof @@ -147,245 +147,245 @@ rule main = parse | "*)" { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - decr comments_level ; - main lexbuf - } + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + decr comments_level ; + main lexbuf + } | "(*" { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - incr comments_level ; - main lexbuf - } + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + incr comments_level ; + main lexbuf + } | _ { incr Odoc_comments_global.nb_chars; - main lexbuf + main lexbuf } and special_comment = parse | "*)" { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - if !comments_level = 1 then - ( + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + if !comments_level = 1 then + ( (* there is just a description *) - let s2 = lecture_string () in - let s3 = remove_blanks s2 in - let s4 = - if !Odoc_args.remove_stars then - remove_stars s3 - else - s3 - in - Description (s4, None) - ) - else - ( - ajout_string s; - decr comments_level; - special_comment lexbuf - ) + let s2 = lecture_string () in + let s3 = remove_blanks s2 in + let s4 = + if !Odoc_args.remove_stars then + remove_stars s3 + else + s3 + in + Description (s4, None) + ) + else + ( + ajout_string s; + decr comments_level; + special_comment lexbuf + ) } | "(*" { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - incr comments_level ; - ajout_string s; - special_comment lexbuf - } + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + incr comments_level ; + ajout_string s; + special_comment lexbuf + } | "\\@" { - let s = Lexing.lexeme lexbuf in - let c = (Lexing.lexeme_char lexbuf 1) in + let s = Lexing.lexeme lexbuf in + let c = (Lexing.lexeme_char lexbuf 1) in ajout_char_string c; - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); special_comment lexbuf - } + } | "@"lowercase+ { - (* we keep the description before we go further *) - let s = lecture_string () in - description := remove_blanks s; - reset_string_buffer (); - let len = String.length (Lexing.lexeme lexbuf) in - lexbuf.Lexing.lex_abs_pos <- lexbuf.Lexing.lex_abs_pos - len; - lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - len; - lexbuf.Lexing.lex_last_pos <- lexbuf.Lexing.lex_last_pos - len; - (* we don't increment the Odoc_comments_global.nb_chars *) - special_comment_part2 lexbuf - } + (* we keep the description before we go further *) + let s = lecture_string () in + description := remove_blanks s; + reset_string_buffer (); + let len = String.length (Lexing.lexeme lexbuf) in + lexbuf.Lexing.lex_abs_pos <- lexbuf.Lexing.lex_abs_pos - len; + lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - len; + lexbuf.Lexing.lex_last_pos <- lexbuf.Lexing.lex_last_pos - len; + (* we don't increment the Odoc_comments_global.nb_chars *) + special_comment_part2 lexbuf + } | _ { - let c = (Lexing.lexeme_char lexbuf 0) in + let c = (Lexing.lexeme_char lexbuf 0) in ajout_char_string c; if c = '\010' then incr line_number; - incr Odoc_comments_global.nb_chars; + incr Odoc_comments_global.nb_chars; special_comment lexbuf - } + } and special_comment_part2 = parse | "*)" { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - if !comments_level = 1 then - (* finally we return the description we kept *) - let desc = - if !Odoc_args.remove_stars then - remove_stars !description - else - !description - in - let remain = lecture_string () in - let remain2 = - if !Odoc_args.remove_stars then - remove_stars remain - else - remain - in - Description (desc, Some remain2) - else - ( - ajout_string s ; - decr comments_level ; - special_comment_part2 lexbuf - ) + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + if !comments_level = 1 then + (* finally we return the description we kept *) + let desc = + if !Odoc_args.remove_stars then + remove_stars !description + else + !description + in + let remain = lecture_string () in + let remain2 = + if !Odoc_args.remove_stars then + remove_stars remain + else + remain + in + Description (desc, Some remain2) + else + ( + ajout_string s ; + decr comments_level ; + special_comment_part2 lexbuf + ) } | "(*" { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - ajout_string s; - incr comments_level ; - special_comment_part2 lexbuf - } + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + ajout_string s; + incr comments_level ; + special_comment_part2 lexbuf + } | _ { - let c = (Lexing.lexeme_char lexbuf 0) in + let c = (Lexing.lexeme_char lexbuf 0) in ajout_char_string c; if c = '\010' then incr line_number; - incr Odoc_comments_global.nb_chars; + incr Odoc_comments_global.nb_chars; special_comment_part2 lexbuf - } + } and elements = parse | [' ' '\013' '\009' '\012'] + { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - elements lexbuf + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + elements lexbuf } | [ '\010' ] { incr line_number; - incr Odoc_comments_global.nb_chars; - print_DEBUG2 "newline"; + incr Odoc_comments_global.nb_chars; + print_DEBUG2 "newline"; elements lexbuf } | "@"lowercase+ { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - let s2 = String.sub s 1 ((String.length s) - 1) in - print_DEBUG2 s2; - match s2 with - "param" -> - T_PARAM - | "author" -> - T_AUTHOR - | "version" -> - T_VERSION - | "see" -> - T_SEE - | "since" -> - T_SINCE - | "deprecated" -> - T_DEPRECATED - | "raise" -> - T_RAISES - | "return" -> - T_RETURN - | s -> - if !Odoc_args.no_custom_tags then - raise (Failure (Odoc_messages.not_a_valid_tag s)) - else - T_CUSTOM s - } + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + let s2 = String.sub s 1 ((String.length s) - 1) in + print_DEBUG2 s2; + match s2 with + "param" -> + T_PARAM + | "author" -> + T_AUTHOR + | "version" -> + T_VERSION + | "see" -> + T_SEE + | "since" -> + T_SINCE + | "deprecated" -> + T_DEPRECATED + | "raise" -> + T_RAISES + | "return" -> + T_RETURN + | s -> + if !Odoc_args.no_custom_tags then + raise (Failure (Odoc_messages.not_a_valid_tag s)) + else + T_CUSTOM s + } | ("\\@" | [^'@'])+ { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - let s = Lexing.lexeme lexbuf in - let s2 = remove_blanks s in - print_DEBUG2 ("Desc "^s2); - Desc s2 - } + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + let s = Lexing.lexeme lexbuf in + let s2 = remove_blanks s in + print_DEBUG2 ("Desc "^s2); + Desc s2 + } | eof { - EOF - } + EOF + } and simple = parse [' ' '\013' '\009' '\012'] + { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - simple lexbuf + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + simple lexbuf } | [ '\010' ] { incr line_number; - incr Odoc_comments_global.nb_chars; + incr Odoc_comments_global.nb_chars; simple lexbuf } | "(**"("*"+) { - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); - incr comments_level; - simple lexbuf - } + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + incr comments_level; + simple lexbuf + } | "(*"("*"+)")" { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - simple lexbuf - } + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + simple lexbuf + } | "(**" { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - incr comments_level; - simple lexbuf - } + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + incr comments_level; + simple lexbuf + } | "(*" { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - incr comments_level; - if !comments_level = 1 then - ( - reset_string_buffer (); - description := ""; - special_comment lexbuf - ) - else - ( - ajout_string s; - simple lexbuf - ) + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + incr comments_level; + if !comments_level = 1 then + ( + reset_string_buffer (); + description := ""; + special_comment lexbuf + ) + else + ( + ajout_string s; + simple lexbuf + ) } | eof @@ -393,15 +393,15 @@ and simple = parse | "*)" { - let s = Lexing.lexeme lexbuf in - Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); - decr comments_level ; - simple lexbuf - } + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + decr comments_level ; + simple lexbuf + } | _ { - incr Odoc_comments_global.nb_chars; - simple lexbuf + incr Odoc_comments_global.nb_chars; + simple lexbuf } diff --git a/ocamldoc/odoc_man.ml b/ocamldoc/odoc_man.ml index 51d717145..a332e1c96 100644 --- a/ocamldoc/odoc_man.ml +++ b/ocamldoc/odoc_man.ml @@ -35,106 +35,106 @@ class virtual info = (** Groff string for an author list. *) method man_of_author_list l = match l with - [] -> - "" + [] -> + "" | _ -> - ".B \""^Odoc_messages.authors^"\"\n:\n"^ - (String.concat ", " l)^ - "\n.sp\n" + ".B \""^Odoc_messages.authors^"\"\n:\n"^ + (String.concat ", " l)^ + "\n.sp\n" (** Groff string for the given optional version information.*) method man_of_version_opt v_opt = match v_opt with - None -> "" + None -> "" | Some v -> ".B \""^Odoc_messages.version^"\"\n:\n"^v^"\n.sp\n" (** Groff string for the given optional since information.*) method man_of_since_opt s_opt = match s_opt with - None -> "" + None -> "" | Some s -> ".B \""^Odoc_messages.since^"\"\n"^s^"\n.sp\n" (** Groff string for the given list of raised exceptions.*) method man_of_raised_exceptions l = match l with - [] -> "" + [] -> "" | (s, t) :: [] -> ".B \""^Odoc_messages.raises^" "^s^"\"\n"^(self#man_of_text t)^"\n.sp\n" | _ -> - ".B \""^Odoc_messages.raises^"\"\n"^ - (String.concat "" - (List.map - (fun (ex, desc) -> ".TP\n.B \""^ex^"\"\n"^(self#man_of_text desc)^"\n") - l - ) - )^"\n.sp\n" + ".B \""^Odoc_messages.raises^"\"\n"^ + (String.concat "" + (List.map + (fun (ex, desc) -> ".TP\n.B \""^ex^"\"\n"^(self#man_of_text desc)^"\n") + l + ) + )^"\n.sp\n" (** Groff string for the given "see also" reference. *) method man_of_see (see_ref, t) = let t_ref = - match see_ref with - Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] - | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t - | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t + match see_ref with + Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] + | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t + | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t in self#man_of_text t_ref (** Groff string for the given list of "see also" references.*) method man_of_sees l = match l with - [] -> "" + [] -> "" | see :: [] -> ".B \""^Odoc_messages.see_also^"\"\n"^(self#man_of_see see)^"\n.sp\n" | _ -> - ".B \""^Odoc_messages.see_also^"\"\n"^ - (String.concat "" - (List.map - (fun see -> ".TP\n \"\"\n"^(self#man_of_see see)^"\n") - l - ) - )^"\n.sp\n" + ".B \""^Odoc_messages.see_also^"\"\n"^ + (String.concat "" + (List.map + (fun see -> ".TP\n \"\"\n"^(self#man_of_see see)^"\n") + l + ) + )^"\n.sp\n" (** Groff string for the given optional return information.*) method man_of_return_opt return_opt = match return_opt with - None -> "" + None -> "" | Some s -> ".B "^Odoc_messages.returns^"\n"^(self#man_of_text s)^"\n.sp\n" (** Return man code for the given list of custom tagged texts. *) method man_of_custom l = let buf = Buffer.create 50 in List.iter - (fun (tag, text) -> - try - let f = List.assoc tag tag_functions in - Buffer.add_string buf (f text) - with - Not_found -> - Odoc_info.warning (Odoc_messages.tag_not_handled tag) - ) - l; + (fun (tag, text) -> + try + let f = List.assoc tag tag_functions in + Buffer.add_string buf (f text) + with + Not_found -> + Odoc_info.warning (Odoc_messages.tag_not_handled tag) + ) + l; Buffer.contents buf (** Return the groff string to display an optional info structure. *) method man_of_info info_opt = - match info_opt with - None -> - "" + match info_opt with + None -> + "" | Some info -> - let module M = Odoc_info in - (match info.M.i_deprecated with - None -> "" - | Some d -> ".B \""^Odoc_messages.deprecated^"\"\n"^(self#man_of_text d)^"\n.sp\n")^ - (match info.M.i_desc with - None -> "" - | Some d when d = [Odoc_info.Raw ""] -> "" - | Some d -> (self#man_of_text d)^"\n.sp\n" - )^ - (self#man_of_author_list info.M.i_authors)^ - (self#man_of_version_opt info.M.i_version)^ - (self#man_of_since_opt info.M.i_since)^ - (self#man_of_raised_exceptions info.M.i_raised_exceptions)^ - (self#man_of_return_opt info.M.i_return_value)^ - (self#man_of_sees info.M.i_sees)^ - (self#man_of_custom info.M.i_custom) + let module M = Odoc_info in + (match info.M.i_deprecated with + None -> "" + | Some d -> ".B \""^Odoc_messages.deprecated^"\"\n"^(self#man_of_text d)^"\n.sp\n")^ + (match info.M.i_desc with + None -> "" + | Some d when d = [Odoc_info.Raw ""] -> "" + | Some d -> (self#man_of_text d)^"\n.sp\n" + )^ + (self#man_of_author_list info.M.i_authors)^ + (self#man_of_version_opt info.M.i_version)^ + (self#man_of_since_opt info.M.i_since)^ + (self#man_of_raised_exceptions info.M.i_raised_exceptions)^ + (self#man_of_return_opt info.M.i_return_value)^ + (self#man_of_sees info.M.i_sees)^ + (self#man_of_custom info.M.i_custom) end (** This class is used to create objects which can generate a simple html documentation. *) @@ -168,52 +168,52 @@ class man = (** Return the groff string for a text element. *) method man_of_text_element te = match te with - | Odoc_info.Raw s -> s - | Odoc_info.Code s -> - let s2 = "\n.B "^(Str.global_replace (Str.regexp "\n") "\n.B " (self#escape s))^"\n" in - s2 - | Odoc_info.CodePre s -> - let s2 = "\n.B "^(Str.global_replace (Str.regexp "\n") "\n.B " (self#escape s))^"\n" in - s2 - | Odoc_info.Verbatim s -> self#escape s - | Odoc_info.Bold t - | Odoc_info.Italic t - | Odoc_info.Emphasize t - | Odoc_info.Center t - | Odoc_info.Left t - | Odoc_info.Right t -> self#man_of_text2 t - | Odoc_info.List tl -> - (String.concat "" - (List.map - (fun t -> ".TP\n \"\"\n"^(self#man_of_text2 t)^"\n") - tl - ) - )^"\n" - | Odoc_info.Enum tl -> - (String.concat "" - (List.map - (fun t -> ".TP\n \"\"\n"^(self#man_of_text2 t)^"\n") - tl - ) - )^"\n" - | Odoc_info.Newline -> - "\n.sp\n" - | Odoc_info.Block t -> - "\n.sp\n"^(self#man_of_text2 t)^"\n.sp\n" - | Odoc_info.Title (n, l_opt, t) -> - self#man_of_text2 [Odoc_info.Code (Odoc_info.string_of_text t)] - | Odoc_info.Latex _ -> - (* don't care about LaTeX stuff in HTML. *) - "" - | Odoc_info.Link (s, t) -> - self#man_of_text2 t - | Odoc_info.Ref (name, _) -> - self#man_of_text_element - (Odoc_info.Code (Odoc_info.use_hidden_modules name)) - | Odoc_info.Superscript t -> - "^{"^(self#man_of_text2 t) - | Odoc_info.Subscript t -> - "_{"^(self#man_of_text2 t) + | Odoc_info.Raw s -> s + | Odoc_info.Code s -> + let s2 = "\n.B "^(Str.global_replace (Str.regexp "\n") "\n.B " (self#escape s))^"\n" in + s2 + | Odoc_info.CodePre s -> + let s2 = "\n.B "^(Str.global_replace (Str.regexp "\n") "\n.B " (self#escape s))^"\n" in + s2 + | Odoc_info.Verbatim s -> self#escape s + | Odoc_info.Bold t + | Odoc_info.Italic t + | Odoc_info.Emphasize t + | Odoc_info.Center t + | Odoc_info.Left t + | Odoc_info.Right t -> self#man_of_text2 t + | Odoc_info.List tl -> + (String.concat "" + (List.map + (fun t -> ".TP\n \"\"\n"^(self#man_of_text2 t)^"\n") + tl + ) + )^"\n" + | Odoc_info.Enum tl -> + (String.concat "" + (List.map + (fun t -> ".TP\n \"\"\n"^(self#man_of_text2 t)^"\n") + tl + ) + )^"\n" + | Odoc_info.Newline -> + "\n.sp\n" + | Odoc_info.Block t -> + "\n.sp\n"^(self#man_of_text2 t)^"\n.sp\n" + | Odoc_info.Title (n, l_opt, t) -> + self#man_of_text2 [Odoc_info.Code (Odoc_info.string_of_text t)] + | Odoc_info.Latex _ -> + (* don't care about LaTeX stuff in HTML. *) + "" + | Odoc_info.Link (s, t) -> + self#man_of_text2 t + | Odoc_info.Ref (name, _) -> + self#man_of_text_element + (Odoc_info.Code (Odoc_info.use_hidden_modules name)) + | Odoc_info.Superscript t -> + "^{"^(self#man_of_text2 t) + | Odoc_info.Subscript t -> + "_{"^(self#man_of_text2 t) (** Groff string to display code. *) method man_of_code s = self#man_of_text [ Code s ] @@ -222,23 +222,23 @@ class man = have been replaced by idents relative to the given module name.*) method relative_idents m_name s = let f str_t = - let match_s = Str.matched_string str_t in - Odoc_info.apply_if_equal - Odoc_info.use_hidden_modules - match_s - (Name.get_relative m_name match_s) + let match_s = Str.matched_string str_t in + Odoc_info.apply_if_equal + Odoc_info.use_hidden_modules + match_s + (Name.get_relative m_name match_s) in let s2 = Str.global_substitute - (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") - f - s + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") + f + s in s2 (** Groff string to display a [Types.type_expr].*) method man_of_type_expr m_name t = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_misc.string_of_type_expr t)) + (Str.split (Str.regexp "\n") (Odoc_misc.string_of_type_expr t)) in let s2 = Str.global_replace (Str.regexp "\n") "\n.B " s in "\n.B "^(self#relative_idents m_name s2)^"\n" @@ -246,7 +246,7 @@ class man = (** Groff string to display a [Types.class_type].*) method man_of_class_type_expr m_name t = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_misc.string_of_class_type t)) + (Str.split (Str.regexp "\n") (Odoc_misc.string_of_class_type t)) in let s2 = Str.global_replace (Str.regexp "\n") "\n.B " s in "\n.B "^(self#relative_idents m_name s2)^"\n" @@ -260,7 +260,7 @@ class man = (** Groff string to display a [Types.module_type]. *) method man_of_module_type m_name t = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_misc.string_of_module_type t)) + (Str.split (Str.regexp "\n") (Odoc_misc.string_of_module_type t)) in let s2 = Str.global_replace (Str.regexp "\n") "\n.B " s in "\n.B "^(self#relative_idents m_name s2)^"\n" @@ -279,19 +279,19 @@ class man = Odoc_info.reset_type_names () ; "\n.I exception "^(Name.simple e.ex_name)^" \n"^ (match e.ex_args with - [] -> "" - | _ -> - ".B of "^ - (self#man_of_type_expr_list (Name.father e.ex_name) " * " e.ex_args) + [] -> "" + | _ -> + ".B of "^ + (self#man_of_type_expr_list (Name.father e.ex_name) " * " e.ex_args) )^ (match e.ex_alias with - None -> "" + None -> "" | Some ea -> " = "^ - ( - match ea.ea_ex with - None -> ea.ea_name - | Some e -> e.ex_name - ) + ( + match ea.ea_ex with + None -> ea.ea_name + | Some e -> e.ex_name + ) )^ "\n.sp\n"^ (self#man_of_info e.ex_info)^ @@ -303,54 +303,54 @@ class man = let father = Name.father t.ty_name in ".I type "^ (match t.ty_parameters with - [] -> "" - | tp :: [] -> (Odoc_misc.string_of_type_expr tp) - | l -> - (self#man_of_type_expr_list father ", " l) + [] -> "" + | tp :: [] -> (Odoc_misc.string_of_type_expr tp) + | l -> + (self#man_of_type_expr_list father ", " l) )^ (match t.ty_parameters with [] -> "" | _ -> ".I ")^(Name.simple t.ty_name)^" \n"^ (match t.ty_manifest with None -> "" | Some typ -> "= "^(self#man_of_type_expr father typ))^ (match t.ty_kind with - Type_abstract -> - "" - | Type_variant l -> - "=\n "^ - (String.concat "" - (List.map - (fun constr -> - "| "^constr.vc_name^ - (match constr.vc_args, constr.vc_text with - [], None -> "\n " - | [], (Some t) -> " (* "^(self#man_of_text t)^" *)\n " - | l, None -> - "\n.B of "^(self#man_of_type_expr_list father " * " l)^" " - | l, (Some t) -> - "\n.B of "^(self#man_of_type_expr_list father " * " l)^ - ".I \" \"\n"^ - "(* "^(self#man_of_text t)^" *)\n " - ) - ) - l - ) - ) - | Type_record l -> - "= {"^ - (String.concat "" - (List.map - (fun r -> - (if r.rf_mutable then "\n\n.B mutable \n" else "\n ")^ - r.rf_name^" : "^(self#man_of_type_expr father r.rf_type)^";"^ - (match r.rf_text with - None -> - "" - | Some t -> - " (* "^(self#man_of_text t)^" *) " - )^"" - ) - l - ) - )^ - "\n }\n" + Type_abstract -> + "" + | Type_variant l -> + "=\n "^ + (String.concat "" + (List.map + (fun constr -> + "| "^constr.vc_name^ + (match constr.vc_args, constr.vc_text with + [], None -> "\n " + | [], (Some t) -> " (* "^(self#man_of_text t)^" *)\n " + | l, None -> + "\n.B of "^(self#man_of_type_expr_list father " * " l)^" " + | l, (Some t) -> + "\n.B of "^(self#man_of_type_expr_list father " * " l)^ + ".I \" \"\n"^ + "(* "^(self#man_of_text t)^" *)\n " + ) + ) + l + ) + ) + | Type_record l -> + "= {"^ + (String.concat "" + (List.map + (fun r -> + (if r.rf_mutable then "\n\n.B mutable \n" else "\n ")^ + r.rf_name^" : "^(self#man_of_type_expr father r.rf_type)^";"^ + (match r.rf_text with + None -> + "" + | Some t -> + " (* "^(self#man_of_text t)^" *) " + )^"" + ) + l + ) + )^ + "\n }\n" )^ "\n.sp\n"^(self#man_of_info t.ty_info)^ "\n.sp\n" @@ -377,67 +377,67 @@ class man = (** Groff for a list of parameters. *) method man_of_parameter_list m_name l = match l with - [] -> - "" + [] -> + "" | _ -> - "\n.B "^Odoc_messages.parameters^": \n"^ - (String.concat "" - (List.map - (fun p -> - ".TP\n"^ - "\""^(Parameter.complete_name p)^"\"\n"^ - (self#man_of_type_expr m_name (Parameter.typ p))^"\n"^ - (self#man_of_parameter_description p)^"\n" - ) - l - ) - )^"\n" + "\n.B "^Odoc_messages.parameters^": \n"^ + (String.concat "" + (List.map + (fun p -> + ".TP\n"^ + "\""^(Parameter.complete_name p)^"\"\n"^ + (self#man_of_type_expr m_name (Parameter.typ p))^"\n"^ + (self#man_of_parameter_description p)^"\n" + ) + l + ) + )^"\n" (** Groff for the description of a function parameter. *) method man_of_parameter_description p = match Parameter.names p with - [] -> - "" + [] -> + "" | name :: [] -> - ( + ( (* Only one name, no need for label for the description. *) - match Parameter.desc_by_name p name with - None -> "" - | Some t -> "\n "^(self#man_of_text t) - ) + match Parameter.desc_by_name p name with + None -> "" + | Some t -> "\n "^(self#man_of_text t) + ) | l -> (* A list of names, we display those with a description. *) - String.concat "" - (List.map - (fun n -> - match Parameter.desc_by_name p n with - None -> "" - | Some t -> (self#man_of_code (n^" : "))^(self#man_of_text t) - ) - l - ) + String.concat "" + (List.map + (fun n -> + match Parameter.desc_by_name p n with + None -> "" + | Some t -> (self#man_of_code (n^" : "))^(self#man_of_text t) + ) + l + ) (** Groff string for a list of module parameters. *) method man_of_module_parameter_list m_name l = match l with - [] -> - "" + [] -> + "" | _ -> - ".B \""^Odoc_messages.parameters^":\"\n"^ - (String.concat "" - (List.map - (fun (p, desc_opt) -> - ".TP\n"^ - "\""^p.mp_name^"\"\n"^ - (self#man_of_module_type m_name p.mp_type)^"\n"^ - (match desc_opt with - None -> "" - | Some t -> self#man_of_text t)^ - "\n" - ) - l - ) - )^"\n\n" + ".B \""^Odoc_messages.parameters^":\"\n"^ + (String.concat "" + (List.map + (fun (p, desc_opt) -> + ".TP\n"^ + "\""^p.mp_name^"\"\n"^ + (self#man_of_module_type m_name p.mp_type)^"\n"^ + (match desc_opt with + None -> "" + | Some t -> self#man_of_text t)^ + "\n" + ) + l + ) + )^"\n\n" (** Groff string for a class. *) method man_of_class c = @@ -446,15 +446,15 @@ class man = Odoc_info.reset_type_names () ; let father = Name.father c.cl_name in p buf ".I class %s" - (if c.cl_virtual then "virtual " else ""); + (if c.cl_virtual then "virtual " else ""); ( match c.cl_type_parameters with - [] -> () + [] -> () | l -> p buf "[%s.I] " (Odoc_misc.string_of_type_list ", " l) ); p buf "%s : %s" - (Name.simple c.cl_name) - (self#man_of_class_type_expr (Name.father c.cl_name) c.cl_type); + (Name.simple c.cl_name) + (self#man_of_class_type_expr (Name.father c.cl_name) c.cl_type); p buf "\n.sp\n%s\n.sp\n" (self#man_of_info c.cl_info); Buffer.contents buf @@ -464,15 +464,15 @@ class man = let p = Printf.bprintf in Odoc_info.reset_type_names () ; p buf ".I class type %s" - (if ct.clt_virtual then "virtual " else ""); + (if ct.clt_virtual then "virtual " else ""); ( match ct.clt_type_parameters with - [] -> () - | l -> p buf "[%s.I ] " (Odoc_misc.string_of_type_list ", " l) + [] -> () + | l -> p buf "[%s.I ] " (Odoc_misc.string_of_type_list ", " l) ); p buf "%s = %s" - (Name.simple ct.clt_name) - (self#man_of_class_type_expr (Name.father ct.clt_name) ct.clt_type); + (Name.simple ct.clt_name) + (self#man_of_class_type_expr (Name.father ct.clt_name) ct.clt_type); p buf "\n.sp\n%s\n.sp\n" (self#man_of_info ct.clt_info); Buffer.contents buf @@ -487,7 +487,7 @@ class man = ".I module type "^(Name.simple mt.mt_name)^ " = "^ (match mt.mt_type with - None -> "" + None -> "" | Some t -> self#man_of_module_type (Name.father mt.mt_name) t )^ "\n.sp\n"^(self#man_of_info mt.mt_info)^"\n.sp\n" @@ -509,14 +509,14 @@ class man = ".I include "^ ( match im.im_module with - None -> im.im_name + None -> im.im_name | Some mmt -> - let name = - match mmt with - Mod m -> m.m_name - | Modtype mt -> mt.mt_name - in - self#relative_idents m_name name + let name = + match mmt with + Mod m -> m.m_name + | Modtype mt -> mt.mt_name + in + self#relative_idents m_name name )^ "\n.sp\n" @@ -526,51 +526,51 @@ class man = let date = Unix.time () in let file = self#file_name cl.cl_name in try - let chanout = self#open_out file in - output_string chanout - (".TH \""^Odoc_messages.clas^"\" "^ - cl.cl_name^" "^ - "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ - "OCamldoc "^ - "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); - - output_string chanout - ( - ".SH "^Odoc_messages.clas^"\n"^ - Odoc_messages.clas^" "^cl.cl_name^"\n"^ - ".SH "^Odoc_messages.documentation^"\n"^ - ".sp\n" - ); - output_string chanout (self#man_of_class cl); - - (* parameters *) - output_string chanout - (self#man_of_parameter_list "" cl.cl_parameters); - (* a large blank *) - output_string chanout "\n.sp\n.sp\n"; + let chanout = self#open_out file in + output_string chanout + (".TH \""^Odoc_messages.clas^"\" "^ + cl.cl_name^" "^ + "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ + "OCamldoc "^ + "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); + + output_string chanout + ( + ".SH "^Odoc_messages.clas^"\n"^ + Odoc_messages.clas^" "^cl.cl_name^"\n"^ + ".SH "^Odoc_messages.documentation^"\n"^ + ".sp\n" + ); + output_string chanout (self#man_of_class cl); + + (* parameters *) + output_string chanout + (self#man_of_parameter_list "" cl.cl_parameters); + (* a large blank *) + output_string chanout "\n.sp\n.sp\n"; (* (* class inheritance *) - self#generate_class_inheritance_info chanout cl; + self#generate_class_inheritance_info chanout cl; *) - (* the various elements *) - List.iter - (fun element -> - match element with - Class_attribute a -> - output_string chanout (self#man_of_attribute a) - | Class_method m -> - output_string chanout (self#man_of_method m) - | Class_comment t -> - output_string chanout (self#man_of_class_comment t) - ) - (Class.class_elements cl); - - close_out chanout + (* the various elements *) + List.iter + (fun element -> + match element with + Class_attribute a -> + output_string chanout (self#man_of_attribute a) + | Class_method m -> + output_string chanout (self#man_of_method m) + | Class_comment t -> + output_string chanout (self#man_of_class_comment t) + ) + (Class.class_elements cl); + + close_out chanout with - Sys_error s -> - incr Odoc_info.errors ; - prerr_endline s + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s (** Generate the man page for the given class type.*) method generate_for_class_type ct = @@ -578,47 +578,47 @@ class man = let date = Unix.time () in let file = self#file_name ct.clt_name in try - let chanout = self#open_out file in - output_string chanout - (".TH \""^Odoc_messages.class_type^"\" "^ - ct.clt_name^" "^ - "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ - "OCamldoc "^ - "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); - - output_string chanout - ( - ".SH "^Odoc_messages.class_type^"\n"^ - Odoc_messages.class_type^" "^ct.clt_name^"\n"^ - ".SH "^Odoc_messages.documentation^"\n"^ - ".sp\n" - ); - output_string chanout (self#man_of_class_type ct); - - (* a large blank *) - output_string chanout "\n.sp\n.sp\n"; + let chanout = self#open_out file in + output_string chanout + (".TH \""^Odoc_messages.class_type^"\" "^ + ct.clt_name^" "^ + "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ + "OCamldoc "^ + "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); + + output_string chanout + ( + ".SH "^Odoc_messages.class_type^"\n"^ + Odoc_messages.class_type^" "^ct.clt_name^"\n"^ + ".SH "^Odoc_messages.documentation^"\n"^ + ".sp\n" + ); + output_string chanout (self#man_of_class_type ct); + + (* a large blank *) + output_string chanout "\n.sp\n.sp\n"; (* (* class inheritance *) - self#generate_class_inheritance_info chanout cl; + self#generate_class_inheritance_info chanout cl; *) - (* the various elements *) - List.iter - (fun element -> - match element with - Class_attribute a -> - output_string chanout (self#man_of_attribute a) - | Class_method m -> - output_string chanout (self#man_of_method m) - | Class_comment t -> - output_string chanout (self#man_of_class_comment t) - ) - (Class.class_type_elements ct); - - close_out chanout + (* the various elements *) + List.iter + (fun element -> + match element with + Class_attribute a -> + output_string chanout (self#man_of_attribute a) + | Class_method m -> + output_string chanout (self#man_of_method m) + | Class_comment t -> + output_string chanout (self#man_of_class_comment t) + ) + (Class.class_type_elements ct); + + close_out chanout with - Sys_error s -> - incr Odoc_info.errors ; - prerr_endline s + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s (** Generate the man file for the given module type. @raise Failure if an error occurs.*) @@ -626,69 +626,69 @@ class man = let date = Unix.time () in let file = self#file_name mt.mt_name in try - let chanout = self#open_out file in - output_string chanout - (".TH \""^Odoc_messages.module_type^"\" "^ - mt.mt_name^" "^ - "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ - "OCamldoc "^ - "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); - - output_string chanout - ( - ".SH "^Odoc_messages.module_type^"\n"^ - Odoc_messages.module_type^" "^mt.mt_name^"\n"^ - ".SH "^Odoc_messages.documentation^"\n"^ - ".sp\n"^ - Odoc_messages.module_type^"\n"^ - ".BI \""^(Name.simple mt.mt_name)^"\"\n"^ - " = "^ - (match mt.mt_type with - None -> "" - | Some t -> self#man_of_module_type (Name.father mt.mt_name) t - )^ - "\n.sp\n"^ - (self#man_of_info mt.mt_info)^"\n"^ - ".sp\n" - ); - - (* parameters for functors *) - output_string chanout - (self#man_of_module_parameter_list "" (Module.module_type_parameters mt)); - (* a large blank *) - output_string chanout "\n.sp\n.sp\n"; - - (* module elements *) - List.iter - (fun ele -> - match ele with - Element_module m -> - output_string chanout (self#man_of_module m) - | Element_module_type mt -> - output_string chanout (self#man_of_modtype mt) - | Element_included_module im -> - output_string chanout (self#man_of_included_module mt.mt_name im) - | Element_class c -> - output_string chanout (self#man_of_class c) - | Element_class_type ct -> - output_string chanout (self#man_of_class_type ct) - | Element_value v -> - output_string chanout (self#man_of_value v) - | Element_exception e -> - output_string chanout (self#man_of_exception e) - | Element_type t -> - output_string chanout (self#man_of_type t) - | Element_module_comment text -> - output_string chanout (self#man_of_module_comment text) - ) - (Module.module_type_elements mt); - - close_out chanout + let chanout = self#open_out file in + output_string chanout + (".TH \""^Odoc_messages.module_type^"\" "^ + mt.mt_name^" "^ + "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ + "OCamldoc "^ + "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); + + output_string chanout + ( + ".SH "^Odoc_messages.module_type^"\n"^ + Odoc_messages.module_type^" "^mt.mt_name^"\n"^ + ".SH "^Odoc_messages.documentation^"\n"^ + ".sp\n"^ + Odoc_messages.module_type^"\n"^ + ".BI \""^(Name.simple mt.mt_name)^"\"\n"^ + " = "^ + (match mt.mt_type with + None -> "" + | Some t -> self#man_of_module_type (Name.father mt.mt_name) t + )^ + "\n.sp\n"^ + (self#man_of_info mt.mt_info)^"\n"^ + ".sp\n" + ); + + (* parameters for functors *) + output_string chanout + (self#man_of_module_parameter_list "" (Module.module_type_parameters mt)); + (* a large blank *) + output_string chanout "\n.sp\n.sp\n"; + + (* module elements *) + List.iter + (fun ele -> + match ele with + Element_module m -> + output_string chanout (self#man_of_module m) + | Element_module_type mt -> + output_string chanout (self#man_of_modtype mt) + | Element_included_module im -> + output_string chanout (self#man_of_included_module mt.mt_name im) + | Element_class c -> + output_string chanout (self#man_of_class c) + | Element_class_type ct -> + output_string chanout (self#man_of_class_type ct) + | Element_value v -> + output_string chanout (self#man_of_value v) + | Element_exception e -> + output_string chanout (self#man_of_exception e) + | Element_type t -> + output_string chanout (self#man_of_type t) + | Element_module_comment text -> + output_string chanout (self#man_of_module_comment text) + ) + (Module.module_type_elements mt); + + close_out chanout with - Sys_error s -> - incr Odoc_info.errors ; - prerr_endline s + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s (** Generate the man file for the given module. @raise Failure if an error occurs.*) @@ -696,100 +696,100 @@ class man = let date = Unix.time () in let file = self#file_name m.m_name in try - let chanout = self#open_out file in - output_string chanout - (".TH \""^Odoc_messages.modul^"\" "^ - m.m_name^" "^ - "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ - "OCamldoc "^ - "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); - - output_string chanout - ( - ".SH "^Odoc_messages.modul^"\n"^ - Odoc_messages.modul^" "^m.m_name^"\n"^ - ".SH "^Odoc_messages.documentation^"\n"^ - ".sp\n"^ - Odoc_messages.modul^"\n"^ - ".BI \""^(Name.simple m.m_name)^"\"\n"^ - " : "^(self#man_of_module_type (Name.father m.m_name) m.m_type)^ - "\n.sp\n"^ - (self#man_of_info m.m_info)^"\n"^ - ".sp\n" - ); - - (* parameters for functors *) - output_string chanout - (self#man_of_module_parameter_list "" (Module.module_parameters m)); - (* a large blank *) - output_string chanout "\n.sp\n.sp\n"; - - (* module elements *) - List.iter - (fun ele -> - match ele with - Element_module m -> - output_string chanout (self#man_of_module m) - | Element_module_type mt -> - output_string chanout (self#man_of_modtype mt) - | Element_included_module im -> - output_string chanout (self#man_of_included_module m.m_name im) - | Element_class c -> - output_string chanout (self#man_of_class c) - | Element_class_type ct -> - output_string chanout (self#man_of_class_type ct) - | Element_value v -> - output_string chanout (self#man_of_value v) - | Element_exception e -> - output_string chanout (self#man_of_exception e) - | Element_type t -> - output_string chanout (self#man_of_type t) - | Element_module_comment text -> - output_string chanout (self#man_of_module_comment text) - ) - (Module.module_elements m); - - close_out chanout + let chanout = self#open_out file in + output_string chanout + (".TH \""^Odoc_messages.modul^"\" "^ + m.m_name^" "^ + "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ + "OCamldoc "^ + "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); + + output_string chanout + ( + ".SH "^Odoc_messages.modul^"\n"^ + Odoc_messages.modul^" "^m.m_name^"\n"^ + ".SH "^Odoc_messages.documentation^"\n"^ + ".sp\n"^ + Odoc_messages.modul^"\n"^ + ".BI \""^(Name.simple m.m_name)^"\"\n"^ + " : "^(self#man_of_module_type (Name.father m.m_name) m.m_type)^ + "\n.sp\n"^ + (self#man_of_info m.m_info)^"\n"^ + ".sp\n" + ); + + (* parameters for functors *) + output_string chanout + (self#man_of_module_parameter_list "" (Module.module_parameters m)); + (* a large blank *) + output_string chanout "\n.sp\n.sp\n"; + + (* module elements *) + List.iter + (fun ele -> + match ele with + Element_module m -> + output_string chanout (self#man_of_module m) + | Element_module_type mt -> + output_string chanout (self#man_of_modtype mt) + | Element_included_module im -> + output_string chanout (self#man_of_included_module m.m_name im) + | Element_class c -> + output_string chanout (self#man_of_class c) + | Element_class_type ct -> + output_string chanout (self#man_of_class_type ct) + | Element_value v -> + output_string chanout (self#man_of_value v) + | Element_exception e -> + output_string chanout (self#man_of_exception e) + | Element_type t -> + output_string chanout (self#man_of_type t) + | Element_module_comment text -> + output_string chanout (self#man_of_module_comment text) + ) + (Module.module_elements m); + + close_out chanout with - Sys_error s -> - raise (Failure s) + Sys_error s -> + raise (Failure s) (** Create the groups of elements to generate pages for. *) method create_groups module_list = let name res_ele = - match res_ele with - Res_module m -> m.m_name - | Res_module_type mt -> mt.mt_name - | Res_class c -> c.cl_name - | Res_class_type ct -> ct.clt_name - | Res_value v -> Name.simple v.val_name - | Res_type t -> Name.simple t.ty_name - | Res_exception e -> Name.simple e.ex_name - | Res_attribute a -> Name.simple a.att_value.val_name - | Res_method m -> Name.simple m.met_value.val_name - | Res_section s -> assert false + match res_ele with + Res_module m -> m.m_name + | Res_module_type mt -> mt.mt_name + | Res_class c -> c.cl_name + | Res_class_type ct -> ct.clt_name + | Res_value v -> Name.simple v.val_name + | Res_type t -> Name.simple t.ty_name + | Res_exception e -> Name.simple e.ex_name + | Res_attribute a -> Name.simple a.att_value.val_name + | Res_method m -> Name.simple m.met_value.val_name + | Res_section s -> assert false in let all_items_pre = Odoc_info.Search.search_by_name module_list (Str.regexp ".*") in let all_items = List.filter - (fun r -> match r with Res_section _ -> false | _ -> true) - all_items_pre + (fun r -> match r with Res_section _ -> false | _ -> true) + all_items_pre in let sorted_items = List.sort (fun e1 -> fun e2 -> compare (name e1) (name e2)) all_items in let rec f acc1 acc2 l = - match l with - [] -> acc2 :: acc1 - | h :: q -> - match acc2 with - [] -> f acc1 [h] q - | h2 :: q2 -> - if (name h) = (name h2) then - if List.mem h acc2 then - f acc1 acc2 q - else - f acc1 (acc2 @ [h]) q - else - f (acc2 :: acc1) [h] q + match l with + [] -> acc2 :: acc1 + | h :: q -> + match acc2 with + [] -> f acc1 [h] q + | h2 :: q2 -> + if (name h) = (name h2) then + if List.mem h acc2 then + f acc1 acc2 q + else + f acc1 (acc2 @ [h]) q + else + f (acc2 :: acc1) [h] q in f [] [] sorted_items @@ -798,89 +798,89 @@ class man = method generate_for_group l = let name = Name.simple - ( - match List.hd l with - Res_module m -> m.m_name - | Res_module_type mt -> mt.mt_name - | Res_class c -> c.cl_name - | Res_class_type ct -> ct.clt_name - | Res_value v -> v.val_name - | Res_type t -> t.ty_name - | Res_exception e -> e.ex_name - | Res_attribute a -> a.att_value.val_name - | Res_method m -> m.met_value.val_name - | Res_section s -> s - ) + ( + match List.hd l with + Res_module m -> m.m_name + | Res_module_type mt -> mt.mt_name + | Res_class c -> c.cl_name + | Res_class_type ct -> ct.clt_name + | Res_value v -> v.val_name + | Res_type t -> t.ty_name + | Res_exception e -> e.ex_name + | Res_attribute a -> a.att_value.val_name + | Res_method m -> m.met_value.val_name + | Res_section s -> s + ) in let date = Unix.time () in let file = self#file_name name in try - let chanout = self#open_out file in - output_string chanout - (".TH \""^name^"\" "^ - "man "^ - "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ - "OCamldoc "^ - "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); - - let f ele = - match ele with - Res_value v -> - output_string chanout - ("\n.SH "^Odoc_messages.modul^" "^(Name.father v.val_name)^"\n"^ - (self#man_of_value v)) - | Res_type t -> - output_string chanout - ("\n.SH "^Odoc_messages.modul^" "^(Name.father t.ty_name)^"\n"^ - (self#man_of_type t)) - | Res_exception e -> - output_string chanout - ("\n.SH "^Odoc_messages.modul^" "^(Name.father e.ex_name)^"\n"^ - (self#man_of_exception e)) - | Res_attribute a -> - output_string chanout - ("\n.SH "^Odoc_messages.clas^" "^(Name.father a.att_value.val_name)^"\n"^ - (self#man_of_attribute a)) - | Res_method m -> - output_string chanout - ("\n.SH "^Odoc_messages.clas^" "^(Name.father m.met_value.val_name)^"\n"^ - (self#man_of_method m)) - | Res_class c -> - output_string chanout - ("\n.SH "^Odoc_messages.modul^" "^(Name.father c.cl_name)^"\n"^ - (self#man_of_class c)) - | Res_class_type ct -> - output_string chanout - ("\n.SH "^Odoc_messages.modul^" "^(Name.father ct.clt_name)^"\n"^ - (self#man_of_class_type ct)) - | _ -> - (* normalement on ne peut pas avoir de module ici. *) - () - in - List.iter f l; - close_out chanout + let chanout = self#open_out file in + output_string chanout + (".TH \""^name^"\" "^ + "man "^ + "\""^(Odoc_misc.string_of_date ~hour: false date)^"\" "^ + "OCamldoc "^ + "\""^(match !Odoc_args.title with Some t -> t | None -> "")^"\"\n"); + + let f ele = + match ele with + Res_value v -> + output_string chanout + ("\n.SH "^Odoc_messages.modul^" "^(Name.father v.val_name)^"\n"^ + (self#man_of_value v)) + | Res_type t -> + output_string chanout + ("\n.SH "^Odoc_messages.modul^" "^(Name.father t.ty_name)^"\n"^ + (self#man_of_type t)) + | Res_exception e -> + output_string chanout + ("\n.SH "^Odoc_messages.modul^" "^(Name.father e.ex_name)^"\n"^ + (self#man_of_exception e)) + | Res_attribute a -> + output_string chanout + ("\n.SH "^Odoc_messages.clas^" "^(Name.father a.att_value.val_name)^"\n"^ + (self#man_of_attribute a)) + | Res_method m -> + output_string chanout + ("\n.SH "^Odoc_messages.clas^" "^(Name.father m.met_value.val_name)^"\n"^ + (self#man_of_method m)) + | Res_class c -> + output_string chanout + ("\n.SH "^Odoc_messages.modul^" "^(Name.father c.cl_name)^"\n"^ + (self#man_of_class c)) + | Res_class_type ct -> + output_string chanout + ("\n.SH "^Odoc_messages.modul^" "^(Name.father ct.clt_name)^"\n"^ + (self#man_of_class_type ct)) + | _ -> + (* normalement on ne peut pas avoir de module ici. *) + () + in + List.iter f l; + close_out chanout with - Sys_error s -> - incr Odoc_info.errors ; - prerr_endline s + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s (** Generate all the man pages from a module list. *) method generate module_list = let sorted_module_list = Sort.list (fun m1 -> fun m2 -> m1.m_name < m2.m_name) module_list in let groups = self#create_groups sorted_module_list in let f group = - match group with - [] -> - () - | [Res_module m] -> self#generate_for_module m - | [Res_module_type mt] -> self#generate_for_module_type mt - | [Res_class cl] -> self#generate_for_class cl - | [Res_class_type ct] -> self#generate_for_class_type ct - | l -> - if !Odoc_args.man_mini then - () - else - self#generate_for_group l + match group with + [] -> + () + | [Res_module m] -> self#generate_for_module m + | [Res_module_type mt] -> self#generate_for_module_type mt + | [Res_class cl] -> self#generate_for_class cl + | [Res_class_type ct] -> self#generate_for_class_type ct + | l -> + if !Odoc_args.man_mini then + () + else + self#generate_for_group l in List.iter f groups end diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml index d1b740221..1316fcbbc 100644 --- a/ocamldoc/odoc_merge.ml +++ b/ocamldoc/odoc_merge.ml @@ -33,10 +33,10 @@ let merge_info merge_options (m1 : info) (m2 : info) = | None, Some d | Some d, None -> Some d | Some d1, Some d2 -> - if List.mem Merge_description merge_options then - Some (d1 @ (Newline :: d2)) - else - Some d1 + if List.mem Merge_description merge_options then + Some (d1 @ (Newline :: d2)) + else + Some d1 in let new_authors = match m1.i_authors, m2.i_authors with @@ -44,10 +44,10 @@ let merge_info merge_options (m1 : info) (m2 : info) = | l, [] | [], l -> l | l1, l2 -> - if List.mem Merge_author merge_options then - l1 @ l2 - else - l1 + if List.mem Merge_author merge_options then + l1 @ l2 + else + l1 in let new_version = match m1.i_version , m2.i_version with @@ -55,10 +55,10 @@ let merge_info merge_options (m1 : info) (m2 : info) = | Some v, None | None, Some v -> Some v | Some v1, Some v2 -> - if List.mem Merge_version merge_options then - Some (v1^" "^v2) - else - Some v1 + if List.mem Merge_version merge_options then + Some (v1^" "^v2) + else + Some v1 in let new_sees = match m1.i_sees, m2.i_sees with @@ -66,10 +66,10 @@ let merge_info merge_options (m1 : info) (m2 : info) = | l, [] | [], l -> l | l1, l2 -> - if List.mem Merge_see merge_options then - l1 @ l2 - else - l1 + if List.mem Merge_see merge_options then + l1 @ l2 + else + l1 in let new_since = match m1.i_since, m2.i_since with @@ -77,10 +77,10 @@ let merge_info merge_options (m1 : info) (m2 : info) = | Some v, None | None, Some v -> Some v | Some v1, Some v2 -> - if List.mem Merge_since merge_options then - Some (v1^" "^v2) - else - Some v1 + if List.mem Merge_since merge_options then + Some (v1^" "^v2) + else + Some v1 in let new_dep = match m1.i_deprecated, m2.i_deprecated with @@ -88,10 +88,10 @@ let merge_info merge_options (m1 : info) (m2 : info) = | None, Some t | Some t, None -> Some t | Some t1, Some t2 -> - if List.mem Merge_deprecated merge_options then - Some (t1 @ (Newline :: t2)) - else - Some t1 + if List.mem Merge_deprecated merge_options then + Some (t1 @ (Newline :: t2)) + else + Some t1 in let new_params = match m1.i_params, m2.i_params with @@ -99,23 +99,23 @@ let merge_info merge_options (m1 : info) (m2 : info) = | l, [] | [], l -> l | l1, l2 -> - if List.mem Merge_param merge_options then - ( - let l_in_m1_and_m2, l_in_m2_only = List.partition - (fun (param2, _) -> List.mem_assoc param2 l1) - l2 - in - let rec iter = function - [] -> [] - | (param2, desc2) :: q -> - let desc1 = List.assoc param2 l1 in - (param2, desc1 @ (Newline :: desc2)) :: (iter q) - in - let l1_completed = iter l_in_m1_and_m2 in - l1_completed @ l_in_m2_only - ) - else - l1 + if List.mem Merge_param merge_options then + ( + let l_in_m1_and_m2, l_in_m2_only = List.partition + (fun (param2, _) -> List.mem_assoc param2 l1) + l2 + in + let rec iter = function + [] -> [] + | (param2, desc2) :: q -> + let desc1 = List.assoc param2 l1 in + (param2, desc1 @ (Newline :: desc2)) :: (iter q) + in + let l1_completed = iter l_in_m1_and_m2 in + l1_completed @ l_in_m2_only + ) + else + l1 in let new_raised_exceptions = match m1.i_raised_exceptions, m2.i_raised_exceptions with @@ -123,23 +123,23 @@ let merge_info merge_options (m1 : info) (m2 : info) = | l, [] | [], l -> l | l1, l2 -> - if List.mem Merge_raised_exception merge_options then - ( - let l_in_m1_and_m2, l_in_m2_only = List.partition - (fun (exc2, _) -> List.mem_assoc exc2 l1) - l2 - in - let rec iter = function - [] -> [] - | (exc2, desc2) :: q -> - let desc1 = List.assoc exc2 l1 in - (exc2, desc1 @ (Newline :: desc2)) :: (iter q) - in - let l1_completed = iter l_in_m1_and_m2 in - l1_completed @ l_in_m2_only - ) - else - l1 + if List.mem Merge_raised_exception merge_options then + ( + let l_in_m1_and_m2, l_in_m2_only = List.partition + (fun (exc2, _) -> List.mem_assoc exc2 l1) + l2 + in + let rec iter = function + [] -> [] + | (exc2, desc2) :: q -> + let desc1 = List.assoc exc2 l1 in + (exc2, desc1 @ (Newline :: desc2)) :: (iter q) + in + let l1_completed = iter l_in_m1_and_m2 in + l1_completed @ l_in_m2_only + ) + else + l1 in let new_rv = match m1.i_return_value, m2.i_return_value with @@ -147,10 +147,10 @@ let merge_info merge_options (m1 : info) (m2 : info) = | None, Some t | Some t, None -> Some t | Some t1, Some t2 -> - if List.mem Merge_return_value merge_options then - Some (t1 @ (Newline :: t2)) - else - Some t1 + if List.mem Merge_return_value merge_options then + Some (t1 @ (Newline :: t2)) + else + Some t1 in let new_custom = match m1.i_custom, m2.i_custom with @@ -158,10 +158,10 @@ let merge_info merge_options (m1 : info) (m2 : info) = | [], l | l, [] -> l | l1, l2 -> - if List.mem Merge_custom merge_options then - l1 @ l2 - else - l1 + if List.mem Merge_custom merge_options then + l1 @ l2 + else + l1 in { Odoc_types.i_desc = new_desc_opt ; @@ -195,65 +195,65 @@ let merge_types merge_options mli ml = | Type_variant l1, Type_variant l2 -> let f cons = - try - let cons2 = List.find - (fun c2 -> c2.vc_name = cons.vc_name) - l2 - in - let new_desc = - match cons.vc_text, cons2.vc_text with - None, None -> None - | Some d, None - | None, Some d -> Some d - | Some d1, Some d2 -> - if List.mem Merge_description merge_options 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)) + try + let cons2 = List.find + (fun c2 -> c2.vc_name = cons.vc_name) + l2 + in + let new_desc = + match cons.vc_text, cons2.vc_text with + None, None -> None + | Some d, None + | None, Some d -> Some d + | Some d1, Some d2 -> + if List.mem Merge_description merge_options 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)) in List.iter f l1 | Type_record l1, Type_record l2 -> let f record = - try - let record2= List.find - (fun r -> r.rf_name = record.rf_name) - l2 - in - let new_desc = - match record.rf_text, record2.rf_text with - None, None -> None - | Some d, None - | None, Some d -> Some d - | Some d1, Some d2 -> - if List.mem Merge_description merge_options 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)) + try + let record2= List.find + (fun r -> r.rf_name = record.rf_name) + l2 + in + let new_desc = + match record.rf_text, record2.rf_text with + None, None -> None + | Some d, None + | None, Some d -> Some d + | Some d1, Some d2 -> + if List.mem Merge_description merge_options 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)) in List.iter f l1 | _ -> if !Odoc_args.inverse_merge_ml_mli then - () + () else - raise (Failure (Odoc_messages.different_types mli.ty_name)) + raise (Failure (Odoc_messages.different_types mli.ty_name)) (** 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 @@ -265,25 +265,25 @@ let rec merge_param_info pi_mli pi_ml = match (pi_mli, pi_ml) with (Simple_name sn_mli, Simple_name sn_ml) -> if sn_mli.sn_name = "" then - Simple_name { sn_mli with sn_name = sn_ml.sn_name } + Simple_name { sn_mli with sn_name = sn_ml.sn_name } else - pi_mli + pi_mli | (Simple_name _, Tuple _) -> pi_mli | (Tuple (_, t_mli), Simple_name sn_ml) -> (* if we're here, then the tuple in the .mli has no parameter names ; - then we take the name of the parameter of the .ml and the type of the .mli. *) + then we take the name of the parameter of the .ml and the type of the .mli. *) Simple_name { sn_ml with sn_type = t_mli } | (Tuple (l_mli, t_mli), Tuple (l_ml, _)) -> (* if the two tuples have different lengths - (which should not occurs), we return the pi_mli, - without further investigation.*) + (which should not occurs), we return the pi_mli, + without further investigation.*) if (List.length l_mli) <> (List.length l_ml) then - pi_mli + pi_mli else - let new_l = List.map2 merge_param_info l_mli l_ml in - Tuple (new_l, t_mli) + let new_l = List.map2 merge_param_info l_mli l_ml in + Tuple (new_l, t_mli) (** Merge of the parameters of two functions/methods/classes, one for a .mli, another for a .ml. The prameters in the .mli are completed by the name in the .ml.*) @@ -309,71 +309,71 @@ let merge_classes merge_options mli ml = List.iter (fun a -> try - let _ = List.find - (fun ele -> - match ele with - Class_attribute a2 -> - if a2.att_value.val_name = a.att_value.val_name then - ( - a.att_value.val_info <- merge_info_opt merge_options - a.att_value.val_info a2.att_value.val_info; - a.att_value.val_loc <- { a.att_value.val_loc with loc_impl = a2.att_value.val_loc.loc_impl } ; - if !Odoc_args.keep_code then - a.att_value.val_code <- a2.att_value.val_code; - true - ) - else - false - | _ -> - false - ) - (* we look for the last attribute with this name defined in the implementation *) - (List.rev (Odoc_class.class_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Class_attribute a2 -> + if a2.att_value.val_name = a.att_value.val_name then + ( + a.att_value.val_info <- merge_info_opt merge_options + a.att_value.val_info a2.att_value.val_info; + a.att_value.val_loc <- { a.att_value.val_loc with loc_impl = a2.att_value.val_loc.loc_impl } ; + if !Odoc_args.keep_code then + a.att_value.val_code <- a2.att_value.val_code; + true + ) + else + false + | _ -> + false + ) + (* we look for the last attribute with this name defined in the implementation *) + (List.rev (Odoc_class.class_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_class.class_attributes mli); (* merge methods *) List.iter (fun m -> try - let _ = List.find - (fun ele -> - match ele with - Class_method m2 -> - if m2.met_value.val_name = m.met_value.val_name then - ( - m.met_value.val_info <- merge_info_opt - merge_options m.met_value.val_info m2.met_value.val_info; - m.met_value.val_loc <- { m.met_value.val_loc with loc_impl = m2.met_value.val_loc.loc_impl } ; - (* merge the parameter names *) - m.met_value.val_parameters <- (merge_parameters - m.met_value.val_parameters - m2.met_value.val_parameters) ; + let _ = List.find + (fun ele -> + match ele with + Class_method m2 -> + if m2.met_value.val_name = m.met_value.val_name then + ( + m.met_value.val_info <- merge_info_opt + merge_options m.met_value.val_info m2.met_value.val_info; + m.met_value.val_loc <- { m.met_value.val_loc with loc_impl = m2.met_value.val_loc.loc_impl } ; + (* merge the parameter names *) + m.met_value.val_parameters <- (merge_parameters + m.met_value.val_parameters + m2.met_value.val_parameters) ; (* we must reassociate comments in @param to the corresponding - parameters because the associated comment of a parameter may have been changed by the merge.*) - Odoc_value.update_value_parameters_text m.met_value; - - if !Odoc_args.keep_code then - m.met_value.val_code <- m2.met_value.val_code; - - true - ) - else - false - | _ -> - false - ) - (* we look for the last method with this name defined in the implementation *) - (List.rev (Odoc_class.class_elements ml)) - in - () + parameters because the associated comment of a parameter may have been changed by the merge.*) + Odoc_value.update_value_parameters_text m.met_value; + + if !Odoc_args.keep_code then + m.met_value.val_code <- m2.met_value.val_code; + + true + ) + else + false + | _ -> + false + ) + (* we look for the last method with this name defined in the implementation *) + (List.rev (Odoc_class.class_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_class.class_methods mli) @@ -386,71 +386,71 @@ let merge_class_types merge_options mli ml = List.iter (fun a -> try - let _ = List.find - (fun ele -> - match ele with - Class_attribute a2 -> - if a2.att_value.val_name = a.att_value.val_name then - ( - a.att_value.val_info <- merge_info_opt merge_options - a.att_value.val_info a2.att_value.val_info; - a.att_value.val_loc <- { a.att_value.val_loc with loc_impl = a2.att_value.val_loc.loc_impl } ; - if !Odoc_args.keep_code then - a.att_value.val_code <- a2.att_value.val_code; - - true - ) - else - false - | _ -> - false - ) - (* we look for the last attribute with this name defined in the implementation *) - (List.rev (Odoc_class.class_type_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Class_attribute a2 -> + if a2.att_value.val_name = a.att_value.val_name then + ( + a.att_value.val_info <- merge_info_opt merge_options + a.att_value.val_info a2.att_value.val_info; + a.att_value.val_loc <- { a.att_value.val_loc with loc_impl = a2.att_value.val_loc.loc_impl } ; + if !Odoc_args.keep_code then + a.att_value.val_code <- a2.att_value.val_code; + + true + ) + else + false + | _ -> + false + ) + (* we look for the last attribute with this name defined in the implementation *) + (List.rev (Odoc_class.class_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_class.class_type_attributes mli); (* merge methods *) List.iter (fun m -> try - let _ = List.find - (fun ele -> - match ele with - Class_method m2 -> - if m2.met_value.val_name = m.met_value.val_name then - ( - m.met_value.val_info <- merge_info_opt - merge_options m.met_value.val_info m2.met_value.val_info; - m.met_value.val_loc <- { m.met_value.val_loc with loc_impl = m2.met_value.val_loc.loc_impl } ; + let _ = List.find + (fun ele -> + match ele with + Class_method m2 -> + if m2.met_value.val_name = m.met_value.val_name then + ( + m.met_value.val_info <- merge_info_opt + merge_options m.met_value.val_info m2.met_value.val_info; + m.met_value.val_loc <- { m.met_value.val_loc with loc_impl = m2.met_value.val_loc.loc_impl } ; m.met_value.val_parameters <- (merge_parameters - m.met_value.val_parameters - m2.met_value.val_parameters) ; + m.met_value.val_parameters + m2.met_value.val_parameters) ; (* we must reassociate comments in @param to the the corresponding - parameters because the associated comment of a parameter may have been changed y the merge.*) - Odoc_value.update_value_parameters_text m.met_value; - - if !Odoc_args.keep_code then - m.met_value.val_code <- m2.met_value.val_code; - - true - ) - else - false - | _ -> - false - ) - (* we look for the last method with this name defined in the implementation *) - (List.rev (Odoc_class.class_type_elements ml)) - in - () + parameters because the associated comment of a parameter may have been changed y the merge.*) + Odoc_value.update_value_parameters_text m.met_value; + + if !Odoc_args.keep_code then + m.met_value.val_code <- m2.met_value.val_code; + + true + ) + else + false + | _ -> + false + ) + (* we look for the last method with this name defined in the implementation *) + (List.rev (Odoc_class.class_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_class.class_type_methods mli) @@ -464,86 +464,86 @@ let rec merge_module_types merge_options mli ml = List.iter (fun ex -> try - let _ = List.find - (fun ele -> - match ele with - Element_exception ex2 -> - if ex2.ex_name = ex.ex_name then - ( - ex.ex_info <- merge_info_opt merge_options ex.ex_info ex2.ex_info; - ex.ex_loc <- { ex.ex_loc with loc_impl = ex2.ex_loc.loc_impl } ; - true - ) - else - false - | _ -> - false - ) - (* we look for the last exception with this name defined in the implementation *) - (List.rev (Odoc_module.module_type_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_exception ex2 -> + if ex2.ex_name = ex.ex_name then + ( + ex.ex_info <- merge_info_opt merge_options ex.ex_info ex2.ex_info; + ex.ex_loc <- { ex.ex_loc with loc_impl = ex2.ex_loc.loc_impl } ; + true + ) + else + false + | _ -> + false + ) + (* we look for the last exception with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_type_exceptions mli); (* merge types *) List.iter (fun ty -> try - let _ = List.find - (fun ele -> - match ele with - Element_type ty2 -> - if ty2.ty_name = ty.ty_name then - ( - merge_types merge_options ty ty2; - true - ) - else - false - | _ -> - false - ) - (* we look for the last type with this name defined in the implementation *) - (List.rev (Odoc_module.module_type_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_type ty2 -> + if ty2.ty_name = ty.ty_name then + ( + merge_types merge_options ty ty2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last type with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_type_types mli); (* merge submodules *) List.iter (fun m -> try - let _ = List.find - (fun ele -> - match ele with - Element_module m2 -> - if m2.m_name = m.m_name then - ( - merge_modules merge_options m m2 ; + let _ = List.find + (fun ele -> + match ele with + Element_module m2 -> + if m2.m_name = m.m_name then + ( + merge_modules merge_options m m2 ; (* - m.m_info <- merge_info_opt merge_options m.m_info m2.m_info; - m.m_loc <- { m.m_loc with loc_impl = m2.m_loc.loc_impl } ; + m.m_info <- merge_info_opt merge_options m.m_info m2.m_info; + m.m_loc <- { m.m_loc with loc_impl = m2.m_loc.loc_impl } ; *) - true - ) - else - false - | _ -> - false - ) - (* we look for the last module with this name defined in the implementation *) - (List.rev (Odoc_module.module_type_elements ml)) - in - () + true + ) + else + false + | _ -> + false + ) + (* we look for the last module with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_type_modules mli); @@ -551,27 +551,27 @@ let rec merge_module_types merge_options mli ml = List.iter (fun m -> try - let _ = List.find - (fun ele -> - match ele with - Element_module_type m2 -> - if m2.mt_name = m.mt_name then - ( - merge_module_types merge_options m m2; - true - ) - else - false - | _ -> - false - ) - (* we look for the last module with this name defined in the implementation *) - (List.rev (Odoc_module.module_type_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_module_type m2 -> + if m2.mt_name = m.mt_name then + ( + merge_module_types merge_options m m2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last module with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_type_module_types mli); @@ -581,39 +581,39 @@ let rec merge_module_types merge_options mli ml = List.iter (fun v -> try - let _ = List.find - (fun ele -> - match ele with - Element_value v2 -> - if v2.val_name = v.val_name then - ( - v.val_info <- merge_info_opt merge_options v.val_info v2.val_info ; - v.val_loc <- { v.val_loc with loc_impl = v2.val_loc.loc_impl } ; - (* in the .mli we don't know any parameters so we add the ones in the .ml *) - v.val_parameters <- (merge_parameters - v.val_parameters - v2.val_parameters) ; - (* we must reassociate comments in @param to the the corresponding - parameters because the associated comment of a parameter may have been changed y the merge.*) - Odoc_value.update_value_parameters_text v; - - if !Odoc_args.keep_code then - v.val_code <- v2.val_code; - - true - ) - else - false - | _ -> - false - ) - (* we look for the last value with this name defined in the implementation *) - (List.rev (Odoc_module.module_type_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_value v2 -> + if v2.val_name = v.val_name then + ( + v.val_info <- merge_info_opt merge_options v.val_info v2.val_info ; + v.val_loc <- { v.val_loc with loc_impl = v2.val_loc.loc_impl } ; + (* in the .mli we don't know any parameters so we add the ones in the .ml *) + v.val_parameters <- (merge_parameters + v.val_parameters + v2.val_parameters) ; + (* we must reassociate comments in @param to the the corresponding + parameters because the associated comment of a parameter may have been changed y the merge.*) + Odoc_value.update_value_parameters_text v; + + if !Odoc_args.keep_code then + v.val_code <- v2.val_code; + + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_type_values mli); @@ -621,27 +621,27 @@ let rec merge_module_types merge_options mli ml = List.iter (fun c -> try - let _ = List.find - (fun ele -> - match ele with - Element_class c2 -> - if c2.cl_name = c.cl_name then - ( - merge_classes merge_options c c2; - true - ) - else - false - | _ -> - false - ) - (* we look for the last value with this name defined in the implementation *) - (List.rev (Odoc_module.module_type_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_class c2 -> + if c2.cl_name = c.cl_name then + ( + merge_classes merge_options c c2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_type_classes mli); @@ -649,27 +649,27 @@ let rec merge_module_types merge_options mli ml = List.iter (fun c -> try - let _ = List.find - (fun ele -> - match ele with - Element_class_type c2 -> - if c2.clt_name = c.clt_name then - ( - merge_class_types merge_options c c2; - true - ) - else - false - | _ -> - false - ) - (* we look for the last value with this name defined in the implementation *) - (List.rev (Odoc_module.module_type_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_class_type c2 -> + if c2.clt_name = c.clt_name then + ( + merge_class_types merge_options c c2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_type_class_types mli) @@ -684,86 +684,86 @@ and merge_modules merge_options mli ml = List.iter (fun ex -> try - let _ = List.find - (fun ele -> - match ele with - Element_exception ex2 -> - if ex2.ex_name = ex.ex_name then - ( - ex.ex_info <- merge_info_opt merge_options ex.ex_info ex2.ex_info; - ex.ex_loc <- { ex.ex_loc with loc_impl = ex.ex_loc.loc_impl } ; - true - ) - else - false - | _ -> - false - ) - (* we look for the last exception with this name defined in the implementation *) - (List.rev (Odoc_module.module_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_exception ex2 -> + if ex2.ex_name = ex.ex_name then + ( + ex.ex_info <- merge_info_opt merge_options ex.ex_info ex2.ex_info; + ex.ex_loc <- { ex.ex_loc with loc_impl = ex.ex_loc.loc_impl } ; + true + ) + else + false + | _ -> + false + ) + (* we look for the last exception with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_exceptions mli); (* merge types *) List.iter (fun ty -> try - let _ = List.find - (fun ele -> - match ele with - Element_type ty2 -> - if ty2.ty_name = ty.ty_name then - ( - merge_types merge_options ty ty2; - true - ) - else - false - | _ -> - false - ) - (* we look for the last type with this name defined in the implementation *) - (List.rev (Odoc_module.module_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_type ty2 -> + if ty2.ty_name = ty.ty_name then + ( + merge_types merge_options ty ty2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last type with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_types mli); (* merge submodules *) List.iter (fun m -> try - let _ = List.find - (fun ele -> - match ele with - Element_module m2 -> - if m2.m_name = m.m_name then - ( - merge_modules merge_options m m2 ; + let _ = List.find + (fun ele -> + match ele with + Element_module m2 -> + if m2.m_name = m.m_name then + ( + merge_modules merge_options m m2 ; (* - m.m_info <- merge_info_opt merge_options m.m_info m2.m_info; - m.m_loc <- { m.m_loc with loc_impl = m2.m_loc.loc_impl } ; + m.m_info <- merge_info_opt merge_options m.m_info m2.m_info; + m.m_loc <- { m.m_loc with loc_impl = m2.m_loc.loc_impl } ; *) - true - ) - else - false - | _ -> - false - ) - (* we look for the last module with this name defined in the implementation *) - (List.rev (Odoc_module.module_elements ml)) - in - () + true + ) + else + false + | _ -> + false + ) + (* we look for the last module with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_modules mli); @@ -771,27 +771,27 @@ and merge_modules merge_options mli ml = List.iter (fun m -> try - let _ = List.find - (fun ele -> - match ele with - Element_module_type m2 -> - if m2.mt_name = m.mt_name then - ( - merge_module_types merge_options m m2; - true - ) - else - false - | _ -> - false - ) - (* we look for the last module with this name defined in the implementation *) - (List.rev (Odoc_module.module_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_module_type m2 -> + if m2.mt_name = m.mt_name then + ( + merge_module_types merge_options m m2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last module with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_module_types mli); @@ -801,34 +801,34 @@ and merge_modules merge_options mli ml = List.iter (fun v -> try - let _ = List.find - (fun v2 -> - if v2.val_name = v.val_name then - ( - v.val_info <- merge_info_opt merge_options v.val_info v2.val_info ; - v.val_loc <- { v.val_loc with loc_impl = v2.val_loc.loc_impl } ; - (* in the .mli we don't know any parameters so we add the ones in the .ml *) - v.val_parameters <- (merge_parameters - v.val_parameters - v2.val_parameters) ; - (* we must reassociate comments in @param to the the corresponding - parameters because the associated comment of a parameter may have been changed y the merge.*) - Odoc_value.update_value_parameters_text v; - - if !Odoc_args.keep_code then - v.val_code <- v2.val_code; - true - ) - else - false - ) - (* we look for the last value with this name defined in the implementation *) - (List.rev (Odoc_module.module_values ml)) - in - () + let _ = List.find + (fun v2 -> + if v2.val_name = v.val_name then + ( + v.val_info <- merge_info_opt merge_options v.val_info v2.val_info ; + v.val_loc <- { v.val_loc with loc_impl = v2.val_loc.loc_impl } ; + (* in the .mli we don't know any parameters so we add the ones in the .ml *) + v.val_parameters <- (merge_parameters + v.val_parameters + v2.val_parameters) ; + (* we must reassociate comments in @param to the the corresponding + parameters because the associated comment of a parameter may have been changed y the merge.*) + Odoc_value.update_value_parameters_text v; + + if !Odoc_args.keep_code then + v.val_code <- v2.val_code; + true + ) + else + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_values ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_values mli); @@ -836,27 +836,27 @@ and merge_modules merge_options mli ml = List.iter (fun c -> try - let _ = List.find - (fun ele -> - match ele with - Element_class c2 -> - if c2.cl_name = c.cl_name then - ( - merge_classes merge_options c c2; - true - ) - else - false - | _ -> - false - ) - (* we look for the last value with this name defined in the implementation *) - (List.rev (Odoc_module.module_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_class c2 -> + if c2.cl_name = c.cl_name then + ( + merge_classes merge_options c c2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_classes mli); @@ -864,27 +864,27 @@ and merge_modules merge_options mli ml = List.iter (fun c -> try - let _ = List.find - (fun ele -> - match ele with - Element_class_type c2 -> - if c2.clt_name = c.clt_name then - ( - merge_class_types merge_options c c2; - true - ) - else - false - | _ -> - false - ) - (* we look for the last value with this name defined in the implementation *) - (List.rev (Odoc_module.module_elements ml)) - in - () + let _ = List.find + (fun ele -> + match ele with + Element_class_type c2 -> + if c2.clt_name = c.clt_name then + ( + merge_class_types merge_options c c2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () with - Not_found -> - () + Not_found -> + () ) (Odoc_module.module_class_types mli); @@ -894,41 +894,41 @@ let merge merge_options modules_list = let rec iter = function [] -> [] | m :: q -> - (* look for another module with the same name *) - let (l_same, l_others) = List.partition - (fun m2 -> m.m_name = m2.m_name) - q - in - match l_same with - [] -> - (* no other module to merge with *) - m :: (iter l_others) - | m2 :: [] -> - ( - (* we can merge m with m2 if there is an implementation - and an interface.*) - let f b = if !Odoc_args.inverse_merge_ml_mli then not b else b in - match f m.m_is_interface, f m2.m_is_interface with - true, false -> (merge_modules merge_options m m2) :: (iter l_others) - | false, true -> (merge_modules merge_options m2 m) :: (iter l_others) - | false, false -> - if !Odoc_args.inverse_merge_ml_mli then - (* two Module.ts for the .mli ! *) - raise (Failure (Odoc_messages.two_interfaces m.m_name)) - else + (* look for another module with the same name *) + let (l_same, l_others) = List.partition + (fun m2 -> m.m_name = m2.m_name) + q + in + match l_same with + [] -> + (* no other module to merge with *) + m :: (iter l_others) + | m2 :: [] -> + ( + (* we can merge m with m2 if there is an implementation + and an interface.*) + let f b = if !Odoc_args.inverse_merge_ml_mli then not b else b in + match f m.m_is_interface, f m2.m_is_interface with + true, false -> (merge_modules merge_options m m2) :: (iter l_others) + | false, true -> (merge_modules merge_options m2 m) :: (iter l_others) + | false, false -> + if !Odoc_args.inverse_merge_ml_mli then + (* two Module.ts for the .mli ! *) + raise (Failure (Odoc_messages.two_interfaces m.m_name)) + else + (* two Module.t for the .ml ! *) + raise (Failure (Odoc_messages.two_implementations m.m_name)) + | true, true -> + if !Odoc_args.inverse_merge_ml_mli then (* two Module.t for the .ml ! *) - raise (Failure (Odoc_messages.two_implementations m.m_name)) - | true, true -> - if !Odoc_args.inverse_merge_ml_mli then - (* two Module.t for the .ml ! *) - raise (Failure (Odoc_messages.two_implementations m.m_name)) - else - (* two Module.ts for the .mli ! *) - raise (Failure (Odoc_messages.two_interfaces m.m_name)) - ) - | _ -> - (* two many Module.t ! *) - raise (Failure (Odoc_messages.too_many_module_objects m.m_name)) + raise (Failure (Odoc_messages.two_implementations m.m_name)) + else + (* two Module.ts for the .mli ! *) + raise (Failure (Odoc_messages.two_interfaces m.m_name)) + ) + | _ -> + (* two many Module.t ! *) + raise (Failure (Odoc_messages.too_many_module_objects m.m_name)) in iter modules_list diff --git a/ocamldoc/odoc_merge.mli b/ocamldoc/odoc_merge.mli index 44e89ee61..3dadeecc0 100644 --- a/ocamldoc/odoc_merge.mli +++ b/ocamldoc/odoc_merge.mli @@ -18,8 +18,8 @@ val merge_info_opt : Odoc_types.merge_option list -> Odoc_types.info option -> - Odoc_types.info option -> - Odoc_types.info option + Odoc_types.info option -> + Odoc_types.info option (** Merge of modules which represent the same OCaml module, in a list of t_module. There must be at most two t_module for the same OCaml module, one for a .mli, another for the .ml. diff --git a/ocamldoc/odoc_messages.ml b/ocamldoc/odoc_messages.ml index f21607d28..96da92798 100644 --- a/ocamldoc/odoc_messages.ml +++ b/ocamldoc/odoc_messages.ml @@ -54,9 +54,9 @@ let dot_include_all = " include all modules in the dot output,\n"^ " not only the modules given on the command line" let dot_types = " generate dependency graph for types instead of modules" let default_dot_colors = [ "darkturquoise" ; "darkgoldenrod2" ; "cyan" ; "green" ; "magenta" ; "yellow" ; - "burlywood1" ; "aquamarine" ; "floralwhite" ; "lightpink" ; - "lightblue" ; "mediumturquoise" ; "salmon" ; "slategray3" ; - ] + "burlywood1" ; "aquamarine" ; "floralwhite" ; "lightpink" ; + "lightblue" ; "mediumturquoise" ; "salmon" ; "slategray3" ; + ] let dot_colors = "<c1,c2,...,cn> use colors c1,c1,...,cn in the dot output\n"^ " (default list is "^(String.concat "," default_dot_colors)^")" let dot_reduce = " perform a transitive reduction on the selected dependency graph before the dot output\n" diff --git a/ocamldoc/odoc_misc.ml b/ocamldoc/odoc_misc.ml index 2ec48c800..e7cce8717 100644 --- a/ocamldoc/odoc_misc.ml +++ b/ocamldoc/odoc_misc.ml @@ -20,12 +20,12 @@ let input_file_as_string nom = try let n = input chanin s 0 len in if n = 0 then - () + () else - ( - Buffer.add_substring buf s 0 n; - iter () - ) + ( + Buffer.add_substring buf s 0 n; + iter () + ) with End_of_file -> () in @@ -47,7 +47,7 @@ let string_of_type_list sep type_list = Types.Tarrow _ | Types.Ttuple _ -> true | Types.Tlink t2 | Types.Tsubst t2 -> need_parent t2 | Types.Tconstr _ -> - false + false | Types.Tvar | Types.Tunivar | Types.Tobject _ | Types.Tpoly _ | Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false in @@ -69,8 +69,8 @@ let string_of_type_list sep type_list = Format.fprintf Format.str_formatter "@[<hov 2>"; print_one_type ty; List.iter - (fun t -> Format.fprintf Format.str_formatter "@,%s" sep; print_one_type t) - tyl; + (fun t -> Format.fprintf Format.str_formatter "@,%s" sep; print_one_type t) + tyl; Format.fprintf Format.str_formatter "@]" end; Format.flush_str_formatter() @@ -83,7 +83,7 @@ let simpl_module_type t = Types.Tmty_ident p -> t | Types.Tmty_signature _ -> Types.Tmty_signature [] | Types.Tmty_functor (id, mt1, mt2) -> - Types.Tmty_functor (id, iter mt1, iter mt2) + Types.Tmty_functor (id, iter mt1, iter mt2) in iter t @@ -101,17 +101,17 @@ let simpl_class_type t = match t with Types.Tcty_constr (p,texp_list,ct) -> t | Types.Tcty_signature cs -> - (* on vire les vals et methods pour ne pas qu'elles soient imprim�es - quand on affichera le type *) - let tnil = { Types.desc = Types.Tnil ; Types.level = 0; Types.id = 0 } in - Types.Tcty_signature { Types.cty_self = { cs.Types.cty_self with - Types.desc = Types.Tobject (tnil, ref None) }; - Types.cty_vars = Types.Vars.empty ; - Types.cty_concr = Types.Concr.empty ; - } + (* on vire les vals et methods pour ne pas qu'elles soient imprim�es + quand on affichera le type *) + let tnil = { Types.desc = Types.Tnil ; Types.level = 0; Types.id = 0 } in + Types.Tcty_signature { Types.cty_self = { cs.Types.cty_self with + Types.desc = Types.Tobject (tnil, ref None) }; + Types.cty_vars = Types.Vars.empty ; + Types.cty_concr = Types.Concr.empty ; + } | Types.Tcty_fun (l, texp, ct) -> - let new_ct = iter ct in - Types.Tcty_fun (l, texp, new_ct) + let new_ct = iter ct in + Types.Tcty_fun (l, texp, new_ct) in iter t @@ -127,13 +127,13 @@ let get_fields type_expr = List.fold_left (fun acc -> fun (label, field_kind, typ) -> match field_kind with - Types.Fabsent -> - acc - | _ -> - if label = "*dummy method*" then - acc - else - acc @ [label, typ] + Types.Fabsent -> + acc + | _ -> + if label = "*dummy method*" then + acc + else + acc @ [label, typ] ) [] fields @@ -147,34 +147,34 @@ let rec string_of_text t = | Odoc_types.Verbatim s -> s | Odoc_types.Bold t | Odoc_types.Italic t - | Odoc_types.Center t - | Odoc_types.Left t - | Odoc_types.Right t + | Odoc_types.Center t + | Odoc_types.Left t + | Odoc_types.Right t | Odoc_types.Emphasize t -> string_of_text t | Odoc_types.List l -> - (String.concat "" - (List.map (fun t -> "\n- "^(string_of_text t)) l))^ - "\n" + (String.concat "" + (List.map (fun t -> "\n- "^(string_of_text t)) l))^ + "\n" | Odoc_types.Enum l -> - let rec f n = function - [] -> "\n" - | t :: q -> - "\n"^(string_of_int n)^". "^(string_of_text t)^ - (f (n + 1) q) - in - f 1 l - | Odoc_types.Newline -> "\n" - | Odoc_types.Block t -> "\t"^(string_of_text t)^"\n" + let rec f n = function + [] -> "\n" + | t :: q -> + "\n"^(string_of_int n)^". "^(string_of_text t)^ + (f (n + 1) q) + in + f 1 l + | Odoc_types.Newline -> "\n" + | Odoc_types.Block t -> "\t"^(string_of_text t)^"\n" | Odoc_types.Title (_, _, t) -> "\n"^(string_of_text t)^"\n" | Odoc_types.Latex s -> "{% "^s^" %}" | Odoc_types.Link (s, t) -> - "["^s^"]"^(string_of_text t) - | Odoc_types.Ref (name, _) -> - iter (Odoc_types.Code name) - | Odoc_types.Superscript t -> - "^{"^(string_of_text t)^"}" - | Odoc_types.Subscript t -> - "^{"^(string_of_text t)^"}" + "["^s^"]"^(string_of_text t) + | Odoc_types.Ref (name, _) -> + iter (Odoc_types.Code name) + | Odoc_types.Superscript t -> + "^{"^(string_of_text t)^"}" + | Odoc_types.Subscript t -> + "^{"^(string_of_text t)^"}" in String.concat "" (List.map iter t) @@ -204,10 +204,10 @@ let string_of_raised_exceptions l = | _ -> Odoc_messages.raises^"\n"^ (String.concat "" - (List.map - (fun (ex, desc) -> "- "^ex^" "^(string_of_text desc)^"\n") - l - ) + (List.map + (fun (ex, desc) -> "- "^ex^" "^(string_of_text desc)^"\n") + l + ) )^"\n" let string_of_see (see_ref, t) = @@ -226,10 +226,10 @@ let string_of_sees l = | _ -> Odoc_messages.see_also^"\n"^ (String.concat "" - (List.map - (fun see -> "- "^(string_of_see see)^"\n") - l - ) + (List.map + (fun see -> "- "^(string_of_see see)^"\n") + l + ) )^"\n" let string_of_return_opt return_opt = @@ -287,10 +287,10 @@ let rec text_no_title_no_list t = | Odoc_types.Title (_,_,t) -> text_no_title_no_list t | Odoc_types.List l | Odoc_types.Enum l -> - (Odoc_types.Raw " ") :: - (text_list_concat - (Odoc_types.Raw ", ") - (List.map text_no_title_no_list l)) + (Odoc_types.Raw " ") :: + (text_list_concat + (Odoc_types.Raw ", ") + (List.map text_no_title_no_list l)) | Odoc_types.Raw _ | Odoc_types.Code _ | Odoc_types.CodePre _ @@ -317,7 +317,7 @@ let get_titles_in_text t = match ele with | Odoc_types.Title (n,lopt,t) -> l := (n,lopt,t) :: !l | Odoc_types.List l - | Odoc_types.Enum l -> List.iter iter_text l + | Odoc_types.Enum l -> List.iter iter_text l | Odoc_types.Raw _ | Odoc_types.Code _ | Odoc_types.CodePre _ @@ -352,12 +352,12 @@ let rec get_before_dot s = (true, s, "") else match s.[n+1] with - ' ' | '\n' | '\r' | '\t' -> - (true, String.sub s 0 (n+1), - String.sub s (n+1) (len - n - 1)) - | _ -> - let b, s2, s_after = get_before_dot (String.sub s (n + 1) (len - n - 1)) in - (b, (String.sub s 0 (n+1))^s2, s_after) + ' ' | '\n' | '\r' | '\t' -> + (true, String.sub s 0 (n+1), + String.sub s (n+1) (len - n - 1)) + | _ -> + let b, s2, s_after = get_before_dot (String.sub s (n + 1) (len - n - 1)) in + (b, (String.sub s 0 (n+1))^s2, s_after) with Not_found -> (false, s, "") @@ -367,11 +367,11 @@ let rec first_sentence_text t = | ele :: q -> let (stop, ele2, ele3_opt) = first_sentence_text_ele ele in if stop then - (stop, [ele2], - match ele3_opt with None -> q | Some e -> e :: q) + (stop, [ele2], + match ele3_opt with None -> q | Some e -> e :: q) else - let (stop2, q2, rest) = first_sentence_text q in - (stop2, ele2 :: q2, rest) + let (stop2, q2, rest) = first_sentence_text q in + (stop2, ele2 :: q2, rest) and first_sentence_text_ele text_ele = @@ -433,19 +433,19 @@ let create_index_lists elements string_of_ele = let rec f current acc0 acc1 acc2 = function [] -> (acc0 :: acc1) @ [acc2] | ele :: q -> - let s = string_of_ele ele in - match s with - "" -> f current acc0 acc1 (acc2 @ [ele]) q - | _ -> - let first = Char.uppercase s.[0] in - match first with - 'A' .. 'Z' -> - if current = first then - f current acc0 acc1 (acc2 @ [ele]) q - else - f first acc0 (acc1 @ [acc2]) [ele] q - | _ -> - f current (acc0 @ [ele]) acc1 acc2 q + let s = string_of_ele ele in + match s with + "" -> f current acc0 acc1 (acc2 @ [ele]) q + | _ -> + let first = Char.uppercase s.[0] in + match first with + 'A' .. 'Z' -> + if current = first then + f current acc0 acc1 (acc2 @ [ele]) q + else + f first acc0 (acc1 @ [acc2]) [ele] q + | _ -> + f current (acc0 @ [ele]) acc1 acc2 q in f '_' [] [] [] elements @@ -459,16 +459,16 @@ let remove_option typ = let rec iter t = match t with | Types.Tconstr (p,tlist,_) -> - ( - match p with - Path.Pident id when Ident.name id = "option" -> - ( - match tlist with - [t2] -> t2.Types.desc - | _ -> t - ) - | _ -> t - ) + ( + match p with + Path.Pident id when Ident.name id = "option" -> + ( + match tlist with + [t2] -> t2.Types.desc + | _ -> t + ) + | _ -> t + ) | Types.Tvar | Types.Tunivar | Types.Tpoly _ diff --git a/ocamldoc/odoc_module.ml b/ocamldoc/odoc_module.ml index 1a18cc7db..b555e8a4a 100644 --- a/ocamldoc/odoc_module.ml +++ b/ocamldoc/odoc_module.ml @@ -51,7 +51,7 @@ and module_kind = | Module_apply of module_kind * module_kind | Module_with of module_type_kind * string | Module_constraint of module_kind * module_type_kind - + (** Representation of a module. *) and t_module = { m_name : Name.t ; @@ -84,7 +84,7 @@ and t_module_type = { mt_is_interface : bool ; (** true for modules read from interface files *) mt_file : string ; (** the file the module type is defined in. *) mutable mt_kind : module_type_kind option ; (** [None] = abstract module type if mt_type = None ; - Always [None] when the module type was extracted from the implementation file. *) + Always [None] when the module type was extracted from the implementation file. *) mutable mt_loc : Odoc_types.location ; } @@ -96,8 +96,8 @@ let values l = List.fold_left (fun acc -> fun ele -> match ele with - Element_value v -> acc @ [v] - | _ -> acc + Element_value v -> acc @ [v] + | _ -> acc ) [] l @@ -107,8 +107,8 @@ let types l = List.fold_left (fun acc -> fun ele -> match ele with - Element_type t -> acc @ [t] - | _ -> acc + Element_type t -> acc @ [t] + | _ -> acc ) [] l @@ -118,8 +118,8 @@ let exceptions l = List.fold_left (fun acc -> fun ele -> match ele with - Element_exception e -> acc @ [e] - | _ -> acc + Element_exception e -> acc @ [e] + | _ -> acc ) [] l @@ -129,8 +129,8 @@ let classes l = List.fold_left (fun acc -> fun ele -> match ele with - Element_class c -> acc @ [c] - | _ -> acc + Element_class c -> acc @ [c] + | _ -> acc ) [] l @@ -140,8 +140,8 @@ let class_types l = List.fold_left (fun acc -> fun ele -> match ele with - Element_class_type ct -> acc @ [ct] - | _ -> acc + Element_class_type ct -> acc @ [ct] + | _ -> acc ) [] l @@ -151,8 +151,8 @@ let modules l = List.fold_left (fun acc -> fun ele -> match ele with - Element_module m -> acc @ [m] - | _ -> acc + Element_module m -> acc @ [m] + | _ -> acc ) [] l @@ -162,8 +162,8 @@ let mod_types l = List.fold_left (fun acc -> fun ele -> match ele with - Element_module_type mt -> acc @ [mt] - | _ -> acc + Element_module_type mt -> acc @ [mt] + | _ -> acc ) [] l @@ -173,8 +173,8 @@ let comments l = List.fold_left (fun acc -> fun ele -> match ele with - Element_module_comment t -> acc @ [t] - | _ -> acc + Element_module_comment t -> acc @ [t] + | _ -> acc ) [] l @@ -184,8 +184,8 @@ let included_modules l = List.fold_left (fun acc -> fun ele -> match ele with - Element_included_module m -> acc @ [m] - | _ -> acc + Element_included_module m -> acc @ [m] + | _ -> acc ) [] l @@ -197,33 +197,33 @@ let rec module_elements ?(trans=true) m = Module_struct l -> l | Module_alias ma -> if trans then - match ma.ma_module with - None -> [] - | Some (Mod m) -> module_elements m - | Some (Modtype mt) -> module_type_elements mt + match ma.ma_module with + None -> [] + | Some (Mod m) -> module_elements m + | Some (Modtype mt) -> module_type_elements mt else - [] + [] | Module_functor (_, k) | Module_apply (k, _) -> iter_kind k | Module_with (tk,_) -> module_type_elements ~trans: trans - { mt_name = "" ; mt_info = None ; mt_type = None ; - mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; - mt_loc = Odoc_types.dummy_loc ; - } + { mt_name = "" ; mt_info = None ; mt_type = None ; + mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; + mt_loc = Odoc_types.dummy_loc ; + } | Module_constraint (k, tk) -> (* A VOIR : utiliser k ou tk ? *) module_elements ~trans: trans - { m_name = "" ; m_info = None ; m_type = Types.Tmty_signature [] ; - m_is_interface = false ; m_file = "" ; m_kind = k ; - m_loc = Odoc_types.dummy_loc ; - m_top_deps = [] ; - } + { m_name = "" ; m_info = None ; m_type = Types.Tmty_signature [] ; + m_is_interface = false ; m_file = "" ; m_kind = k ; + m_loc = Odoc_types.dummy_loc ; + m_top_deps = [] ; + } (* module_type_elements ~trans: trans - { mt_name = "" ; mt_info = None ; mt_type = None ; - mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; - mt_loc = Odoc_types.dummy_loc } + { mt_name = "" ; mt_info = None ; mt_type = None ; + mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; + mt_loc = Odoc_types.dummy_loc } *) in iter_kind m.m_kind @@ -236,15 +236,15 @@ and module_type_elements ?(trans=true) mt = | Some (Module_type_struct l) -> l | Some (Module_type_functor (_, k)) -> iter_kind (Some k) | Some (Module_type_with (k, _)) -> - if trans then - iter_kind (Some k) - else - [] + if trans then + iter_kind (Some k) + else + [] | Some (Module_type_alias mta) -> if trans then - match mta.mta_module with - None -> [] - | Some mt -> module_type_elements mt + match mta.mta_module with + None -> [] + | Some mt -> module_type_elements mt else [] in @@ -306,40 +306,40 @@ let rec module_type_parameters ?(trans=true) mt = let rec iter k = match k with Some (Module_type_functor (params, _)) -> - ( + ( (* we create the couple (parameter, description opt), using - the description of the parameter if we can find it in the comment.*) - match mt.mt_info with - None -> - List.map (fun p -> (p, None)) params - | Some i -> - List.map - (fun p -> - try - let d = List.assoc p.Odoc_parameter.mp_name i.Odoc_types.i_params in - (p, Some d) - with - Not_found -> - (p, None) - ) - params - ) + the description of the parameter if we can find it in the comment.*) + match mt.mt_info with + None -> + List.map (fun p -> (p, None)) params + | Some i -> + List.map + (fun p -> + try + let d = List.assoc p.Odoc_parameter.mp_name i.Odoc_types.i_params in + (p, Some d) + with + Not_found -> + (p, None) + ) + params + ) | Some (Module_type_alias mta) -> - if trans then - match mta.mta_module with - None -> [] - | Some mt2 -> module_type_parameters ~trans mt2 - else - [] + if trans then + match mta.mta_module with + None -> [] + | Some mt2 -> module_type_parameters ~trans mt2 + else + [] | Some (Module_type_with (k, _)) -> - if trans then - iter (Some k) - else - [] + if trans then + iter (Some k) + else + [] | Some (Module_type_struct _) -> - [] + [] | None -> - [] + [] in iter mt.mt_kind @@ -350,35 +350,35 @@ and module_parameters ?(trans=true) m = Module_functor (params, _) -> ( (* we create the couple (parameter, description opt), using - the description of the parameter if we can find it in the comment.*) + the description of the parameter if we can find it in the comment.*) match m.m_info with - None -> - List.map (fun p -> (p, None)) params + None -> + List.map (fun p -> (p, None)) params | Some i -> - List.map - (fun p -> - try - let d = List.assoc p.Odoc_parameter.mp_name i.Odoc_types.i_params in - (p, Some d) - with - Not_found -> - (p, None) - ) - params + List.map + (fun p -> + try + let d = List.assoc p.Odoc_parameter.mp_name i.Odoc_types.i_params in + (p, Some d) + with + Not_found -> + (p, None) + ) + params ) | Module_alias ma -> if trans then - match ma.ma_module with - None -> [] - | Some (Mod m) -> module_parameters ~trans m - | Some (Modtype mt) -> module_type_parameters ~trans mt + match ma.ma_module with + None -> [] + | Some (Mod m) -> module_parameters ~trans m + | Some (Modtype mt) -> module_type_parameters ~trans mt else - [] + [] | Module_constraint (k, tk) -> module_type_parameters ~trans: trans - { mt_name = "" ; mt_info = None ; mt_type = None ; - mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; - mt_loc = Odoc_types.dummy_loc } + { mt_name = "" ; mt_info = None ; mt_type = None ; + mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; + mt_loc = Odoc_types.dummy_loc } | Module_struct _ | Module_apply _ | Module_with _ -> @@ -399,13 +399,13 @@ let rec module_type_is_functor mt = match k with Some (Module_type_functor _) -> true | Some (Module_type_alias mta) -> - ( - match mta.mta_module with - None -> false - | Some mtyp -> module_type_is_functor mtyp - ) + ( + match mta.mta_module with + None -> false + | Some mtyp -> module_type_is_functor mtyp + ) | Some (Module_type_with (k, _)) -> - iter (Some k) + iter (Some k) | Some (Module_type_struct _) | None -> false in @@ -418,7 +418,7 @@ let rec module_is_functor m = | Module_alias ma -> ( match ma.ma_module with - None -> false + None -> false | Some (Mod mo) -> module_is_functor mo | Some (Modtype mt) -> module_type_is_functor mt ) diff --git a/ocamldoc/odoc_name.ml b/ocamldoc/odoc_name.ml index 00adb2cb0..670166b0e 100644 --- a/ocamldoc/odoc_name.ml +++ b/ocamldoc/odoc_name.ml @@ -25,10 +25,10 @@ let infix_chars = [ '|' ; '/' ; '$' ; '%' ; - '=' ; - ':' ; - '~' ; - '!' ; + '=' ; + ':' ; + '~' ; + '!' ; ] type t = string @@ -48,31 +48,31 @@ let cut name = | s -> let len = String.length s in match s.[len-1] with - ')' -> - ( - let j = ref 0 in - let buf = [|Buffer.create len ; Buffer.create len |] in - for i = 0 to len - 1 do - match s.[i] with - '.' when !j = 0 -> - if i < len - 1 then - match s.[i+1] with - '(' -> - j := 1 - | _ -> - Buffer.add_char buf.(!j) '(' - else - Buffer.add_char buf.(!j) s.[i] - | c -> - Buffer.add_char buf.(!j) c - done; - (Buffer.contents buf.(0), Buffer.contents buf.(1)) - ) - | _ -> - match List.rev (Str.split (Str.regexp_string ".") s) with - [] -> ("", "") - | h :: q -> - (String.concat "." (List.rev q), h) + ')' -> + ( + let j = ref 0 in + let buf = [|Buffer.create len ; Buffer.create len |] in + for i = 0 to len - 1 do + match s.[i] with + '.' when !j = 0 -> + if i < len - 1 then + match s.[i+1] with + '(' -> + j := 1 + | _ -> + Buffer.add_char buf.(!j) '(' + else + Buffer.add_char buf.(!j) s.[i] + | c -> + Buffer.add_char buf.(!j) c + done; + (Buffer.contents buf.(0), Buffer.contents buf.(1)) + ) + | _ -> + match List.rev (Str.split (Str.regexp_string ".") s) with + [] -> ("", "") + | h :: q -> + (String.concat "." (List.rev q), h) let simple name = snd (cut name) let father name = fst (cut name) @@ -112,11 +112,11 @@ let hide_given_modules l s = let rec iter = function [] -> s | h :: q -> - let s2 = get_relative h s in - if s = s2 then - iter q - else - s2 + let s2 = get_relative h s in + if s = s2 then + iter q + else + s2 in iter l @@ -131,9 +131,9 @@ let to_path n = match List.fold_left (fun acc_opt -> fun s -> - match acc_opt with - None -> Some (Path.Pident (Ident.create s)) - | Some acc -> Some (Path.Pdot (acc, s, 0))) + match acc_opt with + None -> Some (Path.Pident (Ident.create s)) + | Some acc -> Some (Path.Pdot (acc, s, 0))) None (Str.split (Str.regexp "\\.") n) with @@ -146,14 +146,14 @@ let name_alias name cpl_aliases = let rec f n1 = function [] -> raise Not_found | (n2, n3) :: q -> - if n2 = n1 then - n3 - else - if prefix n2 n1 then - let ln2 = String.length n2 in - n3^(String.sub n1 ln2 ((String.length n1) - ln2)) - else - f n1 q + if n2 = n1 then + n3 + else + if prefix n2 n1 then + let ln2 = String.length n2 in + n3^(String.sub n1 ln2 ((String.length n1) - ln2)) + else + f n1 q in let rec iter n = try iter (f n cpl_aliases) diff --git a/ocamldoc/odoc_ocamlhtml.mll b/ocamldoc/odoc_ocamlhtml.mll index 5881f4a59..72b26960d 100644 --- a/ocamldoc/odoc_ocamlhtml.mll +++ b/ocamldoc/odoc_ocamlhtml.mll @@ -68,8 +68,8 @@ let print ?(esc=true) s = let print_class ?(esc=true) cl s = print ~esc: false ("<span class=\""^cl^"\">"^ - (if esc then escape s else s)^ - "</span>") + (if esc then escape s else s)^ + "</span>") ;; (** The table of keywords with colors *) @@ -174,21 +174,21 @@ let print_comment () = "<span class=\""^comment_class^"\">(*"^(escape s)^"*)</span>" else match s.[0] with - '*' -> - ( - try - let html = !html_of_comment (String.sub s 1 (len-1)) in - "</code><table><tr><td>"^(make_margin ())^"</td><td>"^ - "<span class=\""^comment_class^"\">"^ - "(**"^html^"*)"^ - "</span></td></tr></table><code class=\""^code_class^"\">" - with - e -> - prerr_endline (Printexc.to_string e); - "<span class=\""^comment_class^"\">(*"^(escape s)^"*)</span>" - ) + '*' -> + ( + try + let html = !html_of_comment (String.sub s 1 (len-1)) in + "</code><table><tr><td>"^(make_margin ())^"</td><td>"^ + "<span class=\""^comment_class^"\">"^ + "(**"^html^"*)"^ + "</span></td></tr></table><code class=\""^code_class^"\">" + with + e -> + prerr_endline (Printexc.to_string e); + "<span class=\""^comment_class^"\">(*"^(escape s)^"*)</span>" + ) | _ -> - "<span class=\""^comment_class^"\">(*"^(escape s)^"*)</span>" + "<span class=\""^comment_class^"\">(*"^(escape s)^"*)</span>" in print ~esc: false code @@ -270,16 +270,16 @@ let float_literal = rule token = parse blank { - let s = Lexing.lexeme lexbuf in - ( - match s with - " " -> incr margin - | "\t" -> margin := !margin + 8 - | "\n" -> margin := 0 - | _ -> () - ); - print s; - token lexbuf + let s = Lexing.lexeme lexbuf in + ( + match s with + " " -> incr margin + | "\t" -> margin := !margin + 8 + | "\n" -> margin := 0 + | _ -> () + ); + print s; + token lexbuf } | "_" { print "_" ; token lexbuf } @@ -303,7 +303,7 @@ rule token = parse { let s = Lexing.lexeme lexbuf in try let cl = Hashtbl.find keyword_table s in - (print_class cl s ; token lexbuf ) + (print_class cl s ; token lexbuf ) with Not_found -> (print s ; token lexbuf )} | uppercase identchar * @@ -320,40 +320,40 @@ rule token = parse lexbuf.Lexing.lex_start_pos <- string_start - lexbuf.Lexing.lex_abs_pos; print_class string_class ("\""^(get_stored_string())^"\"") ; - token lexbuf } + token lexbuf } | "'" [^ '\\' '\''] "'" { print_class string_class (Lexing.lexeme lexbuf) ; - token lexbuf } + token lexbuf } | "'" '\\' ['\\' '\'' 'n' 't' 'b' 'r'] "'" { print_class string_class (Lexing.lexeme lexbuf ) ; - token lexbuf } + token lexbuf } | "'" '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" { print_class string_class (Lexing.lexeme lexbuf ) ; - token lexbuf } + token lexbuf } | "(*" { - reset_comment_buffer (); - comment_start_pos := [Lexing.lexeme_start lexbuf]; - comment lexbuf ; - print_comment (); + reset_comment_buffer (); + comment_start_pos := [Lexing.lexeme_start lexbuf]; + comment lexbuf ; + print_comment (); token lexbuf } | "(*)" { reset_comment_buffer (); - comment_start_pos := [Lexing.lexeme_start lexbuf]; + comment_start_pos := [Lexing.lexeme_start lexbuf]; comment lexbuf ; - print_comment (); + print_comment (); token lexbuf } | "*)" { lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1; print (Lexing.lexeme lexbuf) ; - token lexbuf + token lexbuf } | "#" [' ' '\t']* ['0'-'9']+ [^ '\n' '\r'] * ('\n' | '\r' | "\r\n") (* # linenum ... *) { - print (Lexing.lexeme lexbuf); - token lexbuf + print (Lexing.lexeme lexbuf); + token lexbuf } | "#" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } | "&" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } @@ -418,8 +418,8 @@ rule token = parse and comment = parse "(*" { comment_start_pos := Lexing.lexeme_start lexbuf :: !comment_start_pos; - store_comment_char '('; - store_comment_char '*'; + store_comment_char '('; + store_comment_char '*'; comment lexbuf; } | "*)" @@ -427,15 +427,15 @@ and comment = parse | [] -> assert false | [x] -> comment_start_pos := [] | _ :: l -> - store_comment_char '*'; - store_comment_char ')'; - comment_start_pos := l; + store_comment_char '*'; + store_comment_char ')'; + comment_start_pos := l; comment lexbuf; } | "\"" { reset_string_buffer(); string_start_pos := Lexing.lexeme_start lexbuf; - store_comment_char '"'; + store_comment_char '"'; begin try string lexbuf with Error (Unterminated_string, _, _) -> let st = List.hd !comment_start_pos in @@ -444,36 +444,36 @@ and comment = parse comment lexbuf } | "''" { - store_comment_char '\''; - store_comment_char '\''; - comment lexbuf } + store_comment_char '\''; + store_comment_char '\''; + comment lexbuf } | "'" [^ '\\' '\''] "'" { - store_comment_char '\''; - store_comment_char (Lexing.lexeme_char lexbuf 1); - store_comment_char '\''; - comment lexbuf } + store_comment_char '\''; + store_comment_char (Lexing.lexeme_char lexbuf 1); + store_comment_char '\''; + comment lexbuf } | "'\\" ['\\' '\'' 'n' 't' 'b' 'r'] "'" { - store_comment_char '\''; - store_comment_char '\\'; - store_comment_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)) ; - store_comment_char '\''; - comment lexbuf } + store_comment_char '\''; + store_comment_char '\\'; + store_comment_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)) ; + store_comment_char '\''; + comment lexbuf } | "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" { - store_comment_char '\''; - store_comment_char '\\'; - store_comment_char(char_for_decimal_code lexbuf 1); - store_comment_char '\''; - comment lexbuf } + store_comment_char '\''; + store_comment_char '\\'; + store_comment_char(char_for_decimal_code lexbuf 1); + store_comment_char '\''; + comment lexbuf } | eof { let st = List.hd !comment_start_pos in raise (Error (Unterminated_comment, st, st + 2)); } | _ { store_comment_char(Lexing.lexeme_char lexbuf 0); - comment lexbuf } + comment lexbuf } and string = parse '"' @@ -520,9 +520,9 @@ let html_of_code ?(with_pre=true) code = with _ -> (* flush str_formatter because we already output - something in it *) - Format.pp_print_flush !fmt () ; - start^code^ending + something in it *) + Format.pp_print_flush !fmt () ; + start^code^ending ) in pre := old_pre; diff --git a/ocamldoc/odoc_opt.ml b/ocamldoc/odoc_opt.ml index 08d0f04f3..a8be1963e 100644 --- a/ocamldoc/odoc_opt.ml +++ b/ocamldoc/odoc_opt.ml @@ -37,15 +37,15 @@ let loaded_modules = List.flatten (List.map (fun f -> - Odoc_info.verbose (Odoc_messages.loading f); - try - let l = Odoc_analyse.load_modules f in - Odoc_info.verbose Odoc_messages.ok; - l - with Failure s -> - prerr_endline s ; - incr Odoc_global.errors ; - [] + Odoc_info.verbose (Odoc_messages.loading f); + try + let l = Odoc_analyse.load_modules f in + Odoc_info.verbose Odoc_messages.ok; + l + with Failure s -> + prerr_endline s ; + incr Odoc_global.errors ; + [] ) !Odoc_args.load ) @@ -58,8 +58,8 @@ let _ = | Some f -> try Odoc_analyse.dump_modules f modules with Failure s -> - prerr_endline s ; - incr Odoc_global.errors + prerr_endline s ; + incr Odoc_global.errors let _ = match !Odoc_args.doc_generator with diff --git a/ocamldoc/odoc_parameter.ml b/ocamldoc/odoc_parameter.ml index c58a25446..1cd5cac5f 100644 --- a/ocamldoc/odoc_parameter.ml +++ b/ocamldoc/odoc_parameter.ml @@ -47,11 +47,11 @@ let complete_name p = let rec iter pi = match pi with Simple_name sn -> - sn.sn_name + sn.sn_name | Tuple ([], _) -> (* anonymous parameter *) - "??" + "??" | Tuple (pi_list, _) -> - "("^(String.concat "," (List.map iter pi_list))^")" + "("^(String.concat "," (List.map iter pi_list))^")" in iter p @@ -67,9 +67,9 @@ let update_parameter_text f p = let rec iter pi = match pi with Simple_name sn -> - sn.sn_text <- f sn.sn_name + sn.sn_text <- f sn.sn_name | Tuple (l, _) -> - List.iter iter l + List.iter iter l in iter p @@ -79,9 +79,9 @@ let desc_by_name pi name = let rec iter acc pi = match pi with Simple_name sn -> - (sn.sn_name, sn.sn_text) :: acc + (sn.sn_name, sn.sn_text) :: acc | Tuple (pi_list, _) -> - List.fold_left iter acc pi_list + List.fold_left iter acc pi_list in let l = iter [] pi in List.assoc name l @@ -93,9 +93,9 @@ let names pi = let rec iter acc pi = match pi with Simple_name sn -> - sn.sn_name :: acc + sn.sn_name :: acc | Tuple (pi_list, _) -> - List.fold_left iter acc pi_list + List.fold_left iter acc pi_list in iter [] pi @@ -105,9 +105,9 @@ let type_by_name pi name = let rec iter acc pi = match pi with Simple_name sn -> - (sn.sn_name, sn.sn_type) :: acc + (sn.sn_name, sn.sn_type) :: acc | Tuple (pi_list, _) -> - List.fold_left iter acc pi_list + List.fold_left iter acc pi_list in let l = iter [] pi in List.assoc name l @@ -119,12 +119,12 @@ let desc_from_info_opt info_opt s = None -> None | Some i -> match s with - "" -> None - | _ -> - try - Some (List.assoc s i.Odoc_types.i_params) - with - Not_found -> - print_DEBUG ("desc_from_info_opt "^s^" not found in\n"); - List.iter (fun (s, _) -> print_DEBUG s) i.Odoc_types.i_params; - None + "" -> None + | _ -> + try + Some (List.assoc s i.Odoc_types.i_params) + with + Not_found -> + print_DEBUG ("desc_from_info_opt "^s^" not found in\n"); + List.iter (fun (s, _) -> print_DEBUG s) i.Odoc_types.i_params; + None diff --git a/ocamldoc/odoc_parser.mly b/ocamldoc/odoc_parser.mly index 4603ed3a6..13e111101 100644 --- a/ocamldoc/odoc_parser.mly +++ b/ocamldoc/odoc_parser.mly @@ -92,20 +92,20 @@ param: (* we only look for simple id, no pattern nor tuples *) let s = $2 in match Str.split (Str.regexp (blank^"+")) s with - [] + [] | _ :: [] -> - raise (Failure "usage: @param id description") + raise (Failure "usage: @param id description") | id :: _ -> - print_DEBUG ("Identificator "^id); - let reg = identchar^"+" in - print_DEBUG ("reg="^reg); - if Str.string_match (Str.regexp reg) id 0 then - let remain = String.sub s (String.length id) ((String.length s) - (String.length id)) in - print_DEBUG ("T_PARAM Desc remain="^remain); - let remain2 = Str.replace_first (Str.regexp ("^"^blank^"+")) "" remain in - params := !params @ [(id, remain2)] - else - raise (Failure (id^" is not a valid parameter identificator in \"@param "^s^"\"")) + print_DEBUG ("Identificator "^id); + let reg = identchar^"+" in + print_DEBUG ("reg="^reg); + if Str.string_match (Str.regexp reg) id 0 then + let remain = String.sub s (String.length id) ((String.length s) - (String.length id)) in + print_DEBUG ("T_PARAM Desc remain="^remain); + let remain2 = Str.replace_first (Str.regexp ("^"^blank^"+")) "" remain in + params := !params @ [(id, remain2)] + else + raise (Failure (id^" is not a valid parameter identificator in \"@param "^s^"\"")) } ; author: @@ -129,19 +129,19 @@ raise_exc: (* isolate the exception construtor name *) let s = $2 in match Str.split (Str.regexp (blank^"+")) s with - [] + [] | _ :: [] -> - raise (Failure "usage: @raise Exception description") + raise (Failure "usage: @raise Exception description") | id :: _ -> - print_DEBUG ("exception "^id); - let reg = uppercase^identchar^"*"^"\\(\\."^uppercase^identchar^"*\\)*" in - print_DEBUG ("reg="^reg); - if Str.string_match (Str.regexp reg) id 0 then - let remain = String.sub s (String.length id) ((String.length s) - (String.length id)) in - let remain2 = Str.replace_first (Str.regexp ("^"^blank^"+")) "" remain in - raised_exceptions := !raised_exceptions @ [(id, remain2)] - else - raise (Failure (id^" is not a valid exception constructor in \"@raise "^s^"\"")) + print_DEBUG ("exception "^id); + let reg = uppercase^identchar^"*"^"\\(\\."^uppercase^identchar^"*\\)*" in + print_DEBUG ("reg="^reg); + if Str.string_match (Str.regexp reg) id 0 then + let remain = String.sub s (String.length id) ((String.length s) - (String.length id)) in + let remain2 = Str.replace_first (Str.regexp ("^"^blank^"+")) "" remain in + raised_exceptions := !raised_exceptions @ [(id, remain2)] + else + raise (Failure (id^" is not a valid exception constructor in \"@raise "^s^"\"")) } ; return: diff --git a/ocamldoc/odoc_scan.ml b/ocamldoc/odoc_scan.ml index 2750c0368..96abc22f0 100644 --- a/ocamldoc/odoc_scan.ml +++ b/ocamldoc/odoc_scan.ml @@ -46,13 +46,13 @@ class scanner = A VOIR : scan des classes h�rit�es.*) method scan_class_elements c = List.iter - (fun ele -> - match ele with - Odoc_class.Class_attribute a -> self#scan_attribute a - | Odoc_class.Class_method m -> self#scan_method m - | Odoc_class.Class_comment t -> self#scan_class_comment t - ) - (Odoc_class.class_elements c) + (fun ele -> + match ele with + Odoc_class.Class_attribute a -> self#scan_attribute a + | Odoc_class.Class_method m -> self#scan_method m + | Odoc_class.Class_comment t -> self#scan_class_comment t + ) + (Odoc_class.class_elements c) (** Scan of a class. Should not be overriden. It calls [scan_class_pre] and if [scan_class_pre] returns [true], then it calls scan_class_elements.*) @@ -72,13 +72,13 @@ class scanner = A VOIR : scan des classes h�rit�es.*) method scan_class_type_elements ct = List.iter - (fun ele -> - match ele with - Odoc_class.Class_attribute a -> self#scan_attribute a - | Odoc_class.Class_method m -> self#scan_method m - | Odoc_class.Class_comment t -> self#scan_class_type_comment t - ) - (Odoc_class.class_type_elements ct) + (fun ele -> + match ele with + Odoc_class.Class_attribute a -> self#scan_attribute a + | Odoc_class.Class_method m -> self#scan_method m + | Odoc_class.Class_comment t -> self#scan_class_type_comment t + ) + (Odoc_class.class_type_elements ct) (** Scan of a class type. Should not be overriden. It calls [scan_class_type_pre] and if [scan_class_type_pre] returns [true], then it calls scan_class_type_elements.*) @@ -97,19 +97,19 @@ class scanner = (** This method scan the elements of the given module. *) method scan_module_elements m = List.iter - (fun ele -> - match ele with - Odoc_module.Element_module m -> self#scan_module m - | Odoc_module.Element_module_type mt -> self#scan_module_type mt - | Odoc_module.Element_included_module im -> self#scan_included_module im - | Odoc_module.Element_class c -> self#scan_class c - | Odoc_module.Element_class_type ct -> self#scan_class_type ct - | Odoc_module.Element_value v -> self#scan_value v - | Odoc_module.Element_exception e -> self#scan_exception e - | Odoc_module.Element_type t -> self#scan_type t - | Odoc_module.Element_module_comment t -> self#scan_module_comment t - ) - (Odoc_module.module_elements m) + (fun ele -> + match ele with + Odoc_module.Element_module m -> self#scan_module m + | Odoc_module.Element_module_type mt -> self#scan_module_type mt + | Odoc_module.Element_included_module im -> self#scan_included_module im + | Odoc_module.Element_class c -> self#scan_class c + | Odoc_module.Element_class_type ct -> self#scan_class_type ct + | Odoc_module.Element_value v -> self#scan_value v + | Odoc_module.Element_exception e -> self#scan_exception e + | Odoc_module.Element_type t -> self#scan_type t + | Odoc_module.Element_module_comment t -> self#scan_module_comment t + ) + (Odoc_module.module_elements m) (** Scan of a module. Should not be overriden. It calls [scan_module_pre] and if [scan_module_pre] returns [true], then it calls scan_module_elements.*) @@ -128,19 +128,19 @@ class scanner = (** This method scan the elements of the given module type. *) method scan_module_type_elements mt = List.iter - (fun ele -> - match ele with - Odoc_module.Element_module m -> self#scan_module m - | Odoc_module.Element_module_type mt -> self#scan_module_type mt - | Odoc_module.Element_included_module im -> self#scan_included_module im - | Odoc_module.Element_class c -> self#scan_class c - | Odoc_module.Element_class_type ct -> self#scan_class_type ct - | Odoc_module.Element_value v -> self#scan_value v - | Odoc_module.Element_exception e -> self#scan_exception e - | Odoc_module.Element_type t -> self#scan_type t - | Odoc_module.Element_module_comment t -> self#scan_module_comment t - ) - (Odoc_module.module_type_elements mt) + (fun ele -> + match ele with + Odoc_module.Element_module m -> self#scan_module m + | Odoc_module.Element_module_type mt -> self#scan_module_type mt + | Odoc_module.Element_included_module im -> self#scan_included_module im + | Odoc_module.Element_class c -> self#scan_class c + | Odoc_module.Element_class_type ct -> self#scan_class_type ct + | Odoc_module.Element_value v -> self#scan_value v + | Odoc_module.Element_exception e -> self#scan_exception e + | Odoc_module.Element_type t -> self#scan_type t + | Odoc_module.Element_module_comment t -> self#scan_module_comment t + ) + (Odoc_module.module_type_elements mt) (** Scan of a module type. Should not be overriden. It calls [scan_module_type_pre] and if [scan_module_type_pre] returns [true], then it calls scan_module_type_elements.*) diff --git a/ocamldoc/odoc_search.ml b/ocamldoc/odoc_search.ml index 00d4199b9..7d32acd7c 100644 --- a/ocamldoc/odoc_search.ml +++ b/ocamldoc/odoc_search.ml @@ -80,10 +80,10 @@ module Search = | T.Enum l -> List.flatten (List.map (fun t -> search_text root t v) l) | T.Newline -> [] | T.Title (n, l_opt, t) -> - (match l_opt with - None -> [] - | Some s -> search_section (Name.concat root s) v) @ - (search_text root t v) + (match l_opt with + None -> [] + | Some s -> search_section (Name.concat root s) v) @ + (search_text root t v) let search_value va v = if P.p_value va v then [Res_value va] else [] @@ -98,197 +98,197 @@ module Search = let search_class c v = let (go_deeper, ok) = P.p_class c v in let l = - if go_deeper then - let res_att = - List.fold_left - (fun acc -> fun att -> acc @ (search_attribute att v)) - [] - (Odoc_class.class_attributes c) - in - let res_met = - List.fold_left - (fun acc -> fun m -> acc @ (search_method m v)) - [] - (Odoc_class.class_methods c) - in - let res_sec = - List.fold_left - (fun acc -> fun t -> acc @ (search_text c.cl_name t v)) - [] - (Odoc_class.class_comments c) - in - let l = res_att @ res_met @ res_sec in - l - else - [] + if go_deeper then + let res_att = + List.fold_left + (fun acc -> fun att -> acc @ (search_attribute att v)) + [] + (Odoc_class.class_attributes c) + in + let res_met = + List.fold_left + (fun acc -> fun m -> acc @ (search_method m v)) + [] + (Odoc_class.class_methods c) + in + let res_sec = + List.fold_left + (fun acc -> fun t -> acc @ (search_text c.cl_name t v)) + [] + (Odoc_class.class_comments c) + in + let l = res_att @ res_met @ res_sec in + l + else + [] in if ok then - (Res_class c) :: l + (Res_class c) :: l else - l + l let search_class_type ct v = let (go_deeper, ok) = P.p_class_type ct v in let l = - if go_deeper then - let res_att = - List.fold_left - (fun acc -> fun att -> acc @ (search_attribute att v)) - [] - (Odoc_class.class_type_attributes ct) - in - let res_met = - List.fold_left - (fun acc -> fun m -> acc @ (search_method m v)) - [] - (Odoc_class.class_type_methods ct) - in - let res_sec = - List.fold_left - (fun acc -> fun t -> acc @ (search_text ct.clt_name t v)) - [] - (Odoc_class.class_type_comments ct) - in - let l = res_att @ res_met @ res_sec in - l - else - [] + if go_deeper then + let res_att = + List.fold_left + (fun acc -> fun att -> acc @ (search_attribute att v)) + [] + (Odoc_class.class_type_attributes ct) + in + let res_met = + List.fold_left + (fun acc -> fun m -> acc @ (search_method m v)) + [] + (Odoc_class.class_type_methods ct) + in + let res_sec = + List.fold_left + (fun acc -> fun t -> acc @ (search_text ct.clt_name t v)) + [] + (Odoc_class.class_type_comments ct) + in + let l = res_att @ res_met @ res_sec in + l + else + [] in if ok then - (Res_class_type ct) :: l + (Res_class_type ct) :: l else - l + l let rec search_module_type mt v = let (go_deeper, ok) = P.p_module_type mt v in let l = - if go_deeper then - let res_val = - List.fold_left - (fun acc -> fun va -> acc @ (search_value va v)) - [] - (Odoc_module.module_type_values mt) - in - let res_typ = - List.fold_left - (fun acc -> fun t -> acc @ (search_type t v)) - [] - (Odoc_module.module_type_types mt) - in - let res_exc = - List.fold_left - (fun acc -> fun e -> acc @ (search_exception e v)) - [] - (Odoc_module.module_type_exceptions mt) - in - let res_mod = search (Odoc_module.module_type_modules mt) v in - let res_modtyp = - List.fold_left - (fun acc -> fun mt -> acc @ (search_module_type mt v)) - [] - (Odoc_module.module_type_module_types mt) - in - let res_cl = - List.fold_left - (fun acc -> fun cl -> acc @ (search_class cl v)) - [] - (Odoc_module.module_type_classes mt) - in - let res_cltyp = - List.fold_left - (fun acc -> fun clt -> acc @ (search_class_type clt v)) - [] - (Odoc_module.module_type_class_types mt) - in - let res_sec = - List.fold_left - (fun acc -> fun t -> acc @ (search_text mt.mt_name t v)) - [] - (Odoc_module.module_type_comments mt) - in - let l = res_val @ res_typ @ res_exc @ res_mod @ - res_modtyp @ res_cl @ res_cltyp @ res_sec - in - l - else - [] + if go_deeper then + let res_val = + List.fold_left + (fun acc -> fun va -> acc @ (search_value va v)) + [] + (Odoc_module.module_type_values mt) + in + let res_typ = + List.fold_left + (fun acc -> fun t -> acc @ (search_type t v)) + [] + (Odoc_module.module_type_types mt) + in + let res_exc = + List.fold_left + (fun acc -> fun e -> acc @ (search_exception e v)) + [] + (Odoc_module.module_type_exceptions mt) + in + let res_mod = search (Odoc_module.module_type_modules mt) v in + let res_modtyp = + List.fold_left + (fun acc -> fun mt -> acc @ (search_module_type mt v)) + [] + (Odoc_module.module_type_module_types mt) + in + let res_cl = + List.fold_left + (fun acc -> fun cl -> acc @ (search_class cl v)) + [] + (Odoc_module.module_type_classes mt) + in + let res_cltyp = + List.fold_left + (fun acc -> fun clt -> acc @ (search_class_type clt v)) + [] + (Odoc_module.module_type_class_types mt) + in + let res_sec = + List.fold_left + (fun acc -> fun t -> acc @ (search_text mt.mt_name t v)) + [] + (Odoc_module.module_type_comments mt) + in + let l = res_val @ res_typ @ res_exc @ res_mod @ + res_modtyp @ res_cl @ res_cltyp @ res_sec + in + l + else + [] in if ok then - (Res_module_type mt) :: l + (Res_module_type mt) :: l else - l + l and search_module m v = let (go_deeper, ok) = P.p_module m v in let l = - if go_deeper then - let res_val = - List.fold_left - (fun acc -> fun va -> acc @ (search_value va v)) - [] - (Odoc_module.module_values m) - in - let res_typ = - List.fold_left - (fun acc -> fun t -> acc @ (search_type t v)) - [] - (Odoc_module.module_types m) - in - let res_exc = - List.fold_left - (fun acc -> fun e -> acc @ (search_exception e v)) - [] - (Odoc_module.module_exceptions m) - in - let res_mod = search (Odoc_module.module_modules m) v in - let res_modtyp = - List.fold_left - (fun acc -> fun mt -> acc @ (search_module_type mt v)) - [] - (Odoc_module.module_module_types m) - in - let res_cl = - List.fold_left - (fun acc -> fun cl -> acc @ (search_class cl v)) - [] - (Odoc_module.module_classes m) - in - let res_cltyp = - List.fold_left - (fun acc -> fun clt -> acc @ (search_class_type clt v)) - [] - (Odoc_module.module_class_types m) - in - let res_sec = - List.fold_left - (fun acc -> fun t -> acc @ (search_text m.m_name t v)) - [] - (Odoc_module.module_comments m) - in - let l = res_val @ res_typ @ res_exc @ res_mod @ - res_modtyp @ res_cl @ res_cltyp @ res_sec - in - l - else - [] + if go_deeper then + let res_val = + List.fold_left + (fun acc -> fun va -> acc @ (search_value va v)) + [] + (Odoc_module.module_values m) + in + let res_typ = + List.fold_left + (fun acc -> fun t -> acc @ (search_type t v)) + [] + (Odoc_module.module_types m) + in + let res_exc = + List.fold_left + (fun acc -> fun e -> acc @ (search_exception e v)) + [] + (Odoc_module.module_exceptions m) + in + let res_mod = search (Odoc_module.module_modules m) v in + let res_modtyp = + List.fold_left + (fun acc -> fun mt -> acc @ (search_module_type mt v)) + [] + (Odoc_module.module_module_types m) + in + let res_cl = + List.fold_left + (fun acc -> fun cl -> acc @ (search_class cl v)) + [] + (Odoc_module.module_classes m) + in + let res_cltyp = + List.fold_left + (fun acc -> fun clt -> acc @ (search_class_type clt v)) + [] + (Odoc_module.module_class_types m) + in + let res_sec = + List.fold_left + (fun acc -> fun t -> acc @ (search_text m.m_name t v)) + [] + (Odoc_module.module_comments m) + in + let l = res_val @ res_typ @ res_exc @ res_mod @ + res_modtyp @ res_cl @ res_cltyp @ res_sec + in + l + else + [] in if ok then - (Res_module m) :: l + (Res_module m) :: l else - l + l and search module_list v = List.fold_left - (fun acc -> fun m -> - List.fold_left - (fun acc2 -> fun ele -> - if List.mem ele acc2 then acc2 else acc2 @ [ele] - ) - acc - (search_module m v) - ) - [] - module_list + (fun acc -> fun m -> + List.fold_left + (fun acc2 -> fun ele -> + if List.mem ele acc2 then acc2 else acc2 @ [ele] + ) + acc + (search_module m v) + ) + [] + module_list end module P_name = diff --git a/ocamldoc/odoc_see_lexer.mll b/ocamldoc/odoc_see_lexer.mll index 2fa6a5314..8e7dfcd45 100644 --- a/ocamldoc/odoc_see_lexer.mll +++ b/ocamldoc/odoc_see_lexer.mll @@ -30,63 +30,63 @@ rule main = parse | [ '\010' ] { - print_DEBUG2 " [ '\010' ] "; - main lexbuf + print_DEBUG2 " [ '\010' ] "; + main lexbuf } | "<" { - print_DEBUG2 "call url lexbuf" ; - url lexbuf - } + print_DEBUG2 "call url lexbuf" ; + url lexbuf + } | "\"" { - print_DEBUG2 "call doc lexbuf" ; - doc lexbuf - } + print_DEBUG2 "call doc lexbuf" ; + doc lexbuf + } | '\'' { - print_DEBUG2 "call file lexbuf" ; - file lexbuf - } + print_DEBUG2 "call file lexbuf" ; + file lexbuf + } | eof { - print_DEBUG2 "EOF"; - EOF + print_DEBUG2 "EOF"; + EOF } | _ { - Buffer.reset buf ; - Buffer.add_string buf (Lexing.lexeme lexbuf); - desc lexbuf - } + Buffer.reset buf ; + Buffer.add_string buf (Lexing.lexeme lexbuf); + desc lexbuf + } and url = parse | ([^'>'] | '\n')+">" { - let s = Lexing.lexeme lexbuf in - print_DEBUG2 ("([^'>'] | '\n')+ \">\" with "^s) ; - See_url (String.sub s 0 ((String.length s) -1)) + let s = Lexing.lexeme lexbuf in + print_DEBUG2 ("([^'>'] | '\n')+ \">\" with "^s) ; + See_url (String.sub s 0 ((String.length s) -1)) } and doc = parse | ([^'"'] | '\n' | "\\'")* "\"" { - let s = Lexing.lexeme lexbuf in - See_doc (String.sub s 0 ((String.length s) -1)) + let s = Lexing.lexeme lexbuf in + See_doc (String.sub s 0 ((String.length s) -1)) } and file = parse | ([^'\''] | '\n' | "\\\"")* "'" { - let s = Lexing.lexeme lexbuf in - See_file (String.sub s 0 ((String.length s) -1)) + let s = Lexing.lexeme lexbuf in + See_file (String.sub s 0 ((String.length s) -1)) } @@ -95,6 +95,6 @@ and desc = parse { Desc (Buffer.contents buf) } | _ { - Buffer.add_string buf (Lexing.lexeme lexbuf); - desc lexbuf + Buffer.add_string buf (Lexing.lexeme lexbuf); + desc lexbuf } diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml index 649897390..e38c37b59 100644 --- a/ocamldoc/odoc_sig.ml +++ b/ocamldoc/odoc_sig.ml @@ -32,34 +32,34 @@ open Odoc_types module Signature_search = struct type ele = - | M of string - | MT of string - | V of string - | T of string - | C of string - | CT of string - | E of string - | ER of string - | P of string + | M of string + | MT of string + | V of string + | T of string + | C of string + | CT of string + | E of string + | ER of string + | P of string type tab = (ele, Types.signature_item) Hashtbl.t let add_to_hash table signat = match signat with - Types.Tsig_value (ident, _) -> - Hashtbl.add table (V (Name.from_ident ident)) signat - | Types.Tsig_exception (ident, _) -> - Hashtbl.add table (E (Name.from_ident ident)) signat - | Types.Tsig_type (ident, _) -> - Hashtbl.add table (T (Name.from_ident ident)) signat - | Types.Tsig_class (ident,_) -> - Hashtbl.add table (C (Name.from_ident ident)) signat - | Types.Tsig_cltype (ident, _) -> - Hashtbl.add table (CT (Name.from_ident ident)) signat - | Types.Tsig_module (ident, _) -> - Hashtbl.add table (M (Name.from_ident ident)) signat - | Types.Tsig_modtype (ident,_) -> - Hashtbl.add table (MT (Name.from_ident ident)) signat + Types.Tsig_value (ident, _) -> + Hashtbl.add table (V (Name.from_ident ident)) signat + | Types.Tsig_exception (ident, _) -> + Hashtbl.add table (E (Name.from_ident ident)) signat + | Types.Tsig_type (ident, _) -> + Hashtbl.add table (T (Name.from_ident ident)) signat + | Types.Tsig_class (ident,_) -> + Hashtbl.add table (C (Name.from_ident ident)) signat + | Types.Tsig_cltype (ident, _) -> + Hashtbl.add table (CT (Name.from_ident ident)) signat + | Types.Tsig_module (ident, _) -> + Hashtbl.add table (M (Name.from_ident ident)) signat + | Types.Tsig_modtype (ident,_) -> + Hashtbl.add table (MT (Name.from_ident ident)) signat let table signat = let t = Hashtbl.create 13 in @@ -69,46 +69,46 @@ module Signature_search = let search_value table name = match Hashtbl.find table (V name) with | (Types.Tsig_value (_, val_desc)) -> val_desc.Types.val_type - | _ -> assert false + | _ -> assert false let search_exception table name = match Hashtbl.find table (E name) with | (Types.Tsig_exception (_, type_expr_list)) -> - type_expr_list - | _ -> assert false + type_expr_list + | _ -> assert false let search_type table name = match Hashtbl.find table (T name) with | (Types.Tsig_type (_, type_decl)) -> type_decl - | _ -> assert false + | _ -> assert false let search_class table name = match Hashtbl.find table (C name) with | (Types.Tsig_class (_, class_decl)) -> class_decl - | _ -> assert false + | _ -> assert false let search_class_type table name = match Hashtbl.find table (CT name) with | (Types.Tsig_cltype (_, cltype_decl)) -> cltype_decl - | _ -> assert false + | _ -> assert false let search_module table name = match Hashtbl.find table (M name) with | (Types.Tsig_module (ident, module_type)) -> module_type - | _ -> assert false + | _ -> assert false let search_module_type table name = match Hashtbl.find table (MT name) with | (Types.Tsig_modtype (_, Types.Tmodtype_manifest module_type)) -> - Some module_type + Some module_type | (Types.Tsig_modtype (_, Types.Tmodtype_abstract)) -> - None - | _ -> assert false + None + | _ -> assert false let search_attribute_type name class_sig = let (_, type_expr) = Types.Vars.find name class_sig.Types.cty_vars in type_expr - + let search_method_type name class_sig = let fields = Odoc_misc.get_fields class_sig.Types.cty_self in List.assoc name fields @@ -121,7 +121,7 @@ module type Info_retriever = val just_after_special : string -> string -> (int * Odoc_types.info option) val first_special : string -> string -> (int * Odoc_types.info option) val get_comments : - (Odoc_types.text -> 'a) -> string -> string -> (Odoc_types.info option * 'a list) + (Odoc_types.text -> 'a) -> string -> string -> (Odoc_types.info option * 'a list) end module Analyser = @@ -137,318 +137,318 @@ module Analyser = prepare_file must have been called to fill the file global variable.*) let get_string_of_file the_start the_end = try - let s = String.sub !file the_start (the_end-the_start) in - s + let s = String.sub !file the_start (the_end-the_start) in + s with - Invalid_argument _ -> - "" + Invalid_argument _ -> + "" (** This function loads the given file in the file global variable, and sets file_name.*) let prepare_file f input_f = try - let s = Odoc_misc.input_file_as_string input_f in - file := s; - file_name := f + let s = Odoc_misc.input_file_as_string input_f in + file := s; + file_name := f with - e -> - file := ""; - raise e + e -> + file := ""; + raise e (** The function used to get the comments in a class. *) let get_comments_in_class pos_start pos_end = My_ir.get_comments (fun t -> Class_comment t) - !file_name - (get_string_of_file pos_start pos_end) + !file_name + (get_string_of_file pos_start pos_end) (** The function used to get the comments in a module. *) let get_comments_in_module pos_start pos_end = My_ir.get_comments (fun t -> Element_module_comment t) - !file_name - (get_string_of_file pos_start pos_end) + !file_name + (get_string_of_file pos_start pos_end) let merge_infos = Odoc_merge.merge_info_opt Odoc_types.all_merge_options let name_comment_from_type_kind pos_start pos_end pos_limit tk = match tk with - Parsetree.Ptype_abstract -> - (0, []) + Parsetree.Ptype_abstract -> + (0, []) | Parsetree.Ptype_variant cons_core_type_list_list -> (*of (string * core_type list) list *) - let rec f acc last_pos cons_core_type_list_list = - match cons_core_type_list_list with - [] -> - (0, acc) - | (name, core_type_list) :: [] -> - let pos = Str.search_forward (Str.regexp_string name) !file last_pos in - let s = get_string_of_file pos_end pos_limit in - let (len, comment_opt) = My_ir.just_after_special !file_name s in - (len, acc @ [ (name, comment_opt) ]) + let rec f acc last_pos cons_core_type_list_list = + match cons_core_type_list_list with + [] -> + (0, acc) + | (name, core_type_list) :: [] -> + let pos = Str.search_forward (Str.regexp_string name) !file last_pos in + let s = get_string_of_file pos_end pos_limit in + let (len, comment_opt) = My_ir.just_after_special !file_name s in + (len, acc @ [ (name, comment_opt) ]) - | (name, core_type_list) :: (name2, core_type_list2) :: q -> - match (List.rev core_type_list, core_type_list2) with - ([], []) -> - let pos = Str.search_forward (Str.regexp_string name) !file last_pos in - let pos' = pos + (String.length name) in - let pos2 = Str.search_forward (Str.regexp_string name2) !file pos' in - let s = get_string_of_file pos' pos2 in - let (_,comment_opt) = My_ir.just_after_special !file_name s in - f (acc @ [name, comment_opt]) pos2 ((name2, core_type_list2) :: q) - - | ([], (ct2 :: _)) -> - let pos = Str.search_forward (Str.regexp_string name) !file last_pos in - let pos' = pos + (String.length name) in - let pos2 = ct2.Parsetree.ptyp_loc.Location.loc_start in - let pos2' = Str.search_backward (Str.regexp_string name2) !file pos2 in - let s = get_string_of_file pos' pos2' in - let (_,comment_opt) = My_ir.just_after_special !file_name s in - f (acc @ [name, comment_opt]) pos2' ((name2, core_type_list2) :: q) - - | ((ct :: _), _) -> - let pos = ct.Parsetree.ptyp_loc.Location.loc_end in - let pos2 = Str.search_forward (Str.regexp_string name2) !file pos in - let s = get_string_of_file pos pos2 in - let (_,comment_opt) = My_ir.just_after_special !file_name s in - let new_pos_end = - match comment_opt with - None -> ct.Parsetree.ptyp_loc.Location.loc_end - | Some _ -> Str.search_forward (Str.regexp "*)") !file pos - in - f (acc @ [name, comment_opt]) new_pos_end ((name2, core_type_list2) :: q) - in - f [] pos_start cons_core_type_list_list - + | (name, core_type_list) :: (name2, core_type_list2) :: q -> + match (List.rev core_type_list, core_type_list2) with + ([], []) -> + let pos = Str.search_forward (Str.regexp_string name) !file last_pos in + let pos' = pos + (String.length name) in + let pos2 = Str.search_forward (Str.regexp_string name2) !file pos' in + let s = get_string_of_file pos' pos2 in + let (_,comment_opt) = My_ir.just_after_special !file_name s in + f (acc @ [name, comment_opt]) pos2 ((name2, core_type_list2) :: q) + + | ([], (ct2 :: _)) -> + let pos = Str.search_forward (Str.regexp_string name) !file last_pos in + let pos' = pos + (String.length name) in + let pos2 = ct2.Parsetree.ptyp_loc.Location.loc_start in + let pos2' = Str.search_backward (Str.regexp_string name2) !file pos2 in + let s = get_string_of_file pos' pos2' in + let (_,comment_opt) = My_ir.just_after_special !file_name s in + f (acc @ [name, comment_opt]) pos2' ((name2, core_type_list2) :: q) + + | ((ct :: _), _) -> + let pos = ct.Parsetree.ptyp_loc.Location.loc_end in + let pos2 = Str.search_forward (Str.regexp_string name2) !file pos in + let s = get_string_of_file pos pos2 in + let (_,comment_opt) = My_ir.just_after_special !file_name s in + let new_pos_end = + match comment_opt with + None -> ct.Parsetree.ptyp_loc.Location.loc_end + | Some _ -> Str.search_forward (Str.regexp "*)") !file pos + in + f (acc @ [name, comment_opt]) new_pos_end ((name2, core_type_list2) :: q) + in + f [] pos_start cons_core_type_list_list + | Parsetree.Ptype_record name_mutable_type_list (* of (string * mutable_flag * core_type) list*) -> - let rec f = function - [] -> - [] - | (name, _, ct) :: [] -> - let pos = ct.Parsetree.ptyp_loc.Location.loc_end in - let s = get_string_of_file pos pos_end in - let (_,comment_opt) = My_ir.just_after_special !file_name s in - [name, comment_opt] - | (name,_,ct) :: ((name2,_,ct2) as ele2) :: q -> - let pos = ct.Parsetree.ptyp_loc.Location.loc_end in - let pos2 = ct2.Parsetree.ptyp_loc.Location.loc_start in - let s = get_string_of_file pos pos2 in - let (_,comment_opt) = My_ir.just_after_special !file_name s in - (name, comment_opt) :: (f (ele2 :: q)) - in - (0, f name_mutable_type_list) + let rec f = function + [] -> + [] + | (name, _, ct) :: [] -> + let pos = ct.Parsetree.ptyp_loc.Location.loc_end in + let s = get_string_of_file pos pos_end in + let (_,comment_opt) = My_ir.just_after_special !file_name s in + [name, comment_opt] + | (name,_,ct) :: ((name2,_,ct2) as ele2) :: q -> + let pos = ct.Parsetree.ptyp_loc.Location.loc_end in + let pos2 = ct2.Parsetree.ptyp_loc.Location.loc_start in + let s = get_string_of_file pos pos2 in + let (_,comment_opt) = My_ir.just_after_special !file_name s in + (name, comment_opt) :: (f (ele2 :: q)) + in + (0, f name_mutable_type_list) let get_type_kind env name_comment_list type_kind = match type_kind with - Types.Type_abstract -> - Odoc_type.Type_abstract + Types.Type_abstract -> + Odoc_type.Type_abstract | Types.Type_variant l -> - let f (constructor_name, type_expr_list) = - let comment_opt = - try - match List.assoc constructor_name name_comment_list with - None -> None - | Some d -> d.Odoc_types.i_desc - with Not_found -> None - in - { - vc_name = constructor_name ; - vc_args = List.map (Odoc_env.subst_type env) type_expr_list ; - vc_text = comment_opt - } - in - Odoc_type.Type_variant (List.map f l) + let f (constructor_name, type_expr_list) = + let comment_opt = + try + match List.assoc constructor_name name_comment_list with + None -> None + | Some d -> d.Odoc_types.i_desc + with Not_found -> None + in + { + vc_name = constructor_name ; + vc_args = List.map (Odoc_env.subst_type env) type_expr_list ; + vc_text = comment_opt + } + in + Odoc_type.Type_variant (List.map f l) | Types.Type_record (l, _) -> - let f (field_name, mutable_flag, type_expr) = - let comment_opt = - try - match List.assoc field_name name_comment_list with - None -> None - | Some d -> d.Odoc_types.i_desc - with Not_found -> None - in - { - rf_name = field_name ; - rf_mutable = mutable_flag = Mutable ; - rf_type = Odoc_env.subst_type env type_expr ; - rf_text = comment_opt - } - in - Odoc_type.Type_record (List.map f l) + let f (field_name, mutable_flag, type_expr) = + let comment_opt = + try + match List.assoc field_name name_comment_list with + None -> None + | Some d -> d.Odoc_types.i_desc + with Not_found -> None + in + { + rf_name = field_name ; + rf_mutable = mutable_flag = Mutable ; + rf_type = Odoc_env.subst_type env type_expr ; + rf_text = comment_opt + } + in + Odoc_type.Type_record (List.map f l) (** Analysis of the elements of a class, from the information in the parsetree and in the class signature. @return the couple (inherited_class list, elements).*) let analyse_class_elements env current_class_name last_pos pos_limit - class_type_field_list class_signature = + class_type_field_list class_signature = print_DEBUG "Types.Tcty_signature class_signature"; let f_DEBUG var (mutable_flag, type_exp) = print_DEBUG var in Types.Vars.iter f_DEBUG class_signature.Types.cty_vars; print_DEBUG ("Type de la classe "^current_class_name^" : "); print_DEBUG (Odoc_misc.string_of_type_expr class_signature.Types.cty_self); let get_pos_limit2 q = - match q with - [] -> pos_limit - | ele2 :: _ -> - match ele2 with - Parsetree.Pctf_val (_, _, _, loc) - | Parsetree.Pctf_virt (_, _, _, loc) - | Parsetree.Pctf_meth (_, _, _, loc) - | Parsetree.Pctf_cstr (_, _, loc) -> loc.Location.loc_start - | Parsetree.Pctf_inher class_type -> - class_type.Parsetree.pcty_loc.Location.loc_start + match q with + [] -> pos_limit + | ele2 :: _ -> + match ele2 with + Parsetree.Pctf_val (_, _, _, loc) + | Parsetree.Pctf_virt (_, _, _, loc) + | Parsetree.Pctf_meth (_, _, _, loc) + | Parsetree.Pctf_cstr (_, _, loc) -> loc.Location.loc_start + | Parsetree.Pctf_inher class_type -> + class_type.Parsetree.pcty_loc.Location.loc_start in let get_method name comment_opt private_flag loc q = - let complete_name = Name.concat current_class_name name in - let typ = - try Signature_search.search_method_type name class_signature - with Not_found -> - raise (Failure (Odoc_messages.method_type_not_found current_class_name name)) - in - let subst_typ = Odoc_env.subst_type env typ in - let met = - { - met_value = - { - val_name = complete_name ; - val_info = comment_opt ; - val_type = subst_typ ; - val_recursive = false ; - val_parameters = Odoc_value.dummy_parameter_list subst_typ ; - val_code = None ; - val_loc = { loc_impl = None ; loc_inter = Some (!file_name, loc.Location.loc_start) }; - } ; - met_private = private_flag = Asttypes.Private ; - met_virtual = false ; - } - in - let pos_limit2 = get_pos_limit2 q in - let pos_end = loc.Location.loc_end in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end pos_limit2) - in - met.met_value.val_info <- merge_infos met.met_value.val_info info_after_opt ; - (* update the parameter description *) - Odoc_value.update_value_parameters_text met.met_value; + let complete_name = Name.concat current_class_name name in + let typ = + try Signature_search.search_method_type name class_signature + with Not_found -> + raise (Failure (Odoc_messages.method_type_not_found current_class_name name)) + in + let subst_typ = Odoc_env.subst_type env typ in + let met = + { + met_value = + { + val_name = complete_name ; + val_info = comment_opt ; + val_type = subst_typ ; + val_recursive = false ; + val_parameters = Odoc_value.dummy_parameter_list subst_typ ; + val_code = None ; + val_loc = { loc_impl = None ; loc_inter = Some (!file_name, loc.Location.loc_start) }; + } ; + met_private = private_flag = Asttypes.Private ; + met_virtual = false ; + } + in + let pos_limit2 = get_pos_limit2 q in + let pos_end = loc.Location.loc_end in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + met.met_value.val_info <- merge_infos met.met_value.val_info info_after_opt ; + (* update the parameter description *) + Odoc_value.update_value_parameters_text met.met_value; - (met, maybe_more) + (met, maybe_more) in let rec f last_pos class_type_field_list = - match class_type_field_list with - [] -> - let s = get_string_of_file last_pos pos_limit in - let (_, ele_coms) = My_ir.all_special !file_name s in - let ele_comments = - List.fold_left - (fun acc -> fun sc -> - match sc.Odoc_types.i_desc with - None -> - acc - | Some t -> - acc @ [Class_comment t]) - [] - ele_coms - in - ([], ele_comments) + match class_type_field_list with + [] -> + let s = get_string_of_file last_pos pos_limit in + let (_, ele_coms) = My_ir.all_special !file_name s in + let ele_comments = + List.fold_left + (fun acc -> fun sc -> + match sc.Odoc_types.i_desc with + None -> + acc + | Some t -> + acc @ [Class_comment t]) + [] + ele_coms + in + ([], ele_comments) - | Parsetree.Pctf_val (name, mutable_flag, _, loc) :: q -> - (* of (string * mutable_flag * core_type option * Location.t)*) - let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start in - let complete_name = Name.concat current_class_name name in - let typ = - try Signature_search.search_attribute_type name class_signature - with Not_found -> - raise (Failure (Odoc_messages.attribute_type_not_found current_class_name name)) - in - let subst_typ = Odoc_env.subst_type env typ in - let att = - { - att_value = - { - val_name = complete_name ; - val_info = comment_opt ; - val_type = subst_typ; - val_recursive = false ; - val_parameters = [] ; - val_code = None ; - val_loc = { loc_impl = None ; loc_inter = Some (!file_name, loc.Location.loc_start)} ; - } ; - att_mutable = mutable_flag = Asttypes.Mutable ; - } - in - let pos_limit2 = get_pos_limit2 q in - let pos_end = loc.Location.loc_end in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end pos_limit2) - in - att.att_value.val_info <- merge_infos att.att_value.val_info info_after_opt ; - let (inher_l, eles) = f (pos_end + maybe_more) q in - (inher_l, eles_comments @ ((Class_attribute att) :: eles)) + | Parsetree.Pctf_val (name, mutable_flag, _, loc) :: q -> + (* of (string * mutable_flag * core_type option * Location.t)*) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start in + let complete_name = Name.concat current_class_name name in + let typ = + try Signature_search.search_attribute_type name class_signature + with Not_found -> + raise (Failure (Odoc_messages.attribute_type_not_found current_class_name name)) + in + let subst_typ = Odoc_env.subst_type env typ in + let att = + { + att_value = + { + val_name = complete_name ; + val_info = comment_opt ; + val_type = subst_typ; + val_recursive = false ; + val_parameters = [] ; + val_code = None ; + val_loc = { loc_impl = None ; loc_inter = Some (!file_name, loc.Location.loc_start)} ; + } ; + att_mutable = mutable_flag = Asttypes.Mutable ; + } + in + let pos_limit2 = get_pos_limit2 q in + let pos_end = loc.Location.loc_end in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + att.att_value.val_info <- merge_infos att.att_value.val_info info_after_opt ; + let (inher_l, eles) = f (pos_end + maybe_more) q in + (inher_l, eles_comments @ ((Class_attribute att) :: eles)) - | Parsetree.Pctf_virt (name, private_flag, _, loc) :: q -> - (* of (string * private_flag * core_type * Location.t) *) - let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start in - let (met, maybe_more) = get_method name comment_opt private_flag loc q in - let met2 = { met with met_virtual = true } in - let (inher_l, eles) = f (loc.Location.loc_end + maybe_more) q in - (inher_l, eles_comments @ ((Class_method met2) :: eles)) + | Parsetree.Pctf_virt (name, private_flag, _, loc) :: q -> + (* of (string * private_flag * core_type * Location.t) *) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start in + let (met, maybe_more) = get_method name comment_opt private_flag loc q in + let met2 = { met with met_virtual = true } in + let (inher_l, eles) = f (loc.Location.loc_end + maybe_more) q in + (inher_l, eles_comments @ ((Class_method met2) :: eles)) - | Parsetree.Pctf_meth (name, private_flag, _, loc) :: q -> - (* of (string * private_flag * core_type * Location.t) *) - let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start in - let (met, maybe_more) = get_method name comment_opt private_flag loc q in - let (inher_l, eles) = f (loc.Location.loc_end + maybe_more) q in - (inher_l, eles_comments @ ((Class_method met) :: eles)) + | Parsetree.Pctf_meth (name, private_flag, _, loc) :: q -> + (* of (string * private_flag * core_type * Location.t) *) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start in + let (met, maybe_more) = get_method name comment_opt private_flag loc q in + let (inher_l, eles) = f (loc.Location.loc_end + maybe_more) q in + (inher_l, eles_comments @ ((Class_method met) :: eles)) - | (Parsetree.Pctf_cstr (_, _, loc)) :: q -> - (* of (core_type * core_type * Location.t) *) - (* A VOIR : cela correspond aux contraintes, non ? on ne les garde pas pour l'instant *) - let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start in - let (inher_l, eles) = f loc.Location.loc_end q in - (inher_l, eles_comments @ eles) + | (Parsetree.Pctf_cstr (_, _, loc)) :: q -> + (* of (core_type * core_type * Location.t) *) + (* A VOIR : cela correspond aux contraintes, non ? on ne les garde pas pour l'instant *) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start in + let (inher_l, eles) = f loc.Location.loc_end q in + (inher_l, eles_comments @ eles) - | Parsetree.Pctf_inher class_type :: q -> - let loc = class_type.Parsetree.pcty_loc in - let (comment_opt, eles_comments) = - get_comments_in_class last_pos loc.Location.loc_start - in - let pos_limit2 = get_pos_limit2 q in - let pos_end = loc.Location.loc_end in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end pos_limit2) - in - let comment_opt2 = merge_infos comment_opt info_after_opt in - let text_opt = match comment_opt2 with None -> None | Some i -> i.Odoc_types.i_desc in - let inh = - match class_type.Parsetree.pcty_desc with - Parsetree.Pcty_constr (longident, _) -> - (*of Longident.t * core_type list*) - let name = Name.from_longident longident in - let ic = - { - ic_name = Odoc_env.full_class_or_class_type_name env name ; - ic_class = None ; - ic_text = text_opt ; - } - in - ic + | Parsetree.Pctf_inher class_type :: q -> + let loc = class_type.Parsetree.pcty_loc in + let (comment_opt, eles_comments) = + get_comments_in_class last_pos loc.Location.loc_start + in + let pos_limit2 = get_pos_limit2 q in + let pos_end = loc.Location.loc_end in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + let comment_opt2 = merge_infos comment_opt info_after_opt in + let text_opt = match comment_opt2 with None -> None | Some i -> i.Odoc_types.i_desc in + let inh = + match class_type.Parsetree.pcty_desc with + Parsetree.Pcty_constr (longident, _) -> + (*of Longident.t * core_type list*) + let name = Name.from_longident longident in + let ic = + { + ic_name = Odoc_env.full_class_or_class_type_name env name ; + ic_class = None ; + ic_text = text_opt ; + } + in + ic - | Parsetree.Pcty_signature _ - | Parsetree.Pcty_fun _ -> - (* we don't have a name for the class signature, so we call it "object ... end" *) - { - ic_name = Odoc_messages.object_end ; - ic_class = None ; - ic_text = text_opt ; - } - in - let (inher_l, eles) = f (pos_end + maybe_more) q in - (inh :: inher_l , eles_comments @ eles) + | Parsetree.Pcty_signature _ + | Parsetree.Pcty_fun _ -> + (* we don't have a name for the class signature, so we call it "object ... end" *) + { + ic_name = Odoc_messages.object_end ; + ic_class = None ; + ic_text = text_opt ; + } + in + let (inher_l, eles) = f (pos_end + maybe_more) q in + (inh :: inher_l , eles_comments @ eles) in f last_pos class_type_field_list @@ -459,762 +459,762 @@ module Analyser = 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 - [] -> - let s = get_string_of_file last_pos pos_limit in - let (_, ele_coms) = My_ir.all_special !file_name s in - let ele_comments = - List.fold_left - (fun acc -> fun sc -> - match sc.Odoc_types.i_desc with - None -> - acc - | Some t -> - acc @ [Element_module_comment t]) - [] - ele_coms - in - acc_eles @ ele_comments + [] -> + let s = get_string_of_file last_pos pos_limit in + let (_, ele_coms) = My_ir.all_special !file_name s in + let ele_comments = + List.fold_left + (fun acc -> fun sc -> + match sc.Odoc_types.i_desc with + None -> + acc + | Some t -> + acc @ [Element_module_comment t]) + [] + ele_coms + in + acc_eles @ ele_comments - | ele :: q -> - let (assoc_com, ele_comments) = get_comments_in_module - last_pos - ele.Parsetree.psig_loc.Location.loc_start - in - let (maybe_more, new_env, elements) = analyse_signature_item_desc - acc_env - signat - table - current_module_name - ele.Parsetree.psig_loc.Location.loc_start - ele.Parsetree.psig_loc.Location.loc_end - (match q with - [] -> pos_limit - | ele2 :: _ -> ele2.Parsetree.psig_loc.Location.loc_start - ) - assoc_com - ele.Parsetree.psig_desc - in - f (acc_eles @ (ele_comments @ elements)) - new_env - (ele.Parsetree.psig_loc.Location.loc_end + maybe_more) + | ele :: q -> + let (assoc_com, ele_comments) = get_comments_in_module + last_pos + ele.Parsetree.psig_loc.Location.loc_start + in + let (maybe_more, new_env, elements) = analyse_signature_item_desc + acc_env + signat + table + current_module_name + ele.Parsetree.psig_loc.Location.loc_start + ele.Parsetree.psig_loc.Location.loc_end + (match q with + [] -> pos_limit + | ele2 :: _ -> ele2.Parsetree.psig_loc.Location.loc_start + ) + assoc_com + ele.Parsetree.psig_desc + in + f (acc_eles @ (ele_comments @ elements)) + new_env + (ele.Parsetree.psig_loc.Location.loc_end + maybe_more) (* for the comments of constructors in types, - which are after the constructor definition and can - go beyond ele.Parsetree.psig_loc.Location.loc_end *) - q + which are after the constructor definition and can + go beyond ele.Parsetree.psig_loc.Location.loc_end *) + q in f [] env last_pos sig_item_list (** 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 = - match sig_item_desc with - Parsetree.Psig_value (name_pre, value_desc) -> - let type_expr = - try Signature_search.search_value table name_pre - with Not_found -> - raise (Failure (Odoc_messages.value_not_found current_module_name name_pre)) - in - let name = Name.parens_if_infix name_pre in - let subst_typ = Odoc_env.subst_type env type_expr in - let v = - { - val_name = Name.concat current_module_name name ; - val_info = comment_opt ; - val_type = subst_typ ; - val_recursive = false ; - val_parameters = Odoc_value.dummy_parameter_list subst_typ ; - val_code = None ; - val_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele)} - } - in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end_ele pos_limit) - in - v.val_info <- merge_infos v.val_info info_after_opt ; - (* update the parameter description *) - Odoc_value.update_value_parameters_text v; + 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 = + try Signature_search.search_value table name_pre + with Not_found -> + raise (Failure (Odoc_messages.value_not_found current_module_name name_pre)) + in + let name = Name.parens_if_infix name_pre in + let subst_typ = Odoc_env.subst_type env type_expr in + let v = + { + val_name = Name.concat current_module_name name ; + val_info = comment_opt ; + val_type = subst_typ ; + val_recursive = false ; + val_parameters = Odoc_value.dummy_parameter_list subst_typ ; + val_code = None ; + val_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele)} + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + v.val_info <- merge_infos v.val_info info_after_opt ; + (* update the parameter description *) + Odoc_value.update_value_parameters_text v; - let new_env = Odoc_env.add_value env v.val_name in - (maybe_more, new_env, [ Element_value v ]) + let new_env = Odoc_env.add_value env v.val_name in + (maybe_more, new_env, [ Element_value v ]) - | Parsetree.Psig_exception (name, exception_decl) -> - let types_excep_decl = - try Signature_search.search_exception table name - with Not_found -> - raise (Failure (Odoc_messages.exception_not_found current_module_name name)) - in - let e = - { - ex_name = Name.concat current_module_name name ; - ex_info = comment_opt ; - ex_args = List.map (Odoc_env.subst_type env) types_excep_decl ; - ex_alias = None ; - ex_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } - } - in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end_ele pos_limit) - in - e.ex_info <- merge_infos e.ex_info info_after_opt ; - let new_env = Odoc_env.add_exception env e.ex_name in - (maybe_more, new_env, [ Element_exception e ]) + | Parsetree.Psig_exception (name, exception_decl) -> + let types_excep_decl = + try Signature_search.search_exception table name + with Not_found -> + raise (Failure (Odoc_messages.exception_not_found current_module_name name)) + in + let e = + { + ex_name = Name.concat current_module_name name ; + ex_info = comment_opt ; + ex_args = List.map (Odoc_env.subst_type env) types_excep_decl ; + ex_alias = None ; + ex_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + e.ex_info <- merge_infos e.ex_info info_after_opt ; + let new_env = Odoc_env.add_exception env e.ex_name in + (maybe_more, new_env, [ Element_exception e ]) - | Parsetree.Psig_type name_type_decl_list -> - (* we start by extending the environment *) - let new_env = - List.fold_left - (fun acc_env -> fun (name, _) -> - let complete_name = Name.concat current_module_name name in - Odoc_env.add_type acc_env complete_name - ) - env - name_type_decl_list - in - let rec f ?(first=false) acc_maybe_more last_pos name_type_decl_list = - match name_type_decl_list with - [] -> - (acc_maybe_more, []) - | (name, type_decl) :: q -> - let (assoc_com, ele_comments) = - if first then - (comment_opt, []) - else - get_comments_in_module - last_pos - type_decl.Parsetree.ptype_loc.Location.loc_start - in - let pos_limit2 = - match q with - [] -> pos_limit - | (_, td) :: _ -> td.Parsetree.ptype_loc.Location.loc_start - in - let (maybe_more, name_comment_list) = - name_comment_from_type_kind - type_decl.Parsetree.ptype_loc.Location.loc_start - type_decl.Parsetree.ptype_loc.Location.loc_end - pos_limit2 - type_decl.Parsetree.ptype_kind - in - print_DEBUG ("Type "^name^" : "^(match assoc_com with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c)); - let f_DEBUG (name, c_opt) = print_DEBUG ("constructor/field "^name^": "^(match c_opt with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c)) in - List.iter f_DEBUG name_comment_list; - (* get the information for the type in the signature *) - let sig_type_decl = - try Signature_search.search_type table name - with Not_found -> - raise (Failure (Odoc_messages.type_not_found current_module_name name)) - in - (* get the type kind with the associated comments *) - let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in - (* associate the comments to each constructor and build the [Type.t_type] *) - let new_type = - { - ty_name = Name.concat current_module_name name ; - ty_info = assoc_com ; - ty_parameters = List.map (Odoc_env.subst_type new_env) sig_type_decl.Types.type_params ; - ty_kind = type_kind ; - ty_manifest = - (match sig_type_decl.Types.type_manifest with - None -> None - | Some t -> Some (Odoc_env.subst_type new_env t)); - ty_loc = - { loc_impl = None ; - loc_inter = Some (!file_name,type_decl.Parsetree.ptype_loc.Location.loc_start) - }; - } - in - let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end + maybe_more in - let (maybe_more2, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file new_end pos_limit2) - in - new_type.ty_info <- merge_infos new_type.ty_info info_after_opt ; - let (new_maybe_more, eles) = f - (maybe_more + maybe_more2) - (new_end + maybe_more2) - q - in - (new_maybe_more, (ele_comments @ [Element_type new_type]) @ eles) - in - 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 *) - let ele_comments = match comment_opt with - None -> [] - | Some i -> - match i.i_desc with - None -> [] - | Some t -> [Element_module_comment t] - in - (0, env, ele_comments) + | Parsetree.Psig_type name_type_decl_list -> + (* we start by extending the environment *) + let new_env = + List.fold_left + (fun acc_env -> fun (name, _) -> + let complete_name = Name.concat current_module_name name in + Odoc_env.add_type acc_env complete_name + ) + env + name_type_decl_list + in + let rec f ?(first=false) acc_maybe_more last_pos name_type_decl_list = + match name_type_decl_list with + [] -> + (acc_maybe_more, []) + | (name, type_decl) :: q -> + let (assoc_com, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module + last_pos + type_decl.Parsetree.ptype_loc.Location.loc_start + in + let pos_limit2 = + match q with + [] -> pos_limit + | (_, td) :: _ -> td.Parsetree.ptype_loc.Location.loc_start + in + let (maybe_more, name_comment_list) = + name_comment_from_type_kind + type_decl.Parsetree.ptype_loc.Location.loc_start + type_decl.Parsetree.ptype_loc.Location.loc_end + pos_limit2 + type_decl.Parsetree.ptype_kind + in + print_DEBUG ("Type "^name^" : "^(match assoc_com with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c)); + let f_DEBUG (name, c_opt) = print_DEBUG ("constructor/field "^name^": "^(match c_opt with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c)) in + List.iter f_DEBUG name_comment_list; + (* get the information for the type in the signature *) + let sig_type_decl = + try Signature_search.search_type table name + with Not_found -> + raise (Failure (Odoc_messages.type_not_found current_module_name name)) + in + (* get the type kind with the associated comments *) + let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in + (* associate the comments to each constructor and build the [Type.t_type] *) + let new_type = + { + ty_name = Name.concat current_module_name name ; + ty_info = assoc_com ; + ty_parameters = List.map (Odoc_env.subst_type new_env) sig_type_decl.Types.type_params ; + ty_kind = type_kind ; + ty_manifest = + (match sig_type_decl.Types.type_manifest with + None -> None + | Some t -> Some (Odoc_env.subst_type new_env t)); + ty_loc = + { loc_impl = None ; + loc_inter = Some (!file_name,type_decl.Parsetree.ptype_loc.Location.loc_start) + }; + } + in + let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end + maybe_more in + let (maybe_more2, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file new_end pos_limit2) + in + new_type.ty_info <- merge_infos new_type.ty_info info_after_opt ; + let (new_maybe_more, eles) = f + (maybe_more + maybe_more2) + (new_end + maybe_more2) + q + in + (new_maybe_more, (ele_comments @ [Element_type new_type]) @ eles) + in + 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 *) + let ele_comments = match comment_opt with + None -> [] + | Some i -> + match i.i_desc with + None -> [] + | Some t -> [Element_module_comment t] + in + (0, env, ele_comments) - | Parsetree.Psig_module (name, module_type) -> - let complete_name = Name.concat current_module_name name in - (* get the the module type in the signature by the module name *) - let sig_module_type = - try Signature_search.search_module table name - 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 new_module = - { - m_name = complete_name ; - m_type = sig_module_type; - m_info = comment_opt ; - m_is_interface = true ; - m_file = !file_name ; - m_kind = module_kind ; - m_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; - m_top_deps = [] ; - } - in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end_ele pos_limit) - in - new_module.m_info <- merge_infos new_module.m_info info_after_opt ; - let new_env = Odoc_env.add_module env new_module.m_name in - let new_env2 = - match new_module.m_type with (* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *) - Types.Tmty_signature s -> Odoc_env.add_signature new_env new_module.m_name ~rel: (Name.simple new_module.m_name) s - | _ -> new_env - in - (maybe_more, new_env2, [ Element_module new_module ]) + | Parsetree.Psig_module (name, module_type) -> + let complete_name = Name.concat current_module_name name in + (* get the the module type in the signature by the module name *) + let sig_module_type = + try Signature_search.search_module table name + 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 new_module = + { + m_name = complete_name ; + m_type = sig_module_type; + m_info = comment_opt ; + m_is_interface = true ; + m_file = !file_name ; + m_kind = module_kind ; + m_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + m_top_deps = [] ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + new_module.m_info <- merge_infos new_module.m_info info_after_opt ; + let new_env = Odoc_env.add_module env new_module.m_name in + let new_env2 = + match new_module.m_type with (* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *) + Types.Tmty_signature s -> Odoc_env.add_signature new_env new_module.m_name ~rel: (Name.simple new_module.m_name) s + | _ -> new_env + in + (maybe_more, new_env2, [ Element_module new_module ]) | Parsetree.Psig_modtype (name, Parsetree.Pmodtype_abstract) -> - let sig_mtype = - try Signature_search.search_module_type table name - with Not_found -> - raise (Failure (Odoc_messages.module_type_not_found current_module_name name)) - in - let complete_name = Name.concat current_module_name name in - let mt = - { - mt_name = complete_name ; - mt_info = comment_opt ; - mt_type = sig_mtype ; - mt_is_interface = true ; - mt_file = !file_name ; - mt_kind = None ; - mt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; - } - in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end_ele pos_limit) - in - mt.mt_info <- merge_infos mt.mt_info info_after_opt ; - let new_env = Odoc_env.add_module_type env mt.mt_name in - (maybe_more, new_env, [ Element_module_type mt ]) + let sig_mtype = + try Signature_search.search_module_type table name + with Not_found -> + raise (Failure (Odoc_messages.module_type_not_found current_module_name name)) + in + let complete_name = Name.concat current_module_name name in + let mt = + { + mt_name = complete_name ; + mt_info = comment_opt ; + mt_type = sig_mtype ; + mt_is_interface = true ; + mt_file = !file_name ; + mt_kind = None ; + mt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + mt.mt_info <- merge_infos mt.mt_info info_after_opt ; + let new_env = Odoc_env.add_module_type env mt.mt_name in + (maybe_more, new_env, [ Element_module_type mt ]) - | Parsetree.Psig_modtype (name, Parsetree.Pmodtype_manifest module_type) -> - let complete_name = Name.concat current_module_name name in - let sig_mtype_opt = - try Signature_search.search_module_type table name - with Not_found -> - raise (Failure (Odoc_messages.module_type_not_found current_module_name name)) - 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) - | None -> None - in - let mt = - { - mt_name = complete_name ; - mt_info = comment_opt ; - mt_type = sig_mtype_opt ; - mt_is_interface = true ; - mt_file = !file_name ; - mt_kind = module_type_kind ; - mt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; - } - in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end_ele pos_limit) - in - mt.mt_info <- merge_infos mt.mt_info info_after_opt ; - let new_env = Odoc_env.add_module_type env mt.mt_name in - let new_env2 = - match sig_mtype_opt with (* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *) - Some (Types.Tmty_signature s) -> Odoc_env.add_signature new_env mt.mt_name ~rel: (Name.simple mt.mt_name) s - | _ -> new_env - in - (maybe_more, new_env2, [ Element_module_type mt ]) + | Parsetree.Psig_modtype (name, Parsetree.Pmodtype_manifest module_type) -> + let complete_name = Name.concat current_module_name name in + let sig_mtype_opt = + try Signature_search.search_module_type table name + with Not_found -> + raise (Failure (Odoc_messages.module_type_not_found current_module_name name)) + 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) + | None -> None + in + let mt = + { + mt_name = complete_name ; + mt_info = comment_opt ; + mt_type = sig_mtype_opt ; + mt_is_interface = true ; + mt_file = !file_name ; + mt_kind = module_type_kind ; + mt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + mt.mt_info <- merge_infos mt.mt_info info_after_opt ; + let new_env = Odoc_env.add_module_type env mt.mt_name in + let new_env2 = + match sig_mtype_opt with (* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *) + Some (Types.Tmty_signature s) -> Odoc_env.add_signature new_env mt.mt_name ~rel: (Name.simple mt.mt_name) s + | _ -> new_env + in + (maybe_more, new_env2, [ Element_module_type mt ]) - | Parsetree.Psig_include module_type -> - let rec f = function - Parsetree.Pmty_ident longident -> - Name.from_longident longident - | Parsetree.Pmty_signature _ -> - "??" - | Parsetree.Pmty_functor _ -> - "??" - | Parsetree.Pmty_with (mt, _) -> - f mt.Parsetree.pmty_desc - in - let im = - { - im_name = Odoc_env.full_module_or_module_type_name env (f module_type.Parsetree.pmty_desc) ; - im_module = None ; - } - in - (0, env, [ Element_included_module im ]) (* A VOIR : �tendre l'environnement ? avec quoi ? *) + | Parsetree.Psig_include module_type -> + let rec f = function + Parsetree.Pmty_ident longident -> + Name.from_longident longident + | Parsetree.Pmty_signature _ -> + "??" + | Parsetree.Pmty_functor _ -> + "??" + | Parsetree.Pmty_with (mt, _) -> + f mt.Parsetree.pmty_desc + in + let im = + { + im_name = Odoc_env.full_module_or_module_type_name env (f module_type.Parsetree.pmty_desc) ; + im_module = None ; + } + in + (0, env, [ Element_included_module im ]) (* A VOIR : �tendre l'environnement ? avec quoi ? *) - | Parsetree.Psig_class class_description_list -> - (* we start by extending the environment *) - let new_env = - List.fold_left - (fun acc_env -> fun class_desc -> - let complete_name = Name.concat current_module_name class_desc.Parsetree.pci_name in - Odoc_env.add_class acc_env complete_name - ) - env - class_description_list - in - let rec f ?(first=false) acc_maybe_more last_pos class_description_list = - match class_description_list with - [] -> - (acc_maybe_more, []) - | class_desc :: q -> - let (assoc_com, ele_comments) = - if first then - (comment_opt, []) - else - get_comments_in_module - last_pos - class_desc.Parsetree.pci_loc.Location.loc_start - in - let pos_end = class_desc.Parsetree.pci_loc.Location.loc_end in - let pos_limit2 = - match q with - [] -> pos_limit - | cd :: _ -> cd.Parsetree.pci_loc.Location.loc_start - in - let name = class_desc.Parsetree.pci_name in - let complete_name = Name.concat current_module_name name in - let sig_class_decl = - try Signature_search.search_class table name - with Not_found -> - raise (Failure (Odoc_messages.class_not_found current_module_name name)) - in - let sig_class_type = sig_class_decl.Types.cty_type in - let (parameters, class_kind) = - analyse_class_kind - new_env - complete_name - class_desc.Parsetree.pci_loc.Location.loc_start - class_desc.Parsetree.pci_expr - sig_class_type - in - let new_class = - { - cl_name = complete_name ; - cl_info = assoc_com ; - cl_type = Odoc_env.subst_class_type env sig_class_type ; - cl_type_parameters = sig_class_decl.Types.cty_params; - cl_virtual = class_desc.Parsetree.pci_virt = Asttypes.Virtual ; - cl_kind = class_kind ; - cl_parameters = parameters ; - cl_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; - } - in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end pos_limit2) - in - new_class.cl_info <- merge_infos new_class.cl_info info_after_opt ; - Odoc_class.class_update_parameters_text new_class ; - let (new_maybe_more, eles) = - f maybe_more (pos_end + maybe_more) q - in - (new_maybe_more, - ele_comments @ (( Element_class new_class ) :: eles)) - in - let (maybe_more, eles) = - f ~first: true 0 pos_start_ele class_description_list - in - (maybe_more, new_env, eles) + | Parsetree.Psig_class class_description_list -> + (* we start by extending the environment *) + let new_env = + List.fold_left + (fun acc_env -> fun class_desc -> + let complete_name = Name.concat current_module_name class_desc.Parsetree.pci_name in + Odoc_env.add_class acc_env complete_name + ) + env + class_description_list + in + let rec f ?(first=false) acc_maybe_more last_pos class_description_list = + match class_description_list with + [] -> + (acc_maybe_more, []) + | class_desc :: q -> + let (assoc_com, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module + last_pos + class_desc.Parsetree.pci_loc.Location.loc_start + in + let pos_end = class_desc.Parsetree.pci_loc.Location.loc_end in + let pos_limit2 = + match q with + [] -> pos_limit + | cd :: _ -> cd.Parsetree.pci_loc.Location.loc_start + in + let name = class_desc.Parsetree.pci_name in + let complete_name = Name.concat current_module_name name in + let sig_class_decl = + try Signature_search.search_class table name + with Not_found -> + raise (Failure (Odoc_messages.class_not_found current_module_name name)) + in + let sig_class_type = sig_class_decl.Types.cty_type in + let (parameters, class_kind) = + analyse_class_kind + new_env + complete_name + class_desc.Parsetree.pci_loc.Location.loc_start + class_desc.Parsetree.pci_expr + sig_class_type + in + let new_class = + { + cl_name = complete_name ; + cl_info = assoc_com ; + cl_type = Odoc_env.subst_class_type env sig_class_type ; + cl_type_parameters = sig_class_decl.Types.cty_params; + cl_virtual = class_desc.Parsetree.pci_virt = Asttypes.Virtual ; + cl_kind = class_kind ; + cl_parameters = parameters ; + cl_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + new_class.cl_info <- merge_infos new_class.cl_info info_after_opt ; + Odoc_class.class_update_parameters_text new_class ; + let (new_maybe_more, eles) = + f maybe_more (pos_end + maybe_more) q + in + (new_maybe_more, + ele_comments @ (( Element_class new_class ) :: eles)) + in + let (maybe_more, eles) = + f ~first: true 0 pos_start_ele class_description_list + in + (maybe_more, new_env, eles) - | Parsetree.Psig_class_type class_type_declaration_list -> + | Parsetree.Psig_class_type class_type_declaration_list -> (* we start by extending the environment *) - let new_env = - List.fold_left - (fun acc_env -> fun class_type_decl -> - let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name in - Odoc_env.add_class_type acc_env complete_name - ) - env - class_type_declaration_list - in - let rec f ?(first=false) acc_maybe_more last_pos class_type_description_list = - match class_type_description_list with - [] -> - (acc_maybe_more, []) - | ct_decl :: q -> - let (assoc_com, ele_comments) = - if first then - (comment_opt, []) - else - get_comments_in_module - last_pos - ct_decl.Parsetree.pci_loc.Location.loc_start - in - let pos_end = ct_decl.Parsetree.pci_loc.Location.loc_end in - let pos_limit2 = - match q with - [] -> pos_limit - | ct_decl2 :: _ -> ct_decl2.Parsetree.pci_loc.Location.loc_start - in - let name = ct_decl.Parsetree.pci_name in - let complete_name = Name.concat current_module_name name in - let sig_cltype_decl = - try Signature_search.search_class_type table name - with Not_found -> - raise (Failure (Odoc_messages.class_type_not_found current_module_name name)) - in - let sig_class_type = sig_cltype_decl.Types.clty_type in - let kind = analyse_class_type_kind - new_env - complete_name - ct_decl.Parsetree.pci_loc.Location.loc_start - ct_decl.Parsetree.pci_expr - sig_class_type - in - let ct = - { - clt_name = complete_name ; - clt_info = assoc_com ; - clt_type = Odoc_env.subst_class_type env sig_class_type ; - clt_type_parameters = sig_cltype_decl.clty_params ; - clt_virtual = ct_decl.Parsetree.pci_virt = Asttypes.Virtual ; - clt_kind = kind ; - clt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; - } - in - let (maybe_more, info_after_opt) = - My_ir.just_after_special - !file_name - (get_string_of_file pos_end pos_limit2) - in - ct.clt_info <- merge_infos ct.clt_info info_after_opt ; - let (new_maybe_more, eles) = - f maybe_more (pos_end + maybe_more) q - in - (new_maybe_more, - ele_comments @ (( Element_class_type ct) :: eles)) - in - let (maybe_more, eles) = - f ~first: true 0 pos_start_ele class_type_declaration_list - in - (maybe_more, new_env, eles) + let new_env = + List.fold_left + (fun acc_env -> fun class_type_decl -> + let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name in + Odoc_env.add_class_type acc_env complete_name + ) + env + class_type_declaration_list + in + let rec f ?(first=false) acc_maybe_more last_pos class_type_description_list = + match class_type_description_list with + [] -> + (acc_maybe_more, []) + | ct_decl :: q -> + let (assoc_com, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module + last_pos + ct_decl.Parsetree.pci_loc.Location.loc_start + in + let pos_end = ct_decl.Parsetree.pci_loc.Location.loc_end in + let pos_limit2 = + match q with + [] -> pos_limit + | ct_decl2 :: _ -> ct_decl2.Parsetree.pci_loc.Location.loc_start + in + let name = ct_decl.Parsetree.pci_name in + let complete_name = Name.concat current_module_name name in + let sig_cltype_decl = + try Signature_search.search_class_type table name + with Not_found -> + raise (Failure (Odoc_messages.class_type_not_found current_module_name name)) + in + let sig_class_type = sig_cltype_decl.Types.clty_type in + let kind = analyse_class_type_kind + new_env + complete_name + ct_decl.Parsetree.pci_loc.Location.loc_start + ct_decl.Parsetree.pci_expr + sig_class_type + in + let ct = + { + clt_name = complete_name ; + clt_info = assoc_com ; + clt_type = Odoc_env.subst_class_type env sig_class_type ; + clt_type_parameters = sig_cltype_decl.clty_params ; + clt_virtual = ct_decl.Parsetree.pci_virt = Asttypes.Virtual ; + clt_kind = kind ; + clt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + ct.clt_info <- merge_infos ct.clt_info info_after_opt ; + let (new_maybe_more, eles) = + f maybe_more (pos_end + maybe_more) q + in + (new_maybe_more, + ele_comments @ (( Element_class_type ct) :: eles)) + in + let (maybe_more, eles) = + f ~first: true 0 pos_start_ele class_type_declaration_list + in + (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 = match module_type.Parsetree.pmty_desc with - Parsetree.Pmty_ident longident -> - let name = - match sig_module_type with - Types.Tmty_ident path -> Name.from_path path - | _ -> Name.from_longident longident + Parsetree.Pmty_ident longident -> + let name = + match sig_module_type with + Types.Tmty_ident path -> Name.from_path path + | _ -> Name.from_longident longident (* A VOIR cela arrive quand on fait module type F : functor ... -> Toto, Toto n'est pas un ident mais une structure *) - in - Module_type_alias { mta_name = Odoc_env.full_module_type_name env name ; - mta_module = None } + in + Module_type_alias { mta_name = Odoc_env.full_module_type_name env name ; + mta_module = None } | Parsetree.Pmty_signature ast -> - ( + ( (* we must have a signature in the module type *) - match sig_module_type with - Types.Tmty_signature signat -> - let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start in - let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end 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") - ) - + match sig_module_type with + Types.Tmty_signature signat -> + let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start in + let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end 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") + ) + | Parsetree.Pmty_functor (_,_, module_type2) -> - ( - match sig_module_type with - Types.Tmty_functor (ident, param_module_type, body_module_type) -> - let param = - { - mp_name = Name.from_ident ident ; - mp_type = Odoc_env.subst_module_type env param_module_type ; - } - in - ( - match analyse_module_type_kind env current_module_name module_type2 body_module_type with - Module_type_functor (params, k) -> - Module_type_functor (param :: params, k) - | k -> - Module_type_functor ([param], k) - ) + ( + match sig_module_type with + Types.Tmty_functor (ident, param_module_type, body_module_type) -> + let param = + { + mp_name = Name.from_ident ident ; + mp_type = Odoc_env.subst_module_type env param_module_type ; + } + in + ( + match analyse_module_type_kind env current_module_name module_type2 body_module_type with + Module_type_functor (params, k) -> + Module_type_functor (param :: params, k) + | k -> + Module_type_functor ([param], k) + ) - | _ -> - (* if we're here something's wrong *) - raise (Failure "Parsetree.Pmty_functor _ but not Types.Tmty_functor _") - ) + | _ -> + (* if we're here something's wrong *) + raise (Failure "Parsetree.Pmty_functor _ but not Types.Tmty_functor _") + ) | Parsetree.Pmty_with (module_type2, _) -> - (* of module_type * (Longident.t * with_constraint) list *) - ( - let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end in - let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end 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 - Module_type_with (k, s) - ) + (* of module_type * (Longident.t * with_constraint) list *) + ( + let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end in + let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end 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 + 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 = match module_type.Parsetree.pmty_desc with - Parsetree.Pmty_ident longident (*of Longident.t*) -> - let name = - match sig_module_type with - Types.Tmty_ident path -> Name.from_path path - | _ -> - Name.from_longident longident - in - Module_alias { ma_name = Odoc_env.full_module_or_module_type_name env name ; - ma_module = None } + Parsetree.Pmty_ident longident (*of Longident.t*) -> + let name = + match sig_module_type with + Types.Tmty_ident path -> Name.from_path path + | _ -> + Name.from_longident longident + in + Module_alias { ma_name = Odoc_env.full_module_or_module_type_name env name ; + ma_module = None } | Parsetree.Pmty_signature signature -> - ( - match sig_module_type with - Types.Tmty_signature signat -> - Module_struct - (analyse_parsetree - env - signat - current_module_name - module_type.Parsetree.pmty_loc.Location.loc_start - module_type.Parsetree.pmty_loc.Location.loc_end - signature - ) - | _ -> - (* if we're here something's wrong *) - raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat") - ) + ( + match sig_module_type with + Types.Tmty_signature signat -> + Module_struct + (analyse_parsetree + env + signat + current_module_name + module_type.Parsetree.pmty_loc.Location.loc_start + module_type.Parsetree.pmty_loc.Location.loc_end + signature + ) + | _ -> + (* if we're here something's wrong *) + raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat") + ) | Parsetree.Pmty_functor (_,_,module_type2) (* of string * module_type * module_type *) -> - ( - match sig_module_type with - Types.Tmty_functor (ident, param_module_type, body_module_type) -> - let param = - { - mp_name = Name.from_ident ident ; - mp_type = Odoc_env.subst_module_type env param_module_type ; - } - in - ( - match analyse_module_kind env current_module_name module_type2 body_module_type with - Module_functor (params, k) -> - Module_functor (param :: params, k) - | k -> - Module_functor ([param], k) - ) - - | _ -> - (* if we're here something's wrong *) - raise (Failure "Parsetree.Pmty_functor _ but not Types.Tmty_functor _") - ) + ( + match sig_module_type with + Types.Tmty_functor (ident, param_module_type, body_module_type) -> + let param = + { + mp_name = Name.from_ident ident ; + mp_type = Odoc_env.subst_module_type env param_module_type ; + } + in + ( + match analyse_module_kind env current_module_name module_type2 body_module_type with + Module_functor (params, k) -> + Module_functor (param :: params, k) + | k -> + Module_functor ([param], k) + ) + + | _ -> + (* if we're here something's wrong *) + raise (Failure "Parsetree.Pmty_functor _ but not Types.Tmty_functor _") + ) | Parsetree.Pmty_with (module_type2, _) -> (*of module_type * (Longident.t * with_constraint) list*) - ( - let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end in - let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end 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 - Module_with (k, s) - ) + ( + let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end in + let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end 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 + Module_with (k, s) + ) (** Analyse of a Parsetree.class_type and a Types.class_type to return a couple (class parameters, class_kind).*) and analyse_class_kind env current_class_name last_pos parse_class_type sig_class_type = match parse_class_type.Parsetree.pcty_desc, sig_class_type with - (Parsetree.Pcty_constr (_, _) (*of Longident.t * core_type list *), - Types.Tcty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) -> - print_DEBUG "Tcty_constr _"; - let path_name = Name.from_path p in - let name = Odoc_env.full_class_or_class_type_name env path_name in - let k = - Class_constr - { - cco_name = name ; - cco_class = None ; - cco_type_parameters = List.map (Odoc_env.subst_type env) typ_list - } - in - ([], k) + (Parsetree.Pcty_constr (_, _) (*of Longident.t * core_type list *), + Types.Tcty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) -> + print_DEBUG "Tcty_constr _"; + let path_name = Name.from_path p in + let name = Odoc_env.full_class_or_class_type_name env path_name in + let k = + Class_constr + { + cco_name = name ; + cco_class = None ; + cco_type_parameters = List.map (Odoc_env.subst_type env) typ_list + } + in + ([], k) | (Parsetree.Pcty_signature (_, class_type_field_list), Types.Tcty_signature class_signature) -> - print_DEBUG "Types.Tcty_signature class_signature"; - let f_DEBUG var (mutable_flag, type_exp) = print_DEBUG var in - Types.Vars.iter f_DEBUG class_signature.Types.cty_vars; - print_DEBUG ("Type de la classe "^current_class_name^" : "); - print_DEBUG (Odoc_misc.string_of_type_expr class_signature.Types.cty_self); - (* we get the elements of the class in class_type_field_list *) - let (inher_l, ele) = analyse_class_elements env current_class_name - last_pos - parse_class_type.Parsetree.pcty_loc.Location.loc_end - class_type_field_list - class_signature - in - ([], Class_structure (inher_l, ele)) + print_DEBUG "Types.Tcty_signature class_signature"; + let f_DEBUG var (mutable_flag, type_exp) = print_DEBUG var in + Types.Vars.iter f_DEBUG class_signature.Types.cty_vars; + print_DEBUG ("Type de la classe "^current_class_name^" : "); + print_DEBUG (Odoc_misc.string_of_type_expr class_signature.Types.cty_self); + (* we get the elements of the class in class_type_field_list *) + let (inher_l, ele) = analyse_class_elements env current_class_name + last_pos + parse_class_type.Parsetree.pcty_loc.Location.loc_end + class_type_field_list + class_signature + in + ([], Class_structure (inher_l, ele)) | (Parsetree.Pcty_fun (parse_label, _, pclass_type), Types.Tcty_fun (label, type_expr, class_type)) -> (* label = string. Dans les signatures, pas de nom de param�tres � l'int�rieur des tuples *) - (* si label = "", pas de label. ici on a l'information pour savoir si on a un label explicite. *) - if parse_label = label then - ( - let new_param = Simple_name - { - sn_name = Btype.label_name label ; - sn_type = Odoc_env.subst_type env type_expr ; - sn_text = None ; (* will be updated when the class will be created *) - } - in - let (l, k) = analyse_class_kind env current_class_name last_pos pclass_type class_type in - ( (new_param :: l), k ) - ) - else - ( - raise (Failure "Parsetree.Pcty_fun (parse_label, _, pclass_type), labels diff�rents") - ) - + (* si label = "", pas de label. ici on a l'information pour savoir si on a un label explicite. *) + if parse_label = label then + ( + let new_param = Simple_name + { + sn_name = Btype.label_name label ; + sn_type = Odoc_env.subst_type env type_expr ; + sn_text = None ; (* will be updated when the class will be created *) + } + in + let (l, k) = analyse_class_kind env current_class_name last_pos pclass_type class_type in + ( (new_param :: l), k ) + ) + else + ( + raise (Failure "Parsetree.Pcty_fun (parse_label, _, pclass_type), labels diff�rents") + ) + | _ -> - raise (Failure "analyse_class_kind pas de correspondance dans le match") + raise (Failure "analyse_class_kind pas de correspondance dans le match") (** Analyse of a Parsetree.class_type and a Types.class_type to return a class_type_kind.*) and analyse_class_type_kind env current_class_name last_pos parse_class_type sig_class_type = match parse_class_type.Parsetree.pcty_desc, sig_class_type with - (Parsetree.Pcty_constr (_, _) (*of Longident.t * core_type list *), - Types.Tcty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) -> - print_DEBUG "Tcty_constr _"; - let k = - Class_type - { - cta_name = Odoc_env.full_class_or_class_type_name env (Name.from_path p) ; - cta_class = None ; - cta_type_parameters = List.map (Odoc_env.subst_type env) typ_list - } - in - k + (Parsetree.Pcty_constr (_, _) (*of Longident.t * core_type list *), + Types.Tcty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) -> + print_DEBUG "Tcty_constr _"; + let k = + Class_type + { + cta_name = Odoc_env.full_class_or_class_type_name env (Name.from_path p) ; + cta_class = None ; + cta_type_parameters = List.map (Odoc_env.subst_type env) typ_list + } + in + k | (Parsetree.Pcty_signature (_, class_type_field_list), Types.Tcty_signature class_signature) -> - print_DEBUG "Types.Tcty_signature class_signature"; - let f_DEBUG var (mutable_flag, type_exp) = print_DEBUG var in - Types.Vars.iter f_DEBUG class_signature.Types.cty_vars; - print_DEBUG ("Type de la classe "^current_class_name^" : "); - print_DEBUG (Odoc_misc.string_of_type_expr class_signature.Types.cty_self); - (* we get the elements of the class in class_type_field_list *) - let (inher_l, ele) = analyse_class_elements env current_class_name - last_pos - parse_class_type.Parsetree.pcty_loc.Location.loc_end - class_type_field_list - class_signature - in - Class_signature (inher_l, ele) + print_DEBUG "Types.Tcty_signature class_signature"; + let f_DEBUG var (mutable_flag, type_exp) = print_DEBUG var in + Types.Vars.iter f_DEBUG class_signature.Types.cty_vars; + print_DEBUG ("Type de la classe "^current_class_name^" : "); + print_DEBUG (Odoc_misc.string_of_type_expr class_signature.Types.cty_self); + (* we get the elements of the class in class_type_field_list *) + let (inher_l, ele) = analyse_class_elements env current_class_name + last_pos + parse_class_type.Parsetree.pcty_loc.Location.loc_end + class_type_field_list + class_signature + in + Class_signature (inher_l, ele) | (Parsetree.Pcty_fun (parse_label, _, pclass_type), Types.Tcty_fun (label, type_expr, class_type)) -> - raise (Failure "analyse_class_type_kind : Parsetree.Pcty_fun (...) with Types.Tcty_fun (...)") + raise (Failure "analyse_class_type_kind : Parsetree.Pcty_fun (...) with Types.Tcty_fun (...)") (* - | (Parsetree.Pcty_constr (longident, _) (*of Longident.t * core_type list *), - Types.Tcty_signature class_signature) -> - (* A VOIR : c'est pour le cas des contraintes de classes : + | (Parsetree.Pcty_constr (longident, _) (*of Longident.t * core_type list *), + Types.Tcty_signature class_signature) -> + (* A VOIR : c'est pour le cas des contraintes de classes : class type cons = object - method m : int - end - + method m : int + end + class ['a] maxou x = - (object - val a = (x : 'a) - method m = a - end : cons ) + (object + val a = (x : 'a) + method m = a + end : cons ) ^^^^^^ - *) - let k = - Class_type - { - cta_name = Odoc_env.full_class_name env (Name.from_longident longident) ; - cta_class = None ; - cta_type_parameters = List.map (Odoc_env.subst_type env) typ_list (* ?? *) - } - in - ([], k) + *) + let k = + Class_type + { + cta_name = Odoc_env.full_class_name env (Name.from_longident longident) ; + cta_class = None ; + cta_type_parameters = List.map (Odoc_env.subst_type env) typ_list (* ?? *) + } + in + ([], k) *) | _ -> - raise (Failure "analyse_class_type_kind pas de correspondance dans le match") + raise (Failure "analyse_class_type_kind pas de correspondance dans le match") let analyse_signature source_file input_file (ast : Parsetree.signature) (signat : Types.signature) = let complete_source_file = - try - let curdir = Sys.getcwd () in - let (dirname, basename) = (Filename.dirname source_file, Filename.basename source_file) in - Sys.chdir dirname ; - let complete = Filename.concat (Sys.getcwd ()) basename in - Sys.chdir curdir ; - complete - with - Sys_error s -> - prerr_endline s ; - incr Odoc_global.errors ; - source_file + try + let curdir = Sys.getcwd () in + let (dirname, basename) = (Filename.dirname source_file, Filename.basename source_file) in + Sys.chdir dirname ; + let complete = Filename.concat (Sys.getcwd ()) basename in + Sys.chdir curdir ; + complete + with + Sys_error s -> + prerr_endline s ; + incr Odoc_global.errors ; + source_file in prepare_file complete_source_file input_file; (* We create the t_module for this file. *) let mod_name = String.capitalize - (Filename.basename (try Filename.chop_extension source_file with _ -> source_file)) + (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 elements = analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file) ast in let m = - { - m_name = mod_name ; - m_type = Types.Tmty_signature signat ; - m_info = info_opt ; - m_is_interface = true ; - m_file = !file_name ; - m_kind = Module_struct elements ; - m_loc = { loc_impl = None ; loc_inter = Some (!file_name, 0) } ; - m_top_deps = [] ; - } + { + m_name = mod_name ; + m_type = Types.Tmty_signature signat ; + m_info = info_opt ; + m_is_interface = true ; + m_file = !file_name ; + m_kind = Module_struct elements ; + m_loc = { loc_impl = None ; loc_inter = Some (!file_name, 0) } ; + m_top_deps = [] ; + } in print_DEBUG "El�ments du module:"; let f e = - let s = - match e with - Element_module m -> "module "^m.m_name - | Element_module_type mt -> "module type "^mt.mt_name - | Element_included_module im -> "included module "^im.im_name - | Element_class c -> "class "^c.cl_name - | Element_class_type ct -> "class type "^ct.clt_name - | Element_value v -> "value "^v.val_name - | Element_exception e -> "exception "^e.ex_name - | Element_type t -> "type "^t.ty_name - | Element_module_comment t -> Odoc_misc.string_of_text t - in - print_DEBUG s; - () + let s = + match e with + Element_module m -> "module "^m.m_name + | Element_module_type mt -> "module type "^mt.mt_name + | Element_included_module im -> "included module "^im.im_name + | Element_class c -> "class "^c.cl_name + | Element_class_type ct -> "class type "^ct.clt_name + | Element_value v -> "value "^v.val_name + | Element_exception e -> "exception "^e.ex_name + | Element_type t -> "type "^t.ty_name + | Element_module_comment t -> Odoc_misc.string_of_text t + in + print_DEBUG s; + () in List.iter f elements; m - + end diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli index bf29fa3d4..3530659c1 100644 --- a/ocamldoc/odoc_sig.mli +++ b/ocamldoc/odoc_sig.mli @@ -19,55 +19,55 @@ module Signature_search : type tab = (ele, Types.signature_item) Hashtbl.t (** Create a table from a signature. This table is used by some - of the search functions below. *) + of the search functions below. *) val table : Types.signature -> tab (** This function returns the type expression for the value whose name is given, - in the given signature. - @raise Not_found if error.*) + in the given signature. + @raise Not_found if error.*) val search_value : tab -> string -> Types.type_expr (** This function returns the type expression list for the exception whose name is given, - in the given table. - @raise Not_found if error.*) + in the given table. + @raise Not_found if error.*) val search_exception : tab -> string -> Types.exception_declaration (** This function returns the Types.type_declaration for the type whose name is given, - in the given table. - @raise Not_found if error.*) + in the given table. + @raise Not_found if error.*) val search_type : tab -> string -> Types.type_declaration - + (** This function returns the Types.class_declaration for the class whose name is given, - in the given table. - @raise Not_found if error.*) + in the given table. + @raise Not_found if error.*) val search_class : tab -> string -> Types.class_declaration (** This function returns the Types.cltype_declaration for the class type whose name is given, - in the given table. - @raise Not_found if error.*) + in the given table. + @raise Not_found if error.*) val search_class_type : tab -> string -> Types.cltype_declaration (** This function returns the Types.module_type for the module whose name is given, - in the given table. - @raise Not_found if error.*) + in the given table. + @raise Not_found if error.*) val search_module : tab -> string -> Types.module_type (** This function returns the optional Types.module_type for the module type whose name is given, - in the given table. - @raise Not_found if error.*) + in the given table. + @raise Not_found if error.*) val search_module_type : tab -> string -> Types.module_type option (** This function returns the Types.type_expr for the given val name - in the given class signature. - @raise Not_found if error.*) + in the given class signature. + @raise Not_found if error.*) val search_attribute_type : - Types.Vars.key -> Types.class_signature -> Types.type_expr + Types.Vars.key -> Types.class_signature -> Types.type_expr (** This function returns the Types.type_expr for the given method name - in the given class signature. - @raise Not_found if error.*) + in the given class signature. + @raise Not_found if error.*) val search_method_type : - string -> Types.class_signature -> Types.type_expr + string -> Types.class_signature -> Types.type_expr end (** Functions to retrieve simple and special comments from strings. *) @@ -77,32 +77,32 @@ module type Info_retriever = characters read to retrieve [list], which is the list of special comments found in the string. *) val all_special : - string -> string -> int * Odoc_types.info list + string -> string -> int * Odoc_types.info list (** Return true if the given string contains a blank line. *) val blank_line_outside_simple : - string -> string -> bool + string -> string -> bool (** [just_after_special file str] return the pair ([length], [info_opt]) where [info_opt] is the first optional special comment found in [str], without any blank line before. [length] is the number of chars from the beginning of [str] to the end of the special comment. *) val just_after_special : - string -> string -> (int * Odoc_types.info option) + string -> string -> (int * Odoc_types.info option) (** [first_special file str] return the pair ([length], [info_opt]) where [info_opt] is the first optional special comment found in [str]. [length] is the number of chars from the beginning of [str] to the end of the special comment. *) val first_special : - string -> string -> (int * Odoc_types.info option) + string -> string -> (int * Odoc_types.info option) (** Return a pair [(comment_opt, element_comment_list)], where [comment_opt] is the last special comment found in the given string and not followed by a blank line, and [element_comment_list] the list of values built from the other special comments found and the given function. *) val get_comments : - (Odoc_types.text -> 'a) -> string -> string -> (Odoc_types.info option * 'a list) + (Odoc_types.text -> 'a) -> string -> string -> (Odoc_types.info option * 'a list) end @@ -116,59 +116,59 @@ module Analyser : val file_name : string ref (** This function takes two indexes (start and end) and return the string - corresponding to the indexes in the file global variable. The function - prepare_file must have been called to fill the file global variable.*) + corresponding to the indexes in the file global variable. The function + prepare_file must have been called to fill the file global variable.*) val get_string_of_file : int -> int -> string - + (** [prepare_file f input_f] sets [file_name] with [f] and loads the file - [input_f] into [file].*) + [input_f] into [file].*) val prepare_file : string -> string -> unit - + (** The function used to get the comments in a class. *) val get_comments_in_class : int -> int -> - (Odoc_types.info option * Odoc_class.class_element list) + (Odoc_types.info option * Odoc_class.class_element list) (** The function used to get the comments in a module. *) val get_comments_in_module : int -> int -> - (Odoc_types.info option * Odoc_module.module_element list) + (Odoc_types.info option * Odoc_module.module_element list) (** This function takes a [Parsetree.type_kind] and returns the list of - (name, optional comment) for the various fields/constructors of the type, - or an empty list for an abstract type. - [pos_start] and [pos_end] are the first and last char of the complete type definition. - [pos_limit] is the position of the last char we could use to look for a comment, - i.e. usually the beginning on the next element.*) + (name, optional comment) for the various fields/constructors of the type, + or an empty list for an abstract type. + [pos_start] and [pos_end] are the first and last char of the complete type definition. + [pos_limit] is the position of the last char we could use to look for a comment, + i.e. usually the beginning on the next element.*) val name_comment_from_type_kind : - int -> int -> int -> Parsetree.type_kind -> int * (string * Odoc_types.info option) list + int -> int -> int -> Parsetree.type_kind -> int * (string * Odoc_types.info option) list (** This function converts a [Types.type_kind] into a [Odoc_type.type_kind], - by associating the comment found in the parsetree of each constructor/field, if any.*) + by associating the comment found in the parsetree of each constructor/field, if any.*) val get_type_kind : - Odoc_env.env -> (string * Odoc_types.info option) list -> - Types.type_kind -> Odoc_type.type_kind + Odoc_env.env -> (string * Odoc_types.info option) list -> + Types.type_kind -> Odoc_type.type_kind (** This function merge two optional info structures. *) val merge_infos : - Odoc_types.info option -> Odoc_types.info option -> - Odoc_types.info option + Odoc_types.info option -> Odoc_types.info option -> + Odoc_types.info option (** 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.*) + return a class_type_kind.*) val analyse_class_type_kind : Odoc_env.env -> - Odoc_name.t -> int -> Parsetree.class_type -> Types.class_type -> - Odoc_class.class_type_kind + Odoc_name.t -> int -> Parsetree.class_type -> Types.class_type -> + Odoc_class.class_type_kind (** This function takes an interface file name, a file containg the code, a parse tree - and the signature obtained from the compiler. - It goes through the parse tree, creating values for encountered - functions, modules, ..., looking in the source file for comments, - and in the signature for types information. *) + and the signature obtained from the compiler. + It goes through the parse tree, creating values for encountered + functions, modules, ..., looking in the source file for comments, + and in the signature for types information. *) val analyse_signature : string -> string -> Parsetree.signature -> Types.signature -> Odoc_module.t_module diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml index 434ae72f5..00d12ec66 100644 --- a/ocamldoc/odoc_str.ml +++ b/ocamldoc/odoc_str.ml @@ -19,8 +19,8 @@ let string_of_type t = "type "^ (String.concat "" (List.map - (fun p -> (Odoc_misc.string_of_type_expr p)^" ") - t.M.ty_parameters + (fun p -> (Odoc_misc.string_of_type_expr p)^" ") + t.M.ty_parameters ) )^ (Name.simple t.M.ty_name)^" "^ @@ -34,41 +34,41 @@ let string_of_type t = | M.Type_variant l -> "=\n"^ (String.concat "" - (List.map - (fun cons -> - " | "^cons.M.vc_name^ - (match cons.M.vc_args with - [] -> "" - | l -> - " of "^(String.concat " * " - (List.map (fun t -> "("^(Odoc_misc.string_of_type_expr t)^")") l)) - )^ - (match cons.M.vc_text with - None -> - "" - | Some t -> - "(* "^(Odoc_misc.string_of_text t)^" *)" - )^"\n" - ) - l - ) + (List.map + (fun cons -> + " | "^cons.M.vc_name^ + (match cons.M.vc_args with + [] -> "" + | l -> + " of "^(String.concat " * " + (List.map (fun t -> "("^(Odoc_misc.string_of_type_expr t)^")") l)) + )^ + (match cons.M.vc_text with + None -> + "" + | Some t -> + "(* "^(Odoc_misc.string_of_text t)^" *)" + )^"\n" + ) + l + ) ) | M.Type_record l -> "= {\n"^ (String.concat "" - (List.map - (fun record -> - " "^(if record.M.rf_mutable then "mutable " else "")^ - record.M.rf_name^" : "^(Odoc_misc.string_of_type_expr record.M.rf_type)^";"^ - (match record.M.rf_text with - None -> - "" - | Some t -> - "(* "^(Odoc_misc.string_of_text t)^" *)" - )^"\n" - ) - l - ) + (List.map + (fun record -> + " "^(if record.M.rf_mutable then "mutable " else "")^ + record.M.rf_name^" : "^(Odoc_misc.string_of_type_expr record.M.rf_type)^";"^ + (match record.M.rf_text with + None -> + "" + | Some t -> + "(* "^(Odoc_misc.string_of_text t)^" *)" + )^"\n" + ) + l + ) )^ "}\n" )^ @@ -83,7 +83,7 @@ let string_of_exception e = [] -> "" | _ ->" : "^ (String.concat " -> " - (List.map (fun t -> "("^(Odoc_misc.string_of_type_expr t)^")") e.M.ex_args) + (List.map (fun t -> "("^(Odoc_misc.string_of_type_expr t)^")") e.M.ex_args) ) )^ (match e.M.ex_alias with @@ -91,8 +91,8 @@ let string_of_exception e = | Some ea -> " = "^ (match ea.M.ea_ex with - None -> ea.M.ea_name - | Some e2 -> e2.M.ex_name + None -> ea.M.ea_name + | Some e2 -> e2.M.ex_name ) )^"\n"^ (match e.M.ex_info with diff --git a/ocamldoc/odoc_texi.ml b/ocamldoc/odoc_texi.ml index a75b48d06..ec6269384 100644 --- a/ocamldoc/odoc_texi.ml +++ b/ocamldoc/odoc_texi.ml @@ -76,20 +76,20 @@ let nothing = Verbatim "" let module_subparts = let rec iter acc = function | [] -> List.rev acc - (* skip aliases *) + (* skip aliases *) | Element_module { m_kind = Module_alias _ } :: n -> - iter acc n + iter acc n | Element_module_type { mt_kind = Some (Module_type_alias _) } :: n -> - iter acc n + iter acc n (* keep modules, module types, classes and class types *) | Element_module m :: n -> - iter (`Module m :: acc) n + iter (`Module m :: acc) n | Element_module_type mt :: n -> - iter (`Module_type mt :: acc) n + iter (`Module_type mt :: acc) n | Element_class c :: n -> - iter (`Class c :: acc) n + iter (`Class c :: acc) n | Element_class_type ct :: n -> - iter (`Class_type ct :: acc) n + iter (`Class_type ct :: acc) n (* forget the rest *) | _ :: n -> iter acc n in @@ -178,32 +178,32 @@ struct if subpart_list <> [] then begin let menu_line part_qual name = - let sname = Name.simple name in - if sname = name - then ( - puts chan (pad_to 35 - ("* " ^ sname ^ ":: ")) ; - puts_nl chan part_qual ) - else ( - puts chan (pad_to 35 - ("* " ^ sname ^ ": " ^ (fix_nodename name) ^ ". " )) ; - puts_nl chan part_qual ) + let sname = Name.simple name in + if sname = name + then ( + puts chan (pad_to 35 + ("* " ^ sname ^ ":: ")) ; + puts_nl chan part_qual ) + else ( + puts chan (pad_to 35 + ("* " ^ sname ^ ": " ^ (fix_nodename name) ^ ". " )) ; + puts_nl chan part_qual ) in puts_nl chan "@menu" ; List.iter - (function - | `Module { m_name = name } -> - menu_line Odoc_messages.modul name - | `Module_type { mt_name = name } -> - menu_line Odoc_messages.module_type name - | `Class { cl_name = name } -> - menu_line Odoc_messages.clas name - | `Class_type { clt_name = name } -> - menu_line Odoc_messages.class_type name - | `Blank -> nl chan - | `Comment c -> puts_nl chan (escape c) - | `Texi t -> puts_nl chan t - | `Index ind -> Printf.fprintf chan "* %s::\n" ind) + (function + | `Module { m_name = name } -> + menu_line Odoc_messages.modul name + | `Module_type { mt_name = name } -> + menu_line Odoc_messages.module_type name + | `Class { cl_name = name } -> + menu_line Odoc_messages.clas name + | `Class_type { clt_name = name } -> + menu_line Odoc_messages.class_type name + | `Blank -> nl chan + | `Comment c -> puts_nl chan (escape c) + | `Texi t -> puts_nl chan t + | `Index ind -> Printf.fprintf chan "* %s::\n" ind) subpart_list ; puts_nl chan "@end menu" end @@ -262,7 +262,7 @@ class text = (** Return the Texinfo code corresponding to the [text] parameter.*) method texi_of_text t = String.concat "" - (List.map self#texi_of_text_element t) + (List.map self#texi_of_text_element t) (** {3 Conversion methods} @@ -295,54 +295,54 @@ class text = method texi_of_Code s = "@code{" ^ (self#escape s) ^ "}" method texi_of_CodePre s = String.concat "\n" - [ "" ; "@example" ; self#escape s ; "@end example" ; "" ] + [ "" ; "@example" ; self#escape s ; "@end example" ; "" ] method texi_of_Bold t = "@strong{" ^ (self#texi_of_text t) ^ "}" method texi_of_Italic t = "@i{" ^ (self#texi_of_text t) ^ "}" method texi_of_Emphasize t = "@emph{" ^ (self#texi_of_text t) ^ "}" method texi_of_Center t = let sl = Str.split (Str.regexp "\n") (self#texi_of_text t) in String.concat "" - ((List.map (fun s -> "\n@center "^s) sl) @ [ "\n" ]) + ((List.map (fun s -> "\n@center "^s) sl) @ [ "\n" ]) method texi_of_Left t = String.concat "\n" - [ "" ; "@flushleft" ; self#texi_of_text t ; "@end flushleft" ; "" ] + [ "" ; "@flushleft" ; self#texi_of_text t ; "@end flushleft" ; "" ] method texi_of_Right t = String.concat "\n" - [ "" ; "@flushright" ; self#texi_of_text t ; "@end flushright"; "" ] + [ "" ; "@flushright" ; self#texi_of_text t ; "@end flushright"; "" ] method texi_of_List tl = String.concat "\n" - ( [ "" ; "@itemize" ] @ - (List.map (fun t -> "@item\n" ^ (self#texi_of_text t)) tl) @ - [ "@end itemize"; "" ] ) + ( [ "" ; "@itemize" ] @ + (List.map (fun t -> "@item\n" ^ (self#texi_of_text t)) tl) @ + [ "@end itemize"; "" ] ) method texi_of_Enum tl = String.concat "\n" - ( [ "" ; "@enumerate" ] @ - (List.map (fun t -> "@item\n" ^ (self#texi_of_text t)) tl) @ - [ "@end enumerate"; "" ] ) + ( [ "" ; "@enumerate" ] @ + (List.map (fun t -> "@item\n" ^ (self#texi_of_text t)) tl) @ + [ "@end enumerate"; "" ] ) method texi_of_Newline = "\n" method texi_of_Block t = String.concat "\n" - [ "@format" ; self#texi_of_text t ; "@end format" ; "" ] + [ "@format" ; self#texi_of_text t ; "@end format" ; "" ] method texi_of_Title n t = let t_begin = - try List.assoc n titles - with Not_found -> fallback_title in + try List.assoc n titles + with Not_found -> fallback_title in t_begin ^ (self#texi_of_text t) ^ "\n" method texi_of_Link s t = String.concat "" - [ "@uref{" ; s ; "," ; self#texi_of_text t ; "}" ] + [ "@uref{" ; s ; "," ; self#texi_of_text t ; "}" ] method texi_of_Ref name kind = let xname = - match kind with - | Some RK_module -> - Odoc_messages.modul ^ " " ^ (Name.simple name) - | Some RK_module_type -> - Odoc_messages.module_type ^ " " ^ (Name.simple name) - | Some RK_class -> - Odoc_messages.clas ^ " " ^ (Name.simple name) - | Some RK_class_type -> - Odoc_messages.class_type ^ " " ^ (Name.simple name) - | _ -> "" + match kind with + | Some RK_module -> + Odoc_messages.modul ^ " " ^ (Name.simple name) + | Some RK_module_type -> + Odoc_messages.module_type ^ " " ^ (Name.simple name) + | Some RK_class -> + Odoc_messages.clas ^ " " ^ (Name.simple name) + | Some RK_class_type -> + Odoc_messages.class_type ^ " " ^ (Name.simple name) + | _ -> "" in if xname = "" then self#escape name else Texi.xref ~xname name method texi_of_Superscript t = @@ -352,8 +352,8 @@ class text = method heading n t = let f = - try List.assoc n headings - with Not_found -> fallback_heading + try List.assoc n headings + with Not_found -> fallback_heading in f ^ (self#texi_of_text t) ^ "\n" @@ -386,33 +386,33 @@ class texi = method index (ind : indices) ent = Verbatim - (if !with_index - then (String.concat "" - [ "@" ; indices ind ; "index " ; - Texi.escape (Name.simple ent) ; "\n" ]) - else "") + (if !with_index + then (String.concat "" + [ "@" ; indices ind ; "index " ; + Texi.escape (Name.simple ent) ; "\n" ]) + else "") (** Two hacks to fix linebreaks in the descriptions.*) method private fix_linebreaks = let re = Str.regexp "\n[ \t]*" in fun t -> - List.map - (function - | Newline -> Raw "\n" - | Raw s -> Raw (Str.global_replace re "\n" s) - | List tel | Enum tel -> List (List.map self#fix_linebreaks tel) - | te -> te) t + List.map + (function + | Newline -> Raw "\n" + | Raw s -> Raw (Str.global_replace re "\n" s) + | List tel | Enum tel -> List (List.map self#fix_linebreaks tel) + | te -> te) t method private soft_fix_linebreaks = let re = Str.regexp "\n[ \t]*" in fun ind t -> - let rep = String.make (succ ind) ' ' in - rep.[0] <- '\n' ; - List.map - (function - | Raw s -> Raw (Str.global_replace re rep s) - | te -> te) t + let rep = String.make (succ ind) ' ' in + rep.[0] <- '\n' ; + List.map + (function + | Raw s -> Raw (Str.global_replace re rep s) + | te -> te) t (** {3 [text] values generation} Generates [text] values out of description parts. @@ -425,97 +425,97 @@ class texi = method text_of_sees_opt see_l = List.concat - (List.map - (function - | (See_url s, t) -> - [ linebreak ; Bold [ Raw Odoc_messages.see_also ] ; - Raw " " ; Link (s, t) ; Newline ] - | (See_file s, t) - | (See_doc s, t) -> - [ linebreak ; Bold [ Raw Odoc_messages.see_also ] ; - Raw " " ; Raw s ] @ t @ [ Newline ]) - see_l) + (List.map + (function + | (See_url s, t) -> + [ linebreak ; Bold [ Raw Odoc_messages.see_also ] ; + Raw " " ; Link (s, t) ; Newline ] + | (See_file s, t) + | (See_doc s, t) -> + [ linebreak ; Bold [ Raw Odoc_messages.see_also ] ; + Raw " " ; Raw s ] @ t @ [ Newline ]) + see_l) method text_of_params params_list = - List.concat - (List.map - (fun (s, t) -> - [ linebreak ; - Bold [ Raw Odoc_messages.parameters ] ; - Raw " " ; Raw s ; Raw ": " ] @ t @ [ Newline ] ) - params_list) + List.concat + (List.map + (fun (s, t) -> + [ linebreak ; + Bold [ Raw Odoc_messages.parameters ] ; + Raw " " ; Raw s ; Raw ": " ] @ t @ [ Newline ] ) + params_list) method text_of_raised_exceptions = function | [] -> [] | (s, t) :: [] -> - [ linebreak ; - Bold [ Raw Odoc_messages.raises ] ; - Raw " " ; Code s ; Raw " " ] - @ t @ [ Newline ] + [ linebreak ; + Bold [ Raw Odoc_messages.raises ] ; + Raw " " ; Code s ; Raw " " ] + @ t @ [ Newline ] | l -> - [ linebreak ; - Bold [ Raw Odoc_messages.raises ] ; - Raw " :" ; - List - (List.map - (fun (ex, desc) ->(Code ex) :: (Raw " ") :: desc ) l ) ; - Newline ] + [ linebreak ; + Bold [ Raw Odoc_messages.raises ] ; + Raw " :" ; + List + (List.map + (fun (ex, desc) ->(Code ex) :: (Raw " ") :: desc ) l ) ; + Newline ] method text_of_return_opt = function | None -> [] | Some t -> - (Bold [Raw Odoc_messages.returns ]) :: Raw " " :: t @ [ Newline ] + (Bold [Raw Odoc_messages.returns ]) :: Raw " " :: t @ [ Newline ] method text_of_custom c_l = List.flatten - (List.rev - (List.fold_left - (fun acc -> fun (tag, text) -> - try - let f = List.assoc tag tag_functions in - ( linebreak :: (f text) @ [ Newline ] ) :: acc - with - Not_found -> - Odoc_info.warning (Odoc_messages.tag_not_handled tag) ; - acc - ) [] c_l)) + (List.rev + (List.fold_left + (fun acc -> fun (tag, text) -> + try + let f = List.assoc tag tag_functions in + ( linebreak :: (f text) @ [ Newline ] ) :: acc + with + Not_found -> + Odoc_info.warning (Odoc_messages.tag_not_handled tag) ; + acc + ) [] c_l)) method text_of_info ?(block=false) = function | None -> [] | Some info -> - let t = - List.concat - [ ( match info.i_deprecated with - | None -> [] - | Some t -> - (Raw (Odoc_messages.deprecated ^ " ")) :: - (self#fix_linebreaks t) - @ [ Newline ; Newline ] ) ; - self#text_of_desc info.i_desc ; - if info.i_authors <> [] - then ( linebreak :: - self#text_of_author_list info.i_authors ) - else [] ; - if is info.i_version - then ( linebreak :: - self#text_of_version_opt info.i_version ) - else [] ; - self#text_of_sees_opt info.i_sees ; - if is info.i_since - then ( linebreak :: - self#text_of_since_opt info.i_since ) - else [] ; - self#text_of_params info.i_params ; - self#text_of_raised_exceptions info.i_raised_exceptions ; - if is info.i_return_value - then ( linebreak :: - self#text_of_return_opt info.i_return_value ) - else [] ; - self#text_of_custom info.i_custom ; - ] in - if block - then [ Block t ] - else (t @ [ Newline ] ) + let t = + List.concat + [ ( match info.i_deprecated with + | None -> [] + | Some t -> + (Raw (Odoc_messages.deprecated ^ " ")) :: + (self#fix_linebreaks t) + @ [ Newline ; Newline ] ) ; + self#text_of_desc info.i_desc ; + if info.i_authors <> [] + then ( linebreak :: + self#text_of_author_list info.i_authors ) + else [] ; + if is info.i_version + then ( linebreak :: + self#text_of_version_opt info.i_version ) + else [] ; + self#text_of_sees_opt info.i_sees ; + if is info.i_since + then ( linebreak :: + self#text_of_since_opt info.i_since ) + else [] ; + self#text_of_params info.i_params ; + self#text_of_raised_exceptions info.i_raised_exceptions ; + if is info.i_return_value + then ( linebreak :: + self#text_of_return_opt info.i_return_value ) + else [] ; + self#text_of_custom info.i_custom ; + ] in + if block + then [ Block t ] + else (t @ [ Newline ] ) method texi_of_info i = self#texi_of_text (self#text_of_info i) @@ -527,8 +527,8 @@ class texi = method text_el_of_type_expr m_name typ = Raw (indent 5 - (self#relative_idents m_name - (Odoc_info.string_of_type_expr typ))) + (self#relative_idents m_name + (Odoc_info.string_of_type_expr typ))) method text_of_short_type_expr m_name typ = [ Raw (self#normal_type m_name typ) ] @@ -537,12 +537,12 @@ class texi = method texi_of_value v = Odoc_info.reset_type_names () ; let t = [ self#fixedblock - [ Newline ; minus ; - Raw ("val " ^ (Name.simple v.val_name) ^ " :\n") ; - self#text_el_of_type_expr - (Name.father v.val_name) v.val_type ] ; - self#index `Value v.val_name ; Newline ] @ - (self#text_of_info v.val_info) in + [ Newline ; minus ; + Raw ("val " ^ (Name.simple v.val_name) ^ " :\n") ; + self#text_el_of_type_expr + (Name.father v.val_name) v.val_type ] ; + self#index `Value v.val_name ; Newline ] @ + (self#text_of_info v.val_info) in self#texi_of_text t @@ -550,16 +550,16 @@ class texi = method texi_of_attribute a = Odoc_info.reset_type_names () ; let t = [ self#fixedblock - [ Newline ; minus ; - Raw "val " ; - Raw (if a.att_mutable then "mutable " else "") ; - Raw (Name.simple a.att_value.val_name) ; - Raw " :\n" ; - self#text_el_of_type_expr - (Name.father a.att_value.val_name) - a.att_value.val_type ] ; - self#index `Class_att a.att_value.val_name ; Newline ] @ - (self#text_of_info a.att_value.val_info) in + [ Newline ; minus ; + Raw "val " ; + Raw (if a.att_mutable then "mutable " else "") ; + Raw (Name.simple a.att_value.val_name) ; + Raw " :\n" ; + self#text_el_of_type_expr + (Name.father a.att_value.val_name) + a.att_value.val_type ] ; + self#index `Class_att a.att_value.val_name ; Newline ] @ + (self#text_of_info a.att_value.val_info) in self#texi_of_text t @@ -567,24 +567,24 @@ class texi = method texi_of_method m = Odoc_info.reset_type_names () ; let t = [ self#fixedblock - [ Newline ; minus ; Raw "method " ; - Raw (if m.met_private then "private " else "") ; - Raw (if m.met_virtual then "virtual " else "") ; - Raw (Name.simple m.met_value.val_name) ; - Raw " :\n" ; - self#text_el_of_type_expr - (Name.father m.met_value.val_name) - m.met_value.val_type ] ; - self#index `Method m.met_value.val_name ; Newline ] @ - (self#text_of_info m.met_value.val_info) in + [ Newline ; minus ; Raw "method " ; + Raw (if m.met_private then "private " else "") ; + Raw (if m.met_virtual then "virtual " else "") ; + Raw (Name.simple m.met_value.val_name) ; + Raw " :\n" ; + self#text_el_of_type_expr + (Name.father m.met_value.val_name) + m.met_value.val_type ] ; + self#index `Method m.met_value.val_name ; Newline ] @ + (self#text_of_info m.met_value.val_info) in self#texi_of_text t method string_of_type_parameter = function - | [] -> "" - | [ tp ] -> (Odoc_info.string_of_type_expr tp) ^ " " - | l -> "(" ^ (String.concat ", " - (List.map Odoc_info.string_of_type_expr l)) ^ ") " + | [] -> "" + | [ tp ] -> (Odoc_info.string_of_type_expr tp) ^ " " + | l -> "(" ^ (String.concat ", " + (List.map Odoc_info.string_of_type_expr l)) ^ ") " method string_of_type_args = function | [] -> "" @@ -594,163 +594,163 @@ class texi = method texi_of_type ty = Odoc_info.reset_type_names () ; let t = - [ self#fixedblock ( - [ Newline ; minus ; Raw "type " ; - Raw (self#string_of_type_parameter ty.ty_parameters) ; - Raw (Name.simple ty.ty_name) ] @ - ( match ty.ty_manifest with - | None -> [] - | Some typ -> - (Raw " = ") :: (self#text_of_short_type_expr - (Name.father ty.ty_name) typ) ) @ - ( match ty.ty_kind with - | Type_abstract -> [ Newline ] - | Type_variant l -> - (Raw " =\n") :: - (List.flatten - (List.map - (fun constr -> - (Raw (" | " ^ constr.vc_name)) :: - (Raw (self#string_of_type_args constr.vc_args)) :: - (match constr.vc_text with - | None -> [ Newline ] - | Some t -> - ((Raw (indent 5 "\n(* ")) :: (self#soft_fix_linebreaks 8 t)) @ - [ Raw " *)" ; Newline ] - ) ) l ) ) - | Type_record l -> - (Raw " = {\n") :: - (List.flatten - (List.map - (fun r -> - [ Raw (" " ^ r.rf_name ^ " : ") ] @ - (self#text_of_short_type_expr - (Name.father r.rf_name) - r.rf_type) @ - [ Raw " ;" ] @ - (match r.rf_text with - | None -> [ Newline ] - | Some t -> - ((Raw (indent 5 "\n(* ")) :: (self#soft_fix_linebreaks 8 t)) @ - [ Raw " *)" ; Newline ] ) ) - l ) ) - @ [ Raw " }" ] ) ) ; - self#index `Type ty.ty_name ; Newline ] @ - (self#text_of_info ty.ty_info) in + [ self#fixedblock ( + [ Newline ; minus ; Raw "type " ; + Raw (self#string_of_type_parameter ty.ty_parameters) ; + Raw (Name.simple ty.ty_name) ] @ + ( match ty.ty_manifest with + | None -> [] + | Some typ -> + (Raw " = ") :: (self#text_of_short_type_expr + (Name.father ty.ty_name) typ) ) @ + ( match ty.ty_kind with + | Type_abstract -> [ Newline ] + | Type_variant l -> + (Raw " =\n") :: + (List.flatten + (List.map + (fun constr -> + (Raw (" | " ^ constr.vc_name)) :: + (Raw (self#string_of_type_args constr.vc_args)) :: + (match constr.vc_text with + | None -> [ Newline ] + | Some t -> + ((Raw (indent 5 "\n(* ")) :: (self#soft_fix_linebreaks 8 t)) @ + [ Raw " *)" ; Newline ] + ) ) l ) ) + | Type_record l -> + (Raw " = {\n") :: + (List.flatten + (List.map + (fun r -> + [ Raw (" " ^ r.rf_name ^ " : ") ] @ + (self#text_of_short_type_expr + (Name.father r.rf_name) + r.rf_type) @ + [ Raw " ;" ] @ + (match r.rf_text with + | None -> [ Newline ] + | Some t -> + ((Raw (indent 5 "\n(* ")) :: (self#soft_fix_linebreaks 8 t)) @ + [ Raw " *)" ; Newline ] ) ) + l ) ) + @ [ Raw " }" ] ) ) ; + self#index `Type ty.ty_name ; Newline ] @ + (self#text_of_info ty.ty_info) in self#texi_of_text t (** Return Texinfo code for an exception. *) method texi_of_exception e = Odoc_info.reset_type_names () ; let t = - [ self#fixedblock - ( [ Newline ; minus ; Raw "exception " ; - Raw (Name.simple e.ex_name) ; - Raw (self#string_of_type_args e.ex_args) ] @ - (match e.ex_alias with - | None -> [] - | Some ea -> [ Raw " = " ; Raw - ( match ea.ea_ex with - | None -> ea.ea_name - | Some e -> e.ex_name ) ; ] - ) ) ; - self#index `Exception e.ex_name ; Newline ] @ - (self#text_of_info e.ex_info) in + [ self#fixedblock + ( [ Newline ; minus ; Raw "exception " ; + Raw (Name.simple e.ex_name) ; + Raw (self#string_of_type_args e.ex_args) ] @ + (match e.ex_alias with + | None -> [] + | Some ea -> [ Raw " = " ; Raw + ( match ea.ea_ex with + | None -> ea.ea_name + | Some e -> e.ex_name ) ; ] + ) ) ; + self#index `Exception e.ex_name ; Newline ] @ + (self#text_of_info e.ex_info) in self#texi_of_text t (** Return the Texinfo code for the given module. *) method texi_of_module m = let is_alias = function - | { m_kind = Module_alias _ } -> true - | _ -> false in + | { m_kind = Module_alias _ } -> true + | _ -> false in let is_alias_there = function - | { m_kind = Module_alias { ma_module = None } } -> false - | _ -> true in + | { m_kind = Module_alias { ma_module = None } } -> false + | _ -> true in let resolve_alias_name = function - | { m_kind = Module_alias { ma_name = name } } -> name - | { m_name = name } -> name in + | { m_kind = Module_alias { ma_name = name } } -> name + | { m_name = name } -> name in let t = - [ [ self#fixedblock - [ Newline ; minus ; Raw "module " ; - Raw (Name.simple m.m_name) ; - Raw (if is_alias m - then " = " ^ (resolve_alias_name m) - else "" ) ] ] ; - ( if is_alias_there m - then [ Ref (resolve_alias_name m, Some RK_module) ; - Newline ; ] - else [] ) ; - ( if is_alias m - then [ self#index `Module m.m_name ; Newline ] - else [ Newline ] ) ; - self#text_of_info m.m_info ] + [ [ self#fixedblock + [ Newline ; minus ; Raw "module " ; + Raw (Name.simple m.m_name) ; + Raw (if is_alias m + then " = " ^ (resolve_alias_name m) + else "" ) ] ] ; + ( if is_alias_there m + then [ Ref (resolve_alias_name m, Some RK_module) ; + Newline ; ] + else [] ) ; + ( if is_alias m + then [ self#index `Module m.m_name ; Newline ] + else [ Newline ] ) ; + self#text_of_info m.m_info ] in self#texi_of_text (List.flatten t) (** Return the Texinfo code for the given module type. *) method texi_of_module_type mt = let is_alias = function - | { mt_kind = Some (Module_type_alias _) } -> true - | _ -> false in + | { mt_kind = Some (Module_type_alias _) } -> true + | _ -> false in let is_alias_there = function - | { mt_kind = Some (Module_type_alias { mta_module = None }) } -> false - | _ -> true in + | { mt_kind = Some (Module_type_alias { mta_module = None }) } -> false + | _ -> true in let resolve_alias_name = function - | { mt_kind = Some (Module_type_alias { mta_name = name }) } -> name - | { mt_name = name } -> name in + | { mt_kind = Some (Module_type_alias { mta_name = name }) } -> name + | { mt_name = name } -> name in let t = - [ [ self#fixedblock - [ Newline ; minus ; Raw "module type" ; - Raw (Name.simple mt.mt_name) ; - Raw (if is_alias mt - then " = " ^ (resolve_alias_name mt) - else "" ) ] ] ; - ( if is_alias_there mt - then [ Ref (resolve_alias_name mt, Some RK_module_type) ; - Newline ; ] - else [] ) ; - ( if is_alias mt - then [ self#index `Module_type mt.mt_name ; Newline ] - else [ Newline ] ) ; - self#text_of_info mt.mt_info ] + [ [ self#fixedblock + [ Newline ; minus ; Raw "module type" ; + Raw (Name.simple mt.mt_name) ; + Raw (if is_alias mt + then " = " ^ (resolve_alias_name mt) + else "" ) ] ] ; + ( if is_alias_there mt + then [ Ref (resolve_alias_name mt, Some RK_module_type) ; + Newline ; ] + else [] ) ; + ( if is_alias mt + then [ self#index `Module_type mt.mt_name ; Newline ] + else [ Newline ] ) ; + self#text_of_info mt.mt_info ] in self#texi_of_text (List.flatten t) (** Return the Texinfo code for the given included module. *) method texi_of_included_module im = let t = [ self#fixedblock - ( Newline :: minus :: (Raw "include module ") :: - ( match im.im_module with - | None -> - [ Raw im.im_name ] - | Some (Mod { m_name = name }) -> - [ Raw name ; Raw "\n " ; - Ref (name, Some RK_module) ] - | Some (Modtype { mt_name = name }) -> - [ Raw name ; Raw "\n " ; - Ref (name, Some RK_module_type) ] - ) ) ] in + ( Newline :: minus :: (Raw "include module ") :: + ( match im.im_module with + | None -> + [ Raw im.im_name ] + | Some (Mod { m_name = name }) -> + [ Raw name ; Raw "\n " ; + Ref (name, Some RK_module) ] + | Some (Modtype { mt_name = name }) -> + [ Raw name ; Raw "\n " ; + Ref (name, Some RK_module_type) ] + ) ) ] in self#texi_of_text t (** Return the Texinfo code for the given class. *) method texi_of_class c = Odoc_info.reset_type_names () ; let t = [ self#fixedblock - [ Newline ; minus ; Raw "class " ; - Raw (Name.simple c.cl_name) ] ; - Ref (c.cl_name, Some RK_class) ; Newline ; - Newline ] @ (self#text_of_info c.cl_info) in + [ Newline ; minus ; Raw "class " ; + Raw (Name.simple c.cl_name) ] ; + Ref (c.cl_name, Some RK_class) ; Newline ; + Newline ] @ (self#text_of_info c.cl_info) in self#texi_of_text t (** Return the Texinfo code for the given class type. *) method texi_of_class_type ct = Odoc_info.reset_type_names () ; let t = [ self#fixedblock - [ Newline ; minus ; Raw "class type " ; - Raw (Name.simple ct.clt_name) ] ; - Ref (ct.clt_name, Some RK_class_type) ; Newline ; - Newline ] @ (self#text_of_info ct.clt_info) in + [ Newline ; minus ; Raw "class type " ; + Raw (Name.simple ct.clt_name) ] ; + Ref (ct.clt_name, Some RK_class_type) ; Newline ; + Newline ] @ (self#text_of_info ct.clt_info) in self#texi_of_text t (** Return the Texinfo code for the given class element. *) @@ -772,7 +772,7 @@ class texi = | Element_exception e -> self#texi_of_exception e | Element_type t -> self#texi_of_type t | Element_module_comment t -> - self#texi_of_text (Newline :: t @ [Newline]) + self#texi_of_text (Newline :: t @ [Newline]) ) (** {3 Generating methods } @@ -781,26 +781,26 @@ class texi = (** Generate the Texinfo code for the given list of inherited classes.*) method generate_inheritance_info chanout inher_l = let f inh = - match inh.ic_class with - | None -> (* we can't make the reference *) - (Code inh.ic_name) :: - (match inh.ic_text with - | None -> [] - | Some t -> Newline :: t) - | Some cct -> (* we can create the reference *) - let kind = - match cct with - | Cl _ -> Some RK_class - | Cltype _ -> Some RK_class_type in - (Code inh.ic_name) :: - (Ref (inh.ic_name, kind)) :: - ( match inh.ic_text with - | None -> [] - | Some t -> Newline :: t) + match inh.ic_class with + | None -> (* we can't make the reference *) + (Code inh.ic_name) :: + (match inh.ic_text with + | None -> [] + | Some t -> Newline :: t) + | Some cct -> (* we can create the reference *) + let kind = + match cct with + | Cl _ -> Some RK_class + | Cltype _ -> Some RK_class_type in + (Code inh.ic_name) :: + (Ref (inh.ic_name, kind)) :: + ( match inh.ic_text with + | None -> [] + | Some t -> Newline :: t) in let text = [ - Bold [ Raw Odoc_messages.inherits ] ; - List (List.map f inher_l) ; Newline ] + Bold [ Raw Odoc_messages.inherits ] ; + List (List.map f inher_l) ; Newline ] in puts chanout (self#texi_of_text text) @@ -810,12 +810,12 @@ class texi = of the given class. *) method generate_class_inheritance_info chanout cl = let rec iter_kind = function - | Class_structure ([], _) -> () - | Class_structure (l, _) -> - self#generate_inheritance_info chanout l - | Class_constraint (k, _) -> iter_kind k - | Class_apply _ - | Class_constr _ -> () + | Class_structure ([], _) -> () + | Class_structure (l, _) -> + self#generate_inheritance_info chanout l + | Class_constraint (k, _) -> iter_kind k + | Class_apply _ + | Class_constr _ -> () in iter_kind cl.cl_kind @@ -825,12 +825,12 @@ class texi = of the given class type. *) method generate_class_type_inheritance_info chanout clt = match clt.clt_kind with - | Class_signature ([], _) -> - () - | Class_signature (l, _) -> - self#generate_inheritance_info chanout l - | Class_type _ -> - () + | Class_signature ([], _) -> + () + | Class_signature (l, _) -> + self#generate_inheritance_info chanout l + | Class_type _ -> + () (** Generate the Texinfo code for the given class, in the given out channel. *) @@ -838,28 +838,28 @@ class texi = Odoc_info.reset_type_names () ; let depth = Name.depth c.cl_name in let title = [ - self#node depth c.cl_name ; - Title (depth, None, [ Raw (Odoc_messages.clas ^ " ") ; - Code c.cl_name ]) ; - self#index `Class c.cl_name ] in + self#node depth c.cl_name ; + Title (depth, None, [ Raw (Odoc_messages.clas ^ " ") ; + Code c.cl_name ]) ; + self#index `Class c.cl_name ] in puts chanout (self#texi_of_text title) ; if is c.cl_info then begin - let descr = [ Title (succ depth, None, - [ Raw Odoc_messages.description ]) ] in - puts chanout (self#texi_of_text descr) ; - puts chanout (self#texi_of_info c.cl_info) + let descr = [ Title (succ depth, None, + [ Raw Odoc_messages.description ]) ] in + puts chanout (self#texi_of_text descr) ; + puts chanout (self#texi_of_info c.cl_info) end ; let intf = [ Title (succ depth, None, - [ Raw Odoc_messages.interface]) ] in + [ Raw Odoc_messages.interface]) ] in puts chanout (self#texi_of_text intf); self#generate_class_inheritance_info chanout c ; List.iter - (fun ele -> puts chanout - (self#texi_of_class_element c.cl_name ele)) - (Class.class_elements ~trans:false c) + (fun ele -> puts chanout + (self#texi_of_class_element c.cl_name ele)) + (Class.class_elements ~trans:false c) (** Generate the Texinfo code for the given class type, @@ -868,28 +868,28 @@ class texi = Odoc_info.reset_type_names () ; let depth = Name.depth ct.clt_name in let title = [ - self#node depth ct.clt_name ; - Title (depth, None, [ Raw (Odoc_messages.class_type ^ " ") ; - Code ct.clt_name ]) ; - self#index `Class_type ct.clt_name ] in + self#node depth ct.clt_name ; + Title (depth, None, [ Raw (Odoc_messages.class_type ^ " ") ; + Code ct.clt_name ]) ; + self#index `Class_type ct.clt_name ] in puts chanout (self#texi_of_text title) ; if is ct.clt_info then begin - let descr = [ Title (succ depth, None, - [ Raw Odoc_messages.description ]) ] in - puts chanout (self#texi_of_text descr) ; - puts chanout (self#texi_of_info ct.clt_info) + let descr = [ Title (succ depth, None, + [ Raw Odoc_messages.description ]) ] in + puts chanout (self#texi_of_text descr) ; + puts chanout (self#texi_of_info ct.clt_info) end ; let intf = [ Title (succ depth, None, - [ Raw Odoc_messages.interface ]) ] in + [ Raw Odoc_messages.interface ]) ] in puts chanout (self#texi_of_text intf) ; self#generate_class_type_inheritance_info chanout ct; List.iter - (fun ele -> puts chanout - (self#texi_of_class_element ct.clt_name ele)) - (Class.class_type_elements ~trans:false ct) + (fun ele -> puts chanout + (self#texi_of_class_element ct.clt_name ele)) + (Class.class_type_elements ~trans:false ct) @@ -898,46 +898,46 @@ class texi = method generate_for_module_type chanout mt = let depth = Name.depth mt.mt_name in let title = [ - self#node depth mt.mt_name ; - Title (depth, None, [ Raw (Odoc_messages.module_type ^ " ") ; - Code mt.mt_name ]) ; - self#index `Module_type mt.mt_name ; Newline ] in + self#node depth mt.mt_name ; + Title (depth, None, [ Raw (Odoc_messages.module_type ^ " ") ; + Code mt.mt_name ]) ; + self#index `Module_type mt.mt_name ; Newline ] in puts chanout (self#texi_of_text title) ; if is mt.mt_info then begin - let descr = [ Title (succ depth, None, - [ Raw Odoc_messages.description ]) ] in - puts chanout (self#texi_of_text descr) ; - puts chanout (self#texi_of_info mt.mt_info) + let descr = [ Title (succ depth, None, + [ Raw Odoc_messages.description ]) ] in + puts chanout (self#texi_of_text descr) ; + puts chanout (self#texi_of_info mt.mt_info) end ; let mt_ele = Module.module_type_elements ~trans:false mt in let subparts = module_subparts mt_ele in if depth < maxdepth && subparts <> [] then begin - let menu = Texi.ifinfo - ( self#heading (succ depth) [ Raw "Subparts" ]) in - puts chanout menu ; - Texi.generate_menu chanout (subparts :> subparts) + let menu = Texi.ifinfo + ( self#heading (succ depth) [ Raw "Subparts" ]) in + puts chanout menu ; + Texi.generate_menu chanout (subparts :> subparts) end ; let intf = [ Title (succ depth, None, - [ Raw Odoc_messages.interface ]) ] in + [ Raw Odoc_messages.interface ]) ] in puts chanout (self#texi_of_text intf) ; List.iter - (fun ele -> puts chanout - (self#texi_of_module_element mt.mt_name ele)) - mt_ele ; + (fun ele -> puts chanout + (self#texi_of_module_element mt.mt_name ele)) + mt_ele ; (* create sub parts for modules, module types, classes and class types *) List.iter - (function - | `Module m -> self#generate_for_module chanout m - | `Module_type mt -> self#generate_for_module_type chanout mt - | `Class c -> self#generate_for_class chanout c - | `Class_type ct -> self#generate_for_class_type chanout ct) - subparts + (function + | `Module m -> self#generate_for_module chanout m + | `Module_type mt -> self#generate_for_module_type chanout mt + | `Class c -> self#generate_for_class chanout c + | `Class_type ct -> self#generate_for_class_type chanout ct) + subparts (** Generate the Texinfo code for the given module, @@ -945,47 +945,47 @@ class texi = method generate_for_module chanout m = let depth = Name.depth m.m_name in let title = [ - self#node depth m.m_name ; - Title (depth, None, [ Raw (Odoc_messages.modul ^ " ") ; - Code m.m_name ]) ; - self#index `Module m.m_name ; Newline ] in + self#node depth m.m_name ; + Title (depth, None, [ Raw (Odoc_messages.modul ^ " ") ; + Code m.m_name ]) ; + self#index `Module m.m_name ; Newline ] in puts chanout (self#texi_of_text title) ; if is m.m_info then begin - let descr = [ Title (succ depth, None, - [ Raw Odoc_messages.description ]) ] in - puts chanout (self#texi_of_text descr) ; - puts chanout (self#texi_of_info m.m_info) + let descr = [ Title (succ depth, None, + [ Raw Odoc_messages.description ]) ] in + puts chanout (self#texi_of_text descr) ; + puts chanout (self#texi_of_info m.m_info) end ; let m_ele = Module.module_elements ~trans:false m in let subparts = module_subparts m_ele in if depth < maxdepth && subparts <> [] then begin - let menu = Texi.ifinfo - ( self#heading (succ depth) [ Raw "Subparts" ]) in - puts chanout menu ; - Texi.generate_menu chanout (subparts :> subparts) + let menu = Texi.ifinfo + ( self#heading (succ depth) [ Raw "Subparts" ]) in + puts chanout menu ; + Texi.generate_menu chanout (subparts :> subparts) end ; let intf = [ Title (succ depth, None, - [ Raw Odoc_messages.interface]) ] in + [ Raw Odoc_messages.interface]) ] in puts chanout (self#texi_of_text intf) ; List.iter - (fun ele -> puts chanout - (self#texi_of_module_element m.m_name ele)) - m_ele ; + (fun ele -> puts chanout + (self#texi_of_module_element m.m_name ele)) + m_ele ; (* create sub nodes for modules, module types, classes and class types *) List.iter - (function - | `Module m -> self#generate_for_module chanout m - | `Module_type mt -> self#generate_for_module_type chanout mt - | `Class c -> self#generate_for_class chanout c - | `Class_type ct -> self#generate_for_class_type chanout ct ) - subparts + (function + | `Module m -> self#generate_for_module chanout m + | `Module_type mt -> self#generate_for_module_type chanout mt + | `Class c -> self#generate_for_class chanout c + | `Class_type ct -> self#generate_for_class_type chanout ct ) + subparts @@ -995,52 +995,52 @@ class texi = match !Odoc_args.title with | None -> ("", "doc.info") | Some s -> - let s' = self#escape s in - (s', s' ^ ".info") + let s' = self#escape s in + (s', s' ^ ".info") in (* write a standard Texinfo header *) List.iter - (puts_nl chan) - (List.flatten - [ [ "\\input texinfo @c -*-texinfo-*-" ; - "@c %**start of header" ; - "@setfilename " ^ filename ; - "@settitle " ^ title ; - "@c %**end of header" ; ] ; - - (if !with_index then - List.map - (fun (_, shortname) -> - "@defcodeindex " ^ shortname) - indices_names - else []) ; - - [ "@ifinfo" ; - "This file was generated by Ocamldoc using the Texinfo generator." ; - "@end ifinfo" ; - - "@c no titlepage." ; - - "@node Top, , , (dir)" ; - "@top "^ title ; ] - ] ) ; + (puts_nl chan) + (List.flatten + [ [ "\\input texinfo @c -*-texinfo-*-" ; + "@c %**start of header" ; + "@setfilename " ^ filename ; + "@settitle " ^ title ; + "@c %**end of header" ; ] ; + + (if !with_index then + List.map + (fun (_, shortname) -> + "@defcodeindex " ^ shortname) + indices_names + else []) ; + + [ "@ifinfo" ; + "This file was generated by Ocamldoc using the Texinfo generator." ; + "@end ifinfo" ; + + "@c no titlepage." ; + + "@node Top, , , (dir)" ; + "@top "^ title ; ] + ] ) ; if title <> "" then begin - puts_nl chan "@ifinfo" ; - puts_nl chan ("Documentation for " ^ title) ; - puts_nl chan "@end ifinfo" + puts_nl chan "@ifinfo" ; + puts_nl chan ("Documentation for " ^ title) ; + puts_nl chan "@end ifinfo" end else puts_nl chan "@c no title given" ; (* write a top menu *) Texi.generate_menu chan - ((List.map (fun m -> `Module m) m_list) @ - (if !with_index then - [ `Blank ; `Comment "Indices :" ] @ - (List.map - (fun (longname, _) -> `Index (longname ^ " index")) - indices_names ) - else [] )) + ((List.map (fun m -> `Module m) m_list) @ + (if !with_index then + [ `Blank ; `Comment "Indices :" ] @ + (List.map + (fun (longname, _) -> `Index (longname ^ " index")) + indices_names ) + else [] )) (** Writes the header of the TeX document. *) @@ -1048,14 +1048,14 @@ class texi = nl chan ; if !with_index then - List.iter (puts_nl chan) - (List.flatten - (List.map - (fun (longname, shortname) -> - [ "@node " ^ longname ^ " index," ; - "@unnumbered " ^ longname ^ " index" ; - "@printindex " ^ shortname ; ]) - indices_names )) ; + List.iter (puts_nl chan) + (List.flatten + (List.map + (fun (longname, shortname) -> + [ "@node " ^ longname ^ " index," ; + "@unnumbered " ^ longname ^ " index" ; + "@printindex " ^ shortname ; ]) + indices_names )) ; if !Odoc_args.with_toc then puts_nl chan "@contents" ; puts_nl chan "@bye" @@ -1066,22 +1066,22 @@ class texi = in the {!Odoc_args.out_file} file. *) method generate module_list = try - let chanout = open_out - (Filename.concat !Odoc_args.target_dir !Odoc_args.out_file) in - if !Odoc_args.with_header - then self#generate_texi_header chanout module_list ; - List.iter - (fun modu -> - Odoc_info.verbose ("Generate for module " ^ modu.m_name) ; - self#generate_for_module chanout modu) - module_list ; - if !Odoc_args.with_trailer - then self#generate_texi_trailer chanout ; - close_out chanout + let chanout = open_out + (Filename.concat !Odoc_args.target_dir !Odoc_args.out_file) in + if !Odoc_args.with_header + then self#generate_texi_header chanout module_list ; + List.iter + (fun modu -> + Odoc_info.verbose ("Generate for module " ^ modu.m_name) ; + self#generate_for_module chanout modu) + module_list ; + if !Odoc_args.with_trailer + then self#generate_texi_trailer chanout ; + close_out chanout with - | Failure s - | Sys_error s -> - prerr_endline s ; - incr Odoc_info.errors + | Failure s + | Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors end diff --git a/ocamldoc/odoc_text.ml b/ocamldoc/odoc_text.ml index 5a712e5b4..5a9b9130f 100644 --- a/ocamldoc/odoc_text.ml +++ b/ocamldoc/odoc_text.ml @@ -18,13 +18,13 @@ module Texter = let text_of_string s = let lexbuf = Lexing.from_string s in try - Odoc_text_lexer.init (); - Odoc_text_parser.main Odoc_text_lexer.main lexbuf + Odoc_text_lexer.init (); + Odoc_text_parser.main Odoc_text_lexer.main lexbuf with - _ -> - raise (Text_syntax (!Odoc_text_lexer.line_number, - !Odoc_text_lexer.char_number, - s) - ) + _ -> + raise (Text_syntax (!Odoc_text_lexer.line_number, + !Odoc_text_lexer.char_number, + s) + ) end diff --git a/ocamldoc/odoc_text_lexer.mll b/ocamldoc/odoc_text_lexer.mll index 54b7db057..e8cc9f56f 100644 --- a/ocamldoc/odoc_text_lexer.mll +++ b/ocamldoc/odoc_text_lexer.mll @@ -169,77 +169,77 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) then + Char (Lexing.lexeme lexbuf) else - let _ = - if !ele_ref_mode then - ele_ref_mode := false - in - END + let _ = + if !ele_ref_mode then + ele_ref_mode := false + in + END } | begin_title { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - let s = Lexing.lexeme lexbuf in - try + let s = Lexing.lexeme lexbuf in + try (* chech if the "{..." or html_title mark was used. *) - if s.[0] = '<' then - let (n, l) = (2, (String.length s - 3)) in - let s2 = String.sub s n l in - Title (int_of_string s2, None) - else - let (n, l) = (1, (String.length s - 2)) in - let s2 = String.sub s n l in - try - let i = String.index s2 ':' in - let s_n = String.sub s2 0 i in - let s_label = String.sub s2 (i+1) (l-i-1) in - Title (int_of_string s_n, Some s_label) - with - Not_found -> - Title (int_of_string s2, None) - with - _ -> - Title (1, None) + if s.[0] = '<' then + let (n, l) = (2, (String.length s - 3)) in + let s2 = String.sub s n l in + Title (int_of_string s2, None) + else + let (n, l) = (1, (String.length s - 2)) in + let s2 = String.sub s n l in + try + let i = String.index s2 ':' in + let s_n = String.sub s2 0 i in + let s_label = String.sub s2 (i+1) (l-i-1) in + Title (int_of_string s_n, Some s_label) + with + Not_found -> + Title (int_of_string s2, None) + with + _ -> + Title (1, None) } | begin_bold { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - BOLD + BOLD } | begin_italic { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - ITALIC + ITALIC } | begin_link { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - LINK + LINK } | begin_emp { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else EMP } @@ -247,8 +247,8 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else SUPERSCRIPT } @@ -256,8 +256,8 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else SUBSCRIPT } @@ -265,17 +265,17 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - CENTER + CENTER } | begin_left { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else LEFT } @@ -283,8 +283,8 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode - or (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + or (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else RIGHT } @@ -292,8 +292,8 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else LIST } @@ -301,43 +301,43 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - ENUM + ENUM } | begin_item { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - ITEM + ITEM } | begin_latex { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or - (!open_brackets >= 1) or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - ( - latex_mode := true; - LATEX - ) + ( + latex_mode := true; + LATEX + ) } | end_latex { incr_cpts lexbuf ; if !verb_mode or (!open_brackets >= 1) or !code_pre_mode or - !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + !ele_ref_mode then + Char (Lexing.lexeme lexbuf) else - ( - latex_mode := false; - END_LATEX - ) + ( + latex_mode := false; + END_LATEX + ) } | begin_code end_code { @@ -349,35 +349,35 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + Char (Lexing.lexeme lexbuf) else if !open_brackets <= 0 then - ( - open_brackets := 1; - CODE - ) - else - ( - incr open_brackets; - Char (Lexing.lexeme lexbuf) - ) + ( + open_brackets := 1; + CODE + ) + else + ( + incr open_brackets; + Char (Lexing.lexeme lexbuf) + ) } | end_code { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + Char (Lexing.lexeme lexbuf) else - if !open_brackets > 1 then - ( - decr open_brackets; - Char "]" - ) - else - ( - open_brackets := 0; - END_CODE - ) + if !open_brackets > 1 then + ( + decr open_brackets; + Char "]" + ) + else + ( + open_brackets := 0; + END_CODE + ) } | begin_code_pre end_code_pre @@ -390,26 +390,26 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + Char (Lexing.lexeme lexbuf) else - ( - code_pre_mode := true; - CODE_PRE - ) + ( + code_pre_mode := true; + CODE_PRE + ) } | end_code_pre { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + Char (Lexing.lexeme lexbuf) else - if !code_pre_mode then - ( - code_pre_mode := false; - END_CODE_PRE - ) - else - Char (Lexing.lexeme lexbuf) + if !code_pre_mode then + ( + code_pre_mode := false; + END_CODE_PRE + ) + else + Char (Lexing.lexeme lexbuf) } | begin_ele_ref end @@ -422,66 +422,66 @@ rule main = parse { incr_cpts lexbuf ; if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then - Char (Lexing.lexeme lexbuf) + Char (Lexing.lexeme lexbuf) else if not !ele_ref_mode then - ( - ele_ref_mode := true; - ELE_REF - ) - else - ( - Char (Lexing.lexeme lexbuf) - ) + ( + ele_ref_mode := true; + ELE_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) } | begin_verb { incr_cpts lexbuf ; if !latex_mode or (!open_brackets >= 1) or !code_pre_mode or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + Char (Lexing.lexeme lexbuf) else - ( - verb_mode := true; - VERB - ) + ( + verb_mode := true; + VERB + ) } | end_verb { incr_cpts lexbuf ; if !latex_mode or (!open_brackets >= 1) or !code_pre_mode or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + Char (Lexing.lexeme lexbuf) else - ( - verb_mode := false; - END_VERB - ) + ( + verb_mode := false; + END_VERB + ) } | shortcut_list_item { incr_cpts lexbuf ; if !shortcut_list_mode then - ( - SHORTCUT_LIST_ITEM - ) + ( + SHORTCUT_LIST_ITEM + ) else ( - shortcut_list_mode := true; - BEGIN_SHORTCUT_LIST_ITEM - ) + shortcut_list_mode := true; + BEGIN_SHORTCUT_LIST_ITEM + ) } | shortcut_enum_item { incr_cpts lexbuf ; if !shortcut_list_mode then - SHORTCUT_ENUM_ITEM + SHORTCUT_ENUM_ITEM else ( - shortcut_list_mode := true; - BEGIN_SHORTCUT_ENUM_ITEM - ) + shortcut_list_mode := true; + BEGIN_SHORTCUT_ENUM_ITEM + ) } | end_shortcut_list { @@ -491,15 +491,15 @@ rule main = parse lexbuf.Lexing.lex_last_pos <- lexbuf.Lexing.lex_last_pos - 1; decr line_number ; if !shortcut_list_mode then - ( - shortcut_list_mode := false; - (* go back one char to re-use the last '\n', so we can - restart another shortcut-list with a single blank line, - and not two.*) - END_SHORTCUT_LIST - ) + ( + shortcut_list_mode := false; + (* go back one char to re-use the last '\n', so we can + restart another shortcut-list with a single blank line, + and not two.*) + END_SHORTCUT_LIST + ) else - BLANK_LINE + BLANK_LINE } | eof { EOF } @@ -508,9 +508,9 @@ rule main = parse { incr_cpts lexbuf ; if !latex_mode or (!open_brackets >= 1) or !code_pre_mode or !ele_ref_mode then - Char (Lexing.lexeme lexbuf) + Char (Lexing.lexeme lexbuf) else - ERROR + ERROR } | _ { diff --git a/ocamldoc/odoc_to_text.ml b/ocamldoc/odoc_to_text.ml index 27d0d8072..77d9aec6c 100644 --- a/ocamldoc/odoc_to_text.ml +++ b/ocamldoc/odoc_to_text.ml @@ -34,134 +34,134 @@ class virtual info = (** @return [etxt] value for an authors list. *) method text_of_author_list l = match l with - [] -> - [] + [] -> + [] | _ -> - [ Bold [Raw (Odoc_messages.authors^": ")] ; - Raw (String.concat ", " l) ; - Newline - ] + [ Bold [Raw (Odoc_messages.authors^": ")] ; + Raw (String.concat ", " l) ; + Newline + ] (** @return [text] value for the given optional version information.*) method text_of_version_opt v_opt = match v_opt with - None -> [] + None -> [] | Some v -> [ Bold [Raw (Odoc_messages.version^": ")] ; - Raw v ; - Newline - ] + Raw v ; + Newline + ] (** @return [text] value for the given optional since information.*) method text_of_since_opt s_opt = match s_opt with - None -> [] + None -> [] | Some s -> [ Bold [Raw (Odoc_messages.since^": ")] ; - Raw s ; - Newline - ] + Raw s ; + Newline + ] (** @return [text] value for the given list of raised exceptions.*) method text_of_raised_exceptions l = match l with - [] -> [] + [] -> [] | (s, t) :: [] -> - [ Bold [ Raw Odoc_messages.raises ] ; - Raw " " ; - Code s ; - Raw " " - ] - @ t - @ [ Newline ] + [ Bold [ Raw Odoc_messages.raises ] ; + Raw " " ; + Code s ; + Raw " " + ] + @ t + @ [ Newline ] | _ -> - [ Bold [ Raw Odoc_messages.raises ] ; - Raw " " ; - List - (List.map - (fun (ex, desc) ->(Code ex) :: (Raw " ") :: desc ) - l - ) ; - Newline - ] + [ Bold [ Raw Odoc_messages.raises ] ; + Raw " " ; + List + (List.map + (fun (ex, desc) ->(Code ex) :: (Raw " ") :: desc ) + l + ) ; + Newline + ] (** Return [text] value for the given "see also" reference. *) method text_of_see (see_ref, t) = let t_ref = - match see_ref with - Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] - | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t - | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t + match see_ref with + Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] + | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t + | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t in t_ref - + (** Return [text] value for the given list of "see also" references.*) method text_of_sees l = match l with - [] -> [] + [] -> [] | see :: [] -> - (Bold [ Raw Odoc_messages.see_also ]) :: - (Raw " ") :: - (self#text_of_see see) @ [ Newline ] + (Bold [ Raw Odoc_messages.see_also ]) :: + (Raw " ") :: + (self#text_of_see see) @ [ Newline ] | _ -> - (Bold [ Raw Odoc_messages.see_also ]) :: - [ List - (List.map - (fun see -> self#text_of_see see) - l - ); - Newline - ] + (Bold [ Raw Odoc_messages.see_also ]) :: + [ List + (List.map + (fun see -> self#text_of_see see) + l + ); + Newline + ] (** @return [text] value for the given optional return information.*) method text_of_return_opt return_opt = match return_opt with - None -> [] + None -> [] | Some t -> (Bold [Raw (Odoc_messages.returns^" ")]) :: t @ [ Newline ] (** Return a [text] for the given list of custom tagged texts. *) method text_of_custom l = List.fold_left - (fun acc -> fun (tag, text) -> - try - let f = List.assoc tag tag_functions in - match acc with - [] -> f text - | _ -> acc @ (Newline :: (f text)) - with - Not_found -> - Odoc_info.warning (Odoc_messages.tag_not_handled tag) ; - acc - ) - [] - l + (fun acc -> fun (tag, text) -> + try + let f = List.assoc tag tag_functions in + match acc with + [] -> f text + | _ -> acc @ (Newline :: (f text)) + with + Not_found -> + Odoc_info.warning (Odoc_messages.tag_not_handled tag) ; + acc + ) + [] + l (** @return [text] value for a description, except for the i_params field. *) method text_of_info ?(block=true) info_opt = match info_opt with - None -> - [] + None -> + [] | Some info -> - let t = - (match info.i_deprecated with - None -> [] - | Some t -> ( Italic [Raw (Odoc_messages.deprecated^" ")] ) :: t - ) @ - (match info.i_desc with - None -> [] - | Some t when t = [Odoc_info.Raw ""] -> [] - | Some t -> t @ [ Newline ] - ) @ - (self#text_of_author_list info.i_authors) @ - (self#text_of_version_opt info.i_version) @ - (self#text_of_since_opt info.i_since) @ - (self#text_of_raised_exceptions info.i_raised_exceptions) @ - (self#text_of_return_opt info.i_return_value) @ - (self#text_of_sees info.i_sees) @ - (self#text_of_custom info.i_custom) - in - if block then - [Block t] - else - t + let t = + (match info.i_deprecated with + None -> [] + | Some t -> ( Italic [Raw (Odoc_messages.deprecated^" ")] ) :: t + ) @ + (match info.i_desc with + None -> [] + | Some t when t = [Odoc_info.Raw ""] -> [] + | Some t -> t @ [ Newline ] + ) @ + (self#text_of_author_list info.i_authors) @ + (self#text_of_version_opt info.i_version) @ + (self#text_of_since_opt info.i_since) @ + (self#text_of_raised_exceptions info.i_raised_exceptions) @ + (self#text_of_return_opt info.i_return_value) @ + (self#text_of_sees info.i_sees) @ + (self#text_of_custom info.i_custom) + in + if block then + [Block t] + else + t end (** This class defines methods to generate a [text] structure from elements. *) @@ -176,14 +176,14 @@ class virtual to_text = Also remove the "hidden modules".*) method relative_idents m_name s = let f str_t = - let match_s = Str.matched_string str_t in - let rel = Name.get_relative m_name match_s in - Odoc_info.apply_if_equal Odoc_info.use_hidden_modules match_s rel + let match_s = Str.matched_string str_t in + let rel = Name.get_relative m_name match_s in + Odoc_info.apply_if_equal Odoc_info.use_hidden_modules match_s rel in let s2 = Str.global_substitute - (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") - f - s + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") + f + s in s2 @@ -206,11 +206,11 @@ class virtual to_text = (** @return [text] value to represent a [Types.type_expr].*) method text_of_type_expr module_name t = let t = List.flatten - (List.map - (fun s -> [Code s ; Newline ]) - (Str.split (Str.regexp "\n") - (self#normal_type module_name t)) - ) + (List.map + (fun s -> [Code s ; Newline ]) + (Str.split (Str.regexp "\n") + (self#normal_type module_name t)) + ) in t @@ -221,13 +221,13 @@ class virtual to_text = (** Return [text] value or the given list of [Types.type_expr], with the given separator. *) method text_of_type_expr_list module_name sep l = - [ Code (self#normal_type_list module_name sep l) ] + [ Code (self#normal_type_list module_name sep l) ] (** @return [text] value to represent a [Types.module_type]. *) method text_of_module_type t = let s = String.concat "\n" - (Str.split (Str.regexp "\n") (Odoc_info.string_of_module_type t)) + (Str.split (Str.regexp "\n") (Odoc_info.string_of_module_type t)) in [ Code s ] @@ -237,7 +237,7 @@ class virtual to_text = Format.fprintf Format.str_formatter "@[<hov 2>val %s :@ " s_name; let s = - (self#normal_type (Name.father v.val_name) v.val_type) + (self#normal_type (Name.father v.val_name) v.val_type) in [ CodePre s ] @ [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ @@ -247,8 +247,8 @@ class virtual to_text = method text_of_attribute a = let s_name = Name.simple a.att_value.val_name in Format.fprintf Format.str_formatter "@[<hov 2>val %s%s :@ " - (if a.att_mutable then "mutable " else "") - s_name; + (if a.att_mutable then "mutable " else "") + s_name; let mod_name = Name.father a.att_value.val_name in let s = self#normal_type mod_name a.att_value.val_type in (CodePre s) :: @@ -259,9 +259,9 @@ class virtual to_text = method text_of_method m = let s_name = Name.simple m.met_value.val_name in Format.fprintf Format.str_formatter "@[<hov 2>method %s%s%s :@ " - (if m.met_private then "private " else "") - (if m.met_virtual then "virtual " else "") - s_name ; + (if m.met_private then "private " else "") + (if m.met_virtual then "virtual " else "") + s_name ; let mod_name = Name.father m.met_value.val_name in let s = self#normal_type mod_name m.met_value.val_type in (CodePre s) :: @@ -273,25 +273,25 @@ class virtual to_text = method text_of_exception e = let s_name = Name.simple e.ex_name in Format.fprintf Format.str_formatter "@[<hov 2>exception %s" s_name ; - (match e.ex_args with - [] -> () - | _ -> - Format.fprintf Format.str_formatter "@ of " - ); + (match e.ex_args with + [] -> () + | _ -> + Format.fprintf Format.str_formatter "@ of " + ); let s = self#normal_type_list (Name.father e.ex_name) " * " e.ex_args in let s2 = - Format.fprintf Format.str_formatter "%s" s ; - (match e.ex_alias with - None -> () - | Some ea -> - Format.fprintf Format.str_formatter " = %s" - ( - match ea.ea_ex with - None -> ea.ea_name - | Some e -> e.ex_name - ) - ); - Format.flush_str_formatter () + Format.fprintf Format.str_formatter "%s" s ; + (match e.ex_alias with + None -> () + | Some ea -> + Format.fprintf Format.str_formatter " = %s" + ( + match ea.ea_ex with + None -> ea.ea_name + | Some e -> e.ex_name + ) + ); + Format.flush_str_formatter () in [ CodePre s2 ] @ [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ @@ -300,220 +300,220 @@ class virtual to_text = (** Return [text] value for the description of a function parameter. *) method text_of_parameter_description p = match Parameter.names p with - [] -> [] + [] -> [] | name :: [] -> - ( + ( (* Only one name, no need for label for the description. *) - match Parameter.desc_by_name p name with - None -> [] - | Some t -> t - ) + match Parameter.desc_by_name p name with + None -> [] + | Some t -> t + ) | l -> (* A list of names, we display those with a description. *) - let l2 = List.filter (fun n -> (Parameter.desc_by_name p n) <> None) l in - match l2 with - [] -> [] - | _ -> - [List - (List.map - (fun n -> - match Parameter.desc_by_name p n with - None -> [] (* should not occur *) - | Some t -> [Code (n^" ") ; Raw ": "] @ t - ) - l2 - ) - ] + let l2 = List.filter (fun n -> (Parameter.desc_by_name p n) <> None) l in + match l2 with + [] -> [] + | _ -> + [List + (List.map + (fun n -> + match Parameter.desc_by_name p n with + None -> [] (* should not occur *) + | Some t -> [Code (n^" ") ; Raw ": "] @ t + ) + l2 + ) + ] (** Return [text] value for a list of parameters. *) method text_of_parameter_list m_name l = match l with - [] -> - [] + [] -> + [] | _ -> - [ Bold [Raw Odoc_messages.parameters] ; - Raw ":" ; - List - (List.map - (fun p -> - (match Parameter.complete_name p with - "" -> Code "?" - | s -> Code s - ) :: - [Code " : "] @ - (self#text_of_short_type_expr m_name (Parameter.typ p)) @ - [Newline] @ - (self#text_of_parameter_description p) - ) - l - ) - ] + [ Bold [Raw Odoc_messages.parameters] ; + Raw ":" ; + List + (List.map + (fun p -> + (match Parameter.complete_name p with + "" -> Code "?" + | s -> Code s + ) :: + [Code " : "] @ + (self#text_of_short_type_expr m_name (Parameter.typ p)) @ + [Newline] @ + (self#text_of_parameter_description p) + ) + l + ) + ] (** Return [text] value for a list of module parameters. *) method text_of_module_parameter_list l = match l with - [] -> - [] + [] -> + [] | _ -> - [ Newline ; - Bold [Raw Odoc_messages.parameters] ; - Raw ":" ; - List - (List.map - (fun (p, desc_opt) -> - [Code (p.mp_name^" : ")] @ - (self#text_of_module_type p.mp_type) @ - (match desc_opt with - None -> [] - | Some t -> (Raw " ") :: t) - ) - l - ) - ] + [ Newline ; + Bold [Raw Odoc_messages.parameters] ; + Raw ":" ; + List + (List.map + (fun (p, desc_opt) -> + [Code (p.mp_name^" : ")] @ + (self#text_of_module_type p.mp_type) @ + (match desc_opt with + None -> [] + | Some t -> (Raw " ") :: t) + ) + l + ) + ] (**/**) (** Return [text] value for the given [class_kind].*) method text_of_class_kind father ckind = match ckind with - Class_structure _ -> - [Code Odoc_messages.object_end] - - | Class_apply capp -> - [Code - ( - ( - match capp.capp_class with - None -> capp.capp_name - | Some cl -> cl.cl_name - )^ - " "^ - (String.concat " " - (List.map - (fun s -> "("^s^")") - capp.capp_params_code)) - ) - ] - - | Class_constr cco -> - ( - match cco.cco_type_parameters with - [] -> [] - | l -> - (Code "["):: - (self#text_of_type_expr_list father ", " l)@ - [Code "] "] - )@ - [Code ( - match cco.cco_class with - None -> cco.cco_name - | Some (Cl cl) -> Name.get_relative father cl.cl_name - | Some (Cltype (clt,_)) -> Name.get_relative father clt.clt_name - ) - ] - - | Class_constraint (ck, ctk) -> - [Code "( "] @ - (self#text_of_class_kind father ck) @ - [Code " : "] @ - (self#text_of_class_type_kind father ctk) @ - [Code " )"] + Class_structure _ -> + [Code Odoc_messages.object_end] + + | Class_apply capp -> + [Code + ( + ( + match capp.capp_class with + None -> capp.capp_name + | Some cl -> cl.cl_name + )^ + " "^ + (String.concat " " + (List.map + (fun s -> "("^s^")") + capp.capp_params_code)) + ) + ] + + | Class_constr cco -> + ( + match cco.cco_type_parameters with + [] -> [] + | l -> + (Code "["):: + (self#text_of_type_expr_list father ", " l)@ + [Code "] "] + )@ + [Code ( + match cco.cco_class with + None -> cco.cco_name + | Some (Cl cl) -> Name.get_relative father cl.cl_name + | Some (Cltype (clt,_)) -> Name.get_relative father clt.clt_name + ) + ] + + | Class_constraint (ck, ctk) -> + [Code "( "] @ + (self#text_of_class_kind father ck) @ + [Code " : "] @ + (self#text_of_class_type_kind father ctk) @ + [Code " )"] (** Return [text] value for the given [class_type_kind].*) method text_of_class_type_kind father ctkind = match ctkind with - Class_type cta -> - ( - match cta.cta_type_parameters with - [] -> [] - | l -> - (Code "[") :: - (self#text_of_type_expr_list father ", " l) @ - [Code "] "] - ) @ - ( - match cta.cta_class with - None -> [ Code cta.cta_name ] - | Some (Cltype (clt, _)) -> - let rel = Name.get_relative father clt.clt_name in - [Code rel] - | Some (Cl cl) -> - let rel = Name.get_relative father cl.cl_name in - [Code rel] - ) - | Class_signature _ -> - [Code Odoc_messages.object_end] + Class_type cta -> + ( + match cta.cta_type_parameters with + [] -> [] + | l -> + (Code "[") :: + (self#text_of_type_expr_list father ", " l) @ + [Code "] "] + ) @ + ( + match cta.cta_class with + None -> [ Code cta.cta_name ] + | Some (Cltype (clt, _)) -> + let rel = Name.get_relative father clt.clt_name in + [Code rel] + | Some (Cl cl) -> + let rel = Name.get_relative father cl.cl_name in + [Code rel] + ) + | Class_signature _ -> + [Code Odoc_messages.object_end] (** Return [text] value for a [module_kind]. *) method text_of_module_kind ?(with_def_syntax=true) k = match k with - Module_alias m_alias -> - (match m_alias.ma_module with - None -> - [Code ((if with_def_syntax then " = " else "")^m_alias.ma_name)] - | Some (Mod m) -> - [Code ((if with_def_syntax then " = " else "")^m.m_name)] - | Some (Modtype mt) -> - [Code ((if with_def_syntax then " = " else "")^mt.mt_name)] - ) + Module_alias m_alias -> + (match m_alias.ma_module with + None -> + [Code ((if with_def_syntax then " = " else "")^m_alias.ma_name)] + | Some (Mod m) -> + [Code ((if with_def_syntax then " = " else "")^m.m_name)] + | Some (Modtype mt) -> + [Code ((if with_def_syntax then " = " else "")^mt.mt_name)] + ) | Module_apply (k1, k2) -> - (if with_def_syntax then [Code " = "] else []) @ - (self#text_of_module_kind ~with_def_syntax: false k1) @ - [Code " ( "] @ - (self#text_of_module_kind ~with_def_syntax: false k2) @ - [Code " ) "] - + (if with_def_syntax then [Code " = "] else []) @ + (self#text_of_module_kind ~with_def_syntax: false k1) @ + [Code " ( "] @ + (self#text_of_module_kind ~with_def_syntax: false k2) @ + [Code " ) "] + | Module_with (tk, code) -> - (if with_def_syntax then [Code " : "] else []) @ - (self#text_of_module_type_kind ~with_def_syntax: false tk) @ - [Code code] - + (if with_def_syntax then [Code " : "] else []) @ + (self#text_of_module_type_kind ~with_def_syntax: false tk) @ + [Code code] + | Module_constraint (k, tk) -> - (if with_def_syntax then [Code " : "] else []) @ - [Code "( "] @ - (self#text_of_module_kind ~with_def_syntax: false k) @ - [Code " : "] @ - (self#text_of_module_type_kind ~with_def_syntax: false tk) @ - [Code " )"] - + (if with_def_syntax then [Code " : "] else []) @ + [Code "( "] @ + (self#text_of_module_kind ~with_def_syntax: false k) @ + [Code " : "] @ + (self#text_of_module_type_kind ~with_def_syntax: false tk) @ + [Code " )"] + | Module_struct _ -> - [Code ((if with_def_syntax then " : " else "")^ - Odoc_messages.struct_end^" ")] + [Code ((if with_def_syntax then " : " else "")^ + Odoc_messages.struct_end^" ")] | Module_functor (_, k) -> - (if with_def_syntax then [Code " : "] else []) @ - [Code "functor ... "] @ - [Code " -> "] @ - (self#text_of_module_kind ~with_def_syntax: false k) + (if with_def_syntax then [Code " : "] else []) @ + [Code "functor ... "] @ + [Code " -> "] @ + (self#text_of_module_kind ~with_def_syntax: false k) (** Return html code for a [module_type_kind]. *) method text_of_module_type_kind ?(with_def_syntax=true) tk = match tk with | Module_type_struct _ -> - [Code ((if with_def_syntax then " = " else "")^Odoc_messages.sig_end)] + [Code ((if with_def_syntax then " = " else "")^Odoc_messages.sig_end)] | Module_type_functor (params, k) -> - let f p = - [Code ("("^p.mp_name^" : ")] @ - (self#text_of_module_type p.mp_type) @ - [Code ") -> "] - in - let t1 = List.flatten (List.map f params) in - let t2 = self#text_of_module_type_kind ~with_def_syntax: false k in - (if with_def_syntax then [Code " = "] else []) @ t1 @ t2 - + let f p = + [Code ("("^p.mp_name^" : ")] @ + (self#text_of_module_type p.mp_type) @ + [Code ") -> "] + in + let t1 = List.flatten (List.map f params) in + let t2 = self#text_of_module_type_kind ~with_def_syntax: false k in + (if with_def_syntax then [Code " = "] else []) @ t1 @ t2 + | Module_type_with (tk2, code) -> - let t = self#text_of_module_type_kind ~with_def_syntax: false tk2 in - (if with_def_syntax then [Code " = "] else []) @ - t @ [Code code] + let t = self#text_of_module_type_kind ~with_def_syntax: false tk2 in + (if with_def_syntax then [Code " = "] else []) @ + t @ [Code code] | Module_type_alias mt_alias -> - [Code ((if with_def_syntax then " = " else "")^ - (match mt_alias.mta_module with - None -> mt_alias.mta_name - | Some mt -> mt.mt_name)) - ] + [Code ((if with_def_syntax then " = " else "")^ + (match mt_alias.mta_module with + None -> mt_alias.mta_name + | Some mt -> mt.mt_name)) + ] end diff --git a/ocamldoc/odoc_types.mli b/ocamldoc/odoc_types.mli index a26e76cdc..c84f37bbb 100644 --- a/ocamldoc/odoc_types.mli +++ b/ocamldoc/odoc_types.mli @@ -101,9 +101,9 @@ type merge_option = | Merge_since (** Since information are concatenated. *) | Merge_deprecated (** Deprecated information are concatenated. *) | Merge_param (** Information on each parameter is concatenated, - and all parameters are kept. *) + and all parameters are kept. *) | Merge_raised_exception (** Information on each raised_exception is concatenated, - and all raised exceptions are kept. *) + and all raised exceptions are kept. *) | Merge_return_value (** Information on return value are concatenated. *) | Merge_custom (** Merge custom tags (all pairs (tag, text) are kept). *) diff --git a/ocamldoc/odoc_value.ml b/ocamldoc/odoc_value.ml index 1bbb80df6..b5b8eb0d4 100644 --- a/ocamldoc/odoc_value.ml +++ b/ocamldoc/odoc_value.ml @@ -30,14 +30,14 @@ type t_value = { (** Representation of a class attribute. *) type t_attribute = { att_value : t_value ; (** an attribute has almost all the same information - as a value *) + as a value *) att_mutable : bool ; } (** Representation of a class method. *) type t_method = { met_value : t_value ; (** a method has almost all the same information - as a value *) + as a value *) met_private : bool ; met_virtual : bool ; } @@ -51,11 +51,11 @@ let value_parameter_text_by_name v name = None -> None | Some i -> try - let t = List.assoc name i.Odoc_types.i_params in - Some t + let t = List.assoc name i.Odoc_types.i_params in + Some t with - Not_found -> - None + Not_found -> + None (** Update the parameters text of a t_value, according to the val_info field. *) let update_value_parameters_text v = @@ -70,9 +70,9 @@ let parameter_list_from_arrows typ = let rec iter t = match t.Types.desc with Types.Tarrow (l, t1, t2, _) -> - (l, t1) :: (iter t2) + (l, t1) :: (iter t2) | _ -> - [] + [] in iter typ @@ -86,33 +86,33 @@ let dummy_parameter_list typ = match s with "" -> s | _ -> - match s.[0] with - '?' -> String.sub s 1 ((String.length s) - 1) - | _ -> s + match s.[0] with + '?' -> String.sub s 1 ((String.length s) - 1) + | _ -> s in Printtyp.mark_loops typ; let liste_param = parameter_list_from_arrows typ in let rec iter (label, t) = match t.Types.desc with | Types.Ttuple l -> - if label = "" then - Odoc_parameter.Tuple - (List.map (fun t2 -> iter ("", t2)) l, t) - else - (* if there is a label, then we don't want to decompose the tuple *) - Odoc_parameter.Simple_name - { Odoc_parameter.sn_name = normal_name label ; - Odoc_parameter.sn_type = t ; - Odoc_parameter.sn_text = None } + if label = "" then + Odoc_parameter.Tuple + (List.map (fun t2 -> iter ("", t2)) l, t) + else + (* if there is a label, then we don't want to decompose the tuple *) + Odoc_parameter.Simple_name + { Odoc_parameter.sn_name = normal_name label ; + Odoc_parameter.sn_type = t ; + Odoc_parameter.sn_text = None } | Types.Tlink t2 | Types.Tsubst t2 -> - (iter (label, t2)) + (iter (label, t2)) | _ -> - Odoc_parameter.Simple_name - { Odoc_parameter.sn_name = normal_name label ; - Odoc_parameter.sn_type = t ; - Odoc_parameter.sn_text = None } + Odoc_parameter.Simple_name + { Odoc_parameter.sn_name = normal_name label ; + Odoc_parameter.sn_type = t ; + Odoc_parameter.sn_text = None } in List.map iter liste_param @@ -121,12 +121,12 @@ let is_function v = let rec f t = match t.Types.desc with Types.Tarrow _ -> - true + true | Types.Tlink t -> - f t - | _ -> - false + f t + | _ -> + false in f v.val_type - + diff --git a/ocamldoc/runocamldoc b/ocamldoc/runocamldoc index b5fcfb51e..a71d705cc 100644 --- a/ocamldoc/runocamldoc +++ b/ocamldoc/runocamldoc @@ -5,8 +5,8 @@ case "$1" in true) shift exec ../boot/ocamlrun -I ../otherlibs/unix -I ../otherlibs/str \ ./ocamldoc "$@" - ;; + ;; *) shift - exec ./ocamldoc "$@" - ;; + exec ./ocamldoc "$@" + ;; esac |