2004-02-20 08:28:27 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 05:09:31 -07:00
|
|
|
(* *)
|
2004-02-20 08:28:27 -08:00
|
|
|
(* OCamldoc *)
|
|
|
|
(* *)
|
|
|
|
(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2004 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(** Custom generator to perform test on ocamldoc. *)
|
|
|
|
|
|
|
|
open Odoc_info
|
|
|
|
open Odoc_info.Module
|
|
|
|
open Odoc_info.Type
|
|
|
|
|
|
|
|
type test_kind =
|
|
|
|
Types_display
|
|
|
|
|
|
|
|
let p = Format.fprintf
|
|
|
|
|
2012-07-26 12:21:54 -07:00
|
|
|
module Generator (G : Odoc_gen.Base) =
|
2010-08-24 02:45:45 -07:00
|
|
|
struct
|
2012-07-26 12:21:54 -07:00
|
|
|
class string_gen =
|
2004-02-20 08:28:27 -08:00
|
|
|
object(self)
|
|
|
|
inherit Odoc_info.Scan.scanner
|
|
|
|
|
2012-07-26 12:21:54 -07:00
|
|
|
|
2004-02-20 08:28:27 -08:00
|
|
|
val mutable test_kinds = []
|
2010-01-22 04:48:24 -08:00
|
|
|
val mutable fmt = Format.str_formatter
|
2004-02-20 08:28:27 -08:00
|
|
|
|
|
|
|
method must_display_types = List.mem Types_display test_kinds
|
|
|
|
|
|
|
|
method set_test_kinds_from_module m =
|
|
|
|
test_kinds <- List.fold_left
|
2010-01-22 04:48:24 -08:00
|
|
|
(fun acc (s, _) ->
|
|
|
|
match s with
|
|
|
|
"test_types_display" -> Types_display :: acc
|
|
|
|
| _ -> acc
|
|
|
|
)
|
|
|
|
[]
|
|
|
|
(
|
|
|
|
match m.m_info with
|
|
|
|
None -> []
|
|
|
|
| Some i -> i.i_custom
|
|
|
|
)
|
2010-04-07 20:58:41 -07:00
|
|
|
method! scan_type t =
|
2004-02-20 08:28:27 -08:00
|
|
|
match test_kinds with
|
2010-01-22 04:48:24 -08:00
|
|
|
[] -> ()
|
|
|
|
| _ ->
|
|
|
|
p fmt "# type %s:\n" t.ty_name;
|
|
|
|
if self#must_display_types then
|
|
|
|
(
|
|
|
|
p fmt "# manifest (Odoc_info.string_of_type_expr):\n<[%s]>\n"
|
|
|
|
(match t.ty_manifest with
|
|
|
|
None -> "None"
|
|
|
|
| Some e -> Odoc_info.string_of_type_expr e
|
|
|
|
);
|
|
|
|
);
|
2004-02-20 08:28:27 -08:00
|
|
|
|
|
|
|
|
2010-04-07 20:58:41 -07:00
|
|
|
method! scan_module_pre m =
|
2004-02-20 08:28:27 -08:00
|
|
|
p fmt "#\n# module %s:\n" m.m_name ;
|
|
|
|
if self#must_display_types then
|
2010-01-22 04:48:24 -08:00
|
|
|
(
|
|
|
|
p fmt "# Odoc_info.string_of_module_type:\n<[%s]>\n"
|
|
|
|
(Odoc_info.string_of_module_type m.m_type);
|
|
|
|
p fmt "# Odoc_info.string_of_module_type ~complete: true :\n<[%s]>\n"
|
|
|
|
(Odoc_info.string_of_module_type ~complete: true m.m_type);
|
|
|
|
);
|
2004-02-20 08:28:27 -08:00
|
|
|
true
|
|
|
|
|
2010-04-07 20:58:41 -07:00
|
|
|
method! scan_module_type_pre m =
|
2004-02-20 08:28:27 -08:00
|
|
|
p fmt "#\n# module type %s:\n" m.mt_name ;
|
|
|
|
if self#must_display_types then
|
2010-01-22 04:48:24 -08:00
|
|
|
(
|
|
|
|
p fmt "# Odoc_info.string_of_module_type:\n<[%s]>\n"
|
|
|
|
(match m.mt_type with
|
|
|
|
None -> "None"
|
|
|
|
| Some t -> Odoc_info.string_of_module_type t
|
|
|
|
);
|
|
|
|
p fmt "# Odoc_info.string_of_module_type ~complete: true :\n<[%s]>\n"
|
|
|
|
(match m.mt_type with
|
|
|
|
None -> "None"
|
|
|
|
| Some t -> Odoc_info.string_of_module_type ~complete: true t
|
|
|
|
);
|
|
|
|
);
|
2004-02-20 08:28:27 -08:00
|
|
|
true
|
|
|
|
|
|
|
|
method generate (module_list: Odoc_info.Module.t_module list) =
|
2010-08-24 02:45:45 -07:00
|
|
|
let oc = open_out !Odoc_info.Global.out_file in
|
2004-02-20 08:28:27 -08:00
|
|
|
fmt <- Format.formatter_of_out_channel oc;
|
|
|
|
(
|
|
|
|
try
|
2010-01-22 04:48:24 -08:00
|
|
|
List.iter
|
|
|
|
(fun m ->
|
|
|
|
self#set_test_kinds_from_module m;
|
|
|
|
self#scan_module_list [m];
|
|
|
|
)
|
|
|
|
module_list
|
2004-02-20 08:28:27 -08:00
|
|
|
with
|
2010-01-22 04:48:24 -08:00
|
|
|
e ->
|
|
|
|
prerr_endline (Printexc.to_string e)
|
2004-02-20 08:28:27 -08:00
|
|
|
);
|
|
|
|
Format.pp_print_flush fmt ();
|
|
|
|
close_out oc
|
|
|
|
end
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
class generator =
|
|
|
|
let g = new string_gen in
|
|
|
|
object
|
2012-07-26 12:21:54 -07:00
|
|
|
inherit G.generator as base
|
|
|
|
|
|
|
|
method generate l =
|
|
|
|
base#generate l;
|
|
|
|
g#generate l
|
2010-08-24 02:45:45 -07:00
|
|
|
end
|
|
|
|
end;;
|
2004-02-20 08:28:27 -08:00
|
|
|
|
2012-07-26 12:21:54 -07:00
|
|
|
let _ = Odoc_args.extend_base_generator (module Generator : Odoc_gen.Base_functor);;
|