[infer][backend] Save the pretty-print of the type environment when running the analysis in debug mode

Summary: This is very useful to debug issues that have to do with types, for example the cast errors

Reviewed By: sblackshear

Differential Revision: D4289790

fbshipit-source-id: ef5a8bf
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent 5310b617fe
commit 2edafcee92

@ -34,16 +34,26 @@ type lookup = Typename.t => option t;
let compare_fld_typ_ann = [%compare : (Ident.fieldname, Typ.t, Annot.Item.t)];
let pp pe name f {fields} =>
if false {
let pp pe name f {fields, supers, methods, annots} =>
if Config.debug_mode {
/* change false to true to print the details of struct */
F.fprintf
f
"%a {%a}"
"%a \n\tfields: {%a\n\t}\n\tsupers: {%a\n\t}\n\tmethods: {%a\n\t}\n\tannots: {%a\n\t}"
Typename.pp
name
(pp_seq (fun f (fld, t, _) => F.fprintf f "%a %a" (Typ.pp_full pe) t Ident.pp_fieldname fld))
(
pp_seq (
fun f (fld, t, _) => F.fprintf f "\n\t\t%a %a" (Typ.pp_full pe) t Ident.pp_fieldname fld
)
)
fields
(pp_seq (fun f n => F.fprintf f "\n\t\t%a" Typename.pp n))
supers
(pp_seq (fun f m => F.fprintf f "\n\t\t%a" Procname.pp m))
methods
Annot.Item.pp
annots
} else {
F.fprintf f "%a" Typename.pp name
};

@ -22,6 +22,16 @@ let module TypenameHash = Hashtbl.Make {
/** Type for type environment. */
type t = TypenameHash.t StructTyp.t;
let pp fmt (tenv: t) =>
TypenameHash.iter
(
fun name typ => {
Format.fprintf fmt "@[<6>NAME: %s@." (Typename.to_string name);
Format.fprintf fmt "@[<6>TYPE: %a@." (StructTyp.pp pe_text name) typ
}
)
tenv;
/** Create a new type environment. */
let create () => TypenameHash.create 1000;
@ -118,19 +128,17 @@ let load_from_file (filename: DB.filename) :option t =>
/** Save a type environment into a file */
let store_to_file (filename: DB.filename) (tenv: t) =>
let store_to_file (filename: DB.filename) (tenv: t) => {
Serialization.to_file tenv_serializer filename tenv;
if Config.debug_mode {
let debug_filename = DB.filename_to_string (DB.filename_add_suffix filename ".debug");
let out_channel = open_out debug_filename;
let fmt = Format.formatter_of_out_channel out_channel;
Format.fprintf fmt "%a" pp tenv;
close_out out_channel
}
};
let iter f tenv => TypenameHash.iter f tenv;
let fold f tenv => TypenameHash.fold f tenv;
let pp fmt (tenv: t) =>
TypenameHash.iter
(
fun name typ => {
Format.fprintf fmt "@[<6>NAME: %s@." (Typename.to_string name);
Format.fprintf fmt "@[<6>TYPE: %a@." (StructTyp.pp pe_text name) typ
}
)
tenv;

Loading…
Cancel
Save