From bd8d2eb94104c3a10237c5b985798873895f8211 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 17 Sep 2018 15:09:16 -0700 Subject: [PATCH] ProcAttributes: simplify var_attribute Reviewed By: ngorogiannis Differential Revision: D9851539 fbshipit-source-id: 41bb886a2 --- infer/src/IR/ProcAttributes.ml | 18 ++++-------------- infer/src/IR/ProcAttributes.mli | 14 ++++++-------- infer/src/IR/Procdesc.ml | 13 ++++--------- infer/src/clang/cTrans.ml | 13 ++++++++----- infer/src/clang/cVar_decl.ml | 13 +++++-------- infer/src/java/jTrans.ml | 2 +- 6 files changed, 28 insertions(+), 45 deletions(-) diff --git a/infer/src/IR/ProcAttributes.ml b/infer/src/IR/ProcAttributes.ml index 87773712a..31d7efa6c 100644 --- a/infer/src/IR/ProcAttributes.ml +++ b/infer/src/IR/ProcAttributes.ml @@ -29,22 +29,12 @@ let pp_objc_accessor_type fmt objc_accessor_type = annots -type var_attribute = Modify_in_block [@@deriving compare] - -let string_of_var_attribute = function Modify_in_block -> "" - -let var_attribute_equal = [%compare.equal: var_attribute] - -type var_data = {name: Mangled.t; typ: Typ.t; attributes: var_attribute list; is_constexpr: bool} +type var_data = {name: Mangled.t; typ: Typ.t; modify_in_block: bool; is_constexpr: bool} [@@deriving compare] -let pp_var_data fmt {name; typ; attributes} = - F.fprintf fmt "@[{ name=@ %a;@ typ=@ %a" Mangled.pp name (Typ.pp_full Pp.text) typ ; - if not (List.is_empty attributes) then - F.fprintf fmt ";@ attributes=@ [@[%a@]]" - (Pp.semicolon_seq ~print_env:Pp.text_break (Pp.to_string ~f:string_of_var_attribute)) - attributes ; - F.fprintf fmt " }@]" +let pp_var_data fmt {name; typ; modify_in_block} = + F.fprintf fmt "@[{ name=@ %a;@ typ=@ %a;@ modify_in_block=@ %b@ }@]" Mangled.pp name + (Typ.pp_full Pp.text) typ modify_in_block type t = diff --git a/infer/src/IR/ProcAttributes.mli b/infer/src/IR/ProcAttributes.mli index ef7a6c56a..ea9365133 100644 --- a/infer/src/IR/ProcAttributes.mli +++ b/infer/src/IR/ProcAttributes.mli @@ -13,14 +13,12 @@ type objc_accessor_type = Objc_getter of Typ.Struct.field | Objc_setter of Typ.S val kind_of_objc_accessor_type : objc_accessor_type -> string -type var_attribute = Modify_in_block - -(* __block attribute of Objective-C variables, means that it will be modified inside a block *) - -val var_attribute_equal : var_attribute -> var_attribute -> bool -(** Equality for var_attribute *) - -type var_data = {name: Mangled.t; typ: Typ.t; attributes: var_attribute list; is_constexpr: bool} +type var_data = + { name: Mangled.t + ; typ: Typ.t + ; modify_in_block: bool + (** __block attribute of Objective-C variables, means that it will be modified inside a block *) + ; is_constexpr: bool } type t = { access: PredSymb.access (** visibility access *) diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index 338d2ed39..36e2c99ff 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -596,16 +596,13 @@ let is_loop_head pdesc (node : Node.t) = NodeSet.mem node lh -let pp_var_attributes fmt attrs = - let pp_attribute fmt attr = - match attr with ProcAttributes.Modify_in_block -> Format.pp_print_string fmt "__block" - in - if List.is_empty attrs then () else F.fprintf fmt "(%a)" (Pp.seq ~sep:"," pp_attribute) attrs +let pp_modify_in_block fmt modify_in_block = + if modify_in_block then Format.pp_print_string fmt "(__block)" else () let pp_local fmt (var_data : ProcAttributes.var_data) = Format.fprintf fmt " %a:%a%a" Mangled.pp var_data.name (Typ.pp_full Pp.text) var_data.typ - pp_var_attributes var_data.attributes + pp_modify_in_block var_data.modify_in_block let pp_locals_list fmt etl = @@ -682,9 +679,7 @@ let is_captured_var procdesc pvar = let has_modify_in_block_attr procdesc pvar = let pvar_name = Pvar.get_name pvar in let pvar_local_matches (var_data : ProcAttributes.var_data) = - Mangled.equal var_data.name pvar_name - && List.exists var_data.attributes ~f:(fun attr -> - ProcAttributes.var_attribute_equal attr ProcAttributes.Modify_in_block ) + var_data.modify_in_block && Mangled.equal var_data.name pvar_name in List.exists ~f:pvar_local_matches (get_locals procdesc) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 795080135..c5309dd61 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -211,7 +211,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let procdesc = context.CContext.procdesc in let pvar, typ = mk_temp_sil_var_for_expr context.CContext.tenv procdesc var_name expr_info in let var_data = - ProcAttributes.{name= Pvar.get_name pvar; typ; attributes= []; is_constexpr= false} + ProcAttributes.{name= Pvar.get_name pvar; typ; modify_in_block= false; is_constexpr= false} in Procdesc.append_locals procdesc [var_data] ; (Exp.Lvar pvar, typ) @@ -248,7 +248,10 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let procdesc = trans_state.context.CContext.procdesc in let pvar = mk_temp_sil_var procdesc "__temp_return_" in let var_data : ProcAttributes.var_data = - {name= Pvar.get_name pvar; typ= return_type; attributes= []; is_constexpr= false} + { name= Pvar.get_name pvar + ; typ= return_type + ; modify_in_block= false + ; is_constexpr= false } in Procdesc.append_locals procdesc [var_data] ; Exp.Lvar pvar @@ -1138,7 +1141,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let pvar = Pvar.mk_tmp "__temp_construct_" (Procdesc.get_proc_name procdesc) in let class_type = CType_decl.get_type_from_expr_info ei context.CContext.tenv in let var_data : ProcAttributes.var_data = - {name= Pvar.get_name pvar; typ= class_type; attributes= []; is_constexpr= false} + {name= Pvar.get_name pvar; typ= class_type; modify_in_block= false; is_constexpr= false} in Procdesc.append_locals procdesc [var_data] ; (Exp.Lvar pvar, class_type) @@ -1545,7 +1548,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let pvar = mk_temp_sil_var procdesc "SIL_temp_conditional___" in let var_data = ProcAttributes. - {name= Pvar.get_name pvar; typ= var_typ; attributes= []; is_constexpr= false} + {name= Pvar.get_name pvar; typ= var_typ; modify_in_block= false; is_constexpr= false} in Procdesc.append_locals procdesc [var_data] ; let continuation' = mk_cond_continuation trans_state.continuation in @@ -2909,7 +2912,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let res_trans = init_expr_trans trans_state var_exp_typ stmt_info (Some temp_exp) in let _, typ = res_trans.return in let var_data = - ProcAttributes.{name= Pvar.get_name pvar; typ; attributes= []; is_constexpr= false} + ProcAttributes.{name= Pvar.get_name pvar; typ; modify_in_block= false; is_constexpr= false} in Procdesc.append_locals procdesc [var_data] ; res_trans diff --git a/infer/src/clang/cVar_decl.ml b/infer/src/clang/cVar_decl.ml index c7e65a711..3db262f87 100644 --- a/infer/src/clang/cVar_decl.ml +++ b/infer/src/clang/cVar_decl.ml @@ -54,13 +54,10 @@ let sil_var_of_decl_ref context source_range decl_ref procname = decl_ref ) -let get_var_attribute decl_info = +let has_block_attribute decl_info = let open Clang_ast_t in - let has_block_attribute = - List.exists decl_info.Clang_ast_t.di_attributes ~f:(fun attr -> - match attr with BlocksAttr _ -> true | _ -> false ) - in - if has_block_attribute then [ProcAttributes.Modify_in_block] else [] + List.exists decl_info.di_attributes ~f:(fun attr -> + match attr with BlocksAttr _ -> true | _ -> false ) let add_var_to_locals procdesc var_decl typ pvar = @@ -68,13 +65,13 @@ let add_var_to_locals procdesc var_decl typ pvar = match var_decl with | VarDecl (decl_info, _, _, vdi) -> if not vdi.Clang_ast_t.vdi_is_global then - let attributes = get_var_attribute decl_info in + let modify_in_block = has_block_attribute decl_info in let is_constexpr = vdi.Clang_ast_t.vdi_is_const_expr || (Typ.is_const typ.Typ.quals && vdi.Clang_ast_t.vdi_is_init_expr_cxx11_constant) in let var_data : ProcAttributes.var_data = - {name= Pvar.get_name pvar; typ; attributes; is_constexpr} + {name= Pvar.get_name pvar; typ; modify_in_block; is_constexpr} in Procdesc.append_locals procdesc [var_data] | _ -> diff --git a/infer/src/java/jTrans.ml b/infer/src/java/jTrans.ml index 1fc8543a9..cdaed6930 100644 --- a/infer/src/java/jTrans.ml +++ b/infer/src/java/jTrans.ml @@ -415,7 +415,7 @@ let create_cm_procdesc source_file program linereader icfg cm proc_name = let locals_ = translate_locals program tenv formals bytecode jbir_code in let locals = List.map locals_ ~f:(fun (name, typ) -> - ({name; typ; attributes= []; is_constexpr= false} : ProcAttributes.var_data) ) + ({name; typ; modify_in_block= false; is_constexpr= false} : ProcAttributes.var_data) ) in let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in let proc_attributes =