Save space/simplify by deleting Exe.file_map

Reviewed By: jeremydubreil

Differential Revision: D2868560

fb-gh-sync-id: b8f9155
master
Sam Blackshear 9 years ago committed by facebook-github-bot-7
parent 07d71d2370
commit dc0b91662a

@ -38,6 +38,8 @@ end
module SourceFileMap = Map.Make(OrderedSourceFile) module SourceFileMap = Map.Make(OrderedSourceFile)
module SourceFileSet = Set.Make(OrderedSourceFile)
let source_file_from_string path = let source_file_from_string path =
if Filename.is_relative path then if Filename.is_relative path then
Relative path Relative path

@ -63,6 +63,9 @@ type source_file
(** Maps from source_file *) (** Maps from source_file *)
module SourceFileMap : Map.S with type key = source_file module SourceFileMap : Map.S with type key = source_file
(** Set of source files *)
module SourceFileSet : Set.S with type elt = source_file
(** current source file *) (** current source file *)
val current_source : source_file ref val current_source : source_file ref

@ -50,7 +50,6 @@ let new_file_data source nLOC cg_fname =
type t = type t =
{ cg: Cg.t; (** global call graph *) { cg: Cg.t; (** global call graph *)
proc_map: file_data Procname.Hash.t; (** map from procedure name to file data *) proc_map: file_data Procname.Hash.t; (** map from procedure name to file data *)
file_map: (DB.source_file, file_data) Hashtbl.t; (** map from filaname to file data *)
mutable active_opt : Procname.Set.t option; (** if not None, restrict the active procedures to the given set *) mutable active_opt : Procname.Set.t option; (** if not None, restrict the active procedures to the given set *)
mutable procs_defined_in_several_files : Procname.Set.t; (** Procedures defined in more than one file *) mutable procs_defined_in_several_files : Procname.Set.t; (** Procedures defined in more than one file *)
} }
@ -65,7 +64,6 @@ let freeze exe_env = exe_env (* TODO: unclear what this function is used for *)
let create procset_opt = let create procset_opt =
{ cg = Cg.create (); { cg = Cg.create ();
proc_map = Procname.Hash.create 17; proc_map = Procname.Hash.create 17;
file_map = Hashtbl.create 17;
active_opt = procset_opt; active_opt = procset_opt;
procs_defined_in_several_files = Procname.Set.empty; procs_defined_in_several_files = Procname.Set.empty;
} }
@ -109,26 +107,12 @@ let add_cg_exclude_fun (exe_env: t) (source_dir : DB.source_dir) exclude_fun =
source < old_source (* when a procedure is defined in several files, map to the first alphabetically *) source < old_source (* when a procedure is defined in several files, map to the first alphabetically *)
else true in else true in
if should_update then Procname.Hash.replace exe_env.proc_map pname file_data) defined_procs; if should_update then Procname.Hash.replace exe_env.proc_map pname file_data) defined_procs;
Hashtbl.add exe_env.file_map source file_data;
Some cg Some cg
(** add call graph from fname in the spec db, with relative tenv and cfg, to the execution environment *) (** add call graph from fname in the spec db, with relative tenv and cfg, to the execution environment *)
let add_cg exe_env (source_dir : DB.source_dir) = let add_cg exe_env (source_dir : DB.source_dir) =
add_cg_exclude_fun exe_env source_dir (fun _ -> false) add_cg_exclude_fun exe_env source_dir (fun _ -> false)
(** add a new source file -> file data mapping. arguments are the components of the file_data
* record *)
let add_file_mapping exe_env source nLOC tenv_file tenv cfg_file cfg =
let file_data =
{ source = source;
nLOC = nLOC;
tenv_file = tenv_file;
tenv = tenv;
cfg_file = cfg_file;
cfg = cfg;
} in
Hashtbl.add exe_env.file_map source file_data
(** get the procedures defined in more than one file *) (** get the procedures defined in more than one file *)
let get_procs_defined_in_several_files exe_env = let get_procs_defined_in_several_files exe_env =
exe_env.procs_defined_in_several_files exe_env.procs_defined_in_several_files
@ -152,12 +136,7 @@ let get_file_data exe_env pname =
let nLOC = loc.Location.nLOC in let nLOC = loc.Location.nLOC in
let source_dir = DB.source_dir_from_source_file source_file in let source_dir = DB.source_dir_from_source_file source_file in
let cg_fname = DB.source_dir_get_internal_file source_dir ".cg" in let cg_fname = DB.source_dir_get_internal_file source_dir ".cg" in
let file_data = let file_data = new_file_data source_file nLOC cg_fname in
try Hashtbl.find exe_env.file_map source_file with
| Not_found ->
let file_data = new_file_data source_file nLOC cg_fname in
Hashtbl.replace exe_env.file_map source_file file_data;
file_data in
Procname.Hash.replace exe_env.proc_map pname file_data; Procname.Hash.replace exe_env.proc_map pname file_data;
file_data file_data
end end
@ -214,16 +193,15 @@ let get_cfg exe_env pname =
(** [iter_files f exe_env] applies [f] to the filename and tenv and cfg for each file in [exe_env] *) (** [iter_files f exe_env] applies [f] to the filename and tenv and cfg for each file in [exe_env] *)
let iter_files f exe_env = let iter_files f exe_env =
let do_file fname file_data = let do_file _ file_data seen_files_acc =
DB.current_source := fname; let fname = file_data.source in
Config.nLOC := file_data.nLOC; if DB.SourceFileSet.mem fname seen_files_acc
f fname (file_data_to_tenv file_data) (file_data_to_cfg exe_env file_data) in then seen_files_acc
Hashtbl.iter do_file exe_env.file_map else
begin
(** [fold_files f exe_env] folds f through the source file, tenv, and cfg for each file in [exe_env] *) DB.current_source := fname;
let fold_files f acc exe_env = Config.nLOC := file_data.nLOC;
let fold_file fname file_data acc = f fname (file_data_to_tenv file_data) (file_data_to_cfg exe_env file_data);
DB.current_source := fname; DB.SourceFileSet.add fname seen_files_acc
Config.nLOC := file_data.nLOC; end in
f fname (file_data_to_tenv file_data) (file_data_to_cfg exe_env file_data) acc in ignore (Procname.Hash.fold do_file exe_env.proc_map DB.SourceFileSet.empty)
Hashtbl.fold fold_file exe_env.file_map acc

@ -30,11 +30,6 @@ val add_cg : initial -> DB.source_dir -> Cg.t option
(** like add_cg, but use exclude_fun to determine files to be excluded *) (** like add_cg, but use exclude_fun to determine files to be excluded *)
val add_cg_exclude_fun : initial -> DB.source_dir -> (DB.source_file -> bool) -> Cg.t option val add_cg_exclude_fun : initial -> DB.source_dir -> (DB.source_file -> bool) -> Cg.t option
(** add a new source file -> file data mapping. arguments are the components of the file_data
* record *)
val add_file_mapping : t -> DB.source_file -> int -> DB.filename -> Sil.tenv option -> DB.filename
-> Cfg.cfg option -> unit
(** get the global call graph *) (** get the global call graph *)
val get_cg : t -> Cg.t val get_cg : t -> Cg.t
@ -53,9 +48,6 @@ val get_cfg : t -> Procname.t -> Cfg.cfg
(** [iter_files f exe_env] applies [f] to the source file and tenv and cfg for each file in [exe_env] *) (** [iter_files f exe_env] applies [f] to the source file and tenv and cfg for each file in [exe_env] *)
val iter_files : (DB.source_file -> Sil.tenv -> Cfg.cfg -> unit) -> t -> unit val iter_files : (DB.source_file -> Sil.tenv -> Cfg.cfg -> unit) -> t -> unit
(** [fold_files f exe_env] folds f through the source file, tenv, and cfg for each file in [exe_env] *)
val fold_files : (DB.source_file -> Sil.tenv -> Cfg.cfg -> 'a -> 'a) -> 'a -> t -> 'a
(** check if a procedure is marked as active *) (** check if a procedure is marked as active *)
val proc_is_active : t -> Procname.t -> bool val proc_is_active : t -> Procname.t -> bool

Loading…
Cancel
Save