@ -30,19 +30,17 @@ let procedure_callbacks = ref []
let cluster_callbacks = ref []
let cluster_callbacks = ref []
let register_procedure_callback language _opt ( callback : proc_callback_t ) =
let register_procedure_callback language ( callback : proc_callback_t ) =
procedure_callbacks := ( language _opt , callback ) :: ! procedure_callbacks
procedure_callbacks := ( language , callback ) :: ! procedure_callbacks
let register_cluster_callback language _opt ( callback : cluster_callback_t ) =
let register_cluster_callback language ( callback : cluster_callback_t ) =
cluster_callbacks := ( language _opt , callback ) :: ! cluster_callbacks
cluster_callbacks := ( language , callback ) :: ! cluster_callbacks
(* * Collect what we need to know about a procedure for the analysis. *)
(* * Collect what we need to know about a procedure for the analysis. *)
let get_procedure_definition exe_env proc_name =
let get_procedure_definition exe_env proc_name =
let tenv = Exe_env . get_tenv exe_env proc_name in
let tenv = Exe_env . get_tenv exe_env proc_name in
Option . map
Option . map
~ f : ( fun proc_desc ->
~ f : ( fun proc_desc -> ( tenv , proc_name , proc_desc ) )
let language = ( Procdesc . get_attributes proc_desc ) . ProcAttributes . language in
( tenv , proc_name , proc_desc , language ) )
( Exe_env . get_proc_desc exe_env proc_name )
( Exe_env . get_proc_desc exe_env proc_name )
let get_language proc_name = if Typ . Procname . is_java proc_name then Config . Java else Config . Clang
let get_language proc_name = if Typ . Procname . is_java proc_name then Config . Java else Config . Clang
@ -62,17 +60,10 @@ let iterate_procedure_callbacks exe_env summary caller_pname =
match get_procedure_definition exe_env caller_pname with
match get_procedure_definition exe_env caller_pname with
| None
| None
-> summary
-> summary
| Some ( tenv , _ , proc_desc , _ )
| Some ( tenv , _ , proc_desc )
-> List . fold ~ init : summary
-> List . fold ~ init : summary
~ f : ( fun summary ( language_opt , proc_callback ) ->
~ f : ( fun summary ( language , proc_callback ) ->
let language_matches =
if Config . equal_language language procedure_language then
match language_opt with
| Some language
-> Config . equal_language language procedure_language
| None
-> true
in
if language_matches then
proc_callback { get_proc_desc ; get_procs_in_file ; tenv ; summary ; proc_desc }
proc_callback { get_proc_desc ; get_procs_in_file ; tenv ; summary ; proc_desc }
else summary )
else summary )
! procedure_callbacks
! procedure_callbacks
@ -80,23 +71,17 @@ let iterate_procedure_callbacks exe_env summary caller_pname =
(* * Invoke all registered cluster callbacks on a cluster of procedures. *)
(* * Invoke all registered cluster callbacks on a cluster of procedures. *)
let iterate_cluster_callbacks all_procs exe_env =
let iterate_cluster_callbacks all_procs exe_env =
let get_procdesc = Exe_env . get_proc_desc exe_env in
let get_procdesc = Exe_env . get_proc_desc exe_env in
let procedure_definitions = List . filter_map ~ f : ( get_procedure_definition exe_env ) all_procs in
let environment = List . filter_map ~ f : ( get_procedure_definition exe_env ) all_procs in
let environment =
let language_matches language =
List . map
match environment with
~ f : ( fun ( tenv , proc_name , proc_desc , _ ) -> ( tenv , proc_name , proc_desc ) )
| ( _ , pname , _ ) :: _
procedure_definitions
-> Config . equal_language language ( get_language pname )
in
| _
(* Procedures matching the given language or all if no language is specified. *)
-> true
let relevant_procedures language_opt =
Option . value_map
~ f : ( fun l -> List . filter ~ f : ( fun p -> Config . equal_language l ( get_language p ) ) all_procs )
~ default : all_procs language_opt
in
in
List . iter
List . iter
~ f : ( fun ( language_opt , cluster_callback ) ->
~ f : ( fun ( language , cluster_callback ) ->
let proc_names = relevant_procedures language_opt in
if language_matches language then cluster_callback exe_env all_procs get_procdesc environment )
if List . length proc_names > 0 then
cluster_callback exe_env all_procs get_procdesc environment )
! cluster_callbacks
! cluster_callbacks
(* * Invoke all procedure and cluster callbacks on a given environment. *)
(* * Invoke all procedure and cluster callbacks on a given environment. *)