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

ocaml / odoc / 2168

10 Jul 2024 02:38PM UTC coverage: 71.437% (-0.4%) from 71.864%
2168

Pull #1142

github

web-flow
Merge 9bc2c3b35 into de54ed266
Pull Request #1142: Parsing of path-references to pages and modules

68 of 127 new or added lines in 6 files covered. (53.54%)

700 existing lines in 17 files now uncovered.

9794 of 13710 relevant lines covered (71.44%)

3534.91 hits per line

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

50.6
/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)
1,859✔
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)
938✔
13
end)
14

15
module PathModuleMap = Map.Make (struct
16
  type t = Ident.path_module
17

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

21
module ModuleTypeMap = Map.Make (struct
22
  type t = Ident.module_type
23

24
  let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
3,521✔
25
end)
26

27
module PathTypeMap = Map.Make (struct
28
  type t = Ident.path_type
29

30
  let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
2,157✔
31
end)
32

33
module PathValueMap = Map.Make (struct
34
  type t = Ident.path_value
35

36
  let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
×
37
end)
38

39
module PathClassTypeMap = Map.Make (struct
40
  type t = Ident.path_class_type
41

42
  let compare a b = Ident.compare (a :> Ident.any) (b :> Ident.any)
14✔
43
end)
44

45
module IdentMap = Map.Make (struct
46
  type t = Ident.any
47

48
  let compare = Ident.compare
49
end)
50

51
module Delayed = struct
52
  let eager = ref false
53

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

56
  let get : 'a t -> 'a =
57
   fun x ->
58
    match (x.v, x.get) with
77,647✔
59
    | Some x, _ -> x
71,445✔
60
    | None, Some get ->
6,202✔
61
        let v = get () in
62
        x.v <- Some v;
6,202✔
63
        x.get <- None;
64
        v
65
    | _, _ -> failwith "bad delayed"
×
66

67
  let put : (unit -> 'a) -> 'a t =
68
   fun f ->
69
    if !eager then { v = Some (f ()); get = None }
×
70
    else { v = None; get = Some f }
317,242✔
71

72
  let put_val : 'a -> 'a t = fun v -> { v = Some v; get = None }
1,614✔
73
end
74

75
module Opt = struct
76
  let map f = function Some x -> Some (f x) | None -> None
34,608✔
77
end
78

79
module rec Module : sig
80
  type decl =
81
    | Alias of Cpath.module_ * ModuleType.simple_expansion option
82
    | ModuleType of ModuleType.expr
83

84
  type t = {
85
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
86
    doc : CComment.docs;
87
    type_ : decl;
88
    canonical : Odoc_model.Paths.Path.Module.t option;
89
    hidden : bool;
90
  }
91
end =
92
  Module
93

94
and ModuleSubstitution : sig
95
  type t = { doc : CComment.docs; manifest : Cpath.module_ }
96
end =
97
  ModuleSubstitution
98

99
and ModuleTypeSubstitution : sig
100
  type t = { doc : CComment.docs; manifest : ModuleType.expr }
101
end =
102
  ModuleTypeSubstitution
103

104
and TypeExpr : sig
105
  module Polymorphic_variant : sig
106
    type kind = Odoc_model.Lang.TypeExpr.Polymorphic_variant.kind
107

108
    module Constructor : sig
109
      type t = {
110
        name : string;
111
        constant : bool;
112
        arguments : TypeExpr.t list;
113
        doc : CComment.docs;
114
      }
115
    end
116

117
    type element = Type of TypeExpr.t | Constructor of Constructor.t
118

119
    type t = { kind : kind; elements : element list }
120
  end
121

122
  module Object : sig
123
    type method_ = { name : string; type_ : TypeExpr.t }
124

125
    type field = Method of method_ | Inherit of TypeExpr.t
126

127
    type t = { fields : field list; open_ : bool }
128
  end
129

130
  module Package : sig
131
    type substitution = Cfrag.type_ * TypeExpr.t
132

133
    type t = { path : Cpath.module_type; substitutions : substitution list }
134
  end
135

136
  type label = Odoc_model.Lang.TypeExpr.label
137

138
  type t =
139
    | Var of string
140
    | Any
141
    | Alias of t * string
142
    | Arrow of label option * t * t
143
    | Tuple of t list
144
    | Constr of Cpath.type_ * t list
145
    | Polymorphic_variant of TypeExpr.Polymorphic_variant.t
146
    | Object of TypeExpr.Object.t
147
    | Class of Cpath.class_type * t list
148
    | Poly of string list * t
149
    | Package of TypeExpr.Package.t
150
end =
151
  TypeExpr
152

153
and Extension : sig
154
  module Constructor : sig
155
    type t = {
156
      name : string;
157
      source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
158
      doc : CComment.docs;
159
      args : TypeDecl.Constructor.argument;
160
      res : TypeExpr.t option;
161
    }
162
  end
163

164
  type t = {
165
    type_path : Cpath.type_;
166
    doc : CComment.docs;
167
    type_params : TypeDecl.param list;
168
    private_ : bool;
169
    constructors : Constructor.t list;
170
  }
171
end =
172
  Extension
173

174
and Exception : sig
175
  type t = {
176
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
177
    doc : CComment.docs;
178
    args : TypeDecl.Constructor.argument;
179
    res : TypeExpr.t option;
180
  }
181
end =
182
  Exception
183

184
and FunctorParameter : sig
185
  type parameter = { id : Ident.functor_parameter; expr : ModuleType.expr }
186

187
  type t = Named of parameter | Unit
188
end =
189
  FunctorParameter
190

191
and ModuleType : sig
192
  type substitution =
193
    | ModuleEq of Cfrag.module_ * Module.decl
194
    | ModuleSubst of Cfrag.module_ * Cpath.module_
195
    | ModuleTypeEq of Cfrag.module_type * ModuleType.expr
196
    | ModuleTypeSubst of Cfrag.module_type * ModuleType.expr
197
    | TypeEq of Cfrag.type_ * TypeDecl.Equation.t
198
    | TypeSubst of Cfrag.type_ * TypeDecl.Equation.t
199

200
  type type_of_desc =
201
    | ModPath of Cpath.module_
202
    | StructInclude of Cpath.module_
203

204
  type simple_expansion =
205
    | Signature of Signature.t
206
    | Functor of FunctorParameter.t * simple_expansion
207

208
  type typeof_t = {
209
    t_desc : type_of_desc;
210
    t_original_path : Cpath.module_;
211
    t_expansion : simple_expansion option;
212
  }
213

214
  module U : sig
215
    type expr =
216
      | Path of Cpath.module_type
217
      | Signature of Signature.t
218
      | With of substitution list * expr
219
      | TypeOf of type_of_desc * Cpath.module_
220
  end
221

222
  type path_t = {
223
    p_expansion : simple_expansion option;
224
    p_path : Cpath.module_type;
225
  }
226

227
  type with_t = {
228
    w_substitutions : substitution list;
229
    w_expansion : simple_expansion option;
230
    w_expr : U.expr;
231
  }
232

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

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

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

259
  module Constructor : sig
260
    type argument = Tuple of TypeExpr.t list | Record of Field.t list
261

262
    type t = {
263
      name : string;
264
      doc : CComment.docs;
265
      args : argument;
266
      res : TypeExpr.t option;
267
    }
268
  end
269

270
  module Representation : sig
271
    type t =
272
      | Variant of Constructor.t list
273
      | Record of Field.t list
274
      | Extensible
275
  end
276

277
  type param = Odoc_model.Lang.TypeDecl.param
278

279
  module Equation : sig
280
    type t = {
281
      params : param list;
282
      private_ : bool;
283
      manifest : TypeExpr.t option;
284
      constraints : (TypeExpr.t * TypeExpr.t) list;
285
    }
286
  end
287

288
  type t = {
289
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
290
    doc : CComment.docs;
291
    canonical : Odoc_model.Paths.Path.Type.t option;
292
    equation : Equation.t;
293
    representation : Representation.t option;
294
  }
295
end =
296
  TypeDecl
297

298
and Value : sig
299
  type value = Odoc_model.Lang.Value.value
300

301
  type t = {
302
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
303
    doc : CComment.docs;
304
    type_ : TypeExpr.t;
305
    value : value;
306
  }
307
end =
308
  Value
309

310
and Signature : sig
311
  type recursive = Odoc_model.Lang.Signature.recursive
312

313
  type item =
314
    | Module of Ident.module_ * recursive * Module.t Delayed.t
315
    | ModuleSubstitution of Ident.module_ * ModuleSubstitution.t
316
    | ModuleType of Ident.module_type * ModuleType.t Delayed.t
317
    | ModuleTypeSubstitution of Ident.module_type * ModuleTypeSubstitution.t
318
    | Type of Ident.type_ * recursive * TypeDecl.t Delayed.t
319
    | TypeSubstitution of Ident.type_ * TypeDecl.t
320
    | Exception of Ident.exception_ * Exception.t
321
    | TypExt of Extension.t
322
    | Value of Ident.value * Value.t Delayed.t
323
    | Class of Ident.class_ * recursive * Class.t
324
    | ClassType of Ident.class_type * recursive * ClassType.t
325
    | Include of Include.t
326
    | Open of Open.t
327
    | Comment of CComment.docs_or_stop
328

329
  (* When doing destructive substitution we keep track of the items that have been removed,
330
       and the path they've been substituted with *)
331
  type removed_item =
332
    | RModule of Odoc_model.Names.ModuleName.t * Cpath.module_
333
    | RType of Odoc_model.Names.TypeName.t * TypeExpr.t * TypeDecl.Equation.t
334
        (** [RType (_, texpr, eq)], [eq.manifest = Some texpr] *)
335
    | RModuleType of Odoc_model.Names.ModuleTypeName.t * ModuleType.expr
336

337
  type t = {
338
    items : item list;
339
    compiled : bool;
340
    removed : removed_item list;
341
    doc : CComment.docs;
342
  }
343
end =
344
  Signature
345

346
and Open : sig
347
  type t = { expansion : Signature.t; doc : CComment.docs }
348
end =
349
  Open
350

351
and Include : sig
352
  type decl = Alias of Cpath.module_ | ModuleType of ModuleType.U.expr
353

354
  type t = {
355
    parent : Odoc_model.Paths.Identifier.Signature.t;
356
    strengthened : Cpath.module_ option;
357
    doc : CComment.docs;
358
    status : [ `Default | `Inline | `Closed | `Open ];
359
    shadowed : Odoc_model.Lang.Include.shadowed;
360
    expansion_ : Signature.t;
361
    decl : decl;
362
    loc : Odoc_model.Location_.span;
363
  }
364
end =
365
  Include
366

367
and Class : sig
368
  type decl =
369
    | ClassType of ClassType.expr
370
    | Arrow of TypeExpr.label option * TypeExpr.t * decl
371

372
  type t = {
373
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
374
    doc : CComment.docs;
375
    virtual_ : bool;
376
    params : TypeDecl.param list;
377
    type_ : decl;
378
    expansion : ClassSignature.t option;
379
  }
380
end =
381
  Class
382

383
and ClassType : sig
384
  type expr =
385
    | Constr of Cpath.class_type * TypeExpr.t list
386
    | Signature of ClassSignature.t
387

388
  type t = {
389
    source_loc : Odoc_model.Paths.Identifier.SourceLocation.t option;
390
    doc : CComment.docs;
391
    virtual_ : bool;
392
    params : TypeDecl.param list;
393
    expr : expr;
394
    expansion : ClassSignature.t option;
395
  }
396
end =
397
  ClassType
398

399
and ClassSignature : sig
400
  module Constraint : sig
401
    type t = { left : TypeExpr.t; right : TypeExpr.t; doc : CComment.docs }
402
  end
403

404
  module Inherit : sig
405
    type t = { expr : ClassType.expr; doc : CComment.docs }
406
  end
407

408
  type item =
409
    | Method of Ident.method_ * Method.t
410
    | InstanceVariable of Ident.instance_variable * InstanceVariable.t
411
    | Constraint of Constraint.t
412
    | Inherit of Inherit.t
413
    | Comment of CComment.docs_or_stop
414

415
  type t = { self : TypeExpr.t option; items : item list; doc : CComment.docs }
416
end =
417
  ClassSignature
418

419
and Method : sig
420
  type t = {
421
    doc : CComment.docs;
422
    private_ : bool;
423
    virtual_ : bool;
424
    type_ : TypeExpr.t;
425
  }
426
end =
427
  Method
428

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

439
and Substitution : sig
440
  type subst_module =
441
    [ `Prefixed of Cpath.module_ * Cpath.Resolved.module_
442
    | `Substituted
443
    | `Renamed of Ident.path_module ]
444

445
  type subst_module_type =
446
    [ `Prefixed of Cpath.module_type * Cpath.Resolved.module_type
447
    | `Renamed of Ident.module_type ]
448

449
  type subst_type =
450
    [ `Prefixed of Cpath.type_ * Cpath.Resolved.type_
451
    | `Renamed of Ident.path_type ]
452

453
  type subst_class_type =
454
    [ `Prefixed of Cpath.class_type * Cpath.Resolved.class_type
455
    | `Renamed of Ident.path_class_type ]
456

457
  type t = {
458
    module_ : subst_module PathModuleMap.t;
459
    module_type : subst_module_type ModuleTypeMap.t;
460
    type_ : subst_type PathTypeMap.t;
461
    class_type : subst_class_type PathClassTypeMap.t;
462
    type_replacement : (TypeExpr.t * TypeDecl.Equation.t) PathTypeMap.t;
463
    module_type_replacement : ModuleType.expr ModuleTypeMap.t;
464
    path_invalidating_modules : Ident.path_module list;
465
    unresolve_opaque_paths : bool;
466
  }
467
end =
468
  Substitution
469

470
and CComment : sig
471
  type block_element =
472
    [ Odoc_model.Comment.nestable_block_element
473
    | `Heading of Label.t
474
    | `Tag of Odoc_model.Comment.tag ]
475

476
  type docs = block_element Odoc_model.Comment.with_location list
477

478
  type docs_or_stop = [ `Docs of docs | `Stop ]
479
end =
480
  CComment
481

482
and Label : sig
483
  type t = {
484
    attrs : Odoc_model.Comment.heading_attrs;
485
    label : Ident.label;
486
    text : Odoc_model.Comment.paragraph;
487
    location : Odoc_model.Location_.span;
488
  }
489
end =
490
  Label
491

492
module Element = struct
493
  open Odoc_model.Paths
494

495
  type module_ = [ `Module of Identifier.Path.Module.t * Module.t Delayed.t ]
496

497
  type module_type = [ `ModuleType of Identifier.ModuleType.t * ModuleType.t ]
498

499
  type datatype = [ `Type of Identifier.Type.t * TypeDecl.t ]
500

501
  type value = [ `Value of Identifier.Value.t * Value.t ]
502

503
  type label = [ `Label of Identifier.Label.t * Label.t ]
504

505
  type class_ = [ `Class of Identifier.Class.t * Class.t ]
506

507
  type class_type = [ `ClassType of Identifier.ClassType.t * ClassType.t ]
508

509
  type type_ = [ datatype | class_ | class_type ]
510

511
  type signature = [ module_ | module_type ]
512

513
  type constructor =
514
    [ `Constructor of Identifier.Constructor.t * TypeDecl.Constructor.t ]
515

516
  type exception_ = [ `Exception of Identifier.Exception.t * Exception.t ]
517

518
  type extension =
519
    [ `Extension of
520
      Identifier.Extension.t * Extension.Constructor.t * Extension.t ]
521

522
  type extension_decl =
523
    [ `ExtensionDecl of Identifier.Extension.t * Extension.Constructor.t ]
524

525
  type field = [ `Field of Identifier.Field.t * TypeDecl.Field.t ]
526

527
  (* No component for pages yet *)
528
  type page = [ `Page of Identifier.Page.t * Odoc_model.Lang.Page.t ]
529

530
  type label_parent = [ signature | type_ | page ]
531

532
  type fragment_type_parent = [ signature | datatype ]
533

534
  type any =
535
    [ signature
536
    | value
537
    | datatype
538
    | label
539
    | class_
540
    | class_type
541
    | constructor
542
    | exception_
543
    | extension
544
    | extension_decl
545
    | field
546
    | page ]
547

548
  let identifier : [< any ] -> Odoc_model.Paths.Identifier.t =
549
    let open Odoc_model.Paths.Identifier in
550
    function
551
    | `Module (id, _) -> (id :> t)
×
552
    | `ModuleType (id, _) -> (id :> t)
×
553
    | `Type (id, _) -> (id :> t)
×
554
    | `ClassType (id, _) -> (id :> t)
×
555
    | `Class (id, _) -> (id :> t)
×
556
    | `Value (id, _) -> (id :> t)
×
557
    | `Label (id, _) -> (id :> t)
×
558
    | `Constructor (id, _) -> (id :> t)
×
559
    | `Exception (id, _) -> (id :> t)
×
560
    | `Field (id, _) -> (id :> t)
×
561
    | `Extension (id, _, _) -> (id :> t)
×
562
    | `ExtensionDecl (id, _) -> (id :> t)
×
563
    | `Page (id, _) -> (id :> t)
×
564
end
565

566
module Fmt = struct
567
  type config = {
568
    short_paths : bool;
569
    show_canonical : bool;
570
    show_removed : bool;
571
    show_expansions : bool;
572
    show_include_expansions : bool;
573
  }
574

575
  let default =
576
    {
577
      short_paths = false;
578
      show_canonical = true;
579
      show_removed = true;
580
      show_expansions = true;
581
      show_include_expansions = true;
582
    }
583

584
  type id = Odoc_model.Paths.Identifier.t
585
  type path = Odoc_model.Paths.Path.t
586
  type rpath = Odoc_model.Paths.Path.Resolved.t
587
  open Odoc_model.Names
588
  open Odoc_model.Paths
589

590
  let fpf = Format.fprintf
591

592
  let fpp_opt (c : config) fmt pp_a ppf = function
593
    | Some t -> fpf ppf fmt (pp_a c) t
16✔
594
    | None -> ()
27✔
595

596
  let fpp_list fmt_sep fmt_outer pp_a ppf t =
597
    let pp_sep ppf () = fpf ppf fmt_sep in
×
598
    match t with
599
    | [] -> ()
×
600
    | t -> fpf ppf fmt_outer (Format.pp_print_list ~pp_sep pp_a) t
×
601

602
  (* Three helper functions to help with paths. Generally paths
603
     have constructors of the form [`Hidden(p1)] or
604
     [`Alias(p1,p2)]. When printing these paths, if we're printing a
605
     short path we often want to just ignore the constructor and print
606
     one of the inner paths, [p1] or [p2]. These functions do that. If
607
     [short_paths] is set in the config, we skip to one of the inner
608
     paths - in [wrap] there's no choice, but in [wrap2] we pick [p1]
609
     and in [wrap2r] we pick [p2]. If [short_paths] is not set, we
610
     print a string representing the constructor, and one or both paths
611
     with brackets. *)
612
  let wrap :
613
      type a.
614
      config ->
615
      string ->
616
      (config -> Format.formatter -> a -> unit) ->
617
      Format.formatter ->
618
      a ->
619
      unit =
620
   fun c txt fn ppf x ->
621
    if c.short_paths then Format.fprintf ppf "%a" (fn c) x
150✔
622
    else Format.fprintf ppf "%s(%a)" txt (fn c) x
×
623

624
  let wrap2 :
625
      type a b.
626
      config ->
627
      string ->
628
      (config -> Format.formatter -> a -> unit) ->
629
      (config -> Format.formatter -> b -> unit) ->
630
      Format.formatter ->
631
      a ->
632
      b ->
633
      unit =
634
   fun c txt fn1 fn2 ppf x y ->
635
    if c.short_paths then Format.fprintf ppf "%a" (fn1 c) x
6✔
636
    else Format.fprintf ppf "%s(%a,%a)" txt (fn1 c) x (fn2 c) y
×
637

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

652
  let str : config -> Format.formatter -> string -> unit =
653
   fun _ ppf s -> Format.fprintf ppf "%s" s
×
654

655
  let bool : config -> Format.formatter -> bool -> unit =
656
   fun _ ppf b -> Format.fprintf ppf "%b" b
×
657

658
  let ident_fmt : config -> Format.formatter -> [< Ident.any ] -> unit =
659
   fun c ppf i ->
660
    if c.short_paths then Ident.short_fmt ppf i else Ident.fmt ppf i
×
661

662
  let rec model_identifier c ppf (p : id) =
663
    match p.iv with
102✔
664
    | `Root (_, unit_name) ->
48✔
665
        wrap c "root" (fun _ -> ModuleName.fmt) ppf unit_name
48✔
666
    | `Module (parent, name) ->
13✔
667
        Format.fprintf ppf "%a.%s" (model_identifier c)
13✔
668
          (parent :> id)
669
          (ModuleName.to_string name)
13✔
670
    | `ModuleType (parent, name) ->
15✔
671
        Format.fprintf ppf "%a.%s" (model_identifier c)
15✔
672
          (parent :> id)
673
          (ModuleTypeName.to_string name)
15✔
674
    | `Type (parent, name) ->
8✔
675
        Format.fprintf ppf "%a.%s" (model_identifier c)
8✔
676
          (parent :> id)
677
          (TypeName.to_string name)
8✔
678
    | `Parameter (parent, name) ->
×
679
        Format.fprintf ppf "(param %a %s)" (model_identifier c)
×
680
          (parent :> id)
681
          (ModuleName.to_string name)
×
682
    | `Result parent ->
×
683
        if c.short_paths then model_identifier c ppf (parent :> id)
×
684
        else Format.fprintf ppf "%a.result" (model_identifier c) (parent :> id)
×
685
    | `CoreType name -> Format.fprintf ppf "%s" (TypeName.to_string name)
18✔
686
    | `Constructor (ty, x) ->
×
687
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
688
          (ty :> id)
689
          (ConstructorName.to_string x)
×
690
    | `Value (parent, name) ->
×
691
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
692
          (parent :> id)
693
          (ValueName.to_string name)
×
694
    | `CoreException name ->
×
695
        Format.fprintf ppf "%s" (ExceptionName.to_string name)
×
696
    | `Class (sg, name) ->
×
697
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
698
          (sg :> id)
699
          (ClassName.to_string name)
×
700
    | `ClassType (sg, name) ->
×
701
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
702
          (sg :> id)
703
          (ClassTypeName.to_string name)
×
704
    | `InstanceVariable (sg, name) ->
×
705
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
706
          (sg :> id)
707
          (InstanceVariableName.to_string name)
×
708
    | `Method (sg, name) ->
×
709
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
710
          (sg :> id)
711
          (MethodName.to_string name)
×
712
    | `Label (parent, name) ->
×
713
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
714
          (parent :> id)
715
          (LabelName.to_string name)
×
716
    | `Field (ty, name) ->
×
717
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
718
          (ty :> id)
719
          (FieldName.to_string name)
×
720
    | `Exception (p, name) ->
×
721
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
722
          (p :> id)
723
          (ExceptionName.to_string name)
×
724
    | `Extension (p, name) ->
×
725
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
726
          (p :> id)
727
          (ExtensionName.to_string name)
×
728
    | `ExtensionDecl (p, _, name) ->
×
729
        Format.fprintf ppf "%a.%s" (model_identifier c)
×
730
          (p :> id)
731
          (ExtensionName.to_string name)
×
732
    | `Page (_, name) | `LeafPage (_, name) ->
×
733
        Format.fprintf ppf "%s" (PageName.to_string name)
×
734
    | `SourcePage (p, name) | `SourceDir (p, name) ->
×
735
        Format.fprintf ppf "%a/%s" (model_identifier c) (p :> id) name
×
736
    | `SourceLocation (p, def) ->
×
737
        Format.fprintf ppf "%a#%s" (model_identifier c)
×
738
          (p :> id)
739
          (DefName.to_string def)
×
740
    | `SourceLocationInternal (p, def) ->
×
741
        Format.fprintf ppf "%a#%s" (model_identifier c)
×
742
          (p :> id)
743
          (LocalName.to_string def)
×
744
    | `SourceLocationMod p ->
×
745
        Format.fprintf ppf "%a#" (model_identifier c) (p :> id)
×
746
    | `AssetFile (p, name) ->
×
747
        Format.fprintf ppf "%a/%s" (model_identifier c) (p :> id) name
×
748

749
  let rec signature : config -> Format.formatter -> Signature.t -> unit =
750
   fun c ppf sg ->
751
    let open Signature in
83✔
752
    let ident_fmt = if c.short_paths then Ident.short_fmt else Ident.fmt in
×
753
    let sig_item ppf = function
754
      | Module (id, _, m) ->
45✔
755
          Format.fprintf ppf "@[<hov 2>module %a %a@]" ident_fmt id (module_ c)
45✔
756
            (Delayed.get m)
45✔
757
      | ModuleSubstitution (id, m) ->
×
758
          Format.fprintf ppf "@[<v 2>module %a := %a@]" ident_fmt id
759
            (module_path c) m.ModuleSubstitution.manifest
×
760
      | ModuleType (id, mt) ->
15✔
761
          Format.fprintf ppf "@[<hov 2>module type %a %a@]" ident_fmt id
762
            (module_type c) (Delayed.get mt)
15✔
763
      | ModuleTypeSubstitution (id, mts) ->
×
764
          Format.fprintf ppf "@[<v 2>module type %a := %a@]" ident_fmt id
765
            (module_type_expr c) mts.ModuleTypeSubstitution.manifest
×
766
      | Type (id, _, t) ->
41✔
767
          Format.fprintf ppf "@[<v 2>type %a%a@]" ident_fmt id (type_decl c)
41✔
768
            (Delayed.get t)
41✔
769
      | TypeSubstitution (id, t) ->
×
770
          Format.fprintf ppf "@[<v 2>type %a :=%a@]" ident_fmt id (type_decl c)
×
771
            t
772
      | Exception (id, e) ->
×
773
          Format.fprintf ppf "@[<v 2>exception %a %a@]" ident_fmt id
774
            (exception_ c) e
×
775
      | TypExt e ->
×
776
          Format.fprintf ppf "@[<v 2>type_extension %a@]" (extension c) e
×
777
      | Value (id, v) ->
11✔
778
          Format.fprintf ppf "@[<v 2>val %a %a@]" ident_fmt id (value c)
11✔
779
            (Delayed.get v)
11✔
780
      | Class (id, _, cls) ->
×
781
          Format.fprintf ppf "@[<v 2>class %a %a@]" ident_fmt id (class_ c) cls
×
782
      | ClassType (id, _, cty) ->
×
783
          Format.fprintf ppf "@[<v 2>class type %a %a@]" ident_fmt id
784
            (class_type c) cty
×
785
      | Include i -> Format.fprintf ppf "@[<hov 2>include %a@]" (include_ c) i
16✔
786
      | Open o -> Format.fprintf ppf "open [ %a ]" (signature c) o.expansion
1✔
787
      | Comment _c -> ()
4✔
788
    in
789
    let rec inner ppf = function
790
      | [ x ] -> sig_item ppf x
79✔
791
      | x :: xs -> Format.fprintf ppf "%a@ %a" sig_item x inner xs
54✔
792
      | [] -> ()
4✔
793
    in
794
    let removed_fmt ppf removed =
795
      match (c.show_removed, removed) with
83✔
796
      | false, _ | _, [] -> ()
×
797
      | true, items ->
×
798
          Format.fprintf ppf "@ (removed=%a)" (removed_item_list c) items
×
799
    in
800
    Format.fprintf ppf "%a%a" inner sg.items removed_fmt sg.removed
801

802
  and option :
803
      type a.
804
      config ->
805
      (config -> Format.formatter -> a -> unit) ->
806
      Format.formatter ->
807
      a option ->
808
      unit =
809
   fun c pp ppf x ->
810
    match x with
×
811
    | Some x -> Format.fprintf ppf "Some(%a)" (pp c) x
×
812
    | None -> Format.fprintf ppf "None"
×
813

814
  and class_signature c ppf sg =
815
    let open ClassSignature in
×
816
    Format.fprintf ppf "@[<v>self=%a@," (option c type_expr) sg.self;
×
817
    List.iter
×
818
      (function
819
        | Method (id, m) ->
×
820
            Format.fprintf ppf "@[<v 2>method %a : %a@]@," Ident.fmt id
821
              (method_ c) m
×
822
        | InstanceVariable (id, i) ->
×
823
            Format.fprintf ppf "@[<v 2>instance variable %a : %a@]@," Ident.fmt
824
              id (instance_variable c) i
×
825
        | Constraint cst ->
×
826
            Format.fprintf ppf "@[<v 2>constraint %a = %a@]@," (type_expr c)
×
827
              cst.Constraint.left (type_expr c) cst.right
×
828
        | Inherit i ->
×
829
            Format.fprintf ppf "@[<v 2>inherit %a" (class_type_expr c)
×
830
              i.Inherit.expr
831
        | Comment _ -> ())
×
832
      sg.items
833

834
  and method_ c ppf m =
835
    let open Method in
×
836
    Format.fprintf ppf "%s%s%a"
837
      (if m.private_ then "private " else "")
×
838
      (if m.virtual_ then "virtual " else "")
×
839
      (type_expr c) m.type_
×
840

841
  and instance_variable c ppf i =
842
    let open InstanceVariable in
×
843
    Format.fprintf ppf "%s%s%a"
844
      (if i.mutable_ then "mutable " else "")
×
845
      (if i.virtual_ then "virtual " else "")
×
846
      (type_expr c) i.type_
×
847

848
  and list c pp ppf ls =
849
    match ls with
×
850
    | x :: y :: rest ->
×
851
        Format.fprintf ppf "%a, %a" (pp c) x (list c pp) (y :: rest)
×
852
    | [ x ] -> Format.fprintf ppf "%a" (pp c) x
×
853
    | [] -> ()
×
854

855
  and class_type_expr c ppf cty =
856
    let open ClassType in
×
857
    match cty with
858
    | Constr (p, ts) ->
×
859
        Format.fprintf ppf "constr(%a,%a)" (class_type_path c) p
×
860
          (list c type_expr) ts
×
861
    | Signature sg -> Format.fprintf ppf "(%a)" (class_signature c) sg
×
862

863
  and removed_item c ppf r =
864
    let open Signature in
×
865
    match r with
866
    | RModule (id, path) ->
×
867
        Format.fprintf ppf "module %a (%a)" ModuleName.fmt id (module_path c)
×
868
          path
869
    | RType (id, texpr, eq) ->
×
870
        Format.fprintf ppf "type %a %a = (%a)" type_params eq.params
871
          TypeName.fmt id (type_expr c) texpr
×
872
    | RModuleType (id, mty) ->
×
873
        Format.fprintf ppf "module type %a = %a" ModuleTypeName.fmt id
874
          (module_type_expr c) mty
×
875

876
  and removed_item_list c ppf r =
877
    match r with
×
878
    | [] -> ()
×
879
    | [ x ] -> Format.fprintf ppf "%a" (removed_item c) x
×
880
    | x :: ys ->
×
881
        Format.fprintf ppf "%a;%a" (removed_item c) x (removed_item_list c) ys
×
882

883
  and class_decl c ppf cls =
884
    let open Class in
×
885
    match cls with
886
    | ClassType cty -> Format.fprintf ppf "%a" (class_type_expr c) cty
×
887
    | Arrow (lbl, ty, decl) ->
×
888
        Format.fprintf ppf "%a%a -> %a" type_expr_label lbl (type_expr c) ty
×
889
          (class_decl c) decl
×
890

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

893
  and class_type _c ppf _ = Format.fprintf ppf "<todo>"
×
894

895
  and include_ c ppf i =
896
    Format.fprintf ppf "%a@ %a" (include_decl c) i.decl
16✔
897
      (simple_expansion c true)
16✔
898
      (ModuleType.Signature i.expansion_ : ModuleType.simple_expansion)
899

900
  and include_decl c ppf =
901
    let open Include in
16✔
902
    function
903
    | Alias p -> Format.fprintf ppf "%a" (module_path c) p
×
904
    | ModuleType mt -> Format.fprintf ppf "%a" (u_module_type_expr c) mt
16✔
905

906
  and value c ppf v =
907
    let open Value in
11✔
908
    Format.fprintf ppf ": %a" (type_expr c) v.type_
11✔
909

910
  and module_decl c ppf d =
911
    let open Module in
45✔
912
    match d with
913
    | Alias (p, Some e) ->
3✔
914
        Format.fprintf ppf "=@ %a@ %a" (module_path c) p
3✔
915
          (simple_expansion c false) e
3✔
916
    | Alias (p, None) -> Format.fprintf ppf "=@ %a" (module_path c) p
9✔
917
    | ModuleType mt ->
33✔
918
        Format.fprintf ppf ": %a%a" (module_type_expr c) mt
33✔
919
          (module_type_expansion c) mt
33✔
920

921
  and module_ c ppf m =
922
    let fmt_canonical ppf popt =
45✔
923
      if c.show_canonical then
45✔
924
        Format.fprintf ppf "@ (canonical=%a)" (option c model_path) popt
×
925
      else ()
45✔
926
    in
927
    Format.fprintf ppf "%a%a" (module_decl c) m.type_ fmt_canonical
45✔
928
      (m.canonical :> path option)
929

930
  and simple_expansion c is_include ppf (m : ModuleType.simple_expansion) =
931
    if c.show_expansions || (is_include && c.show_include_expansions) then
14✔
932
      match m with
42✔
933
      | ModuleType.Signature sg ->
40✔
934
          Format.fprintf ppf "@[<hv 2>(sig :@ %a@;<1 -1>end@])" (signature c) sg
40✔
935
      | Functor (arg, sg) ->
2✔
936
          Format.fprintf ppf "(functor: (%a) -> %a)" (functor_parameter c) arg
2✔
937
            (simple_expansion c is_include)
2✔
938
            sg
939
    else ()
×
940

941
  and module_type c ppf mt =
942
    match mt.expr with
23✔
943
    | Some x ->
23✔
944
        Format.fprintf ppf "= %a%a" (module_type_expr c) x
23✔
945
          (module_type_expansion c) x
23✔
946
    | None -> ()
×
947

948
  and module_type_type_of_desc c ppf t =
949
    match t with
4✔
950
    | ModuleType.ModPath p ->
×
951
        Format.fprintf ppf "module type of %a" (module_path c) p
×
952
    | StructInclude p ->
4✔
953
        Format.fprintf ppf "module type of struct include %a end"
954
          (module_path c) p
4✔
955

956
  and u_module_type_expr c ppf mt =
957
    let open ModuleType.U in
25✔
958
    match mt with
959
    | Path p -> module_type_path c ppf p
15✔
960
    | Signature sg -> Format.fprintf ppf "sig@,@[<v 2>%a@]end" (signature c) sg
2✔
961
    | With (subs, e) ->
4✔
962
        Format.fprintf ppf "%a with [%a]" (u_module_type_expr c) e
4✔
963
          (substitution_list c) subs
4✔
964
    | TypeOf (t_desc, _) -> module_type_type_of_desc c ppf t_desc
4✔
965

966
  and module_type_expr c ppf mt =
967
    let open ModuleType in
60✔
968
    match mt with
969
    | Path { p_path; _ } -> module_type_path c ppf p_path
7✔
970
    | Signature sg ->
34✔
971
        Format.fprintf ppf "@,@[<hv 2>sig@ %a@;<1 -2>end@]" (signature c) sg
34✔
972
    | With { w_substitutions = subs; w_expr; _ } ->
5✔
973
        Format.fprintf ppf "%a with @[<hov 2>%a@]" (u_module_type_expr c) w_expr
5✔
974
          (substitution_list c) subs
5✔
975
    | Functor (arg, res) ->
1✔
976
        Format.fprintf ppf "(%a) -> %a" (functor_parameter c) arg
1✔
977
          (module_type_expr c) res
1✔
978
    | TypeOf { t_desc = ModPath p; _ } ->
11✔
979
        Format.fprintf ppf "module type of %a" (module_path c) p
11✔
980
    | TypeOf { t_desc = StructInclude p; _ } ->
2✔
981
        Format.fprintf ppf "module type of struct include %a end"
982
          (module_path c) p
2✔
983

984
  and module_type_expansion c ppf mt =
985
    let open ModuleType in
56✔
986
    match mt with
987
    | Signature _ -> ()
30✔
988
    | Path { p_expansion = Some e; _ }
3✔
989
    | With { w_expansion = Some e; _ }
5✔
990
    | TypeOf { t_expansion = Some e; _ } ->
13✔
991
        Format.fprintf ppf "@ %a" (simple_expansion c false) e
21✔
992
    | _ -> ()
5✔
993

994
  and functor_parameter c ppf x =
995
    let open FunctorParameter in
3✔
996
    match x with
997
    | Unit -> ()
×
998
    | Named x -> Format.fprintf ppf "%a" (functor_parameter_parameter c) x
3✔
999

1000
  and functor_parameter_parameter c ppf x =
1001
    Format.fprintf ppf "%a : %a" Ident.fmt x.FunctorParameter.id
3✔
1002
      (module_type_expr c) x.FunctorParameter.expr
3✔
1003

1004
  and type_decl c ppf t =
1005
    let open TypeDecl in
43✔
1006
    match t.representation with
1007
    | Some repr ->
×
1008
        Format.fprintf ppf "%a = %a"
1009
          (fpp_opt c " : %a" type_expr)
×
1010
          t.equation.Equation.manifest (type_decl_repr c) repr
×
1011
    | None -> (fpp_opt c " = %a" type_expr) ppf t.equation.Equation.manifest
43✔
1012

1013
  and type_decl_repr c ppf =
1014
    let open TypeDecl.Representation in
×
1015
    function
1016
    | Variant cs -> fpp_list " | " "%a" (type_decl_constructor c) ppf cs
×
1017
    | Record fs -> type_decl_fields c ppf fs
×
1018
    | Extensible -> Format.fprintf ppf ".."
×
1019

1020
  and type_decl_constructor c ppf t =
1021
    let open TypeDecl.Constructor in
×
1022
    match t.res with
1023
    | Some res ->
×
1024
        fpf ppf "%s : %a -> %a" t.name
1025
          (type_decl_constructor_arg c)
×
1026
          t.args (type_expr c) res
×
1027
    | None -> fpf ppf "%s of %a" t.name (type_decl_constructor_arg c) t.args
×
1028

1029
  and type_decl_constructor_arg c ppf =
1030
    let open TypeDecl.Constructor in
×
1031
    function
1032
    | Tuple ts -> type_tuple c ppf ts | Record fs -> type_decl_fields c ppf fs
×
1033

1034
  and type_decl_field c ppf t =
1035
    let open TypeDecl.Field in
×
1036
    let mutable_ = if t.mutable_ then "mutable " else "" in
×
1037
    fpf ppf "%s%s : %a" mutable_ t.name (type_expr c) t.type_
×
1038

1039
  and type_decl_fields c ppf fs =
1040
    fpp_list "; " "{ %a }" (type_decl_field c) ppf fs
×
1041

1042
  and type_tuple c ppf ts = fpp_list " * " "%a" (type_expr c) ppf ts
×
1043

1044
  and type_param ppf t =
1045
    let desc =
×
1046
      match t.Odoc_model.Lang.TypeDecl.desc with Any -> "_" | Var n -> n
×
1047
    and variance =
1048
      match t.variance with Some Pos -> "+" | Some Neg -> "-" | None -> ""
×
1049
    and injectivity = if t.injectivity then "!" else "" in
×
1050
    Format.fprintf ppf "%s%s%s" variance injectivity desc
1051

1052
  and type_params ppf ts =
1053
    let pp_sep ppf () = Format.fprintf ppf ", " in
×
1054
    Format.fprintf ppf "(%a)" (Format.pp_print_list ~pp_sep type_param) ts
×
1055

1056
  and type_equation c ppf t =
1057
    match t.TypeDecl.Equation.manifest with
7✔
1058
    | None -> ()
×
1059
    | Some m -> Format.fprintf ppf " = %a" (type_expr c) m
7✔
1060

1061
  and exception_ _c _ppf _e = ()
×
1062

1063
  and extension c ppf e =
1064
    Format.fprintf ppf "%a" (type_path c) e.Extension.type_path
×
1065

1066
  and substitution c ppf t =
1067
    let open ModuleType in
9✔
1068
    match t with
1069
    | ModuleEq (frag, decl) ->
×
1070
        Format.fprintf ppf "%a %a" (module_fragment c) frag (module_decl c) decl
×
1071
    | ModuleSubst (frag, mpath) ->
2✔
1072
        Format.fprintf ppf "%a := %a" (module_fragment c) frag (module_path c)
2✔
1073
          mpath
1074
    | ModuleTypeEq (frag, mty) ->
×
1075
        Format.fprintf ppf "%a = %a" (module_type_fragment c) frag
×
1076
          (module_type_expr c) mty
×
1077
    | ModuleTypeSubst (frag, mty) ->
×
1078
        Format.fprintf ppf "%a := %a" (module_type_fragment c) frag
×
1079
          (module_type_expr c) mty
×
1080
    | TypeEq (frag, decl) ->
3✔
1081
        Format.fprintf ppf "%a%a" (type_fragment c) frag (type_equation c) decl
3✔
1082
    | TypeSubst (frag, decl) ->
4✔
1083
        Format.fprintf ppf "%a%a" (type_fragment c) frag (type_equation c) decl
4✔
1084

1085
  and substitution_list c ppf l =
1086
    match l with
9✔
1087
    | [ sub ] -> Format.fprintf ppf "%a" (substitution c) sub
9✔
1088
    | sub :: subs ->
×
1089
        Format.fprintf ppf "%a; %a" (substitution c) sub (substitution_list c)
×
1090
          subs
1091
    | [] -> ()
×
1092

1093
  and type_expr_label ppf l =
1094
    match l with
×
1095
    | Some (Odoc_model.Lang.TypeExpr.Label l) -> Format.fprintf ppf "%s:" l
×
1096
    | Some (Optional o) -> Format.fprintf ppf "?%s:" o
×
1097
    | None -> ()
×
1098

1099
  and type_expr_list c ppf l =
1100
    match l with
×
1101
    | [ t ] -> Format.fprintf ppf "%a" (type_expr c) t
×
1102
    | t :: ts ->
×
1103
        Format.fprintf ppf "%a * %a" (type_expr c) t (type_expr_list c) ts
×
1104
    | [] -> ()
×
1105

1106
  and type_object _c ppf _o = Format.fprintf ppf "(object)"
×
1107

1108
  and type_class c ppf (x, ys) =
1109
    Format.fprintf ppf "(class %a %a)" (class_type_path c) x (type_expr_list c)
×
1110
      ys
1111

1112
  and type_package _c ppf _p = Format.fprintf ppf "(package)"
×
1113

1114
  and type_expr_polymorphic_variant c ppf p =
1115
    let open TypeExpr.Polymorphic_variant in
×
1116
    let pp_element ppf = function
1117
      | Type t -> type_expr c ppf t
×
1118
      | Constructor cstr ->
×
1119
          fpf ppf "`%s%a" cstr.Constructor.name
1120
            (fpp_list " * " " of %a" (type_expr c))
×
1121
            cstr.arguments
1122
    in
1123
    let pp_elements = fpp_list " | " "%a" pp_element in
1124
    match p.kind with
×
1125
    | Fixed -> fpf ppf "[ %a ]" pp_elements p.elements
×
1126
    | Closed xs ->
×
1127
        fpf ppf "[ %a > %a ]" pp_elements p.elements
1128
          (fpp_list " " "%a" Format.pp_print_string)
×
1129
          xs
1130
    | Open -> fpf ppf "[> %a ]" pp_elements p.elements
×
1131

1132
  and type_expr c ppf e =
1133
    let open TypeExpr in
34✔
1134
    match e with
1135
    | Var x -> Format.fprintf ppf "%s" x
×
1136
    | Any -> Format.fprintf ppf "_"
×
1137
    | Alias (x, y) -> Format.fprintf ppf "(alias %a %s)" (type_expr c) x y
×
1138
    | Arrow (l, t1, t2) ->
×
1139
        Format.fprintf ppf "%a(%a) -> %a" type_expr_label l (type_expr c) t1
×
1140
          (type_expr c) t2
×
1141
    | Tuple ts -> Format.fprintf ppf "(%a)" (type_expr_list c) ts
×
1142
    | Constr (p, args) -> (
34✔
1143
        match args with
1144
        | [] -> Format.fprintf ppf "%a" (type_path c) p
34✔
1145
        | _ ->
×
1146
            Format.fprintf ppf "[%a] %a" (type_expr_list c) args (type_path c) p
×
1147
        )
1148
    | Polymorphic_variant poly ->
×
1149
        Format.fprintf ppf "(poly_var %a)"
1150
          (type_expr_polymorphic_variant c)
×
1151
          poly
1152
    | Object x -> type_object c ppf x
×
1153
    | Class (x, y) -> type_class c ppf (x, y)
×
1154
    | Poly (_ss, _t) -> Format.fprintf ppf "(poly)"
×
1155
    | Package x -> type_package c ppf x
×
1156

1157
  and resolved_module_path :
1158
      config -> Format.formatter -> Cpath.Resolved.module_ -> unit =
1159
   fun c ppf p ->
1160
    match p with
63✔
1161
    | `Local ident -> ident_fmt c ppf ident
10✔
1162
    | `Apply (p1, p2) ->
×
1163
        Format.fprintf ppf "%a(%a)" (resolved_module_path c) p1
×
1164
          (resolved_module_path c) p2
×
1165
    | `Gpath p -> Format.fprintf ppf "%a" (model_resolved_path c) (p :> rpath)
30✔
1166
    | `Substituted p -> wrap c "substituted" resolved_module_path ppf p
×
1167
    | `Module (p, m) ->
9✔
1168
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
9✔
1169
          (ModuleName.to_string m)
9✔
1170
    | `Alias (p1, p2, _) ->
2✔
1171
        wrap2r c "alias" resolved_module_path module_path ppf p1 p2
1172
    | `Subst (p1, p2) ->
×
1173
        wrap2r c "subst" resolved_module_type_path resolved_module_path ppf p1
1174
          p2
1175
    | `Hidden p1 -> wrap c "hidden" resolved_module_path ppf p1
12✔
1176
    | `Canonical (p1, p2) ->
×
1177
        wrap2 c "canonical" resolved_module_path model_path ppf p1 (p2 :> path)
1178
    | `OpaqueModule m -> wrap c "opaquemodule" resolved_module_path ppf m
×
1179

1180
  and module_path : config -> Format.formatter -> Cpath.module_ -> unit =
1181
   fun c ppf p ->
1182
    match p with
33✔
1183
    | `Resolved p -> wrap c "resolved" resolved_module_path ppf p
31✔
1184
    | `Dot (p, str) -> Format.fprintf ppf "%a.%s" (module_path c) p str
×
1185
    | `Module (p, n) ->
×
1186
        Format.fprintf ppf "%a.%a" (resolved_parent_path c) p ModuleName.fmt n
×
1187
    | `Apply (p1, p2) ->
×
1188
        Format.fprintf ppf "%a(%a)" (module_path c) p1 (module_path c) p2
×
1189
    | `Identifier (id, b) ->
×
1190
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1191
    | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b
2✔
1192
    | `Substituted p -> wrap c "substituted" module_path ppf p
×
1193
    | `Forward s -> wrap c "forward" str ppf s
×
1194
    | `Root r -> wrap c "unresolvedroot" str ppf r
×
1195

1196
  and resolved_module_type_path :
1197
      config -> Format.formatter -> Cpath.Resolved.module_type -> unit =
1198
   fun c ppf p ->
1199
    match p with
22✔
1200
    | `Local id -> ident_fmt c ppf id
14✔
1201
    | `Gpath p -> model_resolved_path c ppf (p :> rpath)
2✔
1202
    | `Substituted x -> wrap c "substituted" resolved_module_type_path ppf x
×
1203
    | `ModuleType (p, m) ->
6✔
1204
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
6✔
1205
          (ModuleTypeName.to_string m)
6✔
1206
    | `CanonicalModuleType (m1, m2) ->
×
1207
        wrap2 c "canonicalt" resolved_module_type_path model_path ppf m1
1208
          (m2 :> path)
1209
    | `OpaqueModuleType m ->
×
1210
        wrap c "opaquemoduletype" resolved_module_type_path ppf m
1211
    | `AliasModuleType (mt1, mt2) ->
×
1212
        wrap2 c "aliasmoduletype" resolved_module_type_path
1213
          resolved_module_type_path ppf mt1 mt2
1214
    | `SubstT (mt1, mt2) ->
×
1215
        wrap2 c "substt" resolved_module_type_path resolved_module_type_path ppf
1216
          mt1 mt2
1217

1218
  and module_type_path : config -> Format.formatter -> Cpath.module_type -> unit
1219
      =
1220
   fun c ppf m ->
1221
    match m with
22✔
1222
    | `Resolved p -> wrap c "r" resolved_module_type_path ppf p
22✔
1223
    | `Identifier (id, b) ->
×
1224
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1225
    | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b
×
1226
    | `Substituted s -> wrap c "substituted" module_type_path ppf s
×
1227
    | `Dot (m, s) -> Format.fprintf ppf "%a.%s" (module_path c) m s
×
1228
    | `ModuleType (m, n) ->
×
1229
        Format.fprintf ppf "%a.%a" (resolved_parent_path c) m ModuleTypeName.fmt
×
1230
          n
1231

1232
  and resolved_type_path :
1233
      config -> Format.formatter -> Cpath.Resolved.type_ -> unit =
1234
   fun c ppf p ->
1235
    match p with
30✔
1236
    | `Local id -> ident_fmt c ppf id
7✔
1237
    | `Gpath p -> model_resolved_path c ppf (p :> rpath)
18✔
1238
    | `Substituted x -> wrap c "substituted" resolved_type_path ppf x
×
1239
    | `CanonicalType (t1, t2) ->
×
1240
        wrap2 c "canonicaltype" resolved_type_path model_path ppf t1
1241
          (t2 :> path)
1242
    | `Class (p, t) ->
×
1243
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1244
          (ClassName.to_string t)
×
1245
    | `ClassType (p, t) ->
×
1246
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1247
          (ClassTypeName.to_string t)
×
1248
    | `Type (p, t) ->
5✔
1249
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
5✔
1250
          (TypeName.to_string t)
5✔
1251

1252
  and resolved_value_path :
1253
      config -> Format.formatter -> Cpath.Resolved.value -> unit =
1254
   fun c ppf p ->
1255
    match p with
×
1256
    | `Value (p, t) ->
×
1257
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1258
          (ValueName.to_string t)
×
1259
    | `Gpath p -> Format.fprintf ppf "%a" (model_resolved_path c) (p :> rpath)
×
1260

1261
  and resolved_parent_path :
1262
      config -> Format.formatter -> Cpath.Resolved.parent -> unit =
1263
   fun c ppf p ->
1264
    match p with
20✔
1265
    | `Module m -> resolved_module_path c ppf m
20✔
1266
    | `ModuleType m ->
×
1267
        if c.short_paths then resolved_module_type_path c ppf m
×
1268
        else Format.fprintf ppf ">>%a<<" (resolved_module_type_path c) m
×
1269
    | `FragmentRoot -> Format.fprintf ppf "FragmentRoot"
×
1270

1271
  and type_path : config -> Format.formatter -> Cpath.type_ -> unit =
1272
   fun c ppf p ->
1273
    match p with
34✔
1274
    | `Resolved r -> wrap c "resolved" resolved_type_path ppf r
30✔
1275
    | `Identifier (id, b) ->
×
1276
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1277
    | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b
4✔
1278
    | `Substituted s -> wrap c "substituted" type_path ppf s
×
1279
    | `Dot (m, s) -> Format.fprintf ppf "%a.%s" (module_path c) m s
×
1280
    | `Class (p, t) ->
×
1281
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1282
          (ClassName.to_string t)
×
1283
    | `ClassType (p, t) ->
×
1284
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1285
          (ClassTypeName.to_string t)
×
1286
    | `Type (p, t) ->
×
1287
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1288
          (TypeName.to_string t)
×
1289

1290
  and value_path : config -> Format.formatter -> Cpath.value -> unit =
1291
   fun c ppf p ->
1292
    match p with
×
1293
    | `Resolved r -> wrap c "resolved" resolved_value_path ppf r
×
1294
    | `Dot (m, s) -> Format.fprintf ppf "%a.%s" (module_path c) m s
×
1295
    | `Value (p, t) ->
×
1296
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1297
          (ValueName.to_string t)
×
1298
    | `Identifier (id, b) ->
×
1299
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1300

1301
  and resolved_class_type_path :
1302
      config -> Format.formatter -> Cpath.Resolved.class_type -> unit =
1303
   fun c ppf p ->
1304
    match p with
×
1305
    | `Local id -> Format.fprintf ppf "%a" Ident.fmt id
×
1306
    | `Gpath p -> Format.fprintf ppf "%a" (model_resolved_path c) (p :> rpath)
×
1307
    | `Substituted s -> wrap c "substituted" resolved_class_type_path ppf s
×
1308
    | `Class (p, t) ->
×
1309
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1310
          (ClassName.to_string t)
×
1311
    | `ClassType (p, t) ->
×
1312
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1313
          (ClassTypeName.to_string t)
×
1314

1315
  and class_type_path : config -> Format.formatter -> Cpath.class_type -> unit =
1316
   fun c ppf p ->
1317
    match p with
×
1318
    | `Resolved r -> Format.fprintf ppf "%a" (resolved_class_type_path c) r
×
1319
    | `Identifier (id, b) ->
×
1320
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1321
    | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b
×
1322
    | `Substituted s -> wrap c "substituted" class_type_path ppf s
×
1323
    | `Dot (m, s) -> Format.fprintf ppf "%a.%s" (module_path c) m s
×
1324
    | `Class (p, t) ->
×
1325
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1326
          (ClassName.to_string t)
×
1327
    | `ClassType (p, t) ->
×
1328
        Format.fprintf ppf "%a.%s" (resolved_parent_path c) p
×
1329
          (ClassTypeName.to_string t)
×
1330

1331
  and model_path : config -> Format.formatter -> path -> unit =
1332
   fun c ppf (p : path) ->
1333
    match p with
×
1334
    | `Resolved rp -> wrap c "resolved" model_resolved_path ppf rp
×
1335
    | `Identifier (id, b) ->
×
1336
        wrap2 c "identifier" model_identifier bool ppf (id :> id) b
1337
    | `Root s -> wrap c "root" str ppf s
×
1338
    | `Forward s -> wrap c "forward" str ppf s
×
1339
    | `Dot (parent, s) ->
×
1340
        Format.fprintf ppf "%a.%s" (model_path c) (parent :> path) s
×
1341
    | `Apply (func, arg) ->
×
1342
        Format.fprintf ppf "%a(%a)" (model_path c)
×
1343
          (func :> path)
1344
          (model_path c)
×
1345
          (arg :> path)
1346
    | `Substituted m ->
×
1347
        wrap c "substituted" model_path ppf (m :> Odoc_model.Paths.Path.t)
1348
    | `SubstitutedMT m ->
×
1349
        wrap c "substitutedmt" model_path ppf (m :> Odoc_model.Paths.Path.t)
1350
    | `SubstitutedT m ->
×
1351
        wrap c "substitutedt" model_path ppf (m :> Odoc_model.Paths.Path.t)
1352
    | `SubstitutedCT m ->
×
1353
        wrap c "substitutedct" model_path ppf (m :> Odoc_model.Paths.Path.t)
1354

1355
  and model_resolved_path (c : config) ppf (p : rpath) =
1356
    let open Odoc_model.Paths.Path.Resolved in
50✔
1357
    match p with
1358
    | `Identifier id -> Format.fprintf ppf "%a" (model_identifier c) (id :> id)
50✔
1359
    | `Module (parent, name) ->
×
1360
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1361
          (parent :> t)
1362
          (ModuleName.to_string name)
×
1363
    | `ModuleType (parent, name) ->
×
1364
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1365
          (parent :> t)
1366
          (ModuleTypeName.to_string name)
×
1367
    | `Type (parent, name) ->
×
1368
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1369
          (parent :> t)
1370
          (TypeName.to_string name)
×
1371
    | `Value (parent, name) ->
×
1372
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1373
          (parent :> t)
1374
          (ValueName.to_string name)
×
1375
    | `Alias (dest, src) ->
×
1376
        wrap2r c "alias" model_resolved_path model_path ppf
1377
          (dest :> t)
1378
          (src :> path)
1379
    | `AliasModuleType (path, realpath) ->
×
1380
        wrap2r c "aliasmoduletype" model_resolved_path model_resolved_path ppf
1381
          (path :> t)
1382
          (realpath :> t)
1383
    | `Subst (modty, m) ->
×
1384
        wrap2 c "subst" model_resolved_path model_resolved_path ppf
1385
          (modty :> t)
1386
          (m :> t)
1387
    | `SubstT (t1, t2) ->
×
1388
        wrap2 c "substt" model_resolved_path model_resolved_path ppf
1389
          (t1 :> t)
1390
          (t2 :> t)
1391
    | `CanonicalModuleType (t1, t2) ->
×
1392
        wrap2 c "canonicalmoduletype" model_resolved_path model_path ppf
1393
          (t1 :> t)
1394
          (t2 :> path)
1395
    | `CanonicalType (t1, t2) ->
×
1396
        wrap2 c "canonicaltype" model_resolved_path model_path ppf
1397
          (t1 :> t)
1398
          (t2 :> path)
1399
    | `Apply (funct, arg) ->
×
1400
        Format.fprintf ppf "%a(%a)" (model_resolved_path c)
×
1401
          (funct :> t)
1402
          (model_resolved_path c)
×
1403
          (arg :> t)
1404
    | `Canonical (p1, p2) ->
×
1405
        wrap2 c "canonical" model_resolved_path model_path ppf
1406
          (p1 :> t)
1407
          (p2 :> path)
1408
    | `Hidden p -> wrap c "hidden" model_resolved_path ppf (p :> t)
×
1409
    | `Class (parent, name) ->
×
1410
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1411
          (parent :> t)
1412
          (ClassName.to_string name)
×
1413
    | `ClassType (parent, name) ->
×
1414
        Format.fprintf ppf "%a.%s" (model_resolved_path c)
×
1415
          (parent :> t)
1416
          (ClassTypeName.to_string name)
×
1417
    | `OpaqueModule m -> wrap c "opaquemodule" model_resolved_path ppf (m :> t)
×
1418
    | `OpaqueModuleType m ->
×
1419
        wrap c "opaquemoduletype" model_resolved_path ppf (m :> t)
1420
    | `Substituted m -> wrap c "substituted" model_resolved_path ppf (m :> t)
×
1421
    | `SubstitutedMT m ->
×
1422
        wrap c "substitutedmt" model_resolved_path ppf (m :> t)
1423
    | `SubstitutedT m -> wrap c "substitutedt" model_resolved_path ppf (m :> t)
×
1424
    | `SubstitutedCT m ->
×
1425
        wrap c "substitutedct" model_resolved_path ppf (m :> t)
1426

1427
  and model_fragment c ppf (f : Odoc_model.Paths.Fragment.t) =
1428
    match f with
×
1429
    | `Resolved rf -> model_resolved_fragment c ppf rf
×
1430
    | `Dot (sg, d) ->
×
1431
        Format.fprintf ppf "*%a.%s" (model_fragment c)
×
1432
          (sg :> Odoc_model.Paths.Fragment.t)
1433
          d
1434
    | `Root -> ()
×
1435

1436
  and model_resolved_fragment c ppf (f : Odoc_model.Paths.Fragment.Resolved.t) =
1437
    let open Odoc_model.Paths.Fragment.Resolved in
×
1438
    match f with
1439
    | `Root (`ModuleType p) ->
×
1440
        Format.fprintf ppf "root(%a)" (model_resolved_path c) (p :> rpath)
×
1441
    | `Root (`Module p) ->
×
1442
        Format.fprintf ppf "root(%a)" (model_resolved_path c) (p :> rpath)
×
1443
    | `Module (`Root _, m) when c.short_paths ->
×
1444
        Format.fprintf ppf "%s" (ModuleName.to_string m)
×
1445
    | `Module (sg, m) ->
×
1446
        Format.fprintf ppf "%a.%s"
1447
          (model_resolved_fragment c)
×
1448
          (sg :> t)
1449
          (ModuleName.to_string m)
×
1450
    | `Module_type (`Root _, m) when c.short_paths ->
×
1451
        Format.fprintf ppf "%s" (ModuleTypeName.to_string m)
×
1452
    | `Module_type (sg, mty) ->
×
1453
        Format.fprintf ppf "%a.%s"
1454
          (model_resolved_fragment c)
×
1455
          (sg :> t)
1456
          (ModuleTypeName.to_string mty)
×
1457
    | `Type (`Root _, t) when c.short_paths ->
×
1458
        Format.fprintf ppf "%s" (TypeName.to_string t)
×
1459
    | `Type (sg, t) ->
×
1460
        Format.fprintf ppf "%a.%s"
1461
          (model_resolved_fragment c)
×
1462
          (sg :> t)
1463
          (TypeName.to_string t)
×
1464
    | `Subst (path, m) ->
×
1465
        Format.fprintf ppf "(%a subst -> %a)" (model_resolved_path c)
×
1466
          (path :> rpath)
1467
          (model_resolved_fragment c)
×
1468
          (m :> t)
1469
    | `Alias (_, _) -> Format.fprintf ppf "UNIMPLEMENTED subst alias!?"
×
1470
    | `Class (sg, cls) ->
×
1471
        Format.fprintf ppf "%a.%s"
1472
          (model_resolved_fragment c)
×
1473
          (sg :> t)
1474
          (ClassName.to_string cls)
×
1475
    | `ClassType (sg, cls) ->
×
1476
        Format.fprintf ppf "%a.%s"
1477
          (model_resolved_fragment c)
×
1478
          (sg :> t)
1479
          (ClassTypeName.to_string cls)
×
1480
    | `OpaqueModule m ->
×
1481
        Format.fprintf ppf "opaquemodule(%a)"
1482
          (model_resolved_fragment c)
×
1483
          (m :> Odoc_model.Paths.Fragment.Resolved.t)
1484

1485
  and resolved_root_fragment c ppf (f : Cfrag.root) =
1486
    match f with
×
1487
    | `ModuleType p ->
×
1488
        Format.fprintf ppf "root(%a)" (resolved_module_type_path c) p
×
1489
    | `Module p -> Format.fprintf ppf "root(%a)" (resolved_module_path c) p
×
1490

1491
  and resolved_signature_fragment c ppf (f : Cfrag.resolved_signature) =
1492
    match f with
3✔
1493
    | `Root r -> Format.fprintf ppf "%a" (resolved_root_fragment c) r
×
1494
    | (`Subst _ | `Alias _ | `Module _) as x -> resolved_module_fragment c ppf x
×
1495
    | `OpaqueModule m ->
×
1496
        Format.fprintf ppf "opaquemodule(%a)" (resolved_module_fragment c) m
×
1497

1498
  and resolved_module_fragment c ppf (f : Cfrag.resolved_module) =
1499
    match f with
5✔
1500
    | `Subst (s, f) ->
×
1501
        wrap2r c "subst" resolved_module_type_path resolved_module_fragment ppf
1502
          s f
1503
    | `Alias (m, f) ->
×
1504
        wrap2r c "alias" resolved_module_path resolved_module_fragment ppf m f
1505
    | `Module (`Root _, n) when c.short_paths ->
5✔
1506
        Format.fprintf ppf "%s" (ModuleName.to_string n)
5✔
1507
    | `Module (p, n) ->
×
1508
        Format.fprintf ppf "%a.%s"
1509
          (resolved_signature_fragment c)
×
1510
          p (ModuleName.to_string n)
×
1511
    | `OpaqueModule m -> wrap c "opaquemodule" resolved_module_fragment ppf m
×
1512

1513
  and resolved_module_type_fragment c ppf (f : Cfrag.resolved_module_type) =
1514
    match f with
×
1515
    | `ModuleType (`Root _, n) when c.short_paths ->
×
1516
        Format.fprintf ppf "%s" (ModuleTypeName.to_string n)
×
1517
    | `ModuleType (p, n) ->
×
1518
        Format.fprintf ppf "%a.%s"
1519
          (resolved_signature_fragment c)
×
1520
          p
1521
          (ModuleTypeName.to_string n)
×
1522

1523
  and resolved_type_fragment c ppf (f : Cfrag.resolved_type) =
1524
    match f with
5✔
1525
    | `Type (`Root _, n) when c.short_paths ->
2✔
1526
        Format.fprintf ppf "%s" (TypeName.to_string n)
2✔
1527
    | `Class (`Root _, n) when c.short_paths ->
×
1528
        Format.fprintf ppf "%s" (ClassName.to_string n)
×
1529
    | `ClassType (`Root _, n) when c.short_paths ->
×
1530
        Format.fprintf ppf "%s" (ClassTypeName.to_string n)
×
1531
    | `Type (s, n) ->
3✔
1532
        Format.fprintf ppf "%a.%s"
1533
          (resolved_signature_fragment c)
3✔
1534
          s (TypeName.to_string n)
3✔
1535
    | `Class (s, n) ->
×
1536
        Format.fprintf ppf "%a.%s"
1537
          (resolved_signature_fragment c)
×
1538
          s (ClassName.to_string n)
×
1539
    | `ClassType (s, n) ->
×
1540
        Format.fprintf ppf "%a.%s"
1541
          (resolved_signature_fragment c)
×
1542
          s
1543
          (ClassTypeName.to_string n)
×
1544

1545
  and signature_fragment c ppf (f : Cfrag.signature) =
1546
    match f with
×
1547
    | `Resolved r ->
×
1548
        Format.fprintf ppf "r(%a)" (resolved_signature_fragment c) r
×
1549
    | `Dot (s, n) -> Format.fprintf ppf "%a.%s" (signature_fragment c) s n
×
1550
    | `Root -> Format.fprintf ppf "root"
×
1551

1552
  and module_fragment c ppf (f : Cfrag.module_) =
1553
    match f with
2✔
1554
    | `Resolved r -> wrap c "resolved" resolved_module_fragment ppf r
2✔
1555
    | `Dot (`Root, n) when c.short_paths -> Format.fprintf ppf "%s" n
×
1556
    | `Dot (s, n) -> Format.fprintf ppf "%a.%s" (signature_fragment c) s n
×
1557

1558
  and module_type_fragment c ppf (f : Cfrag.module_type) =
1559
    match f with
×
1560
    | `Resolved r -> wrap c "resolved" resolved_module_type_fragment ppf r
×
1561
    | `Dot (`Root, n) when c.short_paths -> Format.fprintf ppf "%s" n
×
1562
    | `Dot (s, n) -> Format.fprintf ppf "%a.%s" (signature_fragment c) s n
×
1563

1564
  and type_fragment c ppf (f : Cfrag.type_) =
1565
    match f with
7✔
1566
    | `Resolved r -> wrap c "resolved" resolved_type_fragment ppf r
5✔
1567
    | `Dot (`Root, n) when c.short_paths -> Format.fprintf ppf "%s" n
2✔
1568
    | `Dot (s, n) -> Format.fprintf ppf "%a.%s" (signature_fragment c) s n
×
1569

1570
  and model_resolved_reference c ppf (r : Odoc_model.Paths.Reference.Resolved.t)
1571
      =
1572
    let open Odoc_model.Paths.Reference.Resolved in
×
1573
    match r with
1574
    | `Identifier id -> Format.fprintf ppf "%a" (model_identifier c) id
×
1575
    | `Hidden p ->
×
1576
        Format.fprintf ppf "hidden(%a)" (model_resolved_reference c) (p :> t)
×
1577
    | `Module (parent, name) ->
×
1578
        Format.fprintf ppf "%a.%s"
1579
          (model_resolved_reference c)
×
1580
          (parent :> t)
1581
          (ModuleName.to_string name)
×
1582
    | `ModuleType (parent, name) ->
×
1583
        Format.fprintf ppf "%a.%s"
1584
          (model_resolved_reference c)
×
1585
          (parent :> t)
1586
          (ModuleTypeName.to_string name)
×
1587
    | `Type (parent, name) ->
×
1588
        Format.fprintf ppf "%a.%s"
1589
          (model_resolved_reference c)
×
1590
          (parent :> t)
1591
          (TypeName.to_string name)
×
1592
    | `Constructor (parent, name) ->
×
1593
        Format.fprintf ppf "%a.%s"
1594
          (model_resolved_reference c)
×
1595
          (parent :> t)
1596
          (ConstructorName.to_string name)
×
1597
    | `PolyConstructor (parent, name) ->
×
1598
        Format.fprintf ppf "%a.%s"
1599
          (model_resolved_reference c)
×
1600
          (parent :> t)
1601
          (ConstructorName.to_string name)
×
1602
    | `Field (parent, name) ->
×
1603
        Format.fprintf ppf "%a.%s"
1604
          (model_resolved_reference c)
×
1605
          (parent :> t)
1606
          (FieldName.to_string name)
×
1607
    | `Extension (parent, name) ->
×
1608
        Format.fprintf ppf "%a.%s"
1609
          (model_resolved_reference c)
×
1610
          (parent :> t)
1611
          (ExtensionName.to_string name)
×
1612
    | `ExtensionDecl (parent, name, _) ->
×
1613
        Format.fprintf ppf "%a.%s"
1614
          (model_resolved_reference c)
×
1615
          (parent :> t)
1616
          (ExtensionName.to_string name)
×
1617
    | `Exception (parent, name) ->
×
1618
        Format.fprintf ppf "%a.%s"
1619
          (model_resolved_reference c)
×
1620
          (parent :> t)
1621
          (ExceptionName.to_string name)
×
1622
    | `Value (parent, name) ->
×
1623
        Format.fprintf ppf "%a.%s"
1624
          (model_resolved_reference c)
×
1625
          (parent :> t)
1626
          (ValueName.to_string name)
×
1627
    | `Class (parent, name) ->
×
1628
        Format.fprintf ppf "%a.%s"
1629
          (model_resolved_reference c)
×
1630
          (parent :> t)
1631
          (ClassName.to_string name)
×
1632
    | `ClassType (parent, name) ->
×
1633
        Format.fprintf ppf "%a.%s"
1634
          (model_resolved_reference c)
×
1635
          (parent :> t)
1636
          (ClassTypeName.to_string name)
×
1637
    | `Method (parent, name) ->
×
1638
        Format.fprintf ppf "%a.%s"
1639
          (model_resolved_reference c)
×
1640
          (parent :> t)
1641
          (MethodName.to_string name)
×
1642
    | `InstanceVariable (parent, name) ->
×
1643
        Format.fprintf ppf "%a.%s"
1644
          (model_resolved_reference c)
×
1645
          (parent :> t)
1646
          (InstanceVariableName.to_string name)
×
1647
    | `Alias (x, y) ->
×
1648
        Format.fprintf ppf "alias(%a,%a)" (model_resolved_path c)
×
1649
          (x :> rpath)
1650
          (model_resolved_reference c)
×
1651
          (y :> Odoc_model.Paths.Reference.Resolved.t)
1652
    | `AliasModuleType (x, y) ->
×
1653
        Format.fprintf ppf "aliasmoduletype(%a,%a)" (model_resolved_path c)
×
1654
          (x :> rpath)
1655
          (model_resolved_reference c)
×
1656
          (y :> Odoc_model.Paths.Reference.Resolved.t)
1657
    | `Label (parent, name) ->
×
1658
        Format.fprintf ppf "%a.%s"
1659
          (model_resolved_reference c)
×
1660
          (parent :> t)
1661
          (LabelName.to_string name)
×
1662

1663
  and model_reference_hierarchy _c ppf
1664
      ((tag, components) : Reference.Hierarchy.t) =
NEW
1665
    (match tag with
×
NEW
1666
    | `TRelativePath -> fpf ppf "./"
×
NEW
1667
    | `TAbsolutePath -> fpf ppf "/"
×
NEW
1668
    | `TCurrentPackage -> fpf ppf "//");
×
NEW
1669
    let pp_sep ppf () = fpf ppf "/" in
×
1670
    Format.pp_print_list ~pp_sep Format.pp_print_string ppf components
1671

1672
  and model_reference c ppf (r : Reference.t) =
1673
    let open Reference in
2,045✔
1674
    match r with
1675
    | `Resolved r' -> Format.fprintf ppf "r(%a)" (model_resolved_reference c) r'
×
1676
    | `Root (name, _) -> Format.fprintf ppf "unresolvedroot(%s)" name
2,032✔
1677
    | `Dot (parent, str) ->
11✔
1678
        Format.fprintf ppf "%a.%s" (model_reference c) (parent :> t) str
11✔
NEW
1679
    | `Page_path p -> model_reference_hierarchy c ppf p
×
NEW
1680
    | `Module_path p -> model_reference_hierarchy c ppf p
×
NEW
1681
    | `Any_path p -> model_reference_hierarchy c ppf p
×
1682
    | `Module (parent, name) ->
×
1683
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1684
          (parent :> t)
1685
          (ModuleName.to_string name)
×
1686
    | `ModuleType (parent, name) ->
×
1687
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1688
          (parent :> t)
1689
          (ModuleTypeName.to_string name)
×
1690
    | `Type (parent, name) ->
×
1691
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1692
          (parent :> t)
1693
          (TypeName.to_string name)
×
1694
    | `Constructor (parent, name) ->
1✔
1695
        Format.fprintf ppf "%a.%s" (model_reference c)
1✔
1696
          (parent :> t)
1697
          (ConstructorName.to_string name)
1✔
1698
    | `Field (parent, name) ->
×
1699
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1700
          (parent :> t)
1701
          (FieldName.to_string name)
×
1702
    | `Extension (parent, name) ->
×
1703
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1704
          (parent :> t)
1705
          (ExtensionName.to_string name)
×
1706
    | `ExtensionDecl (parent, name) ->
×
1707
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1708
          (parent :> t)
1709
          (ExtensionName.to_string name)
×
1710
    | `Exception (parent, name) ->
×
1711
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1712
          (parent :> t)
1713
          (ExceptionName.to_string name)
×
1714
    | `Value (parent, name) ->
×
1715
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1716
          (parent :> t)
1717
          (ValueName.to_string name)
×
1718
    | `Class (parent, name) ->
×
1719
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1720
          (parent :> t)
1721
          (ClassName.to_string name)
×
1722
    | `ClassType (parent, name) ->
×
1723
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1724
          (parent :> t)
1725
          (ClassTypeName.to_string name)
×
1726
    | `Method (parent, name) ->
×
1727
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1728
          (parent :> t)
1729
          (MethodName.to_string name)
×
1730
    | `InstanceVariable (parent, name) ->
×
1731
        Format.fprintf ppf "%a.%s" (model_reference c)
×
1732
          (parent :> t)
1733
          (InstanceVariableName.to_string name)
×
1734
    | `Label (parent, name) ->
1✔
1735
        Format.fprintf ppf "%a.%s" (model_reference c)
1✔
1736
          (parent :> t)
1737
          (LabelName.to_string name)
1✔
1738
end
1739

1740
module LocalIdents = struct
1741
  open Odoc_model
1742
  (** The purpose of this module is to extract identifiers
1743
      that could be referenced in Paths - that is, modules,
1744
      module types, types, classes and class types. That way
1745
      we can assign them an Ident.t ahead of time and be
1746
      self-consistent. Because we don't need _all_ of the
1747
      identifiers we don't traverse the entire structure.
1748
      Additionally, we stop at (class_)signature boundaries
1749
      since identifiers within these won't be referenced 
1750
      except within them, so we only do that on demand. *)
1751

1752
  type t = {
1753
    modules : Paths.Identifier.Module.t list;
1754
    module_types : Paths.Identifier.ModuleType.t list;
1755
    types : Paths.Identifier.Type.t list;
1756
    classes : Paths.Identifier.Class.t list;
1757
    class_types : Paths.Identifier.ClassType.t list;
1758
  }
1759

1760
  let empty =
1761
    {
1762
      modules = [];
1763
      module_types = [];
1764
      types = [];
1765
      classes = [];
1766
      class_types = [];
1767
    }
1768

1769
  open Lang
1770

1771
  let rec signature_items s ids =
1772
    let open Signature in
35,053✔
1773
    List.fold_left
1774
      (fun ids c ->
1775
        match c with
63,365✔
1776
        | Module (_, { Module.id; _ }) ->
26,999✔
1777
            { ids with modules = id :: ids.modules }
1778
        | ModuleType m ->
17,100✔
1779
            { ids with module_types = m.ModuleType.id :: ids.module_types }
1780
        | ModuleSubstitution { ModuleSubstitution.id; _ } ->
5✔
1781
            { ids with modules = id :: ids.modules }
1782
        | ModuleTypeSubstitution { ModuleTypeSubstitution.id; _ } ->
3✔
1783
            { ids with module_types = id :: ids.module_types }
1784
        | Type (_, t) -> { ids with types = t.TypeDecl.id :: ids.types }
17,816✔
1785
        | TypeSubstitution t -> { ids with types = t.TypeDecl.id :: ids.types }
5✔
1786
        | Class (_, c) -> { ids with classes = c.Class.id :: ids.classes }
57✔
1787
        | ClassType (_, c) ->
37✔
1788
            { ids with class_types = c.ClassType.id :: ids.class_types }
1789
        | TypExt _ | Exception _ | Value _ | Comment _ -> ids
29✔
1790
        | Include i -> signature i.Include.expansion.content ids
200✔
1791
        | Open o -> signature o.Open.expansion ids)
32✔
1792
      ids s
1793

1794
  and signature s ids = signature_items s.items ids
35,053✔
1795
end
1796

1797
module Of_Lang = struct
1798
  open Odoc_model
1799

1800
  type map = {
1801
    modules : Ident.module_ Paths.Identifier.Maps.Module.t;
1802
    module_types : Ident.module_type Paths.Identifier.Maps.ModuleType.t;
1803
    functor_parameters :
1804
      Ident.functor_parameter Paths.Identifier.Maps.FunctorParameter.t;
1805
    types : Ident.type_ Paths.Identifier.Maps.Type.t;
1806
    path_types : Ident.path_type Paths.Identifier.Maps.Path.Type.t;
1807
    path_class_types :
1808
      Ident.path_class_type Paths.Identifier.Maps.Path.ClassType.t;
1809
    classes : Ident.class_ Paths.Identifier.Maps.Class.t;
1810
    class_types : Ident.class_type Paths.Identifier.Maps.ClassType.t;
1811
  }
1812

1813
  let empty () =
1814
    let open Paths.Identifier.Maps in
253,239✔
1815
    {
1816
      modules = Module.empty;
1817
      module_types = ModuleType.empty;
1818
      functor_parameters = FunctorParameter.empty;
1819
      types = Type.empty;
1820
      path_types = Path.Type.empty;
1821
      path_class_types = Path.ClassType.empty;
1822
      classes = Class.empty;
1823
      class_types = ClassType.empty;
1824
    }
1825

1826
  let map_of_idents ids map =
1827
    let open Paths.Identifier in
34,821✔
1828
    (* New types go into [types_new] and [path_types_new]
1829
       New classes go into [classes_new] and [path_class_types_new]
1830
       New class_types go into [class_types_new], [path_types_new] and [path_class_types_new] *)
1831
    let types_new, path_types_new =
1832
      List.fold_left
1833
        (fun (types, path_types) i ->
1834
          let id = Ident.Of_Identifier.type_ i in
17,821✔
1835
          ( Maps.Type.add i id types,
17,821✔
1836
            Maps.Path.Type.add
17,821✔
1837
              (i :> Path.Type.t)
1838
              (id :> Ident.path_type)
1839
              path_types ))
1840
        (map.types, map.path_types)
1841
        ids.LocalIdents.types
1842
    in
1843
    let classes_new, path_class_types_new =
34,821✔
1844
      List.fold_left
1845
        (fun (classes, path_class_types) i ->
1846
          let id = Ident.Of_Identifier.class_ i in
57✔
1847
          ( Maps.Class.add i id classes,
57✔
1848
            Maps.Path.ClassType.add
57✔
1849
              (i :> Path.ClassType.t)
1850
              (id :> Ident.path_class_type)
1851
              path_class_types ))
1852
        (map.classes, map.path_class_types)
1853
        ids.LocalIdents.classes
1854
    in
1855
    let class_types_new, path_types_new, path_class_types_new =
34,821✔
1856
      List.fold_left
1857
        (fun (class_types, path_types, path_class_types) i ->
1858
          let id = Ident.Of_Identifier.class_type i in
37✔
1859
          ( Maps.ClassType.add i id class_types,
37✔
1860
            Maps.Path.Type.add
37✔
1861
              (i :> Path.Type.t)
1862
              (id :> Ident.path_type)
1863
              path_types,
1864
            Maps.Path.ClassType.add
37✔
1865
              (i :> Path.ClassType.t)
1866
              (id :> Ident.path_class_type)
1867
              path_class_types ))
1868
        (map.class_types, path_types_new, path_class_types_new)
1869
        ids.LocalIdents.class_types
1870
    in
1871
    let modules_new =
34,821✔
1872
      List.fold_left
1873
        (fun acc i ->
1874
          Maps.Module.add (i :> Module.t) (Ident.Of_Identifier.module_ i) acc)
27,004✔
1875
        map.modules ids.LocalIdents.modules
1876
    in
1877
    let module_types_new =
34,821✔
1878
      List.fold_left
1879
        (fun acc i ->
1880
          Maps.ModuleType.add i (Ident.Of_Identifier.module_type i) acc)
17,103✔
1881
        map.module_types ids.LocalIdents.module_types
1882
    in
1883
    let modules = modules_new in
34,821✔
1884
    let module_types = module_types_new in
1885
    let functor_parameters = map.functor_parameters in
1886
    let types = types_new in
1887
    let classes = classes_new in
1888
    let class_types = class_types_new in
1889
    let path_types = path_types_new in
1890
    let path_class_types = path_class_types_new in
1891
    {
1892
      modules;
1893
      module_types;
1894
      functor_parameters;
1895
      types;
1896
      classes;
1897
      class_types;
1898
      path_types;
1899
      path_class_types;
1900
    }
1901

1902
  let option conv ident_map x =
1903
    match x with None -> None | Some x' -> Some (conv ident_map x')
17,437✔
1904

1905
  let identifier lookup map i =
1906
    match lookup i map with
263,996✔
1907
    | x -> `Local x
20,521✔
1908
    | exception Not_found -> `Identifier i
243,475✔
1909

1910
  let find_any_module i ident_map =
1911
    match i with
260,506✔
1912
    | { Odoc_model.Paths.Identifier.iv = `Root _ | `Module _; _ } as id ->
112,593✔
1913
        (Maps.Module.find id ident_map.modules :> Ident.path_module)
1914
    | {
99✔
1915
        Odoc_model.Paths.Identifier.iv = #Paths.Identifier.FunctorParameter.t_pv;
1916
        _;
1917
      } as id ->
1918
        (Maps.FunctorParameter.find id ident_map.functor_parameters
1919
          :> Ident.path_module)
1920
    | _ -> raise Not_found
×
1921

1922
  let rec resolved_module_path :
1923
      _ -> Odoc_model.Paths.Path.Resolved.Module.t -> Cpath.Resolved.module_ =
1924
   fun ident_map p ->
1925
    let recurse = resolved_module_path ident_map in
359,838✔
1926
    match p with
359,838✔
1927
    | `Identifier i -> (
149,764✔
1928
        match identifier find_any_module ident_map i with
1929
        | `Local l -> `Local l
316✔
1930
        | `Identifier _ -> `Gpath p)
149,448✔
1931
    | `Module (p, name) -> `Module (`Module (recurse p), name)
49,687✔
1932
    | `Apply (p1, p2) -> `Apply (recurse p1, recurse p2)
47✔
1933
    | `Alias (p1, p2) -> `Alias (recurse p1, module_path ident_map p2, None)
109,683✔
1934
    | `Subst (p1, p2) ->
9✔
1935
        `Subst (resolved_module_type_path ident_map p1, recurse p2)
9✔
1936
    | `Canonical (p1, p2) -> `Canonical (recurse p1, p2)
50,245✔
1937
    | `Hidden p1 -> `Hidden (recurse p1)
281✔
1938
    | `OpaqueModule m -> `OpaqueModule (recurse m)
1✔
1939
    | `Substituted m -> `Substituted (recurse m)
121✔
1940

1941
  and resolved_module_type_path :
1942
      _ ->
1943
      Odoc_model.Paths.Path.Resolved.ModuleType.t ->
1944
      Cpath.Resolved.module_type =
1945
   fun ident_map p ->
1946
    match p with
881✔
1947
    | `Identifier i -> (
517✔
1948
        match identifier Maps.ModuleType.find ident_map.module_types i with
1949
        | `Local l -> `Local l
74✔
1950
        | `Identifier _ -> `Gpath p)
443✔
1951
    | `ModuleType (p, name) ->
219✔
1952
        `ModuleType (`Module (resolved_module_path ident_map p), name)
219✔
1953
    | `CanonicalModuleType (p1, p2) ->
18✔
1954
        `CanonicalModuleType (resolved_module_type_path ident_map p1, p2)
18✔
1955
    | `OpaqueModuleType m ->
31✔
1956
        `OpaqueModuleType (resolved_module_type_path ident_map m)
31✔
1957
    | `AliasModuleType (m1, m2) ->
59✔
1958
        `AliasModuleType
1959
          ( resolved_module_type_path ident_map m1,
59✔
1960
            resolved_module_type_path ident_map m2 )
59✔
1961
    | `SubstT (p1, p2) ->
37✔
1962
        `SubstT
1963
          ( resolved_module_type_path ident_map p1,
37✔
1964
            resolved_module_type_path ident_map p2 )
37✔
1965
    | `SubstitutedMT m -> `Substituted (resolved_module_type_path ident_map m)
×
1966

1967
  and resolved_type_path :
1968
      _ -> Odoc_model.Paths.Path.Resolved.Type.t -> Cpath.Resolved.type_ =
1969
   fun ident_map p ->
1970
    match p with
1,296✔
1971
    | `Identifier i -> (
1,047✔
1972
        match identifier Maps.Path.Type.find ident_map.path_types i with
1973
        | `Local l -> `Local l
92✔
1974
        | `Identifier _ -> `Gpath p)
955✔
1975
    | `CanonicalType (p1, p2) ->
22✔
1976
        `CanonicalType (resolved_type_path ident_map p1, p2)
22✔
1977
    | `Type (p, name) -> `Type (`Module (resolved_module_path ident_map p), name)
224✔
1978
    | `Class (p, name) ->
3✔
1979
        `Class (`Module (resolved_module_path ident_map p), name)
3✔
1980
    | `ClassType (p, name) ->
×
1981
        `ClassType (`Module (resolved_module_path ident_map p), name)
×
1982
    | `SubstitutedT m -> `Substituted (resolved_type_path ident_map m)
×
1983
    | `SubstitutedCT m ->
×
1984
        `Substituted
1985
          (resolved_class_type_path ident_map m :> Cpath.Resolved.type_)
×
1986

1987
  and resolved_value_path :
1988
      _ -> Odoc_model.Paths.Path.Resolved.Value.t -> Cpath.Resolved.value =
1989
   fun ident_map p ->
1990
    match p with
×
1991
    | `Value (p, name) ->
×
1992
        `Value (`Module (resolved_module_path ident_map p), name)
×
1993
    | `Identifier _ -> `Gpath p
×
1994

1995
  and resolved_class_type_path :
1996
      _ ->
1997
      Odoc_model.Paths.Path.Resolved.ClassType.t ->
1998
      Cpath.Resolved.class_type =
1999
   fun ident_map p ->
2000
    match p with
23✔
2001
    | `Identifier i -> (
23✔
2002
        match
2003
          identifier Maps.Path.ClassType.find ident_map.path_class_types i
2004
        with
2005
        | `Local l -> `Local l
11✔
2006
        | `Identifier _ -> `Gpath p)
12✔
2007
    | `Class (p, name) ->
×
2008
        `Class (`Module (resolved_module_path ident_map p), name)
×
2009
    | `ClassType (p, name) ->
×
2010
        `ClassType (`Module (resolved_module_path ident_map p), name)
×
2011
    | `SubstitutedCT c -> `Substituted (resolved_class_type_path ident_map c)
×
2012

2013
  and module_path : _ -> Odoc_model.Paths.Path.Module.t -> Cpath.module_ =
2014
   fun ident_map p ->
2015
    match p with
271,520✔
2016
    | `Resolved r -> `Resolved (resolved_module_path ident_map r)
99,934✔
2017
    | `Substituted m -> `Substituted (module_path ident_map m)
25✔
2018
    | `Identifier (i, b) -> (
110,742✔
2019
        match identifier find_any_module ident_map i with
2020
        | `Identifier i -> `Identifier (i, b)
90,813✔
2021
        | `Local i -> `Local (i, b))
19,929✔
2022
    | `Dot (path', x) -> `Dot (module_path ident_map path', x)
10,908✔
2023
    | `Apply (p1, p2) ->
37✔
2024
        `Apply (module_path ident_map p1, module_path ident_map p2)
37✔
2025
    | `Forward str -> `Forward str
×
2026
    | `Root str -> `Root str
49,874✔
2027

2028
  and module_type_path :
2029
      _ -> Odoc_model.Paths.Path.ModuleType.t -> Cpath.module_type =
2030
   fun ident_map p ->
2031
    match p with
1,034✔
2032
    | `Resolved r -> `Resolved (resolved_module_type_path ident_map r)
466✔
2033
    | `SubstitutedMT m -> `Substituted (module_type_path ident_map m)
×
2034
    | `Identifier (i, b) -> (
474✔
2035
        match identifier Maps.ModuleType.find ident_map.module_types i with
2036
        | `Identifier i -> `Identifier (i, b)
449✔
2037
        | `Local i -> `Local (i, b))
25✔
2038
    | `Dot (path', x) -> `Dot (module_path ident_map path', x)
94✔
2039

2040
  and type_path : _ -> Odoc_model.Paths.Path.Type.t -> Cpath.type_ =
2041
   fun ident_map p ->
2042
    match p with
2,995✔
2043
    | `Resolved r -> `Resolved (resolved_type_path ident_map r)
1,268✔
2044
    | `SubstitutedT t -> `Substituted (type_path ident_map t)
×
2045
    | `Identifier (i, b) -> (
1,397✔
2046
        match identifier Maps.Path.Type.find ident_map.path_types i with
2047
        | `Identifier i -> `Identifier (i, b)
1,332✔
2048
        | `Local i -> `Local (i, b))
65✔
2049
    | `Dot (path', x) -> `Dot (module_path ident_map path', x)
330✔
2050

2051
  and value_path : _ -> Odoc_model.Paths.Path.Value.t -> Cpath.value =
2052
   fun ident_map p ->
2053
    match p with
69✔
2054
    | `Resolved r -> `Resolved (resolved_value_path ident_map r)
×
2055
    | `Dot (path', x) -> `Dot (module_path ident_map path', x)
69✔
2056
    | `Identifier (i, b) -> `Identifier (i, b)
×
2057

2058
  and class_type_path :
2059
      _ -> Odoc_model.Paths.Path.ClassType.t -> Cpath.class_type =
2060
   fun ident_map p ->
2061
    match p with
69✔
2062
    | `Resolved r -> `Resolved (resolved_class_type_path ident_map r)
23✔
2063
    | `SubstitutedCT c -> `Substituted (class_type_path ident_map c)
×
2064
    | `Identifier (i, b) -> (
32✔
2065
        match
2066
          identifier Maps.Path.ClassType.find ident_map.path_class_types i
2067
        with
2068
        | `Identifier i -> `Identifier (i, b)
23✔
2069
        | `Local i -> `Local (i, b))
9✔
2070
    | `Dot (path', x) -> `Dot (module_path ident_map path', x)
14✔
2071

2072
  let rec resolved_signature_fragment :
2073
      map ->
2074
      Odoc_model.Paths.Fragment.Resolved.Signature.t ->
2075
      Cfrag.resolved_signature =
2076
   fun ident_map ty ->
2077
    match ty with
49,374✔
2078
    | `Root (`ModuleType path) ->
158✔
2079
        `Root (`ModuleType (resolved_module_type_path ident_map path))
158✔
2080
    | `Root (`Module path) ->
49,181✔
2081
        `Root (`Module (resolved_module_path ident_map path))
49,181✔
2082
    | (`Alias _ | `Subst _ | `Module _ | `OpaqueModule _) as x ->
×
2083
        (resolved_module_fragment ident_map x :> Cfrag.resolved_signature)
2084

2085
  and resolved_module_fragment :
2086
      _ -> Odoc_model.Paths.Fragment.Resolved.Module.t -> Cfrag.resolved_module
2087
      =
2088
   fun ident_map ty ->
2089
    match ty with
49,257✔
2090
    | `Subst (p, m) ->
4✔
2091
        `Subst
2092
          ( resolved_module_type_path ident_map p,
4✔
2093
            resolved_module_fragment ident_map m )
4✔
2094
    | `Alias (p, m) ->
10✔
2095
        `Alias
2096
          ( resolved_module_path ident_map p,
10✔
2097
            resolved_module_fragment ident_map m )
10✔
2098
    | `Module (p, m) -> `Module (resolved_signature_fragment ident_map p, m)
49,243✔
2099
    | `OpaqueModule m -> `OpaqueModule (resolved_module_fragment ident_map m)
×
2100

2101
  and resolved_module_type_fragment :
2102
      _ ->
2103
      Odoc_model.Paths.Fragment.Resolved.ModuleType.t ->
2104
      Cfrag.resolved_module_type =
2105
   fun ident_map ty ->
2106
    match ty with
24✔
2107
    | `Module_type (p, m) ->
24✔
2108
        `ModuleType (resolved_signature_fragment ident_map p, m)
24✔
2109

2110
  and resolved_type_fragment :
2111
      _ -> Odoc_model.Paths.Fragment.Resolved.Type.t -> Cfrag.resolved_type =
2112
   fun ident_map ty ->
2113
    match ty with
107✔
2114
    | `Type (p, n) -> `Type (resolved_signature_fragment ident_map p, n)
107✔
2115
    | `Class (p, n) -> `Class (resolved_signature_fragment ident_map p, n)
×
2116
    | `ClassType (p, n) ->
×
2117
        `ClassType (resolved_signature_fragment ident_map p, n)
×
2118

2119
  let rec signature_fragment :
2120
      _ -> Odoc_model.Paths.Fragment.Signature.t -> Cfrag.signature =
2121
   fun ident_map ty ->
2122
    match ty with
283✔
2123
    | `Resolved r -> `Resolved (resolved_signature_fragment ident_map r)
×
2124
    | `Dot (p, n) -> `Dot (signature_fragment ident_map p, n)
33✔
2125
    | `Root -> `Root
250✔
2126

2127
  let module_fragment : _ -> Odoc_model.Paths.Fragment.Module.t -> Cfrag.module_
2128
      =
2129
   fun ident_map ty ->
2130
    match ty with
49,291✔
2131
    | `Resolved r -> `Resolved (resolved_module_fragment ident_map r)
49,195✔
2132
    | `Dot (p, n) -> `Dot (signature_fragment ident_map p, n)
96✔
2133

2134
  let module_type_fragment :
2135
      _ -> Odoc_model.Paths.Fragment.ModuleType.t -> Cfrag.module_type =
2136
   fun ident_map ty ->
2137
    match ty with
46✔
2138
    | `Resolved r -> `Resolved (resolved_module_type_fragment ident_map r)
18✔
2139
    | `Dot (p, n) -> `Dot (signature_fragment ident_map p, n)
28✔
2140

2141
  let type_fragment : _ -> Odoc_model.Paths.Fragment.Type.t -> Cfrag.type_ =
2142
   fun ident_map ty ->
2143
    match ty with
206✔
2144
    | `Resolved r -> `Resolved (resolved_type_fragment ident_map r)
80✔
2145
    | `Dot (p, n) -> `Dot (signature_fragment ident_map p, n)
126✔
2146

2147
  let rec type_decl ident_map ty =
2148
    let open Odoc_model.Lang.TypeDecl in
67,752✔
2149
    {
2150
      TypeDecl.source_loc = ty.source_loc;
2151
      doc = docs ident_map ty.doc;
67,752✔
2152
      canonical = ty.canonical;
2153
      equation = type_equation ident_map ty.equation;
67,752✔
2154
      representation =
2155
        Opt.map (type_decl_representation ident_map) ty.representation;
67,752✔
2156
    }
2157

2158
  and type_decl_representation ident_map r =
2159
    let open Odoc_model.Lang.TypeDecl.Representation in
357✔
2160
    match r with
2161
    | Variant cs ->
306✔
2162
        TypeDecl.Representation.Variant
2163
          (List.map (type_decl_constructor ident_map) cs)
306✔
2164
    | Record fs -> Record (List.map (type_decl_field ident_map) fs)
19✔
2165
    | Extensible -> Extensible
32✔
2166

2167
  and type_decl_constructor ident_map t =
2168
    let open Odoc_model.Lang.TypeDecl.Constructor in
397✔
2169
    let args = type_decl_constructor_argument ident_map t.args in
2170
    let res = Opt.map (type_expression ident_map) t.res in
397✔
2171
    {
397✔
2172
      TypeDecl.Constructor.name = Paths.Identifier.name t.id;
397✔
2173
      doc = docs ident_map t.doc;
397✔
2174
      args;
2175
      res;
2176
    }
2177

2178
  and type_decl_constructor_argument ident_map a =
2179
    let open Odoc_model.Lang.TypeDecl.Constructor in
562✔
2180
    match a with
2181
    | Tuple ts ->
554✔
2182
        TypeDecl.Constructor.Tuple (List.map (type_expression ident_map) ts)
554✔
2183
    | Record fs -> Record (List.map (type_decl_field ident_map) fs)
8✔
2184

2185
  and type_decl_field ident_map f =
2186
    let open Odoc_model.Lang.TypeDecl.Field in
46✔
2187
    let type_ = type_expression ident_map f.type_ in
2188
    {
46✔
2189
      TypeDecl.Field.name = Paths.Identifier.name f.id;
46✔
2190
      doc = docs ident_map f.doc;
46✔
2191
      mutable_ = f.mutable_;
2192
      type_;
2193
    }
2194

2195
  and type_equation ident_map teq =
2196
    let open Odoc_model.Lang.TypeDecl.Equation in
67,977✔
2197
    {
2198
      TypeDecl.Equation.params = teq.params;
2199
      private_ = teq.private_;
2200
      manifest = option type_expression ident_map teq.manifest;
67,977✔
2201
      constraints =
2202
        List.map
67,977✔
2203
          (fun (x, y) ->
2204
            (type_expression ident_map x, type_expression ident_map y))
24✔
2205
          teq.constraints;
2206
    }
2207

2208
  and type_expr_polyvar ident_map v =
2209
    let open Odoc_model.Lang.TypeExpr.Polymorphic_variant in
94✔
2210
    let map_element = function
2211
      | Type expr ->
10✔
2212
          TypeExpr.Polymorphic_variant.Type (type_expression ident_map expr)
10✔
2213
      | Constructor c ->
148✔
2214
          Constructor
2215
            TypeExpr.Polymorphic_variant.Constructor.
2216
              {
2217
                name = c.name;
2218
                constant = c.constant;
2219
                arguments = List.map (type_expression ident_map) c.arguments;
148✔
2220
                doc = docs ident_map c.doc;
148✔
2221
              }
2222
    in
2223
    {
2224
      TypeExpr.Polymorphic_variant.kind = v.kind;
2225
      elements = List.map map_element v.elements;
94✔
2226
    }
2227

2228
  and type_object ident_map o =
2229
    let open Odoc_model.Lang.TypeExpr.Object in
20✔
2230
    let map_field = function
2231
      | Method m ->
30✔
2232
          TypeExpr.(
2233
            Object.Method
2234
              {
2235
                Object.name = m.name;
2236
                type_ = type_expression ident_map m.type_;
30✔
2237
              })
2238
      | Inherit i -> Inherit (type_expression ident_map i)
×
2239
    in
2240
    { TypeExpr.Object.open_ = o.open_; fields = List.map map_field o.fields }
20✔
2241

2242
  and type_package ident_map pkg =
2243
    let open Odoc_model.Lang.TypeExpr.Package in
6✔
2244
    {
2245
      TypeExpr.Package.path = module_type_path ident_map pkg.path;
6✔
2246
      substitutions =
2247
        List.map
6✔
2248
          (fun (x, y) ->
2249
            let f = type_fragment ident_map x in
4✔
2250
            (f, type_expression ident_map y))
4✔
2251
          pkg.substitutions;
2252
    }
2253

2254
  and type_expression ident_map expr =
2255
    let open Odoc_model.Lang.TypeExpr in
2,636✔
2256
    match expr with
2257
    | Var s -> TypeExpr.Var s
294✔
2258
    | Any -> Any
×
2259
    | Constr (p, xs) ->
1,910✔
2260
        Constr (type_path ident_map p, List.map (type_expression ident_map) xs)
1,910✔
2261
    | Arrow (lbl, t1, t2) ->
231✔
2262
        Arrow (lbl, type_expression ident_map t1, type_expression ident_map t2)
231✔
2263
    | Tuple ts -> Tuple (List.map (type_expression ident_map) ts)
45✔
2264
    | Polymorphic_variant v ->
94✔
2265
        Polymorphic_variant (type_expr_polyvar ident_map v)
94✔
2266
    | Poly (s, ts) -> Poly (s, type_expression ident_map ts)
6✔
2267
    | Alias (t, s) -> Alias (type_expression ident_map t, s)
20✔
2268
    | Class (p, ts) ->
10✔
2269
        Class
2270
          (class_type_path ident_map p, List.map (type_expression ident_map) ts)
10✔
2271
    | Object o -> Object (type_object ident_map o)
20✔
2272
    | Package p -> Package (type_package ident_map p)
6✔
2273

2274
  and module_decl ident_map m =
2275
    match m with
51,361✔
2276
    | Lang.Module.Alias (p, e) ->
50,103✔
2277
        Module.Alias
2278
          (module_path ident_map p, option simple_expansion ident_map e)
50,103✔
2279
    | Lang.Module.ModuleType s ->
1,258✔
2280
        Module.ModuleType (module_type_expr ident_map s)
1,258✔
2281

2282
  and include_decl ident_map m =
2283
    match m with
342✔
2284
    | Odoc_model.Lang.Include.Alias p -> Include.Alias (module_path ident_map p)
×
2285
    | ModuleType s -> ModuleType (u_module_type_expr ident_map s)
342✔
2286

2287
  and simple_expansion ident_map
2288
      (f : Odoc_model.Lang.ModuleType.simple_expansion) :
2289
      ModuleType.simple_expansion =
2290
    let open Odoc_model.Lang.ModuleType in
16,656✔
2291
    let open Odoc_model.Lang.FunctorParameter in
2292
    match f with
2293
    | Signature t -> Signature (signature ident_map t)
16,643✔
2294
    | Functor (arg, sg) -> (
13✔
2295
        match arg with
2296
        | Named arg ->
13✔
2297
            let identifier = arg.Odoc_model.Lang.FunctorParameter.id in
2298
            let id = Ident.Of_Identifier.functor_parameter identifier in
2299
            let ident_map' =
13✔
2300
              {
2301
                ident_map with
2302
                functor_parameters =
2303
                  Maps.FunctorParameter.add identifier id
13✔
2304
                    ident_map.functor_parameters;
2305
              }
2306
            in
2307
            let arg' = functor_parameter ident_map' id arg in
2308
            Functor (FunctorParameter.Named arg', simple_expansion ident_map' sg)
13✔
2309
        | Unit -> Functor (FunctorParameter.Unit, simple_expansion ident_map sg)
×
2310
        )
2311

2312
  and module_ ident_map m =
2313
    let type_ = module_decl ident_map m.Odoc_model.Lang.Module.type_ in
2,111✔
2314
    let canonical = m.Odoc_model.Lang.Module.canonical in
2,111✔
2315
    {
2316
      Module.source_loc = m.source_loc;
2317
      doc = docs ident_map m.doc;
2,111✔
2318
      type_;
2319
      canonical;
2320
      hidden = m.hidden;
2321
    }
2322

2323
  and with_module_type_substitution ident_map m =
2324
    let open Odoc_model.Lang.ModuleType in
16,712✔
2325
    match m with
2326
    | ModuleEq (frag, decl) ->
16,501✔
2327
        ModuleType.ModuleEq
2328
          (module_fragment ident_map frag, module_decl ident_map decl)
16,501✔
2329
    | ModuleSubst (frag, p) ->
30✔
2330
        ModuleType.ModuleSubst
2331
          (module_fragment ident_map frag, module_path ident_map p)
30✔
2332
    | ModuleTypeEq (frag, mty) ->
22✔
2333
        ModuleType.ModuleTypeEq
2334
          (module_type_fragment ident_map frag, module_type_expr ident_map mty)
22✔
2335
    | ModuleTypeSubst (frag, mty) ->
12✔
2336
        ModuleType.ModuleTypeSubst
2337
          (module_type_fragment ident_map frag, module_type_expr ident_map mty)
12✔
2338
    | TypeEq (frag, eqn) ->
85✔
2339
        ModuleType.TypeEq
2340
          (type_fragment ident_map frag, type_equation ident_map eqn)
85✔
2341
    | TypeSubst (frag, eqn) ->
62✔
2342
        ModuleType.TypeSubst
2343
          (type_fragment ident_map frag, type_equation ident_map eqn)
62✔
2344

2345
  and functor_parameter ident_map id a =
2346
    let expr' =
42✔
2347
      module_type_expr ident_map a.Odoc_model.Lang.FunctorParameter.expr
2348
    in
2349
    { FunctorParameter.id; expr = expr' }
42✔
2350

2351
  and extension ident_map e =
2352
    let open Odoc_model.Lang.Extension in
73✔
2353
    let type_path = type_path ident_map e.type_path in
2354
    let constructors =
73✔
2355
      List.map (extension_constructor ident_map) e.constructors
73✔
2356
    in
2357
    {
73✔
2358
      Extension.type_path;
2359
      doc = docs ident_map e.doc;
73✔
2360
      type_params = e.type_params;
2361
      private_ = e.private_;
2362
      constructors;
2363
    }
2364

2365
  and extension_constructor ident_map c =
2366
    let open Odoc_model.Lang.Extension.Constructor in
125✔
2367
    let args = type_decl_constructor_argument ident_map c.args in
2368
    let res = Opt.map (type_expression ident_map) c.res in
125✔
2369
    {
125✔
2370
      Extension.Constructor.name = Paths.Identifier.name c.id;
125✔
2371
      source_loc = c.source_loc;
2372
      doc = docs ident_map c.doc;
125✔
2373
      args;
2374
      res;
2375
    }
2376

2377
  and exception_ ident_map e =
2378
    let open Odoc_model.Lang.Exception in
40✔
2379
    let args = type_decl_constructor_argument ident_map e.args in
2380
    let res = Opt.map (type_expression ident_map) e.res in
40✔
2381
    {
40✔
2382
      Exception.source_loc = e.source_loc;
2383
      doc = docs ident_map e.doc;
40✔
2384
      args;
2385
      res;
2386
    }
2387

2388
  and u_module_type_expr ident_map m =
2389
    let open Odoc_model in
49,849✔
2390
    match m with
2391
    | Lang.ModuleType.U.Signature s ->
60✔
2392
        let s = signature ident_map s in
2393
        ModuleType.U.Signature s
60✔
2394
    | Path p ->
394✔
2395
        let p' = module_type_path ident_map p in
2396
        Path p'
394✔
2397
    | With (w, e) ->
46✔
2398
        let w' = List.map (with_module_type_substitution ident_map) w in
46✔
2399
        With (w', u_module_type_expr ident_map e)
46✔
2400
    | TypeOf (t_desc, t_original_path) ->
49,349✔
2401
        let t_desc =
2402
          match t_desc with
2403
          | ModPath p -> ModuleType.ModPath (module_path ident_map p)
49,260✔
2404
          | StructInclude p -> StructInclude (module_path ident_map p)
89✔
2405
        in
2406
        (* see comment in module_type_expr below *)
2407
        let t_original_path = module_path (empty ()) t_original_path in
49,349✔
2408
        TypeOf (t_desc, t_original_path)
49,349✔
2409

2410
  and module_type_expr ident_map m =
2411
    let open Odoc_model in
35,167✔
2412
    let open Paths in
2413
    match m with
2414
    | Lang.ModuleType.Signature s ->
18,112✔
2415
        let s = signature ident_map s in
2416
        ModuleType.Signature s
18,112✔
2417
    | Lang.ModuleType.Path p ->
326✔
2418
        let p' =
2419
          ModuleType.
2420
            {
2421
              p_path = module_type_path ident_map p.p_path;
326✔
2422
              p_expansion = option simple_expansion ident_map p.p_expansion;
326✔
2423
            }
2424
        in
2425
        ModuleType.Path p'
2426
    | Lang.ModuleType.With w ->
16,600✔
2427
        let w' =
2428
          ModuleType.
2429
            {
2430
              w_substitutions =
2431
                List.map
16,600✔
2432
                  (with_module_type_substitution ident_map)
16,600✔
2433
                  w.w_substitutions;
2434
              w_expansion = option simple_expansion ident_map w.w_expansion;
16,600✔
2435
              w_expr = u_module_type_expr ident_map w.w_expr;
16,600✔
2436
            }
2437
        in
2438
        ModuleType.With w'
2439
    | Lang.ModuleType.Functor (Named arg, expr) ->
29✔
2440
        let identifier = arg.Lang.FunctorParameter.id in
2441
        let id = Ident.Of_Identifier.functor_parameter identifier in
2442
        let ident_map' =
29✔
2443
          {
2444
            ident_map with
2445
            functor_parameters =
2446
              Identifier.Maps.FunctorParameter.add identifier id
29✔
2447
                ident_map.functor_parameters;
2448
          }
2449
        in
2450
        let arg' = functor_parameter ident_map' id arg in
2451
        let expr' = module_type_expr ident_map' expr in
29✔
2452
        ModuleType.Functor (Named arg', expr')
29✔
2453
    | Lang.ModuleType.Functor (Unit, expr) ->
1✔
2454
        let expr' = module_type_expr ident_map expr in
2455
        ModuleType.Functor (Unit, expr')
1✔
2456
    | Lang.ModuleType.TypeOf { t_desc; t_original_path; t_expansion } ->
99✔
2457
        let t_desc =
2458
          match t_desc with
2459
          | ModPath p -> ModuleType.ModPath (module_path ident_map p)
78✔
2460
          | StructInclude p -> StructInclude (module_path ident_map p)
21✔
2461
        in
2462
        let t_expansion = option simple_expansion ident_map t_expansion in
2463
        (* Nb, we _never_ want to relativize this path, because this should always be
2464
           the _original_ path. That's why we're passing in (empty()) rather than
2465
           ident_map. We don't leave it as a Lang path because we'll occasionally
2466
           _create_ a `TypeOf` expression as part of fragmap *)
2467
        let t_original_path = module_path (empty ()) t_original_path in
99✔
2468
        ModuleType.(TypeOf { t_desc; t_original_path; t_expansion })
99✔
2469

2470
  and module_type ident_map m =
2471
    let expr =
33,484✔
2472
      Opt.map (module_type_expr ident_map) m.Odoc_model.Lang.ModuleType.expr
33,484✔
2473
    in
2474
    {
33,484✔
2475
      ModuleType.source_loc = m.source_loc;
2476
      doc = docs ident_map m.doc;
33,484✔
2477
      canonical = m.canonical;
2478
      expr;
2479
    }
2480

2481
  and value ident_map v =
2482
    let type_ = type_expression ident_map v.Lang.Value.type_ in
321✔
2483
    {
321✔
2484
      Value.type_;
2485
      doc = docs ident_map v.doc;
321✔
2486
      value = v.value;
2487
      source_loc = v.source_loc;
2488
    }
2489

2490
  and include_ ident_map i =
2491
    let open Odoc_model.Lang.Include in
200✔
2492
    let decl = include_decl ident_map i.decl in
2493
    {
200✔
2494
      Include.parent = i.parent;
2495
      doc = docs ident_map i.doc;
200✔
2496
      shadowed = i.expansion.shadowed;
2497
      expansion_ = apply_sig_map ident_map i.expansion.content;
200✔
2498
      status = i.status;
2499
      strengthened = option module_path ident_map i.strengthened;
200✔
2500
      decl;
2501
      loc = i.loc;
2502
    }
2503

2504
  and class_ ident_map c =
2505
    let open Odoc_model.Lang.Class in
111✔
2506
    let expansion = Opt.map (class_signature ident_map) c.expansion in
111✔
2507
    {
111✔
2508
      Class.source_loc = c.source_loc;
2509
      doc = docs ident_map c.doc;
111✔
2510
      virtual_ = c.virtual_;
2511
      params = c.params;
2512
      type_ = class_decl ident_map c.type_;
111✔
2513
      expansion;
2514
    }
2515

2516
  and class_decl ident_map c =
2517
    let open Odoc_model.Lang.Class in
120✔
2518
    match c with
2519
    | ClassType e -> Class.ClassType (class_type_expr ident_map e)
111✔
2520
    | Arrow (lbl, e, d) ->
9✔
2521
        Arrow (lbl, type_expression ident_map e, class_decl ident_map d)
9✔
2522

2523
  and class_type_expr ident_map e =
2524
    let open Odoc_model.Lang.ClassType in
189✔
2525
    match e with
2526
    | Constr (p, ts) ->
40✔
2527
        ClassType.Constr
2528
          (class_type_path ident_map p, List.map (type_expression ident_map) ts)
40✔
2529
    | Signature s -> Signature (class_signature ident_map s)
149✔
2530

2531
  and class_type ident_map t =
2532
    let open Odoc_model.Lang.ClassType in
66✔
2533
    let expansion = Opt.map (class_signature ident_map) t.expansion in
66✔
2534
    {
66✔
2535
      ClassType.source_loc = t.source_loc;
2536
      doc = docs ident_map t.doc;
66✔
2537
      virtual_ = t.virtual_;
2538
      params = t.params;
2539
      expr = class_type_expr ident_map t.expr;
66✔
2540
      expansion;
2541
    }
2542

2543
  and class_signature ident_map sg =
2544
    let open Odoc_model.Lang.ClassSignature in
238✔
2545
    let items =
2546
      List.map
2547
        (function
2548
          | Method m ->
94✔
2549
              let id = Ident.Of_Identifier.method_ m.id in
2550
              let m' = method_ ident_map m in
94✔
2551
              ClassSignature.Method (id, m')
94✔
2552
          | InstanceVariable i ->
12✔
2553
              let id = Ident.Of_Identifier.instance_variable i.id in
2554
              let i' = instance_variable ident_map i in
12✔
2555
              ClassSignature.InstanceVariable (id, i')
12✔
2556
          | Constraint cst -> Constraint (class_constraint ident_map cst)
6✔
2557
          | Inherit e -> Inherit (inherit_ ident_map e)
12✔
2558
          | Comment c -> Comment (docs_or_stop ident_map c))
24✔
2559
        sg.items
2560
    in
2561
    {
238✔
2562
      ClassSignature.self = Opt.map (type_expression ident_map) sg.self;
238✔
2563
      items;
2564
      doc = docs ident_map sg.doc;
238✔
2565
    }
2566

2567
  and method_ ident_map m =
2568
    let open Odoc_model.Lang.Method in
142✔
2569
    {
2570
      Method.doc = docs ident_map m.doc;
142✔
2571
      private_ = m.private_;
2572
      virtual_ = m.virtual_;
2573
      type_ = type_expression ident_map m.type_;
142✔
2574
    }
2575

2576
  and instance_variable ident_map i =
2577
    {
12✔
2578
      InstanceVariable.doc = docs ident_map i.doc;
12✔
2579
      mutable_ = i.mutable_;
2580
      virtual_ = i.virtual_;
2581
      type_ = type_expression ident_map i.type_;
12✔
2582
    }
2583

2584
  and class_constraint ident_map cst =
2585
    {
6✔
2586
      ClassSignature.Constraint.doc = docs ident_map cst.doc;
6✔
2587
      left = type_expression ident_map cst.left;
6✔
2588
      right = type_expression ident_map cst.right;
6✔
2589
    }
2590

2591
  and inherit_ ident_map ih =
2592
    {
12✔
2593
      ClassSignature.Inherit.doc = docs ident_map ih.doc;
12✔
2594
      expr = class_type_expr ident_map ih.expr;
12✔
2595
    }
2596

2597
  and module_substitution ident_map (t : Odoc_model.Lang.ModuleSubstitution.t) =
2598
    {
5✔
2599
      ModuleSubstitution.doc = docs ident_map t.doc;
5✔
2600
      manifest = module_path ident_map t.manifest;
5✔
2601
    }
2602

2603
  and module_type_substitution ident_map
2604
      (t : Odoc_model.Lang.ModuleTypeSubstitution.t) =
2605
    {
3✔
2606
      ModuleTypeSubstitution.doc = docs ident_map t.doc;
3✔
2607
      manifest = module_type_expr ident_map t.manifest;
3✔
2608
    }
2609

2610
  and module_of_module_substitution ident_map
2611
      (t : Odoc_model.Lang.ModuleSubstitution.t) =
2612
    let manifest = module_path ident_map t.manifest in
1✔
2613
    {
1✔
2614
      Module.source_loc = None;
2615
      doc = docs ident_map t.doc;
1✔
2616
      type_ = Alias (manifest, None);
2617
      canonical = None;
2618
      hidden = false;
2619
    }
2620

2621
  and signature : _ -> Odoc_model.Lang.Signature.t -> Signature.t =
2622
   fun ident_map items ->
2623
    (* First we construct a list of brand new [Ident.t]s
2624
                for each item in the signature *)
2625
    let ident_map =
34,821✔
2626
      map_of_idents (LocalIdents.signature items LocalIdents.empty) ident_map
34,821✔
2627
    in
2628
    (* Now we construct the Components for each item,
2629
                converting all paths containing Identifiers pointing at
2630
                our elements to local paths *)
2631
    apply_sig_map ident_map items
34,821✔
2632

2633
  and open_ ident_map o =
2634
    Open.
32✔
2635
      {
2636
        expansion = apply_sig_map ident_map o.Odoc_model.Lang.Open.expansion;
32✔
2637
        doc = docs ident_map o.Odoc_model.Lang.Open.doc;
32✔
2638
      }
2639

2640
  and removed_item ident_map r =
2641
    let open Odoc_model.Lang.Signature in
42✔
2642
    match r with
2643
    | RModule (id, p) -> Signature.RModule (id, module_path ident_map p)
13✔
2644
    | RType (id, texpr, eqn) ->
27✔
2645
        RType (id, type_expression ident_map texpr, type_equation ident_map eqn)
27✔
2646
    | RModuleType (id, m) -> RModuleType (id, module_type_expr ident_map m)
2✔
2647

2648
  and apply_sig_map ident_map sg =
2649
    let items =
35,053✔
2650
      List.rev_map
2651
        (let open Odoc_model.Lang.Signature in
2652
         let open Odoc_model.Paths in
2653
         function
2654
         | Type (r, t) ->
17,816✔
2655
             let id = Identifier.Maps.Type.find t.id ident_map.types in
2656
             let t' = Delayed.put (fun () -> type_decl ident_map t) in
394✔
2657
             Signature.Type (id, r, t')
17,816✔
2658
         | TypeSubstitution t ->
5✔
2659
             let id = Identifier.Maps.Type.find t.id ident_map.types in
2660
             let t' = type_decl ident_map t in
5✔
2661
             Signature.TypeSubstitution (id, t')
5✔
2662
         | Module (r, m) ->
26,999✔
2663
             let id =
2664
               Identifier.Maps.Module.find
2665
                 (m.id :> Identifier.Module.t)
2666
                 ident_map.modules
2667
             in
2668
             let m' = Delayed.put (fun () -> module_ ident_map m) in
768✔
2669
             Signature.Module (id, r, m')
26,999✔
2670
         | ModuleSubstitution m ->
5✔
2671
             let id = Identifier.Maps.Module.find m.id ident_map.modules in
2672
             let m' = module_substitution ident_map m in
5✔
2673
             Signature.ModuleSubstitution (id, m')
5✔
2674
         | ModuleTypeSubstitution m ->
3✔
2675
             let id =
2676
               Identifier.Maps.ModuleType.find m.id ident_map.module_types
2677
             in
2678
             let m' = module_type_substitution ident_map m in
3✔
2679
             Signature.ModuleTypeSubstitution (id, m')
3✔
2680
         | ModuleType m ->
17,100✔
2681
             let id =
2682
               Identifier.Maps.ModuleType.find m.id ident_map.module_types
2683
             in
2684
             let m' = Delayed.put (fun () -> module_type ident_map m) in
211✔
2685
             Signature.ModuleType (id, m')
17,100✔
2686
         | Value v ->
623✔
2687
             let id = Ident.Of_Identifier.value v.id in
2688
             let v' = Delayed.put (fun () -> value ident_map v) in
68✔
2689
             Signature.Value (id, v')
623✔
2690
         | Comment c -> Comment (docs_or_stop ident_map c)
407✔
2691
         | TypExt e -> TypExt (extension ident_map e)
52✔
2692
         | Exception e ->
29✔
2693
             let id = Ident.Of_Identifier.exception_ e.id in
2694
             Exception (id, exception_ ident_map e)
29✔
2695
         | Class (r, c) ->
57✔
2696
             let id = Identifier.Maps.Class.find c.id ident_map.classes in
2697
             Class (id, r, class_ ident_map c)
57✔
2698
         | ClassType (r, c) ->
37✔
2699
             let id =
2700
               Identifier.Maps.ClassType.find c.id ident_map.class_types
2701
             in
2702
             ClassType (id, r, class_type ident_map c)
37✔
2703
         | Open o -> Open (open_ ident_map o)
32✔
2704
         | Include i -> Include (include_ ident_map i))
200✔
2705
        sg.items
2706
      |> List.rev
35,053✔
2707
    in
2708
    let removed = List.map (removed_item ident_map) sg.removed in
35,053✔
2709
    { items; removed; compiled = sg.compiled; doc = docs ident_map sg.doc }
35,053✔
2710

2711
  and block_element _ b :
2712
      CComment.block_element Odoc_model.Comment.with_location =
2713
    match b with
1,589✔
2714
    | { Odoc_model.Location_.value = `Heading (attrs, label, text); location }
261✔
2715
      ->
2716
        let label = Ident.Of_Identifier.label label in
2717
        Odoc_model.Location_.same b
261✔
2718
          (`Heading { Label.attrs; label; text; location })
2719
    | { value = `Tag _; _ } as t -> t
56✔
2720
    | { value = #Odoc_model.Comment.nestable_block_element; _ } as n -> n
1,272✔
2721

2722
  and docs ident_map d = List.map (block_element ident_map) d
141,627✔
2723

2724
  and docs_or_stop ident_map = function
2725
    | `Docs d -> `Docs (docs ident_map d)
379✔
2726
    | `Stop -> `Stop
52✔
2727
end
2728

2729
let module_of_functor_argument (arg : FunctorParameter.parameter) =
2730
  {
8✔
2731
    Module.source_loc = None;
2732
    doc = [];
2733
    type_ = ModuleType arg.expr;
2734
    canonical = None;
2735
    hidden = false;
2736
  }
2737

2738
(** This is equivalent to {!Lang.extract_signature_doc}. *)
2739
let extract_signature_doc (s : Signature.t) =
2740
  match (s.doc, s.items) with
24✔
2741
  | [], Include { expansion_; status = `Inline; _ } :: _ -> expansion_.doc
1✔
2742
  | 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