11open Result
22module Error = Odoc_model. Error
33
4- module Lookup_def = Lookup_def
5-
64let read_string parent_definition filename text =
75 let location =
86 let pos =
@@ -46,9 +44,17 @@ exception Make_root_error of string
4644
4745(* * [cmt_info.cmt_annots = Implementation _] *)
4846let read_cmt_infos' source_id_opt id cmt_info =
49- match Implementation. of_cmt source_id_opt id cmt_info with
50- | None , _ -> None
51- | Some shape , jmp_infos -> Some (shape, jmp_infos)
47+ match Odoc_model.Compat. shape_of_cmt_infos cmt_info with
48+ | Some shape -> begin
49+ let uid_to_loc = cmt_info.cmt_uid_to_loc in
50+ match source_id_opt, cmt_info.cmt_annots with
51+ | Some source_id , Implementation impl ->
52+ let (map, source_infos) = Implementation. of_cmt source_id id impl uid_to_loc in
53+ (Some shape, map, Some { Odoc_model.Lang.Source_info. id= source_id; infos = source_infos})
54+ | _ , _ ->
55+ (Some shape, Odoc_model.Compat. empty_map, None )
56+ end
57+ | None -> (None , Odoc_model.Compat. empty_map, None )
5258
5359let read_cmt_infos source_id_opt id ~filename () =
5460 match Cmt_format. read_cmt filename with
@@ -59,7 +65,7 @@ let read_cmt_infos source_id_opt id ~filename () =
5965 | _ -> raise Not_an_implementation )
6066
6167let make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
62- ?canonical content =
68+ ?canonical ? shape ~ uid_to_id ~ source_info content =
6369 let open Odoc_model.Lang.Compilation_unit in
6470 let interface, digest =
6571 match interface with
@@ -95,16 +101,18 @@ let make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
95101 expansion = None ;
96102 linked = false ;
97103 canonical;
98- source_info = None ;
104+ source_info;
105+ shape;
106+ uid_to_id;
99107 }
100108
101109let compilation_unit_of_sig ~make_root ~imports ~interface ?sourcefile ~name ~id
102- ?canonical sg =
110+ ?canonical ? shape ~ uid_to_id sg =
103111 let content = Odoc_model.Lang.Compilation_unit. Module sg in
104112 make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
105- ?canonical content
113+ ?canonical ?shape ~uid_to_id content
106114
107- let read_cmti ~make_root ~parent ~filename () =
115+ let read_cmti ~make_root ~parent ~filename ~ cmt_filename_opt ~ source_id_opt () =
108116 let cmt_info = Cmt_format. read_cmt filename in
109117 match cmt_info.cmt_annots with
110118 | Interface intf -> (
@@ -118,8 +126,15 @@ let read_cmti ~make_root ~parent ~filename () =
118126 cmt_info.cmt_builddir )
119127 in
120128 let id, sg, canonical = Cmti. read_interface parent name intf in
129+ let (shape, uid_to_id, source_info) =
130+ match cmt_filename_opt with
131+ | Some cmt_filename ->
132+ read_cmt_infos source_id_opt id ~filename: cmt_filename ()
133+ | None ->
134+ (None , Odoc_model.Compat. empty_map, None )
135+ in
121136 compilation_unit_of_sig ~make_root ~imports: cmt_info.cmt_imports
122- ~interface ~sourcefile ~name ~id ?canonical sg)
137+ ~interface ~sourcefile ~name ~id ?shape ~uid_to_id ~source_info ? canonical sg)
123138 | _ -> raise Not_an_interface
124139
125140let read_cmt ~make_root ~parent ~filename ~source_id_opt () =
@@ -161,14 +176,14 @@ let read_cmt ~make_root ~parent ~filename ~source_id_opt () =
161176 items
162177 in
163178 let content = Odoc_model.Lang.Compilation_unit. Pack items in
164- ( make_compilation_unit ~make_root ~imports ~interface ~sourcefile
165- ~name ~id content,
166- None )
179+ make_compilation_unit ~make_root ~imports ~interface ~sourcefile
180+ ~name ~id ~uid_to_id: Odoc_model.Compat. empty_map ~source_info: None content
167181 | Implementation impl ->
168182 let id, sg, canonical = Cmt. read_implementation parent name impl in
169- ( compilation_unit_of_sig ~make_root ~imports ~interface ~sourcefile
170- ~name ~id ?canonical sg,
171- read_cmt_infos' source_id_opt id cmt_info )
183+ let (shape, uid_to_id, source_info) =
184+ read_cmt_infos source_id_opt id ~filename () in
185+ compilation_unit_of_sig ~make_root ~imports ~interface ~sourcefile
186+ ~name ~id ?canonical ?shape ~uid_to_id ~source_info sg
172187 | _ -> raise Not_an_implementation )
173188
174189let read_cmi ~make_root ~parent ~filename () =
@@ -179,7 +194,7 @@ let read_cmi ~make_root ~parent ~filename () =
179194 Cmi. read_interface parent name
180195 (Odoc_model.Compat. signature cmi_info.cmi_sign)
181196 in
182- compilation_unit_of_sig ~make_root ~imports ~interface ~name ~id sg
197+ compilation_unit_of_sig ~make_root ~imports ~interface ~name ~id ~source_info: None ~uid_to_id: Odoc_model.Compat. empty_map sg
183198 | _ -> raise Corrupted
184199
185200(* * Catch errors from reading the object files and some internal errors *)
@@ -195,11 +210,8 @@ let wrap_errors ~filename f =
195210 | Not_an_interface -> not_an_interface filename
196211 | Make_root_error m -> error_msg filename m)
197212
198- let read_cmt_infos source_id_opt id ~filename =
199- wrap_errors ~filename (read_cmt_infos source_id_opt id ~filename )
200-
201- let read_cmti ~make_root ~parent ~filename =
202- wrap_errors ~filename (read_cmti ~make_root ~parent ~filename )
213+ let read_cmti ~make_root ~parent ~filename ~source_id_opt ~cmt_filename_opt =
214+ wrap_errors ~filename (read_cmti ~make_root ~parent ~filename ~source_id_opt ~cmt_filename_opt )
203215
204216let read_cmt ~make_root ~parent ~filename ~source_id_opt =
205217 wrap_errors ~filename (read_cmt ~make_root ~parent ~filename ~source_id_opt )
0 commit comments