Remove the concept of generated method from the frontend and proc attributes

Summary:
public The concept of generated method is not used anymore, so it is removed.
In general,  I think we have noticed that generating code in the frontend is not the best
idea because it decreases performance, it's better to do it in the backend like with the
getters/setters.

Reviewed By: akotulski

Differential Revision: D2739142

fb-gh-sync-id: 0cf9535
master
Dulma Rodriguez 9 years ago committed by facebook-github-bot-5
parent 1e5b8aeee7
commit b51da4f050

@ -700,12 +700,6 @@ let get_all_procs cfg =
let get_defined_procs cfg =
IList.filter Procdesc.is_defined (get_all_procs cfg)
(** Get the objc procedures whose body is generated *)
let get_objc_generated_procs cfg =
IList.filter (
fun procdesc ->
(Procdesc.get_attributes procdesc).ProcAttributes.is_generated) (get_all_procs cfg)
(** get the function names which should be analyzed before the other ones *)
let get_priority_procnames cfg =
cfg.Node.priority_set

@ -290,9 +290,6 @@ val get_all_procs : cfg -> Procdesc.t list
(** Get the procedures whose body is defined in this cfg *)
val get_defined_procs : cfg -> Procdesc.t list
(** Get the objc procedures whose body is generated *)
val get_objc_generated_procs : cfg -> Procdesc.t list
(** get the function names which should be analyzed before the other ones *)
val get_priority_procnames : cfg -> Procname.Set.t

@ -976,15 +976,10 @@ let pp_cfgnodelabel fmt (n : Cfg.Node.t) =
let pp_label fmt n =
match Cfg.Node.get_kind n with
| Cfg.Node.Start_node (pdesc) ->
let gen =
if (Cfg.Procdesc.get_attributes pdesc).ProcAttributes.is_generated
then " (generated)"
else "" in
(* let def = if Cfg.Procdesc.is_defined pdesc then "defined" else "declared" in *)
(* Format.fprintf fmt "Start %a (%s)" pp_id (Procname.to_string (Cfg.Procdesc.get_proc_name pdesc)) def *)
Format.fprintf fmt "Start %s%s\\nFormals: %a\\nLocals: %a"
Format.fprintf fmt "Start %s\\nFormals: %a\\nLocals: %a"
(Procname.to_string (Cfg.Procdesc.get_proc_name pdesc))
gen
pp_etlist (Cfg.Procdesc.get_formals pdesc)
pp_local_list (Cfg.Procdesc.get_locals pdesc);
if IList.length (Cfg.Procdesc.get_captured pdesc) <> 0 then

@ -29,7 +29,6 @@ type t =
is_abstract : bool; (** the procedure is abstract *)
mutable is_bridge_method : bool; (** the procedure is a bridge method *)
is_defined : bool; (** true if the procedure is defined, and not just declared *)
is_generated : bool; (** the procedure has been generated *)
is_objc_instance_method : bool; (** the procedure is an objective-C instance method *)
is_cpp_instance_method : bool; (** the procedure is an C++ instance method *)
objc_accessor : objc_accessor_type option; (** the proc is ObjC accessor *)
@ -54,7 +53,6 @@ let copy pa =
is_abstract = pa.is_abstract;
is_bridge_method = pa.is_bridge_method;
is_defined = pa.is_defined;
is_generated = pa.is_generated;
is_objc_instance_method = pa.is_objc_instance_method;
is_cpp_instance_method = pa.is_cpp_instance_method;
objc_accessor = pa.objc_accessor;
@ -78,7 +76,6 @@ let default proc_name language = {
is_abstract = false;
is_defined = false;
is_bridge_method = false;
is_generated = false;
is_objc_instance_method = false;
is_cpp_instance_method = false;
objc_accessor = None;

@ -26,7 +26,6 @@ type t =
is_abstract : bool; (** the procedure is abstract *)
mutable is_bridge_method : bool; (** the procedure is a bridge method *)
is_defined : bool; (** true if the procedure is defined, and not just declared *)
is_generated : bool; (** the procedure has been generated *)
is_objc_instance_method : bool; (** the procedure is an objective-C instance method *)
is_cpp_instance_method : bool; (** the procedure is an C++ instance method *)
objc_accessor : objc_accessor_type option; (** the proc is ObjC accessor *)

@ -149,8 +149,6 @@ let objects = "objects"
let enumerateObjectsUsingBlock = "enumerateObjectsUsingBlock:"
let generated_suffix = "*generated"
let pointer_type_index = ref Clang_ast_main.PointerMap.empty
(* Map from type pointers or declaration pointers to sil types *)

@ -141,8 +141,6 @@ val objects : string
val enumerateObjectsUsingBlock : string
val generated_suffix : string
(** Map from clang pointers to types produced by ast exporter.
Populated once on InferClang startup *)
val pointer_type_index : Clang_ast_t.c_type Clang_ast_main.PointerMap.t ref

@ -277,16 +277,6 @@ struct
| Some tp -> Some tp
| None -> None
let is_generated name_info =
match name_info.Clang_ast_t.ni_qual_name with
| name :: quals ->
(try
let rexp = Str.regexp CFrontend_config.generated_suffix in
let _ = Str.search_forward rexp name 0 in
true
with Not_found -> false)
| _ -> false
let get_decl decl_ptr =
try
Some (Clang_ast_main.PointerMap.find decl_ptr !CFrontend_config.pointer_decl_index)

@ -69,8 +69,6 @@ sig
val type_from_unary_expr_or_type_trait_expr_info :
Clang_ast_t.unary_expr_or_type_trait_expr_info -> Clang_ast_t.type_ptr option
val is_generated : Clang_ast_t.named_decl_info -> bool
val get_decl : Clang_ast_t.pointer -> Clang_ast_t.decl option
val get_decl_opt : Clang_ast_t.pointer option -> Clang_ast_t.decl option

@ -17,7 +17,6 @@ type method_signature = {
_attributes : Clang_ast_t.attribute list;
_loc : Clang_ast_t.source_range;
_is_instance : bool;
_is_generated : bool;
_language : CFrontend_config.lang;
_pointer_to_parent : Clang_ast_t.pointer option;
_pointer_to_property_opt : Clang_ast_t.pointer option; (* If set then method is a getter/setter *)
@ -44,9 +43,6 @@ let ms_get_loc ms =
let ms_is_instance ms =
ms._is_instance
let ms_is_generated ms =
ms._is_generated
let ms_get_lang ms =
ms._language
@ -68,7 +64,7 @@ let ms_is_setter ms =
Option.is_some ms._pointer_to_property_opt &&
IList.length ms._args == 2
let make_ms procname args ret_type attributes loc is_instance is_generated lang pointer_to_parent
let make_ms procname args ret_type attributes loc is_instance lang pointer_to_parent
pointer_to_property_opt =
let meth_signature = {
_name = procname;
@ -77,7 +73,6 @@ let make_ms procname args ret_type attributes loc is_instance is_generated lang
_attributes = attributes;
_loc = loc;
_is_instance = is_instance;
_is_generated = is_generated;
_language = lang;
_pointer_to_parent = pointer_to_parent;
_pointer_to_property_opt = pointer_to_property_opt;
@ -88,8 +83,7 @@ let replace_name_ms ms name =
{ ms with _name = name }
let ms_to_string ms =
let gen = if ms._is_generated then " (generated)" else "" in
"Method " ^ (Procname.to_string ms._name) ^ gen ^ " " ^
"Method " ^ (Procname.to_string ms._name) ^ " " ^
IList.to_string
(fun (s1, s2) -> s1 ^ ", " ^ (Clang_ast_j.string_of_type_ptr s2))
ms._args

@ -38,11 +38,9 @@ val ms_is_getter : method_signature -> bool
val ms_is_setter : method_signature -> bool
val make_ms : Procname.t -> (string * Clang_ast_t.type_ptr) list -> Clang_ast_t.type_ptr
-> Clang_ast_t.attribute list -> Clang_ast_t.source_range -> bool -> bool -> CFrontend_config.lang
-> Clang_ast_t.attribute list -> Clang_ast_t.source_range -> bool -> CFrontend_config.lang
-> Clang_ast_t.pointer option -> Clang_ast_t.pointer option -> method_signature
val replace_name_ms : method_signature -> Procname.t -> method_signature
val ms_to_string : method_signature -> string
val ms_is_generated : method_signature -> bool

@ -87,7 +87,7 @@ let get_return_type function_method_decl_info =
| ObjC_Meth_decl_info (method_decl_info, _) -> method_decl_info.Clang_ast_t.omdi_result_type
let build_method_signature decl_info procname function_method_decl_info is_anonym_block
is_generated parent_pointer pointer_to_property_opt =
parent_pointer pointer_to_property_opt =
let source_range = decl_info.Clang_ast_t.di_source_range in
let tp = get_return_type function_method_decl_info in
let is_instance_method = is_instance_method function_method_decl_info in
@ -95,8 +95,8 @@ let build_method_signature decl_info procname function_method_decl_info is_anony
let attributes = decl_info.Clang_ast_t.di_attributes in
let lang = get_language function_method_decl_info in
CMethod_signature.make_ms
procname parameters tp attributes source_range is_instance_method is_generated
lang parent_pointer pointer_to_property_opt
procname parameters tp attributes source_range is_instance_method lang parent_pointer
pointer_to_property_opt
let get_assume_not_null_calls param_decls =
let do_one_param decl = match decl with
@ -120,7 +120,7 @@ let method_signature_of_decl meth_decl block_data_opt =
let func_decl = Func_decl_info (fdi, tp, language) in
let function_info = Some (decl_info, fdi) in
let procname = General_utils.mk_procname_from_function name function_info tp language in
let ms = build_method_signature decl_info procname func_decl false false None None in
let ms = build_method_signature decl_info procname func_decl false None None in
let extra_instrs = get_assume_not_null_calls fdi.Clang_ast_t.fdi_parameters in
ms, fdi.Clang_ast_t.fdi_body, extra_instrs
| CXXMethodDecl (decl_info, name_info, tp, fdi, mdi), _
@ -130,7 +130,7 @@ let method_signature_of_decl meth_decl block_data_opt =
let procname = General_utils.mk_procname_from_cpp_method class_name method_name tp in
let method_decl = Cpp_Meth_decl_info (fdi, mdi, class_name, tp) in
let parent_pointer = decl_info.Clang_ast_t.di_parent_pointer in
let ms = build_method_signature decl_info procname method_decl false false parent_pointer
let ms = build_method_signature decl_info procname method_decl false parent_pointer
None in
let non_null_instrs = get_assume_not_null_calls fdi.Clang_ast_t.fdi_parameters in
let init_list_instrs = get_init_list_instrs mdi in (* it will be empty for methods *)
@ -142,19 +142,18 @@ let method_signature_of_decl meth_decl block_data_opt =
let method_kind = Procname.objc_method_kind_of_bool is_instance in
let procname = General_utils.mk_procname_from_objc_method class_name method_name method_kind in
let method_decl = ObjC_Meth_decl_info (mdi, class_name) in
let is_generated = Ast_utils.is_generated name_info in
let parent_pointer = decl_info.Clang_ast_t.di_parent_pointer in
let pointer_to_property_opt =
match mdi.Clang_ast_t.omdi_property_decl with
| Some decl_ref -> Some decl_ref.Clang_ast_t.dr_decl_pointer
| None -> None in
let ms = build_method_signature decl_info procname method_decl false is_generated
let ms = build_method_signature decl_info procname method_decl false
parent_pointer pointer_to_property_opt in
let extra_instrs = get_assume_not_null_calls mdi.omdi_parameters in
ms, mdi.omdi_body, extra_instrs
| BlockDecl (decl_info, bdi), Some (outer_context, tp, procname, _) ->
let func_decl = Block_decl_info (bdi, tp, outer_context) in
let ms = build_method_signature decl_info procname func_decl true false None None in
let ms = build_method_signature decl_info procname func_decl true None None in
let extra_instrs = get_assume_not_null_calls bdi.bdi_parameters in
ms, bdi.bdi_body, extra_instrs
| _ -> raise Invalid_declaration
@ -289,14 +288,11 @@ let sil_func_attributes_of_attributes attrs =
| _:: tl -> do_translation acc tl in
do_translation [] attrs
let should_create_procdesc cfg procname defined generated =
let should_create_procdesc cfg procname defined =
match Cfg.Procdesc.find_from_name cfg procname with
| Some prevoius_procdesc ->
let is_defined_previous = Cfg.Procdesc.is_defined prevoius_procdesc in
let is_generated_previous =
(Cfg.Procdesc.get_attributes prevoius_procdesc).ProcAttributes.is_generated in
if defined &&
((not is_defined_previous) || (generated && is_generated_previous)) then
if defined && (not is_defined_previous) then
(Cfg.Procdesc.remove cfg (Cfg.Procdesc.get_proc_name prevoius_procdesc) true;
true)
else false
@ -324,7 +320,6 @@ let create_local_procdesc cfg tenv ms fbody captured is_objc_inst_method =
let attributes = sil_func_attributes_of_attributes (CMethod_signature.ms_get_attributes ms) in
let method_annotation =
sil_method_annotation_of_args (CMethod_signature.ms_get_args ms) in
let is_generated = CMethod_signature.ms_is_generated ms in
let is_cpp_inst_method = CMethod_signature.ms_is_instance ms
&& CMethod_signature.ms_get_lang ms = CFrontend_config.CPP in
let create_new_procdesc () =
@ -348,7 +343,6 @@ let create_local_procdesc cfg tenv ms fbody captured is_objc_inst_method =
formals;
func_attributes = attributes;
is_defined = defined;
is_generated;
is_objc_instance_method = is_objc_inst_method;
is_cpp_instance_method = is_cpp_inst_method;
loc = loc_start;
@ -368,8 +362,7 @@ let create_local_procdesc cfg tenv ms fbody captured is_objc_inst_method =
let exit_node = Cfg.Node.create cfg loc_exit exit_kind [] procdesc [] in
Cfg.Procdesc.set_start_node procdesc start_node;
Cfg.Procdesc.set_exit_node procdesc exit_node) in
let generated = CMethod_signature.ms_is_generated ms in
if should_create_procdesc cfg proc_name defined generated then
if should_create_procdesc cfg proc_name defined then
(create_new_procdesc (); true)
else false
@ -427,7 +420,7 @@ let get_method_for_frontend_checks cfg cg tenv class_name decl_info =
| Some pdesc -> pdesc
| None ->
let ms = CMethod_signature.make_ms proc_name [] (Clang_ast_types.pointer_to_type_ptr "-1")
[] source_range false false CFrontend_config.OBJC None None in
[] source_range false CFrontend_config.OBJC None None in
let body = [Clang_ast_t.CompoundStmt (stmt_info, [])] in
ignore (create_local_procdesc cfg tenv ms body [] false);
let pdesc = Option.get (Cfg.Procdesc.find_from_name cfg proc_name) in

@ -33,8 +33,6 @@ val get_class_name_method_call_from_receiver_kind : CContext.t ->
val get_class_name_method_call_from_clang : Clang_ast_t.obj_c_message_expr_info -> string option
val should_create_procdesc : Cfg.cfg -> Procname.t -> bool -> bool -> bool
val method_signature_of_decl : Clang_ast_t.decl -> CModule_type.block_data option ->
CMethod_signature.method_signature * Clang_ast_t.stmt option * CModule_type.instr_type list

@ -127,7 +127,7 @@ let get_predefined_ms_method condition class_name method_name method_kind mk_pro
| Some procname -> procname
| None -> mk_procname class_name method_name method_kind in
let ms = CMethod_signature.make_ms procname arguments return_type attributes
(Ast_expressions.dummy_source_range ()) false false lang None None in
(Ast_expressions.dummy_source_range ()) false lang None None in
Some ms
else None

@ -269,14 +269,6 @@ let get_memory_management_attribute attributes =
att memory_management_attributes) attributes)
with Not_found -> None
let create_generated_method_name name_info =
let qual_name = match name_info.Clang_ast_t.ni_qual_name with
| [] -> []
| name :: quals -> (name ^ CFrontend_config.generated_suffix) :: quals in
{ Clang_ast_t.ni_name = name_info.Clang_ast_t.ni_name;
ni_qual_name = qual_name;
}
let get_ivar_name prop_name ivar_opt =
match ivar_opt with
| Some ivar_name -> ivar_name

Loading…
Cancel
Save