[clang-tools-extra] r316643 - [clang-tidy ObjC] [1/3] New module `objc` for Objective-C checks

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 26 01:23:20 PDT 2017


Author: hokein
Date: Thu Oct 26 01:23:20 2017
New Revision: 316643

URL: http://llvm.org/viewvc/llvm-project?rev=316643&view=rev
Log:
[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

Added:
    clang-tools-extra/trunk/clang-tidy/objc/
    clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
    clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
    clang-tools-extra/trunk/unittests/clang-tidy/ObjCModuleTest.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
    clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
    clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
    clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
    clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
    clang-tools-extra/trunk/docs/ReleaseNotes.rst
    clang-tools-extra/trunk/docs/clang-tidy/index.rst
    clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=316643&r1=316642&r2=316643&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Thu Oct 26 01:23:20 2017
@@ -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)

Added: clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt?rev=316643&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt Thu Oct 26 01:23:20 2017
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyObjCModule
+  ObjCTidyModule.cpp
+
+  LINK_LIBS
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangTidy
+  clangTidyUtils
+  )

Added: clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp?rev=316643&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp Thu Oct 26 01:23:20 2017
@@ -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

Modified: clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt?rev=316643&r1=316642&r2=316643&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt Thu Oct 26 01:23:20 2017
@@ -17,6 +17,7 @@ add_clang_library(clangTidyPlugin
   clangTidyMiscModule
   clangTidyModernizeModule
   clangTidyMPIModule
+  clangTidyObjCModule
   clangTidyPerformanceModule
   clangTidyReadabilityModule
   clangTooling

Modified: clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp?rev=316643&r1=316642&r2=316643&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp Thu Oct 26 01:23:20 2017
@@ -123,5 +123,10 @@ extern volatile int ReadabilityModuleAnc
 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

Modified: clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt?rev=316643&r1=316642&r2=316643&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt Thu Oct 26 01:23:20 2017
@@ -27,6 +27,7 @@ target_link_libraries(clang-tidy
   clangTidyMiscModule
   clangTidyModernizeModule
   clangTidyMPIModule
+  clangTidyObjCModule
   clangTidyPerformanceModule
   clangTidyReadabilityModule
   clangTooling

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=316643&r1=316642&r2=316643&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Thu Oct 26 01:23:20 2017
@@ -517,6 +517,11 @@ extern volatile int ReadabilityModuleAnc
 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 =

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=316643&r1=316642&r2=316643&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Oct 26 01:23:20 2017
@@ -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:
 

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=316643&r1=316642&r2=316643&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Thu Oct 26 01:23:20 2017
@@ -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
       ...
 
 

Modified: clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt?rev=316643&r1=316642&r2=316643&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt Thu Oct 26 01:23:20 2017
@@ -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

Added: clang-tools-extra/trunk/unittests/clang-tidy/ObjCModuleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ObjCModuleTest.cpp?rev=316643&view=auto
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/ObjCModuleTest.cpp (added)
+++ clang-tools-extra/trunk/unittests/clang-tidy/ObjCModuleTest.cpp Thu Oct 26 01:23:20 2017
@@ -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




More information about the cfe-commits mailing list