[NFC] Update to account for DiagnosticRenderer use of FullSourceLoc

D31709 [NFC] Refactor DiagnosticRenderer to use FullSourceLoc was committed
in r305684 and reverted in 305688 as clang-tidy and clang-query failed to
build. This change updates the extra tools to use the new interface.

Reviewers: christof, rnk, rsmith, rovka, alexfh

Reviewed By: alexfh

Differential Revision: https://reviews.llvm.org/D34513

llvm-svn: 306385
This commit is contained in:
Peter Smith 2017-06-27 10:04:04 +00:00
parent fb4a0450db
commit d34a65d6b6
2 changed files with 26 additions and 29 deletions

View File

@ -97,10 +97,10 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
if (R.isValid()) { if (R.isValid()) {
TextDiagnostic TD(OS, AST->getASTContext().getLangOpts(), TextDiagnostic TD(OS, AST->getASTContext().getLangOpts(),
&AST->getDiagnostics().getDiagnosticOptions()); &AST->getDiagnostics().getDiagnosticOptions());
TD.emitDiagnostic(R.getBegin(), DiagnosticsEngine::Note, TD.emitDiagnostic(
"\"" + BI->first + "\" binds here", FullSourceLoc(R.getBegin(), AST->getSourceManager()),
CharSourceRange::getTokenRange(R), None, DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here",
&AST->getSourceManager()); CharSourceRange::getTokenRange(R), None);
} }
break; break;
} }

View File

@ -36,10 +36,9 @@ public:
: DiagnosticRenderer(LangOpts, DiagOpts), Error(Error) {} : DiagnosticRenderer(LangOpts, DiagOpts), Error(Error) {}
protected: protected:
void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
DiagnosticsEngine::Level Level, StringRef Message, DiagnosticsEngine::Level Level, StringRef Message,
ArrayRef<CharSourceRange> Ranges, ArrayRef<CharSourceRange> Ranges,
const SourceManager *SM,
DiagOrStoredDiag Info) override { DiagOrStoredDiag Info) override {
// Remove check name from the message. // Remove check name from the message.
// FIXME: Remove this once there's a better way to pass check names than // FIXME: Remove this once there's a better way to pass check names than
@ -49,9 +48,10 @@ protected:
if (Message.endswith(CheckNameInMessage)) if (Message.endswith(CheckNameInMessage))
Message = Message.substr(0, Message.size() - CheckNameInMessage.size()); Message = Message.substr(0, Message.size() - CheckNameInMessage.size());
auto TidyMessage = Loc.isValid() auto TidyMessage =
? tooling::DiagnosticMessage(Message, *SM, Loc) Loc.isValid()
: tooling::DiagnosticMessage(Message); ? tooling::DiagnosticMessage(Message, Loc.getManager(), Loc)
: tooling::DiagnosticMessage(Message);
if (Level == DiagnosticsEngine::Note) { if (Level == DiagnosticsEngine::Note) {
Error.Notes.push_back(TidyMessage); Error.Notes.push_back(TidyMessage);
return; return;
@ -60,15 +60,13 @@ protected:
Error.Message = TidyMessage; Error.Message = TidyMessage;
} }
void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
DiagnosticsEngine::Level Level, DiagnosticsEngine::Level Level,
ArrayRef<CharSourceRange> Ranges, ArrayRef<CharSourceRange> Ranges) override {}
const SourceManager &SM) override {}
void emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level, void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
SmallVectorImpl<CharSourceRange> &Ranges, SmallVectorImpl<CharSourceRange> &Ranges,
ArrayRef<FixItHint> Hints, ArrayRef<FixItHint> Hints) override {
const SourceManager &SM) override {
assert(Loc.isValid()); assert(Loc.isValid());
for (const auto &FixIt : Hints) { for (const auto &FixIt : Hints) {
CharSourceRange Range = FixIt.RemoveRange; CharSourceRange Range = FixIt.RemoveRange;
@ -77,7 +75,8 @@ protected:
assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() && assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() &&
"Only file locations supported in fix-it hints."); "Only file locations supported in fix-it hints.");
tooling::Replacement Replacement(SM, Range, FixIt.CodeToInsert); tooling::Replacement Replacement(Loc.getManager(), Range,
FixIt.CodeToInsert);
llvm::Error Err = Error.Fix[Replacement.getFilePath()].add(Replacement); llvm::Error Err = Error.Fix[Replacement.getFilePath()].add(Replacement);
// FIXME: better error handling (at least, don't let other replacements be // FIXME: better error handling (at least, don't let other replacements be
// applied). // applied).
@ -89,16 +88,13 @@ protected:
} }
} }
void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override {}
const SourceManager &SM) override {}
void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
StringRef ModuleName, StringRef ModuleName) override {}
const SourceManager &SM) override {}
void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
StringRef ModuleName, StringRef ModuleName) override {}
const SourceManager &SM) override {}
void endDiagnostic(DiagOrStoredDiag D, void endDiagnostic(DiagOrStoredDiag D,
DiagnosticsEngine::Level Level) override { DiagnosticsEngine::Level Level) override {
@ -419,11 +415,12 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
Errors.back()); Errors.back());
SmallString<100> Message; SmallString<100> Message;
Info.FormatDiagnostic(Message); Info.FormatDiagnostic(Message);
SourceManager *Sources = nullptr; FullSourceLoc Loc =
if (Info.hasSourceManager()) (Info.getLocation().isInvalid())
Sources = &Info.getSourceManager(); ? FullSourceLoc()
Converter.emitDiagnostic(Info.getLocation(), DiagLevel, Message, : FullSourceLoc(Info.getLocation(), Info.getSourceManager());
Info.getRanges(), Info.getFixItHints(), Sources); Converter.emitDiagnostic(Loc, DiagLevel, Message, Info.getRanges(),
Info.getFixItHints());
checkFilters(Info.getLocation()); checkFilters(Info.getLocation());
} }