Predicate for `using namespace`

Reviewed By: dulmarod

Differential Revision: D5172430

fbshipit-source-id: 0cd9251
master
Dino Distefano 8 years ago committed by Facebook Github Bot
parent 8917536944
commit 55da0055c9

@ -422,3 +422,14 @@ let objc_method_has_nth_parameter_of_type an _num _typ =
type_ptr_equal_type qt.qt_type_ptr typ type_ptr_equal_type qt.qt_type_ptr typ
| _ -> false) | _ -> false)
| _, _, _ -> false | _, _, _ -> false
let using_namespace an namespace =
let open Clang_ast_t in
match an with
| Ctl_parser_types.Decl (UsingDirectiveDecl (_, _, uddi)) ->
(match uddi.uddi_nominated_namespace with
| Some dr -> (match dr.dr_kind, dr.dr_name with
| `Namespace, Some ni -> ALVar.compare_str_with_alexp ni.ni_name namespace
| _ -> false)
| None -> false)
| _ -> false

@ -81,3 +81,5 @@ val within_responds_to_selector_block :
val objc_method_has_nth_parameter_of_type : val objc_method_has_nth_parameter_of_type :
Ctl_parser_types.ast_node -> ALVar.alexp -> ALVar.alexp -> bool Ctl_parser_types.ast_node -> ALVar.alexp -> ALVar.alexp -> bool
val using_namespace : Ctl_parser_types.ast_node -> ALVar.alexp -> bool

@ -647,6 +647,8 @@ let rec eval_Atomic _pred_name args an lcxt =
CPredicates.within_responds_to_selector_block lcxt an CPredicates.within_responds_to_selector_block lcxt an
| "objc_method_has_nth_parameter_of_type", [num; typ], an -> | "objc_method_has_nth_parameter_of_type", [num; typ], an ->
CPredicates.objc_method_has_nth_parameter_of_type an num typ CPredicates.objc_method_has_nth_parameter_of_type an num typ
| "using_namespace", [namespace], an ->
CPredicates.using_namespace an namespace
| _ -> failwith | _ -> failwith
("ERROR: Undefined Predicate or wrong set of arguments: '" ("ERROR: Undefined Predicate or wrong set of arguments: '"
^ pred_name ^ "'") ^ pred_name ^ "'")

@ -6,7 +6,8 @@ codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 9, FILTER_BY_ALL
codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 10, TEST_VAR_TYPE_CHECK, [] codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 10, TEST_VAR_TYPE_CHECK, []
codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 11, TEST_IMPLICIT_CAST_CHECK, [] codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 11, TEST_IMPLICIT_CAST_CHECK, []
codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 11, TEST_VAR_TYPE_CHECK, [] codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 11, TEST_VAR_TYPE_CHECK, []
codetoanalyze/objc/linters-for-test-only/namespace.mm, Linters_dummy_method, 9, TEST_NAMESPACE_NAME, [] codetoanalyze/objc/linters-for-test-only/namespace.mm, Linters_dummy_method, 9, TEST_DEFINE_NAMESPACE, []
codetoanalyze/objc/linters-for-test-only/namespace.mm, Linters_dummy_method, 17, TEST_USING_NAMESPACE, []
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_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, []

@ -217,7 +217,7 @@ DEFINE-CHECKER TEST_NTH_PARAM_TYPE_CHECK = {
SET severity = "LIKE"; SET severity = "LIKE";
}; };
DEFINE-CHECKER TEST_NAMESPACE_NAME = { DEFINE-CHECKER TEST_DEFINE_NAMESPACE = {
SET report_when = SET report_when =
WHEN WHEN
@ -228,6 +228,15 @@ DEFINE-CHECKER TEST_NAMESPACE_NAME = {
}; };
DEFINE-CHECKER TEST_USING_NAMESPACE = {
SET report_when =
using_namespace(REGEXP("FirstNam*"));
SET message = "Found using namespace with name....";
};
DEFINE-CHECKER FILTER_BY_PATH_EXAMPLE = { DEFINE-CHECKER FILTER_BY_PATH_EXAMPLE = {
SET report_when = SET report_when =
WHEN declaration_has_name("main") WHEN declaration_has_name("main")

@ -14,3 +14,5 @@ class C {
} }
void SecodNameSpace::C::m() {} void SecodNameSpace::C::m() {}
} }
using namespace FirstNameSpace;
void foo() { SecodNameSpace::C(); }

Loading…
Cancel
Save