2002-03-27 08:20:32 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 05:09:31 -07:00
|
|
|
(* *)
|
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. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(** Representation and manipulation of classes and class types.*)
|
|
|
|
|
|
|
|
module Name = Odoc_name
|
|
|
|
|
|
|
|
(** To keep the order of elements in a class *)
|
|
|
|
type class_element =
|
|
|
|
Class_attribute of Odoc_value.t_attribute
|
|
|
|
| Class_method of Odoc_value.t_method
|
|
|
|
| Class_comment of Odoc_types.text
|
|
|
|
|
|
|
|
(** Used when we can reference t_class or t_class_type. *)
|
2010-01-22 04:48:24 -08:00
|
|
|
type cct =
|
2002-03-27 08:20:32 -08:00
|
|
|
Cl of t_class
|
|
|
|
| Cltype of t_class_type * Types.type_expr list (** class type and type parameters *)
|
|
|
|
|
|
|
|
and inherited_class = {
|
|
|
|
ic_name : Name.t ; (** Complete name of the inherited class *)
|
|
|
|
mutable ic_class : cct option ; (** The associated t_class or t_class_type *)
|
|
|
|
ic_text : Odoc_types.text option ; (** The inheritance comment, if any *)
|
2010-01-22 04:48:24 -08:00
|
|
|
}
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
and class_apply = {
|
|
|
|
capp_name : Name.t ; (** The complete name of the applied class *)
|
|
|
|
mutable capp_class : t_class option; (** The associated t_class if we found it *)
|
|
|
|
capp_params : Types.type_expr list; (** The type of expressions the class is applied to *)
|
2004-03-26 07:57:03 -08:00
|
|
|
capp_params_code : string list ; (** The code of these expressions *)
|
2010-01-22 04:48:24 -08:00
|
|
|
}
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
and class_constr = {
|
|
|
|
cco_name : Name.t ; (** The complete name of the applied class *)
|
2002-04-02 07:16:31 -08:00
|
|
|
mutable cco_class : cct option; (** The associated class ot class type if we found it *)
|
2002-03-27 08:20:32 -08:00
|
|
|
cco_type_parameters : Types.type_expr list; (** The type parameters of the class, if needed *)
|
2010-01-22 04:48:24 -08:00
|
|
|
}
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
and class_kind =
|
|
|
|
Class_structure of inherited_class list * class_element list
|
2002-07-23 07:12:03 -07:00
|
|
|
(** an explicit class structure, used in implementation and interface *)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Class_apply of class_apply (** application/alias of a class, used in implementation only *)
|
|
|
|
| Class_constr of class_constr (** a class used to give the type of the defined class,
|
2002-07-23 07:12:03 -07:00
|
|
|
instead of a structure, used in interface only.
|
2010-01-22 04:48:24 -08:00
|
|
|
For example, it will be used with the name "M1.M2....tutu"
|
2002-07-23 07:12:03 -07:00
|
|
|
when the class to is defined like this :
|
|
|
|
class toto : int -> tutu *)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Class_constraint of class_kind * class_type_kind
|
2002-07-23 07:12:03 -07:00
|
|
|
(** A class definition with a constraint. *)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Representation of a class. *)
|
|
|
|
and t_class = {
|
|
|
|
cl_name : Name.t ; (** Name of the class *)
|
|
|
|
mutable cl_info : Odoc_types.info option ; (** The optional associated user information *)
|
|
|
|
cl_type : Types.class_type ;
|
|
|
|
cl_type_parameters : Types.type_expr list ; (** Type parameters *)
|
|
|
|
cl_virtual : bool ; (** true = virtual *)
|
|
|
|
mutable cl_kind : class_kind ;
|
|
|
|
mutable cl_parameters : Odoc_parameter.parameter list ;
|
|
|
|
mutable cl_loc : Odoc_types.location ;
|
2010-01-22 04:48:24 -08:00
|
|
|
}
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
and class_type_alias = {
|
|
|
|
cta_name : Name.t ;
|
|
|
|
mutable cta_class : cct option ; (** we can have a t_class or a t_class_type *)
|
|
|
|
cta_type_parameters : Types.type_expr list ; (** the type parameters *)
|
2010-01-22 04:48:24 -08:00
|
|
|
}
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
and class_type_kind =
|
2002-03-27 08:20:32 -08:00
|
|
|
Class_signature of inherited_class list * class_element list
|
|
|
|
| Class_type of class_type_alias (** a class type eventually applied to type args *)
|
|
|
|
|
|
|
|
(** Representation of a class type. *)
|
|
|
|
and t_class_type = {
|
2010-01-22 04:48:24 -08:00
|
|
|
clt_name : Name.t ;
|
2002-03-27 08:20:32 -08:00
|
|
|
mutable clt_info : Odoc_types.info option ; (** The optional associated user information *)
|
|
|
|
clt_type : Types.class_type ;
|
|
|
|
clt_type_parameters : Types.type_expr list ; (** type parameters *)
|
|
|
|
clt_virtual : bool ; (** true = virtual *)
|
|
|
|
mutable clt_kind : class_type_kind ;
|
|
|
|
mutable clt_loc : Odoc_types.location ;
|
2010-01-22 04:48:24 -08:00
|
|
|
}
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
(** {2 Functions} *)
|
|
|
|
|
|
|
|
(** Returns the text associated to the given parameter label
|
|
|
|
in the given class, or None. *)
|
|
|
|
let class_parameter_text_by_name cl label =
|
|
|
|
match cl.cl_info with
|
|
|
|
None -> None
|
|
|
|
| Some i ->
|
|
|
|
try
|
2002-07-23 07:12:03 -07:00
|
|
|
let t = List.assoc label i.Odoc_types.i_params in
|
|
|
|
Some t
|
2002-03-27 08:20:32 -08:00
|
|
|
with
|
2002-07-23 07:12:03 -07:00
|
|
|
Not_found ->
|
|
|
|
None
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Returns the list of elements of a t_class. *)
|
2010-01-22 04:48:24 -08:00
|
|
|
let rec class_elements ?(trans=true) cl =
|
|
|
|
let rec iter_kind k =
|
2002-03-27 08:20:32 -08:00
|
|
|
match k with
|
|
|
|
Class_structure (_, elements) -> elements
|
|
|
|
| Class_constraint (c_kind, ct_kind) ->
|
2002-07-23 07:12:03 -07:00
|
|
|
iter_kind c_kind
|
2002-03-27 08:20:32 -08:00
|
|
|
(* A VOIR : utiliser le c_kind ou le ct_kind ?
|
2012-07-30 02:48:32 -07:00
|
|
|
Pour l'instant, comme le ct_kind n'est pas analyse,
|
2002-07-23 07:12:03 -07:00
|
|
|
on cherche dans le c_kind
|
2010-01-22 04:48:24 -08:00
|
|
|
class_type_elements ~trans: trans
|
2002-07-23 07:12:03 -07:00
|
|
|
{ clt_name = "" ; clt_info = None ;
|
|
|
|
clt_type_parameters = [] ;
|
|
|
|
clt_virtual = false ;
|
|
|
|
clt_kind = ct_kind }
|
2002-03-27 08:20:32 -08:00
|
|
|
*)
|
|
|
|
| Class_apply capp ->
|
2002-07-23 07:12:03 -07:00
|
|
|
(
|
|
|
|
match capp.capp_class with
|
|
|
|
Some c when trans -> class_elements ~trans: trans c
|
|
|
|
| _ -> []
|
|
|
|
)
|
2002-03-27 08:20:32 -08:00
|
|
|
| Class_constr cco ->
|
2002-07-23 07:12:03 -07:00
|
|
|
(
|
|
|
|
match cco.cco_class with
|
|
|
|
Some (Cl c) when trans -> class_elements ~trans: trans c
|
|
|
|
| Some (Cltype (ct,_)) when trans -> class_type_elements ~trans: trans ct
|
|
|
|
| _ -> []
|
|
|
|
)
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2010-01-22 04:48:24 -08:00
|
|
|
iter_kind cl.cl_kind
|
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** Returns the list of elements of a t_class_type. *)
|
2010-01-22 04:48:24 -08:00
|
|
|
and class_type_elements ?(trans=true) clt =
|
2002-03-27 08:20:32 -08:00
|
|
|
match clt.clt_kind with
|
|
|
|
Class_signature (_, elements) -> elements
|
|
|
|
| Class_type { cta_class = Some (Cltype (ct, _)) } when trans ->
|
|
|
|
class_type_elements ~trans ct
|
|
|
|
| Class_type { cta_class = Some (Cl c) } when trans ->
|
|
|
|
class_elements ~trans c
|
|
|
|
| Class_type _ ->
|
|
|
|
[]
|
|
|
|
|
|
|
|
(** Returns the attributes of a t_class. *)
|
|
|
|
let class_attributes ?(trans=true) cl =
|
|
|
|
List.fold_left
|
|
|
|
(fun acc -> fun ele ->
|
|
|
|
match ele with
|
2002-07-23 07:12:03 -07:00
|
|
|
Class_attribute a ->
|
|
|
|
acc @ [ a ]
|
2002-03-27 08:20:32 -08:00
|
|
|
| _ ->
|
2002-07-23 07:12:03 -07:00
|
|
|
acc
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
[]
|
|
|
|
(class_elements ~trans cl)
|
|
|
|
|
|
|
|
(** Returns the methods of a t_class. *)
|
|
|
|
let class_methods ?(trans=true) cl =
|
|
|
|
List.fold_left
|
|
|
|
(fun acc -> fun ele ->
|
|
|
|
match ele with
|
2002-07-23 07:12:03 -07:00
|
|
|
Class_method m ->
|
|
|
|
acc @ [ m ]
|
2002-03-27 08:20:32 -08:00
|
|
|
| _ ->
|
2002-07-23 07:12:03 -07:00
|
|
|
acc
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
[]
|
|
|
|
(class_elements ~trans cl)
|
|
|
|
|
|
|
|
(** Returns the comments in a t_class. *)
|
|
|
|
let class_comments ?(trans=true) cl =
|
|
|
|
List.fold_left
|
|
|
|
(fun acc -> fun ele ->
|
|
|
|
match ele with
|
2002-07-23 07:12:03 -07:00
|
|
|
Class_comment t ->
|
|
|
|
acc @ [ t ]
|
2002-03-27 08:20:32 -08:00
|
|
|
| _ ->
|
2002-07-23 07:12:03 -07:00
|
|
|
acc
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
[]
|
|
|
|
(class_elements ~trans cl)
|
|
|
|
|
|
|
|
|
|
|
|
(** Update the parameters text of a t_class, according to the cl_info field. *)
|
|
|
|
let class_update_parameters_text cl =
|
2010-01-22 04:48:24 -08:00
|
|
|
let f p =
|
|
|
|
Odoc_parameter.update_parameter_text (class_parameter_text_by_name cl) p
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
|
|
|
List.iter f cl.cl_parameters
|
|
|
|
|
|
|
|
(** Returns the attributes of a t_class_type. *)
|
|
|
|
let class_type_attributes ?(trans=true) clt =
|
|
|
|
List.fold_left
|
|
|
|
(fun acc -> fun ele ->
|
|
|
|
match ele with
|
2002-07-23 07:12:03 -07:00
|
|
|
Class_attribute a ->
|
|
|
|
acc @ [ a ]
|
2002-03-27 08:20:32 -08:00
|
|
|
| _ ->
|
2002-07-23 07:12:03 -07:00
|
|
|
acc
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
[]
|
|
|
|
(class_type_elements ~trans clt)
|
|
|
|
|
|
|
|
(** Returns the methods of a t_class_type. *)
|
|
|
|
let class_type_methods ?(trans=true) clt =
|
|
|
|
List.fold_left
|
|
|
|
(fun acc -> fun ele ->
|
|
|
|
match ele with
|
2002-07-23 07:12:03 -07:00
|
|
|
Class_method m ->
|
|
|
|
acc @ [ m ]
|
2002-03-27 08:20:32 -08:00
|
|
|
| _ ->
|
2002-07-23 07:12:03 -07:00
|
|
|
acc
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
[]
|
|
|
|
(class_type_elements ~trans clt)
|
|
|
|
|
|
|
|
(** Returns the comments in a t_class_type. *)
|
|
|
|
let class_type_comments ?(trans=true) clt =
|
|
|
|
List.fold_left
|
|
|
|
(fun acc -> fun ele ->
|
|
|
|
match ele with
|
2002-07-23 07:12:03 -07:00
|
|
|
Class_comment m ->
|
|
|
|
acc @ [ m ]
|
2002-03-27 08:20:32 -08:00
|
|
|
| _ ->
|
2002-07-23 07:12:03 -07:00
|
|
|
acc
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
[]
|
|
|
|
(class_type_elements ~trans clt)
|
|
|
|
|
|
|
|
(** Returns the text associated to the given parameter label
|
|
|
|
in the given class type, or None. *)
|
|
|
|
let class_type_parameter_text_by_name clt label =
|
|
|
|
match clt.clt_info with
|
|
|
|
None -> None
|
|
|
|
| Some i ->
|
|
|
|
try
|
2002-07-23 07:12:03 -07:00
|
|
|
let t = List.assoc label i.Odoc_types.i_params in
|
|
|
|
Some t
|
2002-03-27 08:20:32 -08:00
|
|
|
with
|
2002-07-23 07:12:03 -07:00
|
|
|
Not_found ->
|
|
|
|
None
|