Add new predicate has_cxx_qual_name and macro %cxx_full_name%

Reviewed By: jvillard

Differential Revision: D13490505

fbshipit-source-id: df66224d6
master
David Lively 6 years ago committed by Facebook Github Bot
parent a130556869
commit 1f2b0d4152

@ -127,6 +127,8 @@ let evaluate_place_holder context ph an =
MF.monospaced_to_string (Ctl_parser_types.stmt_node_child_type an) MF.monospaced_to_string (Ctl_parser_types.stmt_node_child_type an)
| "%name%" -> | "%name%" ->
MF.monospaced_to_string (Ctl_parser_types.ast_node_name an) MF.monospaced_to_string (Ctl_parser_types.ast_node_name an)
| "%cxx_full_name%" ->
MF.monospaced_to_string (Ctl_parser_types.ast_node_cxx_full_name an)
| _ -> | _ ->
L.die InternalError "helper function %s is unknown" ph L.die InternalError "helper function %s is unknown" ph

@ -1412,6 +1412,14 @@ let is_cxx_copy_constructor an =
false false
let has_cxx_full_name an qual_name_re =
match Ctl_parser_types.ast_node_cxx_full_name an with
| "" ->
false
| full_name ->
ALVar.compare_str_with_alexp full_name qual_name_re
let is_cxx_method_overriding an qual_name_re = let is_cxx_method_overriding an qual_name_re =
let rec overrides_named (decl_refs : Clang_ast_t.decl_ref list) (qnre : ALVar.alexp) = let rec overrides_named (decl_refs : Clang_ast_t.decl_ref list) (qnre : ALVar.alexp) =
List.exists List.exists

@ -487,6 +487,11 @@ val is_method_called_by_superclass : Ctl_parser_types.ast_node -> bool
val is_cxx_copy_constructor : Ctl_parser_types.ast_node -> bool val is_cxx_copy_constructor : Ctl_parser_types.ast_node -> bool
(** true if the current node is a C++ copy constructor *) (** true if the current node is a C++ copy constructor *)
val has_cxx_full_name : Ctl_parser_types.ast_node -> ALVar.alexp -> bool
(** true iff node has C++ fully qualified name (w/class and namespace)
* matching the given regexp
*)
val is_cxx_method_overriding : Ctl_parser_types.ast_node -> ALVar.alexp option -> bool val is_cxx_method_overriding : Ctl_parser_types.ast_node -> ALVar.alexp option -> bool
(** (**
* True iff the current node is a CXXMethodDecl node and is overriding a * True iff the current node is a CXXMethodDecl node and is overriding a

@ -973,6 +973,8 @@ let rec eval_Atomic pred_name_ args an lcxt =
CPredicates.context_in_synchronized_block lcxt CPredicates.context_in_synchronized_block lcxt
| "declaration_has_name", [decl_name], an -> | "declaration_has_name", [decl_name], an ->
CPredicates.declaration_has_name an decl_name CPredicates.declaration_has_name an decl_name
| "has_cxx_full_name", [qual_name_re], an ->
CPredicates.has_cxx_full_name an qual_name_re
| "declaration_ref_name", [decl_name], an -> | "declaration_ref_name", [decl_name], an ->
CPredicates.declaration_ref_name an decl_name CPredicates.declaration_ref_name an decl_name
| "decl_unavailable_in_supported_ios_sdk", [], an -> | "decl_unavailable_in_supported_ios_sdk", [], an ->

@ -80,6 +80,29 @@ let rec ast_node_name an =
"" ""
let rec ast_node_cxx_full_name an =
let full_name qual_name = "::" ^ String.concat ~sep:"::" (List.rev qual_name) in
let open Clang_ast_t in
match an with
| Decl dec -> (
match Clang_ast_proj.get_named_decl_tuple dec with
| Some (_, n) ->
full_name n.Clang_ast_t.ni_qual_name
| None ->
"" )
| Stmt (DeclRefExpr (_, _, _, {drti_decl_ref= Some dr})) ->
let ndi, _, _ = CAst_utils.get_info_from_decl_ref dr in
full_name ndi.ni_qual_name
| Stmt (OpaqueValueExpr (_, _, _, {ovei_source_expr= Some stmt}))
| Stmt (ImplicitCastExpr (_, [stmt], _, _))
| Stmt (PseudoObjectExpr (_, stmt :: _, _))
| Stmt (ParenExpr (_, [stmt], _))
| Stmt (CallExpr (_, stmt :: _, _)) ->
ast_node_cxx_full_name (Stmt stmt)
| _ ->
""
let ast_node_kind node = let ast_node_kind node =
match node with match node with
| Stmt stmt -> | Stmt stmt ->

@ -15,6 +15,8 @@ val ast_node_equal : ast_node -> ast_node -> bool
val ast_node_name : ast_node -> string val ast_node_name : ast_node -> string
val ast_node_cxx_full_name : ast_node -> string
val ast_node_type : ast_node -> string val ast_node_type : ast_node -> string
val ast_node_kind : ast_node -> string val ast_node_kind : ast_node -> string

@ -3,10 +3,16 @@ codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 17, FIND_CXX_CO
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, B_bar, 16, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, B_bar, 16, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, B_foo, 14, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, B_foo, 14, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_async_tm_poke, 36, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_async_tm_poke, 36, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_async_tm_poke, 36, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_future_poke, 37, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_future_poke, 37, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_future_poke, 37, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_poke, 35, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_semifuture_poke, 38, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_semifuture_poke, 38, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_semifuture_poke, 38, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_~SvIf, 34, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_async_tm_poke, 50, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_async_tm_poke, 50, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_future_poke, 51, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_future_poke, 51, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_future_poke, 51, FIND_CXX_METHOD_OVERRIDES_MATCHING, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_future_poke, 51, FIND_CXX_METHOD_OVERRIDES_MATCHING, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_poke, 49, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_poke, 49, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_semifuture_poke, 52, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_semifuture_poke, 52, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Linters_dummy_method, 32, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, []

@ -37,3 +37,8 @@ DEFINE-CHECKER FIND_CXX_METHOD_OVERRIDES_MATCHING = {
HOLDS-IN-NODE CXXMethodDecl; HOLDS-IN-NODE CXXMethodDecl;
SET message = "%decl_name% overriding matching method"; SET message = "%decl_name% overriding matching method";
}; };
DEFINE-CHECKER FIND_NODES_WITH_CXX_FULL_NAME = {
SET report_when = has_cxx_full_name(REGEXP("::Foo::Bar::"));
SET message = "%cxx_full_name% matches";
};

Loading…
Cancel
Save