[clang] Restore the debug tenv file for the clang frontend

Reviewed By: jeremydubreil

Differential Revision: D7112368

fbshipit-source-id: de8a566
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent b4b901c725
commit eef8774aa2

@ -122,13 +122,23 @@ let load source =
|> function Global -> load_global () | FileLocal tenv -> Some tenv ) ) |> 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 = let store_to_filename tenv tenv_filename =
Serialization.write_to_file tenv_serializer tenv_filename ~data:tenv ; Serialization.write_to_file tenv_serializer tenv_filename ~data:tenv ;
if Config.debug_mode then ( if Config.debug_mode then 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_global tenv = let store_global tenv =

@ -20,6 +20,8 @@ val create : unit -> t
val load : SourceFile.t -> t option val load : SourceFile.t -> t option
(** Load a type environment for a source file *) (** Load a type environment for a source file *)
val store_debug_file_for_source : SourceFile.t -> t -> unit
val load_global : unit -> t option val load_global : unit -> t option
(** load the global type environment (Java) *) (** load the global type environment (Java) *)

@ -60,6 +60,15 @@ type source_dir = string [@@deriving compare]
(** expose the source dir as a string *) (** expose the source dir as a string *)
let source_dir_to_string source_dir = source_dir 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 *) (** get the source directory corresponding to a source file *)
let source_dir_from_source_file source_file = let source_dir_from_source_file source_file =
Filename.concat Config.captured_dir (source_file_encoding source_file) Filename.concat Config.captured_dir (source_file_encoding source_file)

@ -81,6 +81,9 @@ type source_dir [@@deriving compare]
val source_dir_to_string : source_dir -> string val source_dir_to_string : source_dir -> string
(** expose the source dir as a 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 val source_dir_from_source_file : SourceFile.t -> source_dir
(** get the source directory corresponding to a source file *) (** get the source directory corresponding to a source file *)

@ -52,6 +52,7 @@ let do_source_file (translation_unit_context: CFrontend_config.translation_unit_
(* This could be moved in the cfg_infer module *) (* This could be moved in the cfg_infer module *)
NullabilityPreanalysis.analysis cfg tenv ; NullabilityPreanalysis.analysis cfg tenv ;
SourceFiles.add source_file cfg (FileLocal 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 then Cfg.check_cfg_connectedness cfg ;
if Config.debug_mode || Config.testing_mode || Config.frontend_tests if Config.debug_mode || Config.testing_mode || Config.frontend_tests
|| Option.is_some Config.icfg_dotty_outfile || Option.is_some Config.icfg_dotty_outfile

Loading…
Cancel
Save