@ -7,37 +7,35 @@
open ! IStd
open ! IStd
(* * Module to register and invoke callbacks *)
type proc_callback_args =
type proc_callback_args =
{ get_procs_in_file : Procname . t -> Procname . t list ; summary : Summary . t ; exe_env : Exe_env . t }
{ get_procs_in_file : Procname . t -> Procname . t list ; summary : Summary . t ; exe_env : Exe_env . t }
type proc_callback_t = proc_callback_args -> Summary . t
type proc_callback_t = proc_callback_args -> Summary . t
type cluster _callback_args =
type file _callback_args =
{ procedures : Procname . t list ; source_file : SourceFile . t ; exe_env : Exe_env . t }
{ procedures : Procname . t list ; source_file : SourceFile . t ; exe_env : Exe_env . t }
type cluster_callback_t = cluster _callback_args -> unit
type file_callback_t = file _callback_args -> unit
type procedure_callback =
type procedure_callback =
{ name: string ; dynamic_dispatch : bool ; language : Language . t ; callback : proc_callback_t }
{ checker_ name: string ; dynamic_dispatch : bool ; language : Language . t ; callback : proc_callback_t }
type cluster_callback = { name: string ; language : Language . t ; callback : cluster _callback_t}
type file_callback = { checker_ name: string ; language : Language . t ; callback : file _callback_t}
let procedure_callbacks = ref []
let procedure_callbacks = ref []
let cluster _callbacks = ref []
let file _callbacks = ref []
let register_procedure_callback ~ name ? ( dynamic_dispatch = false ) language
let register_procedure_callback ~ checker_ name ? ( dynamic_dispatch = false ) language
( callback : proc_callback_t ) =
( callback : proc_callback_t ) =
procedure_callbacks := { name ; dynamic_dispatch ; language ; callback } :: ! procedure_callbacks
procedure_callbacks :=
{ checker_name ; dynamic_dispatch ; language ; callback } :: ! procedure_callbacks
let register_ cluster_callback ~ name language ( callback : cluster _callback_t) =
let register_ file_callback ~ checker_name language ( callback : file _callback_t) =
cluster_callbacks := { name ; language ; callback } :: ! cluster _callbacks
file_callbacks := { checker_name ; language ; callback } :: ! file _callbacks
(* * Invoke all registered procedure callbacks on the given procedure. *)
let iterate_procedure_callbacks exe_env summary =
let iterate_procedure_callbacks exe_env summary =
let proc_desc = Summary . get_proc_desc summary in
let proc_desc = Summary . get_proc_desc summary in
let proc_name = Procdesc . get_proc_name proc_desc in
let proc_name = Procdesc . get_proc_name proc_desc in
@ -55,11 +53,11 @@ let iterate_procedure_callbacks exe_env summary =
in
in
let is_specialized = Procdesc . is_specialized proc_desc in
let is_specialized = Procdesc . is_specialized proc_desc in
List . fold ~ init : summary
List . fold ~ init : summary
~ f : ( fun summary { name; dynamic_dispatch ; language ; callback } ->
~ f : ( fun summary { checker_ name; dynamic_dispatch ; language ; callback } ->
if Language . equal language procedure_language && ( dynamic_dispatch | | not is_specialized ) then (
if Language . equal language procedure_language && ( dynamic_dispatch | | not is_specialized ) then (
PerfEvent . (
PerfEvent . (
log ( fun logger ->
log ( fun logger ->
log_begin_event logger ~ name ~ categories : [ " backend " ]
log_begin_event logger ~ name : checker_name ~ categories : [ " backend " ]
~ arguments : [ ( " proc " , ` String ( Procname . to_string proc_name ) ) ]
~ arguments : [ ( " proc " , ` String ( Procname . to_string proc_name ) ) ]
() ) ) ;
() ) ) ;
let summary = callback { get_procs_in_file ; summary ; exe_env } in
let summary = callback { get_procs_in_file ; summary ; exe_env } in
@ -69,9 +67,8 @@ let iterate_procedure_callbacks exe_env summary =
! procedure_callbacks
! procedure_callbacks
(* * Invoke all registered cluster callbacks on a cluster of procedures. *)
let iterate_file_callbacks procedures exe_env source_file =
let iterate_cluster_callbacks procedures exe_env source_file =
if not ( List . is_empty ! file_callbacks ) then
if not ( List . is_empty ! cluster_callbacks ) then
let environment = { procedures ; source_file ; exe_env } in
let environment = { procedures ; source_file ; exe_env } in
let language_matches language =
let language_matches language =
match procedures with
match procedures with
@ -85,4 +82,4 @@ let iterate_cluster_callbacks procedures exe_env source_file =
if language_matches language then (
if language_matches language then (
Language . curr_language := language ;
Language . curr_language := language ;
callback environment ) )
callback environment ) )
! cluster _callbacks
! file _callbacks