@ -7,6 +7,7 @@
open ! IStd
module Implementation = struct
let attribute_replace_statement =
(* The innermost SELECT returns either the current attributes_kind and source_file associated with
the given proc name , or default values of ( - 1 , " " ) . These default values have the property that
@ -41,7 +42,8 @@ let attribute_replace_statement =
let replace_attributes ~ pname_str ~ pname ~ akind ~ source_file ~ attributes ~ proc_desc ~ callees =
ResultsDatabase . with_registered_statement attribute_replace_statement ~ f : ( fun db replace_stmt ->
ResultsDatabase . with_registered_statement attribute_replace_statement
~ f : ( fun db replace_stmt ->
Sqlite3 . bind replace_stmt 1 (* :pname *) pname
| > SqliteUtils . check_result_code db ~ log : " replace bind pname " ;
Sqlite3 . bind replace_stmt 2 (* :proc_name_hum *) ( Sqlite3 . Data . TEXT pname_str )
@ -135,14 +137,67 @@ let merge_dbs ~infer_out_src =
let db_file = infer_out_src ^/ ResultsDatabase . database_filename in
let main_db = ResultsDatabase . get_database () in
Sqlite3 . exec main_db ( Printf . sprintf " ATTACH '%s' AS attached " db_file )
| > SqliteUtils . check_result_code main_db ~ log : ( Printf . sprintf " attaching database '%s' " db_file ) ;
| > SqliteUtils . check_result_code main_db
~ log : ( Printf . sprintf " attaching database '%s' " db_file ) ;
merge_procedures_table ~ db_file ;
merge_source_files_table ~ db_file ;
Sqlite3 . exec main_db " DETACH attached "
| > SqliteUtils . check_result_code main_db ~ log : ( Printf . sprintf " detaching database '%s' " db_file ) ;
| > SqliteUtils . check_result_code main_db
~ log : ( Printf . sprintf " detaching database '%s' " db_file ) ;
()
let canonicalize () =
let db = ResultsDatabase . get_database () in
SqliteUtils . exec db ~ log : " running VACUUM " ~ stmt : " VACUUM "
end
module Command = struct
type t =
| ReplaceAttributes of
{ pname_str : string
; pname : Sqlite3 . Data . t
; akind : int64
; source_file : Sqlite3 . Data . t
; attributes : Sqlite3 . Data . t
; proc_desc : Sqlite3 . Data . t
; callees : Sqlite3 . Data . t }
| AddSourceFile of
{ source_file : Sqlite3 . Data . t
; tenv : Sqlite3 . Data . t
; integer_type_widths : Sqlite3 . Data . t
; proc_names : Sqlite3 . Data . t }
| MarkAllSourceFilesStale
| MergeDBs of { infer_out_src : string }
| Vacuum
let execute = function
| ReplaceAttributes { pname_str ; pname ; akind ; source_file ; attributes ; proc_desc ; callees } ->
Implementation . replace_attributes ~ pname_str ~ pname ~ akind ~ source_file ~ attributes
~ proc_desc ~ callees
| AddSourceFile { source_file ; tenv ; integer_type_widths ; proc_names } ->
Implementation . add_source_file ~ source_file ~ tenv ~ integer_type_widths ~ proc_names
| MarkAllSourceFilesStale ->
Implementation . mark_all_source_files_stale ()
| MergeDBs { infer_out_src } ->
Implementation . merge_dbs ~ infer_out_src
| Vacuum ->
Implementation . canonicalize ()
end
let perform cmd = Command . execute cmd
let replace_attributes ~ pname_str ~ pname ~ akind ~ source_file ~ attributes ~ proc_desc ~ callees =
Command . ReplaceAttributes { pname_str ; pname ; akind ; source_file ; attributes ; proc_desc ; callees }
| > perform
let add_source_file ~ source_file ~ tenv ~ integer_type_widths ~ proc_names =
Command . AddSourceFile { source_file ; tenv ; integer_type_widths ; proc_names } | > perform
let mark_all_source_files_stale () = perform Command . MarkAllSourceFilesStale
let merge_dbs ~ infer_out_src = Command . MergeDBs { infer_out_src } | > perform
let canonicalize () = perform Command . Vacuum