From eef8774aa268934806bdee2eda97cff0bd301dbd Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Mon, 5 Mar 2018 03:48:07 -0800 Subject: [PATCH] [clang] Restore the debug tenv file for the clang frontend Reviewed By: jeremydubreil Differential Revision: D7112368 fbshipit-source-id: de8a566 --- infer/src/IR/Tenv.ml | 20 +++++++++++++++----- infer/src/IR/Tenv.mli | 2 ++ infer/src/base/DB.ml | 9 +++++++++ infer/src/base/DB.mli | 3 +++ infer/src/clang/cFrontend.ml | 1 + 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/infer/src/IR/Tenv.ml b/infer/src/IR/Tenv.ml index 32d34de55..91b91ccdf 100644 --- a/infer/src/IR/Tenv.ml +++ b/infer/src/IR/Tenv.ml @@ -122,13 +122,23 @@ let load source = |> function Global -> load_global () | FileLocal tenv -> Some tenv ) ) +let store_debug_file tenv tenv_filename = + let debug_filename = DB.filename_to_string (DB.filename_add_suffix tenv_filename ".debug") in + let out_channel = Out_channel.create debug_filename in + let fmt = Format.formatter_of_out_channel out_channel in + Format.fprintf fmt "%a" pp tenv ; Out_channel.close out_channel + + +let store_debug_file_for_source source_file tenv = + let tenv_filename_of_source_file = + DB.source_dir_get_internal_file (DB.source_dir_from_source_file source_file) ".tenv" + in + store_debug_file tenv tenv_filename_of_source_file + + let store_to_filename tenv tenv_filename = Serialization.write_to_file tenv_serializer tenv_filename ~data:tenv ; - if Config.debug_mode then ( - let debug_filename = DB.filename_to_string (DB.filename_add_suffix tenv_filename ".debug") in - let out_channel = Out_channel.create debug_filename in - let fmt = Format.formatter_of_out_channel out_channel in - Format.fprintf fmt "%a" pp tenv ; Out_channel.close out_channel ) + if Config.debug_mode then store_debug_file tenv tenv_filename let store_global tenv = diff --git a/infer/src/IR/Tenv.mli b/infer/src/IR/Tenv.mli index 34037a6d9..4b4a759b1 100644 --- a/infer/src/IR/Tenv.mli +++ b/infer/src/IR/Tenv.mli @@ -20,6 +20,8 @@ val create : unit -> t val load : SourceFile.t -> t option (** Load a type environment for a source file *) +val store_debug_file_for_source : SourceFile.t -> t -> unit + val load_global : unit -> t option (** load the global type environment (Java) *) diff --git a/infer/src/base/DB.ml b/infer/src/base/DB.ml index cf12faa96..7c85ee96d 100644 --- a/infer/src/base/DB.ml +++ b/infer/src/base/DB.ml @@ -60,6 +60,15 @@ type source_dir = string [@@deriving compare] (** expose the source dir as a string *) let source_dir_to_string source_dir = source_dir +(** get the path to an internal file with the given extention (.tenv, ...) *) +let source_dir_get_internal_file source_dir extension = + let source_dir_name = + append_crc_cutoff (Caml.Filename.remove_extension (Filename.basename source_dir)) + in + let fname = source_dir_name ^ extension in + Filename.concat source_dir fname + + (** get the source directory corresponding to a source file *) let source_dir_from_source_file source_file = Filename.concat Config.captured_dir (source_file_encoding source_file) diff --git a/infer/src/base/DB.mli b/infer/src/base/DB.mli index b992c7538..c01c6cf84 100644 --- a/infer/src/base/DB.mli +++ b/infer/src/base/DB.mli @@ -81,6 +81,9 @@ type source_dir [@@deriving compare] val source_dir_to_string : source_dir -> string (** expose the source dir as a string *) +val source_dir_get_internal_file : source_dir -> string -> filename +(** get the path to an internal file with the given extention (.tenv, ...) *) + val source_dir_from_source_file : SourceFile.t -> source_dir (** get the source directory corresponding to a source file *) diff --git a/infer/src/clang/cFrontend.ml b/infer/src/clang/cFrontend.ml index 6b1e2b0a2..133dd7f07 100644 --- a/infer/src/clang/cFrontend.ml +++ b/infer/src/clang/cFrontend.ml @@ -52,6 +52,7 @@ let do_source_file (translation_unit_context: CFrontend_config.translation_unit_ (* This could be moved in the cfg_infer module *) NullabilityPreanalysis.analysis cfg tenv ; SourceFiles.add source_file cfg (FileLocal tenv) ; + if Config.debug_mode then Tenv.store_debug_file_for_source source_file tenv ; if Config.debug_mode then Cfg.check_cfg_connectedness cfg ; if Config.debug_mode || Config.testing_mode || Config.frontend_tests || Option.is_some Config.icfg_dotty_outfile