ProcAttributes: simplify var_attribute

Reviewed By: ngorogiannis

Differential Revision: D9851539

fbshipit-source-id: 41bb886a2
master
Mehdi Bouaziz 6 years ago committed by Facebook Github Bot
parent ff851040fc
commit bd8d2eb941

@ -29,22 +29,12 @@ let pp_objc_accessor_type fmt objc_accessor_type =
annots annots
type var_attribute = Modify_in_block [@@deriving compare] type var_data = {name: Mangled.t; typ: Typ.t; modify_in_block: bool; is_constexpr: bool}
let string_of_var_attribute = function Modify_in_block -> "<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}
[@@deriving compare] [@@deriving compare]
let pp_var_data fmt {name; typ; attributes} = let pp_var_data fmt {name; typ; modify_in_block} =
F.fprintf fmt "@[<h>{ name=@ %a;@ typ=@ %a" Mangled.pp name (Typ.pp_full Pp.text) typ ; F.fprintf fmt "@[<h>{ name=@ %a;@ typ=@ %a;@ modify_in_block=@ %b@ }@]" Mangled.pp name
if not (List.is_empty attributes) then (Typ.pp_full Pp.text) typ modify_in_block
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 " }@]"
type t = type t =

@ -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 val kind_of_objc_accessor_type : objc_accessor_type -> string
type var_attribute = Modify_in_block type var_data =
{ name: Mangled.t
(* __block attribute of Objective-C variables, means that it will be modified inside a block *) ; typ: Typ.t
; modify_in_block: bool
val var_attribute_equal : var_attribute -> var_attribute -> bool (** __block attribute of Objective-C variables, means that it will be modified inside a block *)
(** Equality for var_attribute *) ; is_constexpr: bool }
type var_data = {name: Mangled.t; typ: Typ.t; attributes: var_attribute list; is_constexpr: bool}
type t = type t =
{ access: PredSymb.access (** visibility access *) { access: PredSymb.access (** visibility access *)

@ -596,16 +596,13 @@ let is_loop_head pdesc (node : Node.t) =
NodeSet.mem node lh NodeSet.mem node lh
let pp_var_attributes fmt attrs = let pp_modify_in_block fmt modify_in_block =
let pp_attribute fmt attr = if modify_in_block then Format.pp_print_string fmt "(__block)" else ()
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_local fmt (var_data : ProcAttributes.var_data) = 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 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 = 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 has_modify_in_block_attr procdesc pvar =
let pvar_name = Pvar.get_name pvar in let pvar_name = Pvar.get_name pvar in
let pvar_local_matches (var_data : ProcAttributes.var_data) = let pvar_local_matches (var_data : ProcAttributes.var_data) =
Mangled.equal var_data.name pvar_name var_data.modify_in_block && Mangled.equal var_data.name pvar_name
&& List.exists var_data.attributes ~f:(fun attr ->
ProcAttributes.var_attribute_equal attr ProcAttributes.Modify_in_block )
in in
List.exists ~f:pvar_local_matches (get_locals procdesc) List.exists ~f:pvar_local_matches (get_locals procdesc)

@ -211,7 +211,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let procdesc = context.CContext.procdesc in 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 pvar, typ = mk_temp_sil_var_for_expr context.CContext.tenv procdesc var_name expr_info in
let var_data = 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 in
Procdesc.append_locals procdesc [var_data] ; Procdesc.append_locals procdesc [var_data] ;
(Exp.Lvar pvar, typ) (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 procdesc = trans_state.context.CContext.procdesc in
let pvar = mk_temp_sil_var procdesc "__temp_return_" in let pvar = mk_temp_sil_var procdesc "__temp_return_" in
let var_data : ProcAttributes.var_data = 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 in
Procdesc.append_locals procdesc [var_data] ; Procdesc.append_locals procdesc [var_data] ;
Exp.Lvar pvar 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 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 class_type = CType_decl.get_type_from_expr_info ei context.CContext.tenv in
let var_data : ProcAttributes.var_data = 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 in
Procdesc.append_locals procdesc [var_data] ; Procdesc.append_locals procdesc [var_data] ;
(Exp.Lvar pvar, class_type) (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 pvar = mk_temp_sil_var procdesc "SIL_temp_conditional___" in
let var_data = let var_data =
ProcAttributes. 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 in
Procdesc.append_locals procdesc [var_data] ; Procdesc.append_locals procdesc [var_data] ;
let continuation' = mk_cond_continuation trans_state.continuation in 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 res_trans = init_expr_trans trans_state var_exp_typ stmt_info (Some temp_exp) in
let _, typ = res_trans.return in let _, typ = res_trans.return in
let var_data = 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 in
Procdesc.append_locals procdesc [var_data] ; Procdesc.append_locals procdesc [var_data] ;
res_trans res_trans

@ -54,13 +54,10 @@ let sil_var_of_decl_ref context source_range decl_ref procname =
decl_ref ) decl_ref )
let get_var_attribute decl_info = let has_block_attribute decl_info =
let open Clang_ast_t in let open Clang_ast_t in
let has_block_attribute = List.exists decl_info.di_attributes ~f:(fun attr ->
List.exists decl_info.Clang_ast_t.di_attributes ~f:(fun attr -> match attr with BlocksAttr _ -> true | _ -> false )
match attr with BlocksAttr _ -> true | _ -> false )
in
if has_block_attribute then [ProcAttributes.Modify_in_block] else []
let add_var_to_locals procdesc var_decl typ pvar = 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 match var_decl with
| VarDecl (decl_info, _, _, vdi) -> | VarDecl (decl_info, _, _, vdi) ->
if not vdi.Clang_ast_t.vdi_is_global then 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 = let is_constexpr =
vdi.Clang_ast_t.vdi_is_const_expr vdi.Clang_ast_t.vdi_is_const_expr
|| (Typ.is_const typ.Typ.quals && vdi.Clang_ast_t.vdi_is_init_expr_cxx11_constant) || (Typ.is_const typ.Typ.quals && vdi.Clang_ast_t.vdi_is_init_expr_cxx11_constant)
in in
let var_data : ProcAttributes.var_data = 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 in
Procdesc.append_locals procdesc [var_data] Procdesc.append_locals procdesc [var_data]
| _ -> | _ ->

@ -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_ = translate_locals program tenv formals bytecode jbir_code in
let locals = let locals =
List.map locals_ ~f:(fun (name, typ) -> 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 in
let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in
let proc_attributes = let proc_attributes =

Loading…
Cancel
Save