Skip to content

Commit

Permalink
Provide an interface for ocamldoc's odoc_class module
Browse files Browse the repository at this point in the history
  • Loading branch information
shindere committed Jun 30, 2022
1 parent 0d5bdc1 commit 5120e18
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 34 deletions.
40 changes: 24 additions & 16 deletions ocamldoc/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ odoc_analyse.cmo : \
odoc_dep.cmo \
odoc_cross.cmi \
odoc_comments.cmi \
odoc_class.cmo \
odoc_class.cmi \
odoc_ast.cmi \
../parsing/location.cmi \
../parsing/lexer.cmi \
Expand Down Expand Up @@ -120,7 +120,7 @@ odoc_ast.cmo : \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_env.cmi \
odoc_class.cmo \
odoc_class.cmi \
../parsing/location.cmi \
../typing/ident.cmi \
../typing/btype.cmi \
Expand Down Expand Up @@ -161,13 +161,21 @@ odoc_class.cmo : \
odoc_value.cmi \
odoc_types.cmi \
odoc_parameter.cmi \
odoc_name.cmi
odoc_name.cmi \
odoc_class.cmi
odoc_class.cmx : \
../typing/types.cmx \
odoc_value.cmx \
odoc_types.cmx \
odoc_parameter.cmx \
odoc_name.cmx
odoc_name.cmx \
odoc_class.cmi
odoc_class.cmi : \
../typing/types.cmi \
odoc_value.cmi \
odoc_types.cmi \
odoc_parameter.cmi \
odoc_name.cmi
odoc_comments.cmo : \
odoc_types.cmi \
odoc_text.cmi \
Expand Down Expand Up @@ -225,7 +233,7 @@ odoc_cross.cmo : \
odoc_global.cmi \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo \
odoc_class.cmi \
../utils/misc.cmi \
odoc_cross.cmi
odoc_cross.cmx : \
Expand Down Expand Up @@ -405,7 +413,7 @@ odoc_info.cmo : \
odoc_dep.cmo \
odoc_config.cmi \
odoc_comments.cmi \
odoc_class.cmo \
odoc_class.cmi \
odoc_analyse.cmi \
../parsing/location.cmi \
odoc_info.cmi
Expand Down Expand Up @@ -444,7 +452,7 @@ odoc_info.cmi : \
odoc_global.cmi \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo \
odoc_class.cmi \
../parsing/location.cmi \
../parsing/asttypes.cmi
odoc_inherit.cmo :
Expand Down Expand Up @@ -497,7 +505,7 @@ odoc_merge.cmo : \
odoc_global.cmi \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo \
odoc_class.cmi \
odoc_merge.cmi
odoc_merge.cmx : \
odoc_value.cmx \
Expand Down Expand Up @@ -552,7 +560,7 @@ odoc_module.cmo : \
odoc_name.cmi \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo \
odoc_class.cmi \
../utils/misc.cmi
odoc_module.cmx : \
../typing/types.cmx \
Expand Down Expand Up @@ -620,7 +628,7 @@ odoc_scan.cmo : \
odoc_module.cmo \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo
odoc_class.cmi
odoc_scan.cmx : \
odoc_value.cmx \
odoc_types.cmx \
Expand All @@ -637,7 +645,7 @@ odoc_search.cmo : \
odoc_misc.cmi \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo \
odoc_class.cmi \
odoc_search.cmi
odoc_search.cmx : \
odoc_value.cmx \
Expand All @@ -656,7 +664,7 @@ odoc_search.cmi : \
odoc_module.cmo \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo
odoc_class.cmi
odoc_see_lexer.cmo : \
odoc_parser.cmi
odoc_see_lexer.cmx : \
Expand All @@ -677,7 +685,7 @@ odoc_sig.cmo : \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_env.cmi \
odoc_class.cmo \
odoc_class.cmi \
../parsing/longident.cmi \
../parsing/location.cmi \
../typing/ident.cmi \
Expand Down Expand Up @@ -718,7 +726,7 @@ odoc_sig.cmi : \
odoc_name.cmi \
odoc_module.cmo \
odoc_env.cmi \
odoc_class.cmo \
odoc_class.cmi \
../parsing/location.cmi
odoc_str.cmo : \
../typing/types.cmi \
Expand All @@ -731,7 +739,7 @@ odoc_str.cmo : \
odoc_messages.cmi \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo \
odoc_class.cmi \
../parsing/asttypes.cmi \
odoc_str.cmi
odoc_str.cmx : \
Expand All @@ -754,7 +762,7 @@ odoc_str.cmi : \
odoc_type.cmi \
odoc_extension.cmi \
odoc_exception.cmi \
odoc_class.cmo
odoc_class.cmi
odoc_test.cmo : \
odoc_info.cmi \
odoc_gen.cmi \
Expand Down
18 changes: 0 additions & 18 deletions ocamldoc/odoc_class.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

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
Expand Down Expand Up @@ -93,11 +92,6 @@ and t_class_type = {
mutable clt_loc : Odoc_types.location ;
}


(** {1 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
Expand All @@ -109,7 +103,6 @@ let class_parameter_text_by_name cl label =
Not_found ->
None

(** Returns the list of elements of a t_class. *)
let rec class_elements ?(trans=true) cl =
let rec iter_kind k =
match k with
Expand Down Expand Up @@ -141,7 +134,6 @@ let rec class_elements ?(trans=true) cl =
in
iter_kind cl.cl_kind

(** Returns the list of elements of a t_class_type. *)
and class_type_elements ?(trans=true) clt =
match clt.clt_kind with
Class_signature (_, elements) -> elements
Expand All @@ -152,7 +144,6 @@ and class_type_elements ?(trans=true) clt =
| Class_type _ ->
[]

(** Returns the attributes of a t_class. *)
let class_attributes ?(trans=true) cl =
List.fold_left
(fun acc -> fun ele ->
Expand All @@ -165,7 +156,6 @@ let class_attributes ?(trans=true) cl =
[]
(class_elements ~trans cl)

(** Returns the methods of a t_class. *)
let class_methods ?(trans=true) cl =
List.fold_left
(fun acc -> fun ele ->
Expand All @@ -178,7 +168,6 @@ let class_methods ?(trans=true) cl =
[]
(class_elements ~trans cl)

(** Returns the comments in a t_class. *)
let class_comments ?(trans=true) cl =
List.fold_left
(fun acc -> fun ele ->
Expand All @@ -191,15 +180,12 @@ let class_comments ?(trans=true) cl =
[]
(class_elements ~trans cl)


(** Update the parameters text of a t_class, according to the cl_info field. *)
let class_update_parameters_text cl =
let f p =
Odoc_parameter.update_parameter_text (class_parameter_text_by_name cl) p
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 ->
Expand All @@ -212,7 +198,6 @@ let class_type_attributes ?(trans=true) clt =
[]
(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 ->
Expand All @@ -225,7 +210,6 @@ let class_type_methods ?(trans=true) clt =
[]
(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 ->
Expand All @@ -238,8 +222,6 @@ let class_type_comments ?(trans=true) clt =
[]
(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
Expand Down
114 changes: 114 additions & 0 deletions ocamldoc/odoc_class.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Sebastien Hinderer, projet Cambium, INRIA Paris *)
(* *)
(* Copyright 2022 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 classes and class types.*)

module Name = Odoc_name

(** {1 Types} *)

type class_element =
Class_attribute of Odoc_value.t_attribute
| Class_method of Odoc_value.t_method
| Class_comment of Odoc_types.text
(** To keep the order of elements in a class *)

type cct =
Cl of t_class
| Cltype of t_class_type * Types.type_expr list
and inherited_class = {
ic_name : Name.t;
mutable ic_class : cct option;
ic_text : Odoc_types.text option;
} and class_apply = {
capp_name : Name.t;
mutable capp_class : t_class option;
capp_params : Types.type_expr list;
capp_params_code : string list;
} and class_constr = {
cco_name : Name.t;
mutable cco_class : cct option;
cco_type_parameters : Types.type_expr list;
} and class_kind =
Class_structure of inherited_class list * class_element list
| Class_apply of class_apply
| Class_constr of class_constr
| Class_constraint of class_kind * class_type_kind
and t_class = {
cl_name : Name.t;
mutable cl_info : Odoc_types.info option;
cl_type : Types.class_type;
cl_type_parameters : Types.type_expr list;
cl_virtual : bool;
mutable cl_kind : class_kind;
mutable cl_parameters : Odoc_parameter.parameter list;
mutable cl_loc : Odoc_types.location;
} and class_type_alias = {
cta_name : Name.t;
mutable cta_class : cct option;
cta_type_parameters : Types.type_expr list;
} and class_type_kind =
Class_signature of inherited_class list * class_element list
| Class_type of class_type_alias
and t_class_type = {
clt_name : Name.t;
mutable clt_info : Odoc_types.info option;
clt_type : Types.class_type;
clt_type_parameters : Types.type_expr list;
clt_virtual : bool;
mutable clt_kind : class_type_kind;
mutable clt_loc : Odoc_types.location;
}

(** {1 Functions} *)

val class_parameter_text_by_name :
t_class -> string -> Odoc_types.text option
(** Returns the text associated to the given parameter label
in the given class, or None. *)

val class_elements : ?trans:bool -> t_class -> class_element list
(** Returns the list of elements of a t_class. *)

val class_type_elements : ?trans:bool -> t_class_type -> class_element list
(** Returns the list of elements of a t_class_type. *)

val class_attributes : ?trans:bool -> t_class -> Odoc_value.t_attribute list
(** Returns the attributes of a t_class. *)

val class_methods : ?trans:bool -> t_class -> Odoc_value.t_method list
(** Returns the methods of a t_class. *)

val class_comments : ?trans:bool -> t_class -> Odoc_types.text list
(** Returns the comments in a t_class. *)

val class_update_parameters_text : t_class -> unit
(** Update the parameters text of a t_class, according to the cl_info field. *)

val class_type_attributes :
?trans:bool -> t_class_type -> Odoc_value.t_attribute list
(** Returns the attributes of a t_class_type. *)

val class_type_methods :
?trans:bool -> t_class_type -> Odoc_value.t_method list
(** Returns the methods of a t_class_type. *)

val class_type_comments : ?trans:bool -> t_class_type -> Odoc_types.text list
(** Returns the comments in a t_class_type. *)

val class_type_parameter_text_by_name :
t_class_type -> string -> Odoc_types.text option
(** Returns the text associated to the given parameter label
in the given class type, or None. *)

0 comments on commit 5120e18

Please sign in to comment.