[racerd] require container method to be non-static

Summary: Narrow container read/write modelled methods by requiring they are all non-static.

Reviewed By: ezgicicek

Differential Revision: D29331533

fbshipit-source-id: e0e445573
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent 2d1ccf5994
commit 5c0d3fce24

@ -84,97 +84,115 @@ let is_csharp_container_read =
let is_java_container_write = let is_java_container_write =
let open MethodMatcher in let matcher =
let array_methods = let open MethodMatcher in
["append"; "clear"; "delete"; "put"; "remove"; "removeAt"; "removeAtRange"; "setValueAt"] let array_methods =
["append"; "clear"; "delete"; "put"; "remove"; "removeAt"; "removeAtRange"; "setValueAt"]
in
(* https://developer.android.com/reference/androidx/core/util/Pools.SimplePool *)
make_android_support_template "Pools$SimplePool" ["acquire"; "release"]
(* https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap *)
@ make_android_support_template "SimpleArrayMap"
["clear"; "ensureCapacity"; "put"; "putAll"; "remove"; "removeAt"; "setValueAt"]
(* https://developer.android.com/reference/android/support/v4/util/SparseArrayCompat *)
@ make_android_support_template "SparseArrayCompat" array_methods
@ (* https://developer.android.com/reference/android/util/SparseArray *)
[ {default with classname= "android.util.SparseArray"; methods= array_methods}
; (* https://docs.oracle.com/javase/8/docs/api/java/util/List.html
Only methods not in parent interface [Collection] are listed *)
{default with classname= "java.util.List"; methods= ["replaceAll"; "retainAll"; "set"; "sort"]}
; (* https://docs.oracle.com/javase/8/docs/api/java/util/Map.html *)
{ default with
classname= "java.util.Map"
; methods=
["clear"; "merge"; "put"; "putAll"; "putIfAbsent"; "remove"; "replace"; "replaceAll"] }
; (* https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html *)
{ default with
classname= "java.util.Collection"
; methods= ["add"; "addAll"; "clear"; "remove"; "removeAll"; "removeIf"] }
; (* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Mac.html *)
{default with classname= "javax.crypto.Mac"; methods= ["update"; "init"; "doFinal"]} ]
|> of_records
in in
(* https://developer.android.com/reference/androidx/core/util/Pools.SimplePool *) fun tenv (pn : Procname.t) ->
make_android_support_template "Pools$SimplePool" ["acquire"; "release"] match pn with
(* https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap *) | Java java_pn ->
@ make_android_support_template "SimpleArrayMap" (not (Procname.Java.is_static java_pn)) && matcher tenv pn []
["clear"; "ensureCapacity"; "put"; "putAll"; "remove"; "removeAt"; "setValueAt"] | _ ->
(* https://developer.android.com/reference/android/support/v4/util/SparseArrayCompat *) L.die InternalError "is_java_container_write called with a non-Java procname.@\n"
@ make_android_support_template "SparseArrayCompat" array_methods
@ (* https://developer.android.com/reference/android/util/SparseArray *)
[ {default with classname= "android.util.SparseArray"; methods= array_methods}
; (* https://docs.oracle.com/javase/8/docs/api/java/util/List.html
Only methods not in parent interface [Collection] are listed *)
{default with classname= "java.util.List"; methods= ["replaceAll"; "retainAll"; "set"; "sort"]}
; (* https://docs.oracle.com/javase/8/docs/api/java/util/Map.html *)
{ default with
classname= "java.util.Map"
; methods= ["clear"; "merge"; "put"; "putAll"; "putIfAbsent"; "remove"; "replace"; "replaceAll"]
}
; (* https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html *)
{ default with
classname= "java.util.Collection"
; methods= ["add"; "addAll"; "clear"; "remove"; "removeAll"; "removeIf"] }
; (* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Mac.html *)
{default with classname= "javax.crypto.Mac"; methods= ["update"; "init"; "doFinal"]} ]
|> of_records
let is_java_container_read = let is_java_container_read =
let open MethodMatcher in let matcher =
let array_methods = ["clone"; "get"; "indexOfKey"; "indexOfValue"; "keyAt"; "size"; "valueAt"] in let open MethodMatcher in
(* https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap *) let array_methods =
make_android_support_template "SimpleArrayMap" ["clone"; "get"; "indexOfKey"; "indexOfValue"; "keyAt"; "size"; "valueAt"]
[ "containsKey" in
; "containsValue" (* https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap *)
; "get" make_android_support_template "SimpleArrayMap"
; "hashCode" [ "containsKey"
; "indexOfKey" ; "containsValue"
; "isEmpty" ; "get"
; "keyAt" ; "hashCode"
; "size" ; "indexOfKey"
; "valueAt" ] ; "isEmpty"
(* https://developer.android.com/reference/android/support/v4/util/SparseArrayCompat *) ; "keyAt"
@ make_android_support_template "SparseArrayCompat" array_methods ; "size"
@ (* https://developer.android.com/reference/android/util/SparseArray *) ; "valueAt" ]
[ {default with classname= "android.util.SparseArray"; methods= array_methods} (* https://developer.android.com/reference/android/support/v4/util/SparseArrayCompat *)
; (* https://docs.oracle.com/javase/8/docs/api/java/util/List.html @ make_android_support_template "SparseArrayCompat" array_methods
Only methods not in parent interface [Collection] are listed *) @ (* https://developer.android.com/reference/android/util/SparseArray *)
{ default with [ {default with classname= "android.util.SparseArray"; methods= array_methods}
classname= "java.util.List" ; (* https://docs.oracle.com/javase/8/docs/api/java/util/List.html
; methods= ["get"; "indexOf"; "isEmpty"; "lastIndexOf"; "listIterator"] } Only methods not in parent interface [Collection] are listed *)
; (* https://docs.oracle.com/javase/8/docs/api/java/util/Map.html *) { default with
{ default with classname= "java.util.List"
classname= "java.util.Map" ; methods= ["get"; "indexOf"; "isEmpty"; "lastIndexOf"; "listIterator"] }
; methods= ; (* https://docs.oracle.com/javase/8/docs/api/java/util/Map.html *)
[ "compute" { default with
; "computeIfAbsent" classname= "java.util.Map"
; "computeIfPresent" ; methods=
; "containsKey" [ "compute"
; "containsValue" ; "computeIfAbsent"
; "entrySet" ; "computeIfPresent"
; "equals" ; "containsKey"
; "forEach" ; "containsValue"
; "get" ; "entrySet"
; "getOrDefault" ; "equals"
; "hashCode" ; "forEach"
; "isEmpty" ; "get"
; "keySet" ; "getOrDefault"
; "size" ; "hashCode"
; "values" ] } ; "isEmpty"
; (* https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html *) ; "keySet"
{ default with ; "size"
classname= "java.util.Collection" ; "values" ] }
; methods= ; (* https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html *)
[ "contains" { default with
; "containsAll" classname= "java.util.Collection"
; "equals" ; methods=
; "get" [ "contains"
; "hashCode" ; "containsAll"
; "isEmpty" ; "equals"
; "iterator" ; "get"
; "parallelStream" ; "hashCode"
; "size" ; "isEmpty"
; "spliterator" ; "iterator"
; "stream" ; "parallelStream"
; "toArray" ] } ; "size"
; (* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Mac.html *) ; "spliterator"
{default with classname= "javax.crypto.Mac"; methods= ["doFinal"]} ] ; "stream"
|> of_records ; "toArray" ] }
; (* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Mac.html *)
{default with classname= "javax.crypto.Mac"; methods= ["doFinal"]} ]
|> of_records
in
fun tenv (pn : Procname.t) ->
match pn with
| Java java_pn ->
(not (Procname.Java.is_static java_pn)) && matcher tenv pn []
| _ ->
L.die InternalError "is_java_container_read called with a non-Java procname.@\n"
let is_cpp_container_read = let is_cpp_container_read =
@ -198,12 +216,12 @@ let is_cpp_container_write =
let is_container_write tenv pn = let is_container_write tenv pn =
match (pn : Procname.t) with match (pn : Procname.t) with
| CSharp _ when is_csharp_container_write tenv pn [] -> | CSharp _ ->
true is_csharp_container_write tenv pn []
| Java _ when is_java_container_write tenv pn [] -> | Java _ ->
true is_java_container_write tenv pn
| (ObjC_Cpp _ | C _) when is_cpp_container_write pn -> | ObjC_Cpp _ | C _ ->
true is_cpp_container_write pn
| _ -> | _ ->
false false
@ -213,7 +231,7 @@ let is_container_read tenv pn =
| CSharp _ -> | CSharp _ ->
is_csharp_container_read tenv pn [] is_csharp_container_read tenv pn []
| Java _ -> | Java _ ->
is_java_container_read tenv pn [] is_java_container_read tenv pn
(* The following order matters: we want to check if pname is a container write (* The following order matters: we want to check if pname is a container write
before we check if pname is a container read. This is due to a different before we check if pname is a container read. This is due to a different
treatment between std::map::operator[] and all other operator[]. *) treatment between std::map::operator[] and all other operator[]. *)

Loading…
Cancel
Save