[sqlite] calls in the db

Reviewed By: mbouaziz, martintrojer

Differential Revision: D15199334

fbshipit-source-id: 7938a2024
master
Nikos Gorogiannis 6 years ago committed by Facebook Github Bot
parent d5755fe5c0
commit d082f36448

@ -52,7 +52,7 @@ let replace_statement =
ResultsDatabase.register_statement
{|
INSERT OR REPLACE INTO procedures
SELECT :pname, :proc_name_hum, :akind, :sfile, :pattr, :cfg
SELECT :pname, :proc_name_hum, :akind, :sfile, :pattr, :cfg, :callees
FROM (
SELECT NULL
FROM (
@ -64,7 +64,7 @@ FROM (
OR (attr_kind = :akind AND source_file <= :sfile) )|}
let replace pname pname_blob akind loc_file attr_blob proc_desc =
let replace pname pname_blob akind loc_file attr_blob proc_desc callees =
ResultsDatabase.with_registered_statement replace_statement ~f:(fun db replace_stmt ->
Sqlite3.bind replace_stmt 1 (* :pname *) pname_blob
|> SqliteUtils.check_result_code db ~log:"replace bind pname" ;
@ -79,6 +79,8 @@ let replace pname pname_blob akind loc_file attr_blob proc_desc =
|> SqliteUtils.check_result_code db ~log:"replace bind proc attributes" ;
Sqlite3.bind replace_stmt 6 (* :cfg *) (Procdesc.SQLite.serialize proc_desc)
|> SqliteUtils.check_result_code db ~log:"replace bind cfg" ;
Sqlite3.bind replace_stmt 7 (* :callees *) (Typ.Procname.SQLiteList.serialize callees)
|> SqliteUtils.check_result_code db ~log:"replace bind callees" ;
SqliteUtils.result_unit db ~finalize:false ~log:"Attributes.replace" replace_stmt )
@ -134,6 +136,7 @@ let store ~proc_desc (attr : ProcAttributes.t) =
(SourceFile.SQLite.serialize attr.loc.Location.file)
(ProcAttributes.SQLite.serialize attr)
proc_desc
(Option.map proc_desc ~f:Procdesc.get_static_callees |> Option.value ~default:[])
let load_defined pname = Typ.Procname.SQLite.serialize pname |> find ~defined:true

@ -501,6 +501,18 @@ let fold_instrs pdesc ~init ~f =
fold_nodes ~f:fold_node ~init pdesc
let get_static_callees pdesc =
let callees =
fold_instrs pdesc ~init:Typ.Procname.Set.empty ~f:(fun acc _node instr ->
match instr with
| Sil.Call (_, Exp.Const (Const.Cfun callee_pn), _, _, _) ->
Typ.Procname.Set.add callee_pn acc
| _ ->
acc )
in
Typ.Procname.Set.remove (get_proc_name pdesc) callees |> Typ.Procname.Set.elements
let find_map_nodes pdesc ~f = List.find_map ~f (get_nodes pdesc)
let find_map_instrs pdesc ~f =

@ -248,6 +248,9 @@ val get_ret_var : t -> Pvar.t
val get_start_node : t -> Node.t
val get_static_callees : t -> Typ.Procname.t list
(** get a list of unique static callees excluding self *)
val is_defined : t -> bool
(** Return [true] iff the procedure is defined, and not just declared *)

@ -16,7 +16,7 @@ let merge_procedures_table ~db_file =
Sqlite3.exec db
{|
INSERT OR REPLACE INTO procedures
SELECT sub.proc_name, sub.proc_name_hum, sub.attr_kind, sub.source_file, sub.proc_attributes, sub.cfg
SELECT sub.proc_name, sub.proc_name_hum, sub.attr_kind, sub.source_file, sub.proc_attributes, sub.cfg, sub.callees
FROM (
attached.procedures AS sub
LEFT OUTER JOIN procedures AS main

@ -20,6 +20,7 @@ let procedures_schema =
, source_file TEXT NOT NULL
, proc_attributes BLOB NOT NULL
, cfg BLOB
, callees BLOB NOT NULL
)|}

Loading…
Cancel
Save