Add a notion of "post-diagnostic hooks", which are callbacks attached
to a diagnostic that will be invoked after the diagnostic (if it is
not suppressed). The hooks are allowed to produce additional
diagnostics (typically notes) that provide more information. We should
be able to use this to help diagnostic clients link notes back to the
diagnostic they clarify. Comments welcome; I'll write up documentation
and convert other clients (e.g., overload resolution failures) if
there are no screams of protest.

As the first client of post-diagnostic hooks, we now produce a
template instantiation backtrace when a failure occurs during template
instantiation. There's still more work to do to make this output
pretty, if that's even possible.




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66557 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index 893eae5..fa5ca57 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -201,6 +201,8 @@
   
   ArgToStringFn = DummyArgToStringFn;
   ArgToStringCookie = 0;
+
+  InPostDiagnosticHook = false;
 }
 
 Diagnostic::~Diagnostic() {
@@ -225,6 +227,12 @@
   return DiagID < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) < ERROR;
 }
 
+/// \brief Determine whether the given built-in diagnostic ID is a
+/// Note.
+bool Diagnostic::isBuiltinNote(unsigned DiagID) {
+  return DiagID < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) == NOTE;
+}
+
 
 /// getDescription - Given a diagnostic ID, return a description of the
 /// issue.
@@ -373,6 +381,16 @@
   // Finally, report it.
   Client->HandleDiagnostic(DiagLevel, Info);
   if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics;
+
+  // Invoke any post-diagnostic hooks.
+  unsigned LastDiag = CurDiagID;
+  CurDiagID = ~0U;
+  
+  InPostDiagnosticHook = true;
+  for (unsigned Hook = 0; Hook < NumPostDiagnosticHooks; ++Hook)
+    PostDiagnosticHooks[Hook].Hook(LastDiag, 
+                                   PostDiagnosticHooks[Hook].Cookie);
+  InPostDiagnosticHook = false;
 }