• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ocaml / odoc / 3129

01 May 2026 03:36PM UTC coverage: 71.05% (-0.1%) from 71.191%
3129

Pull #1407

github

web-flow
Merge 1ee25b106 into 27216c784
Pull Request #1407: OxCaml: Support for unboxed named types

1 of 31 new or added lines in 10 files covered. (3.23%)

11 existing lines in 3 files now uncovered.

10411 of 14653 relevant lines covered (71.05%)

5889.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.76
/src/xref2/component.ml
1
module Maps = Odoc_model.Paths.Identifier.Maps
2

3
module ModuleMap = Map.Make (struct
4
  type t = Ident.module_
5

6
  let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
221,851✔
7
end)
8

9
module TypeMap = Map.Make (struct
10
  type t = Ident.type_
11

12
  let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
2,345✔
13
end)
14

15
module ModuleTypeMap = Map.Make (struct
16
  type t = Ident.module_type
17

18
  let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
1,965✔
19
end)
20

21
module ValueMap = Map.Make (struct
22
  type t = Ident.value
23

24
  let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
×
25
end)
26

27
module IdentMap = Map.Make (struct
28
  type t = Ident.any
29

30
  let compare = Ident.compare
31
end)
32

33
module Delayed = struct
34
  let eager = ref false
35

36
  type 'a t = { mutable v : 'a option; mutable get : (unit -> 'a) option }
37

38
  let get : 'a t -> 'a =
39
   fun x ->
40
    match (x.v, x.get) with
10,940✔
41
    | Some x, _ -> x
5,457✔
42
    | None, Some get ->
5,483✔
43
        let v = get () in
44
        x.v <- Some v;
5,483✔
45
        x.get <- None;
46
        v
47
    | _, _ -> failwith "bad delayed"
×
48

49
  let put : (unit -> 'a) -> 'a t =
50
   fun f ->
51
    if !eager then { v = Some (f ()); get = None }
×
52
    else { v = None; get = Some f }
14,429✔
53

54
  let put_val : 'a -> 'a t = fun v -> { v = Some v; get = None }
1,586✔
55
end
56

57
module Opt = struct
58
  let map f = function Some x -> Some (f x) | None -> None
1,464✔
59
end
60

61
module rec Module : sig
62
  type decl =
63
    | Alias of Cpath.module_ * ModuleType.simple_expansion option
64
    | ModuleType of ModuleType.expr
65

66
  type t = {
67
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
68
    doc : CComment.docs;
69
    type_ : decl;
70
    canonical : Odoc_model.Paths.Path.Module.t option;
71
    hidden : bool;
72
  }
73
end =
74
  Module
75

76
and ModuleSubstitution : sig
77
  type t = { doc : CComment.docs; manifest : Cpath.module_ }
78
end =
79
  ModuleSubstitution
80

81
and ModuleTypeSubstitution : sig
82
  type t = { doc : CComment.docs; manifest : ModuleType.expr }
83
end =
84
  ModuleTypeSubstitution
85

86
and TypeExpr : sig
87
  module Polymorphic_variant : sig
88
    type kind = Odoc_model.Lang.TypeExpr.Polymorphic_variant.kind
89

90
    module Constructor : sig
91
      type t = {
92
        name : string;
93
        constant : bool;
94
        arguments : TypeExpr.t list;
95
        doc : CComment.docs;
96
      }
97
    end
98

99
    type element = Type of TypeExpr.t | Constructor of Constructor.t
100

101
    type t = { kind : kind; elements : element list }
102
  end
103

104
  module Object : sig
105
    type method_ = { name : string; type_ : TypeExpr.t }
106

107
    type field = Method of method_ | Inherit of TypeExpr.t
108

109
    type t = { fields : field list; open_ : bool }
110
  end
111

112
  module Package : sig
113
    type substitution = Cfrag.type_ * TypeExpr.t
114

115
    type t = { path : Cpath.module_type; substitutions : substitution list }
116
  end
117

118
  module Module : sig
119
    type t = { package : Package.t; id : Ident.module_ }
120
  end
121

122
  type label = Odoc_model.Lang.TypeExpr.label
123

124
  type t =
125
    | Var of string
126
    | Any
127
    | Alias of t * string
128
    | Arrow of label option * t * t
129
    | Tuple of (string option * t) list
130
    | Unboxed_tuple of (string option * t) list
131
    | Constr of Cpath.type_ * t list
132
    | Polymorphic_variant of TypeExpr.Polymorphic_variant.t
133
    | Object of TypeExpr.Object.t
134
    | Class of Cpath.class_type * t list
135
    | Poly of string list * t
136
    | Quote of t
137
    | Splice of t
138
    | Package of TypeExpr.Package.t
139
    | Arrow_functor of label option * Module.t * t
140
end =
141
  TypeExpr
142

143
and Extension : sig
144
  module Constructor : sig
145
    type t = {
146
      name : string;
147
      source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
148
      doc : CComment.docs;
149
      args : TypeDecl.Constructor.argument;
150
      res : TypeExpr.t option;
151
    }
152
  end
153

154
  type t = {
155
    type_path : Cpath.type_;
156
    doc : CComment.docs;
157
    type_params : TypeDecl.param list;
158
    private_ : bool;
159
    constructors : Constructor.t list;
160
  }
161
end =
162
  Extension
163

164
and Exception : sig
165
  type t = {
166
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
167
    doc : CComment.docs;
168
    args : TypeDecl.Constructor.argument;
169
    res : TypeExpr.t option;
170
  }
171
end =
172
  Exception
173

174
and FunctorParameter : sig
175
  type parameter = { id : Ident.module_; expr : ModuleType.expr }
176

177
  type t = Named of parameter | Unit
178
end =
179
  FunctorParameter
180

181
and ModuleType : sig
182
  type substitution =
183
    | ModuleEq of Cfrag.module_ * Module.decl
184
    | ModuleSubst of Cfrag.module_ * Cpath.module_
185
    | ModuleTypeEq of Cfrag.module_type * ModuleType.expr
186
    | ModuleTypeSubst of Cfrag.module_type * ModuleType.expr
187
    | TypeEq of Cfrag.type_ * TypeDecl.Equation.t
188
    | TypeSubst of Cfrag.type_ * TypeDecl.Equation.t
189

190
  type type_of_desc =
191
    | ModPath of Cpath.module_
192
    | StructInclude of Cpath.module_
193

194
  type simple_expansion =
195
    | Signature of Signature.t
196
    | Functor of FunctorParameter.t * simple_expansion
197

198
  type typeof_t = {
199
    t_desc : type_of_desc;
200
    t_original_path : Cpath.module_;
201
    t_expansion : simple_expansion option;
202
  }
203

204
  module U : sig
205
    type expr =
206
      | Path of Cpath.module_type
207
      | Signature of Signature.t
208
      | With of substitution list * expr
209
      | TypeOf of type_of_desc * Cpath.module_
210
      | Strengthen of expr * Cpath.module_ * bool
211
  end
212

213
  type path_t = {
214
    p_expansion : simple_expansion option;
215
    p_path : Cpath.module_type;
216
  }
217

218
  type with_t = {
219
    w_substitutions : substitution list;
220
    w_expansion : simple_expansion option;
221
    w_expr : U.expr;
222
  }
223

224
  type strengthen_t = {
225
    s_expansion : simple_expansion option;
226
    s_expr : U.expr;
227
    s_path : Cpath.module_;
228
    s_aliasable : bool;
229
  }
230

231
  type expr =
232
    | Path of path_t
233
    | Signature of Signature.t
234
    | With of with_t
235
    | Functor of FunctorParameter.t * expr
236
    | TypeOf of typeof_t
237
    | Strengthen of strengthen_t
238

239
  type t = {
240
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
241
    doc : CComment.docs;
242
    canonical : Odoc_model.Paths.Path.ModuleType.t option;
243
    expr : expr option;
244
  }
245
end =
246
  ModuleType
247

248
and TypeDecl : sig
249
  module Field : sig
250
    type t = {
251
      name : string;
252
      doc : CComment.docs;
253
      mutable_ : bool;
254
      type_ : TypeExpr.t;
255
    }
256
  end
257

258
  module UnboxedField : sig
259
    type t = {
260
      name : string;
261
      doc : CComment.docs;
262
      mutable_ : bool;
263
      type_ : TypeExpr.t;
264
    }
265
  end
266

267
  module Constructor : sig
268
    type argument = Tuple of TypeExpr.t list | Record of Field.t list
269

270
    type t = {
271
      name : string;
272
      doc : CComment.docs;
273
      args : argument;
274
      res : TypeExpr.t option;
275
    }
276
  end
277

278
  module Representation : sig
279
    type t =
280
      | Variant of Constructor.t list
281
      | Record of Field.t list
282
      | Record_unboxed_product of UnboxedField.t list
283
      | Extensible
284
  end
285

286
  type param = Odoc_model.Lang.TypeDecl.param
287

288
  module Equation : sig
289
    type t = {
290
      params : param list;
291
      private_ : bool;
292
      manifest : TypeExpr.t option;
293
      constraints : (TypeExpr.t * TypeExpr.t) list;
294
    }
295
  end
296

297
  type t = {
298
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
299
    doc : CComment.docs;
300
    canonical : Odoc_model.Paths.Path.Type.t option;
301
    equation : Equation.t;
302
    representation : Representation.t option;
303
  }
304
end =
305
  TypeDecl
306

307
and Value : sig
308
  type value = Odoc_model.Lang.Value.value
309

310
  type t = {
311
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
312
    doc : CComment.docs;
313
    type_ : TypeExpr.t;
314
    value : value;
315
  }
316
end =
317
  Value
318

319
and Signature : sig
320
  type recursive = Odoc_model.Lang.Signature.recursive
321

322
  type item =
323
    | Module of Ident.module_ * recursive * Module.t Delayed.t
324
    | ModuleSubstitution of Ident.module_ * ModuleSubstitution.t
325
    | ModuleType of Ident.module_type * ModuleType.t Delayed.t
326
    | ModuleTypeSubstitution of Ident.module_type * ModuleTypeSubstitution.t
327
    | Type of Ident.type_ * recursive * TypeDecl.t Delayed.t
328
    | TypeSubstitution of Ident.type_ * TypeDecl.t
329
    | Exception of Ident.exception_ * Exception.t
330
    | TypExt of Extension.t
331
    | Value of Ident.value * Value.t Delayed.t
332
    | Class of Ident.type_ * recursive * Class.t
333
    | ClassType of Ident.type_ * recursive * ClassType.t
334
    | Include of Include.t
335
    | Open of Open.t
336
    | Comment of CComment.docs_or_stop
337

338
  (* When doing destructive substitution we keep track of the items that have been removed,
339
       and the path they've been substituted with *)
340
  type removed_item =
341
    | RModule of Odoc_model.Names.ModuleName.t * Cpath.module_
342
    | RType of Odoc_model.Names.TypeName.t * TypeExpr.t * TypeDecl.Equation.t
343
        (** [RType (_, texpr, eq)], [eq.manifest = Some texpr] *)
344
    | RModuleType of Odoc_model.Names.ModuleTypeName.t * ModuleType.expr
345

346
  type t = {
347
    items : item list;
348
    compiled : bool;
349
    removed : removed_item list;
350
    doc : CComment.docs;
351
  }
352
end =
353
  Signature
354

355
and Open : sig
356
  type t = { expansion : Signature.t; doc : CComment.docs }
357
end =
358
  Open
359

360
and Include : sig
361
  type decl = Alias of Cpath.module_ | ModuleType of ModuleType.U.expr
362

363
  type t = {
364
    parent : Odoc_model.Paths.Identifier.Signature.t;
365
    strengthened : Cpath.module_ option;
366
    doc : CComment.docs;
367
    status : [ `Default | `Inline | `Closed | `Open ];
368
    shadowed : Odoc_model.Lang.Include.shadowed;
369
    expansion_ : Signature.t;
370
    decl : decl;
371
    loc : Odoc_model.Location_.span;
372
  }
373
end =
374
  Include
375

376
and Class : sig
377
  type decl =
378
    | ClassType of ClassType.expr
379
    | Arrow of TypeExpr.label option * TypeExpr.t * decl
380

381
  type t = {
382
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
383
    doc : CComment.docs;
384
    virtual_ : bool;
385
    params : TypeDecl.param list;
386
    type_ : decl;
387
    expansion : ClassSignature.t option;
388
  }
389
end =
390
  Class
391

392
and ClassType : sig
393
  type expr =
394
    | Constr of Cpath.class_type * TypeExpr.t list
395
    | Signature of ClassSignature.t
396

397
  type t = {
398
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
399
    doc : CComment.docs;
400
    virtual_ : bool;
401
    params : TypeDecl.param list;
402
    expr : expr;
403
    expansion : ClassSignature.t option;
404
  }
405
end =
406
  ClassType
407

408
and ClassSignature : sig
409
  module Constraint : sig
410
    type t = { left : TypeExpr.t; right : TypeExpr.t; doc : CComment.docs }
411
  end
412

413
  module Inherit : sig
414
    type t = { expr : ClassType.expr; doc : CComment.docs }
415
  end
416

417
  type item =
418
    | Method of Ident.method_ * Method.t
419
    | InstanceVariable of Ident.instance_variable * InstanceVariable.t
420
    | Constraint of Constraint.t
421
    | Inherit of Inherit.t
422
    | Comment of CComment.docs_or_stop
423

424
  type t = { self : TypeExpr.t option; items : item list; doc : CComment.docs }
425
end =
426
  ClassSignature
427

428
and Method : sig
429
  type t = {
430
    doc : CComment.docs;
431
    private_ : bool;
432
    virtual_ : bool;
433
    type_ : TypeExpr.t;
434
  }
435
end =
436
  Method
437

438
and InstanceVariable : sig
439
  type t = {
440
    doc : CComment.docs;
441
    mutable_ : bool;
442
    virtual_ : bool;
443
    type_ : TypeExpr.t;
444
  }
445
end =
446
  InstanceVariable
447

448
and Substitution : sig
449
  type subst_module =
450
    [ `Prefixed of Cpath.module_ * Cpath.Resolved.module_
451
    | `Substituted
452
    | `Renamed of Ident.module_ ]
453

454
  type subst_module_type =
455
    [ `Prefixed of Cpath.module_type * Cpath.Resolved.module_type
456
    | `Renamed of Ident.module_type ]
457

458
  type subst_type =
459
    [ `Prefixed of Cpath.type_ * Cpath.Resolved.type_ | `Renamed of Ident.type_ ]
460

461
  type subst_class_type =
462
    [ `Prefixed of Cpath.class_type * Cpath.Resolved.class_type
463
    | `Renamed of Ident.type_ ]
464

465
  type t = {
466
    module_ : subst_module ModuleMap.t;
467
    module_type : subst_module_type ModuleTypeMap.t;
468
    type_ : subst_type TypeMap.t;
469
    class_type : subst_class_type TypeMap.t;
470
    type_replacement : (TypeExpr.t * TypeDecl.Equation.t) TypeMap.t;
471
    module_type_replacement : ModuleType.expr ModuleTypeMap.t;
472
    path_invalidating_modules : Ident.module_ list;
473
    unresolve_opaque_paths : bool;
474
  }
475
end =
476
  Substitution
477

478
and CComment : sig
479
  type block_element =
480
    [ Odoc_model.Comment.nestable_block_element
481
    | `Heading of Label.t
482
    | `Tag of Odoc_model.Comment.tag
483
    | `Media of
484
      Odoc_model.Comment.media_href * Odoc_model.Comment.media * string ]
485

486
  type docs = {
487
    elements : block_element Odoc_model.Comment.with_location list;
488
    warnings_tag : string option;
489
  }
490

491
  type docs_or_stop = [ `Docs of docs | `Stop ]
492
end =
493
  CComment
494

495
and Label : sig
496
  type t = {
497
    attrs : Odoc_model.Comment.heading_attrs;
498
    label : Ident.label;
499
    text : Odoc_model.Comment.paragraph;
500
    location : Odoc_model.Location_.span;
501
  }
502
end =
503
  Label
504

505
module Element = struct
506
  open Odoc_model.Paths
507

508
  type module_ = [ `Module of Identifier.Path.Module.t * Module.t Delayed.t ]
509

510
  type module_type = [ `ModuleType of Identifier.ModuleType.t * ModuleType.t ]
511

512
  type datatype = [ `Type of Identifier.Type.t * TypeDecl.t ]
513

514
  type value = [ `Value of Identifier.Value.t * Value.t ]
515

516
  type label = [ `Label of Identifier.Label.t * Label.t ]
517

518
  type class_ = [ `Class of Identifier.Class.t * Class.t ]
519

520
  type class_type = [ `ClassType of Identifier.ClassType.t * ClassType.t ]
521

522
  type type_ = [ datatype | class_ | class_type ]
523

524
  type signature = [ module_ | module_type ]
525

526
  type constructor =
527
    [ `Constructor of Identifier.Constructor.t * TypeDecl.Constructor.t ]
528

529
  type exception_ = [ `Exception of Identifier.Exception.t * Exception.t ]
530

531
  type extension =
532
    [ `Extension of
533
      Identifier.Extension.t * Extension.Constructor.t * Extension.t ]
534

535
  type extension_decl =
536
    [ `ExtensionDecl of Identifier.Extension.t * Extension.Constructor.t ]
537

538
  type field = [ `Field of Identifier.Field.t * TypeDecl.Field.t ]
539

540
  type unboxed_field =
541
    [ `UnboxedField of Identifier.UnboxedField.t * TypeDecl.UnboxedField.t ]
542

543
  (* No component for pages yet *)
544
  type page = [ `Page of Identifier.Page.t * Odoc_model.Lang.Page.t ]
545

546
  type label_parent = [ signature | type_ | page ]
547

548
  type fragment_type_parent = [ signature | datatype ]
549

550
  type any =
551
    [ signature
552
    | value
553
    | datatype
554
    | label
555
    | class_
556
    | class_type
557
    | constructor
558
    | exception_
559
    | extension
560
    | extension_decl
561
    | field
562
    | unboxed_field
563
    | page ]
564

565
  let identifier : [< any ] -> Odoc_model.Paths.Identifier.t =
566
    let open Odoc_model.Paths.Identifier in
567
    function
568
    | `Module (id, _) -> (id :> t)
×
569
    | `ModuleType (id, _) -> (id :> t)
×
570
    | `Type (id, _) -> (id :> t)
×
571
    | `ClassType (id, _) -> (id :> t)
×
572
    | `Class (id, _) -> (id :> t)
×
573
    | `Value (id, _) -> (id :> t)
×
574
    | `Label (id, _) -> (id :> t)
×
575
    | `Constructor (id, _) -> (id :> t)
×
576
    | `Exception (id, _) -> (id :> t)
×
577
    | `Field (id, _) -> (id :> t)
×
578
    | `UnboxedField (id, _) -> (id :> t)
×
579
    | `Extension (id, _, _) -> (id :> t)
×
580
    | `ExtensionDecl (id, _) -> (id :> t)
×
581
    | `Page (id, _) -> (id :> t)
×
582
end
583

584
module Fmt = struct
585
  type config = {
586
    short_paths : bool;
587
    show_canonical : bool;
588
    show_removed : bool;
589
    show_expansions : bool;
590
    show_include_expansions : bool;
591
  }
592

593
  let default =
594
    {
595
      short_paths = false;
596
      show_canonical = true;
597
      show_removed = true;
598
      show_expansions = true;
599
      show_include_expansions = true;
600
    }
601

602
  type id = Odoc_model.Paths.Identifier.t
603
  type path = Odoc_model.Paths.Path.t
604
  type rpath = Odoc_model.Paths.Path.Resolved.t
605
  open Odoc_model.Names
606
  open Odoc_model.Paths
607

608
  let fpf = Format.fprintf
609

610
  let fpp_opt (c : config) fmt pp_a ppf = function
611
    | Some t -> fpf ppf fmt (pp_a c) t
16✔
612
    | None -> ()
31✔
613

614
  let fpp_list fmt_sep fmt_outer pp_a ppf t =
615
    let pp_sep ppf () = fpf ppf fmt_sep in
×
616
    match t with
617
    | [] -> ()
×
618
    | t -> fpf ppf fmt_outer (Format.pp_print_list ~pp_sep pp_a) t
×
619

620
  (* Three helper functions to help with paths. Generally paths
621
     have constructors of the form [`Hidden(p1)] or
622
     [`Alias(p1,p2)]. When printing these paths, if we're printing a
623
     short path we often want to just ignore the constructor and print
624
     one of the inner paths, [p1] or [p2]. These functions do that. If
625
     [short_paths] is set in the config, we skip to one of the inner
626
     paths - in [wrap] there's no choice, but in [wrap2] we pick [p1]
627
     and in [wrap2r] we pick [p2]. If [short_paths] is not set, we
628
     print a string representing the constructor, and one or both paths
629
     with brackets. *)
630
  let wrap : type a.
631
      config ->
632
      string ->
633
      (config -> Format.formatter -> a -> unit) ->
634
      Format.formatter ->
635
      a ->
636
      unit =
637
   fun c txt fn ppf x ->
638
    if c.short_paths then Format.fprintf ppf "%a" (fn c) x
143✔
639
    else Format.fprintf ppf "%s(%a)" txt (fn c) x
×
640

641
  let wrap2 : type a b.
642
      config ->
643
      string ->
644
      (config -> Format.formatter -> a -> unit) ->
645
      (config -> Format.formatter -> b -> unit) ->
646
      Format.formatter ->
647
      a ->
648
      b ->
649
      unit =
650
   fun c txt fn1 fn2 ppf x y ->
651
    if c.short_paths then Format.fprintf ppf "%a" (fn1 c) x
9✔
652
    else Format.fprintf ppf "%s(%a,%a)" txt (fn1 c) x (fn2 c) y
×
653

654
  let wrap2r : type a b.
655
      config ->
656
      string ->
657
      (config -> Format.formatter -> a -> unit) ->
658
      (config -> Format.formatter -> b -> unit) ->
659
      Format.formatter ->
660
      a ->
661
      b ->
662
      unit =
663
   fun c txt fn1 fn2 ppf x y ->
664
    if c.short_paths then Format.fprintf ppf "%a" (fn2 c) y
1✔
665
    else Format.fprintf ppf "%s(%a,%a)" txt (fn1 c) x (fn2 c) y
×
666

667
  let str : config -> Format.formatter -> string -> unit =
668
   fun _ ppf s -> Format.fprintf ppf "%s" s
×
669

670
  let bool : config -> Format.formatter -> bool -> unit =
671
   fun _ ppf b -> Format.fprintf ppf "%b" b
×
672

673
  let ident_fmt : config -> Format.formatter -> [< Ident.any ] -> unit =
674
   fun c ppf i ->
675
    if c.short_paths then Ident.short_fmt ppf i else Ident.fmt ppf i
×
676

677
  let rec model_identifier c ppf (p : id) =
678
    match p.iv with
83✔
679
    | `Root (_, unit_name) ->
47✔
680
        wrap c "root" (fun _ -> ModuleName.fmt) ppf unit_name
47✔
681
    | `Module (parent, name) ->
13✔
682
        Format.fprintf ppf "%a.%s" (model_identifier c)
13✔
683
          (parent :> id)
684
          (ModuleName.to_string name)
13✔
685
    | `ModuleType (parent, name) ->
15✔
686
        Format.fprintf ppf "%a.%s" (model_identifier c)
15✔
687
          (parent :> id)
688
          (ModuleTypeName.to_string name)
15✔
689
    | `Type (parent, name) ->
8✔
690
        Format.fprintf ppf "%a.%s" (model_identifier c)
8✔
691
          (parent :> id)
692
          (TypeName.to_string name)
8✔
693
    | `Parameter (parent, name) ->
×
694
        Format.fprintf ppf "(param %a %s)" (model_identifier c)
×
695
          (parent :> id)
696
          (ModuleName.to_string name)
×
697
    | `Result parent ->
×
698
        if c.short_paths then model_identifier c ppf (parent :> id)
×
699
        else Format.fprintf ppf "%a.result" (model_identifier c) (parent :> id)
×
700
    | `Constructor (ty, x) ->
×
701
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
702
          (ty :> id)
703
          (ConstructorName.to_string x)
×
704
    | `Value (parent, name) ->
×
705
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
706
          (parent :> id)
707
          (ValueName.to_string name)
×
708
    | `Class (sg, name) ->
×
709
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
710
          (sg :> id)
711
          (TypeName.to_string name)
×
712
    | `ClassType (sg, name) ->
×
713
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
714
          (sg :> id)
715
          (TypeName.to_string name)
×
716
    | `InstanceVariable (sg, name) ->
×
717
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
718
          (sg :> id)
719
          (InstanceVariableName.to_string name)
×
720
    | `Method (sg, name) ->
×
721
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
722
          (sg :> id)
723
          (MethodName.to_string name)
×
724
    | `Label (parent, name) ->
×
725
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
726
          (parent :> id)
727
          (LabelName.to_string name)
×
728
    | `Field (ty, name) ->
×
729
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
730
          (ty :> id)
731
          (FieldName.to_string name)
×
732
    | `UnboxedField (ty, name) ->
×
733
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
734
          (ty :> id)
735
          (UnboxedFieldName.to_string name)
×
736
    | `Exception (p, name) ->
×
737
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
738
          (p :> id)
739
          (ExceptionName.to_string name)
×
740
    | `Extension (p, name) ->
×
741
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
742
          (p :> id)
743
          (ExtensionName.to_string name)
×
744
    | `ExtensionDecl (p, _, name) ->
×
745
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
746
          (p :> id)
747
          (ExtensionName.to_string name)
×
748
    | `Page (_, name) | `LeafPage (_, name) ->
×
749
        Format.fprintf ppf "%s" (PageName.to_string name)
×
750
    | `SourcePage (p, name) ->
×
751
        Format.fprintf ppf "%a/%s" (model_identifier c) (p :> id) name
×
752
    | `SourceLocation (p, def) ->
×
753
        Format.fprintf ppf "%a#%s" (model_identifier c)
×
754
          (p :> id)
755
          (DefName.to_string def)
×
756
    | `SourceLocationInternal (p, def) ->
×
757
        Format.fprintf ppf "%a#%s" (model_identifier c)
×
758
          (p :> id)
759
          (LocalName.to_string def)
×
760
    | `SourceLocationMod p ->
×
761
        Format.fprintf ppf "%a#" (model_identifier c) (p :> id)
×
762
    | `AssetFile (p, name) ->
×
763
        Format.fprintf ppf "%a/%s" (model_identifier c)
×
764
          (p :> id)
765
          (AssetName.to_string name)
×
766

767
  let rec signature : config -> Format.formatter -> Signature.t -> unit =
768
   fun c ppf sg ->
769
    let open Signature in
89✔
770
    let ident_fmt = if c.short_paths then Ident.short_fmt else Ident.fmt in
×
771
    let sig_item ppf = function
772
      | Module (id, _, m) ->
47✔
773
          Format.fprintf ppf "@[<hov 2>module %a %a@]" ident_fmt id (module_ c)
47✔
774
            (Delayed.get m)
47✔
775
      | ModuleSubstitution (id, m) ->
×
776
          Format.fprintf ppf "@[<v 2>module %a := %a@]" ident_fmt id
777
            (module_path c) m.ModuleSubstitution.manifest
×
778
      | ModuleType (id, mt) ->
13✔
779
          Format.fprintf ppf "@[<hov 2>module type %a %a@]" ident_fmt id
780
            (module_type c) (Delayed.get mt)
13✔
781
      | ModuleTypeSubstitution (id, mts) ->
×
782
          Format.fprintf ppf "@[<v 2>module type %a := %a@]" ident_fmt id
783
            (module_type_expr c) mts.ModuleTypeSubstitution.manifest
×
784
      | Type (id, _, t) ->
45✔
785
          Format.fprintf ppf "@[<v 2>type %a%a@]" ident_fmt id (type_decl c)
45✔
786
            (Delayed.get t)
45✔
787
      | TypeSubstitution (id, t) ->
×
788
          Format.fprintf ppf "@[<v 2>type %a :=%a@]" ident_fmt id (type_decl c)
×
789
            t
790
      | Exception (id, e) ->
×
791
          Format.fprintf ppf "@[<v 2>exception %a %a@]" ident_fmt id
792
            (exception_ c) e
×
793
      | TypExt e ->
×
794
          Format.fprintf ppf "@[<v 2>type_extension %a@]" (extension c) e
×
795
      | Value (id, v) ->
11✔
796
          Format.fprintf ppf "@[<v 2>val %a %a@]" ident_fmt id (value c)
11✔
797
            (Delayed.get v)
11✔
798
      | Class (id, _, cls) ->
×
799
          Format.fprintf ppf "@[<v 2>class %a %a@]" ident_fmt id (class_ c) cls
×
800
      | ClassType (id, _, cty) ->
×
801
          Format.fprintf ppf "@[<v 2>class type %a %a@]" ident_fmt id
802
            (class_type c) cty
×
803
      | Include i -> Format.fprintf ppf "@[<hov 2>include %a@]" (include_ c) i
18✔
804
      | Open o -> Format.fprintf ppf "open [ %a ]" (signature c) o.expansion
1✔
805
      | Comment _c -> ()
4✔
806
    in
807
    let rec inner ppf = function
808
      | [ x ] -> sig_item ppf x
85✔
809
      | x :: xs -> Format.fprintf ppf "%a@ %a" sig_item x inner xs
54✔
810
      | [] -> ()
4✔
811
    in
812
    let removed_fmt ppf removed =
813
      match (c.show_removed, removed) with
89✔
814
      | false, _ | _, [] -> ()
×
815
      | true, items ->
×
816
          Format.fprintf ppf "@ (removed=%a)" (removed_item_list c) items
×
817
    in
818
    Format.fprintf ppf "%a%a" inner sg.items removed_fmt sg.removed
819

820
  and option : type a.
821
      config ->
822
      (config -> Format.formatter -> a -> unit) ->
823
      Format.formatter ->
824
      a option ->
825
      unit =
826
   fun c pp ppf x ->
827
    match x with
×
828
    | Some x -> Format.fprintf ppf "Some(%a)" (pp c) x
×
829
    | None -> Format.fprintf ppf "None"
×
830

831
  and class_signature c ppf sg =
832
    let open ClassSignature in
×
833
    Format.fprintf ppf "@[<v>self=%a@," (option c type_expr) sg.self;
×
834
    List.iter
×
835
      (function
836
        | Method (id, m) ->
×
837
            Format.fprintf ppf "@[<v 2>method %a : %a@]@," Ident.fmt id
838
              (method_ c) m
×
839
        | InstanceVariable (id, i) ->
×
840
            Format.fprintf ppf "@[<v 2>instance variable %a : %a@]@," Ident.fmt
841
              id (instance_variable c) i
×
842
        | Constraint cst ->
×
843
            Format.fprintf ppf "@[<v 2>constraint %a = %a@]@," (type_expr c)
×
844
              cst.Constraint.left (type_expr c) cst.right
×
845
        | Inherit i ->
×
846
            Format.fprintf ppf "@[<v 2>inherit %a" (class_type_expr c)
×
847
              i.Inherit.expr
848
        | Comment _ -> ())
×
849
      sg.items
850

851
  and method_ c ppf m =
852
    let open Method in
×
853
    Format.fprintf ppf "%s%s%a"
854
      (if m.private_ then "private " else "")
×
855
      (if m.virtual_ then "virtual " else "")
×
856
      (type_expr c) m.type_
×
857

858
  and instance_variable c ppf i =
859
    let open InstanceVariable in
×
860
    Format.fprintf ppf "%s%s%a"
861
      (if i.mutable_ then "mutable " else "")
×
862
      (if i.virtual_ then "virtual " else "")
×
863
      (type_expr c) i.type_
×
864

865
  and list c pp ppf ls =
866
    match ls with
×
867
    | x :: y :: rest ->
×
868
        Format.fprintf ppf "%a, %a" (pp c) x (list c pp) (y :: rest)
×
869
    | [ x ] -> Format.fprintf ppf "%a" (pp c) x
×
870
    | [] -> ()
×
871

872
  and class_type_expr c ppf cty =
873
    let open ClassType in
×
874
    match cty with
875
    | Constr (p, ts) ->
×
876
        Format.fprintf ppf "constr(%a,%a)" (class_type_path c) p
×
877
          (list c type_expr) ts
×
878
    | Signature sg -> Format.fprintf ppf "(%a)" (class_signature c) sg
×
879

880
  and removed_item c ppf r =
881
    let open Signature in
×
882
    match r with
883
    | RModule (id, path) ->
×
884
        Format.fprintf ppf "module %a (%a)" ModuleName.fmt id (module_path c)
×
885
          path
886
    | RType (id, texpr, eq) ->
×
887
        Format.fprintf ppf "type %a %a = (%a)" type_params eq.params
888
          TypeName.fmt id (type_expr c) texpr
×
889
    | RModuleType (id, mty) ->
×
890
        Format.fprintf ppf "module type %a = %a" ModuleTypeName.fmt id
891
          (module_type_expr c) mty
×
892

893
  and removed_item_list c ppf r =
894
    match r with
×
895
    | [] -> ()
×
896
    | [ x ] -> Format.fprintf ppf "%a" (removed_item c) x
×
897
    | x :: ys ->
×
898
        Format.fprintf ppf "%a;%a" (removed_item c) x (removed_item_list c) ys
×
899

900
  and class_decl c ppf cls =
901
    let open Class in
×
902
    match cls with
903
    | ClassType cty -> Format.fprintf ppf "%a" (class_type_expr c) cty
×
904
    | Arrow (lbl, ty, decl) ->
×
905
        Format.fprintf ppf "%a%a -> %a" type_expr_label lbl (type_expr c) ty
×
906
          (class_decl c) decl
×
907

908
  and class_ c ppf cls = Format.fprintf ppf "%a" (class_decl c) cls.type_
×
909

910
  and class_type _c ppf _ = Format.fprintf ppf "<todo>"
×
911

912
  and include_ c ppf i =
913
    Format.fprintf ppf "%a@ %a" (include_decl c) i.decl
18✔
914
      (simple_expansion c true)
18✔
915
      (ModuleType.Signature i.expansion_ : ModuleType.simple_expansion)
916

917
  and include_decl c ppf =
918
    let open Include in
18✔
919
    function
920
    | Alias p -> Format.fprintf ppf "%a" (module_path c) p
×
921
    | ModuleType mt -> Format.fprintf ppf "%a" (u_module_type_expr c) mt
18✔
922

923
  and value c ppf v =
924
    let open Value in
11✔
925
    Format.fprintf ppf ": %a" (type_expr c) v.type_
11✔
926

927
  and module_decl c ppf d =
928
    let open Module in
47✔
929
    match d with
930
    | Alias (p, Some e) ->
3✔
931
        Format.fprintf ppf "=@ %a@ %a" (module_path c) p
3✔
932
          (simple_expansion c false) e
3✔
933
    | Alias (p, None) -> Format.fprintf ppf "=@ %a" (module_path c) p
9✔
934
    | ModuleType mt ->
35✔
935
        Format.fprintf ppf ": %a%a" (module_type_expr c) mt
35✔
936
          (module_type_expansion c) mt
35✔
937

938
  and module_ c ppf m =
939
    let fmt_canonical ppf popt =
47✔
940
      if c.show_canonical then
47✔
941
        Format.fprintf ppf "@ (canonical=%a)" (option c model_path) popt
×
942
      else ()
47✔
943
    in
944
    Format.fprintf ppf "%a%a" (module_decl c) m.type_ fmt_canonical
47✔
945
      (m.canonical :> path option)
946

947
  and simple_expansion c is_include ppf (m : ModuleType.simple_expansion) =
948
    if c.show_expansions || (is_include && c.show_include_expansions) then
16✔
949
      match m with
44✔
950
      | ModuleType.Signature sg ->
42✔
951
          Format.fprintf ppf "@[<hv 2>(sig :@ %a@;<1 -1>end@])" (signature c) sg
42✔
952
      | Functor (arg, sg) ->
2✔
953
          Format.fprintf ppf "(functor: (%a) -> %a)" (functor_parameter c) arg
2✔
954
            (simple_expansion c is_include)
2✔
955
            sg
956
    else ()
×
957

958
  and module_type c ppf mt =
959
    match mt.expr with
21✔
960
    | Some x ->
21✔
961
        Format.fprintf ppf "= %a%a" (module_type_expr c) x
21✔
962
          (module_type_expansion c) x
21✔
963
    | None -> ()
×
964

965
  and module_type_type_of_desc c ppf t =
966
    match t with
6✔
967
    | ModuleType.ModPath p ->
×
968
        Format.fprintf ppf "module type of %a" (module_path c) p
×
969
    | StructInclude p ->
6✔
970
        Format.fprintf ppf "module type of struct include %a end"
971
          (module_path c) p
6✔
972

973
  and u_module_type_expr c ppf mt =
974
    let open ModuleType.U in
27✔
975
    match mt with
976
    | Path p -> module_type_path c ppf p
13✔
977
    | Signature sg -> Format.fprintf ppf "sig@,@[<v 2>%a@]end" (signature c) sg
4✔
978
    | With (subs, e) ->
4✔
979
        Format.fprintf ppf "%a with [%a]" (u_module_type_expr c) e
4✔
980
          (substitution_list c) subs
4✔
981
    | TypeOf (t_desc, _) -> module_type_type_of_desc c ppf t_desc
6✔
982
    | Strengthen (e, p, _) ->
×
983
        Format.fprintf ppf "%a with %a" (u_module_type_expr c) e (module_path c)
×
984
          p
985

986
  and module_type_expr c ppf mt =
987
    let open ModuleType in
60✔
988
    match mt with
989
    | Path { p_path; _ } -> module_type_path c ppf p_path
5✔
990
    | Signature sg ->
36✔
991
        Format.fprintf ppf "@,@[<hv 2>sig@ %a@;<1 -2>end@]" (signature c) sg
36✔
992
    | With { w_substitutions = subs; w_expr; _ } ->
5✔
993
        Format.fprintf ppf "%a with @[<hov 2>%a@]" (u_module_type_expr c) w_expr
5✔
994
          (substitution_list c) subs
5✔
995
    | Functor (arg, res) ->
1✔
996
        Format.fprintf ppf "(%a) -> %a" (functor_parameter c) arg
1✔
997
          (module_type_expr c) res
1✔
998
    | TypeOf { t_desc = ModPath p; _ } ->
11✔
999
        Format.fprintf ppf "module type of %a" (module_path c) p
11✔
1000
    | TypeOf { t_desc = StructInclude p; _ } ->
2✔
1001
        Format.fprintf ppf "module type of struct include %a end"
1002
          (module_path c) p
2✔
1003
    | Strengthen { s_expr; s_path; _ } ->
×
1004
        Format.fprintf ppf "%a with %a" (u_module_type_expr c) s_expr
×
1005
          (module_path c) s_path
×
1006

1007
  and module_type_expansion c ppf mt =
1008
    let open ModuleType in
56✔
1009
    match mt with
1010
    | Signature _ -> ()
32✔
1011
    | Path { p_expansion = Some e; _ }
3✔
1012
    | With { w_expansion = Some e; _ }
5✔
1013
    | TypeOf { t_expansion = Some e; _ } ->
13✔
1014
        Format.fprintf ppf "@ %a" (simple_expansion c false) e
21✔
1015
    | _ -> ()
3✔
1016

1017
  and functor_parameter c ppf x =
1018
    let open FunctorParameter in
3✔
1019
    match x with
1020
    | Unit -> ()
×
1021
    | Named x -> Format.fprintf ppf "%a" (functor_parameter_parameter c) x
3✔
1022

1023
  and functor_parameter_parameter c ppf x =
1024
    Format.fprintf ppf "%a : %a" Ident.fmt x.FunctorParameter.id
3✔
1025
      (module_type_expr c) x.FunctorParameter.expr
3✔
1026

1027
  and type_decl c ppf t =
1028
    let open TypeDecl in
47✔
1029
    match t.representation with
1030
    | Some repr ->
×
1031
        Format.fprintf ppf "%a = %a"
1032
          (fpp_opt c " : %a" type_expr)
×
1033
          t.equation.Equation.manifest (type_decl_repr c) repr
×
1034
    | None -> (fpp_opt c " = %a" type_expr) ppf t.equation.Equation.manifest
47✔
1035

1036
  and type_decl_repr c ppf =
1037
    let open TypeDecl.Representation in
×
1038
    function
1039
    | Variant cs -> fpp_list " | " "%a" (type_decl_constructor c) ppf cs
×
1040
    | Record fs -> type_decl_fields c ppf fs
×
1041
    | Record_unboxed_product fs -> type_decl_unboxed_fields c ppf fs
×
1042
    | Extensible -> Format.fprintf ppf ".."
×
1043

1044
  and type_decl_constructor c ppf t =
1045
    let open TypeDecl.Constructor in
×
1046
    match t.res with
1047
    | Some res ->
×
1048
        fpf ppf "%s : %a -> %a" t.name
1049
          (type_decl_constructor_arg c)
×
1050
          t.args (type_expr c) res
×
1051
    | None -> fpf ppf "%s of %a" t.name (type_decl_constructor_arg c) t.args
×
1052

1053
  and type_decl_constructor_arg c ppf =
1054
    let open TypeDecl.Constructor in
×
1055
    function
1056
    | Tuple ts -> type_constructor_params c ppf ts
×
1057
    | Record fs -> type_decl_fields c ppf fs
×
1058

1059
  and type_decl_field c ppf t =
1060
    let open TypeDecl.Field in
×
1061
    let mutable_ = if t.mutable_ then "mutable " else "" in
×
1062
    fpf ppf "%s%s : %a" mutable_ t.name (type_expr c) t.type_
×
1063

1064
  and type_decl_unboxed_field c ppf t =
1065
    let open TypeDecl.UnboxedField in
×
1066
    let mutable_ = if t.mutable_ then "mutable " else "" in
×
1067
    fpf ppf "%s%s : %a" mutable_ t.name (type_expr c) t.type_
×
1068

1069
  and type_decl_fields c ppf fs =
1070
    fpf ppf "{ %a }" (fpp_list "; " "%a" (type_decl_field c)) fs
×
1071

1072
  and type_decl_unboxed_fields c ppf fs =
1073
    fpf ppf "#{ %a }" (fpp_list "; " "%a" (type_decl_unboxed_field c)) fs
×
1074

1075
  and type_constructor_params c ppf ts =
1076
    fpp_list " * " "%a" (type_expr c) ppf ts
×
1077

1078
  and type_param ppf t =
1079
    let desc =
×
1080
      match t.Odoc_model.Lang.TypeDecl.desc with Any -> "_" | Var n -> n
×
1081
    and variance =
1082
      match t.variance with
1083
      | Some Pos -> "+"
×
1084
      | Some Neg -> "-"
×
1085
      | Some Bivariant -> "+-"
×
1086
      | None -> ""
×
1087
    and injectivity = if t.injectivity then "!" else "" in
×
1088
    Format.fprintf ppf "%s%s%s" variance injectivity desc
1089

1090
  and type_params ppf ts =
1091
    let pp_sep ppf () = Format.fprintf ppf ", " in
×
1092
    Format.fprintf ppf "(%a)" (Format.pp_print_list ~pp_sep type_param) ts
×
1093

1094
  and type_equation_manifest c ppf t =
1095
    match t.TypeDecl.Equation.manifest with
7✔
1096
    | None -> ()
×
1097
    | Some m -> Format.fprintf ppf " = %a" (type_expr c) m
7✔
1098

1099
  and type_equation_params _c ppf t =
1100
    match t.TypeDecl.Equation.params with
7✔
1101
    | [] -> ()
7✔
1102
    | ps -> Format.fprintf ppf "%a" type_params ps
×
1103

1104
  and type_equation c ppf t =
1105
    Format.fprintf ppf "(params %a)%a" (type_equation_params c) t
7✔
1106
      (type_equation_manifest c) t
7✔
1107

1108
  and exception_ _c _ppf _e = ()
×
1109

1110
  and extension c ppf e =
1111
    Format.fprintf ppf "%a" (type_path c) e.Extension.type_path
×
1112

1113
  and substitution c ppf t =
1114
    let open ModuleType in
9✔
1115
    match t with
1116
    | ModuleEq (frag, decl) ->
×
1117
        Format.fprintf ppf "%a %a" (module_fragment c) frag (module_decl c) decl
×
1118
    | ModuleSubst (frag, mpath) ->
2✔
1119
        Format.fprintf ppf "%a := %a" (module_fragment c) frag (module_path c)
2✔
1120
          mpath
1121
    | ModuleTypeEq (frag, mty) ->
×
1122
        Format.fprintf ppf "%a = %a" (module_type_fragment c) frag
×
1123
          (module_type_expr c) mty
×
1124
    | ModuleTypeSubst (frag, mty) ->
×
1125
        Format.fprintf ppf "%a := %a" (module_type_fragment c) frag
×
1126
          (module_type_expr c) mty
×
1127
    | TypeEq (frag, decl) ->
3✔
1128
        Format.fprintf ppf "%a%a" (type_fragment c) frag (type_equation c) decl
3✔
1129
    | TypeSubst (frag, decl) ->
4✔
1130
        Format.fprintf ppf "%a%a" (type_fragment c) frag (type_equation c) decl
4✔
1131

1132
  and substitution_list c ppf l =
1133
    match l with
9✔
1134
    | [ sub ] -> Format.fprintf ppf "%a" (substitution c) sub
9✔
1135
    | sub :: subs ->
×
1136
        Format.fprintf ppf "%a; %a" (substitution c) sub (substitution_list c)
×
1137
          subs
1138
    | [] -> ()
×
1139

1140
  and type_expr_label ppf l =
1141
    match l with
×
1142
    | Some (Odoc_model.Lang.TypeExpr.Label l) -> Format.fprintf ppf "%s:" l
×
1143
    | Some (RawOptional o) -> Format.fprintf ppf "?(%s):" o
×
1144
    | Some (Optional o) -> Format.fprintf ppf "?%s:" o
×
1145
    | None -> ()
×
1146

1147
  and type_expr_list c ppf l =
1148
    match l with
×
1149
    | [ t ] -> Format.fprintf ppf "%a" (type_expr c) t
×
1150
    | t :: ts ->
×
1151
        Format.fprintf ppf "%a * %a" (type_expr c) t (type_expr_list c) ts
×
1152
    | [] -> ()
×
1153

1154
  and type_labeled_tuple c ppf l =
1155
    match l with
×
1156
    | [ t ] -> with_label c ppf t
×
1157
    | t :: ts ->
×
1158
        Format.fprintf ppf "%a * %a" (with_label c) t (type_labeled_tuple c) ts
×
1159
    | [] -> ()
×
1160

1161
  and with_label c ppf (l, ty) =
1162
    match l with
×
1163
    | None -> type_expr c ppf ty
×
1164
    | Some lbl -> Format.fprintf ppf "%s:%a" lbl (type_expr c) ty
×
1165

1166
  and type_object _c ppf _o = Format.fprintf ppf "(object)"
×
1167

1168
  and type_class c ppf (x, ys) =
1169
    Format.fprintf ppf "(class %a %a)" (class_type_path c) x (type_expr_list c)
×
1170
      ys
1171

1172
  and type_package _c ppf _p = Format.fprintf ppf "(package)"
×
1173

1174
  and type_expr_polymorphic_variant c ppf p =
1175
    let open TypeExpr.Polymorphic_variant in
×
1176
    let pp_element ppf = function
1177
      | Type t -> type_expr c ppf t
×
1178
      | Constructor cstr ->
×
1179
          fpf ppf "`%s%a" cstr.Constructor.name
1180
            (fpp_list " * " " of %a" (type_expr c))
×
1181
            cstr.arguments
1182
    in
1183
    let pp_elements = fpp_list " | " "%a" pp_element in
1184
    match p.kind with
×
1185
    | Fixed -> fpf ppf "[ %a ]" pp_elements p.elements
×
1186
    | Closed xs ->
×
1187
        fpf ppf "[ %a > %a ]" pp_elements p.elements
1188
          (fpp_list " " "%a" Format.pp_print_string)
×
1189
          xs
1190
    | Open -> fpf ppf "[> %a ]" pp_elements p.elements
×
1191

1192
  and type_expr c ppf e =
1193
    let open TypeExpr in
34✔
1194
    match e with
1195
    | Var x -> Format.fprintf ppf "%s" x
×
1196
    | Any -> Format.fprintf ppf "_"
×
1197
    | Alias (x, y) -> Format.fprintf ppf "(alias %a %s)" (type_expr c) x y
×
1198
    | Arrow (l, t1, t2) ->
×
1199
        Format.fprintf ppf "%a(%a) -> %a" type_expr_label l (type_expr c) t1
×
1200
          (type_expr c) t2
×
1201
    | Tuple ts -> Format.fprintf ppf "(%a)" (type_labeled_tuple c) ts
×
1202
    | Unboxed_tuple ts -> Format.fprintf ppf "#(%a)" (type_labeled_tuple c) ts
×
1203
    | Constr (p, args) -> (
34✔
1204
        match args with
1205
        | [] -> Format.fprintf ppf "%a" (type_path c) p
34✔
1206
        | _ ->
×
1207
            Format.fprintf ppf "[%a] %a" (type_expr_list c) args (type_path c) p
×
1208
        )
1209
    | Polymorphic_variant poly ->
×
1210
        Format.fprintf ppf "(poly_var %a)"
1211
          (type_expr_polymorphic_variant c)
×
1212
          poly
1213
    | Object x -> type_object c ppf x
×
1214
    | Class (x, y) -> type_class c ppf (x, y)
×
1215
    | Poly (_ss, _t) -> Format.fprintf ppf "(poly)"
×
1216
    | Quote t -> Format.fprintf ppf "(quote %a)" (type_expr c) t
×
1217
    | Splice t -> Format.fprintf ppf "(splice %a)" (type_expr c) t
×
1218
    | Package x -> type_package c ppf x
×
1219
    | Arrow_functor (l, m_arg, t) ->
×
1220
        Format.fprintf ppf "%a(%a) -> %a" type_expr_label l (type_module_arg c)
×
1221
          m_arg (type_expr c) t
×
1222

1223
  and type_module_arg _c ppf _m = Format.fprintf ppf "(module_arg)"
×
1224

1225
  and resolved_module_path :
1226
      config -> Format.formatter -> Cpath.Resolved.module_ -> unit =
1227
   fun c ppf p ->
1228
    match p with
62✔
1229
    | `Local ident -> ident_fmt c ppf ident
10✔
1230
    | `Apply (p1, p2) ->
×
1231
        Format.fprintf ppf "%a(%a)" (resolved_module_path c) p1
×
1232
          (resolved_module_path c) p2
×
1233
    | `Gpath p -> Format.fprintf ppf "%a" (model_resolved_path c) (p :> rpath)
29✔
1234
    | `Substituted p -> wrap c "substituted" resolved_module_path ppf p
×
1235
    | `Module (p, m) ->
10✔
1236
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
10✔
1237
          (ModuleName.to_string m)
10✔
1238
    | `Alias (p1, p2, _) ->
1✔
1239
        wrap2r c "alias" resolved_module_path module_path ppf p1 p2
1240
    | `Subst (p1, p2) ->
×
1241
        wrap2r c "subst" resolved_module_type_path resolved_module_path ppf p1
1242
          p2
1243
    | `Hidden p1 -> wrap c "hidden" resolved_module_path ppf p1
12✔
1244
    | `Canonical (p1, p2) ->
×
1245
        wrap2 c "canonical" resolved_module_path model_path ppf p1 (p2 :> path)
1246
    | `OpaqueModule m -> wrap c "opaquemodule" resolved_module_path ppf m
×
1247

1248
  and module_path : config -> Format.formatter -> Cpath.module_ -> unit =
1249
   fun c ppf p ->
1250
    match p with
34✔
1251
    | `Resolved p -> wrap c "resolved" resolved_module_path ppf p
31✔
1252
    | `Dot (p, n) ->
×
1253
        Format.fprintf ppf "%a.%a" (module_path c) p ModuleName.fmt n
×
1254
    | `Module (p, n) ->
×
1255
        Format.fprintf ppf "%a.%a" (resolved_parent_path c) p ModuleName.fmt n
×
1256
    | `Apply (p1, p2) ->
×
1257
        Format.fprintf ppf "%a(%a)" (module_path c) p1 (module_path c) p2
×
1258
    | `Identifier (id, b) ->
×
1259
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1260
    | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b
3✔
1261
    | `Substituted p -> wrap c "substituted" module_path ppf p
×
1262
    | `Forward s -> wrap c "forward" str ppf s
×
1263
    | `Root r -> wrap c "unresolvedroot" str ppf (ModuleName.to_string r)
×
1264

1265
  and resolved_module_type_path :
1266
      config -> Format.formatter -> Cpath.Resolved.module_type -> unit =
1267
   fun c ppf p ->
1268
    match p with
18✔
1269
    | `Local id -> ident_fmt c ppf id
12✔
1270
    | `Gpath p -> model_resolved_path c ppf (p :> rpath)
2✔
1271
    | `Substituted x -> wrap c "substituted" resolved_module_type_path ppf x
×
1272
    | `ModuleType (p, m) ->
4✔
1273
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
4✔
1274
          (ModuleTypeName.to_string m)
4✔
1275
    | `CanonicalModuleType (m1, m2) ->
×
1276
        wrap2 c "canonicalt" resolved_module_type_path model_path ppf m1
1277
          (m2 :> path)
1278
    | `OpaqueModuleType m ->
×
1279
        wrap c "opaquemoduletype" resolved_module_type_path ppf m
1280
    | `AliasModuleType (mt1, mt2) ->
×
1281
        wrap2 c "aliasmoduletype" resolved_module_type_path
1282
          resolved_module_type_path ppf mt1 mt2
1283
    | `SubstT (mt1, mt2) ->
×
1284
        wrap2 c "substt" resolved_module_type_path resolved_module_type_path ppf
1285
          mt1 mt2
1286

1287
  and module_type_path : config -> Format.formatter -> Cpath.module_type -> unit
1288
      =
1289
   fun c ppf m ->
1290
    match m with
18✔
1291
    | `Resolved p -> wrap c "r" resolved_module_type_path ppf p
18✔
1292
    | `Identifier (id, b) ->
×
1293
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1294
    | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b
×
1295
    | `Substituted s -> wrap c "substituted" module_type_path ppf s
×
1296
    | `DotMT (m, s) ->
×
1297
        Format.fprintf ppf "%a.%a" (module_path c) m ModuleTypeName.fmt s
×
1298
    | `ModuleType (m, n) ->
×
1299
        Format.fprintf ppf "%a.%a" (resolved_parent_path c) m ModuleTypeName.fmt
×
1300
          n
1301

1302
  and resolved_type_path :
1303
      config -> Format.formatter -> Cpath.Resolved.type_ -> unit =
1304
   fun c ppf p ->
1305
    match p with
28✔
1306
    | `CoreType n -> Format.fprintf ppf "%s" (TypeName.to_string n)
17✔
1307
    | `Local id -> ident_fmt c ppf id
6✔
1308
    | `Gpath p -> model_resolved_path c ppf (p :> rpath)
×
1309
    | `Substituted x -> wrap c "substituted" resolved_type_path ppf x
×
NEW
1310
    | `Unbox x -> wrap c "unbox" resolved_type_path ppf x
×
UNCOV
1311
    | `CanonicalType (t1, t2) ->
×
1312
        wrap2 c "canonicaltype" resolved_type_path model_path ppf t1
1313
          (t2 :> path)
1314
    | `Class (p, t) ->
×
1315
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1316
          (TypeName.to_string t)
×
1317
    | `ClassType (p, t) ->
×
1318
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1319
          (TypeName.to_string t)
×
1320
    | `Type (p, t) ->
5✔
1321
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
5✔
1322
          (TypeName.to_string t)
5✔
1323

1324
  and resolved_value_path :
1325
      config -> Format.formatter -> Cpath.Resolved.value -> unit =
1326
   fun c ppf p ->
1327
    match p with
×
1328
    | `Value (p, t) ->
×
1329
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1330
          (ValueName.to_string t)
×
1331
    | `Gpath p -> Format.fprintf ppf "%a" (model_resolved_path c) (p :> rpath)
×
1332

1333
  and resolved_parent_path :
1334
      config -> Format.formatter -> Cpath.Resolved.parent -> unit =
1335
   fun c ppf p ->
1336
    match p with
19✔
1337
    | `Module m -> resolved_module_path c ppf m
19✔
1338
    | `ModuleType m ->
×
1339
        if c.short_paths then resolved_module_type_path c ppf m
×
1340
        else Format.fprintf ppf ">>%a<<" (resolved_module_type_path c) m
×
1341
    | `FragmentRoot -> Format.fprintf ppf "FragmentRoot"
×
1342

1343
  and type_path : config -> Format.formatter -> Cpath.type_ -> unit =
1344
   fun c ppf p ->
1345
    match p with
34✔
1346
    | `Resolved r -> wrap c "resolved" resolved_type_path ppf r
28✔
1347
    | `Identifier (id, b) ->
×
1348
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1349
    | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b
6✔
1350
    | `Substituted s -> wrap c "substituted" type_path ppf s
×
1351
    | `DotT (m, s) ->
×
1352
        Format.fprintf ppf "%a.%a" (module_path c) m TypeName.fmt s
×
1353
    | `Class (p, t) ->
×
1354
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1355
          (TypeName.to_string t)
×
1356
    | `ClassType (p, t) ->
×
1357
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1358
          (TypeName.to_string t)
×
1359
    | `Type (p, t) ->
×
1360
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1361
          (TypeName.to_string t)
×
NEW
1362
    | `Unbox t -> Format.fprintf ppf "%a#" (type_path c) t
×
1363

1364
  and value_path : config -> Format.formatter -> Cpath.value -> unit =
1365
   fun c ppf p ->
1366
    match p with
×
1367
    | `Resolved r -> wrap c "resolved" resolved_value_path ppf r
×
1368
    | `DotV (m, s) ->
×
1369
        Format.fprintf ppf "%a.%a" (module_path c) m ValueName.fmt s
×
1370
    | `Value (p, t) ->
×
1371
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1372
          (ValueName.to_string t)
×
1373
    | `Identifier (id, b) ->
×
1374
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1375

1376
  and resolved_class_type_path :
1377
      config -> Format.formatter -> Cpath.Resolved.class_type -> unit =
1378
   fun c ppf p ->
1379
    match p with
×
1380
    | `Local id -> Format.fprintf ppf "%a" Ident.fmt id
×
1381
    | `Gpath p -> Format.fprintf ppf "%a" (model_resolved_path c) (p :> rpath)
×
1382
    | `Substituted s -> wrap c "substituted" resolved_class_type_path ppf s
×
1383
    | `Class (p, t) ->
×
1384
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1385
          (TypeName.to_string t)
×
1386
    | `ClassType (p, t) ->
×
1387
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1388
          (TypeName.to_string t)
×
1389

1390
  and class_type_path : config -> Format.formatter -> Cpath.class_type -> unit =
1391
   fun c ppf p ->
1392
    match p with
×
1393
    | `Resolved r -> Format.fprintf ppf "%a" (resolved_class_type_path c) r
×
1394
    | `Identifier (id, b) ->
×
1395
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1396
    | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b
×
1397
    | `Substituted s -> wrap c "substituted" class_type_path ppf s
×
1398
    | `DotT (m, s) ->
×
1399
        Format.fprintf ppf "%a.%a" (module_path c) m TypeName.fmt s
×
1400
    | `Class (p, t) ->
×
1401
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1402
          (TypeName.to_string t)
×
1403
    | `ClassType (p, t) ->
×
1404
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1405
          (TypeName.to_string t)
×
1406

1407
  and model_path : config -> Format.formatter -> path -> unit =
1408
   fun c ppf (p : path) ->
1409
    let dot p s =
×
1410
      Format.fprintf ppf "%a.%s" (model_path c)
×
1411
        (p : Odoc_model.Paths.Path.Module.t :> path)
1412
        s
1413
    in
1414

1415
    match p with
1416
    | `Resolved rp -> wrap c "resolved" model_resolved_path ppf rp
×
1417
    | `Identifier (id, b) ->
×
1418
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1419
    | `Root s -> wrap c "root" str ppf (ModuleName.to_string s)
×
1420
    | `Forward s -> wrap c "forward" str ppf s
×
1421
    | `Dot (p, s) -> dot p (ModuleName.to_string s)
×
1422
    | `DotMT (p, s) -> dot p (ModuleTypeName.to_string s)
×
1423
    | `DotT (p, s) -> dot p (TypeName.to_string s)
×
1424
    | `DotV (p, s) -> dot p (ValueName.to_string s)
×
1425
    | `Apply (func, arg) ->
×
1426
        Format.fprintf ppf "%a(%a)" (model_path c)
×
1427
          (func :> path)
1428
          (model_path c)
×
1429
          (arg :> path)
1430
    | `Substituted m ->
×
1431
        wrap c "substituted" model_path ppf (m :> Odoc_model.Paths.Path.t)
1432
    | `SubstitutedMT m ->
×
1433
        wrap c "substitutedmt" model_path ppf (m :> Odoc_model.Paths.Path.t)
1434
    | `SubstitutedT m ->
×
1435
        wrap c "substitutedt" model_path ppf (m :> Odoc_model.Paths.Path.t)
1436
    | `SubstitutedCT m ->
×
1437
        wrap c "substitutedct" model_path ppf (m :> Odoc_model.Paths.Path.t)
NEW
1438
    | `Unbox t -> wrap c "unbox" model_path ppf (t :> Odoc_model.Paths.Path.t)
×
1439

1440
  and model_resolved_path (c : config) ppf (p : rpath) =
1441
    let open Odoc_model.Paths.Path.Resolved in
31✔
1442
    match p with
1443
    | `CoreType x -> Format.fprintf ppf "%s" (TypeName.to_string x)
×
1444
    | `Identifier id -> Format.fprintf ppf "%a" (model_identifier c) (id :> id)
31✔
1445
    | `Module (parent, name) ->
×
1446
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1447
          (parent :> t)
1448
          (ModuleName.to_string name)
×
1449
    | `ModuleType (parent, name) ->
×
1450
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1451
          (parent :> t)
1452
          (ModuleTypeName.to_string name)
×
1453
    | `Type (parent, name) ->
×
1454
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1455
          (parent :> t)
1456
          (TypeName.to_string name)
×
1457
    | `Value (parent, name) ->
×
1458
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1459
          (parent :> t)
1460
          (ValueName.to_string name)
×
1461
    | `Alias (dest, src) ->
×
1462
        wrap2r c "alias" model_resolved_path model_path ppf
1463
          (dest :> t)
1464
          (src :> path)
1465
    | `AliasModuleType (path, realpath) ->
×
1466
        wrap2r c "aliasmoduletype" model_resolved_path model_resolved_path ppf
1467
          (path :> t)
1468
          (realpath :> t)
1469
    | `Subst (modty, m) ->
×
1470
        wrap2 c "subst" model_resolved_path model_resolved_path ppf
1471
          (modty :> t)
1472
          (m :> t)
1473
    | `SubstT (t1, t2) ->
×
1474
        wrap2 c "substt" model_resolved_path model_resolved_path ppf
1475
          (t1 :> t)
1476
          (t2 :> t)
1477
    | `CanonicalModuleType (t1, t2) ->
×
1478
        wrap2 c "canonicalmoduletype" model_resolved_path model_path ppf
1479
          (t1 :> t)
1480
          (t2 :> path)
1481
    | `CanonicalType (t1, t2) ->
×
1482
        wrap2 c "canonicaltype" model_resolved_path model_path ppf
1483
          (t1 :> t)
1484
          (t2 :> path)
1485
    | `Apply (funct, arg) ->
×
1486
        Format.fprintf ppf "%a(%a)" (model_resolved_path c)
×
1487
          (funct :> t)
1488
          (model_resolved_path c)
×
1489
          (arg :> t)
1490
    | `Canonical (p1, p2) ->
×
1491
        wrap2 c "canonical" model_resolved_path model_path ppf
1492
          (p1 :> t)
1493
          (p2 :> path)
1494
    | `Hidden p -> wrap c "hidden" model_resolved_path ppf (p :> t)
×
1495
    | `Class (parent, name) ->
×
1496
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1497
          (parent :> t)
1498
          (TypeName.to_string name)
×
1499
    | `ClassType (parent, name) ->
×
1500
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1501
          (parent :> t)
1502
          (TypeName.to_string name)
×
1503
    | `OpaqueModule m -> wrap c "opaquemodule" model_resolved_path ppf (m :> t)
×
1504
    | `OpaqueModuleType m ->
×
1505
        wrap c "opaquemoduletype" model_resolved_path ppf (m :> t)
1506
    | `Substituted m -> wrap c "substituted" model_resolved_path ppf (m :> t)
×
1507
    | `SubstitutedMT m ->
×
1508
        wrap c "substitutedmt" model_resolved_path ppf (m :> t)
1509
    | `SubstitutedT m -> wrap c "substitutedt" model_resolved_path ppf (m :> t)
×
1510
    | `SubstitutedCT m ->
×
1511
        wrap c "substitutedct" model_resolved_path ppf (m :> t)
NEW
1512
    | `Unbox t -> wrap c "unbox" model_resolved_path ppf (t :> t)
×
1513

1514
  and model_fragment c ppf (f : Odoc_model.Paths.Fragment.t) =
1515
    match f with
×
1516
    | `Resolved rf -> model_resolved_fragment c ppf rf
×
1517
    | `Dot (sg, d) ->
×
1518
        Format.fprintf ppf "*%a.%s" (model_fragment c)
×
1519
          (sg :> Odoc_model.Paths.Fragment.t)
1520
          d
1521
    | `Root -> ()
×
1522

1523
  and model_resolved_fragment c ppf (f : Odoc_model.Paths.Fragment.Resolved.t) =
1524
    let open Odoc_model.Paths.Fragment.Resolved in
×
1525
    match f with
1526
    | `Root (`ModuleType p) ->
×
1527
        Format.fprintf ppf "root(%a)" (model_resolved_path c) (p :> rpath)
×
1528
    | `Root (`Module p) ->
×
1529
        Format.fprintf ppf "root(%a)" (model_resolved_path c) (p :> rpath)
×
1530
    | `Module (`Root _, m) when c.short_paths ->
×
1531
        Format.fprintf ppf "%s" (ModuleName.to_string m)
×
1532
    | `Module (sg, m) ->
×
1533
        Format.fprintf ppf "%a.%s"
1534
          (model_resolved_fragment c)
×
1535
          (sg :> t)
1536
          (ModuleName.to_string m)
×
1537
    | `Module_type (`Root _, m) when c.short_paths ->
×
1538
        Format.fprintf ppf "%s" (ModuleTypeName.to_string m)
×
1539
    | `Module_type (sg, mty) ->
×
1540
        Format.fprintf ppf "%a.%s"
1541
          (model_resolved_fragment c)
×
1542
          (sg :> t)
1543
          (ModuleTypeName.to_string mty)
×
1544
    | `Type (`Root _, t) when c.short_paths ->
×
1545
        Format.fprintf ppf "%s" (TypeName.to_string t)
×
1546
    | `Type (sg, t) ->
×
1547
        Format.fprintf ppf "%a.%s"
1548
          (model_resolved_fragment c)
×
1549
          (sg :> t)
1550
          (TypeName.to_string t)
×
1551
    | `Subst (path, m) ->
×
1552
        Format.fprintf ppf "(%a subst -> %a)" (model_resolved_path c)
×
1553
          (path :> rpath)
1554
          (model_resolved_fragment c)
×
1555
          (m :> t)
1556
    | `Alias (_, _) -> Format.fprintf ppf "UNIMPLEMENTED subst alias!?"
×
1557
    | `Class (sg, cls) ->
×
1558
        Format.fprintf ppf "%a.%s"
1559
          (model_resolved_fragment c)
×
1560
          (sg :> t)
1561
          (TypeName.to_string cls)
×
1562
    | `ClassType (sg, cls) ->
×
1563
        Format.fprintf ppf "%a.%s"
1564
          (model_resolved_fragment c)
×
1565
          (sg :> t)
1566
          (TypeName.to_string cls)
×
1567
    | `OpaqueModule m ->
×
1568
        Format.fprintf ppf "opaquemodule(%a)"
1569
          (model_resolved_fragment c)
×
1570
          (m :> Odoc_model.Paths.Fragment.Resolved.t)
1571

1572
  and resolved_root_fragment c ppf (f : Cfrag.root) =
1573
    match f with
×
1574
    | `ModuleType p ->
×
1575
        Format.fprintf ppf "root(%a)" (resolved_module_type_path c) p
×
1576
    | `Module p -> Format.fprintf ppf "root(%a)" (resolved_module_path c) p
×
1577

1578
  and resolved_signature_fragment c ppf (f : Cfrag.resolved_signature) =
1579
    match f with
3✔
1580
    | `Root r -> Format.fprintf ppf "%a" (resolved_root_fragment c) r
×
1581
    | (`Subst _ | `Alias _ | `Module _) as x -> resolved_module_fragment c ppf x
×
1582
    | `OpaqueModule m ->
×
1583
        Format.fprintf ppf "opaquemodule(%a)" (resolved_module_fragment c) m
×
1584

1585
  and resolved_module_fragment c ppf (f : Cfrag.resolved_module) =
1586
    match f with
5✔
1587
    | `Subst (s, f) ->
×
1588
        wrap2r c "subst" resolved_module_type_path resolved_module_fragment ppf
1589
          s f
1590
    | `Alias (m, f) ->
×
1591
        wrap2r c "alias" resolved_module_path resolved_module_fragment ppf m f
1592
    | `Module (`Root _, n) when c.short_paths ->
5✔
1593
        Format.fprintf ppf "%s" (ModuleName.to_string n)
5✔
1594
    | `Module (p, n) ->
×
1595
        Format.fprintf ppf "%a.%s"
1596
          (resolved_signature_fragment c)
×
1597
          p (ModuleName.to_string n)
×
1598
    | `OpaqueModule m -> wrap c "opaquemodule" resolved_module_fragment ppf m
×
1599

1600
  and resolved_module_type_fragment c ppf (f : Cfrag.resolved_module_type) =
1601
    match f with
×
1602
    | `ModuleType (`Root _, n) when c.short_paths ->
×
1603
        Format.fprintf ppf "%s" (ModuleTypeName.to_string n)
×
1604
    | `ModuleType (p, n) ->
×
1605
        Format.fprintf ppf "%a.%s"
1606
          (resolved_signature_fragment c)
×
1607
          p
1608
          (ModuleTypeName.to_string n)
×
1609

1610
  and resolved_type_fragment c ppf (f : Cfrag.resolved_type) =
1611
    match f with
5✔
1612
    | `Type (`Root _, n) when c.short_paths ->
2✔
1613
        Format.fprintf ppf "%s" (TypeName.to_string n)
2✔
1614
    | `Class (`Root _, n) when c.short_paths ->
×
1615
        Format.fprintf ppf "%s" (TypeName.to_string n)
×
1616
    | `ClassType (`Root _, n) when c.short_paths ->
×
1617
        Format.fprintf ppf "%s" (TypeName.to_string n)
×
1618
    | `Type (s, n) ->
3✔
1619
        Format.fprintf ppf "%a.%s"
1620
          (resolved_signature_fragment c)
3✔
1621
          s (TypeName.to_string n)
3✔
1622
    | `Class (s, n) ->
×
1623
        Format.fprintf ppf "%a.%s"
1624
          (resolved_signature_fragment c)
×
1625
          s (TypeName.to_string n)
×
1626
    | `ClassType (s, n) ->
×
1627
        Format.fprintf ppf "%a.%s"
1628
          (resolved_signature_fragment c)
×
1629
          s (TypeName.to_string n)
×
1630

1631
  and signature_fragment c ppf (f : Cfrag.signature) =
1632
    match f with
×
1633
    | `Resolved r ->
×
1634
        Format.fprintf ppf "r(%a)" (resolved_signature_fragment c) r
×
1635
    | `Dot (s, n) -> Format.fprintf ppf "%a.%s" (signature_fragment c) s n
×
1636
    | `Root -> Format.fprintf ppf "root"
×
1637

1638
  and module_fragment c ppf (f : Cfrag.module_) =
1639
    match f with
2✔
1640
    | `Resolved r -> wrap c "resolved" resolved_module_fragment ppf r
2✔
1641
    | `Dot (`Root, n) when c.short_paths -> Format.fprintf ppf "%s" n
×
1642
    | `Dot (s, n) -> Format.fprintf ppf "%a.%s" (signature_fragment c) s n
×
1643

1644
  and module_type_fragment c ppf (f : Cfrag.module_type) =
1645
    match f with
×
1646
    | `Resolved r -> wrap c "resolved" resolved_module_type_fragment ppf r
×
1647
    | `Dot (`Root, n) when c.short_paths -> Format.fprintf ppf "%s" n
×
1648
    | `Dot (s, n) -> Format.fprintf ppf "%a.%s" (signature_fragment c) s n
×
1649

1650
  and type_fragment c ppf (f : Cfrag.type_) =
1651
    match f with
7✔
1652
    | `Resolved r -> wrap c "resolved" resolved_type_fragment ppf r
5✔
1653
    | `Dot (`Root, n) when c.short_paths -> Format.fprintf ppf "%s" n
2✔
1654
    | `Dot (s, n) -> Format.fprintf ppf "%a.%s" (signature_fragment c) s n
×
1655

1656
  and model_resolved_reference c ppf (r : Odoc_model.Paths.Reference.Resolved.t)
1657
      =
1658
    let open Odoc_model.Paths.Reference.Resolved in
×
1659
    match r with
1660
    | `Identifier id -> Format.fprintf ppf "%a" (model_identifier c) id
×
1661
    | `Hidden p ->
×
1662
        Format.fprintf ppf "hidden(%a)" (model_resolved_reference c) (p :> t)
×
1663
    | `Module (parent, name) ->
×
1664
        Format.fprintf ppf "%a.%s"
1665
          (model_resolved_reference c)
×
1666
          (parent :> t)
1667
          (ModuleName.to_string name)
×
1668
    | `ModuleType (parent, name) ->
×
1669
        Format.fprintf ppf "%a.%s"
1670
          (model_resolved_reference c)
×
1671
          (parent :> t)
1672
          (ModuleTypeName.to_string name)
×
1673
    | `Type (parent, name) ->
×
1674
        Format.fprintf ppf "%a.%s"
1675
          (model_resolved_reference c)
×
1676
          (parent :> t)
1677
          (TypeName.to_string name)
×
1678
    | `Constructor (parent, name) ->
×
1679
        Format.fprintf ppf "%a.%s"
1680
          (model_resolved_reference c)
×
1681
          (parent :> t)
1682
          (ConstructorName.to_string name)
×
1683
    | `PolyConstructor (parent, name) ->
×
1684
        Format.fprintf ppf "%a.%s"
1685
          (model_resolved_reference c)
×
1686
          (parent :> t)
1687
          (ConstructorName.to_string name)
×
1688
    | `Field (parent, name) ->
×
1689
        Format.fprintf ppf "%a.%s"
1690
          (model_resolved_reference c)
×
1691
          (parent :> t)
1692
          (FieldName.to_string name)
×
1693
    | `UnboxedField (parent, name) ->
×
1694
        Format.fprintf ppf "%a.#%s"
1695
          (model_resolved_reference c)
×
1696
          (parent :> t)
1697
          (UnboxedFieldName.to_string name)
×
1698
    | `Extension (parent, name) ->
×
1699
        Format.fprintf ppf "%a.%s"
1700
          (model_resolved_reference c)
×
1701
          (parent :> t)
1702
          (ExtensionName.to_string name)
×
1703
    | `ExtensionDecl (parent, name, _) ->
×
1704
        Format.fprintf ppf "%a.%s"
1705
          (model_resolved_reference c)
×
1706
          (parent :> t)
1707
          (ExtensionName.to_string name)
×
1708
    | `Exception (parent, name) ->
×
1709
        Format.fprintf ppf "%a.%s"
1710
          (model_resolved_reference c)
×
1711
          (parent :> t)
1712
          (ExceptionName.to_string name)
×
1713
    | `Value (parent, name) ->
×
1714
        Format.fprintf ppf "%a.%s"
1715
          (model_resolved_reference c)
×
1716
          (parent :> t)
1717
          (ValueName.to_string name)
×
1718
    | `Class (parent, name) ->
×
1719
        Format.fprintf ppf "%a.%s"
1720
          (model_resolved_reference c)
×
1721
          (parent :> t)
1722
          (TypeName.to_string name)
×
1723
    | `ClassType (parent, name) ->
×
1724
        Format.fprintf ppf "%a.%s"
1725
          (model_resolved_reference c)
×
1726
          (parent :> t)
1727
          (TypeName.to_string name)
×
1728
    | `Method (parent, name) ->
×
1729
        Format.fprintf ppf "%a.%s"
1730
          (model_resolved_reference c)
×
1731
          (parent :> t)
1732
          (MethodName.to_string name)
×
1733
    | `InstanceVariable (parent, name) ->
×
1734
        Format.fprintf ppf "%a.%s"
1735
          (model_resolved_reference c)
×
1736
          (parent :> t)
1737
          (InstanceVariableName.to_string name)
×
1738
    | `Alias (x, y) ->
×
1739
        Format.fprintf ppf "alias(%a,%a)" (model_resolved_path c)
×
1740
          (x :> rpath)
1741
          (model_resolved_reference c)
×
1742
          (y :> Odoc_model.Paths.Reference.Resolved.t)
1743
    | `AliasModuleType (x, y) ->
×
1744
        Format.fprintf ppf "aliasmoduletype(%a,%a)" (model_resolved_path c)
×
1745
          (x :> rpath)
1746
          (model_resolved_reference c)
×
1747
          (y :> Odoc_model.Paths.Reference.Resolved.t)
1748
    | `Label (parent, name) ->
×
1749
        Format.fprintf ppf "%a.%s"
1750
          (model_resolved_reference c)
×
1751
          (parent :> t)
1752
          (LabelName.to_string name)
×
1753

1754
  and model_reference_hierarchy _c ppf
1755
      ((tag, components) : Reference.Hierarchy.t) =
1756
    (match tag with
12✔
1757
    | `TRelativePath -> fpf ppf "./"
7✔
1758
    | `TAbsolutePath -> fpf ppf "/"
3✔
1759
    | `TCurrentPackage -> fpf ppf "//");
2✔
1760
    let pp_sep ppf () = fpf ppf "/" in
7✔
1761
    Format.pp_print_list ~pp_sep Format.pp_print_string ppf components
1762

1763
  and model_reference c ppf (r : Reference.t) =
1764
    let open Reference in
46✔
1765
    match r with
1766
    | `Resolved r' -> Format.fprintf ppf "r(%a)" (model_resolved_reference c) r'
×
1767
    | `Root (name, _) -> Format.fprintf ppf "unresolvedroot(%s)" name
25✔
1768
    | `Dot (parent, str) ->
7✔
1769
        Format.fprintf ppf "%a.%s" (model_reference c) (parent :> t) str
7✔
1770
    | `Page_path p -> model_reference_hierarchy c ppf p
×
1771
    | `Asset_path p -> model_reference_hierarchy c ppf p
4✔
1772
    | `Module_path p -> model_reference_hierarchy c ppf p
×
1773
    | `Any_path p -> model_reference_hierarchy c ppf p
8✔
1774
    | `Module (parent, name) ->
×
1775
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1776
          (parent :> t)
1777
          (ModuleName.to_string name)
×
1778
    | `ModuleType (parent, name) ->
×
1779
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1780
          (parent :> t)
1781
          (ModuleTypeName.to_string name)
×
1782
    | `Type (parent, name) ->
×
1783
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1784
          (parent :> t)
1785
          (TypeName.to_string name)
×
1786
    | `Constructor (parent, name) ->
1✔
1787
        Format.fprintf ppf "%a.%s" (model_reference c)
1✔
1788
          (parent :> t)
1789
          (ConstructorName.to_string name)
1✔
1790
    | `Field (parent, name) ->
×
1791
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1792
          (parent :> t)
1793
          (FieldName.to_string name)
×
1794
    | `UnboxedField (parent, name) ->
×
1795
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1796
          (parent :> t)
1797
          (UnboxedFieldName.to_string name)
×
1798
    | `Extension (parent, name) ->
×
1799
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1800
          (parent :> t)
1801
          (ExtensionName.to_string name)
×
1802
    | `ExtensionDecl (parent, name) ->
×
1803
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1804
          (parent :> t)
1805
          (ExtensionName.to_string name)
×
1806
    | `Exception (parent, name) ->
×
1807
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1808
          (parent :> t)
1809
          (ExceptionName.to_string name)
×
1810
    | `Value (parent, name) ->
×
1811
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1812
          (parent :> t)
1813
          (ValueName.to_string name)
×
1814
    | `Class (parent, name) ->
×
1815
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1816
          (parent :> t)
1817
          (TypeName.to_string name)
×
1818
    | `ClassType (parent, name) ->
×
1819
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1820
          (parent :> t)
1821
          (TypeName.to_string name)
×
1822
    | `Method (parent, name) ->
×
1823
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1824
          (parent :> t)
1825
          (MethodName.to_string name)
×
1826
    | `InstanceVariable (parent, name) ->
×
1827
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1828
          (parent :> t)
1829
          (InstanceVariableName.to_string name)
×
1830
    | `Label (parent, name) ->
1✔
1831
        Format.fprintf ppf "%a.%s" (model_reference c)
1✔
1832
          (parent :> t)
1833
          (LabelName.to_string name)
1✔
1834
end
1835

1836
module LocalIdents = struct
1837
  open Odoc_model
1838
  (** The purpose of this module is to extract identifiers that could be
1839
      referenced in Paths - that is, modules, module types, types, classes and
1840
      class types. That way we can assign them an Ident.t ahead of time and be
1841
      self-consistent. Because we don't need _all_ of the identifiers we don't
1842
      traverse the entire structure. Additionally, we stop at (class_)signature
1843
      boundaries since identifiers within these won't be referenced except
1844
      within them, so we only do that on demand. *)
1845

1846
  type t = {
1847
    modules : Paths.Identifier.Module.t list;
1848
    module_types : Paths.Identifier.ModuleType.t list;
1849
    types : Paths.Identifier.Type.t list;
1850
    classes : Paths.Identifier.Class.t list;
1851
    class_types : Paths.Identifier.ClassType.t list;
1852
  }
1853

1854
  let empty =
1855
    {
1856
      modules = [];
1857
      module_types = [];
1858
      types = [];
1859
      classes = [];
1860
      class_types = [];
1861
    }
1862

1863
  open Lang
1864

1865
  let rec signature_items s ids =
1866
    let open Signature in
2,534✔
1867
    List.fold_left
1868
      (fun ids c ->
1869
        match c with
6,736✔
1870
        | Module (_, { Module.id; _ }) ->
2,580✔
1871
            { ids with modules = id :: ids.modules }
1872
        | ModuleType m ->
848✔
1873
            { ids with module_types = m.ModuleType.id :: ids.module_types }
1874
        | ModuleSubstitution { ModuleSubstitution.id; _ } ->
3✔
1875
            { ids with modules = id :: ids.modules }
1876
        | ModuleTypeSubstitution { ModuleTypeSubstitution.id; _ } ->
11✔
1877
            { ids with module_types = id :: ids.module_types }
1878
        | Type (_, t) -> { ids with types = t.TypeDecl.id :: ids.types }
1,505✔
1879
        | TypeSubstitution t -> { ids with types = t.TypeDecl.id :: ids.types }
20✔
1880
        | Class (_, c) -> { ids with classes = c.Class.id :: ids.classes }
61✔
1881
        | ClassType (_, c) ->
41✔
1882
            { ids with class_types = c.ClassType.id :: ids.class_types }
1883
        | TypExt _ | Exception _ | Value _ | Comment _ -> ids
33✔
1884
        | Include i -> signature i.Include.expansion.content ids
265✔
1885
        | Open o -> signature o.Open.expansion ids)
32✔
1886
      ids s
1887

1888
  and signature s ids = signature_items s.items ids
2,534✔
1889
end
1890

1891
module Of_Lang = struct
1892
  open Odoc_model
1893

1894
  type map = {
1895
    modules : Ident.module_ Paths.Identifier.Maps.Module.t;
1896
    module_types : Ident.module_type Paths.Identifier.Maps.ModuleType.t;
1897
    functor_parameters : Ident.module_ Paths.Identifier.Maps.FunctorParameter.t;
1898
    types : Ident.type_ Paths.Identifier.Maps.Type.t;
1899
    path_types : Ident.type_ Paths.Identifier.Maps.Path.Type.t;
1900
    path_class_types : Ident.type_ Paths.Identifier.Maps.Path.ClassType.t;
1901
    classes : Ident.type_ Paths.Identifier.Maps.Class.t;
1902
    class_types : Ident.type_ Paths.Identifier.Maps.ClassType.t;
1903
  }
1904

1905
  let empty () =
1906
    let open Paths.Identifier.Maps in
7,343✔
1907
    {
1908
      modules = Module.empty;
1909
      module_types = ModuleType.empty;
1910
      functor_parameters = FunctorParameter.empty;
1911
      types = Type.empty;
1912
      path_types = Path.Type.empty;
1913
      path_class_types = Path.ClassType.empty;
1914
      classes = Class.empty;
1915
      class_types = ClassType.empty;
1916
    }
1917

1918
  let map_of_idents ids map =
1919
    let open Paths.Identifier in
2,237✔
1920
    (* New types go into [types_new] and [path_types_new]
1921
       New classes go into [classes_new] and [path_class_types_new]
1922
       New class_types go into [class_types_new], [path_types_new] and [path_class_types_new] *)
1923
    let types_new, path_types_new =
1924
      List.fold_left
1925
        (fun (types, path_types) i ->
1926
          let id = Ident.Of_Identifier.type_ i in
1,525✔
1927
          ( Maps.Type.add i id types,
1,525✔
1928
            Maps.Path.Type.add (i :> Path.Type.t) id path_types ))
1,525✔
1929
        (map.types, map.path_types)
1930
        ids.LocalIdents.types
1931
    in
1932
    let classes_new, path_class_types_new =
2,237✔
1933
      List.fold_left
1934
        (fun (classes, path_class_types) i ->
1935
          let id = Ident.Of_Identifier.class_ i in
61✔
1936
          ( Maps.Class.add i id classes,
61✔
1937
            Maps.Path.ClassType.add (i :> Path.ClassType.t) id path_class_types
61✔
1938
          ))
1939
        (map.classes, map.path_class_types)
1940
        ids.LocalIdents.classes
1941
    in
1942
    let class_types_new, path_types_new, path_class_types_new =
2,237✔
1943
      List.fold_left
1944
        (fun (class_types, path_types, path_class_types) i ->
1945
          let id = Ident.Of_Identifier.class_type i in
41✔
1946
          ( Maps.ClassType.add i id class_types,
41✔
1947
            Maps.Path.Type.add (i :> Path.Type.t) id path_types,
41✔
1948
            Maps.Path.ClassType.add (i :> Path.ClassType.t) id path_class_types
41✔
1949
          ))
1950
        (map.class_types, path_types_new, path_class_types_new)
1951
        ids.LocalIdents.class_types
1952
    in
1953
    let modules_new =
2,237✔
1954
      List.fold_left
1955
        (fun acc i ->
1956
          Maps.Module.add (i :> Module.t) (Ident.Of_Identifier.module_ i) acc)
2,583✔
1957
        map.modules ids.LocalIdents.modules
1958
    in
1959
    let module_types_new =
2,237✔
1960
      List.fold_left
1961
        (fun acc i ->
1962
          Maps.ModuleType.add i (Ident.Of_Identifier.module_type i) acc)
859✔
1963
        map.module_types ids.LocalIdents.module_types
1964
    in
1965
    let modules = modules_new in
2,237✔
1966
    let module_types = module_types_new in
1967
    let functor_parameters = map.functor_parameters in
1968
    let types = types_new in
1969
    let classes = classes_new in
1970
    let class_types = class_types_new in
1971
    let path_types = path_types_new in
1972
    let path_class_types = path_class_types_new in
1973
    {
1974
      modules;
1975
      module_types;
1976
      functor_parameters;
1977
      types;
1978
      classes;
1979
      class_types;
1980
      path_types;
1981
      path_class_types;
1982
    }
1983

1984
  let option conv ident_map x =
1985
    match x with None -> None | Some x' -> Some (conv ident_map x')
1,135✔
1986

1987
  let identifier lookup map i =
1988
    match lookup i map with
115,412✔
1989
    | x -> `Local x
20,584✔
1990
    | exception Not_found -> `Identifier i
94,828✔
1991

1992
  let find_any_module i ident_map =
1993
    match i with
113,526✔
1994
    | { Odoc_model.Paths.Identifier.iv = `Root _ | `Module _; _ } as id ->
1,043✔
1995
        Maps.Module.find id ident_map.modules
1996
    | {
91✔
1997
        Odoc_model.Paths.Identifier.iv = #Paths.Identifier.FunctorParameter.t_pv;
1998
        _;
1999
      } as id ->
2000
        Maps.FunctorParameter.find id ident_map.functor_parameters
2001
    | _ -> raise Not_found
×
2002

2003
  let rec resolved_module_path :
2004
      _ -> Odoc_model.Paths.Path.Resolved.Module.t -> Cpath.Resolved.module_ =
2005
   fun ident_map p ->
2006
    let recurse = resolved_module_path ident_map in
164,057✔
2007
    match p with
164,057✔
2008
    | `Identifier i -> (
2,932✔
2009
        match identifier find_any_module ident_map i with
2010
        | `Local l -> `Local l
319✔
2011
        | `Identifier _ -> `Gpath p)
2,613✔
2012
    | `Module (p, name) -> `Module (`Module (recurse p), name)
756✔
2013
    | `Apply (p1, p2) -> `Apply (recurse p1, recurse p2)
43✔
2014
    | `Alias (p1, p2) -> `Alias (recurse p1, module_path ident_map p2, None)
109,674✔
2015
    | `Subst (p1, p2) ->
9✔
2016
        `Subst (resolved_module_type_path ident_map p1, recurse p2)
9✔
2017
    | `Canonical (p1, p2) -> `Canonical (recurse p1, p2)
50,254✔
2018
    | `Hidden p1 -> `Hidden (recurse p1)
276✔
2019
    | `OpaqueModule m -> `OpaqueModule (recurse m)
1✔
2020
    | `Substituted m -> `Substituted (recurse m)
112✔
2021

2022
  and resolved_module_type_path :
2023
      _ ->
2024
      Odoc_model.Paths.Path.Resolved.ModuleType.t ->
2025
      Cpath.Resolved.module_type =
2026
   fun ident_map p ->
2027
    match p with
870✔
2028
    | `Identifier i -> (
530✔
2029
        match identifier Maps.ModuleType.find ident_map.module_types i with
2030
        | `Local l -> `Local l
72✔
2031
        | `Identifier _ -> `Gpath p)
458✔
2032
    | `ModuleType (p, name) ->
203✔
2033
        `ModuleType (`Module (resolved_module_path ident_map p), name)
203✔
2034
    | `CanonicalModuleType (p1, p2) ->
18✔
2035
        `CanonicalModuleType (resolved_module_type_path ident_map p1, p2)
18✔
2036
    | `OpaqueModuleType m ->
30✔
2037
        `OpaqueModuleType (resolved_module_type_path ident_map m)
30✔
2038
    | `AliasModuleType (m1, m2) ->
55✔
2039
        `AliasModuleType
2040
          ( resolved_module_type_path ident_map m1,
55✔
2041
            resolved_module_type_path ident_map m2 )
55✔
2042
    | `SubstT (p1, p2) ->
34✔
2043
        `SubstT
2044
          ( resolved_module_type_path ident_map p1,
34✔
2045
            resolved_module_type_path ident_map p2 )
34✔
2046
    | `SubstitutedMT m -> `Substituted (resolved_module_type_path ident_map m)
×
2047

2048
  and resolved_type_path :
2049
      _ -> Odoc_model.Paths.Path.Resolved.Type.t -> Cpath.Resolved.type_ =
2050
   fun ident_map p ->
2051
    match p with
2,471✔
2052
    | `CoreType _ as c -> c
1,802✔
2053
    | `Identifier i -> (
428✔
2054
        match identifier Maps.Path.Type.find ident_map.path_types i with
2055
        | `Local l -> `Local l
113✔
2056
        | `Identifier _ -> `Gpath p)
315✔
2057
    | `CanonicalType (p1, p2) ->
22✔
2058
        `CanonicalType (resolved_type_path ident_map p1, p2)
22✔
2059
    | `Type (p, name) -> `Type (`Module (resolved_module_path ident_map p), name)
216✔
2060
    | `Class (p, name) ->
3✔
2061
        `Class (`Module (resolved_module_path ident_map p), name)
3✔
2062
    | `ClassType (p, name) ->
×
2063
        `ClassType (`Module (resolved_module_path ident_map p), name)
×
2064
    | `SubstitutedT m -> `Substituted (resolved_type_path ident_map m)
×
2065
    | `SubstitutedCT m ->
×
2066
        `Substituted
2067
          (resolved_class_type_path ident_map m :> Cpath.Resolved.type_)
×
NEW
2068
    | `Unbox m -> `Unbox (resolved_type_path ident_map m)
×
2069

2070
  and resolved_value_path :
2071
      _ -> Odoc_model.Paths.Path.Resolved.Value.t -> Cpath.Resolved.value =
2072
   fun ident_map p ->
2073
    match p with
×
2074
    | `Value (p, name) ->
×
2075
        `Value (`Module (resolved_module_path ident_map p), name)
×
2076
    | `Identifier _ -> `Gpath p
×
2077

2078
  and resolved_class_type_path :
2079
      _ ->
2080
      Odoc_model.Paths.Path.Resolved.ClassType.t ->
2081
      Cpath.Resolved.class_type =
2082
   fun ident_map p ->
2083
    match p with
23✔
2084
    | `Identifier i -> (
23✔
2085
        match
2086
          identifier Maps.Path.ClassType.find ident_map.path_class_types i
2087
        with
2088
        | `Local l -> `Local l
11✔
2089
        | `Identifier _ -> `Gpath p)
12✔
2090
    | `Class (p, name) ->
×
2091
        `Class (`Module (resolved_module_path ident_map p), name)
×
2092
    | `ClassType (p, name) ->
×
2093
        `ClassType (`Module (resolved_module_path ident_map p), name)
×
2094
    | `SubstitutedCT c -> `Substituted (resolved_class_type_path ident_map c)
×
2095

2096
  and module_path : _ -> Odoc_model.Paths.Path.Module.t -> Cpath.module_ =
2097
   fun ident_map p ->
2098
    match p with
124,427✔
2099
    | `Resolved r -> `Resolved (resolved_module_path ident_map r)
2,039✔
2100
    | `Substituted m -> `Substituted (module_path ident_map m)
15✔
2101
    | `Identifier (i, b) -> (
110,594✔
2102
        match identifier find_any_module ident_map i with
2103
        | `Identifier i -> `Identifier (i, b)
90,664✔
2104
        | `Local i -> `Local (i, b))
19,930✔
2105
    | `Dot (path', x) -> `Dot (module_path ident_map path', x)
10,848✔
2106
    | `Apply (p1, p2) ->
27✔
2107
        `Apply (module_path ident_map p1, module_path ident_map p2)
27✔
2108
    | `Forward str -> `Forward str
×
2109
    | `Root str -> `Root str
904✔
2110

2111
  and module_type_path :
2112
      _ -> Odoc_model.Paths.Path.ModuleType.t -> Cpath.module_type =
2113
   fun ident_map p ->
2114
    match p with
857✔
2115
    | `Resolved r -> `Resolved (resolved_module_type_path ident_map r)
454✔
2116
    | `SubstitutedMT m -> `Substituted (module_type_path ident_map m)
×
2117
    | `Identifier (i, b) -> (
331✔
2118
        match identifier Maps.ModuleType.find ident_map.module_types i with
2119
        | `Identifier i -> `Identifier (i, b)
306✔
2120
        | `Local i -> `Local (i, b))
25✔
2121
    | `DotMT (path', x) -> `DotMT (module_path ident_map path', x)
72✔
2122

2123
  and type_path : _ -> Odoc_model.Paths.Path.Type.t -> Cpath.type_ =
2124
   fun ident_map p ->
2125
    match p with
3,283✔
2126
    | `Resolved r -> `Resolved (resolved_type_path ident_map r)
2,443✔
2127
    | `SubstitutedT t -> `Substituted (type_path ident_map t)
×
2128
    | `Identifier (i, b) -> (
542✔
2129
        match identifier Maps.Path.Type.find ident_map.path_types i with
2130
        | `Identifier i -> `Identifier (i, b)
437✔
2131
        | `Local i -> `Local (i, b))
105✔
2132
    | `DotT (path', x) -> `DotT (module_path ident_map path', x)
298✔
NEW
2133
    | `Unbox t -> `Unbox (type_path ident_map t)
×
2134

2135
  and value_path : _ -> Odoc_model.Paths.Path.Value.t -> Cpath.value =
2136
   fun ident_map p ->
2137
    match p with
69✔
2138
    | `Resolved r -> `Resolved (resolved_value_path ident_map r)
×
2139
    | `DotV (path', x) -> `DotV (module_path ident_map path', x)
69✔
2140
    | `Identifier (i, b) -> `Identifier (i, b)
×
2141

2142
  and class_type_path :
2143
      _ -> Odoc_model.Paths.Path.ClassType.t -> Cpath.class_type =
2144
   fun ident_map p ->
2145
    match p with
69✔
2146
    | `Resolved r -> `Resolved (resolved_class_type_path ident_map r)
23✔
2147
    | `SubstitutedCT c -> `Substituted (class_type_path ident_map c)
×
2148
    | `Identifier (i, b) -> (
32✔
2149
        match
2150
          identifier Maps.Path.ClassType.find ident_map.path_class_types i
2151
        with
2152
        | `Identifier i -> `Identifier (i, b)
23✔
2153
        | `Local i -> `Local (i, b))
9✔
2154
    | `DotT (path', x) -> `DotT (module_path ident_map path', x)
14✔
2155

2156
  let rec resolved_signature_fragment :
2157
      map ->
2158
      Odoc_model.Paths.Fragment.Resolved.Signature.t ->
2159
      Cfrag.resolved_signature =
2160
   fun ident_map ty ->
2161
    match ty with
478✔
2162
    | `Root (`ModuleType path) ->
174✔
2163
        `Root (`ModuleType (resolved_module_type_path ident_map path))
174✔
2164
    | `Root (`Module path) ->
269✔
2165
        `Root (`Module (resolved_module_path ident_map path))
269✔
2166
    | (`Alias _ | `Subst _ | `Module _ | `OpaqueModule _) as x ->
×
2167
        (resolved_module_fragment ident_map x :> Cfrag.resolved_signature)
2168

2169
  and resolved_module_fragment :
2170
      _ -> Odoc_model.Paths.Fragment.Resolved.Module.t -> Cfrag.resolved_module
2171
      =
2172
   fun ident_map ty ->
2173
    match ty with
341✔
2174
    | `Subst (p, m) ->
4✔
2175
        `Subst
2176
          ( resolved_module_type_path ident_map p,
4✔
2177
            resolved_module_fragment ident_map m )
4✔
2178
    | `Alias (p, m) ->
10✔
2179
        `Alias
2180
          ( resolved_module_path ident_map p,
10✔
2181
            resolved_module_fragment ident_map m )
10✔
2182
    | `Module (p, m) -> `Module (resolved_signature_fragment ident_map p, m)
327✔
2183
    | `OpaqueModule m -> `OpaqueModule (resolved_module_fragment ident_map m)
×
2184

2185
  and resolved_module_type_fragment :
2186
      _ ->
2187
      Odoc_model.Paths.Fragment.Resolved.ModuleType.t ->
2188
      Cfrag.resolved_module_type =
2189
   fun ident_map ty ->
2190
    match ty with
24✔
2191
    | `Module_type (p, m) ->
24✔
2192
        `ModuleType (resolved_signature_fragment ident_map p, m)
24✔
2193

2194
  and resolved_type_fragment :
2195
      _ -> Odoc_model.Paths.Fragment.Resolved.Type.t -> Cfrag.resolved_type =
2196
   fun ident_map ty ->
2197
    match ty with
127✔
2198
    | `Type (p, n) -> `Type (resolved_signature_fragment ident_map p, n)
127✔
2199
    | `Class (p, n) -> `Class (resolved_signature_fragment ident_map p, n)
×
2200
    | `ClassType (p, n) ->
×
2201
        `ClassType (resolved_signature_fragment ident_map p, n)
×
2202

2203
  let rec signature_fragment :
2204
      _ -> Odoc_model.Paths.Fragment.Signature.t -> Cfrag.signature =
2205
   fun ident_map ty ->
2206
    match ty with
177✔
2207
    | `Resolved r -> `Resolved (resolved_signature_fragment ident_map r)
×
2208
    | `Dot (p, n) -> `Dot (signature_fragment ident_map p, n)
19✔
2209
    | `Root -> `Root
158✔
2210

2211
  let module_fragment : _ -> Odoc_model.Paths.Fragment.Module.t -> Cfrag.module_
2212
      =
2213
   fun ident_map ty ->
2214
    match ty with
330✔
2215
    | `Resolved r -> `Resolved (resolved_module_fragment ident_map r)
280✔
2216
    | `Dot (p, n) -> `Dot (signature_fragment ident_map p, n)
50✔
2217

2218
  let module_type_fragment :
2219
      _ -> Odoc_model.Paths.Fragment.ModuleType.t -> Cfrag.module_type =
2220
   fun ident_map ty ->
2221
    match ty with
32✔
2222
    | `Resolved r -> `Resolved (resolved_module_type_fragment ident_map r)
18✔
2223
    | `Dot (p, n) -> `Dot (signature_fragment ident_map p, n)
14✔
2224

2225
  let type_fragment : _ -> Odoc_model.Paths.Fragment.Type.t -> Cfrag.type_ =
2226
   fun ident_map ty ->
2227
    match ty with
189✔
2228
    | `Resolved r -> `Resolved (resolved_type_fragment ident_map r)
95✔
2229
    | `Dot (p, n) -> `Dot (signature_fragment ident_map p, n)
94✔
2230

2231
  let rec type_decl ident_map ty =
2232
    let open Odoc_model.Lang.TypeDecl in
1,640✔
2233
    {
2234
      TypeDecl.source_loc = ty.source_loc;
2235
      doc = docs ident_map ty.doc;
1,640✔
2236
      canonical = ty.canonical;
2237
      equation = type_equation ident_map ty.equation;
1,640✔
2238
      representation =
2239
        Opt.map (type_decl_representation ident_map) ty.representation;
1,640✔
2240
    }
2241

2242
  and type_decl_representation ident_map r =
2243
    let open Odoc_model.Lang.TypeDecl.Representation in
175✔
2244
    match r with
2245
    | Variant cs ->
118✔
2246
        TypeDecl.Representation.Variant
2247
          (List.map (type_decl_constructor ident_map) cs)
118✔
2248
    | Record fs -> Record (List.map (type_decl_field ident_map) fs)
23✔
2249
    | Record_unboxed_product fs ->
×
2250
        Record_unboxed_product (List.map (type_decl_unboxed_field ident_map) fs)
×
2251
    | Extensible -> Extensible
34✔
2252

2253
  and type_decl_constructor ident_map t =
2254
    let open Odoc_model.Lang.TypeDecl.Constructor in
192✔
2255
    let args = type_decl_constructor_argument ident_map t.args in
2256
    let res = Opt.map (type_expression ident_map) t.res in
192✔
2257
    {
192✔
2258
      TypeDecl.Constructor.name = Paths.Identifier.name t.id;
192✔
2259
      doc = docs ident_map t.doc;
192✔
2260
      args;
2261
      res;
2262
    }
2263

2264
  and type_decl_constructor_argument ident_map a =
2265
    let open Odoc_model.Lang.TypeDecl.Constructor in
377✔
2266
    match a with
2267
    | Tuple ts ->
371✔
2268
        TypeDecl.Constructor.Tuple (List.map (type_expression ident_map) ts)
371✔
2269
    | Record fs -> Record (List.map (type_decl_field ident_map) fs)
6✔
2270

2271
  and type_decl_field ident_map f =
2272
    let open Odoc_model.Lang.TypeDecl.Field in
52✔
2273
    let type_ = type_expression ident_map f.type_ in
2274
    {
52✔
2275
      TypeDecl.Field.name = Paths.Identifier.name f.id;
52✔
2276
      doc = docs ident_map f.doc;
52✔
2277
      mutable_ = f.mutable_;
2278
      type_;
2279
    }
2280

2281
  and type_decl_unboxed_field ident_map f =
2282
    let type_ = type_expression ident_map f.type_ in
×
2283
    {
×
2284
      TypeDecl.UnboxedField.name = Paths.Identifier.name f.id;
×
2285
      doc = docs ident_map f.doc;
×
2286
      mutable_ = f.mutable_;
2287
      type_;
2288
    }
2289

2290
  and type_equation ident_map teq =
2291
    let open Odoc_model.Lang.TypeDecl.Equation in
1,858✔
2292
    {
2293
      TypeDecl.Equation.params = teq.params;
2294
      private_ = teq.private_;
2295
      manifest = option type_expression ident_map teq.manifest;
1,858✔
2296
      constraints =
2297
        List.map
1,858✔
2298
          (fun (x, y) ->
2299
            (type_expression ident_map x, type_expression ident_map y))
24✔
2300
          teq.constraints;
2301
    }
2302

2303
  and type_expr_polyvar ident_map v =
2304
    let open Odoc_model.Lang.TypeExpr.Polymorphic_variant in
63✔
2305
    let map_element = function
2306
      | Type expr ->
8✔
2307
          TypeExpr.Polymorphic_variant.Type (type_expression ident_map expr)
8✔
2308
      | Constructor c ->
99✔
2309
          Constructor
2310
            TypeExpr.Polymorphic_variant.Constructor.
2311
              {
2312
                name = c.name;
2313
                constant = c.constant;
2314
                arguments = List.map (type_expression ident_map) c.arguments;
99✔
2315
                doc = docs ident_map c.doc;
99✔
2316
              }
2317
    in
2318
    {
2319
      TypeExpr.Polymorphic_variant.kind = v.kind;
2320
      elements = List.map map_element v.elements;
63✔
2321
    }
2322

2323
  and type_object ident_map o =
2324
    let open Odoc_model.Lang.TypeExpr.Object in
20✔
2325
    let map_field = function
2326
      | Method m ->
30✔
2327
          TypeExpr.(
2328
            Object.Method
2329
              {
2330
                Object.name = m.name;
2331
                type_ = type_expression ident_map m.type_;
30✔
2332
              })
2333
      | Inherit i -> Inherit (type_expression ident_map i)
×
2334
    in
2335
    { TypeExpr.Object.open_ = o.open_; fields = List.map map_field o.fields }
20✔
2336

2337
  and type_package ident_map pkg =
2338
    let open Odoc_model.Lang.TypeExpr.Package in
6✔
2339
    {
2340
      TypeExpr.Package.path = module_type_path ident_map pkg.path;
6✔
2341
      substitutions =
2342
        List.map
6✔
2343
          (fun (x, y) ->
2344
            let f = type_fragment ident_map x in
4✔
2345
            (f, type_expression ident_map y))
4✔
2346
          pkg.substitutions;
2347
    }
2348

2349
  and type_expression ident_map expr =
2350
    let open Odoc_model.Lang.TypeExpr in
3,023✔
2351
    match expr with
2352
    | Var s -> TypeExpr.Var s
389✔
2353
    | Any -> Any
×
2354
    | Constr (p, xs) ->
2,152✔
2355
        Constr (type_path ident_map p, List.map (type_expression ident_map) xs)
2,152✔
2356
    | Arrow (lbl, t1, t2) ->
309✔
2357
        Arrow (lbl, type_expression ident_map t1, type_expression ident_map t2)
309✔
2358
    | Tuple ts ->
46✔
2359
        Tuple
2360
          (List.map (fun (lbl, ty) -> (lbl, type_expression ident_map ty)) ts)
46✔
2361
    | Unboxed_tuple ts ->
×
2362
        Unboxed_tuple
2363
          (List.map (fun (l, t) -> (l, type_expression ident_map t)) ts)
×
2364
    | Polymorphic_variant v ->
63✔
2365
        Polymorphic_variant (type_expr_polyvar ident_map v)
63✔
2366
    | Poly (s, ts) -> Poly (s, type_expression ident_map ts)
6✔
2367
    | Alias (t, s) -> Alias (type_expression ident_map t, s)
22✔
2368
    | Class (p, ts) ->
10✔
2369
        Class
2370
          (class_type_path ident_map p, List.map (type_expression ident_map) ts)
10✔
2371
    | Object o -> Object (type_object ident_map o)
20✔
2372
    | Quote t -> Quote (type_expression ident_map t)
×
2373
    | Splice t -> Splice (type_expression ident_map t)
×
2374
    | Package p -> Package (type_package ident_map p)
6✔
2375
    | Arrow_functor (lbl, m_arg, t) ->
×
2376
        Arrow_functor
2377
          (lbl, type_module_arg ident_map m_arg, type_expression ident_map t)
×
2378

2379
  and type_module_arg ident_map { package; id } =
2380
    let id = Ident.Of_Identifier.functor_parameter id in
×
2381
    let package = type_package ident_map package in
×
2382
    { package; id }
×
2383

2384
  and module_decl ident_map m =
2385
    match m with
2,521✔
2386
    | Lang.Module.Alias (p, e) ->
1,166✔
2387
        Module.Alias
2388
          (module_path ident_map p, option simple_expansion ident_map e)
1,166✔
2389
    | Lang.Module.ModuleType s ->
1,355✔
2390
        Module.ModuleType (module_type_expr ident_map s)
1,355✔
2391

2392
  and include_decl ident_map m =
2393
    match m with
412✔
2394
    | Odoc_model.Lang.Include.Alias p -> Include.Alias (module_path ident_map p)
×
2395
    | ModuleType s -> ModuleType (u_module_type_expr ident_map s)
412✔
2396

2397
  and simple_expansion ident_map
2398
      (f : Odoc_model.Lang.ModuleType.simple_expansion) :
2399
      ModuleType.simple_expansion =
2400
    let open Odoc_model.Lang.ModuleType in
352✔
2401
    let open Odoc_model.Lang.FunctorParameter in
2402
    match f with
2403
    | Signature t -> Signature (signature ident_map t)
341✔
2404
    | Functor (arg, sg) -> (
11✔
2405
        match arg with
2406
        | Named arg ->
11✔
2407
            let identifier = arg.Odoc_model.Lang.FunctorParameter.id in
2408
            let id = Ident.Of_Identifier.functor_parameter identifier in
2409
            let ident_map' =
11✔
2410
              {
2411
                ident_map with
2412
                functor_parameters =
2413
                  Maps.FunctorParameter.add identifier id
11✔
2414
                    ident_map.functor_parameters;
2415
              }
2416
            in
2417
            let arg' = functor_parameter ident_map' id arg in
2418
            Functor (FunctorParameter.Named arg', simple_expansion ident_map' sg)
11✔
2419
        | Unit -> Functor (FunctorParameter.Unit, simple_expansion ident_map sg)
×
2420
        )
2421

2422
  and module_ ident_map m =
2423
    let type_ = module_decl ident_map m.Odoc_model.Lang.Module.type_ in
2,217✔
2424
    let canonical = m.Odoc_model.Lang.Module.canonical in
2,217✔
2425
    {
2426
      Module.source_loc = m.source_loc;
2427
      doc = docs ident_map m.doc;
2,217✔
2428
      type_;
2429
      canonical;
2430
      hidden = m.hidden;
2431
    }
2432

2433
  and with_module_type_substitution ident_map m =
2434
    let open Odoc_model.Lang.ModuleType in
399✔
2435
    match m with
2436
    | ModuleEq (frag, decl) ->
206✔
2437
        ModuleType.ModuleEq
2438
          (module_fragment ident_map frag, module_decl ident_map decl)
206✔
2439
    | ModuleSubst (frag, p) ->
21✔
2440
        ModuleType.ModuleSubst
2441
          (module_fragment ident_map frag, module_path ident_map p)
21✔
2442
    | ModuleTypeEq (frag, mty) ->
17✔
2443
        ModuleType.ModuleTypeEq
2444
          (module_type_fragment ident_map frag, module_type_expr ident_map mty)
17✔
2445
    | ModuleTypeSubst (frag, mty) ->
9✔
2446
        ModuleType.ModuleTypeSubst
2447
          (module_type_fragment ident_map frag, module_type_expr ident_map mty)
9✔
2448
    | TypeEq (frag, eqn) ->
70✔
2449
        ModuleType.TypeEq
2450
          (type_fragment ident_map frag, type_equation ident_map eqn)
70✔
2451
    | TypeSubst (frag, eqn) ->
76✔
2452
        ModuleType.TypeSubst
2453
          (type_fragment ident_map frag, type_equation ident_map eqn)
76✔
2454

2455
  and functor_parameter ident_map id a =
2456
    let expr' =
38✔
2457
      module_type_expr ident_map a.Odoc_model.Lang.FunctorParameter.expr
2458
    in
2459
    { FunctorParameter.id; expr = expr' }
38✔
2460

2461
  and extension ident_map e =
2462
    let open Odoc_model.Lang.Extension in
84✔
2463
    let type_path = type_path ident_map e.type_path in
2464
    let constructors =
84✔
2465
      List.map (extension_constructor ident_map) e.constructors
84✔
2466
    in
2467
    {
84✔
2468
      Extension.type_path;
2469
      doc = docs ident_map e.doc;
84✔
2470
      type_params = e.type_params;
2471
      private_ = e.private_;
2472
      constructors;
2473
    }
2474

2475
  and extension_constructor ident_map c =
2476
    let open Odoc_model.Lang.Extension.Constructor in
139✔
2477
    let args = type_decl_constructor_argument ident_map c.args in
2478
    let res = Opt.map (type_expression ident_map) c.res in
139✔
2479
    {
139✔
2480
      Extension.Constructor.name = Paths.Identifier.name c.id;
139✔
2481
      source_loc = c.source_loc;
2482
      doc = docs ident_map c.doc;
139✔
2483
      args;
2484
      res;
2485
    }
2486

2487
  and exception_ ident_map e =
2488
    let open Odoc_model.Lang.Exception in
46✔
2489
    let args = type_decl_constructor_argument ident_map e.args in
2490
    let res = Opt.map (type_expression ident_map) e.res in
46✔
2491
    {
46✔
2492
      Exception.source_loc = e.source_loc;
2493
      doc = docs ident_map e.doc;
46✔
2494
      args;
2495
      res;
2496
    }
2497

2498
  and u_module_type_expr ident_map m =
2499
    let open Odoc_model in
926✔
2500
    match m with
2501
    | Lang.ModuleType.U.Signature s ->
61✔
2502
        let s = signature ident_map s in
2503
        ModuleType.U.Signature s
61✔
2504
    | Path p ->
391✔
2505
        let p' = module_type_path ident_map p in
2506
        Path p'
391✔
2507
    | With (w, e) ->
57✔
2508
        let w' = List.map (with_module_type_substitution ident_map) w in
57✔
2509
        With (w', u_module_type_expr ident_map e)
57✔
2510
    | TypeOf (t_desc, t_original_path) ->
417✔
2511
        let t_desc =
2512
          match t_desc with
2513
          | ModPath p -> ModuleType.ModPath (module_path ident_map p)
318✔
2514
          | StructInclude p -> StructInclude (module_path ident_map p)
99✔
2515
        in
2516
        (* see comment in module_type_expr below *)
2517
        let t_original_path = module_path (empty ()) t_original_path in
417✔
2518
        TypeOf (t_desc, t_original_path)
417✔
2519
    | Strengthen (e, p, a) ->
×
2520
        let e = u_module_type_expr ident_map e in
2521
        let p = module_path ident_map p in
×
2522
        Strengthen (e, p, a)
×
2523

2524
  and module_type_expr ident_map m =
2525
    let open Odoc_model in
2,464✔
2526
    let open Paths in
2527
    match m with
2528
    | Lang.ModuleType.Signature s ->
1,829✔
2529
        let s = signature ident_map s in
2530
        ModuleType.Signature s
1,829✔
2531
    | Lang.ModuleType.Path p ->
258✔
2532
        let p' =
2533
          ModuleType.
2534
            {
2535
              p_path = module_type_path ident_map p.p_path;
258✔
2536
              p_expansion = option simple_expansion ident_map p.p_expansion;
258✔
2537
            }
2538
        in
2539
        ModuleType.Path p'
2540
    | Lang.ModuleType.With w ->
275✔
2541
        let w' =
2542
          ModuleType.
2543
            {
2544
              w_substitutions =
2545
                List.map
275✔
2546
                  (with_module_type_substitution ident_map)
275✔
2547
                  w.w_substitutions;
2548
              w_expansion = option simple_expansion ident_map w.w_expansion;
275✔
2549
              w_expr = u_module_type_expr ident_map w.w_expr;
275✔
2550
            }
2551
        in
2552
        ModuleType.With w'
2553
    | Lang.ModuleType.Functor (Named arg, expr) ->
27✔
2554
        let identifier = arg.Lang.FunctorParameter.id in
2555
        let id = Ident.Of_Identifier.functor_parameter identifier in
2556
        let ident_map' =
27✔
2557
          {
2558
            ident_map with
2559
            functor_parameters =
2560
              Identifier.Maps.FunctorParameter.add identifier id
27✔
2561
                ident_map.functor_parameters;
2562
          }
2563
        in
2564
        let arg' = functor_parameter ident_map' id arg in
2565
        let expr' = module_type_expr ident_map' expr in
27✔
2566
        ModuleType.Functor (Named arg', expr')
27✔
2567
    | Lang.ModuleType.Functor (Unit, expr) ->
1✔
2568
        let expr' = module_type_expr ident_map expr in
2569
        ModuleType.Functor (Unit, expr')
1✔
2570
    | Lang.ModuleType.TypeOf { t_desc; t_original_path; t_expansion } ->
74✔
2571
        let t_desc =
2572
          match t_desc with
2573
          | ModPath p -> ModuleType.ModPath (module_path ident_map p)
60✔
2574
          | StructInclude p -> StructInclude (module_path ident_map p)
14✔
2575
        in
2576
        let t_expansion = option simple_expansion ident_map t_expansion in
2577
        (* Nb, we _never_ want to relativize this path, because this should always be
2578
           the _original_ path. That's why we're passing in (empty()) rather than
2579
           ident_map. We don't leave it as a Lang path because we'll occasionally
2580
           _create_ a `TypeOf` expression as part of fragmap *)
2581
        let t_original_path = module_path (empty ()) t_original_path in
74✔
2582
        ModuleType.(TypeOf { t_desc; t_original_path; t_expansion })
74✔
2583
    | Lang.ModuleType.Strengthen s ->
×
2584
        let s' =
2585
          ModuleType.
2586
            {
2587
              s_expr = u_module_type_expr ident_map s.s_expr;
×
2588
              s_path = module_path ident_map s.s_path;
×
2589
              s_aliasable = s.s_aliasable;
2590
              s_expansion = option simple_expansion ident_map s.s_expansion;
×
2591
            }
2592
        in
2593
        ModuleType.Strengthen s'
2594

2595
  and module_type ident_map m =
2596
    let expr =
803✔
2597
      Opt.map (module_type_expr ident_map) m.Odoc_model.Lang.ModuleType.expr
803✔
2598
    in
2599
    {
803✔
2600
      ModuleType.source_loc = m.source_loc;
2601
      doc = docs ident_map m.doc;
803✔
2602
      canonical = m.canonical;
2603
      expr;
2604
    }
2605

2606
  and value ident_map v =
2607
    let type_ = type_expression ident_map v.Lang.Value.type_ in
456✔
2608
    {
456✔
2609
      Value.type_;
2610
      doc = docs ident_map v.doc;
456✔
2611
      value = v.value;
2612
      source_loc = v.source_loc;
2613
    }
2614

2615
  and include_ ident_map i =
2616
    let open Odoc_model.Lang.Include in
265✔
2617
    let decl = include_decl ident_map i.decl in
2618
    {
265✔
2619
      Include.parent = i.parent;
2620
      doc = docs ident_map i.doc;
265✔
2621
      shadowed = i.expansion.shadowed;
2622
      expansion_ = apply_sig_map ident_map i.expansion.content;
265✔
2623
      status = i.status;
2624
      strengthened = option module_path ident_map i.strengthened;
265✔
2625
      decl;
2626
      loc = i.loc;
2627
    }
2628

2629
  and class_ ident_map c =
2630
    let open Odoc_model.Lang.Class in
115✔
2631
    let expansion = Opt.map (class_signature ident_map) c.expansion in
115✔
2632
    {
115✔
2633
      Class.source_loc = c.source_loc;
2634
      doc = docs ident_map c.doc;
115✔
2635
      virtual_ = c.virtual_;
2636
      params = c.params;
2637
      type_ = class_decl ident_map c.type_;
115✔
2638
      expansion;
2639
    }
2640

2641
  and class_decl ident_map c =
2642
    let open Odoc_model.Lang.Class in
124✔
2643
    match c with
2644
    | ClassType e -> Class.ClassType (class_type_expr ident_map e)
115✔
2645
    | Arrow (lbl, e, d) ->
9✔
2646
        Arrow (lbl, type_expression ident_map e, class_decl ident_map d)
9✔
2647

2648
  and class_type_expr ident_map e =
2649
    let open Odoc_model.Lang.ClassType in
199✔
2650
    match e with
2651
    | Constr (p, ts) ->
40✔
2652
        ClassType.Constr
2653
          (class_type_path ident_map p, List.map (type_expression ident_map) ts)
40✔
2654
    | Signature s -> Signature (class_signature ident_map s)
159✔
2655

2656
  and class_type ident_map t =
2657
    let open Odoc_model.Lang.ClassType in
72✔
2658
    let expansion = Opt.map (class_signature ident_map) t.expansion in
72✔
2659
    {
72✔
2660
      ClassType.source_loc = t.source_loc;
2661
      doc = docs ident_map t.doc;
72✔
2662
      virtual_ = t.virtual_;
2663
      params = t.params;
2664
      expr = class_type_expr ident_map t.expr;
72✔
2665
      expansion;
2666
    }
2667

2668
  and class_signature ident_map sg =
2669
    let open Odoc_model.Lang.ClassSignature in
256✔
2670
    let items =
2671
      List.map
2672
        (function
2673
          | Method m ->
112✔
2674
              let id = Ident.Of_Identifier.method_ m.id in
2675
              let m' = method_ ident_map m in
112✔
2676
              ClassSignature.Method (id, m')
112✔
2677
          | InstanceVariable i ->
22✔
2678
              let id = Ident.Of_Identifier.instance_variable i.id in
2679
              let i' = instance_variable ident_map i in
22✔
2680
              ClassSignature.InstanceVariable (id, i')
22✔
2681
          | Constraint cst -> Constraint (class_constraint ident_map cst)
6✔
2682
          | Inherit e -> Inherit (inherit_ ident_map e)
12✔
2683
          | Comment c -> Comment (docs_or_stop ident_map c))
24✔
2684
        sg.items
2685
    in
2686
    {
256✔
2687
      ClassSignature.self = Opt.map (type_expression ident_map) sg.self;
256✔
2688
      items;
2689
      doc = docs ident_map sg.doc;
256✔
2690
    }
2691

2692
  and method_ ident_map m =
2693
    let open Odoc_model.Lang.Method in
162✔
2694
    {
2695
      Method.doc = docs ident_map m.doc;
162✔
2696
      private_ = m.private_;
2697
      virtual_ = m.virtual_;
2698
      type_ = type_expression ident_map m.type_;
162✔
2699
    }
2700

2701
  and instance_variable ident_map i =
2702
    {
22✔
2703
      InstanceVariable.doc = docs ident_map i.doc;
22✔
2704
      mutable_ = i.mutable_;
2705
      virtual_ = i.virtual_;
2706
      type_ = type_expression ident_map i.type_;
22✔
2707
    }
2708

2709
  and class_constraint ident_map cst =
2710
    {
6✔
2711
      ClassSignature.Constraint.doc = docs ident_map cst.doc;
6✔
2712
      left = type_expression ident_map cst.left;
6✔
2713
      right = type_expression ident_map cst.right;
6✔
2714
    }
2715

2716
  and inherit_ ident_map ih =
2717
    {
12✔
2718
      ClassSignature.Inherit.doc = docs ident_map ih.doc;
12✔
2719
      expr = class_type_expr ident_map ih.expr;
12✔
2720
    }
2721

2722
  and module_substitution ident_map (t : Odoc_model.Lang.ModuleSubstitution.t) =
2723
    {
3✔
2724
      ModuleSubstitution.doc = docs ident_map t.doc;
3✔
2725
      manifest = module_path ident_map t.manifest;
3✔
2726
    }
2727

2728
  and module_type_substitution ident_map
2729
      (t : Odoc_model.Lang.ModuleTypeSubstitution.t) =
2730
    {
11✔
2731
      ModuleTypeSubstitution.doc = docs ident_map t.doc;
11✔
2732
      manifest = module_type_expr ident_map t.manifest;
11✔
2733
    }
2734

2735
  and module_of_module_substitution ident_map
2736
      (t : Odoc_model.Lang.ModuleSubstitution.t) =
2737
    let manifest = module_path ident_map t.manifest in
×
2738
    {
×
2739
      Module.source_loc = None;
2740
      doc = docs ident_map t.doc;
×
2741
      type_ = Alias (manifest, None);
2742
      canonical = None;
2743
      hidden = false;
2744
    }
2745

2746
  and signature : _ -> Odoc_model.Lang.Signature.t -> Signature.t =
2747
   fun ident_map items ->
2748
    (* First we construct a list of brand new [Ident.t]s
2749
                for each item in the signature *)
2750
    let ident_map =
2,237✔
2751
      map_of_idents (LocalIdents.signature items LocalIdents.empty) ident_map
2,237✔
2752
    in
2753
    (* Now we construct the Components for each item,
2754
                converting all paths containing Identifiers pointing at
2755
                our elements to local paths *)
2756
    apply_sig_map ident_map items
2,237✔
2757

2758
  and open_ ident_map o =
2759
    Open.
32✔
2760
      {
2761
        expansion = apply_sig_map ident_map o.Odoc_model.Lang.Open.expansion;
32✔
2762
        doc = docs ident_map o.Odoc_model.Lang.Open.doc;
32✔
2763
      }
2764

2765
  and removed_item ident_map r =
2766
    let open Odoc_model.Lang.Signature in
50✔
2767
    match r with
2768
    | RModule (id, p) -> Signature.RModule (id, module_path ident_map p)
11✔
2769
    | RType (id, texpr, eqn) ->
37✔
2770
        RType (id, type_expression ident_map texpr, type_equation ident_map eqn)
37✔
2771
    | RModuleType (id, m) -> RModuleType (id, module_type_expr ident_map m)
2✔
2772

2773
  and apply_sig_map ident_map sg =
2774
    let items =
2,534✔
2775
      List.rev_map
2776
        (let open Odoc_model.Lang.Signature in
2777
         let open Odoc_model.Paths in
2778
         function
2779
         | Type (r, t) ->
1,505✔
2780
             let id = Identifier.Maps.Type.find t.id ident_map.types in
2781
             let t' = Delayed.put (fun () -> type_decl ident_map t) in
408✔
2782
             Signature.Type (id, r, t')
1,505✔
2783
         | TypeSubstitution t ->
20✔
2784
             let id = Identifier.Maps.Type.find t.id ident_map.types in
2785
             let t' = type_decl ident_map t in
20✔
2786
             Signature.TypeSubstitution (id, t')
20✔
2787
         | Module (r, m) ->
2,580✔
2788
             let id =
2789
               Identifier.Maps.Module.find
2790
                 (m.id :> Identifier.Module.t)
2791
                 ident_map.modules
2792
             in
2793
             let m' = Delayed.put (fun () -> module_ ident_map m) in
766✔
2794
             Signature.Module (id, r, m')
2,580✔
2795
         | ModuleSubstitution m ->
3✔
2796
             let id = Identifier.Maps.Module.find m.id ident_map.modules in
2797
             let m' = module_substitution ident_map m in
3✔
2798
             Signature.ModuleSubstitution (id, m')
3✔
2799
         | ModuleTypeSubstitution m ->
11✔
2800
             let id =
2801
               Identifier.Maps.ModuleType.find m.id ident_map.module_types
2802
             in
2803
             let m' = module_type_substitution ident_map m in
11✔
2804
             Signature.ModuleTypeSubstitution (id, m')
11✔
2805
         | ModuleType m ->
848✔
2806
             let id =
2807
               Identifier.Maps.ModuleType.find m.id ident_map.module_types
2808
             in
2809
             let m' = Delayed.put (fun () -> module_type ident_map m) in
199✔
2810
             Signature.ModuleType (id, m')
848✔
2811
         | Value v ->
819✔
2812
             let id = Ident.Of_Identifier.value v.id in
2813
             let v' = Delayed.put (fun () -> value ident_map v) in
91✔
2814
             Signature.Value (id, v')
819✔
2815
         | Comment c -> Comment (docs_or_stop ident_map c)
458✔
2816
         | TypExt e -> TypExt (extension ident_map e)
60✔
2817
         | Exception e ->
33✔
2818
             let id = Ident.Of_Identifier.exception_ e.id in
2819
             Exception (id, exception_ ident_map e)
33✔
2820
         | Class (r, c) ->
61✔
2821
             let id = Identifier.Maps.Class.find c.id ident_map.classes in
2822
             Class (id, r, class_ ident_map c)
61✔
2823
         | ClassType (r, c) ->
41✔
2824
             let id =
2825
               Identifier.Maps.ClassType.find c.id ident_map.class_types
2826
             in
2827
             ClassType (id, r, class_type ident_map c)
41✔
2828
         | Open o -> Open (open_ ident_map o)
32✔
2829
         | Include i -> Include (include_ ident_map i))
265✔
2830
        sg.items
2831
      |> List.rev
2,534✔
2832
    in
2833
    let removed = List.map (removed_item ident_map) sg.removed in
2,534✔
2834
    { items; removed; compiled = sg.compiled; doc = docs ident_map sg.doc }
2,534✔
2835

2836
  and block_element _ b :
2837
      CComment.block_element Odoc_model.Comment.with_location =
2838
    match b with
1,879✔
2839
    | { Odoc_model.Location_.value = `Heading (attrs, label, text); location }
331✔
2840
      ->
2841
        let label = Ident.Of_Identifier.label label in
2842
        Odoc_model.Location_.same b
331✔
2843
          (`Heading { Label.attrs; label; text; location })
2844
    | { value = `Tag _ | `Media _; _ } as t -> t
×
2845
    | { value = #Odoc_model.Comment.nestable_block_element; _ } as n -> n
1,490✔
2846

2847
  and docs ident_map d =
2848
    {
10,524✔
2849
      elements = List.map (block_element ident_map) d.elements;
10,524✔
2850
      warnings_tag = d.warnings_tag;
2851
    }
2852

2853
  and docs_or_stop ident_map = function
2854
    | `Docs d -> `Docs (docs ident_map d)
426✔
2855
    | `Stop -> `Stop
56✔
2856
end
2857

2858
let module_of_functor_argument (arg : FunctorParameter.parameter) =
2859
  {
3✔
2860
    Module.source_loc = None;
2861
    doc = { elements = []; warnings_tag = None };
2862
    type_ = ModuleType arg.expr;
2863
    canonical = None;
2864
    hidden = false;
2865
  }
2866

2867
(** This is equivalent to {!Lang.extract_signature_doc}. *)
2868
let extract_signature_doc (s : Signature.t) =
2869
  match (s.doc, s.items) with
24✔
2870
  | { elements = []; _ }, Include { expansion_; status = `Inline; _ } :: _ ->
1✔
2871
      expansion_.doc
2872
  | doc, _ -> doc
23✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc