@ -14,13 +14,16 @@ open! IStd
module L = Logging
(* * per-file data: type environment and cfg *)
type file_data = { source : SourceFile . t ; mutable tenv : Tenv . t option }
type file_data =
{ source : SourceFile . t
; mutable tenv : Tenv . t option
; mutable integer_type_widths : Typ . IntegerWidths . t option }
(* * create a new file_data *)
let new_file_data source =
(* Do not fill in tenv and cfg as they can be quite large. This makes calls to fork ( ) cheaper
until we start filling out these fields . * )
{ source ; tenv = None (* Sil.load_tenv_from_file tenv_file *) }
{ source ; tenv = None (* Sil.load_tenv_from_file tenv_file *) ; integer_type_widths = None }
let create_file_data table source =
@ -63,6 +66,13 @@ let file_data_to_tenv file_data =
file_data . tenv
let file_data_to_integer_type_widths file_data =
if is_none file_data . integer_type_widths then
file_data . integer_type_widths
<- Option . first_some ( Typ . IntegerWidths . load file_data . source ) ( Some Typ . IntegerWidths . java ) ;
file_data . integer_type_widths
let java_global_tenv =
lazy
( match Tenv . load_global () with
@ -72,27 +82,39 @@ let java_global_tenv =
tenv )
(* * return the type environment associated to the procedure *)
let get_tenv exe_env proc_name =
let get_column_value ~ value_on_java ~ file_data_to_value ~ column_name exe_env proc_name =
match proc_name with
| Typ . Procname . Java _ ->
Lazy . force java_global_tenv
Lazy . force value_on_java
| _ -> (
match get_file_data exe_env proc_name with
| Some file_data -> (
match file_data_to_ tenv file_data with
| Some ten v ->
ten v
match file_data_to_ value file_data with
| Some v ->
v
| None ->
let loc = State . get_loc_exn () in
L . ( die InternalError )
" get_ tenv: tenv not found for %a in file '%a' at %a" Typ . Procname . pp proc_name
SourceFile . pp loc . Location . file Location . pp loc )
" get_ column_value: %s not found for %a in file '%a' at %a" column_name Typ . Procname . pp
proc_name SourceFile . pp loc . Location . file Location . pp loc )
| None ->
let loc = State . get_loc_exn () in
L . ( die InternalError )
" get_tenv: file_data not found for %a in file '%a' at %a " Typ . Procname . pp proc_name
SourceFile . pp loc . Location . file Location . pp loc )
" get_column_value: file_data not found for %a in file '%a' at %a " Typ . Procname . pp
proc_name SourceFile . pp loc . Location . file Location . pp loc )
(* * return the type environment associated to the procedure *)
let get_tenv =
get_column_value ~ value_on_java : java_global_tenv ~ file_data_to_value : file_data_to_tenv
~ column_name : " tenv "
(* * return the integer type widths associated to the procedure *)
let get_integer_type_widths =
get_column_value
~ value_on_java : ( lazy Typ . IntegerWidths . java )
~ file_data_to_value : file_data_to_integer_type_widths ~ column_name : " integer type widths "
let mk () = { proc_map = Typ . Procname . Hash . create 17 ; file_map = SourceFile . Hash . create 1 }