[linters] Ading predicate is_in_objc_class_named and make a verbose rule more targeted

Reviewed By: ddino

Differential Revision: D6323539

fbshipit-source-id: 5681c95
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent d8be5e0874
commit a1010fb9fc

@ -481,6 +481,14 @@ let is_in_objc_subclass_of context name =
false false
let is_in_objc_class_named context name =
match context.CLintersContext.current_objc_class with
| Some cls ->
is_objc_interface_named (Decl cls) name
| None ->
false
let captures_cxx_references an = List.length (captured_variables_cxx_ref an) > 0 let captures_cxx_references an = List.length (captured_variables_cxx_ref an) > 0
let is_binop_with_kind an alexp_kind = let is_binop_with_kind an alexp_kind =

@ -70,6 +70,8 @@ val is_objc_dealloc : CLintersContext.context -> bool
val is_in_objc_subclass_of : CLintersContext.context -> ALVar.alexp -> bool val is_in_objc_subclass_of : CLintersContext.context -> ALVar.alexp -> bool
val is_in_objc_class_named : CLintersContext.context -> ALVar.alexp -> bool
val is_subclass_of : Clang_ast_t.decl -> ALVar.alexp -> bool val is_subclass_of : Clang_ast_t.decl -> ALVar.alexp -> bool
val captures_cxx_references : Ctl_parser_types.ast_node -> bool val captures_cxx_references : Ctl_parser_types.ast_node -> bool

@ -1020,6 +1020,10 @@ let rec eval_Atomic _pred_name args an lcxt =
CPredicates.is_in_function lcxt name CPredicates.is_in_function lcxt name
| "is_in_objc_method", [name], _ -> | "is_in_objc_method", [name], _ ->
CPredicates.is_in_objc_method lcxt name CPredicates.is_in_objc_method lcxt name
| "is_in_objc_class_named", [name], _ ->
CPredicates.is_in_objc_class_named lcxt name
| "is_in_objc_subclass_of", [name], _ ->
CPredicates.is_in_objc_subclass_of lcxt name
| "is_ivar_atomic", [], an -> | "is_ivar_atomic", [], an ->
CPredicates.is_ivar_atomic an CPredicates.is_ivar_atomic an
| "is_method_property_accessor_of_ivar", [], an -> | "is_method_property_accessor_of_ivar", [], an ->
@ -1032,8 +1036,6 @@ let rec eval_Atomic _pred_name args an lcxt =
CPredicates.is_objc_dealloc lcxt CPredicates.is_objc_dealloc lcxt
| "is_objc_extension", [], _ -> | "is_objc_extension", [], _ ->
CPredicates.is_objc_extension lcxt CPredicates.is_objc_extension lcxt
| "is_in_objc_subclass_of", [name], _ ->
CPredicates.is_in_objc_subclass_of lcxt name
| "is_objc_interface_named", [name], an -> | "is_objc_interface_named", [name], an ->
CPredicates.is_objc_interface_named an name CPredicates.is_objc_interface_named an name
| "is_property_pointer_type", [], an -> | "is_property_pointer_type", [], an ->

@ -1,30 +1,13 @@
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelfBase_testView, 11, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelfBase_testView, 16, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelfBase_testView, 17, TEST_VAR_TYPE_CHECK, [] codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelfBase_testView, 17, TEST_VAR_TYPE_CHECK, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_methodThatShallBeOkaySuper, 36, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_methodThatShallBeOkayVoid, 32, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_methodThatShallComplain, 25, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_methodThatShallComplain, 40, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_methodThatShallComplain, 41, TEST_IF_VIEW_METHOD_IS_NOT_CALLED_WITH_SUPER, [] codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_methodThatShallComplain, 41, TEST_IF_VIEW_METHOD_IS_NOT_CALLED_WITH_SUPER, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_methodThatShallNotComplain, 23, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_testView, 27, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_testView, 44, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_testView, 45, TEST_VAR_TYPE_CHECK, [] codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf_testView, 45, TEST_VAR_TYPE_CHECK, []
codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, InContextOfMethodsTest_method, 15, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, InContextOfMethodsTest_method, 16, TEST_IN_METHOD_CONTEXT, [] codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, InContextOfMethodsTest_method, 16, TEST_IN_METHOD_CONTEXT, []
codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, InContextOfMethodsTest_method, 16, TEST_VAR_TYPE_CHECK, [] codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, InContextOfMethodsTest_method, 16, TEST_VAR_TYPE_CHECK, []
codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, InContextOfMethodsTest_method_with_block, 19, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, function, 27, TEST_IN_FUNCTION_CONTEXT, [] codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, function, 27, TEST_IN_FUNCTION_CONTEXT, []
codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, function, 27, TEST_VAR_TYPE_CHECK, [] codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, function, 27, TEST_VAR_TYPE_CHECK, []
codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, objc_block_1, 21, TEST_VAR_TYPE_CHECK, [] codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, objc_block_1, 21, TEST_VAR_TYPE_CHECK, []
codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, objc_block_2, 21, TEST_IN_BLOCK_CONTEXT, [] codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, objc_block_2, 21, TEST_IN_BLOCK_CONTEXT, []
codetoanalyze/objc/linters-for-test-only/InSubclassExample.m, HappySadView2_foo, 38, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/InSubclassExample.m, HappySadView2_makeBadAction, 34, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/InSubclassExample.m, HappySadView2_makeBadAction, 35, IN_SUBCLASS_TEST, [] codetoanalyze/objc/linters-for-test-only/InSubclassExample.m, HappySadView2_makeBadAction, 35, IN_SUBCLASS_TEST, []
codetoanalyze/objc/linters-for-test-only/InSubclassExample.m, HappySadView_foo, 20, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/InSubclassExample.m, HappySadView_makeBadAction, 16, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/PrivateAPIChecker.m, TestView_methodd, 16, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/PrivateAPIChecker.m, TestView_methoddd, 20, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/PrivateAPIChecker.m, TestView_methoddd, 21, TEST_SELECTOR, [] codetoanalyze/objc/linters-for-test-only/PrivateAPIChecker.m, TestView_methoddd, 21, TEST_SELECTOR, []
codetoanalyze/objc/linters-for-test-only/enums.m, test, 17, ENUM_CONSTANTS, [] codetoanalyze/objc/linters-for-test-only/enums.m, test, 17, ENUM_CONSTANTS, []
codetoanalyze/objc/linters-for-test-only/enums.m, test, 17, ENUM_CONSTANTS_OF_ENUM, [] codetoanalyze/objc/linters-for-test-only/enums.m, test, 17, ENUM_CONSTANTS_OF_ENUM, []
@ -52,21 +35,16 @@ codetoanalyze/objc/linters-for-test-only/protocols.m, Foo_newWithC, 26, TEST_PRO
codetoanalyze/objc/linters-for-test-only/protocols.m, Foo_newWithCs, 27, TEST_GENERICS_TYPE, [] codetoanalyze/objc/linters-for-test-only/protocols.m, Foo_newWithCs, 27, TEST_GENERICS_TYPE, []
codetoanalyze/objc/linters-for-test-only/protocols.m, Foo_newWithCs, 27, TEST_INSTANCE_TYPE, [] codetoanalyze/objc/linters-for-test-only/protocols.m, Foo_newWithCs, 27, TEST_INSTANCE_TYPE, []
codetoanalyze/objc/linters-for-test-only/protocols.m, Foo_newWithCs, 27, TEST_PROTOCOL_TYPE_INHERITANCE, [] codetoanalyze/objc/linters-for-test-only/protocols.m, Foo_newWithCs, 27, TEST_PROTOCOL_TYPE_INHERITANCE, []
codetoanalyze/objc/linters-for-test-only/protocols.m, Foo_newWithD, 28, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/protocols.m, Linters_dummy_method, 11, TEST_PROTOCOL_DEF_INHERITANCE, [] codetoanalyze/objc/linters-for-test-only/protocols.m, Linters_dummy_method, 11, TEST_PROTOCOL_DEF_INHERITANCE, []
codetoanalyze/objc/linters-for-test-only/protocols.m, Linters_dummy_method, 14, TEST_PROTOCOL_DEF_INHERITANCE, [] codetoanalyze/objc/linters-for-test-only/protocols.m, Linters_dummy_method, 14, TEST_PROTOCOL_DEF_INHERITANCE, []
codetoanalyze/objc/linters-for-test-only/protocols.m, Linters_dummy_method, 17, TEST_PROTOCOL_DEF_INHERITANCE, [] codetoanalyze/objc/linters-for-test-only/protocols.m, Linters_dummy_method, 17, TEST_PROTOCOL_DEF_INHERITANCE, []
codetoanalyze/objc/linters-for-test-only/sel.m, fooButtonComponent_newWithAction, 12, TEST_INSTANCE_TYPE, [] codetoanalyze/objc/linters-for-test-only/sel.m, fooButtonComponent_newWithAction, 12, TEST_INSTANCE_TYPE, []
codetoanalyze/objc/linters-for-test-only/sel.m, fooButtonComponent_newWithAction, 12, TEST_PARAMETER_SEL_TYPE, [] codetoanalyze/objc/linters-for-test-only/sel.m, fooButtonComponent_newWithAction, 12, TEST_PARAMETER_SEL_TYPE, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 13, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 13, TEST_PARAM_TYPE_CHECK2, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 13, TEST_PARAM_TYPE_CHECK2, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 13, TEST_RETURN_METHOD, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 13, TEST_RETURN_METHOD, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 19, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 19, TEST_PARAM_TYPE_CHECK2, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 19, TEST_PARAM_TYPE_CHECK2, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 19, TEST_RETURN_METHOD, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo, 19, TEST_RETURN_METHOD, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 28, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 28, TEST_RETURN_METHOD, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 28, TEST_RETURN_METHOD, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 34, TEST_BUILTIN_TYPE, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 34, TEST_RETURN_METHOD, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 34, TEST_RETURN_METHOD, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 35, TEST_ALL_METHODS, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 35, TEST_ALL_METHODS, []
codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 36, MACRO_TEST1, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, B_bar, 36, MACRO_TEST1, []

@ -128,7 +128,8 @@ DEFINE-CHECKER TEST_BUILTIN_TYPE = {
SET report_when = SET report_when =
WHEN WHEN
method_return_type("void") is_in_objc_class_named("TestType") AND
(method_return_type("void")
OR method_return_type("bool") OR method_return_type("bool")
OR method_return_type("char") OR method_return_type("char")
OR method_return_type("unsigned char") OR method_return_type("unsigned char")
@ -153,7 +154,7 @@ DEFINE-CHECKER TEST_BUILTIN_TYPE = {
OR method_return_type("float *") OR method_return_type("float *")
OR method_return_type("unsigned int **") OR method_return_type("unsigned int **")
OR method_return_type("A*") OR method_return_type("A*")
OR method_return_type("REGEXP('This.+')*" ) OR method_return_type("REGEXP('This.+')*" ))
HOLDS-IN-NODE ObjCMethodDecl; HOLDS-IN-NODE ObjCMethodDecl;
SET message = "Method return....."; SET message = "Method return.....";
@ -423,10 +424,10 @@ DEFINE-CHECKER TEST_PARAMETER_SEL_TYPE = {
SET message = "Method has parameter of type SEL"; SET message = "Method has parameter of type SEL";
}; };
DEFINE-CHECKER IN_SUBCLASS_TEST = { DEFINE-CHECKER IN_SUBCLASS_TEST = {
SET report_when = SET report_when =
WHEN is_in_objc_subclass_of("SubClassTestClass") WHEN is_in_objc_subclass_of("SubClassTestClass")
HOLDS-IN-NODE ObjCMessageExpr; HOLDS-IN-NODE ObjCMessageExpr;
SET message = "Found a message call in a class that is not subclass of A."; SET message = "Found a message call in a class that is not subclass of A.";
}; };

Loading…
Cancel
Save