diff options
author | Alexander Kornienko <alexfh@google.com> | 2014-09-12 08:53:36 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2014-09-12 08:53:36 +0000 |
commit | 6e0cbc89471c210c59cd080901b1dfe656db117f (patch) | |
tree | dec7c96c3799366aafa7ddcb51866a8248eb8e31 /clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp | |
parent | 313f5e2f29c1826f6aa8bc91f5862bf556cac03b (diff) | |
download | bcm5719-llvm-6e0cbc89471c210c59cd080901b1dfe656db117f.tar.gz bcm5719-llvm-6e0cbc89471c210c59cd080901b1dfe656db117f.zip |
Implemented clang-tidy-check-specific options.
Summary:
Each check can implement readOptions and storeOptions methods to read
and store custom options. Each check's options are stored in a local namespace
to avoid name collisions and provide some sort of context to the user.
Reviewers: bkramer, klimek
Reviewed By: klimek
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D5296
llvm-svn: 217661
Diffstat (limited to 'clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp index d9789fe2dda..897c60a9203 100644 --- a/clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/NamespaceCommentCheck.cpp @@ -11,20 +11,26 @@ #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Lex/Lexer.h" - - -#include "llvm/Support/raw_ostream.h" +#include "llvm/ADT/StringExtras.h" using namespace clang::ast_matchers; namespace clang { namespace tidy { -NamespaceCommentCheck::NamespaceCommentCheck() - : NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" +NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, + ClangTidyContext *Context) + : ClangTidyCheck(Name, Context), + NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" "namespace( +([a-zA-Z0-9_]+))? *(\\*/)?$", llvm::Regex::IgnoreCase), - ShortNamespaceLines(1) {} + ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)), + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {} + +void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); + Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); +} void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(namespaceDecl().bind("namespace"), this); @@ -36,10 +42,12 @@ bool locationsInSameFile(const SourceManager &Sources, SourceLocation Loc1, Sources.getFileID(Loc1) == Sources.getFileID(Loc2); } -std::string getNamespaceComment(const NamespaceDecl *ND, bool InsertLineBreak) { +std::string getNamespaceComment(const NamespaceDecl *ND, bool InsertLineBreak, + unsigned SpacesBeforeComments) { std::string Fix = "// namespace"; if (!ND->isAnonymousNamespace()) - Fix.append(" ").append(ND->getNameAsString()); + Fix.append(std::string(SpacesBeforeComments, ' ')) + .append(ND->getNameAsString()); if (InsertLineBreak) Fix.append("\n"); return Fix; @@ -97,7 +105,8 @@ 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)); + OldCommentRange, + getNamespaceComment(ND, NeedLineBreak, SpacesBeforeComments)); return; } @@ -110,7 +119,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { diag(ND->getLocation(), "namespace not terminated with a closing comment") << FixItHint::CreateInsertion( - AfterRBrace, " " + getNamespaceComment(ND, NeedLineBreak)); + AfterRBrace, + " " + getNamespaceComment(ND, NeedLineBreak, SpacesBeforeComments)); } } // namespace tidy |