Skip to content

Commit 04b6335

Browse files
panglesdjonludlam
authored andcommitted
Adding path to values in the odoc model
Signed-off-by: Paul-Elliot <[email protected]>
1 parent acdd2f5 commit 04b6335

File tree

17 files changed

+231
-1
lines changed

17 files changed

+231
-1
lines changed

src/document/url.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ let render_path : Odoc_model.Paths.Path.t -> string =
4141
| `ModuleType (p, s) ->
4242
render_resolved (p :> t) ^ "." ^ ModuleTypeName.to_string s
4343
| `Type (p, s) -> render_resolved (p :> t) ^ "." ^ TypeName.to_string s
44+
| `Value (p, s) -> render_resolved (p :> t) ^ "." ^ ValueName.to_string s
4445
| `Class (p, s) -> render_resolved (p :> t) ^ "." ^ ClassName.to_string s
4546
| `ClassType (p, s) ->
4647
render_resolved (p :> t) ^ "." ^ ClassTypeName.to_string s

src/model/paths.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,14 @@ module Identifier = struct
421421
let compare = compare
422422
end
423423

424+
module Value = struct
425+
type t = Id.path_value
426+
type t_pv = Id.value_pv
427+
let equal = equal
428+
let hash = hash
429+
let compare = compare
430+
end
431+
424432
module ClassType = struct
425433
type t = Id.path_class_type
426434
type t_pv = Id.path_class_type_pv
@@ -656,6 +664,8 @@ module Path = struct
656664
| `ModuleType (p, _) -> inner (p : module_ :> any)
657665
| `Type (_, t) when Names.TypeName.is_internal t -> true
658666
| `Type (p, _) -> inner (p : module_ :> any)
667+
| `Value (_, t) when Names.ValueName.is_internal t -> true
668+
| `Value (p, _) -> inner (p : module_ :> any)
659669
| `Class (p, _) -> inner (p : module_ :> any)
660670
| `ClassType (p, _) -> inner (p : module_ :> any)
661671
| `Alias (dest, `Resolved src) ->
@@ -747,6 +757,10 @@ module Path = struct
747757
type t = Paths_types.Resolved_path.type_
748758
end
749759

760+
module Value = struct
761+
type t = Paths_types.Resolved_path.value
762+
end
763+
750764
module ClassType = struct
751765
type t = Paths_types.Resolved_path.class_type
752766
end
@@ -760,6 +774,7 @@ module Path = struct
760774
| `Canonical (p, _) -> identifier (p :> t)
761775
| `Apply (m, _) -> identifier (m :> t)
762776
| `Type (m, n) -> Identifier.Mk.type_ (parent_module_identifier m, n)
777+
| `Value (m, n) -> Identifier.Mk.value (parent_module_identifier m, n)
763778
| `ModuleType (m, n) ->
764779
Identifier.Mk.module_type (parent_module_identifier m, n)
765780
| `Class (m, n) -> Identifier.Mk.class_ (parent_module_identifier m, n)
@@ -797,6 +812,10 @@ module Path = struct
797812
type t = Paths_types.Path.type_
798813
end
799814

815+
module Value = struct
816+
type t = Paths_types.Path.value
817+
end
818+
800819
module ClassType = struct
801820
type t = Paths_types.Path.class_type
802821
end

src/model/paths.mli

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ module Identifier : sig
182182
module Type :
183183
IdSig with type t = Id.path_type and type t_pv = Id.path_type_pv
184184

185+
module Value : IdSig with type t = Id.path_value and type t_pv = Id.value_pv
186+
185187
module ClassType :
186188
IdSig
187189
with type t = Id.path_class_type
@@ -365,6 +367,16 @@ module rec Path : sig
365367
(* val identifier : t -> Identifier.Path.Type.t *)
366368
end
367369

370+
module Value : sig
371+
type t = Paths_types.Resolved_path.value
372+
373+
(* val of_ident : Identifier.Path.Value.t -> t *)
374+
375+
(* val is_hidden : t -> bool *)
376+
377+
(* val identifier : t -> Identifier.Path.Type.t *)
378+
end
379+
368380
module ClassType : sig
369381
type t = Paths_types.Resolved_path.class_type
370382

@@ -394,6 +406,10 @@ module rec Path : sig
394406
type t = Paths_types.Path.type_
395407
end
396408

409+
module Value : sig
410+
type t = Paths_types.Path.value
411+
end
412+
397413
module ClassType : sig
398414
type t = Paths_types.Path.class_type
399415
end

src/model/paths_types.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,21 @@ module Identifier = struct
256256
and path_type = path_type_pv id
257257
(** @canonical Odoc_model.Paths.Identifier.Path.Type.t *)
258258

259+
type path_value = value
260+
259261
type path_class_type_pv = [ class_pv | class_type_pv ]
260262
(** @canonical Odoc_model.Paths.Identifier.Path.ClassType.t_pv *)
261263

262264
and path_class_type = path_class_type_pv id
263265
(** @canonical Odoc_model.Paths.Identifier.Path.ClassType.t *)
264266

265267
type path_any =
266-
[ path_module_pv | module_type_pv | path_type_pv | path_class_type_pv ] id
268+
[ path_module_pv
269+
| module_type_pv
270+
| path_type_pv
271+
| path_class_type_pv
272+
| value_pv ]
273+
id
267274
(** @canonical Odoc_model.Paths.Identifier.Path.t *)
268275

269276
type fragment_module = path_module
@@ -324,6 +331,9 @@ module rec Path : sig
324331
| `Dot of module_ * string ]
325332
(** @canonical Odoc_model.Paths.Path.Type.t *)
326333

334+
type value = [ `Resolved of Resolved_path.value | `Dot of module_ * string ]
335+
(** @canonical Odoc_model.Paths.Path.Value.t *)
336+
327337
type class_type =
328338
[ `Resolved of Resolved_path.class_type
329339
| `Identifier of Identifier.path_class_type * bool
@@ -370,6 +380,9 @@ and Resolved_path : sig
370380
| `ClassType of module_ * ClassTypeName.t ]
371381
(** @canonical Odoc_model.Paths.Path.Resolved.Type.t *)
372382

383+
type value = [ `Value of module_ * ValueName.t ]
384+
(** @canonical Odoc_model.Paths.Path.Resolved.Value.t *)
385+
373386
type class_type =
374387
[ `Identifier of Identifier.path_class_type
375388
| `Class of module_ * ClassName.t
@@ -394,6 +407,7 @@ and Resolved_path : sig
394407
| `Class of module_ * ClassName.t
395408
| `ClassType of module_ * ClassTypeName.t
396409
| `Class of module_ * ClassName.t
410+
| `Value of module_ * ValueName.t
397411
| `ClassType of module_ * ClassTypeName.t ]
398412
(** @canonical Odoc_model.Paths.Path.Resolved.t *)
399413
end =

src/model_desc/paths_desc.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ module General_paths = struct
265265
| `OpaqueModuleType x -> C ("`OpaqueModuleType", (x :> rp), resolved_path)
266266
| `Type (x1, x2) ->
267267
C ("`Type", ((x1 :> rp), x2), Pair (resolved_path, Names.typename))
268+
| `Value (x1, x2) ->
269+
C ("`Value", ((x1 :> rp), x2), Pair (resolved_path, Names.valuename))
268270
| `Class (x1, x2) ->
269271
C ("`Class", ((x1 :> rp), x2), Pair (resolved_path, Names.classname))
270272
| `ClassType (x1, x2) ->

src/xref2/compile.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ let type_path : Env.t -> Paths.Path.Type.t -> Paths.Path.Type.t =
2121
| Ok p' -> `Resolved Lang_of.(Path.resolved_type (empty ()) p')
2222
| Error _ -> p)
2323

24+
and value_path : Env.t -> Paths.Path.Value.t -> Paths.Path.Value.t =
25+
fun env p ->
26+
match p with
27+
| `Resolved _ -> p
28+
| _ -> (
29+
let cp = Component.Of_Lang.(value_path (empty ()) p) in
30+
match Tools.resolve_value_path env cp with
31+
| Ok p' -> `Resolved Lang_of.(Path.resolved_value (empty ()) p')
32+
| Error _ -> p)
33+
2434
and module_type_path :
2535
Env.t -> Paths.Path.ModuleType.t -> Paths.Path.ModuleType.t =
2636
fun env p ->

src/xref2/component.ml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ module PathTypeMap = Map.Make (struct
3030
let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
3131
end)
3232

33+
module PathValueMap = Map.Make (struct
34+
type t = Ident.path_value
35+
36+
let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
37+
end)
38+
3339
module PathClassTypeMap = Map.Make (struct
3440
type t = Ident.path_class_type
3541

@@ -1028,6 +1034,13 @@ module Fmt = struct
10281034
Format.fprintf ppf "%a.%s" resolved_parent_path p
10291035
(Odoc_model.Names.TypeName.to_string t)
10301036

1037+
and resolved_value_path : Format.formatter -> Cpath.Resolved.value -> unit =
1038+
fun ppf p ->
1039+
match p with
1040+
| `Value (p, t) ->
1041+
Format.fprintf ppf "%a.%s" resolved_parent_path p
1042+
(Odoc_model.Names.ValueName.to_string t)
1043+
10311044
and resolved_parent_path : Format.formatter -> Cpath.Resolved.parent -> unit =
10321045
fun ppf p ->
10331046
match p with
@@ -1056,6 +1069,15 @@ module Fmt = struct
10561069
Format.fprintf ppf "%a.%s" resolved_parent_path p
10571070
(Odoc_model.Names.TypeName.to_string t)
10581071

1072+
and value_path : Format.formatter -> Cpath.value -> unit =
1073+
fun ppf p ->
1074+
match p with
1075+
| `Resolved r -> Format.fprintf ppf "r(%a)" resolved_value_path r
1076+
| `Dot (m, s) -> Format.fprintf ppf "%a.%s" module_path m s
1077+
| `Value (p, t) ->
1078+
Format.fprintf ppf "%a.%s" resolved_parent_path p
1079+
(Odoc_model.Names.ValueName.to_string t)
1080+
10591081
and resolved_class_type_path :
10601082
Format.formatter -> Cpath.Resolved.class_type -> unit =
10611083
fun ppf p ->
@@ -1129,6 +1151,10 @@ module Fmt = struct
11291151
Format.fprintf ppf "%a.%s" model_resolved_path
11301152
(parent :> t)
11311153
(Odoc_model.Names.TypeName.to_string name)
1154+
| `Value (parent, name) ->
1155+
Format.fprintf ppf "%a.%s" model_resolved_path
1156+
(parent :> t)
1157+
(Odoc_model.Names.ValueName.to_string name)
11321158
| `Alias (dest, src) ->
11331159
Format.fprintf ppf "alias(%a,%a)" model_resolved_path
11341160
(dest :> t)
@@ -1770,6 +1796,11 @@ module Of_Lang = struct
17701796
| `ClassType (p, name) ->
17711797
`ClassType (`Module (resolved_module_path ident_map p), name)
17721798

1799+
and resolved_value_path :
1800+
_ -> Odoc_model.Paths.Path.Resolved.Value.t -> Cpath.Resolved.value =
1801+
fun ident_map (`Value (p, name)) ->
1802+
`Value (`Module (resolved_module_path ident_map p), name)
1803+
17731804
and resolved_class_type_path :
17741805
_ ->
17751806
Odoc_model.Paths.Path.Resolved.ClassType.t ->
@@ -1822,6 +1853,12 @@ module Of_Lang = struct
18221853
| `Local i -> `Local (i, b))
18231854
| `Dot (path', x) -> `Dot (module_path ident_map path', x)
18241855

1856+
and value_path : _ -> Odoc_model.Paths.Path.Value.t -> Cpath.value =
1857+
fun ident_map p ->
1858+
match p with
1859+
| `Resolved r -> `Resolved (resolved_value_path ident_map r)
1860+
| `Dot (path', x) -> `Dot (module_path ident_map path', x)
1861+
18251862
and class_type_path :
18261863
_ -> Odoc_model.Paths.Path.ClassType.t -> Cpath.class_type =
18271864
fun ident_map p ->

src/xref2/component.mli

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module ModuleTypeMap : Map.S with type key = Ident.module_type
1111

1212
module PathTypeMap : Map.S with type key = Ident.path_type
1313

14+
module PathValueMap : Map.S with type key = Ident.path_value
15+
1416
module PathClassTypeMap : Map.S with type key = Ident.path_class_type
1517

1618
module IdentMap : Map.S with type key = Ident.any
@@ -585,10 +587,14 @@ module Fmt : sig
585587

586588
val resolved_type_path : Format.formatter -> Cpath.Resolved.type_ -> unit
587589

590+
val resolved_value_path : Format.formatter -> Cpath.Resolved.value -> unit
591+
588592
val resolved_parent_path : Format.formatter -> Cpath.Resolved.parent -> unit
589593

590594
val type_path : Format.formatter -> Cpath.type_ -> unit
591595

596+
val value_path : Format.formatter -> Cpath.value -> unit
597+
592598
val resolved_class_type_path :
593599
Format.formatter -> Cpath.Resolved.class_type -> unit
594600

@@ -650,6 +656,9 @@ module Of_Lang : sig
650656
val resolved_type_path :
651657
map -> Odoc_model.Paths.Path.Resolved.Type.t -> Cpath.Resolved.type_
652658

659+
val resolved_value_path :
660+
map -> Odoc_model.Paths.Path.Resolved.Value.t -> Cpath.Resolved.value
661+
653662
val resolved_class_type_path :
654663
map ->
655664
Odoc_model.Paths.Path.Resolved.ClassType.t ->
@@ -662,6 +671,8 @@ module Of_Lang : sig
662671

663672
val type_path : map -> Odoc_model.Paths.Path.Type.t -> Cpath.type_
664673

674+
val value_path : map -> Odoc_model.Paths.Path.Value.t -> Cpath.value
675+
665676
val class_type_path :
666677
map -> Odoc_model.Paths.Path.ClassType.t -> Cpath.class_type
667678

src/xref2/cpath.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module rec Resolved : sig
3636
| `Class of parent * ClassName.t
3737
| `ClassType of parent * ClassTypeName.t ]
3838

39+
and value = [ `Value of parent * ValueName.t ]
40+
3941
and class_type =
4042
[ `Local of Ident.path_class_type
4143
| `Substituted of class_type
@@ -75,6 +77,11 @@ and Cpath : sig
7577
| `Class of Resolved.parent * ClassName.t
7678
| `ClassType of Resolved.parent * ClassTypeName.t ]
7779

80+
and value =
81+
[ `Resolved of Resolved.value
82+
| `Dot of module_ * string
83+
| `Value of Resolved.parent * ValueName.t ]
84+
7885
and class_type =
7986
[ `Resolved of Resolved.class_type
8087
| `Substituted of class_type

src/xref2/errors.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ module Tools_error = struct
7272
(* Could not find the module in the environment *)
7373
| `Parent of parent_lookup_error ]
7474

75+
and simple_value_lookup_error =
76+
[ `LocalValue of
77+
Env.t * Ident.path_value
78+
(* Internal error: Found local path during lookup *)
79+
| `Find_failure
80+
(* Internal error: the type was not found in the parent signature *)
81+
| `Lookup_failureV of
82+
Identifier.Path.Value.t
83+
(* Could not find the module in the environment *)
84+
| `Parent of parent_lookup_error ]
85+
7586
and parent_lookup_error =
7687
[ `Parent_sig of
7788
expansion_of_module_error
@@ -98,6 +109,7 @@ module Tools_error = struct
98109

99110
type any =
100111
[ simple_type_lookup_error
112+
| simple_value_lookup_error
101113
| simple_module_type_lookup_error
102114
| simple_module_type_expr_of_module_error
103115
| simple_module_lookup_error
@@ -135,6 +147,8 @@ module Tools_error = struct
135147
| `LocalMT (_, id) -> Format.fprintf fmt "Local id found: %a" Ident.fmt id
136148
| `Local (_, id) -> Format.fprintf fmt "Local id found: %a" Ident.fmt id
137149
| `LocalType (_, id) -> Format.fprintf fmt "Local id found: %a" Ident.fmt id
150+
| `LocalValue (_, id) ->
151+
Format.fprintf fmt "Local id found: %a" Ident.fmt id
138152
| `Find_failure -> Format.fprintf fmt "Find failure"
139153
| `Lookup_failure m ->
140154
Format.fprintf fmt "Lookup failure (module): %a"
@@ -150,6 +164,10 @@ module Tools_error = struct
150164
Format.fprintf fmt "Lookup failure (type): %a"
151165
Component.Fmt.model_identifier
152166
(m :> Odoc_model.Paths.Identifier.t)
167+
| `Lookup_failureV m ->
168+
Format.fprintf fmt "Lookup failure (value): %a"
169+
Component.Fmt.model_identifier
170+
(m :> Odoc_model.Paths.Identifier.t)
153171
| `ApplyNotFunctor -> Format.fprintf fmt "Apply module is not a functor"
154172
| `Class_replaced -> Format.fprintf fmt "Class replaced"
155173
| `Parent p -> pp fmt (p :> any)
@@ -204,7 +222,9 @@ let is_unexpanded_module_type_of =
204222
| `UnresolvedPath (`Module (_, e)) -> inner (e :> any)
205223
| `UnresolvedPath (`ModuleType (_, e)) -> inner (e :> any)
206224
| `Lookup_failureT _ -> false
225+
| `Lookup_failureV _ -> false
207226
| `LocalType _ -> false
227+
| `LocalValue _ -> false
208228
| `Class_replaced -> false
209229
| `OpaqueClass -> false
210230
| `Reference (`Parent p) -> inner (p :> any)
@@ -272,6 +292,7 @@ open Paths
272292
type what =
273293
[ `Functor_parameter of Identifier.FunctorParameter.t
274294
| `Value of Identifier.Value.t
295+
| `Value_path of Cpath.value
275296
| `Class of Identifier.Class.t
276297
| `Class_type of Identifier.ClassType.t
277298
| `Module of Identifier.Module.t
@@ -328,6 +349,7 @@ let report ~(what : what) ?tools_error action =
328349
r "module package" module_type_path (path :> Cpath.module_type)
329350
| `Type cfrag -> r "type" type_fragment cfrag
330351
| `Type_path path -> r "type" type_path path
352+
| `Value_path path -> r "value" value_path path
331353
| `Class_type_path path -> r "class_type" class_type_path path
332354
| `With_module frag -> r "module substitution" module_fragment frag
333355
| `With_module_type frag ->

0 commit comments

Comments
 (0)