1 (***********************************************************************)
4 (* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
6 (* Copyright 2001 Institut National de Recherche en Informatique et *)
7 (* en Automatique. All rights reserved. This file is distributed *)
8 (* under the terms of the Q Public License version 1.0. *)
10 (***********************************************************************)
12 (* $Id: odoc_value.ml 8927 2008-07-23 08:55:36Z guesdon $ *)
14 (** Representation and manipulation of values, class attributes and class methods. *)
16 module Name = Odoc_name
20 (** Representation of a value. *)
23 mutable val_info : Odoc_types.info option ;
24 val_type : Types.type_expr ;
25 val_recursive : bool ;
26 mutable val_parameters : Odoc_parameter.parameter list ;
27 mutable val_code : string option ;
28 mutable val_loc : Odoc_types.location ;
31 (** Representation of a class attribute. *)
33 att_value : t_value ; (** an attribute has almost all the same information
39 (** Representation of a class method. *)
41 met_value : t_value ; (** a method has almost all the same information
49 (** Returns the text associated to the given parameter name
50 in the given value, or None. *)
51 let value_parameter_text_by_name v name =
56 let t = List.assoc name i.Odoc_types.i_params in
62 (** Update the parameters text of a t_value, according to the val_info field. *)
63 let update_value_parameters_text v =
65 Odoc_parameter.update_parameter_text (value_parameter_text_by_name v) p
67 List.iter f v.val_parameters
69 (** Create a list of (parameter name, typ) from a type, according to the arrows.
70 [parameter_list_from_arrows t = [ a ; b ]] if t = a -> b -> c.*)
71 let parameter_list_from_arrows typ =
73 match t.Types.desc with
74 Types.Tarrow (l, t1, t2, _) ->
77 | Types.Tsubst texp ->
79 | Types.Tpoly (texp, _) -> iter texp
92 (** Create a list of parameters with dummy names "??" from a type list.
93 Used when we want to merge the parameters of a value, from the .ml
94 and the .mli file. In the .mli file we don't have parameter names
95 so there is nothing to merge. With this dummy list we can merge the
96 parameter names from the .ml and the type from the .mli file. *)
97 let dummy_parameter_list typ =
103 '?' -> String.sub s 1 ((String.length s) - 1)
106 Printtyp.mark_loops typ;
107 let liste_param = parameter_list_from_arrows typ in
108 let rec iter (label, t) =
109 match t.Types.desc with
113 (List.map (fun t2 -> iter ("", t2)) l, t)
115 (* if there is a label, then we don't want to decompose the tuple *)
116 Odoc_parameter.Simple_name
117 { Odoc_parameter.sn_name = normal_name label ;
118 Odoc_parameter.sn_type = t ;
119 Odoc_parameter.sn_text = None }
125 Odoc_parameter.Simple_name
126 { Odoc_parameter.sn_name = normal_name label ;
127 Odoc_parameter.sn_type = t ;
128 Odoc_parameter.sn_text = None }
130 List.map iter liste_param
132 (** Return true if the value is a function, i.e. has a functional type.*)
135 match t.Types.desc with