[cfe-commits] r97101 - in /cfe/trunk: include/clang/Frontend/TextDiagnosticPrinter.h lib/Frontend/TextDiagnosticPrinter.cpp

Daniel Dunbar daniel at zuster.org
Wed Feb 24 19:23:40 PST 2010


Author: ddunbar
Date: Wed Feb 24 21:23:40 2010
New Revision: 97101

URL: http://llvm.org/viewvc/llvm-project?rev=97101&view=rev
Log:
Add TextDiagnosticPrinter::setPrefix, for adding a string to prefix diagnostic
messages with.

Modified:
    cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
    cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Modified: cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h?rev=97101&r1=97100&r2=97101&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h Wed Feb 24 21:23:40 2010
@@ -37,11 +37,19 @@
   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;
   }

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=97101&r1=97100&r2=97101&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Wed Feb 24 21:23:40 2010
@@ -31,7 +31,7 @@
   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 @@
   // 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()) {





More information about the cfe-commits mailing list