@@ -144,11 +144,12 @@ module IdentHashtbl = Hashtbl.Make (struct
144
144
let hash = Hashtbl. hash
145
145
end )
146
146
147
- (* populate a [loc_to_id] and an [ident_to_id] map with local informations. Also
148
- removes the definitions from the list, since their information has been taken
149
- into account *)
150
- let process_local_defs source_id poses loc_tbl ident_to_id =
151
- List. filter_map
147
+ module UidHashtbl = Shape.Uid. Tbl
148
+
149
+ (* Adds the local definitions found in traverse infos to the [loc_to_id] and
150
+ [ident_to_id] tables. *)
151
+ let populate_local_defs source_id poses loc_to_id ident_to_id =
152
+ List. iter
152
153
(function
153
154
| Typedtree_traverse.Analysis. Definition id , loc ->
154
155
let name =
@@ -159,9 +160,8 @@ let process_local_defs source_id poses loc_tbl ident_to_id =
159
160
Odoc_model.Paths.Identifier.Mk. source_location_int (source_id, name)
160
161
in
161
162
IdentHashtbl. add ident_to_id id identifier;
162
- LocHashtbl. add loc_tbl loc identifier;
163
- None
164
- | x -> Some x)
163
+ LocHashtbl. add loc_to_id loc identifier
164
+ | _ -> () )
165
165
poses
166
166
167
167
(* In order to turn an identifier into a source identifier, we need to generate
@@ -243,44 +243,44 @@ let anchor_of_identifier id =
243
243
in
244
244
anchor_of_identifier [] id |> String. concat " ."
245
245
246
- (* Adds the global defs from the odoc environment to [loc_to_id] table *)
247
- let process_global_defs env source_id loc_to_id =
246
+ (* Adds the global definitions, found in the [uid_to_loc], to the [loc_to_id]
247
+ and [uid_to_id] tables. *)
248
+ let populate_global_defs env source_id loc_to_id uid_to_loc uid_to_id =
248
249
let mk_src_id id =
249
250
let name = Odoc_model.Names.DefName. make_std (anchor_of_identifier id) in
250
251
(Odoc_model.Paths.Identifier.Mk. source_location (source_id, name)
251
252
:> Odoc_model.Paths.Identifier.SourceLocation. t)
252
253
in
253
- Ident_env. iter_located_identifier env @@ fun loc id ->
254
- LocHashtbl. add loc_to_id loc (mk_src_id id)
255
-
256
- (* The [uid_to_id] is useful as when resolving a shape, we get the uid. *)
257
- let build_uid_to_id source_id uid_to_loc loc_to_id =
258
- let uid_to_loc_map = Shape.Uid.Tbl. to_map uid_to_loc in
254
+ let () =
255
+ Ident_env. iter_located_identifier env @@ fun loc id ->
256
+ LocHashtbl. add loc_to_id loc (mk_src_id id)
257
+ in
259
258
let mk_src_id () =
260
259
let name =
261
260
Odoc_model.Names.DefName. make_std (Printf. sprintf " def_%d" (counter () ))
262
261
in
263
262
(Odoc_model.Paths.Identifier.Mk. source_location (source_id, name)
264
263
:> Odoc_model.Paths.Identifier.SourceLocation. t)
265
264
in
266
- Shape.Uid.Map. filter_map
265
+ Shape.Uid.Tbl. iter
267
266
(fun uid loc ->
268
- if loc.Location. loc_ghost then None
267
+ if loc.Location. loc_ghost then ()
269
268
else
270
269
match LocHashtbl. find_opt loc_to_id loc with
271
- | Some id -> Some id
270
+ | Some id -> UidHashtbl. add uid_to_id uid id
272
271
| None -> (
273
272
(* In case there is no entry for the location of the uid, we add one. *)
274
273
match uid with
275
274
| Item _ ->
276
275
let id = mk_src_id () in
277
276
LocHashtbl. add loc_to_id loc id;
278
- Some id
279
- | Compilation_unit _ -> None
280
- | _ -> None ))
281
- uid_to_loc_map
277
+ UidHashtbl. add uid_to_id uid id
278
+ | Compilation_unit _ -> ()
279
+ | _ -> () ))
280
+ uid_to_loc
282
281
283
- (* Turns [Typedtree_traverse] occurrence information into proper source infos *)
282
+ (* Extract [Typedtree_traverse] occurrence information and turn them into proper
283
+ source infos *)
284
284
let process_occurrences poses uid_to_id ident_to_id =
285
285
List. filter_map
286
286
(function
@@ -290,14 +290,14 @@ let process_occurrences poses uid_to_id ident_to_id =
290
290
Some (Odoc_model.Lang.Source_info. Value anchor, pos_of_loc loc)
291
291
| None -> None )
292
292
| Value (DefJmp x ), loc -> (
293
- match Shape.Uid.Map. find_opt x uid_to_id with
293
+ match UidHashtbl. find_opt uid_to_id x with
294
294
| Some id -> Some (Value id, pos_of_loc loc)
295
295
| None -> None )
296
296
| Definition _ , _ -> None )
297
297
poses
298
298
299
299
(* Add definition source info from the [loc_to_id] table *)
300
- let add_definitions occurrences loc_to_id =
300
+ let add_definitions loc_to_id occurrences =
301
301
LocHashtbl. fold
302
302
(fun loc id acc ->
303
303
(Odoc_model.Lang.Source_info. Definition id, pos_of_loc loc) :: acc)
@@ -310,25 +310,26 @@ let read_cmt_infos source_id_opt id cmt_info =
310
310
match (source_id_opt, cmt_info.cmt_annots) with
311
311
| Some source_id , Implementation impl ->
312
312
let env = Env. of_structure id impl in
313
- let occ_infos =
313
+ let traverse_infos =
314
314
Typedtree_traverse. of_cmt env uid_to_loc impl |> List. rev
315
315
(* Information are accumulated in a list. We need to have the
316
316
first info first in the list, to assign anchors with increasing
317
317
numbers, so that adding some content at the end of a file does
318
318
not modify the anchors for existing anchors. *)
319
319
in
320
320
let loc_to_id = LocHashtbl. create 10
321
- and ident_to_id = IdentHashtbl. create 10 in
322
- let occurrences =
323
- process_local_defs source_id occ_infos loc_to_id ident_to_id
321
+ and ident_to_id = IdentHashtbl. create 10
322
+ and uid_to_id = UidHashtbl. create 10 in
323
+ let () =
324
+ (* populate [loc_to_id], [ident_to_id] and [uid_to_id] *)
325
+ populate_local_defs source_id traverse_infos loc_to_id ident_to_id;
326
+ populate_global_defs env source_id loc_to_id uid_to_loc uid_to_id
324
327
in
325
- let () = process_global_defs env source_id loc_to_id in
326
- let uid_to_id = build_uid_to_id source_id uid_to_loc loc_to_id in
327
- let occurrences =
328
- process_occurrences occurrences uid_to_id ident_to_id
328
+ let source_infos =
329
+ process_occurrences traverse_infos uid_to_id ident_to_id
330
+ |> add_definitions loc_to_id
329
331
in
330
- let source_infos = add_definitions occurrences loc_to_id in
331
- ( Some (shape, uid_to_id),
332
+ ( Some (shape, Shape.Uid.Tbl. to_map uid_to_id),
332
333
Some
333
334
{
334
335
Odoc_model.Lang.Source_info. id = source_id;
0 commit comments