From ebbbb1b211119e13229c487dfc1713e8d1e77a41 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 20 Feb 2009 00:18:51 +0000 Subject: [PATCH] refactor, pass ranges down instead of the whole DiagnosticInfo. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65088 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/TextDiagnosticPrinter.h | 5 ++-- lib/Driver/TextDiagnosticPrinter.cpp | 24 ++++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/clang/Driver/TextDiagnosticPrinter.h b/include/clang/Driver/TextDiagnosticPrinter.h index 19d1b76030..3f4f06a2c7 100644 --- a/include/clang/Driver/TextDiagnosticPrinter.h +++ b/include/clang/Driver/TextDiagnosticPrinter.h @@ -46,8 +46,9 @@ public: std::string &CaretLine, const std::string &SourceLine); - void EmitCaretDiagnostic(const DiagnosticInfo &Info, - SourceLocation Loc, SourceManager &SM); + void EmitCaretDiagnostic(SourceLocation Loc, + const SourceRange *Ranges, unsigned NumRanges, + SourceManager &SM); virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, const DiagnosticInfo &Info); diff --git a/lib/Driver/TextDiagnosticPrinter.cpp b/lib/Driver/TextDiagnosticPrinter.cpp index 39a4328ae3..31b492a27a 100644 --- a/lib/Driver/TextDiagnosticPrinter.cpp +++ b/lib/Driver/TextDiagnosticPrinter.cpp @@ -101,8 +101,9 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R, CaretLine[i] = '~'; } -void TextDiagnosticPrinter::EmitCaretDiagnostic(const DiagnosticInfo &Info, - SourceLocation Loc, +void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc, + const SourceRange *Ranges, + unsigned NumRanges, SourceManager &SM) { assert(!Loc.isInvalid() && "must have a valid source location here"); @@ -110,7 +111,7 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(const DiagnosticInfo &Info, // points. This more closely correlates to what the user writes. if (!Loc.isFileID()) { SourceLocation OneLevelUp = SM.getImmediateInstantiationRange(Loc).first; - EmitCaretDiagnostic(Info, OneLevelUp, SM); + EmitCaretDiagnostic(OneLevelUp, Ranges, NumRanges, SM); Loc = SM.getInstantiationLoc(SM.getImmediateSpellingLoc(Loc)); @@ -154,11 +155,11 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(const DiagnosticInfo &Info, std::string CaretLine(LineEnd-LineStart, ' '); // Highlight all of the characters covered by Ranges with ~ characters. - if (Info.getNumRanges()) { + if (NumRanges) { unsigned LineNo = SM.getLineNumber(FID, FileOffset); - for (unsigned i = 0; i != Info.getNumRanges(); ++i) - HighlightRange(Info.getRange(i), SM, LineNo, FID, CaretLine, SourceLine); + for (unsigned i = 0, e = NumRanges; i != e; ++i) + HighlightRange(Ranges[i], SM, LineNo, FID, CaretLine, SourceLine); } // Next, insert the caret itself. @@ -244,9 +245,14 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, // Cache the LastLoc, it allows us to omit duplicate source/caret spewage. LastLoc = Info.getLocation(); - // Inspect the actual source location of the diagnostic, we don't care - // about presumed locations anymore. - EmitCaretDiagnostic(Info, LastLoc, LastLoc.getManager()); + // Get the ranges into a local array we can hack on. + SourceRange Ranges[10]; + unsigned NumRanges = Info.getNumRanges(); + assert(NumRanges < 10 && "Out of space"); + for (unsigned i = 0; i != NumRanges; ++i) + Ranges[i] = Info.getRange(i); + + EmitCaretDiagnostic(LastLoc, Ranges, NumRanges, LastLoc.getManager()); } OS.flush(); -- 2.40.0