new predicate is_in_source_file and placeholders %source_file% and %kind%

Reviewed By: ddino

Differential Revision: D13745562

fbshipit-source-id: b3e646001
master
David Lively 6 years ago committed by Facebook Github Bot
parent ca463d17c1
commit a8c946f1d9

@ -129,6 +129,14 @@ let evaluate_place_holder context ph an =
MF.monospaced_to_string (Ctl_parser_types.ast_node_name an) MF.monospaced_to_string (Ctl_parser_types.ast_node_name an)
| "%cxx_fully_qualified_name%" -> | "%cxx_fully_qualified_name%" ->
MF.monospaced_to_string (Ctl_parser_types.ast_node_cxx_fully_qualified_name an) MF.monospaced_to_string (Ctl_parser_types.ast_node_cxx_fully_qualified_name an)
| "%kind%" ->
MF.monospaced_to_string (Ctl_parser_types.ast_node_kind an)
| "%source_file%" ->
(* N.B.: This is the source_file in which the AST node occurs, which is not
* necessarily the same as the translation unit's source file.
*)
MF.monospaced_to_string
(SourceFile.to_rel_path (SourceFile.create (Ctl_parser_types.get_source_file an)))
| _ -> | _ ->
L.die InternalError "helper function %s is unknown" ph L.die InternalError "helper function %s is unknown" ph

@ -1456,3 +1456,8 @@ let is_init_expr_cxx11_constant an =
vdi.vdi_is_init_expr_cxx11_constant vdi.vdi_is_init_expr_cxx11_constant
| _ -> | _ ->
false false
let is_in_source_file an path_re =
let src_file = Ctl_parser_types.get_source_file an in
ALVar.compare_str_with_alexp (SourceFile.to_rel_path (SourceFile.create src_file)) path_re

@ -492,6 +492,11 @@ val has_cxx_fully_qualified_name : Ctl_parser_types.ast_node -> ALVar.alexp -> b
* matching the given regexp * matching the given regexp
*) *)
val is_in_source_file : Ctl_parser_types.ast_node -> ALVar.alexp -> bool
(**
* True iff the source file path of the given node matches the given regexp or string.
*)
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

@ -1163,6 +1163,8 @@ let rec eval_Atomic pred_name_ args an lcxt =
CPredicates.is_init_expr_cxx11_constant an CPredicates.is_init_expr_cxx11_constant an
| "cxx_construct_expr_has_no_parameters", [], an -> | "cxx_construct_expr_has_no_parameters", [], an ->
CPredicates.cxx_construct_expr_has_no_parameters an CPredicates.cxx_construct_expr_has_no_parameters an
| "is_in_source_file", [path_re], an ->
CPredicates.is_in_source_file an path_re
| _ -> | _ ->
L.(die ExternalError) "Undefined Predicate or wrong set of arguments: '%s'" pred_name L.(die ExternalError) "Undefined Predicate or wrong set of arguments: '%s'" pred_name

@ -598,3 +598,23 @@ let stmt_node_child_type an =
match stmts with [stmt] -> ast_node_type (Stmt stmt) | _ -> "" ) match stmts with [stmt] -> ast_node_type (Stmt stmt) | _ -> "" )
| _ -> | _ ->
"" ""
let get_source_range an =
match an with
| Stmt stmt ->
let stmt_info, _ = Clang_ast_proj.get_stmt_tuple stmt in
stmt_info.si_source_range
| Decl decl ->
let decl_info = Clang_ast_proj.get_decl_tuple decl in
decl_info.di_source_range
let get_source_file an =
match get_source_range an with
| {sl_file= Some sf}, _ ->
sf
| _, {sl_file= Some sf} ->
sf
| _ ->
assert false

@ -83,3 +83,5 @@ type abs_ctype =
val c_type_equal : Clang_ast_t.c_type -> abs_ctype -> bool val c_type_equal : Clang_ast_t.c_type -> abs_ctype -> bool
val abs_ctype_to_string : abs_ctype -> string val abs_ctype_to_string : abs_ctype -> string
val get_source_file : ast_node -> Clang_ast_t.source_file

@ -1,5 +1,6 @@
codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, f, 12, FIND_STATIC_LOCAL_VAR, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, f, 12, FIND_STATIC_LOCAL_VAR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 17, FIND_CXX_COPY_CONSTRUCTOR, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 17, FIND_CXX_COPY_CONSTRUCTOR, no_bucket, WARNING, []
codetoanalyze/cpp/linters-for-test-only/test_included.h, Bazoo_fibble, 11, FIND_CXX_METHODS_FROM_HEADER_FILE, 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_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, []

@ -42,3 +42,9 @@ DEFINE-CHECKER FIND_NODES_WITH_CXX_FULL_NAME = {
SET report_when = has_cxx_fully_qualified_name(REGEXP("::Foo::.*")); SET report_when = has_cxx_fully_qualified_name(REGEXP("::Foo::.*"));
SET message = "%cxx_fully_qualified_name% matches"; SET message = "%cxx_fully_qualified_name% matches";
}; };
DEFINE-CHECKER FIND_CXX_METHODS_FROM_HEADER_FILE = {
SET report_when = WHEN is_in_source_file(REGEXP("/test_included.h$"))
HOLDS-IN-NODE CXXMethodDecl;
SET message = "found C++ method %name% in %source_file%";
};

@ -0,0 +1,12 @@
/*
* Copyright (c) 2019-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
struct Bazoo {
void fibble();
};

@ -0,0 +1,12 @@
/*
* Copyright (c) 2019-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "test_included.h"
struct Bazowey {
void frazzle();
};
Loading…
Cancel
Save