[componentkit][clang] Move is_factory_method to Ast_utils

Reviewed By: dulmarod

Differential Revision: D4060088

fbshipit-source-id: 9129152
master
Ryan Rhee 8 years ago committed by Facebook Github Bot
parent db94cae74b
commit 471beed515

@ -184,35 +184,6 @@ let component_with_unconventional_superclass_advice context decl =
None None
| _ -> assert false | _ -> assert false
let if_decl_to_di_pointer_opt if_decl =
match if_decl with
| Clang_ast_t.ObjCInterfaceDecl (if_decl_info, _, _, _, _) ->
Some if_decl_info.di_pointer
| _ -> None
let is_instance_type type_ptr =
match Ast_utils.name_opt_of_typedef_type_ptr type_ptr with
| Some name -> name = "instancetype"
| None -> false
let return_type_matches_class_type rtp type_decl_pointer =
if is_instance_type rtp then
true
else
let return_type_decl_opt = Ast_utils.type_ptr_to_objc_interface rtp in
let return_type_decl_pointer_opt =
Option.map if_decl_to_di_pointer_opt return_type_decl_opt in
(Some type_decl_pointer) = return_type_decl_pointer_opt
(** A class method that returns an instance of the class is a factory method. *)
let is_factory_method if_decl meth_decl =
let if_type_decl_pointer = if_decl_to_di_pointer_opt if_decl in
match meth_decl with
| Clang_ast_t.ObjCMethodDecl (_, _, omdi) ->
(not omdi.omdi_is_instance_method) &&
(return_type_matches_class_type omdi.omdi_result_type if_type_decl_pointer)
| _ -> false
(** Components should only have one factory method. (** Components should only have one factory method.
(They could technically have none if they re-use the parent class's factory (They could technically have none if they re-use the parent class's factory
@ -227,7 +198,7 @@ let component_with_multiple_factory_methods_advice context decl =
let check_interface if_decl = let check_interface if_decl =
match if_decl with match if_decl with
| Clang_ast_t.ObjCInterfaceDecl (decl_info, _, decls, _, _) -> | Clang_ast_t.ObjCInterfaceDecl (decl_info, _, decls, _, _) ->
let factory_methods = IList.filter (is_factory_method if_decl) decls in let factory_methods = IList.filter (Ast_utils.is_objc_factory_method if_decl) decls in
if (IList.length factory_methods) > 1 then if (IList.length factory_methods) > 1 then
Some { Some {
CIssue.issue = CIssue.Component_with_multiple_factory_methods; CIssue.issue = CIssue.Component_with_multiple_factory_methods;

@ -476,6 +476,35 @@ struct
type_ptr_to_objc_interface function_type_info.Clang_ast_t.fti_return_type type_ptr_to_objc_interface function_type_info.Clang_ast_t.fti_return_type
| _ -> None | _ -> None
let if_decl_to_di_pointer_opt if_decl =
match if_decl with
| Clang_ast_t.ObjCInterfaceDecl (if_decl_info, _, _, _, _) ->
Some if_decl_info.di_pointer
| _ -> None
let is_instance_type type_ptr =
match name_opt_of_typedef_type_ptr type_ptr with
| Some name -> name = "instancetype"
| None -> false
let return_type_matches_class_type rtp type_decl_pointer =
if is_instance_type rtp then
true
else
let return_type_decl_opt = type_ptr_to_objc_interface rtp in
let return_type_decl_pointer_opt =
Option.map if_decl_to_di_pointer_opt return_type_decl_opt in
(Some type_decl_pointer) = return_type_decl_pointer_opt
let is_objc_factory_method if_decl meth_decl =
let if_type_decl_pointer = if_decl_to_di_pointer_opt if_decl in
match meth_decl with
| Clang_ast_t.ObjCMethodDecl (_, _, omdi) ->
(not omdi.omdi_is_instance_method) &&
(return_type_matches_class_type omdi.omdi_result_type if_type_decl_pointer)
| _ -> false
(* (*
let rec getter_attribute_opt attributes = let rec getter_attribute_opt attributes =
match attributes with match attributes with

@ -172,6 +172,9 @@ sig
?blacklist:string list -> Clang_ast_t.decl option -> string list -> bool ?blacklist:string list -> Clang_ast_t.decl option -> string list -> bool
val type_ptr_to_objc_interface : Clang_ast_types.t_ptr -> Clang_ast_t.decl option val type_ptr_to_objc_interface : Clang_ast_types.t_ptr -> Clang_ast_t.decl option
(** A class method that returns an instance of the class is a factory method. *)
val is_objc_factory_method : Clang_ast_t.decl -> Clang_ast_t.decl -> bool
end end
module General_utils : module General_utils :

Loading…
Cancel
Save