From 50c73e517b39763f101aa9db685b598cac13fcc4 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Mon, 30 Jan 2017 11:28:19 -0800 Subject: [PATCH] [cleanup] adding Annotations.pname_has_return_annot function Reviewed By: jberdine Differential Revision: D4475437 fbshipit-source-id: b20979c --- infer/src/checkers/ThreadSafety.ml | 11 ++++++----- infer/src/checkers/annotationReachability.ml | 7 ++----- infer/src/checkers/annotations.ml | 7 +++++++ infer/src/checkers/annotations.mli | 9 +++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 36157d090..12e4e1110 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -596,14 +596,15 @@ let process_results_table file_env tab = (* TODO (t15588153): clean this up *) let is_thread_safe_method pdesc tenv = let overrides_thread_safe_method pname tenv = - let check_method_attributes check pname = - match Specs.proc_resolve_attributes pname with - | None -> false - | Some attributes -> check (fst attributes.ProcAttributes.method_annotation) in let found = ref false in PatternMatch.proc_iter_overridden_methods (fun pn -> - found := !found || check_method_attributes Annotations.ia_is_thread_safe_method pn) + found := + !found || + Annotations.pname_has_return_annot + pn + ~attrs_of_pname:Specs.proc_resolve_attributes + Annotations.ia_is_thread_safe_method) tenv pname; !found in diff --git a/infer/src/checkers/annotationReachability.ml b/infer/src/checkers/annotationReachability.ml index c01e4cd5b..a14548c89 100644 --- a/infer/src/checkers/annotationReachability.ml +++ b/infer/src/checkers/annotationReachability.ml @@ -127,11 +127,8 @@ let is_allocator tenv pname = false let check_attributes check tenv pname = - let check_method_attributes check pname = - match Specs.proc_resolve_attributes pname with - | None -> false - | Some attributes -> check (fst attributes.ProcAttributes.method_annotation) in - PatternMatch.check_class_attributes check tenv pname || check_method_attributes check pname + PatternMatch.check_class_attributes check tenv pname || + Annotations.pname_has_return_annot pname ~attrs_of_pname:Specs.proc_resolve_attributes check let method_overrides is_annotated tenv pname = let overrides () = diff --git a/infer/src/checkers/annotations.ml b/infer/src/checkers/annotations.ml index fe54ff0e1..9004cfe2d 100644 --- a/infer/src/checkers/annotations.ml +++ b/infer/src/checkers/annotations.ml @@ -107,6 +107,13 @@ let pdesc_has_return_annot pdesc predicate = let pdesc_return_annot_ends_with pdesc annot = pdesc_has_return_annot pdesc (fun ia -> ia_ends_with ia annot) +(* note: we would use Specs.proc_resolve_attributes directly instead of requiring [attrs_of_pname], + but doing so creates a circular dependency *) +let pname_has_return_annot pname ~attrs_of_pname predicate = + match attrs_of_pname pname with + | Some attributes -> predicate (fst attributes.ProcAttributes.method_annotation) + | None -> false + let field_has_annot fieldname (struct_typ : StructTyp.t) predicate = let fld_has_taint_annot (fname, _, annot) = Ident.equal_fieldname fieldname fname && predicate annot in diff --git a/infer/src/checkers/annotations.mli b/infer/src/checkers/annotations.mli index 60aaf0d02..1f518ded5 100644 --- a/infer/src/checkers/annotations.mli +++ b/infer/src/checkers/annotations.mli @@ -126,6 +126,15 @@ val pdesc_get_return_annot : Procdesc.t -> Annot.Item.t value *) val pdesc_has_return_annot : Procdesc.t -> (Annot.Item.t -> bool) -> bool +(** return true if the given predicate evaluates to true on the annotation of [pname]'s return + value. the function [attrs_of_pname] should resolve the proc attributes of [pname]. + Specs.proc_resolve_attributes is a good choice for this resolution function. *) +val pname_has_return_annot : + Procname.t -> + attrs_of_pname:(Procname.t -> ProcAttributes.t option) -> + (Annot.Item.t -> bool) -> + bool + (** return true if [pdesc]'s return value is annotated with a value ending with the given string *) val pdesc_return_annot_ends_with : Procdesc.t -> string -> bool