[componentkit] Move is_in_main_file check to CTL

Reviewed By: dulmarod

Differential Revision: D4203449

fbshipit-source-id: 0a56415
master
Ryan Rhee 8 years ago committed by Facebook Github Bot
parent b2cef3e0b2
commit a2c8c94a3b

@ -10,9 +10,28 @@
open CFrontend_utils open CFrontend_utils
open !Utils open !Utils
let is_ck_context (context: CLintersContext.context) decl = let get_source_range an =
match an with
| CTL.Decl decl ->
let decl_info = Clang_ast_proj.get_decl_tuple decl in
decl_info.Clang_ast_t.di_source_range
| CTL.Stmt stmt ->
let stmt_info, _ = Clang_ast_proj.get_stmt_tuple stmt in
stmt_info.Clang_ast_t.si_source_range
let is_in_main_file translation_unit_context an =
let file_opt = (fst (get_source_range an)).Clang_ast_t.sl_file in
match file_opt with
| None ->
false
| Some file ->
DB.inode_equal
(CLocation.source_file_from_path file)
translation_unit_context.CFrontend_config.source_file
let is_ck_context (context: CLintersContext.context) an =
context.is_ck_translation_unit context.is_ck_translation_unit
&& Ast_utils.is_in_main_file context.translation_unit_context decl && is_in_main_file context.translation_unit_context an
&& General_utils.is_objc_extension context.translation_unit_context && General_utils.is_objc_extension context.translation_unit_context
@ -92,7 +111,7 @@ let mutable_local_vars_advice context an =
qt_is_const qt_is_const
| _ -> false in | _ -> false in
let is_const = qual_type.qt_is_const || is_const_ref in let is_const = qual_type.qt_is_const || is_const_ref in
let condition = is_ck_context context decl let condition = is_ck_context context an
&& (not (Ast_utils.is_syntactically_global_var decl)) && (not (Ast_utils.is_syntactically_global_var decl))
&& (not is_const) && (not is_const)
&& not (is_of_whitelisted_type qual_type) && not (is_of_whitelisted_type qual_type)
@ -118,11 +137,11 @@ let component_factory_function_advice context an =
Ast_utils.is_objc_if_descendant decl [CFrontend_config.ckcomponent_cl] in Ast_utils.is_objc_if_descendant decl [CFrontend_config.ckcomponent_cl] in
match an with match an with
| CTL.Decl (Clang_ast_t.FunctionDecl (decl_info, _, (qual_type: Clang_ast_t.qual_type), _) as decl) -> | CTL.Decl (Clang_ast_t.FunctionDecl (decl_info, _, (qual_type: Clang_ast_t.qual_type), _)) ->
let objc_interface = let objc_interface =
Ast_utils.type_ptr_to_objc_interface qual_type.qt_type_ptr in Ast_utils.type_ptr_to_objc_interface qual_type.qt_type_ptr in
let condition = let condition =
is_ck_context context decl && is_component_if objc_interface in is_ck_context context an && is_component_if objc_interface in
if condition then if condition then
CTL.True, Some { CTL.True, Some {
CIssue.issue = CIssue.Component_factory_function; CIssue.issue = CIssue.Component_factory_function;
@ -178,10 +197,10 @@ let component_with_unconventional_superclass_advice context an =
CTL.False, None CTL.False, None
| _ -> assert false in | _ -> assert false in
match an with match an with
| CTL.Decl (Clang_ast_t.ObjCImplementationDecl (_, _, _, _, impl_decl_info) as decl) -> | CTL.Decl (Clang_ast_t.ObjCImplementationDecl (_, _, _, _, impl_decl_info)) ->
let if_decl_opt = let if_decl_opt =
Ast_utils.get_decl_opt_with_decl_ref impl_decl_info.oidi_class_interface in Ast_utils.get_decl_opt_with_decl_ref impl_decl_info.oidi_class_interface in
if Option.is_some if_decl_opt && is_ck_context context decl then if Option.is_some if_decl_opt && is_ck_context context an then
check_interface (Option.get if_decl_opt) check_interface (Option.get if_decl_opt)
else else
CTL.False, None CTL.False, None
@ -226,11 +245,11 @@ let component_with_multiple_factory_methods_advice context an =
CTL.False, None CTL.False, None
| _ -> assert false in | _ -> assert false in
match an with match an with
| CTL.Decl (Clang_ast_t.ObjCImplementationDecl (_, _, _, _, impl_decl_info) as decl) -> | CTL.Decl (Clang_ast_t.ObjCImplementationDecl (_, _, _, _, impl_decl_info)) ->
let if_decl_opt = let if_decl_opt =
Ast_utils.get_decl_opt_with_decl_ref impl_decl_info.oidi_class_interface in Ast_utils.get_decl_opt_with_decl_ref impl_decl_info.oidi_class_interface in
(match if_decl_opt with (match if_decl_opt with
| Some d when is_ck_context context decl -> check_interface d | Some d when is_ck_context context an -> check_interface d
| _ -> CTL.False, None) | _ -> CTL.False, None)
| _ -> CTL.False, None | _ -> CTL.False, None
@ -253,7 +272,7 @@ let rec _component_initializer_with_side_effects_advice
in_ck_class context in_ck_class context
&& context.in_objc_static_factory_method && context.in_objc_static_factory_method
&& (match context.current_objc_impl with && (match context.current_objc_impl with
| Some d -> Ast_utils.is_in_main_file context.translation_unit_context d | Some d -> is_in_main_file context.translation_unit_context (CTL.Decl d)
| None -> false) in | None -> false) in
if condition then if condition then
match call_stmt with match call_stmt with

@ -437,17 +437,6 @@ struct
| Clang_ast_t.ObjCImplementationDecl (_, _, _, _, idi) -> Some idi | Clang_ast_t.ObjCImplementationDecl (_, _, _, _, idi) -> Some idi
| _ -> None | _ -> None
let is_in_main_file translation_unit_context decl =
let decl_info = Clang_ast_proj.get_decl_tuple decl in
let file_opt = (fst decl_info.Clang_ast_t.di_source_range).Clang_ast_t.sl_file in
match file_opt with
| None ->
false
| Some file ->
DB.inode_equal
(CLocation.source_file_from_path file)
translation_unit_context.CFrontend_config.source_file
let default_blacklist = let default_blacklist =
let open CFrontend_config in let open CFrontend_config in
[nsobject_cl; nsproxy_cl] [nsobject_cl; nsproxy_cl]

@ -155,11 +155,6 @@ sig
val get_super_ObjCImplementationDecl : val get_super_ObjCImplementationDecl :
Clang_ast_t.obj_c_implementation_decl_info -> Clang_ast_t.decl option Clang_ast_t.obj_c_implementation_decl_info -> Clang_ast_t.decl option
(** Returns true if the declaration or statement is inside the main source
file, as opposed to an imported header file. For statements, this refers
to the parent decl. *)
val is_in_main_file : CFrontend_config.translation_unit_context -> Clang_ast_t.decl -> bool
(** Recursively go up the inheritance hierarchy of a given ObjCInterfaceDecl. (** Recursively go up the inheritance hierarchy of a given ObjCInterfaceDecl.
Returns true if the passed in decl is an objc interface decl that's an Returns true if the passed in decl is an objc interface decl that's an
eventual descendant of one of the classes passed in. eventual descendant of one of the classes passed in.

Loading…
Cancel
Save