@@ -21,130 +21,10 @@ let fold_dirs ~dirs ~f ~init =
2121 acc dir)
2222 (Ok init)
2323
24- module H = Hashtbl. Make (Odoc_model.Paths. Identifier )
25-
26- module Occtbl : sig
27- type item = { direct : int ; indirect : int ; sub : item H .t }
28- type t = item H .t
29- type key = Odoc_model.Paths.Identifier .t
30- val v : unit -> t
31-
32- val add : t -> key -> unit
33-
34- val iter : (key -> item -> unit ) -> t -> unit
35-
36- val get : t -> key -> item option
37- end = struct
38- type item = { direct : int ; indirect : int ; sub : item H .t }
39- type t = item H .t
40- type key = Odoc_model.Paths.Identifier .t
41-
42- let v_item () = { direct = 0 ; indirect = 0 ; sub = H. create 0 }
43-
44- let v () = H. create 0
45-
46- let add tbl id =
47- let rec add ?(kind = `Indirect ) id =
48- let incr htbl id =
49- let { direct; indirect; sub } =
50- try H. find htbl id with Not_found -> v_item ()
51- in
52- let direct, indirect =
53- match kind with
54- | `Direct -> (direct + 1 , indirect)
55- | `Indirect -> (direct, indirect + 1 )
56- in
57- H. replace htbl id { direct; indirect; sub };
58- sub
59- in
60- let do_ parent =
61- let htbl = add (parent :> key ) in
62- incr htbl id
63- in
64- match id.iv with
65- | `InstanceVariable (parent , _ ) -> do_ parent
66- | `Parameter (parent , _ ) -> do_ parent
67- | `Module (parent , _ ) -> do_ parent
68- | `ModuleType (parent , _ ) -> do_ parent
69- | `Method (parent , _ ) -> do_ parent
70- | `Field (parent , _ ) -> do_ parent
71- | `Extension (parent , _ ) -> do_ parent
72- | `Type (parent , _ ) -> do_ parent
73- | `CoreType _ -> incr tbl id
74- | `Constructor (parent , _ ) -> do_ parent
75- | `Exception (parent , _ ) -> do_ parent
76- | `ExtensionDecl (parent , _ , _ ) -> do_ parent
77- | `Class (parent , _ ) -> do_ parent
78- | `Value (parent , _ ) -> do_ parent
79- | `ClassType (parent , _ ) -> do_ parent
80- | `Root _ -> incr tbl id
81- | `SourcePage _ | `Page _ | `LeafPage _ | `SourceLocation _
82- | `CoreException _ | `Label _ | `SourceLocationMod _ | `Result _
83- | `AssetFile _ | `SourceDir _ | `SourceLocationInternal _ ->
84- assert false
85- in
86- let _htbl = add ~kind: `Direct id in
87- ()
88-
89- let rec get t id =
90- let do_ parent =
91- get t (parent :> key ) |> function
92- | None -> None
93- | Some { sub; _ } -> ( try Some (H. find sub id) with Not_found -> None )
94- in
95- match id.iv with
96- | `InstanceVariable (parent , _ ) -> do_ parent
97- | `Parameter (parent , _ ) -> do_ parent
98- | `Module (parent , _ ) -> do_ parent
99- | `ModuleType (parent , _ ) -> do_ parent
100- | `Method (parent , _ ) -> do_ parent
101- | `Field (parent , _ ) -> do_ parent
102- | `Extension (parent , _ ) -> do_ parent
103- | `ExtensionDecl (parent , _ , _ ) -> do_ parent
104- | `Type (parent , _ ) -> do_ parent
105- | `Constructor (parent , _ ) -> do_ parent
106- | `Exception (parent , _ ) -> do_ parent
107- | `Class (parent , _ ) -> do_ parent
108- | `Value (parent , _ ) -> do_ parent
109- | `ClassType (parent , _ ) -> do_ parent
110- | `Root _ -> ( try Some (H. find t id) with Not_found -> None )
111- | `SourcePage _ | `Page _ | `LeafPage _ | `CoreType _ | `SourceLocation _
112- | `CoreException _ | `Label _ | `SourceLocationMod _ | `Result _
113- | `AssetFile _ | `SourceDir _ | `SourceLocationInternal _ ->
114- assert false
115-
116- let rec iter f tbl =
117- H. iter
118- (fun id v ->
119- iter f v.sub;
120- f id v)
121- tbl
122- end
123-
12424let count ~dst ~warnings_options :_ directories include_hidden =
125- let htbl = H. create 100 in
25+ let htbl = Odoc_occurrences.Table. v () in
12626 let f () (unit : Odoc_model.Lang.Compilation_unit.t ) =
127- let incr tbl p =
128- let p = (p :> Odoc_model.Paths.Path.Resolved.t ) in
129- let id = Odoc_model.Paths.Path.Resolved. identifier p in
130- if (not (Odoc_model.Paths.Path.Resolved. is_hidden p)) || include_hidden
131- then Occtbl. add tbl id
132- in
133- let () =
134- List. iter
135- (function
136- | ( Odoc_model.Lang.Source_info. Module
137- { documentation = Some (`Resolved p); _ },
138- _ ) ->
139- incr htbl p
140- | Value { documentation = Some (`Resolved p ); _ } , _ -> incr htbl p
141- | ModuleType { documentation = Some (`Resolved p ); _ } , _ ->
142- incr htbl p
143- | Type { documentation = Some (`Resolved p ); _ } , _ -> incr htbl p
144- | _ -> () )
145- (match unit .source_info with None -> [] | Some i -> i.infos)
146- in
147- ()
27+ Odoc_occurrences. of_impl ~include_hidden unit htbl
14828 in
14929 fold_dirs ~dirs: directories ~f ~init: () >> = fun () ->
15030 Fs.Directory. mkdir_p (Fs.File. dirname dst);
@@ -175,27 +55,18 @@ let aggregate files file_list ~warnings_options:_ ~dst =
17555 try
17656 parse_input_files file_list >> = fun new_files ->
17757 let files = files @ new_files in
178- let from_file file : Occtbl .t =
58+ let from_file file : Odoc_occurrences.Table .t =
17959 let ic = open_in_bin (Fs.File. to_string file) in
18060 Marshal. from_channel ic
18161 in
182- let rec loop n f =
183- if n > 0 then (
184- f () ;
185- loop (n - 1 ) f)
186- else ()
187- in
18862 let occtbl =
18963 match files with
190- | [] -> H. create 0
191- | file1 :: files ->
192- let acc = from_file file1 in
64+ | [] -> Odoc_occurrences.Table. v ()
65+ | file :: files ->
66+ let acc = from_file file in
19367 List. iter
19468 (fun file ->
195- Occtbl. iter
196- (fun id { direct; _ } ->
197- loop direct (fun () -> Occtbl. add acc id))
198- (from_file file))
69+ Odoc_occurrences. aggregate ~tbl: acc ~data: (from_file file))
19970 files;
20071 acc
20172 in
0 commit comments