From 46c0c0297bf0c169ebba4f048b90120f019c311b Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 29 Apr 2021 07:26:00 -0700 Subject: [PATCH] [refactor] Pvar.is_local_to_procedure Summary: Small refactor as this function belongs more in Pvar than Var. Reviewed By: skcho Differential Revision: D28091618 fbshipit-source-id: 259bd82d5 --- infer/src/IR/Pvar.ml | 4 ++++ infer/src/IR/Pvar.mli | 2 ++ infer/src/IR/Var.ml | 9 +-------- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/infer/src/IR/Pvar.ml b/infer/src/IR/Pvar.ml index 02698d62d..1f97a5f2d 100644 --- a/infer/src/IR/Pvar.ml +++ b/infer/src/IR/Pvar.ml @@ -335,3 +335,7 @@ end) let get_pvar_formals (attributes : ProcAttributes.t) = let pname = attributes.proc_name in List.map attributes.formals ~f:(fun (name, typ) -> (mk name pname, typ)) + + +let is_local_to_procedure proc_name pvar = + get_declaring_function pvar |> Option.exists ~f:(Procname.equal proc_name) diff --git a/infer/src/IR/Pvar.mli b/infer/src/IR/Pvar.mli index b37f68eeb..de818a475 100644 --- a/infer/src/IR/Pvar.mli +++ b/infer/src/IR/Pvar.mli @@ -162,6 +162,8 @@ val is_pod : t -> bool (** Is the variable's type a "Plain Old Data" type (C++)? Always (potentially incorrectly) returns [true] for non-globals. *) +val is_local_to_procedure : Procname.t -> t -> bool + val get_initializer_pname : t -> Procname.t option (** Get the procname of the initializer function for the given global variable *) diff --git a/infer/src/IR/Var.ml b/infer/src/IR/Var.ml index d540a0a2d..f09037cb3 100644 --- a/infer/src/IR/Var.ml +++ b/infer/src/IR/Var.ml @@ -48,15 +48,8 @@ let is_none = function LogicalVar id -> Ident.is_none id | _ -> false let is_this = function ProgramVar pv -> Pvar.is_this pv | LogicalVar _ -> false -let get_declaring_function = function - | LogicalVar _ -> - None - | ProgramVar pvar -> - Pvar.get_declaring_function pvar - - let is_local_to_procedure proc_name var = - get_declaring_function var |> Option.exists ~f:(Procname.equal proc_name) + get_pvar var |> Option.exists ~f:(fun pvar -> Pvar.is_local_to_procedure proc_name pvar) let get_all_vars_in_exp e =