From af20afb761a2426cd715fb8db36b90092e0bb6ef Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 25 Feb 2010 03:23:43 +0000 Subject: [PATCH] Driver: Use TextDiagnosticPrinter instead of a custom one. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97102 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/driver/driver.cpp | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index ed89cd9538..fa0f0c2ded 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -15,6 +15,8 @@ #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Option.h" +#include "clang/Frontend/DiagnosticOptions.h" +#include "clang/Frontend/TextDiagnosticPrinter.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/OwningPtr.h" @@ -29,38 +31,6 @@ using namespace clang; using namespace clang::driver; -class DriverDiagnosticPrinter : public DiagnosticClient { - std::string ProgName; - llvm::raw_ostream &OS; - -public: - DriverDiagnosticPrinter(const std::string _ProgName, - llvm::raw_ostream &_OS) - : ProgName(_ProgName), - OS(_OS) {} - - virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, - const DiagnosticInfo &Info); -}; - -void DriverDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, - const DiagnosticInfo &Info) { - OS << ProgName << ": "; - - switch (Level) { - case Diagnostic::Ignored: assert(0 && "Invalid diagnostic type"); - case Diagnostic::Note: OS << "note: "; break; - case Diagnostic::Warning: OS << "warning: "; break; - case Diagnostic::Error: OS << "error: "; break; - case Diagnostic::Fatal: OS << "fatal error: "; break; - } - - llvm::SmallString<100> OutStr; - Info.FormatDiagnostic(OutStr); - OS.write(OutStr.begin(), OutStr.size()); - OS << '\n'; -} - llvm::sys::Path GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) { if (!CanonicalPrefixes) return llvm::sys::Path(Argv0); @@ -218,7 +188,8 @@ int main(int argc, const char **argv) { llvm::sys::Path Path = GetExecutablePath(argv[0], CanonicalPrefixes); - DriverDiagnosticPrinter DiagClient(Path.getBasename(), llvm::errs()); + TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions()); + DiagClient.setPrefix(Path.getBasename()); Diagnostic Diags(&DiagClient); -- 2.40.0