From b96b6709fbf5044ab06223ebfefccd58d7aaa88b Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 25 Feb 2010 03:23:40 +0000 Subject: [PATCH] Add TextDiagnosticPrinter::setPrefix, for adding a string to prefix diagnostic messages with. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97101 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/TextDiagnosticPrinter.h | 8 ++++++++ lib/Frontend/TextDiagnosticPrinter.cpp | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/clang/Frontend/TextDiagnosticPrinter.h b/include/clang/Frontend/TextDiagnosticPrinter.h index d727e48007..d09e51fd01 100644 --- a/include/clang/Frontend/TextDiagnosticPrinter.h +++ b/include/clang/Frontend/TextDiagnosticPrinter.h @@ -37,11 +37,19 @@ class TextDiagnosticPrinter : public DiagnosticClient { unsigned LastCaretDiagnosticWasNote : 1; unsigned OwnsOutputStream : 1; + /// A string to prefix to error messages. + std::string Prefix; + public: TextDiagnosticPrinter(llvm::raw_ostream &os, const DiagnosticOptions &diags, bool OwnsOutputStream = false); virtual ~TextDiagnosticPrinter(); + /// setPrefix - Set the diagnostic printer prefix string, which will be + /// printed at the start of any diagnostics. If empty, no prefix string is + /// used. + void setPrefix(std::string Value) { Prefix = Value; } + void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) { LangOpts = &LO; } diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 3c64332512..d2aa5480b4 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -31,7 +31,7 @@ static const enum llvm::raw_ostream::Colors warningColor = llvm::raw_ostream::MAGENTA; static const enum llvm::raw_ostream::Colors errorColor = llvm::raw_ostream::RED; static const enum llvm::raw_ostream::Colors fatalColor = llvm::raw_ostream::RED; -// used for changing only the bold attribute +// Used for changing only the bold attribute. static const enum llvm::raw_ostream::Colors savedColor = llvm::raw_ostream::SAVEDCOLOR; @@ -682,6 +682,9 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, // file+line+column number prefix is. uint64_t StartOfLocationInfo = OS.tell(); + if (!Prefix.empty()) + OS << Prefix << ": "; + // If the location is specified, print out a file/line/col and include trace // if enabled. if (Info.getLocation().isValid()) { -- 2.40.0