@@ -34,130 +34,10 @@ let fold_dirs ~dirs ~f ~init =
3434 acc dir)
3535 (Ok init)
3636
37- module H = Hashtbl. Make (Odoc_model.Paths. Identifier )
38-
39- module Occtbl : sig
40- type item = { direct : int ; indirect : int ; sub : item H .t }
41- type t = item H .t
42- type key = Odoc_model.Paths.Identifier .t
43- val v : unit -> t
44-
45- val add : t -> key -> unit
46-
47- val iter : (key -> item -> unit ) -> t -> unit
48-
49- val get : t -> key -> item option
50- end = struct
51- type item = { direct : int ; indirect : int ; sub : item H .t }
52- type t = item H .t
53- type key = Odoc_model.Paths.Identifier .t
54-
55- let v_item () = { direct = 0 ; indirect = 0 ; sub = H. create 0 }
56-
57- let v () = H. create 0
58-
59- let add tbl id =
60- let rec add ?(kind = `Indirect ) id =
61- let incr htbl id =
62- let { direct; indirect; sub } =
63- try H. find htbl id with Not_found -> v_item ()
64- in
65- let direct, indirect =
66- match kind with
67- | `Direct -> (direct + 1 , indirect)
68- | `Indirect -> (direct, indirect + 1 )
69- in
70- H. replace htbl id { direct; indirect; sub };
71- sub
72- in
73- let do_ parent =
74- let htbl = add (parent :> key ) in
75- incr htbl id
76- in
77- match id.iv with
78- | `InstanceVariable (parent , _ ) -> do_ parent
79- | `Parameter (parent , _ ) -> do_ parent
80- | `Module (parent , _ ) -> do_ parent
81- | `ModuleType (parent , _ ) -> do_ parent
82- | `Method (parent , _ ) -> do_ parent
83- | `Field (parent , _ ) -> do_ parent
84- | `Extension (parent , _ ) -> do_ parent
85- | `Type (parent , _ ) -> do_ parent
86- | `CoreType _ -> incr tbl id
87- | `Constructor (parent , _ ) -> do_ parent
88- | `Exception (parent , _ ) -> do_ parent
89- | `ExtensionDecl (parent , _ , _ ) -> do_ parent
90- | `Class (parent , _ ) -> do_ parent
91- | `Value (parent , _ ) -> do_ parent
92- | `ClassType (parent , _ ) -> do_ parent
93- | `Root _ -> incr tbl id
94- | `SourcePage _ | `Page _ | `LeafPage _ | `SourceLocation _
95- | `CoreException _ | `Label _ | `SourceLocationMod _ | `Result _
96- | `AssetFile _ | `SourceDir _ | `SourceLocationInternal _ ->
97- assert false
98- in
99- let _htbl = add ~kind: `Direct id in
100- ()
101-
102- let rec get t id =
103- let do_ parent =
104- get t (parent :> key ) |> function
105- | None -> None
106- | Some { sub; _ } -> ( try Some (H. find sub id) with Not_found -> None )
107- in
108- match id.iv with
109- | `InstanceVariable (parent , _ ) -> do_ parent
110- | `Parameter (parent , _ ) -> do_ parent
111- | `Module (parent , _ ) -> do_ parent
112- | `ModuleType (parent , _ ) -> do_ parent
113- | `Method (parent , _ ) -> do_ parent
114- | `Field (parent , _ ) -> do_ parent
115- | `Extension (parent , _ ) -> do_ parent
116- | `ExtensionDecl (parent , _ , _ ) -> do_ parent
117- | `Type (parent , _ ) -> do_ parent
118- | `Constructor (parent , _ ) -> do_ parent
119- | `Exception (parent , _ ) -> do_ parent
120- | `Class (parent , _ ) -> do_ parent
121- | `Value (parent , _ ) -> do_ parent
122- | `ClassType (parent , _ ) -> do_ parent
123- | `Root _ -> ( try Some (H. find t id) with Not_found -> None )
124- | `SourcePage _ | `Page _ | `LeafPage _ | `CoreType _ | `SourceLocation _
125- | `CoreException _ | `Label _ | `SourceLocationMod _ | `Result _
126- | `AssetFile _ | `SourceDir _ | `SourceLocationInternal _ ->
127- assert false
128-
129- let rec iter f tbl =
130- H. iter
131- (fun id v ->
132- iter f v.sub;
133- f id v)
134- tbl
135- end
136-
13737let count ~dst ~warnings_options :_ directories include_hidden =
138- let htbl = H. create 100 in
38+ let htbl = Odoc_occurrences.Table. v () in
13939 let f () (unit : Odoc_model.Lang.Implementation.t ) =
140- let incr tbl p =
141- let p = (p :> Odoc_model.Paths.Path.Resolved.t ) in
142- let id = Odoc_model.Paths.Path.Resolved. identifier p in
143- if (not (Odoc_model.Paths.Path.Resolved. is_hidden p)) || include_hidden
144- then Occtbl. add tbl id
145- in
146- let () =
147- List. iter
148- (function
149- | ( Odoc_model.Lang.Source_info. Module
150- { documentation = Some (`Resolved p); _ },
151- _ ) ->
152- incr htbl p
153- | Value { documentation = Some (`Resolved p ); _ } , _ -> incr htbl p
154- | ModuleType { documentation = Some (`Resolved p ); _ } , _ ->
155- incr htbl p
156- | Type { documentation = Some (`Resolved p ); _ } , _ -> incr htbl p
157- | _ -> () )
158- unit .source_info
159- in
160- ()
40+ Odoc_occurrences. of_impl ~include_hidden unit htbl
16141 in
16242 fold_dirs ~dirs: directories ~f ~init: () >> = fun () ->
16343 Fs.Directory. mkdir_p (Fs.File. dirname dst);
@@ -188,27 +68,18 @@ let aggregate files file_list ~warnings_options:_ ~dst =
18868 try
18969 parse_input_files file_list >> = fun new_files ->
19070 let files = files @ new_files in
191- let from_file file : Occtbl .t =
71+ let from_file file : Odoc_occurrences.Table .t =
19272 let ic = open_in_bin (Fs.File. to_string file) in
19373 Marshal. from_channel ic
19474 in
195- let rec loop n f =
196- if n > 0 then (
197- f () ;
198- loop (n - 1 ) f)
199- else ()
200- in
20175 let occtbl =
20276 match files with
203- | [] -> H. create 0
204- | file1 :: files ->
205- let acc = from_file file1 in
77+ | [] -> Odoc_occurrences.Table. v ()
78+ | file :: files ->
79+ let acc = from_file file in
20680 List. iter
20781 (fun file ->
208- Occtbl. iter
209- (fun id { direct; _ } ->
210- loop direct (fun () -> Occtbl. add acc id))
211- (from_file file))
82+ Odoc_occurrences. aggregate ~tbl: acc ~data: (from_file file))
21283 files;
21384 acc
21485 in
0 commit comments