-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathodoc_parameter.ml
103 lines (90 loc) · 2.89 KB
/
odoc_parameter.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
(**************************************************************************)
(* *)
(* 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. *)
(* *)
(**************************************************************************)
(** Representation and manipulation of method / function / class parameters. *)
(** Types *)
type simple_name = {
sn_name : string ;
sn_type : Types.type_expr ;
mutable sn_text : Odoc_types.text option ;
}
type param_info =
| Simple_name of simple_name
| Tuple of param_info list * Types.type_expr
type parameter = param_info
(** Functions *)
let complete_name p =
let rec iter pi =
match pi with
Simple_name sn ->
sn.sn_name
| Tuple ([], _) -> (* anonymous parameter *)
"??"
| Tuple (pi_list, _) ->
"("^(String.concat "," (List.map iter pi_list))^")"
in
iter p
let typ pi =
match pi with
Simple_name sn -> sn.sn_type
| Tuple (_, typ) -> typ
let update_parameter_text f p =
let rec iter pi =
match pi with
Simple_name sn ->
sn.sn_text <- f sn.sn_name
| Tuple (l, _) ->
List.iter iter l
in
iter p
let desc_by_name pi name =
let rec iter acc pi =
match pi with
Simple_name sn ->
(sn.sn_name, sn.sn_text) :: acc
| Tuple (pi_list, _) ->
List.fold_left iter acc pi_list
in
let l = iter [] pi in
List.assoc name l
let names pi =
let rec iter acc pi =
match pi with
Simple_name sn ->
sn.sn_name :: acc
| Tuple (pi_list, _) ->
List.fold_left iter acc pi_list
in
iter [] pi
let type_by_name pi name =
let rec iter acc pi =
match pi with
Simple_name sn ->
(sn.sn_name, sn.sn_type) :: acc
| Tuple (pi_list, _) ->
List.fold_left iter acc pi_list
in
let l = iter [] pi in
List.assoc name l
let desc_from_info_opt info_opt s =
match info_opt with
None -> None
| Some i ->
match s with
"" -> None
| _ ->
try
Some (List.assoc s i.Odoc_types.i_params)
with
Not_found -> None