3030(* cil *)
3131open GoblintCil
3232
33+ (* chlib *)
34+ open CHCommon
35+
3336(* chutil *)
3437open CHIndexTable
3538open CHStringIndexTable
39+ open CHTimingLog
40+ open CHTraceResult
3641open CHXmlDocument
3742
3843(* chcil *)
@@ -60,6 +65,7 @@ object (self)
6065 val location_table = mk_index_table " location-table"
6166 val string_table = mk_string_index_table " filename-table"
6267 val mutable tables = []
68+ val mutable cfilename = " "
6369
6470 initializer
6571 tables < - [
@@ -74,6 +80,8 @@ object (self)
7480 enuminfo_table
7581 ]
7682
83+ method set_filename s = cfilename < - s
84+
7785 method index_init_opt (iinfo : init option ) =
7886 match iinfo with
7987 | None -> (- 1 )
@@ -100,26 +108,60 @@ object (self)
100108 | Some i -> [self#index_init i]
101109 | _ -> [] in
102110 let tags = [vinfo.vname; storage_mfts#ts vinfo.vstorage] in
103- let args =
104- [vinfo.vid;
105- cd#index_typ vinfo.vtype;
106- cd#index_attributes vinfo.vattr;
107- ibool vinfo.vglob;
108- ibool vinfo.vinline;
109- self#index_location vinfo.vdecl;
110- ibool vinfo.vaddrof;
111- 0 ] @ vinit_ix in
112- varinfo_table#add (tags,args)
111+ let locix_r = self#index_location vinfo.vdecl in
112+ match locix_r with
113+ | Ok locix ->
114+ let args =
115+ [vinfo.vid;
116+ cd#index_typ vinfo.vtype;
117+ cd#index_attributes vinfo.vattr;
118+ ibool vinfo.vglob;
119+ ibool vinfo.vinline;
120+ locix;
121+ ibool vinfo.vaddrof;
122+ 0 ] @ vinit_ix in
123+ varinfo_table#add (tags,args)
124+ | Error e ->
125+ begin
126+ log_error
127+ " index_varinfo: %s; %s"
128+ vinfo.vname
129+ (String. concat " , " e);
130+ raise
131+ (CHFailure
132+ (LBLOCK [
133+ STR " index_varinfo: " ;
134+ STR vinfo.vname;
135+ STR " ; " ;
136+ STR (String. concat " , " e)]))
137+ end
113138
114139 method index_fieldinfo (finfo : fieldinfo ) =
115140 let tags = [finfo.fname] in
116- let args =
117- [finfo.fcomp.ckey;
118- cd#index_typ finfo.ftype;
119- (match finfo.fbitfield with Some b -> b | _ -> - 1 );
120- cd#index_attributes finfo.fattr;
121- self#index_location finfo.floc] in
122- fieldinfo_table#add (tags, args)
141+ let locix_r = self#index_location finfo.floc in
142+ match locix_r with
143+ | Ok locix ->
144+ let args =
145+ [finfo.fcomp.ckey;
146+ cd#index_typ finfo.ftype;
147+ (match finfo.fbitfield with Some b -> b | _ -> - 1 );
148+ cd#index_attributes finfo.fattr;
149+ locix
150+ ] in
151+ fieldinfo_table#add (tags, args)
152+ | Error e ->
153+ begin
154+ log_error
155+ " index fieldinfo: %s %s"
156+ finfo.fname
157+ (String. concat " , " e);
158+ raise
159+ (CHFailure
160+ (LBLOCK [
161+ STR " index fieldinfo: " ;
162+ STR finfo.fname;
163+ STR (String. concat " , " e)]))
164+ end
123165
124166 method index_compinfo (cinfo : compinfo ) =
125167 let tags = [cinfo.cname] in
@@ -131,10 +173,26 @@ object (self)
131173 compinfo_table#add (tags, args)
132174
133175 method index_enumitem (eitem : enumitem ) =
134- let (name,exp,loc) = eitem in
176+ let (name, exp, loc) = eitem in
135177 let tags = [name] in
136- let args = [cd#index_exp exp; self#index_location loc] in
137- enumitem_table#add (tags, args)
178+ let locix_r = self#index_location loc in
179+ match locix_r with
180+ | Ok locix ->
181+ let args = [cd#index_exp exp; locix] in
182+ enumitem_table#add (tags, args)
183+ | Error e ->
184+ begin
185+ log_error
186+ " index enumitem: %s %s"
187+ name
188+ (String. concat " , " e);
189+ raise
190+ (CHFailure
191+ (LBLOCK [
192+ STR " index enumitem: " ;
193+ STR name;
194+ STR (String. concat " , " e)]))
195+ end
138196
139197 method index_enuminfo (einfo : enuminfo ) =
140198 let tags = [einfo.ename; ikind_mfts#ts einfo.ekind] in
@@ -148,16 +206,20 @@ object (self)
148206 let args = [cd#index_typ tinfo.ttype] in
149207 typeinfo_table#add (tags,args)
150208
151- method index_location (loc : location ) =
209+ method index_location (loc : location ): int traceresult =
152210 if loc.byte = - 1 && loc.line = - 1 then
153- (- 1 )
211+ Ok (- 1 )
154212 else
155- let filename =
156- get_location_filename ! CHCilFileUtil. project_path_prefix " " loc.file in
157- let args = [self#index_filename filename; loc.byte; loc.line] in
158- location_table#add ([] ,args)
213+ let filename_r =
214+ get_location_filename
215+ ! CHCilFileUtil. project_path_prefix cfilename loc.file in
216+ tmap
217+ (fun filename ->
218+ let args = [self#index_filename filename; loc.byte; loc.line] in
219+ location_table#add ([] , args))
220+ filename_r
159221
160- method index_filename (f :string ) = string_table#add f
222+ method index_filename (f : string ) = string_table#add f
161223
162224 method write_xml_varinfo
163225 ?(tag =" ivinfo" ) (node : xml_element_int ) (vinfo : varinfo ) =
@@ -188,7 +250,13 @@ object (self)
188250
189251 method write_xml_location
190252 ?(tag =" iloc" ) (node : xml_element_int ) (loc : location ) =
191- node#setIntAttribute tag (self#index_location loc)
253+ let locix_r = self#index_location loc in
254+ match locix_r with
255+ | Ok locix -> node#setIntAttribute tag locix
256+ | Error e ->
257+ raise
258+ (CHFailure
259+ (LBLOCK [STR " write_xml_location: " ; STR (String. concat " , " e)]))
192260
193261 method write_xml (node : xml_element_int ) =
194262 let snode = xmlElement string_table#get_name in
0 commit comments