1(**************************************************************************) 2(* *) 3(* OCaml *) 4(* *) 5(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) 6(* *) 7(* Copyright 2001 Institut National de Recherche en Informatique et *) 8(* en Automatique. *) 9(* *) 10(* All rights reserved. This file is distributed under the terms of *) 11(* the GNU Lesser General Public License version 2.1, with the *) 12(* special exception on linking described in the file LICENSE. *) 13(* *) 14(**************************************************************************) 15 16(** Representation and manipulation of method / function / class parameters. *) 17 18let print_DEBUG s = print_string s ; print_newline () 19 20(** Types *) 21 22(** Representation of a simple parameter name *) 23type simple_name = { 24 sn_name : string ; 25 sn_type : Types.type_expr ; 26 mutable sn_text : Odoc_types.text option ; 27 } 28 29(** Representation of parameter names. We need it to represent parameter names in tuples. 30 The value [Tuple ([], t)] stands for an anonymous parameter.*) 31type param_info = 32 | Simple_name of simple_name 33 | Tuple of param_info list * Types.type_expr 34 35(** A parameter is just a param_info.*) 36type parameter = param_info 37 38(** Functions *) 39 40(** acces to the name as a string. For tuples, parenthesis and commas are added. *) 41let complete_name p = 42 let rec iter pi = 43 match pi with 44 Simple_name sn -> 45 sn.sn_name 46 | Tuple ([], _) -> (* anonymous parameter *) 47 "??" 48 | Tuple (pi_list, _) -> 49 "("^(String.concat "," (List.map iter pi_list))^")" 50 in 51 iter p 52 53(** access to the complete type *) 54let typ pi = 55 match pi with 56 Simple_name sn -> sn.sn_type 57 | Tuple (_, typ) -> typ 58 59(** Update the text of a parameter using a function returning 60 the optional text associated to a parameter name.*) 61let update_parameter_text f p = 62 let rec iter pi = 63 match pi with 64 Simple_name sn -> 65 sn.sn_text <- f sn.sn_name 66 | Tuple (l, _) -> 67 List.iter iter l 68 in 69 iter p 70 71(** access to the description of a specific name. 72 @raise Not_found if no description is associated to the given name. *) 73let desc_by_name pi name = 74 let rec iter acc pi = 75 match pi with 76 Simple_name sn -> 77 (sn.sn_name, sn.sn_text) :: acc 78 | Tuple (pi_list, _) -> 79 List.fold_left iter acc pi_list 80 in 81 let l = iter [] pi in 82 List.assoc name l 83 84 85(** acces to the list of names ; only one for a simple parameter, or 86 a list for tuples. *) 87let names pi = 88 let rec iter acc pi = 89 match pi with 90 Simple_name sn -> 91 sn.sn_name :: acc 92 | Tuple (pi_list, _) -> 93 List.fold_left iter acc pi_list 94 in 95 iter [] pi 96 97(** access to the type of a specific name. 98 @raise Not_found if no type is associated to the given name. *) 99let type_by_name pi name = 100 let rec iter acc pi = 101 match pi with 102 Simple_name sn -> 103 (sn.sn_name, sn.sn_type) :: acc 104 | Tuple (pi_list, _) -> 105 List.fold_left iter acc pi_list 106 in 107 let l = iter [] pi in 108 List.assoc name l 109 110(** access to the optional description of a parameter name from an optional info structure.*) 111let desc_from_info_opt info_opt s = 112 print_DEBUG "desc_from_info_opt"; 113 match info_opt with 114 None -> None 115 | Some i -> 116 match s with 117 "" -> None 118 | _ -> 119 try 120 Some (List.assoc s i.Odoc_types.i_params) 121 with 122 Not_found -> 123 print_DEBUG ("desc_from_info_opt "^s^" not found in\n"); 124 List.iter (fun (s, _) -> print_DEBUG s) i.Odoc_types.i_params; 125 None 126