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
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Representation and manipulation of method / function / class parameters. *)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Types *)
|
|
|
|
|
|
|
|
(** Representation of a simple parameter name *)
|
|
|
|
type simple_name = {
|
|
|
|
sn_name : string ;
|
|
|
|
sn_type : Types.type_expr ;
|
|
|
|
mutable sn_text : Odoc_types.text option ;
|
2010-01-22 04:48:24 -08:00
|
|
|
}
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
(** Representation of parameter names. We need it to represent parameter names in tuples.
|
2002-03-27 08:20:32 -08:00
|
|
|
The value [Tuple ([], t)] stands for an anonymous parameter.*)
|
|
|
|
type param_info =
|
|
|
|
| Simple_name of simple_name
|
|
|
|
| Tuple of param_info list * Types.type_expr
|
|
|
|
|
2002-04-05 03:51:15 -08:00
|
|
|
(** A parameter is just a param_info.*)
|
|
|
|
type parameter = param_info
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Functions *)
|
|
|
|
|
2017-08-10 03:59:23 -07:00
|
|
|
(** access to the name as a string. For tuples, parentheses and commas are added. *)
|
2002-03-27 08:20:32 -08:00
|
|
|
let complete_name p =
|
2010-01-22 04:48:24 -08:00
|
|
|
let rec iter pi =
|
2002-03-27 08:20:32 -08:00
|
|
|
match pi with
|
|
|
|
Simple_name sn ->
|
2002-07-23 07:12:03 -07:00
|
|
|
sn.sn_name
|
2002-03-27 08:20:32 -08:00
|
|
|
| Tuple ([], _) -> (* anonymous parameter *)
|
2002-07-23 07:12:03 -07:00
|
|
|
"??"
|
2002-03-27 08:20:32 -08:00
|
|
|
| Tuple (pi_list, _) ->
|
2002-07-23 07:12:03 -07:00
|
|
|
"("^(String.concat "," (List.map iter pi_list))^")"
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2002-04-05 03:51:15 -08:00
|
|
|
iter p
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** access to the complete type *)
|
2010-01-22 04:48:24 -08:00
|
|
|
let typ pi =
|
2002-04-02 07:16:31 -08:00
|
|
|
match pi with
|
2002-03-27 08:20:32 -08:00
|
|
|
Simple_name sn -> sn.sn_type
|
|
|
|
| Tuple (_, typ) -> typ
|
|
|
|
|
|
|
|
(** Update the text of a parameter using a function returning
|
|
|
|
the optional text associated to a parameter name.*)
|
|
|
|
let update_parameter_text f p =
|
2010-01-22 04:48:24 -08:00
|
|
|
let rec iter pi =
|
2002-04-02 07:16:31 -08:00
|
|
|
match pi with
|
2002-03-27 08:20:32 -08:00
|
|
|
Simple_name sn ->
|
2002-07-23 07:12:03 -07:00
|
|
|
sn.sn_text <- f sn.sn_name
|
2002-03-27 08:20:32 -08:00
|
|
|
| Tuple (l, _) ->
|
2002-07-23 07:12:03 -07:00
|
|
|
List.iter iter l
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2002-04-05 03:51:15 -08:00
|
|
|
iter p
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** access to the description of a specific name.
|
|
|
|
@raise Not_found if no description is associated to the given name. *)
|
2010-01-22 04:48:24 -08:00
|
|
|
let desc_by_name pi name =
|
2002-03-27 08:20:32 -08:00
|
|
|
let rec iter acc pi =
|
|
|
|
match pi with
|
|
|
|
Simple_name sn ->
|
2002-07-23 07:12:03 -07:00
|
|
|
(sn.sn_name, sn.sn_text) :: acc
|
2002-03-27 08:20:32 -08:00
|
|
|
| Tuple (pi_list, _) ->
|
2002-07-23 07:12:03 -07:00
|
|
|
List.fold_left iter acc pi_list
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2002-04-02 07:16:31 -08:00
|
|
|
let l = iter [] pi in
|
2002-03-27 08:20:32 -08:00
|
|
|
List.assoc name l
|
|
|
|
|
|
|
|
|
2017-08-10 03:59:23 -07:00
|
|
|
(** access to the list of names ; only one for a simple parameter, or
|
2002-03-27 08:20:32 -08:00
|
|
|
a list for tuples. *)
|
2002-04-05 03:51:15 -08:00
|
|
|
let names pi =
|
2002-03-27 08:20:32 -08:00
|
|
|
let rec iter acc pi =
|
|
|
|
match pi with
|
|
|
|
Simple_name sn ->
|
2002-07-23 07:12:03 -07:00
|
|
|
sn.sn_name :: acc
|
2002-03-27 08:20:32 -08:00
|
|
|
| Tuple (pi_list, _) ->
|
2002-07-23 07:12:03 -07:00
|
|
|
List.fold_left iter acc pi_list
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2002-04-02 07:16:31 -08:00
|
|
|
iter [] pi
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
(** access to the type of a specific name.
|
2002-03-27 08:20:32 -08:00
|
|
|
@raise Not_found if no type is associated to the given name. *)
|
2010-01-22 04:48:24 -08:00
|
|
|
let type_by_name pi name =
|
2002-03-27 08:20:32 -08:00
|
|
|
let rec iter acc pi =
|
|
|
|
match pi with
|
|
|
|
Simple_name sn ->
|
2002-07-23 07:12:03 -07:00
|
|
|
(sn.sn_name, sn.sn_type) :: acc
|
2002-03-27 08:20:32 -08:00
|
|
|
| Tuple (pi_list, _) ->
|
2002-07-23 07:12:03 -07:00
|
|
|
List.fold_left iter acc pi_list
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2002-04-02 07:16:31 -08:00
|
|
|
let l = iter [] pi in
|
2002-03-27 08:20:32 -08:00
|
|
|
List.assoc name l
|
|
|
|
|
|
|
|
(** access to the optional description of a parameter name from an optional info structure.*)
|
|
|
|
let desc_from_info_opt info_opt s =
|
|
|
|
match info_opt with
|
|
|
|
None -> None
|
|
|
|
| Some i ->
|
|
|
|
match s with
|
2002-07-23 07:12:03 -07:00
|
|
|
"" -> None
|
|
|
|
| _ ->
|
2010-01-22 04:48:24 -08:00
|
|
|
try
|
2002-07-23 07:12:03 -07:00
|
|
|
Some (List.assoc s i.Odoc_types.i_params)
|
|
|
|
with
|
2020-06-09 03:30:44 -07:00
|
|
|
Not_found -> None
|