2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2001 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
(** Analysis of source files. This module is strongly inspired from
|
|
|
|
driver/main.ml :-) *)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
open Format
|
|
|
|
open Typedtree
|
|
|
|
|
2004-08-20 10:04:35 -07:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** Initialize the search path.
|
|
|
|
The current directory is always searched first,
|
|
|
|
then the directories specified with the -I option (in command-line order),
|
|
|
|
then the standard library directory. *)
|
2019-03-11 11:38:16 -07:00
|
|
|
let init_path () = Compmisc.init_path ()
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Return the initial environment in which compilation proceeds. *)
|
|
|
|
let initial_env () =
|
2018-09-01 07:56:57 -07:00
|
|
|
let current = Env.get_unit_name () in
|
|
|
|
let initial = !Odoc_global.initially_opened_module in
|
2017-01-12 03:56:24 -08:00
|
|
|
let initially_opened_module =
|
2018-09-01 07:56:57 -07:00
|
|
|
if initial = current then
|
2017-01-12 03:56:24 -08:00
|
|
|
None
|
|
|
|
else
|
2018-09-01 07:56:57 -07:00
|
|
|
Some initial
|
2017-01-12 03:56:24 -08:00
|
|
|
in
|
2018-09-01 07:56:57 -07:00
|
|
|
let open_implicit_modules =
|
|
|
|
let ln = !Odoc_global.library_namespace in
|
|
|
|
let ln = if current = ln || ln = initial || ln = "" then [] else [ln] in
|
|
|
|
ln @ List.rev !Clflags.open_modules in
|
2018-02-02 02:44:23 -08:00
|
|
|
Typemod.initial_env
|
|
|
|
~loc:(Location.in_file "ocamldoc command line")
|
|
|
|
~safe_string:(Config.safe_string || not !Clflags.unsafe_string)
|
2018-09-01 07:56:57 -07:00
|
|
|
~open_implicit_modules
|
2017-01-12 03:56:24 -08:00
|
|
|
~initially_opened_module
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Optionally preprocess a source file *)
|
|
|
|
let preprocess sourcefile =
|
2012-06-13 01:32:57 -07:00
|
|
|
try
|
|
|
|
Pparse.preprocess sourcefile
|
2013-09-12 06:41:01 -07:00
|
|
|
with Pparse.Error err ->
|
2013-01-25 01:12:31 -08:00
|
|
|
Format.eprintf "Preprocessing error@.%a@."
|
|
|
|
Pparse.report_error err;
|
2012-06-13 01:32:57 -07:00
|
|
|
exit 2
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Analysis of an implementation file. Returns (Some typedtree) if
|
2017-08-10 03:59:23 -07:00
|
|
|
no error occurred, else None and an error message is printed.*)
|
2014-08-07 02:46:34 -07:00
|
|
|
|
|
|
|
let tool_name = "ocamldoc"
|
|
|
|
|
2015-12-13 03:23:46 -08:00
|
|
|
(** Deactivate the generation of docstrings in the lexer *)
|
|
|
|
let no_docstring f x =
|
|
|
|
Lexer.handle_docstrings := false;
|
|
|
|
let result = f x in
|
|
|
|
Lexer.handle_docstrings := true;
|
|
|
|
result
|
|
|
|
|
2016-03-09 15:21:42 -08:00
|
|
|
let process_implementation_file sourcefile =
|
2005-07-31 05:03:40 -07:00
|
|
|
init_path ();
|
2002-03-27 08:20:32 -08:00
|
|
|
let prefixname = Filename.chop_extension sourcefile in
|
2014-12-21 03:46:14 -08:00
|
|
|
let modulename = String.capitalize_ascii(Filename.basename prefixname) in
|
2005-07-31 05:03:40 -07:00
|
|
|
Env.set_unit_name modulename;
|
2002-03-27 08:20:32 -08:00
|
|
|
let inputfile = preprocess sourcefile in
|
|
|
|
let env = initial_env () in
|
|
|
|
try
|
2014-08-07 02:46:34 -07:00
|
|
|
let parsetree =
|
2018-07-15 12:01:22 -07:00
|
|
|
Pparse.file ~tool_name inputfile
|
2015-12-13 13:26:57 -08:00
|
|
|
(no_docstring Parse.implementation) Pparse.Structure
|
2014-08-07 02:46:34 -07:00
|
|
|
in
|
2012-05-30 07:52:37 -07:00
|
|
|
let typedtree =
|
|
|
|
Typemod.type_implementation
|
2012-07-30 04:52:38 -07:00
|
|
|
sourcefile prefixname modulename env parsetree
|
2012-05-30 07:52:37 -07:00
|
|
|
in
|
2002-03-27 08:20:32 -08:00
|
|
|
(Some (parsetree, typedtree), inputfile)
|
|
|
|
with
|
2018-11-05 08:37:21 -08:00
|
|
|
| Syntaxerr.Error _ as exn ->
|
|
|
|
begin match Location.error_of_exn exn with
|
|
|
|
| Some (`Ok err) ->
|
2002-07-23 07:12:03 -07:00
|
|
|
fprintf Format.err_formatter "@[%a@]@."
|
2018-11-05 08:37:21 -08:00
|
|
|
Location.print_report err
|
|
|
|
| _ ->
|
|
|
|
assert false
|
|
|
|
end;
|
|
|
|
None, inputfile
|
|
|
|
| Failure s ->
|
|
|
|
prerr_endline s;
|
|
|
|
incr Odoc_global.errors ;
|
|
|
|
None, inputfile
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Analysis of an interface file. Returns (Some signature) if
|
2017-08-10 03:59:23 -07:00
|
|
|
no error occurred, else None and an error message is printed.*)
|
2016-03-09 15:21:42 -08:00
|
|
|
let process_interface_file sourcefile =
|
2005-07-31 05:03:40 -07:00
|
|
|
init_path ();
|
|
|
|
let prefixname = Filename.chop_extension sourcefile in
|
2014-12-21 03:46:14 -08:00
|
|
|
let modulename = String.capitalize_ascii(Filename.basename prefixname) in
|
2005-07-31 05:03:40 -07:00
|
|
|
Env.set_unit_name modulename;
|
2002-03-27 08:20:32 -08:00
|
|
|
let inputfile = preprocess sourcefile in
|
2014-08-07 02:46:34 -07:00
|
|
|
let ast =
|
2018-07-15 12:01:22 -07:00
|
|
|
Pparse.file ~tool_name inputfile
|
2015-12-13 13:26:57 -08:00
|
|
|
(no_docstring Parse.interface) Pparse.Signature
|
2014-08-07 02:46:34 -07:00
|
|
|
in
|
2019-03-13 03:46:37 -07:00
|
|
|
let sg = Typemod.type_interface (initial_env()) ast in
|
2002-03-27 08:20:32 -08:00
|
|
|
Warnings.check_fatal ();
|
|
|
|
(ast, sg, inputfile)
|
|
|
|
|
|
|
|
(** The module used to analyse the parsetree and signature of an implementation file.*)
|
|
|
|
module Ast_analyser = Odoc_ast.Analyser (Odoc_comments.Basic_info_retriever)
|
2003-02-21 09:22:25 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** The module used to analyse the parse tree and typed tree of an interface file.*)
|
|
|
|
module Sig_analyser = Odoc_sig.Analyser (Odoc_comments.Basic_info_retriever)
|
|
|
|
|
2013-09-12 07:45:03 -07:00
|
|
|
(** Handle an error. *)
|
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
let process_error exn =
|
2017-03-08 01:16:01 -08:00
|
|
|
try Location.report_exception Format.err_formatter exn
|
|
|
|
with exn ->
|
|
|
|
fprintf Format.err_formatter
|
|
|
|
"Compilation error(%s). Use the OCaml compiler to get more details.@."
|
|
|
|
(Printexc.to_string exn)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Process the given file, according to its extension. Return the Module.t created, if any.*)
|
2016-03-09 15:21:42 -08:00
|
|
|
let process_file sourcefile =
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Odoc_global.verbose then
|
2002-03-27 08:20:32 -08:00
|
|
|
(
|
2006-01-04 08:55:50 -08:00
|
|
|
let f = match sourcefile with
|
2010-08-24 02:45:45 -07:00
|
|
|
Odoc_global.Impl_file f
|
|
|
|
| Odoc_global.Intf_file f -> f
|
|
|
|
| Odoc_global.Text_file f -> f
|
2006-01-04 08:55:50 -08:00
|
|
|
in
|
2004-08-20 10:04:35 -07:00
|
|
|
print_string (Odoc_messages.analysing f) ;
|
2002-03-27 08:20:32 -08:00
|
|
|
print_newline ();
|
|
|
|
);
|
2004-08-20 10:04:35 -07:00
|
|
|
match sourcefile with
|
2010-08-24 02:45:45 -07:00
|
|
|
Odoc_global.Impl_file file ->
|
2004-08-20 10:04:35 -07:00
|
|
|
(
|
2007-12-04 05:38:58 -08:00
|
|
|
Location.input_name := file;
|
2004-08-20 10:04:35 -07:00
|
|
|
try
|
2016-03-09 15:21:42 -08:00
|
|
|
let (parsetree_typedtree_opt, input_file) = process_implementation_file file in
|
2006-01-04 08:55:50 -08:00
|
|
|
match parsetree_typedtree_opt with
|
2004-08-20 10:04:35 -07:00
|
|
|
None ->
|
|
|
|
None
|
2020-11-05 10:06:12 -08:00
|
|
|
| Some (parsetree, Typedtree.{structure; coercion; _}) ->
|
2020-11-05 07:59:15 -08:00
|
|
|
let typedtree = (structure, coercion) in
|
2004-08-20 10:04:35 -07:00
|
|
|
let file_module = Ast_analyser.analyse_typed_tree file
|
2015-11-07 05:53:52 -08:00
|
|
|
input_file parsetree typedtree
|
2006-01-04 08:55:50 -08:00
|
|
|
in
|
2004-08-20 10:04:35 -07:00
|
|
|
file_module.Odoc_module.m_top_deps <- Odoc_dep.impl_dependencies parsetree ;
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Odoc_global.verbose then
|
2004-08-20 10:04:35 -07:00
|
|
|
(
|
2006-01-04 08:55:50 -08:00
|
|
|
print_string Odoc_messages.ok;
|
|
|
|
print_newline ()
|
2004-08-20 10:04:35 -07:00
|
|
|
);
|
2012-06-13 01:32:57 -07:00
|
|
|
Pparse.remove_preprocessed input_file;
|
2004-08-20 10:04:35 -07:00
|
|
|
Some file_module
|
|
|
|
with
|
2004-12-03 06:42:09 -08:00
|
|
|
| Sys_error s
|
2004-08-20 10:04:35 -07:00
|
|
|
| Failure s ->
|
|
|
|
prerr_endline s ;
|
|
|
|
incr Odoc_global.errors ;
|
|
|
|
None
|
|
|
|
| e ->
|
|
|
|
process_error e ;
|
|
|
|
incr Odoc_global.errors ;
|
|
|
|
None
|
|
|
|
)
|
2010-08-24 02:45:45 -07:00
|
|
|
| Odoc_global.Intf_file file ->
|
2002-03-27 08:20:32 -08:00
|
|
|
(
|
2007-12-04 05:38:58 -08:00
|
|
|
Location.input_name := file;
|
2002-03-27 08:20:32 -08:00
|
|
|
try
|
2016-03-09 15:21:42 -08:00
|
|
|
let (ast, signat, input_file) = process_interface_file file in
|
2004-08-20 10:04:35 -07:00
|
|
|
let file_module = Sig_analyser.analyse_signature file
|
2015-11-07 05:53:52 -08:00
|
|
|
input_file ast signat.sig_type
|
2006-01-04 08:55:50 -08:00
|
|
|
in
|
2002-07-23 07:12:03 -07:00
|
|
|
|
|
|
|
file_module.Odoc_module.m_top_deps <- Odoc_dep.intf_dependencies ast ;
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Odoc_global.verbose then
|
2002-07-23 07:12:03 -07:00
|
|
|
(
|
|
|
|
print_string Odoc_messages.ok;
|
|
|
|
print_newline ()
|
|
|
|
);
|
2012-06-13 01:32:57 -07:00
|
|
|
Pparse.remove_preprocessed input_file;
|
2002-07-23 07:12:03 -07:00
|
|
|
Some file_module
|
2002-03-27 08:20:32 -08:00
|
|
|
with
|
2004-12-03 06:42:09 -08:00
|
|
|
| Sys_error s
|
2002-03-27 08:20:32 -08:00
|
|
|
| Failure s ->
|
2002-07-23 07:12:03 -07:00
|
|
|
prerr_endline s;
|
|
|
|
incr Odoc_global.errors ;
|
|
|
|
None
|
2002-03-27 08:20:32 -08:00
|
|
|
| e ->
|
2002-07-23 07:12:03 -07:00
|
|
|
process_error e ;
|
|
|
|
incr Odoc_global.errors ;
|
|
|
|
None
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
2010-08-24 02:45:45 -07:00
|
|
|
| Odoc_global.Text_file file ->
|
2007-12-04 05:38:58 -08:00
|
|
|
Location.input_name := file;
|
2006-01-04 08:55:50 -08:00
|
|
|
try
|
|
|
|
let mod_name =
|
2012-08-16 02:46:33 -07:00
|
|
|
let s =
|
|
|
|
try Filename.chop_extension file
|
|
|
|
with _ -> file
|
|
|
|
in
|
2014-12-21 03:46:14 -08:00
|
|
|
String.capitalize_ascii (Filename.basename s)
|
2006-01-04 08:55:50 -08:00
|
|
|
in
|
|
|
|
let txt =
|
|
|
|
try Odoc_text.Texter.text_of_string (Odoc_misc.input_file_as_string file)
|
|
|
|
with Odoc_text.Text_syntax (l, c, s) ->
|
|
|
|
raise (Failure (Odoc_messages.text_parse_error l c s))
|
|
|
|
in
|
2016-08-28 03:54:50 -07:00
|
|
|
let m_info =
|
2016-08-31 04:13:41 -07:00
|
|
|
Some Odoc_types.{dummy_info with i_desc= Some txt } in
|
2006-01-04 08:55:50 -08:00
|
|
|
let m =
|
|
|
|
{
|
|
|
|
Odoc_module.m_name = mod_name ;
|
2012-05-30 07:52:37 -07:00
|
|
|
Odoc_module.m_type = Types.Mty_signature [] ;
|
2016-08-28 03:54:50 -07:00
|
|
|
Odoc_module.m_info;
|
2006-01-04 08:55:50 -08:00
|
|
|
Odoc_module.m_is_interface = true ;
|
|
|
|
Odoc_module.m_file = file ;
|
2016-08-31 04:13:41 -07:00
|
|
|
Odoc_module.m_kind = Odoc_module.Module_struct [] ;
|
2006-01-04 08:55:50 -08:00
|
|
|
Odoc_module.m_loc =
|
|
|
|
{ Odoc_types.loc_impl = None ;
|
2012-07-26 12:21:54 -07:00
|
|
|
Odoc_types.loc_inter = Some (Location.in_file file) } ;
|
2006-01-04 08:55:50 -08:00
|
|
|
Odoc_module.m_top_deps = [] ;
|
|
|
|
Odoc_module.m_code = None ;
|
|
|
|
Odoc_module.m_code_intf = None ;
|
2006-04-16 16:28:22 -07:00
|
|
|
Odoc_module.m_text_only = true ;
|
2006-01-04 08:55:50 -08:00
|
|
|
}
|
|
|
|
in
|
|
|
|
Some m
|
|
|
|
with
|
|
|
|
| Sys_error s
|
|
|
|
| Failure s ->
|
|
|
|
prerr_endline s;
|
|
|
|
incr Odoc_global.errors ;
|
|
|
|
None
|
|
|
|
| e ->
|
|
|
|
process_error e ;
|
|
|
|
incr Odoc_global.errors ;
|
|
|
|
None
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2005-08-13 13:59:37 -07:00
|
|
|
(** Remove the class elements between the stop special comments. *)
|
|
|
|
let rec remove_class_elements_between_stop keep eles =
|
2002-03-27 08:20:32 -08:00
|
|
|
match eles with
|
|
|
|
[] -> []
|
|
|
|
| ele :: q ->
|
|
|
|
match ele with
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_class.Class_comment [ Odoc_types.Raw "/*" ] ->
|
|
|
|
remove_class_elements_between_stop (not keep) q
|
2004-12-03 06:42:09 -08:00
|
|
|
| Odoc_class.Class_attribute _
|
|
|
|
| Odoc_class.Class_method _
|
2005-08-13 13:59:37 -07:00
|
|
|
| Odoc_class.Class_comment _ ->
|
|
|
|
if keep then
|
|
|
|
ele :: (remove_class_elements_between_stop keep q)
|
|
|
|
else
|
|
|
|
remove_class_elements_between_stop keep q
|
|
|
|
|
|
|
|
(** Remove the class elements between the stop special comments in a class kind. *)
|
|
|
|
let rec remove_class_elements_between_stop_in_class_kind k =
|
2002-03-27 08:20:32 -08:00
|
|
|
match k with
|
|
|
|
Odoc_class.Class_structure (inher, l) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_class.Class_structure (inher, remove_class_elements_between_stop true l)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_class.Class_apply _ -> k
|
|
|
|
| Odoc_class.Class_constr _ -> k
|
|
|
|
| Odoc_class.Class_constraint (k1, ctk) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_class.Class_constraint (remove_class_elements_between_stop_in_class_kind k1,
|
|
|
|
remove_class_elements_between_stop_in_class_type_kind ctk)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2017-08-10 03:59:23 -07:00
|
|
|
(** Remove the class elements between the stop special comments in a class type kind. *)
|
2005-08-13 13:59:37 -07:00
|
|
|
and remove_class_elements_between_stop_in_class_type_kind tk =
|
2002-03-27 08:20:32 -08:00
|
|
|
match tk with
|
|
|
|
Odoc_class.Class_signature (inher, l) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_class.Class_signature (inher, remove_class_elements_between_stop true l)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_class.Class_type _ -> tk
|
|
|
|
|
|
|
|
|
2005-08-13 13:59:37 -07:00
|
|
|
(** Remove the module elements between the stop special comments. *)
|
|
|
|
let rec remove_module_elements_between_stop keep eles =
|
|
|
|
let f = remove_module_elements_between_stop in
|
2002-03-27 08:20:32 -08:00
|
|
|
match eles with
|
|
|
|
[] -> []
|
|
|
|
| ele :: q ->
|
|
|
|
match ele with
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_module.Element_module_comment [ Odoc_types.Raw "/*" ] ->
|
|
|
|
f (not keep) q
|
2002-07-23 07:12:03 -07:00
|
|
|
| Odoc_module.Element_module_comment _ ->
|
2005-08-13 13:59:37 -07:00
|
|
|
if keep then
|
|
|
|
ele :: (f keep q)
|
|
|
|
else
|
|
|
|
f keep q
|
2002-07-23 07:12:03 -07:00
|
|
|
| Odoc_module.Element_module m ->
|
2005-08-13 13:59:37 -07:00
|
|
|
if keep then
|
|
|
|
(
|
|
|
|
m.Odoc_module.m_kind <- remove_module_elements_between_stop_in_module_kind m.Odoc_module.m_kind ;
|
|
|
|
(Odoc_module.Element_module m) :: (f keep q)
|
|
|
|
)
|
|
|
|
else
|
|
|
|
f keep q
|
2002-07-23 07:12:03 -07:00
|
|
|
| Odoc_module.Element_module_type mt ->
|
2005-08-13 13:59:37 -07:00
|
|
|
if keep then
|
|
|
|
(
|
|
|
|
mt.Odoc_module.mt_kind <- Odoc_misc.apply_opt
|
|
|
|
remove_module_elements_between_stop_in_module_type_kind mt.Odoc_module.mt_kind ;
|
|
|
|
(Odoc_module.Element_module_type mt) :: (f keep q)
|
|
|
|
)
|
|
|
|
else
|
|
|
|
f keep q
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Element_included_module _ ->
|
2005-08-13 13:59:37 -07:00
|
|
|
if keep then
|
|
|
|
ele :: (f keep q)
|
|
|
|
else
|
|
|
|
f keep q
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Element_class c ->
|
2005-08-13 13:59:37 -07:00
|
|
|
if keep then
|
|
|
|
(
|
|
|
|
c.Odoc_class.cl_kind <- remove_class_elements_between_stop_in_class_kind c.Odoc_class.cl_kind ;
|
|
|
|
(Odoc_module.Element_class c) :: (f keep q)
|
|
|
|
)
|
|
|
|
else
|
|
|
|
f keep q
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Element_class_type ct ->
|
2005-08-13 13:59:37 -07:00
|
|
|
if keep then
|
|
|
|
(
|
|
|
|
ct.Odoc_class.clt_kind <- remove_class_elements_between_stop_in_class_type_kind ct.Odoc_class.clt_kind ;
|
|
|
|
(Odoc_module.Element_class_type ct) :: (f keep q)
|
|
|
|
)
|
|
|
|
else
|
|
|
|
f keep q
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Element_value _
|
2014-05-04 16:08:45 -07:00
|
|
|
| Odoc_module.Element_type_extension _
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Element_exception _
|
|
|
|
| Odoc_module.Element_type _ ->
|
2005-08-13 13:59:37 -07:00
|
|
|
if keep then
|
|
|
|
ele :: (f keep q)
|
|
|
|
else
|
|
|
|
f keep q
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
|
2005-08-13 13:59:37 -07:00
|
|
|
(** Remove the module elements between the stop special comments, in the given module kind. *)
|
|
|
|
and remove_module_elements_between_stop_in_module_kind k =
|
2002-03-27 08:20:32 -08:00
|
|
|
match k with
|
2005-08-13 13:59:37 -07:00
|
|
|
| Odoc_module.Module_struct l -> Odoc_module.Module_struct (remove_module_elements_between_stop true l)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Module_alias _ -> k
|
|
|
|
| Odoc_module.Module_functor (params, k2) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_module.Module_functor (params, remove_module_elements_between_stop_in_module_kind k2)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Module_apply (k1, k2) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_module.Module_apply (remove_module_elements_between_stop_in_module_kind k1,
|
|
|
|
remove_module_elements_between_stop_in_module_kind k2)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Module_with (mtkind, s) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_module.Module_with (remove_module_elements_between_stop_in_module_type_kind mtkind, s)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Module_constraint (k2, mtkind) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_module.Module_constraint (remove_module_elements_between_stop_in_module_kind k2,
|
|
|
|
remove_module_elements_between_stop_in_module_type_kind mtkind)
|
2010-04-19 09:48:42 -07:00
|
|
|
| Odoc_module.Module_typeof _ -> k
|
2010-05-03 08:06:17 -07:00
|
|
|
| Odoc_module.Module_unpack _ -> k
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2005-08-13 13:59:37 -07:00
|
|
|
(** Remove the module elements between the stop special comment, in the given module type kind. *)
|
|
|
|
and remove_module_elements_between_stop_in_module_type_kind tk =
|
2002-03-27 08:20:32 -08:00
|
|
|
match tk with
|
2005-08-13 13:59:37 -07:00
|
|
|
| Odoc_module.Module_type_struct l -> Odoc_module.Module_type_struct (remove_module_elements_between_stop true l)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Module_type_functor (params, tk2) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_module.Module_type_functor (params, remove_module_elements_between_stop_in_module_type_kind tk2)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Odoc_module.Module_type_alias _ -> tk
|
|
|
|
| Odoc_module.Module_type_with (tk2, s) ->
|
2005-08-13 13:59:37 -07:00
|
|
|
Odoc_module.Module_type_with (remove_module_elements_between_stop_in_module_type_kind tk2, s)
|
2010-04-19 09:34:13 -07:00
|
|
|
| Odoc_module.Module_type_typeof _ -> tk
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2005-08-13 13:59:37 -07:00
|
|
|
(** Remove elements between the stop special comment. *)
|
|
|
|
let remove_elements_between_stop module_list =
|
2002-03-27 08:20:32 -08:00
|
|
|
List.map
|
2004-12-03 06:42:09 -08:00
|
|
|
(fun m ->
|
2005-08-13 13:59:37 -07:00
|
|
|
m.Odoc_module.m_kind <- remove_module_elements_between_stop_in_module_kind m.Odoc_module.m_kind;
|
2002-03-27 08:20:32 -08:00
|
|
|
m
|
|
|
|
)
|
|
|
|
module_list
|
|
|
|
|
|
|
|
(** This function builds the modules from the given list of source files. *)
|
|
|
|
let analyse_files ?(init=[]) files =
|
2004-12-03 06:42:09 -08:00
|
|
|
let modules_pre =
|
|
|
|
init @
|
2002-03-27 08:20:32 -08:00
|
|
|
(List.fold_left
|
|
|
|
(fun acc -> fun file ->
|
2002-07-23 07:12:03 -07:00
|
|
|
try
|
2016-03-09 15:21:42 -08:00
|
|
|
match process_file file with
|
2002-07-23 07:12:03 -07:00
|
|
|
None ->
|
|
|
|
acc
|
|
|
|
| Some m ->
|
|
|
|
acc @ [ m ]
|
|
|
|
with
|
|
|
|
Failure s ->
|
|
|
|
prerr_endline s ;
|
|
|
|
incr Odoc_global.errors ;
|
|
|
|
acc
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
[]
|
|
|
|
files
|
|
|
|
)
|
|
|
|
in
|
2005-08-13 13:59:37 -07:00
|
|
|
(* Remove elements between the stop special comments, if needed. *)
|
2004-12-03 06:42:09 -08:00
|
|
|
let modules =
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Odoc_global.no_stop then
|
2002-03-27 08:20:32 -08:00
|
|
|
modules_pre
|
|
|
|
else
|
2005-08-13 13:59:37 -07:00
|
|
|
remove_elements_between_stop modules_pre
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
|
|
|
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Odoc_global.verbose then
|
2002-03-27 08:20:32 -08:00
|
|
|
(
|
|
|
|
print_string Odoc_messages.merging;
|
|
|
|
print_newline ()
|
|
|
|
);
|
2010-08-24 02:45:45 -07:00
|
|
|
let merged_modules = Odoc_merge.merge !Odoc_global.merge_options modules in
|
|
|
|
if !Odoc_global.verbose then
|
2002-03-27 08:20:32 -08:00
|
|
|
(
|
|
|
|
print_string Odoc_messages.ok;
|
|
|
|
print_newline ();
|
|
|
|
);
|
2004-12-03 06:42:09 -08:00
|
|
|
let modules_list =
|
2002-03-27 08:20:32 -08:00
|
|
|
(List.fold_left
|
|
|
|
(fun acc -> fun m -> acc @ (Odoc_module.module_all_submodules ~trans: false m))
|
|
|
|
merged_modules
|
|
|
|
merged_modules
|
|
|
|
)
|
|
|
|
in
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Odoc_global.verbose then
|
2002-03-27 08:20:32 -08:00
|
|
|
(
|
|
|
|
print_string Odoc_messages.cross_referencing;
|
|
|
|
print_newline ()
|
|
|
|
);
|
2016-01-19 15:02:30 -08:00
|
|
|
Odoc_cross.associate modules_list;
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Odoc_global.verbose then
|
2002-03-27 08:20:32 -08:00
|
|
|
(
|
|
|
|
print_string Odoc_messages.ok;
|
|
|
|
print_newline ();
|
|
|
|
);
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Odoc_global.sort_modules then
|
2014-08-22 06:45:02 -07:00
|
|
|
List.sort (fun m1 m2 -> compare m1.Odoc_module.m_name m2.Odoc_module.m_name) merged_modules
|
2002-03-27 08:20:32 -08:00
|
|
|
else
|
|
|
|
merged_modules
|
|
|
|
|
|
|
|
let dump_modules file (modules : Odoc_module.t_module list) =
|
|
|
|
try
|
|
|
|
let chanout = open_out_bin file in
|
2002-04-09 05:31:57 -07:00
|
|
|
let dump = Odoc_types.make_dump modules in
|
|
|
|
output_value chanout dump;
|
2002-03-27 08:20:32 -08:00
|
|
|
close_out chanout
|
|
|
|
with
|
|
|
|
Sys_error s ->
|
|
|
|
raise (Failure s)
|
|
|
|
|
|
|
|
let load_modules file =
|
|
|
|
try
|
|
|
|
let chanin = open_in_bin file in
|
2002-04-09 05:31:57 -07:00
|
|
|
let dump = input_value chanin in
|
2002-03-27 08:20:32 -08:00
|
|
|
close_in chanin ;
|
2002-04-09 05:31:57 -07:00
|
|
|
let (l : Odoc_module.t_module list) = Odoc_types.open_dump dump in
|
2002-03-27 08:20:32 -08:00
|
|
|
l
|
|
|
|
with
|
|
|
|
Sys_error s ->
|
|
|
|
raise (Failure s)
|