From 127ba72982da279420fe41b3e70420e533aecfb7 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Fri, 25 Oct 2019 05:53:49 -0700 Subject: [PATCH] [pulse][minor] reduce code duplication for attribute "getters" Summary: This will be more useful later when adding another one. Reviewed By: ezgicicek, jberdine Differential Revision: D18115231 fbshipit-source-id: a0a01901a --- infer/src/pulse/PulseBaseMemory.ml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/infer/src/pulse/PulseBaseMemory.ml b/infer/src/pulse/PulseBaseMemory.ml index a4b14fe11..b8bd19346 100644 --- a/infer/src/pulse/PulseBaseMemory.ml +++ b/infer/src/pulse/PulseBaseMemory.ml @@ -82,15 +82,14 @@ let check_valid address memory = Ok () -let get_closure_proc_name address memory = - Graph.find_opt address (snd memory) - |> Option.bind ~f:(fun attributes -> Attributes.get_closure_proc_name attributes) +let get_attribute getter address memory = + let open Option.Monad_infix in + Graph.find_opt address (snd memory) >>= getter -let get_constant address memory = - Graph.find_opt address (snd memory) - |> Option.bind ~f:(fun attributes -> Attributes.get_constant attributes) +let get_closure_proc_name = get_attribute Attributes.get_closure_proc_name +let get_constant = get_attribute Attributes.get_constant let std_vector_reserve address memory = add_attribute address Attribute.StdVectorReserve memory