summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/add_new_check.py
diff options
context:
space:
mode:
authorDon Hinton <hintonda@gmail.com>2019-05-10 18:27:09 +0000
committerDon Hinton <hintonda@gmail.com>2019-05-10 18:27:09 +0000
commitb75e7eae17a56a42f6e23f0f11d331ef260a51fe (patch)
tree900f5fe6e70dff7769be881e9a5a6c53c9b9d22f /clang-tools-extra/clang-tidy/add_new_check.py
parent0c55985bbb407633eedde126a296438696866780 (diff)
downloadbcm5719-llvm-b75e7eae17a56a42f6e23f0f11d331ef260a51fe.tar.gz
bcm5719-llvm-b75e7eae17a56a42f6e23f0f11d331ef260a51fe.zip
[clang-tidy] Change the namespace for llvm checkers from 'llvm' to 'llvm_check'
Summary: Change the namespace for llvm checkers from 'llvm' to 'llvm_check', and modify add_new_check.py and rename_check.py to support the new namespace. Checker, file, and directory names remain unchanged. Used new version of rename_check.py to make the change in existing llvm checkers, but had to fix LLVMTidyModule.cpp and LLVMModuleTest.cpp by hand. The changes made by rename_check.py are idempotent, so if accidentally run multiple times, it won't do anything. Reviewed By: aaron.ballman Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D60629 llvm-svn: 360450
Diffstat (limited to 'clang-tools-extra/clang-tidy/add_new_check.py')
-rwxr-xr-xclang-tools-extra/clang-tidy/add_new_check.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py
index 8f96cbd874e..6a06e6dea5d 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -46,7 +46,7 @@ def adapt_cmake(module_path, check_name_camel):
# Adds a header for the new check.
-def write_header(module_path, module, check_name, check_name_camel):
+def write_header(module_path, module, namespace, check_name, check_name_camel):
check_name_dashes = module + '-' + check_name
filename = os.path.join(module_path, check_name_camel) + '.h'
print('Creating %s...' % filename)
@@ -73,7 +73,7 @@ def write_header(module_path, module, check_name, check_name_camel):
namespace clang {
namespace tidy {
-namespace %(module)s {
+namespace %(namespace)s {
/// FIXME: Write a short description.
///
@@ -87,7 +87,7 @@ public:
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace %(module)s
+} // namespace %(namespace)s
} // namespace tidy
} // namespace clang
@@ -95,11 +95,12 @@ public:
""" % {'header_guard': header_guard,
'check_name': check_name_camel,
'check_name_dashes': check_name_dashes,
- 'module': module})
+ 'module': module,
+ 'namespace': namespace})
# Adds the implementation of the new check.
-def write_implementation(module_path, module, check_name_camel):
+def write_implementation(module_path, module, namespace, check_name_camel):
filename = os.path.join(module_path, check_name_camel) + '.cpp'
print('Creating %s...' % filename)
with open(filename, 'w') as f:
@@ -124,7 +125,7 @@ using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
-namespace %(module)s {
+namespace %(namespace)s {
void %(check_name)s::registerMatchers(MatchFinder *Finder) {
// FIXME: Add matchers.
@@ -142,11 +143,12 @@ void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
<< FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
}
-} // namespace %(module)s
+} // namespace %(namespace)s
} // namespace tidy
} // namespace clang
""" % {'check_name': check_name_camel,
- 'module': module})
+ 'module': module,
+ 'namespace': namespace})
# Modifies the module to include the new check.
@@ -375,8 +377,15 @@ def main():
if not adapt_cmake(module_path, check_name_camel):
return
- write_header(module_path, module, check_name, check_name_camel)
- write_implementation(module_path, module, check_name_camel)
+
+ # Map module names to namespace names that don't conflict with widely used top-level namespaces.
+ if module == 'llvm':
+ namespace = module + '_check'
+ else:
+ namespace = module
+
+ write_header(module_path, module, namespace, check_name, check_name_camel)
+ write_implementation(module_path, module, namespace, check_name_camel)
adapt_module(module_path, module, check_name, check_name_camel)
add_release_notes(module_path, module, check_name)
test_extension = language_to_extension.get(args.language)
OpenPOWER on IntegriCloud