From b3cef556b7ab178b1a2f3f1c79d2ed8a20a1477a Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 17 Oct 2018 05:34:57 -0700 Subject: [PATCH] [debug] Print types in access paths/expressions in verbose mode Reviewed By: ngorogiannis Differential Revision: D10414234 fbshipit-source-id: ad73c79ab --- infer/src/IR/AccessExpression.ml | 18 ++++++++++++------ infer/src/IR/AccessPath.ml | 15 ++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/infer/src/IR/AccessExpression.ml b/infer/src/IR/AccessExpression.ml index 6ad981327..c5c0e06fc 100644 --- a/infer/src/IR/AccessExpression.ml +++ b/infer/src/IR/AccessExpression.ml @@ -92,17 +92,23 @@ let rec get_typ t tenv : Typ.t option = match base_typ_opt with Some {Typ.desc= Tptr (typ, _)} -> Some typ | _ -> None ) +let may_pp_typ fmt typ = + if Config.debug_level_analysis >= 3 then F.fprintf fmt ":%a" (Typ.pp Pp.text) typ + + let rec pp fmt = function - | Base (pvar, _) -> - Var.pp fmt pvar + | Base (pvar, typ) -> + Var.pp fmt pvar ; may_pp_typ fmt typ | FieldOffset (Dereference ae, fld) -> F.fprintf fmt "%a->%a" pp ae Typ.Fieldname.pp fld | FieldOffset (ae, fld) -> F.fprintf fmt "%a.%a" pp ae Typ.Fieldname.pp fld - | ArrayOffset (ae, _, []) -> - F.fprintf fmt "%a[_]" pp ae - | ArrayOffset (ae, _, index_aes) -> - F.fprintf fmt "%a[%a]" pp ae (PrettyPrintable.pp_collection ~pp_item:pp) index_aes + | ArrayOffset (ae, typ, []) -> + F.fprintf fmt "%a[_]%a" pp ae may_pp_typ typ + | ArrayOffset (ae, typ, index_aes) -> + F.fprintf fmt "%a[%a]%a" pp ae + (PrettyPrintable.pp_collection ~pp_item:pp) + index_aes may_pp_typ typ | AddressOf ae -> F.fprintf fmt "&(%a)" pp ae | Dereference ae -> diff --git a/infer/src/IR/AccessPath.ml b/infer/src/IR/AccessPath.ml index ab920f204..1a43b66b2 100644 --- a/infer/src/IR/AccessPath.ml +++ b/infer/src/IR/AccessPath.ml @@ -27,15 +27,20 @@ module Raw = struct let equal_access_list l1 l2 = Int.equal (List.compare compare_access l1 l2) 0 - let pp_base fmt (pvar, _) = Var.pp fmt pvar + let may_pp_typ fmt typ = + if Config.debug_level_analysis >= 3 then F.fprintf fmt ":%a" (Typ.pp Pp.text) typ + + + let pp_base fmt (pvar, typ) = Var.pp fmt pvar ; may_pp_typ fmt typ let rec pp_access fmt = function | FieldAccess field_name -> Typ.Fieldname.pp fmt field_name - | ArrayAccess (_, []) -> - F.pp_print_string fmt "[_]" - | ArrayAccess (_, index_aps) -> - F.fprintf fmt "[%a]" (PrettyPrintable.pp_collection ~pp_item:pp) index_aps + | ArrayAccess (typ, []) -> + F.pp_print_string fmt "[_]" ; may_pp_typ fmt typ + | ArrayAccess (typ, index_aps) -> + F.fprintf fmt "[%a]" (PrettyPrintable.pp_collection ~pp_item:pp) index_aps ; + may_pp_typ fmt typ and pp_access_list fmt accesses =