2002-03-27 08:20:32 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* OCamldoc *)
|
|
|
|
(* *)
|
|
|
|
(* 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 Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2003-11-24 02:44:07 -08:00
|
|
|
(* $Id$ *)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** The module for analysing a signature and source code and creating modules, classes, ..., elements.*)
|
|
|
|
|
|
|
|
(** The functions used to retrieve information from a signature. *)
|
|
|
|
module Signature_search :
|
|
|
|
sig
|
2002-04-19 09:28:08 -07:00
|
|
|
type ele
|
|
|
|
type tab = (ele, Types.signature_item) Hashtbl.t
|
|
|
|
|
|
|
|
(** Create a table from a signature. This table is used by some
|
2002-07-23 07:12:03 -07:00
|
|
|
of the search functions below. *)
|
2002-04-19 09:28:08 -07:00
|
|
|
val table : Types.signature -> tab
|
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** This function returns the type expression for the value whose name is given,
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given signature.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-04-19 09:28:08 -07:00
|
|
|
val search_value : tab -> string -> Types.type_expr
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** This function returns the type expression list for the exception whose name is given,
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given table.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-04-19 09:28:08 -07:00
|
|
|
val search_exception : tab -> string -> Types.exception_declaration
|
2004-11-03 01:31:19 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** This function returns the Types.type_declaration for the type whose name is given,
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given table.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-04-19 09:28:08 -07:00
|
|
|
val search_type : tab -> string -> Types.type_declaration
|
2004-11-03 01:31:19 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** This function returns the Types.class_declaration for the class whose name is given,
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given table.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-04-19 09:28:08 -07:00
|
|
|
val search_class : tab -> string -> Types.class_declaration
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** This function returns the Types.cltype_declaration for the class type whose name is given,
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given table.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-04-19 09:28:08 -07:00
|
|
|
val search_class_type : tab -> string -> Types.cltype_declaration
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** This function returns the Types.module_type for the module whose name is given,
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given table.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-04-19 09:28:08 -07:00
|
|
|
val search_module : tab -> string -> Types.module_type
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** This function returns the optional Types.module_type for the module type whose name is given,
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given table.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-04-19 09:28:08 -07:00
|
|
|
val search_module_type : tab -> string -> Types.module_type option
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** This function returns the Types.type_expr for the given val name
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given class signature.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-03-27 08:20:32 -08:00
|
|
|
val search_attribute_type :
|
2002-07-23 07:12:03 -07:00
|
|
|
Types.Vars.key -> Types.class_signature -> Types.type_expr
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** This function returns the Types.type_expr for the given method name
|
2004-11-03 01:31:19 -08:00
|
|
|
in the given class signature.
|
2002-07-23 07:12:03 -07:00
|
|
|
@raise Not_found if error.*)
|
2002-03-27 08:20:32 -08:00
|
|
|
val search_method_type :
|
2002-07-23 07:12:03 -07:00
|
|
|
string -> Types.class_signature -> Types.type_expr
|
2002-03-27 08:20:32 -08:00
|
|
|
end
|
2004-11-03 01:31:19 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** Functions to retrieve simple and special comments from strings. *)
|
|
|
|
module type Info_retriever =
|
|
|
|
sig
|
|
|
|
(** Return the couple [(n, list)] where [n] is the number of
|
|
|
|
characters read to retrieve [list], which is the list
|
|
|
|
of special comments found in the string. *)
|
|
|
|
val all_special :
|
2002-07-23 07:12:03 -07:00
|
|
|
string -> string -> int * Odoc_types.info list
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Return true if the given string contains a blank line. *)
|
|
|
|
val blank_line_outside_simple :
|
2002-07-23 07:12:03 -07:00
|
|
|
string -> string -> bool
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** [just_after_special file str] return the pair ([length], [info_opt])
|
2004-11-03 01:31:19 -08:00
|
|
|
where [info_opt] is the first optional special comment found
|
2002-03-27 08:20:32 -08:00
|
|
|
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 :
|
2002-07-23 07:12:03 -07:00
|
|
|
string -> string -> (int * Odoc_types.info option)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** [first_special file str] return the pair ([length], [info_opt])
|
2004-11-03 01:31:19 -08:00
|
|
|
where [info_opt] is the first optional special comment found
|
2002-03-27 08:20:32 -08:00
|
|
|
in [str]. [length] is the number of chars from the beginning of [str]
|
|
|
|
to the end of the special comment. *)
|
|
|
|
val first_special :
|
2002-07-23 07:12:03 -07:00
|
|
|
string -> string -> (int * Odoc_types.info option)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Return a pair [(comment_opt, element_comment_list)], where [comment_opt] is the last special
|
2004-11-03 01:31:19 -08:00
|
|
|
comment found in the given string and not followed by a blank line,
|
2002-03-27 08:20:32 -08:00
|
|
|
and [element_comment_list] the list of values built from the other
|
|
|
|
special comments found and the given function. *)
|
2004-11-03 01:31:19 -08:00
|
|
|
val get_comments :
|
2002-07-23 07:12:03 -07:00
|
|
|
(Odoc_types.text -> 'a) -> string -> string -> (Odoc_types.info option * 'a list)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module Analyser :
|
|
|
|
functor (My_ir : Info_retriever) ->
|
|
|
|
sig
|
|
|
|
(** This variable is used to load a file as a string and retrieve characters from it.*)
|
2004-11-03 01:31:19 -08:00
|
|
|
val file : string ref
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** The name of the analysed file. *)
|
|
|
|
val file_name : string ref
|
|
|
|
|
|
|
|
(** This function takes two indexes (start and end) and return the string
|
2002-07-23 07:12:03 -07:00
|
|
|
corresponding to the indexes in the file global variable. The function
|
|
|
|
prepare_file must have been called to fill the file global variable.*)
|
2002-03-27 08:20:32 -08:00
|
|
|
val get_string_of_file : int -> int -> string
|
2004-11-03 01:31:19 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** [prepare_file f input_f] sets [file_name] with [f] and loads the file
|
2002-07-23 07:12:03 -07:00
|
|
|
[input_f] into [file].*)
|
2002-03-27 08:20:32 -08:00
|
|
|
val prepare_file : string -> string -> unit
|
2004-11-03 01:31:19 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** The function used to get the comments in a class. *)
|
2004-11-03 01:31:19 -08:00
|
|
|
val get_comments_in_class : int -> int ->
|
2002-07-23 07:12:03 -07:00
|
|
|
(Odoc_types.info option * Odoc_class.class_element list)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** The function used to get the comments in a module. *)
|
2004-11-03 01:31:19 -08:00
|
|
|
val get_comments_in_module : int -> int ->
|
2002-07-23 07:12:03 -07:00
|
|
|
(Odoc_types.info option * Odoc_module.module_element list)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-11-03 01:31:19 -08:00
|
|
|
(** [name_comment_from_type_kind pos_end pos_limit type_kind].
|
|
|
|
This function takes a [Parsetree.type_kind] and returns the list of
|
|
|
|
(name, optional comment) for the various fields/constructors of the type,
|
2002-07-23 07:12:03 -07:00
|
|
|
or an empty list for an abstract type.
|
2004-11-03 01:31:19 -08:00
|
|
|
[pos_end] is last char of the complete type definition.
|
2002-07-23 07:12:03 -07:00
|
|
|
[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.*)
|
2004-11-03 01:31:19 -08:00
|
|
|
val name_comment_from_type_kind :
|
|
|
|
int -> int -> Parsetree.type_kind -> int * (string * Odoc_types.info option) list
|
2002-06-04 01:48:12 -07:00
|
|
|
|
|
|
|
(** This function converts a [Types.type_kind] into a [Odoc_type.type_kind],
|
2002-07-23 07:12:03 -07:00
|
|
|
by associating the comment found in the parsetree of each constructor/field, if any.*)
|
2004-11-03 01:31:19 -08:00
|
|
|
val get_type_kind :
|
|
|
|
Odoc_env.env -> (string * Odoc_types.info option) list ->
|
2002-07-23 07:12:03 -07:00
|
|
|
Types.type_kind -> Odoc_type.type_kind
|
2002-06-04 01:48:12 -07:00
|
|
|
|
|
|
|
(** This function merge two optional info structures. *)
|
2004-11-03 01:31:19 -08:00
|
|
|
val merge_infos :
|
|
|
|
Odoc_types.info option -> Odoc_types.info option ->
|
2002-07-23 07:12:03 -07:00
|
|
|
Odoc_types.info option
|
2002-06-04 01:48:12 -07:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *)
|
2004-11-03 01:31:19 -08:00
|
|
|
val analyse_module_type_kind :
|
|
|
|
Odoc_env.env -> Odoc_name.t ->
|
2002-07-23 07:12:03 -07:00
|
|
|
Parsetree.module_type -> Types.module_type ->
|
|
|
|
Odoc_module.module_type_kind
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Analysis of a Parsetree.class_type and a Types.class_type to
|
2002-07-23 07:12:03 -07:00
|
|
|
return a class_type_kind.*)
|
2002-03-27 08:20:32 -08:00
|
|
|
val analyse_class_type_kind : Odoc_env.env ->
|
2002-07-23 07:12:03 -07:00
|
|
|
Odoc_name.t -> int -> Parsetree.class_type -> Types.class_type ->
|
|
|
|
Odoc_class.class_type_kind
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-11-03 01:31:19 -08:00
|
|
|
(** This function takes an interface file name, a file containg the code, a parse tree
|
2002-07-23 07:12:03 -07:00
|
|
|
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. *)
|
2004-11-03 01:31:19 -08:00
|
|
|
val analyse_signature :
|
2002-03-27 08:20:32 -08:00
|
|
|
string -> string ->
|
|
|
|
Parsetree.signature -> Types.signature -> Odoc_module.t_module
|
|
|
|
end
|