Add an overload for SourceMgr::PrintMessage that takes an existing diagnostic.
authorJordan Rose <jordan_rose@apple.com>
Tue, 17 Jun 2014 02:15:40 +0000 (02:15 +0000)
committerJordan Rose <jordan_rose@apple.com>
Tue, 17 Jun 2014 02:15:40 +0000 (02:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211087 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/SourceMgr.h
lib/Support/SourceMgr.cpp

index aee4744a592cbfd97d779b5f3490cb4cb488758f..30eccd99acbc63431fcf475e48e244c0c40b9432 100644 (file)
@@ -157,6 +157,13 @@ public:
                     ArrayRef<SMFixIt> FixIts = None,
                     bool ShowColors = true) const;
 
+  /// Emits a manually-constructed diagnostic to the given output stream.
+  ///
+  /// \param ShowColors Display colored messages if output is a terminal and
+  /// the default error handler is used.
+  void PrintMessage(raw_ostream &OS, const SMDiagnostic &Diagnostic,
+                    bool ShowColors = true) const;
+
   /// Return an SMDiagnostic at the specified location with the specified
   /// string.
   ///
index 6d530e6fa0d854ef20c01f513baa7af7703ca9f0..4d00d3baa417852f20034b0d395ca10a303759b4 100644 (file)
@@ -199,20 +199,16 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
                       LineStr, ColRanges, FixIts);
 }
 
-void SourceMgr::PrintMessage(raw_ostream &OS, SMLoc Loc,
-                             SourceMgr::DiagKind Kind,
-                             const Twine &Msg, ArrayRef<SMRange> Ranges,
-                             ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
-  SMDiagnostic Diagnostic = GetMessage(Loc, Kind, Msg, Ranges, FixIts);
-  
+void SourceMgr::PrintMessage(raw_ostream &OS, const SMDiagnostic &Diagnostic,
+                             bool ShowColors) const {
   // Report the message with the diagnostic handler if present.
   if (DiagHandler) {
     DiagHandler(Diagnostic, DiagContext);
     return;
   }
 
-  if (Loc != SMLoc()) {
-    int CurBuf = FindBufferContainingLoc(Loc);
+  if (Diagnostic.getLoc().isValid()) {
+    int CurBuf = FindBufferContainingLoc(Diagnostic.getLoc());
     assert(CurBuf != -1 && "Invalid or unspecified location!");
     PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
   }
@@ -220,6 +216,13 @@ void SourceMgr::PrintMessage(raw_ostream &OS, SMLoc Loc,
   Diagnostic.print(nullptr, OS, ShowColors);
 }
 
+void SourceMgr::PrintMessage(raw_ostream &OS, SMLoc Loc,
+                             SourceMgr::DiagKind Kind,
+                             const Twine &Msg, ArrayRef<SMRange> Ranges,
+                             ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
+  PrintMessage(OS, GetMessage(Loc, Kind, Msg, Ranges, FixIts), ShowColors);
+}
+
 void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
                              const Twine &Msg, ArrayRef<SMRange> Ranges,
                              ArrayRef<SMFixIt> FixIts, bool ShowColors) const {