aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/ClangTidyDiagnosticConsumer.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2018-11-08 17:42:16 +0000
committerSam McCall <sam.mccall@gmail.com>2018-11-08 17:42:16 +0000
commit69f3a508988df6e41450877c1855e50b924751d1 (patch)
treeff71cf03529e360abaae249f51e67c59295cdb8b /clang-tidy/ClangTidyDiagnosticConsumer.cpp
parentde7076ec3968326b901bcb5d7ace9f5698778666 (diff)
[clang-tidy] Untangle layering in ClangTidyDiagnosticConsumer somewhat. NFC
Summary: Clang's hierarchy is CompilerInstance -> DiagnosticsEngine -> DiagnosticConsumer. (Ownership is optional/shared, but this structure is fairly clear). Currently ClangTidyDiagnosticConsumer *owns* the DiagnosticsEngine: - this inverts the hierarchy, which is confusing - this means ClangTidyDiagnosticConsumer() mutates the passed-in context, which is both surprising and limits flexibility - it's not possible to use a different DiagnosticsEngine with ClangTidy This means a little bit more code in the places ClangTidy is used standalone, but more flexibility in using ClangTidy with other diagnostics configurations. Reviewers: hokein Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D54033 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@346418 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/ClangTidyDiagnosticConsumer.cpp')
-rw-r--r--clang-tidy/ClangTidyDiagnosticConsumer.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index ae3b3301..6e2385bb 100644
--- a/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -267,13 +267,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
ClangTidyContext &Ctx, bool RemoveIncompatibleErrors)
: Context(Ctx), RemoveIncompatibleErrors(RemoveIncompatibleErrors),
LastErrorRelatesToUserCode(false), LastErrorPassesLineFilter(false),
- LastErrorWasIgnored(false) {
- IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
- Diags = llvm::make_unique<DiagnosticsEngine>(
- IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts, this,
- /*ShouldOwnClient=*/false);
- Context.DiagEngine = Diags.get();
-}
+ LastErrorWasIgnored(false) {}
void ClangTidyDiagnosticConsumer::finalizeLastError() {
if (!Errors.empty()) {
@@ -391,7 +385,7 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
if (Info.getLocation().isValid() && DiagLevel != DiagnosticsEngine::Error &&
DiagLevel != DiagnosticsEngine::Fatal &&
- LineIsMarkedWithNOLINTinMacro(Diags->getSourceManager(),
+ LineIsMarkedWithNOLINTinMacro(Info.getSourceManager(),
Info.getLocation(), Info.getID(),
Context)) {
++Context.Stats.ErrorsIgnoredNOLINT;
@@ -453,14 +447,14 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
Errors.back());
SmallString<100> Message;
Info.FormatDiagnostic(Message);
- FullSourceLoc Loc =
- (Info.getLocation().isInvalid())
- ? FullSourceLoc()
- : FullSourceLoc(Info.getLocation(), Info.getSourceManager());
+ FullSourceLoc Loc;
+ if (Info.getLocation().isValid() && Info.hasSourceManager())
+ Loc = FullSourceLoc(Info.getLocation(), Info.getSourceManager());
Converter.emitDiagnostic(Loc, DiagLevel, Message, Info.getRanges(),
Info.getFixItHints());
- checkFilters(Info.getLocation());
+ if (Info.hasSourceManager())
+ checkFilters(Info.getLocation(), Info.getSourceManager());
}
bool ClangTidyDiagnosticConsumer::passesLineFilter(StringRef FileName,
@@ -481,7 +475,8 @@ bool ClangTidyDiagnosticConsumer::passesLineFilter(StringRef FileName,
return false;
}
-void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location) {
+void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
+ const SourceManager &Sources) {
// Invalid location may mean a diagnostic in a command line, don't skip these.
if (!Location.isValid()) {
LastErrorRelatesToUserCode = true;
@@ -489,7 +484,6 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location) {
return;
}
- const SourceManager &Sources = Diags->getSourceManager();
if (!*Context.getOptions().SystemHeaders &&
Sources.isInSystemHeader(Location))
return;