This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed.  In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a 
ton of random stuff.  This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.

In addition to introducing DiagnosticInfo, this also substantially changes how 
Diagnostic::Report works.  Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and 
ID) and returns a fresh DiagnosticInfo *by value*.  The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator.  When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information.  This is a somewhat tricky dance, but it means that the 
accumulated DiagnosticInfo is allowed to keep pointers to other expression 
temporaries without those pointers getting invalidated.

This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema.  For example, instead of calling:

  Diag(BuiltinLoc, diag::err_overload_no_match, typeNames,
       SourceRange(BuiltinLoc, RParenLoc));

We will soon be able to just do:

  Diag(BuiltinLoc, diag::err_overload_no_match)
      << typeNames << SourceRange(BuiltinLoc, RParenLoc));

This scales better to support arbitrary types being passed in (not just 
strings) in a type-safe way.  Go operator overloading?!



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59502 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/TextDiagnosticPrinter.cpp b/lib/Driver/TextDiagnosticPrinter.cpp
index e03588b..3b8ec10 100644
--- a/lib/Driver/TextDiagnosticPrinter.cpp
+++ b/lib/Driver/TextDiagnosticPrinter.cpp
@@ -34,7 +34,7 @@
 /// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s)
 /// any characters in LineNo that intersect the SourceRange.
 void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
-                                           SourceManager& SourceMgr,
+                                           const SourceManager& SourceMgr,
                                            unsigned LineNo, unsigned FileID,
                                            std::string &CaretLine,
                                            const std::string &SourceLine) {
@@ -92,17 +92,12 @@
     CaretLine[i] = '~';
 }
 
-void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
-                                             Diagnostic::Level Level, 
-                                             FullSourceLoc Pos,
-                                             diag::kind ID,
-                                             const std::string **Strs,
-                                             unsigned NumStrs,
-                                             const SourceRange *Ranges,
-                                             unsigned NumRanges) {
+void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, 
+                                             const DiagnosticInfo &Info) {
   unsigned LineNo = 0, ColNo = 0;
   unsigned FileID = 0;
   const char *LineStart = 0, *LineEnd = 0;
+  const FullSourceLoc &Pos = Info.getLocation();
   
   if (Pos.isValid()) {
     FullSourceLoc LPos = Pos.getLogicalLoc();
@@ -146,9 +141,10 @@
     break;
   }
   
-  OS << FormatDiagnostic(Diags, Level, ID, Strs, NumStrs) << "\n";
+  OS << FormatDiagnostic(Info) << "\n";
   
-  if (CaretDiagnostics && Pos.isValid() && ((LastLoc != Pos) || Ranges)) {
+  if (CaretDiagnostics && Pos.isValid() && ((LastLoc != Pos) ||
+                                            Info.getNumRanges())) {
     // Cache the LastLoc, it allows us to omit duplicate source/caret spewage.
     LastLoc = Pos;
     
@@ -160,8 +156,8 @@
     std::string CaretLine(LineEnd-LineStart, ' ');
     
     // Highlight all of the characters covered by Ranges with ~ characters.
-    for (unsigned i = 0; i != NumRanges; ++i)
-      HighlightRange(Ranges[i], Pos.getManager(), LineNo, FileID,
+    for (unsigned i = 0; i != Info.getNumRanges(); ++i)
+      HighlightRange(Info.getRange(i), Pos.getManager(), LineNo, FileID,
                      CaretLine, SourceLine);
     
     // Next, insert the caret itself.