diff options
author | Alexander Kornienko <alexfh@google.com> | 2014-05-19 16:39:08 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2014-05-19 16:39:08 +0000 |
commit | bef51cdf055d19dfb276c0e155d82acf62feed09 (patch) | |
tree | 65692f83672d62722c421559d7d1e28b70821794 /clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp | |
parent | 06c59e259867ee866b23ae3108a10e62af72c852 (diff) | |
download | bcm5719-llvm-bef51cdf055d19dfb276c0e155d82acf62feed09.tar.gz bcm5719-llvm-bef51cdf055d19dfb276c0e155d82acf62feed09.zip |
Improved llvm-namespace-comment check.
Summary:
Handle various forms of existing namespace closing comments, fix
existing comments with wrong namespace name, ignore short namespaces.
The state of this check now seems to be enough to enable it by default to gather
user feedback ;)
Reviewers: klimek
Reviewed By: klimek
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3825
llvm-svn: 209141
Diffstat (limited to 'clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp | 64 |
1 files changed, 2 insertions, 62 deletions
diff --git a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp index 32766731586..31a114eeebd 100644 --- a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp @@ -7,75 +7,15 @@ // //===----------------------------------------------------------------------===// -#include "LLVMTidyModule.h" #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/ASTMatchers/ASTMatchers.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Lex/PPCallbacks.h" -#include "clang/Lex/Preprocessor.h" -#include "llvm/Support/raw_ostream.h" - -using namespace clang::ast_matchers; +#include "IncludeOrderCheck.h" +#include "NamespaceCommentCheck.h" namespace clang { namespace tidy { -void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher(namespaceDecl().bind("namespace"), this); -} - -void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { - const NamespaceDecl *ND = Result.Nodes.getNodeAs<NamespaceDecl>("namespace"); - Token Tok; - SourceLocation Loc = ND->getRBraceLoc().getLocWithOffset(1); - while (Lexer::getRawToken(Loc, Tok, *Result.SourceManager, - Result.Context->getLangOpts())) { - Loc = Loc.getLocWithOffset(1); - } - // FIXME: Check that this namespace is "long". - if (Tok.is(tok::comment)) { - // FIXME: Check comment content. - // FIXME: Check comment placement on the same line. - return; - } - std::string Fix = " // namespace"; - if (!ND->isAnonymousNamespace()) - Fix = Fix.append(" ").append(ND->getNameAsString()); - - diag(ND->getLocation(), "namespace not terminated with a closing comment") - << FixItHint::CreateInsertion(ND->getRBraceLoc().getLocWithOffset(1), - Fix); -} - -namespace { -class IncludeOrderPPCallbacks : public PPCallbacks { -public: - explicit IncludeOrderPPCallbacks(IncludeOrderCheck &Check) : Check(Check) {} - - void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, - StringRef FileName, bool IsAngled, - CharSourceRange FilenameRange, const FileEntry *File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported) override { - // FIXME: This is a dummy implementation to show how to get at preprocessor - // information. Implement a real include order check. - Check.diag(HashLoc, "This is an include"); - } - -private: - IncludeOrderCheck &Check; -}; -} // namespace - -void IncludeOrderCheck::registerPPCallbacks(CompilerInstance &Compiler) { - Compiler.getPreprocessor() - .addPPCallbacks(new IncludeOrderPPCallbacks(*this)); -} - class LLVMModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { |