[cleanup] adding Annotations.pname_has_return_annot function

Reviewed By: jberdine

Differential Revision: D4475437

fbshipit-source-id: b20979c
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent cc8ffd9d1e
commit 50c73e517b

@ -596,14 +596,15 @@ let process_results_table file_env tab =
(* TODO (t15588153): clean this up *) (* TODO (t15588153): clean this up *)
let is_thread_safe_method pdesc tenv = let is_thread_safe_method pdesc tenv =
let overrides_thread_safe_method pname 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 let found = ref false in
PatternMatch.proc_iter_overridden_methods PatternMatch.proc_iter_overridden_methods
(fun pn -> (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 tenv
pname; pname;
!found in !found in

@ -127,11 +127,8 @@ let is_allocator tenv pname =
false false
let check_attributes check tenv pname = let check_attributes check tenv pname =
let check_method_attributes check pname = PatternMatch.check_class_attributes check tenv pname ||
match Specs.proc_resolve_attributes pname with Annotations.pname_has_return_annot pname ~attrs_of_pname:Specs.proc_resolve_attributes check
| None -> false
| Some attributes -> check (fst attributes.ProcAttributes.method_annotation) in
PatternMatch.check_class_attributes check tenv pname || check_method_attributes check pname
let method_overrides is_annotated tenv pname = let method_overrides is_annotated tenv pname =
let overrides () = let overrides () =

@ -107,6 +107,13 @@ let pdesc_has_return_annot pdesc predicate =
let pdesc_return_annot_ends_with pdesc annot = let pdesc_return_annot_ends_with pdesc annot =
pdesc_has_return_annot pdesc (fun ia -> ia_ends_with ia 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 field_has_annot fieldname (struct_typ : StructTyp.t) predicate =
let fld_has_taint_annot (fname, _, annot) = let fld_has_taint_annot (fname, _, annot) =
Ident.equal_fieldname fieldname fname && predicate annot in Ident.equal_fieldname fieldname fname && predicate annot in

@ -126,6 +126,15 @@ val pdesc_get_return_annot : Procdesc.t -> Annot.Item.t
value *) value *)
val pdesc_has_return_annot : Procdesc.t -> (Annot.Item.t -> bool) -> bool 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 *) (** 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 val pdesc_return_annot_ends_with : Procdesc.t -> string -> bool

Loading…
Cancel
Save