diff --git a/infer/src/IR/StructTyp.re b/infer/src/IR/StructTyp.re index 4370b3ee9..964667f1c 100644 --- a/infer/src/IR/StructTyp.re +++ b/infer/src/IR/StructTyp.re @@ -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 }; diff --git a/infer/src/IR/Tenv.re b/infer/src/IR/Tenv.re index bb4e2d03c..0449f9c25 100644 --- a/infer/src/IR/Tenv.re +++ b/infer/src/IR/Tenv.re @@ -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;