summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2014-09-22 10:41:39 +0000
committerAlexander Kornienko <alexfh@google.com>2014-09-22 10:41:39 +0000
commit33fc3db9a16f8174bb0fcabc5b323c1f8b48cf4c (patch)
tree8bd7322e39bfb512b561dd6e3e18fc9e8a7335a9 /clang-tools-extra/clang-tidy
parent3a3bf0bbe35fee25219e075ee9b76abb8633c24b (diff)
downloadbcm5719-llvm-33fc3db9a16f8174bb0fcabc5b323c1f8b48cf4c.tar.gz
bcm5719-llvm-33fc3db9a16f8174bb0fcabc5b323c1f8b48cf4c.zip
Add NamespaceCommentCheck to the Google module.
Summary: This uses a bit hacky way to set the defaults for the spaces before comments, but it's also one of the simplest ways. Fixed a bug with how the SpacesBeforeComments option was used. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5410 llvm-svn: 218240
Diffstat (limited to 'clang-tools-extra/clang-tidy')
-rw-r--r--clang-tools-extra/clang-tidy/CMakeLists.txt1
-rw-r--r--clang-tools-extra/clang-tidy/Makefile2
-rw-r--r--clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/llvm/CMakeLists.txt2
-rw-r--r--clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/CMakeLists.txt13
-rw-r--r--clang-tools-extra/clang-tidy/readability/Makefile12
-rw-r--r--clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp (renamed from clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp)20
-rw-r--r--clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h (renamed from clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.h)11
9 files changed, 50 insertions, 18 deletions
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 92ed4e3db1d..6fcfb839e9e 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -27,4 +27,5 @@ add_subdirectory(tool)
add_subdirectory(llvm)
add_subdirectory(google)
add_subdirectory(misc)
+add_subdirectory(readability)
add_subdirectory(utils)
diff --git a/clang-tools-extra/clang-tidy/Makefile b/clang-tools-extra/clang-tidy/Makefile
index 0278294cfc4..74937341d25 100644
--- a/clang-tools-extra/clang-tidy/Makefile
+++ b/clang-tools-extra/clang-tidy/Makefile
@@ -11,6 +11,6 @@ CLANG_LEVEL := ../../..
LIBRARYNAME := clangTidy
include $(CLANG_LEVEL)/../../Makefile.config
-DIRS = utils llvm google misc tool
+DIRS = utils readability llvm google misc tool
include $(CLANG_LEVEL)/Makefile
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index 11fa14faeeb..b839fd0e55e 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -21,6 +21,7 @@
#include "TodoCommentCheck.h"
#include "UnnamedNamespaceInHeaderCheck.h"
#include "UsingNamespaceDirectiveCheck.h"
+#include "../readability/NamespaceCommentCheck.h"
using namespace clang::ast_matchers;
@@ -52,6 +53,8 @@ public:
"google-readability-function");
CheckFactories.registerCheck<readability::TodoCommentCheck>(
"google-readability-todo");
+ CheckFactories.registerCheck<readability::NamespaceCommentCheck>(
+ "google-readability-namespace-comments");
}
};
diff --git a/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt b/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
index 420745d4cb5..360e9308e90 100644
--- a/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
@@ -4,7 +4,6 @@ add_clang_library(clangTidyLLVMModule
HeaderGuardCheck.cpp
IncludeOrderCheck.cpp
LLVMTidyModule.cpp
- NamespaceCommentCheck.cpp
TwineLocalCheck.cpp
LINK_LIBS
@@ -13,6 +12,7 @@ add_clang_library(clangTidyLLVMModule
clangBasic
clangLex
clangTidy
+ clangTidyReadability
clangTidyUtils
clangTooling
)
diff --git a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
index 1eb82c58f59..73add5e8f5a 100644
--- a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
@@ -12,7 +12,7 @@
#include "../ClangTidyModuleRegistry.h"
#include "HeaderGuardCheck.h"
#include "IncludeOrderCheck.h"
-#include "NamespaceCommentCheck.h"
+#include "../readability/NamespaceCommentCheck.h"
#include "TwineLocalCheck.h"
namespace clang {
@@ -23,7 +23,7 @@ public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<LLVMHeaderGuardCheck>("llvm-header-guard");
CheckFactories.registerCheck<IncludeOrderCheck>("llvm-include-order");
- CheckFactories.registerCheck<NamespaceCommentCheck>(
+ CheckFactories.registerCheck<readability::NamespaceCommentCheck>(
"llvm-namespace-comment");
CheckFactories.registerCheck<TwineLocalCheck>("llvm-twine-local");
}
diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
new file mode 100644
index 00000000000..dc805cb219c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyReadability
+ NamespaceCommentCheck.cpp
+
+ LINK_LIBS
+ clangAST
+ clangASTMatchers
+ clangBasic
+ clangLex
+ clangTidy
+ clangTooling
+ )
diff --git a/clang-tools-extra/clang-tidy/readability/Makefile b/clang-tools-extra/clang-tidy/readability/Makefile
new file mode 100644
index 00000000000..7d9e2acec7e
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/Makefile
@@ -0,0 +1,12 @@
+##===- clang-tidy/readability/Makefile ---------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+CLANG_LEVEL := ../../../..
+LIBRARYNAME := clangTidyReadability
+
+include $(CLANG_LEVEL)/Makefile
diff --git a/clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
index 897c60a9203..da29c59f5b8 100644
--- a/clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -17,6 +17,7 @@ using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
+namespace readability {
NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
ClangTidyContext *Context)
@@ -25,7 +26,8 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
"namespace( +([a-zA-Z0-9_]+))? *(\\*/)?$",
llvm::Regex::IgnoreCase),
ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
- SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
+ SpacesBeforeComments(Options.get("SpacesBeforeComments",
+ Name.startswith("google") ? 2u : 1u)) {}
void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines);
@@ -42,12 +44,10 @@ bool locationsInSameFile(const SourceManager &Sources, SourceLocation Loc1,
Sources.getFileID(Loc1) == Sources.getFileID(Loc2);
}
-std::string getNamespaceComment(const NamespaceDecl *ND, bool InsertLineBreak,
- unsigned SpacesBeforeComments) {
+std::string getNamespaceComment(const NamespaceDecl *ND, bool InsertLineBreak) {
std::string Fix = "// namespace";
if (!ND->isAnonymousNamespace())
- Fix.append(std::string(SpacesBeforeComments, ' '))
- .append(ND->getNameAsString());
+ Fix.append(" ").append(ND->getNameAsString());
if (InsertLineBreak)
Fix.append("\n");
return Fix;
@@ -105,8 +105,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
diag(Loc, "namespace closing comment refers to a wrong namespace '%0'")
<< NamespaceNameInComment
<< FixItHint::CreateReplacement(
- OldCommentRange,
- getNamespaceComment(ND, NeedLineBreak, SpacesBeforeComments));
+ OldCommentRange, getNamespaceComment(ND, NeedLineBreak));
return;
}
@@ -118,10 +117,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
}
diag(ND->getLocation(), "namespace not terminated with a closing comment")
- << FixItHint::CreateInsertion(
- AfterRBrace,
- " " + getNamespaceComment(ND, NeedLineBreak, SpacesBeforeComments));
+ << FixItHint::CreateInsertion(AfterRBrace,
+ std::string(SpacesBeforeComments, ' ') +
+ getNamespaceComment(ND, NeedLineBreak));
}
+} // namespace readability
} // namespace tidy
} // namespace clang
diff --git a/clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
index f1b92e7b63b..b72eb65150d 100644
--- a/clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
@@ -7,18 +7,20 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_NAMESPACE_COMMENT_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_NAMESPACE_COMMENT_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NAMESPACECOMMENTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NAMESPACECOMMENTCHECK_H
#include "../ClangTidy.h"
#include "llvm/Support/Regex.h"
namespace clang {
namespace tidy {
+namespace readability {
/// \brief Checks that long namespaces have a closing comment.
///
-/// see: http://llvm.org/docs/CodingStandards.html#namespace-indentation
+/// http://llvm.org/docs/CodingStandards.html#namespace-indentation
+/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Namespaces
class NamespaceCommentCheck : public ClangTidyCheck {
public:
NamespaceCommentCheck(StringRef Name, ClangTidyContext *Context);
@@ -33,7 +35,8 @@ private:
const unsigned SpacesBeforeComments;
};
+} // namespace readability
} // namespace tidy
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_NAMESPACE_COMMENT_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NAMESPACECOMMENTCHECK_H
OpenPOWER on IntegriCloud