rewrite FormatDiagnostic to be less gross and a lot more efficient.
This also makes it illegal to have bare '%'s in diagnostics. If you
want a % in a diagnostic, use %%.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59596 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/TextDiagnosticBuffer.cpp b/lib/Driver/TextDiagnosticBuffer.cpp
index b138b1a..5032cdb 100644
--- a/lib/Driver/TextDiagnosticBuffer.cpp
+++ b/lib/Driver/TextDiagnosticBuffer.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Driver/TextDiagnosticBuffer.h"
+#include "llvm/ADT/SmallString.h"
using namespace clang;
/// HandleDiagnostic - Store the errors, warnings, and notes that are
@@ -19,19 +20,19 @@
///
void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level,
const DiagnosticInfo &Info) {
+ llvm::SmallString<100> StrC;
+ Info.FormatDiagnostic(StrC);
+ std::string Str(StrC.begin(), StrC.end());
switch (Level) {
default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
case Diagnostic::Note:
- Notes.push_back(std::make_pair(Info.getLocation().getLocation(),
- FormatDiagnostic(Info)));
+ Notes.push_back(std::make_pair(Info.getLocation().getLocation(), Str));
break;
case Diagnostic::Warning:
- Warnings.push_back(std::make_pair(Info.getLocation().getLocation(),
- FormatDiagnostic(Info)));
+ Warnings.push_back(std::make_pair(Info.getLocation().getLocation(), Str));
break;
case Diagnostic::Error:
- Errors.push_back(std::make_pair(Info.getLocation().getLocation(),
- FormatDiagnostic(Info)));
+ Errors.push_back(std::make_pair(Info.getLocation().getLocation(), Str));
break;
}
}
diff --git a/lib/Driver/TextDiagnosticPrinter.cpp b/lib/Driver/TextDiagnosticPrinter.cpp
index 3b8ec10..cfbe8a7 100644
--- a/lib/Driver/TextDiagnosticPrinter.cpp
+++ b/lib/Driver/TextDiagnosticPrinter.cpp
@@ -15,6 +15,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/ADT/SmallString.h"
using namespace clang;
void TextDiagnosticPrinter::
@@ -138,13 +139,15 @@
case Diagnostic::Warning: OS << "warning: "; break;
case Diagnostic::Error: OS << "error: "; break;
case Diagnostic::Fatal: OS << "fatal error: "; break;
- break;
}
- OS << FormatDiagnostic(Info) << "\n";
+ llvm::SmallString<100> OutStr;
+ Info.FormatDiagnostic(OutStr);
+ OS.write(OutStr.begin(), OutStr.size());
+ OS << '\n';
- if (CaretDiagnostics && Pos.isValid() && ((LastLoc != Pos) ||
- Info.getNumRanges())) {
+ if (CaretDiagnostics && Pos.isValid() &&
+ ((LastLoc != Pos) || Info.getNumRanges())) {
// Cache the LastLoc, it allows us to omit duplicate source/caret spewage.
LastLoc = Pos;