[exe_env] replace set of sources by singleton

Summary:
This is a more accurate type since an execution environment is always a single
file, and allows us to make one of the fields of `Exe_env.t` immutable.

Reviewed By: mbouaziz

Differential Revision: D6620477

fbshipit-source-id: 9553516
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 764224139c
commit b71d567157

@ -27,7 +27,7 @@ let analyze_exe_env_tasks cluster exe_env : Tasks.t =
(** Create tasks to analyze a cluster *)
let analyze_cluster_tasks cluster_num (cluster: Cluster.t) : Tasks.t =
let exe_env = Exe_env.from_cluster cluster in
let exe_env = Exe_env.mk cluster in
let defined_procs = Cg.get_defined_nodes (Exe_env.get_cg exe_env) in
let num_procs = List.length defined_procs in
L.(debug Analysis Medium)

@ -65,29 +65,19 @@ type t =
{ cg: Cg.t (** global call graph *)
; proc_map: file_data Typ.Procname.Hash.t (** map from procedure name to file data *)
; file_map: file_data FilenameHash.t (** map from cg fname to file data *)
; mutable source_files: SourceFile.Set.t (** Source files in the execution environment *) }
; source_file: SourceFile.t (** source file being analyzed *) }
(** initial state, used to add cg's *)
type initial = t
(** create a new execution environment *)
let create () =
{ cg= Cg.create (SourceFile.invalid __FILE__)
; proc_map= Typ.Procname.Hash.create 17
; file_map= FilenameHash.create 1
; source_files= SourceFile.Set.empty }
(** add call graph from fname in the spec db,
with relative tenv and cfg, to the execution environment *)
let add_cg (exe_env: t) (source_dir: DB.source_dir) =
let cg_fname = DB.source_dir_get_internal_file source_dir ".cg" in
let add_cg exe_env source =
let cg_fname = DB.source_dir_get_internal_file (DB.source_dir_from_source_file source) ".cg" in
match Cg.load_from_file cg_fname with
| None ->
L.internal_error "Error: cannot load %s@." (DB.filename_to_string cg_fname)
| Some cg ->
let source = Cg.get_source cg in
exe_env.source_files <- SourceFile.Set.add source exe_env.source_files ;
let defined_procs = Cg.get_defined_nodes cg in
let duplicate_procs_to_print =
List.filter_map defined_procs ~f:(fun pname ->
@ -199,23 +189,18 @@ let get_proc_desc exe_env pname =
None
(** Create an exe_env from a source dir *)
let from_cluster cluster =
let exe_env = create () in
add_cg exe_env (DB.source_dir_from_source_file cluster) ;
exe_env
let mk source_file =
let exe_env =
{ cg= Cg.create (SourceFile.invalid __FILE__)
; proc_map= Typ.Procname.Hash.create 17
; file_map= FilenameHash.create 1
; source_file }
in
add_cg exe_env source_file ; 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 do_file _ file_data seen_files_acc =
let fname = file_data.source in
if SourceFile.Set.mem fname seen_files_acc
|| (* only files added with add_cg* functions *)
not (SourceFile.Set.mem fname exe_env.source_files)
then seen_files_acc
else (
Option.iter ~f:(fun cfg -> f fname cfg) (file_data_to_cfg file_data) ;
SourceFile.Set.add fname seen_files_acc )
in
ignore (Typ.Procname.Hash.fold do_file exe_env.proc_map SourceFile.Set.empty)
let source = exe_env.source_file in
let cfg = Cfg.load source in
Option.iter ~f:(f source) cfg

@ -18,12 +18,8 @@ type initial
(** execution environment: a global call graph, and map from procedure names to cfg and tenv *)
type t
val add_cg : initial -> DB.source_dir -> unit
(** add call graph from the source dir in the spec db,
with relative tenv and cfg, to the execution environment *)
val from_cluster : Cluster.t -> t
(** Create an exe_env from a cluster *)
val mk : SourceFile.t -> t
(** Create an exe_env from a source file *)
val get_cg : t -> Cg.t
(** get the global call graph *)

@ -528,7 +528,7 @@ let write_html_file linereader filename procs =
(** Create filename.ext.html for each file in the cluster. *)
let write_all_html_files cluster =
let exe_env = Exe_env.from_cluster cluster in
let exe_env = Exe_env.mk cluster in
let load_proc_desc pname = ignore (Exe_env.get_proc_desc exe_env pname) in
let () = List.iter ~f:load_proc_desc (Cg.get_defined_nodes (Exe_env.get_cg exe_env)) in
let opt_whitelist_regex =

Loading…
Cancel
Save