|
|
@ -312,12 +312,21 @@ let get_current_class_and_annotated_superclasses is_annot tenv pname =
|
|
|
|
None
|
|
|
|
None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let find_annotated_or_overriden_annotated_method ~attrs_of_pname is_annot pname tenv =
|
|
|
|
let is_class_or_superclasses_annotated is_annot tenv pname =
|
|
|
|
|
|
|
|
get_current_class_and_annotated_superclasses is_annot tenv pname
|
|
|
|
|
|
|
|
|> Option.exists ~f:(fun (_, annotated) -> not (List.is_empty annotated))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let find_method_or_override_annotated ~attrs_of_pname is_annot pname tenv =
|
|
|
|
PatternMatch.override_find
|
|
|
|
PatternMatch.override_find
|
|
|
|
(fun pn -> Annotations.pname_has_return_annot pn ~attrs_of_pname is_annot)
|
|
|
|
(fun pn -> Annotations.pname_has_return_annot pn ~attrs_of_pname is_annot)
|
|
|
|
tenv pname
|
|
|
|
tenv pname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let is_method_or_override_annotated ~attrs_of_pname is_annot pname tenv =
|
|
|
|
|
|
|
|
find_method_or_override_annotated ~attrs_of_pname is_annot pname tenv |> Option.is_some
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let ui_matcher_records =
|
|
|
|
let ui_matcher_records =
|
|
|
|
let open MethodMatcher in
|
|
|
|
let open MethodMatcher in
|
|
|
|
let fragment_methods =
|
|
|
|
let fragment_methods =
|
|
|
@ -362,57 +371,64 @@ let is_ui_method =
|
|
|
|
fun tenv pname -> MethodMatcher.of_list matchers tenv pname []
|
|
|
|
fun tenv pname -> MethodMatcher.of_list matchers tenv pname []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let runs_on_ui_thread =
|
|
|
|
let if_pred_evalopt ~pred ~f x =
|
|
|
|
(* assume that methods annotated with @UiThread, @OnEvent, @OnBind, @OnMount, @OnUnbind,
|
|
|
|
IOption.if_none_evalopt x ~f:(fun () -> if pred () then Some (f ()) else None)
|
|
|
|
@OnUnmount always run on the UI thread *)
|
|
|
|
|
|
|
|
let annotation_matchers =
|
|
|
|
|
|
|
|
[ Annotations.ia_is_mainthread
|
|
|
|
(* assume that methods annotated with @MainThread, @UiThread,
|
|
|
|
; Annotations.ia_is_ui_thread
|
|
|
|
and any string starting with "On" always run on the UI thread.
|
|
|
|
; Annotations.ia_is_on_bind
|
|
|
|
We do the latter because there are too many to precisely list. *)
|
|
|
|
; Annotations.ia_is_on_event
|
|
|
|
let is_uithread annots =
|
|
|
|
; Annotations.ia_is_on_mount
|
|
|
|
let f (annot, _) =
|
|
|
|
; Annotations.ia_is_on_unbind
|
|
|
|
let ending = Annotations.get_annot_ending annot in
|
|
|
|
; Annotations.ia_is_on_unmount ]
|
|
|
|
String.equal ending Annotations.mainthread
|
|
|
|
|
|
|
|
|| String.equal ending Annotations.ui_thread
|
|
|
|
|
|
|
|
|| String.is_prefix ~prefix:"On" ending
|
|
|
|
in
|
|
|
|
in
|
|
|
|
let is_annot annot = List.exists annotation_matchers ~f:(fun m -> m annot) in
|
|
|
|
List.exists annots ~f
|
|
|
|
let mono_pname = MF.wrap_monospaced Typ.Procname.pp in
|
|
|
|
|
|
|
|
fun ~attrs_of_pname tenv proc_desc ->
|
|
|
|
|
|
|
|
let pname = Procdesc.get_proc_name proc_desc in
|
|
|
|
let mono_pname = MF.wrap_monospaced Typ.Procname.pp
|
|
|
|
if
|
|
|
|
|
|
|
|
Annotations.pdesc_has_return_annot proc_desc Annotations.ia_is_worker_thread
|
|
|
|
let runs_on_ui_thread ~attrs_of_pname tenv proc_desc =
|
|
|
|
|| find_annotated_or_overriden_annotated_method ~attrs_of_pname
|
|
|
|
let pname = Procdesc.get_proc_name proc_desc in
|
|
|
|
Annotations.ia_is_worker_thread pname tenv
|
|
|
|
if
|
|
|
|
|> Option.is_some
|
|
|
|
is_method_or_override_annotated ~attrs_of_pname Annotations.ia_is_worker_thread pname tenv
|
|
|
|
|| get_current_class_and_annotated_superclasses Annotations.ia_is_worker_thread tenv pname
|
|
|
|
|| is_class_or_superclasses_annotated Annotations.ia_is_worker_thread tenv pname
|
|
|
|
|> Option.value_map ~default:false ~f:(function _, [] -> false | _ -> true)
|
|
|
|
then None
|
|
|
|
then None
|
|
|
|
else
|
|
|
|
else if is_ui_method tenv pname then
|
|
|
|
None
|
|
|
|
Some (F.asprintf "%a is a standard UI-thread method" mono_pname pname)
|
|
|
|
|> if_pred_evalopt
|
|
|
|
else if Annotations.pdesc_has_return_annot proc_desc is_annot then
|
|
|
|
~pred:(fun () -> is_ui_method tenv pname)
|
|
|
|
Some
|
|
|
|
~f:(fun () -> F.asprintf "%a is a standard UI-thread method" mono_pname pname)
|
|
|
|
(F.asprintf "%a is annotated %s" mono_pname pname
|
|
|
|
|> if_pred_evalopt
|
|
|
|
(MF.monospaced_to_string Annotations.ui_thread))
|
|
|
|
~pred:(fun () -> Annotations.pdesc_has_return_annot proc_desc is_uithread)
|
|
|
|
else
|
|
|
|
~f:(fun () ->
|
|
|
|
match find_annotated_or_overriden_annotated_method ~attrs_of_pname is_annot pname tenv with
|
|
|
|
F.asprintf "%a is annotated %s" mono_pname pname
|
|
|
|
| Some override_pname ->
|
|
|
|
(MF.monospaced_to_string Annotations.ui_thread) )
|
|
|
|
Some
|
|
|
|
|> IOption.if_none_evalopt ~f:(fun () ->
|
|
|
|
(F.asprintf "class %a overrides %a, which is annotated %s" mono_pname pname mono_pname
|
|
|
|
find_method_or_override_annotated ~attrs_of_pname is_uithread pname tenv
|
|
|
|
override_pname
|
|
|
|
|> Option.map ~f:(fun override_pname ->
|
|
|
|
(MF.monospaced_to_string Annotations.ui_thread))
|
|
|
|
F.asprintf "class %a overrides %a, which is annotated %s" mono_pname pname
|
|
|
|
| None -> (
|
|
|
|
mono_pname override_pname
|
|
|
|
match get_current_class_and_annotated_superclasses is_annot tenv pname with
|
|
|
|
(MF.monospaced_to_string Annotations.ui_thread) ) )
|
|
|
|
| Some (current_class, (super_class :: _ as super_classes)) ->
|
|
|
|
|> IOption.if_none_evalopt ~f:(fun () ->
|
|
|
|
let middle =
|
|
|
|
get_current_class_and_annotated_superclasses is_uithread tenv pname
|
|
|
|
if List.exists super_classes ~f:(Typ.Name.equal current_class) then ""
|
|
|
|
|> Option.bind ~f:(function
|
|
|
|
else F.asprintf " extends %a, which" (MF.wrap_monospaced Typ.Name.pp) super_class
|
|
|
|
| current_class, (super_class :: _ as super_classes) ->
|
|
|
|
in
|
|
|
|
let middle =
|
|
|
|
Some
|
|
|
|
if List.exists super_classes ~f:(Typ.Name.equal current_class) then ""
|
|
|
|
(F.asprintf "class %s%s is annotated %s"
|
|
|
|
else
|
|
|
|
(MF.monospaced_to_string (Typ.Name.name current_class))
|
|
|
|
F.asprintf " extends %a, which" (MF.wrap_monospaced Typ.Name.pp)
|
|
|
|
middle
|
|
|
|
super_class
|
|
|
|
(MF.monospaced_to_string Annotations.ui_thread))
|
|
|
|
in
|
|
|
|
| _ ->
|
|
|
|
Some
|
|
|
|
None )
|
|
|
|
(F.asprintf "class %s%s is annotated %s"
|
|
|
|
|
|
|
|
(MF.monospaced_to_string (Typ.Name.name current_class))
|
|
|
|
|
|
|
|
middle
|
|
|
|
|
|
|
|
(MF.monospaced_to_string Annotations.ui_thread))
|
|
|
|
|
|
|
|
| _ ->
|
|
|
|
|
|
|
|
None ) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let cpp_lock_types_matcher = Clang.lock_types_matcher
|
|
|
|
let cpp_lock_types_matcher = Clang.lock_types_matcher
|
|
|
|