diff options
author | Haojian Wu <hokein@google.com> | 2017-10-26 08:23:20 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2017-10-26 08:23:20 +0000 |
commit | abcd64ccbf3357598f792f97f039d1685f42d6e7 (patch) | |
tree | 41551e56683d229552834f29c604aaf2d86516dd | |
parent | 37d57dac63539e8f402db96f9053b7fa7205c8e8 (diff) | |
download | llvm-abcd64ccbf3357598f792f97f039d1685f42d6e7.zip llvm-abcd64ccbf3357598f792f97f039d1685f42d6e7.tar.gz llvm-abcd64ccbf3357598f792f97f039d1685f42d6e7.tar.bz2 |
[clang-tidy ObjC] [1/3] New module `objc` for Objective-C checks
Summary:
This is part 1 of 3 of a series of changes to improve Objective-C
linting in clang-tidy.
This introduces a new clang-tidy module, `objc`, specifically for
Objective-C / Objective-C++ checks.
The module is currently empty; D39142 adds the first check.
Test Plan: `ninja check-clang-tools`
Patch by Ben Hamilton!
Reviewers: hokein, alexfh
Reviewed By: hokein
Subscribers: Wizard, mgorny
Differential Revision: https://reviews.llvm.org/D39188
llvm-svn: 316643
11 files changed, 97 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt index 9d6fc7f..0a3de85 100644 --- a/clang-tools-extra/clang-tidy/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/CMakeLists.txt @@ -37,6 +37,7 @@ add_subdirectory(llvm) add_subdirectory(misc) add_subdirectory(modernize) add_subdirectory(mpi) +add_subdirectory(objc) add_subdirectory(performance) add_subdirectory(plugin) add_subdirectory(readability) diff --git a/clang-tools-extra/clang-tidy/objc/CMakeLists.txt b/clang-tools-extra/clang-tidy/objc/CMakeLists.txt new file mode 100644 index 0000000..85682b5 --- /dev/null +++ b/clang-tools-extra/clang-tidy/objc/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_library(clangTidyObjCModule + ObjCTidyModule.cpp + + LINK_LIBS + clangAST + clangASTMatchers + clangBasic + clangLex + clangTidy + clangTidyUtils + ) diff --git a/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp b/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp new file mode 100644 index 0000000..46ff21f --- /dev/null +++ b/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp @@ -0,0 +1,39 @@ +//===--- ObjCTidyModule.cpp - clang-tidy --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace objc { + +class ObjCModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + // TODO(D39142): Add checks here. + } +}; + +// Register the ObjCTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<ObjCModule> X( + "objc-module", + "Adds Objective-C lint checks."); + +} // namespace objc + +// This anchor is used to force the linker to link in the generated object file +// and thus register the ObjCModule. +volatile int ObjCModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/clang-tidy/plugin/CMakeLists.txt b/clang-tools-extra/clang-tidy/plugin/CMakeLists.txt index 5c88832..995c086 100644 --- a/clang-tools-extra/clang-tidy/plugin/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/plugin/CMakeLists.txt @@ -17,6 +17,7 @@ add_clang_library(clangTidyPlugin clangTidyMiscModule clangTidyModernizeModule clangTidyMPIModule + clangTidyObjCModule clangTidyPerformanceModule clangTidyReadabilityModule clangTooling diff --git a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp index 1e6346c..25c13c7 100644 --- a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp +++ b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp @@ -123,5 +123,10 @@ extern volatile int ReadabilityModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination = ReadabilityModuleAnchorSource; +// This anchor is used to force the linker to link the ObjCModule. +extern volatile int ObjCModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination = + ObjCModuleAnchorSource; + } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/tool/CMakeLists.txt b/clang-tools-extra/clang-tidy/tool/CMakeLists.txt index 994ee90..61b70b5 100644 --- a/clang-tools-extra/clang-tidy/tool/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/tool/CMakeLists.txt @@ -27,6 +27,7 @@ target_link_libraries(clang-tidy clangTidyMiscModule clangTidyModernizeModule clangTidyMPIModule + clangTidyObjCModule clangTidyPerformanceModule clangTidyReadabilityModule clangTooling diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index 79c0d0b..6f1718f 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -517,6 +517,11 @@ extern volatile int ReadabilityModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination = ReadabilityModuleAnchorSource; +// This anchor is used to force the linker to link the ObjCModule. +extern volatile int ObjCModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination = + ObjCModuleAnchorSource; + // This anchor is used to force the linker to link the HICPPModule. extern volatile int HICPPModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination = diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 71e00ba..4dc3483 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -57,6 +57,8 @@ The improvements are... Improvements to clang-tidy -------------------------- +- New module `objc` for Objective-C style checks. + - Renamed checks to use correct term "implicit conversion" instead of "implicit cast" and modified messages and option names accordingly: diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst index 69136e6..e1e3341 100644 --- a/clang-tools-extra/docs/clang-tidy/index.rst +++ b/clang-tools-extra/docs/clang-tidy/index.rst @@ -68,6 +68,7 @@ Name prefix Description ``modernize-`` Checks that advocate usage of modern (currently "modern" means "C++11") language constructs. ``mpi-`` Checks related to MPI (Message Passing Interface). +``objc-`` Checks related to Objective-C coding conventions. ``performance-`` Checks that target performance-related issues. ``readability-`` Checks that target readability-related issues that don't relate to any particular coding style. @@ -341,6 +342,11 @@ The Directory Structure |-- LLVMTidyModule.cpp |-- LLVMTidyModule.h ... + |-- objc/ # Objective-C clang-tidy module. + |-+ + |-- ObjCTidyModule.cpp + |-- ObjCTidyModule.h + ... |-- tool/ # Sources of the clang-tidy binary. ... test/clang-tidy/ # Integration tests. @@ -349,6 +355,7 @@ The Directory Structure |-- ClangTidyTest.h |-- GoogleModuleTest.cpp |-- LLVMModuleTest.cpp + |-- ObjCModuleTest.cpp ... diff --git a/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt b/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt index 0d9ab7c..0973ee1 100644 --- a/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt +++ b/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt @@ -14,6 +14,7 @@ add_extra_unittest(ClangTidyTests LLVMModuleTest.cpp MiscModuleTest.cpp NamespaceAliaserTest.cpp + ObjCModuleTest.cpp OverlappingReplacementsTest.cpp UsingInserterTest.cpp ReadabilityModuleTest.cpp) @@ -29,6 +30,7 @@ target_link_libraries(ClangTidyTests clangTidyGoogleModule clangTidyLLVMModule clangTidyMiscModule + clangTidyObjCModule clangTidyReadabilityModule clangTidyUtils clangTooling diff --git a/clang-tools-extra/unittests/clang-tidy/ObjCModuleTest.cpp b/clang-tools-extra/unittests/clang-tidy/ObjCModuleTest.cpp new file mode 100644 index 0000000..c50480a --- /dev/null +++ b/clang-tools-extra/unittests/clang-tidy/ObjCModuleTest.cpp @@ -0,0 +1,21 @@ +//===---- ObjCModuleTest.cpp - clang-tidy ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "ClangTidyTest.h" +#include "gtest/gtest.h" + +namespace clang { +namespace tidy { +namespace test { + +// TODO(D39142) Add unit tests for the ObjC module here once a check lands. + +} // namespace test +} // namespace tidy +} // namespace clang |