Give llvm::SourceMgr the ability to have a client-specified
diagnostic handler.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100503 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp
index 83c7964..fe2fbd9 100644
--- a/lib/Support/SourceMgr.cpp
+++ b/lib/Support/SourceMgr.cpp
@@ -168,13 +168,20 @@
   }
   PrintedMsg += Msg;
 
-  return SMDiagnostic(CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
+  return SMDiagnostic(Loc,
+                      CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
                       Loc.getPointer()-LineStart, PrintedMsg,
                       LineStr, ShowLine);
 }
 
 void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg,
                              const char *Type, bool ShowLine) const {
+  // Report the message with the diagnostic handler if present.
+  if (DiagHandler) {
+    DiagHandler(GetMessage(Loc, Msg, Type, ShowLine), DiagContext);
+    return;
+  }
+  
   raw_ostream &OS = errs();
 
   int CurBuf = FindBufferContainingLoc(Loc);