diff options
| author | Alexander Kornienko <alexfh@google.com> | 2014-01-09 02:21:52 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2014-01-09 02:21:52 +0000 |
| commit | 73f7b0273efabfb414d14d2c68cfb70b808ba34a (patch) | |
| tree | fead08336ba0b6a1ce48a0de57d9bbbc1e0aa8c6 | |
| parent | 58983f139896f7458b8539c16e7015a5fb778282 (diff) | |
| download | bcm5719-llvm-73f7b0273efabfb414d14d2c68cfb70b808ba34a.tar.gz bcm5719-llvm-73f7b0273efabfb414d14d2c68cfb70b808ba34a.zip | |
Reverted r198807, r198808, as they cause link errors in configure builds. Will look at this later.
llvm-svn: 198832
| -rw-r--r-- | clang-tools-extra/clang-tidy/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/ClangTidy.cpp | 32 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp | 117 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h | 54 |
4 files changed, 81 insertions, 123 deletions
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt index b1d32cb6603..a1610b7e3df 100644 --- a/clang-tools-extra/clang-tidy/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/CMakeLists.txt @@ -5,7 +5,6 @@ set(LLVM_LINK_COMPONENTS add_clang_library(clangTidy ClangTidy.cpp ClangTidyModule.cpp - ClangTidyDiagnosticConsumer.cpp ) target_link_libraries(clangTidy clangAST diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index bbcd0204f2d..e465c6cbbfd 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -174,6 +174,38 @@ bool ChecksFilter::IsCheckEnabled(StringRef Name) { return EnableChecks.match(Name) && !DisableChecks.match(Name); } +ClangTidyMessage::ClangTidyMessage(StringRef Message) : Message(Message) {} + +ClangTidyMessage::ClangTidyMessage(StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) + : Message(Message) { + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +ClangTidyError::ClangTidyError(const ClangTidyMessage &Message) + : Message(Message) {} + +DiagnosticBuilder ClangTidyContext::Diag(SourceLocation Loc, + StringRef Message) { + return DiagEngine->Report( + Loc, DiagEngine->getCustomDiagID(DiagnosticsEngine::Warning, Message)); +} + +void ClangTidyContext::setDiagnosticsEngine(DiagnosticsEngine *Engine) { + DiagEngine = Engine; +} + +void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) { + DiagEngine->setSourceManager(SourceMgr); +} + +/// \brief Store a \c ClangTidyError. +void ClangTidyContext::storeError(const ClangTidyError &Error) { + Errors->push_back(Error); +} + void ClangTidyCheck::run(const ast_matchers::MatchFinder::MatchResult &Result) { Context->setSourceManager(Result.SourceManager); check(Result); diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp deleted file mode 100644 index 4d92222588b..00000000000 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ /dev/null @@ -1,117 +0,0 @@ -//===--- tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp ----------=== // -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// -/// \file This file implements ClangTidyDiagnosticConsumer, ClangTidyMessage, -/// ClangTidyContext and ClangTidyError classes. -/// -/// This tool uses the Clang Tooling infrastructure, see -/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html -/// for details on setting it up with LLVM source tree. -/// -//===----------------------------------------------------------------------===// - -#include "ClangTidyDiagnosticConsumer.h" - -#include "llvm/ADT/SmallString.h" - -namespace clang { -namespace tidy { - -ClangTidyMessage::ClangTidyMessage(StringRef Message) : Message(Message) {} - -ClangTidyMessage::ClangTidyMessage(StringRef Message, - const SourceManager &Sources, - SourceLocation Loc) - : Message(Message) { - FilePath = Sources.getFilename(Loc); - FileOffset = Sources.getFileOffset(Loc); -} - -ClangTidyError::ClangTidyError(const ClangTidyMessage &Message) - : Message(Message) {} - -DiagnosticBuilder ClangTidyContext::Diag(SourceLocation Loc, - StringRef Message) { - return DiagEngine->Report( - Loc, DiagEngine->getCustomDiagID(DiagnosticsEngine::Warning, Message)); -} - -void ClangTidyContext::setDiagnosticsEngine(DiagnosticsEngine *Engine) { - DiagEngine = Engine; -} - -void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) { - DiagEngine->setSourceManager(SourceMgr); -} - -/// \brief Store a \c ClangTidyError. -void ClangTidyContext::storeError(const ClangTidyError &Error) { - Errors->push_back(Error); -} - -ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx) - : Context(Ctx) { - IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); - Diags.reset(new DiagnosticsEngine( - IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts, this, - /*ShouldOwnClient=*/false)); - Context.setDiagnosticsEngine(Diags.get()); -} - -void ClangTidyDiagnosticConsumer::HandleDiagnostic( - DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) { - // FIXME: Demultiplex diagnostics. - // FIXME: Ensure that we don't get notes from user code related to errors - // from non-user code. - if (Diags->getSourceManager().isInSystemHeader(Info.getLocation())) - return; - if (DiagLevel != DiagnosticsEngine::Note) { - Errors.push_back(ClangTidyError(getMessage(Info))); - } else { - assert(!Errors.empty() && - "A diagnostic note can only be appended to a message."); - Errors.back().Notes.push_back(getMessage(Info)); - } - addFixes(Info, Errors.back()); -} - -// Flushes the internal diagnostics buffer to the ClangTidyContext. -void ClangTidyDiagnosticConsumer::finish() { - for (unsigned i = 0, e = Errors.size(); i != e; ++i) { - Context.storeError(Errors[i]); - } - Errors.clear(); -} - -void ClangTidyDiagnosticConsumer::addFixes(const Diagnostic &Info, - ClangTidyError &Error) { - if (!Info.hasSourceManager()) - return; - SourceManager &SourceMgr = Info.getSourceManager(); - tooling::Replacements Replacements; - for (unsigned i = 0, e = Info.getNumFixItHints(); i != e; ++i) { - Error.Fix.insert(tooling::Replacement( - SourceMgr, Info.getFixItHint(i).RemoveRange.getBegin(), 0, - Info.getFixItHint(i).CodeToInsert)); - } -} - -ClangTidyMessage -ClangTidyDiagnosticConsumer::getMessage(const Diagnostic &Info) const { - SmallString<100> Buf; - Info.FormatDiagnostic(Buf); - if (!Info.hasSourceManager()) { - return ClangTidyMessage(Buf.str()); - } - return ClangTidyMessage(Buf.str(), Info.getSourceManager(), - Info.getLocation()); -} - -} // namespace tidy -} // namespace clang diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h index f8ac6efdf31..613e8fb8c57 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -13,6 +13,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Tooling/Refactoring.h" +#include "llvm/ADT/SmallString.h" namespace clang { @@ -102,20 +103,63 @@ private: // implementation file. class ClangTidyDiagnosticConsumer : public DiagnosticConsumer { public: - ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx); + ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx) : Context(Ctx) { + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + Diags.reset(new DiagnosticsEngine( + IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts, this, + /*ShouldOwnClient=*/false)); + Context.setDiagnosticsEngine(Diags.get()); + } // FIXME: The concept of converting between FixItHints and Replacements is // more generic and should be pulled out into a more useful Diagnostics // library. virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Info) LLVM_OVERRIDE; + const Diagnostic &Info) LLVM_OVERRIDE { + // FIXME: Ensure that we don't get notes from user code related to errors + // from non-user code. + if (Diags->getSourceManager().isInSystemHeader(Info.getLocation())) + return; + if (DiagLevel != DiagnosticsEngine::Note) { + Errors.push_back(ClangTidyError(getMessage(Info))); + } else { + assert(!Errors.empty() && + "A diagnostic note can only be appended to a message."); + Errors.back().Notes.push_back(getMessage(Info)); + } + addFixes(Info, Errors.back()); + } // Flushes the internal diagnostics buffer to the ClangTidyContext. - virtual void finish() LLVM_OVERRIDE; + virtual void finish() LLVM_OVERRIDE { + for (unsigned i = 0, e = Errors.size(); i != e; ++i) { + Context.storeError(Errors[i]); + } + Errors.clear(); + } private: - void addFixes(const Diagnostic &Info, ClangTidyError &Error); - ClangTidyMessage getMessage(const Diagnostic &Info) const; + void addFixes(const Diagnostic &Info, ClangTidyError &Error) { + if (!Info.hasSourceManager()) + return; + SourceManager &SourceMgr = Info.getSourceManager(); + tooling::Replacements Replacements; + for (unsigned i = 0, e = Info.getNumFixItHints(); i != e; ++i) { + Error.Fix.insert(tooling::Replacement( + SourceMgr, Info.getFixItHint(i).RemoveRange.getBegin(), 0, + Info.getFixItHint(i).CodeToInsert)); + } + } + + ClangTidyMessage getMessage(const Diagnostic &Info) const { + SmallString<100> Buf; + Info.FormatDiagnostic(Buf); + if (!Info.hasSourceManager()) { + return ClangTidyMessage(Buf.str()); + } + return ClangTidyMessage(Buf.str(), Info.getSourceManager(), + Info.getLocation()); + } ClangTidyContext &Context; OwningPtr<DiagnosticsEngine> Diags; |

