[procname][refactor] Move is_cpp_lambda to Procname

Reviewed By: skcho

Differential Revision: D26946308

fbshipit-source-id: 464ecfe4b
master
Daiva Naudziuniene 4 years ago committed by Facebook GitHub Bot
parent 778c629401
commit aae28efb44

@ -841,15 +841,11 @@ let is_captured_pvar procdesc pvar =
in in
let pvar_matches (name, _) = Mangled.equal name pvar_name in let pvar_matches (name, _) = Mangled.equal name pvar_name in
let is_captured_var_cpp_lambda = let is_captured_var_cpp_lambda =
match procname with
| Procname.ObjC_Cpp cpp_pname ->
(* var is captured if the procedure is a lambda and the var is not in the locals or formals *) (* var is captured if the procedure is a lambda and the var is not in the locals or formals *)
Procname.ObjC_Cpp.is_cpp_lambda cpp_pname Procname.is_cpp_lambda procname
&& not && not
( List.exists ~f:pvar_local_matches (get_locals procdesc) ( List.exists ~f:pvar_local_matches (get_locals procdesc)
|| List.exists ~f:pvar_matches (get_formals procdesc) ) || List.exists ~f:pvar_matches (get_formals procdesc) )
| _ ->
false
in in
let pvar_matches_in_captured {CapturedVar.name} = Mangled.equal name pvar_name in let pvar_matches_in_captured {CapturedVar.name} = Mangled.equal name pvar_name in
let is_captured_var_objc_block = let is_captured_var_objc_block =

@ -624,6 +624,14 @@ let rec get_method = function
(** Return whether the procname is a block procname. *) (** Return whether the procname is a block procname. *)
let is_objc_block = function Block _ -> true | _ -> false let is_objc_block = function Block _ -> true | _ -> false
(** Return whether the procname is a cpp lambda procname. *)
let is_cpp_lambda = function
| ObjC_Cpp cpp_pname when ObjC_Cpp.is_cpp_lambda cpp_pname ->
true
| _ ->
false
(** Return the language of the procedure. *) (** Return the language of the procedure. *)
let get_language = function let get_language = function
| ObjC_Cpp _ -> | ObjC_Cpp _ ->

@ -181,9 +181,6 @@ module ObjC_Cpp : sig
val is_constexpr : t -> bool val is_constexpr : t -> bool
(** Check if this is a constexpr function. *) (** Check if this is a constexpr function. *)
val is_cpp_lambda : t -> bool
(** Return whether the procname is a cpp lambda. *)
end end
module C : sig module C : sig
@ -316,6 +313,9 @@ val get_method : t -> string
val is_objc_block : t -> bool val is_objc_block : t -> bool
(** Return whether the procname is a block procname. *) (** Return whether the procname is a block procname. *)
val is_cpp_lambda : t -> bool
(** Return whether the procname is a cpp lambda procname. *)
val is_objc_dealloc : t -> bool val is_objc_dealloc : t -> bool
(** Return whether the dealloc method of an Objective-C class. *) (** Return whether the dealloc method of an Objective-C class. *)

@ -831,17 +831,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
(* Captured variables without initialization do not have the correct types (* Captured variables without initialization do not have the correct types
inside of lambda bodies. The same issue happens for variables captured by reference inside of lambda bodies. The same issue happens for variables captured by reference
inside objc blocks. Use the types stored in the procdesc. *) inside objc blocks. Use the types stored in the procdesc. *)
let is_objc_block_or_cpp_lambda =
match procname with
| Procname.ObjC_Cpp cpp_pname when Procname.ObjC_Cpp.is_cpp_lambda cpp_pname ->
true
| Block _ ->
true
| _ ->
false
in
let typ = let typ =
if is_objc_block_or_cpp_lambda then if Procname.is_cpp_lambda procname || Procname.is_objc_block procname then
let pvar_name = Pvar.get_name pvar in let pvar_name = Pvar.get_name pvar in
List.find (Procdesc.get_captured context.procdesc) List.find (Procdesc.get_captured context.procdesc)
~f:(fun {CapturedVar.name= captured_var} -> Mangled.equal captured_var pvar_name) ~f:(fun {CapturedVar.name= captured_var} -> Mangled.equal captured_var pvar_name)

@ -365,7 +365,7 @@ let should_report_on_proc tenv procdesc =
&& (not (Procname.Java.is_class_initializer java_pname)) && (not (Procname.Java.is_class_initializer java_pname))
&& (not (Procname.Java.is_autogen_method java_pname)) && (not (Procname.Java.is_autogen_method java_pname))
&& not (Annotations.pdesc_return_annot_ends_with procdesc Annotations.visibleForTesting) && not (Annotations.pdesc_return_annot_ends_with procdesc Annotations.visibleForTesting)
| ObjC_Cpp objc_cpp when Procname.ObjC_Cpp.is_cpp_lambda objc_cpp -> | ObjC_Cpp _ when Procname.is_cpp_lambda proc_name ->
(* do not report on lambdas; they are essentially private though do not appear as such *) (* do not report on lambdas; they are essentially private though do not appear as such *)
false false
| ObjC_Cpp {kind= CPPMethod _ | CPPConstructor _ | CPPDestructor _} -> | ObjC_Cpp {kind= CPPMethod _ | CPPConstructor _ | CPPDestructor _} ->

Loading…
Cancel
Save