[clang][frontend] Allow custom blacklist for checking objc descendant

Reviewed By: dulmarod

Differential Revision: D3940347

fbshipit-source-id: 3142727
master
Ryan Rhee 8 years ago committed by Facebook Github Bot
parent 07797410cc
commit b635269fa8

@ -97,6 +97,16 @@ module StringSet = Set.Make(String)
let pp_stringset fmt ss =
StringSet.iter (fun s -> F.fprintf fmt "%s " s) ss
(** string list -> StringSet.t
from http://stackoverflow.com/a/2382330 *)
let string_set_of_list list =
IList.fold_left (fun acc x -> StringSet.add x acc) StringSet.empty list
(** intersection of two string lists, as a StringSet.t
from http://stackoverflow.com/a/2382330 *)
let string_list_intersection a b =
StringSet.inter (string_set_of_list a) (string_set_of_list b)
(** Maps from integers *)
module IntMap = Map.Make (struct
type t = int

@ -92,6 +92,12 @@ module StringSet : Set.S with type elt = string
(** Pretty print a set of strings *)
val pp_stringset : Format.formatter -> StringSet.t -> unit
(** list of strings -> set of strings *)
val string_set_of_list : string list -> StringSet.t
(** List intersection *)
val string_list_intersection : string list -> string list -> StringSet.t
(** Maps from integers *)
module IntMap : Map.S with type key = int

@ -442,11 +442,18 @@ struct
let file_opt = (fst decl_info.Clang_ast_t.di_source_range).Clang_ast_t.sl_file in
opt_equal string_equal file_opt Config.source_file && Option.is_some file_opt
let rec is_objc_if_descendant if_decl ancestors =
let default_blacklist =
let open CFrontend_config in
[nsobject_cl; nsproxy_cl]
let rec is_objc_if_descendant ?(blacklist = default_blacklist) if_decl ancestors =
(* List of ancestors to check for and list of classes to short-circuit to
false can't intersect *)
if not (StringSet.is_empty (string_list_intersection blacklist ancestors)) then
failwith "Blacklist and ancestors must be mutually exclusive."
else
match if_decl with
| Some Clang_ast_t.ObjCInterfaceDecl (_, ndi, _, _, _) ->
let open CFrontend_config in
let blacklist = [nsobject_cl; nsproxy_cl] in
let in_list some_list = IList.mem string_equal ndi.Clang_ast_t.ni_name some_list in
if in_list ancestors then
true

@ -165,8 +165,11 @@ sig
eventual descendant of one of the classes passed in.
Ancestors param is a list of strings that represent the class names.
Will short-circuit on NSObject and NSProxy since those are known to be
common base classes. *)
val is_objc_if_descendant : Clang_ast_t.decl option -> (string) list -> bool
common base classes.
The list of classes to short-circuit on can be overridden via specifying
the named `blacklist` argument. *)
val is_objc_if_descendant :
?blacklist:string list -> Clang_ast_t.decl option -> string list -> bool
end

Loading…
Cancel
Save