Split the DiagnosticInfo class into two disjoint classes:
one for building up the diagnostic that is in flight (DiagnosticBuilder)
and one for pulling structured information out of the diagnostic when
formatting and presenting it.

There is no functionality change with this patch.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59849 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index e83d4f3..164ac1b 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -129,7 +129,7 @@
   NumDiagnostics = 0;
   NumErrors = 0;
   CustomDiagInfo = 0;
-  NumDiagArgs = -1;
+  CurDiagID = ~0U;
 }
 
 Diagnostic::~Diagnostic() {
@@ -215,7 +215,9 @@
 
 /// ProcessDiag - This is the method used to report a diagnostic that is
 /// finally fully formed.
-void Diagnostic::ProcessDiag(const DiagnosticInfo &Info) {
+void Diagnostic::ProcessDiag() {
+  DiagnosticInfo Info(this);
+  
   // Figure out the diagnostic level of this message.
   Diagnostic::Level DiagLevel = getDiagnosticLevel(Info.getID());
   
@@ -347,25 +349,25 @@
     unsigned StrNo = *DiagStr++ - '0';
 
     switch (getArgKind(StrNo)) {
-    case DiagnosticInfo::ak_std_string: {
+    case Diagnostic::ak_std_string: {
       const std::string &S = getArgStdStr(StrNo);
       assert(ModifierLen == 0 && "No modifiers for strings yet");
       OutStr.append(S.begin(), S.end());
       break;
     }
-    case DiagnosticInfo::ak_c_string: {
+    case Diagnostic::ak_c_string: {
       const char *S = getArgCStr(StrNo);
       assert(ModifierLen == 0 && "No modifiers for strings yet");
       OutStr.append(S, S + strlen(S));
       break;
     }
-    case DiagnosticInfo::ak_identifierinfo: {
+    case Diagnostic::ak_identifierinfo: {
       const IdentifierInfo *II = getArgIdentifier(StrNo);
       assert(ModifierLen == 0 && "No modifiers for strings yet");
       OutStr.append(II->getName(), II->getName() + II->getLength());
       break;
     }
-    case DiagnosticInfo::ak_sint: {
+    case Diagnostic::ak_sint: {
       int Val = getArgSInt(StrNo);
       
       if (ModifierIs(Modifier, ModifierLen, "select")) {
@@ -380,7 +382,7 @@
       }
       break;
     }
-    case DiagnosticInfo::ak_uint: {
+    case Diagnostic::ak_uint: {
       unsigned Val = getArgUInt(StrNo);
       
       if (ModifierIs(Modifier, ModifierLen, "select")) {
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index eebdd1e..4c25287 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -309,9 +309,9 @@
 
 /// Diag - Forwarding function for diagnostics.  This translate a source
 /// position in the current buffer into a SourceLocation object for rendering.
-DiagnosticInfo Lexer::Diag(const char *Loc, unsigned DiagID) const {
+DiagnosticBuilder Lexer::Diag(const char *Loc, unsigned DiagID) const {
   if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID))
-    return DiagnosticInfo(0, FullSourceLoc(), 0);
+    return DiagnosticBuilder();
   return PP->Diag(getSourceLocation(Loc), DiagID);
 }
 
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 3d0b4d0..5f8f351 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -117,11 +117,11 @@
 /// Diag - Forwarding function for diagnostics.  This emits a diagnostic at
 /// the specified Token's location, translating the token's start
 /// position in the current buffer into a SourcePosition object for rendering.
-DiagnosticInfo Preprocessor::Diag(SourceLocation Loc, unsigned DiagID) {
+DiagnosticBuilder Preprocessor::Diag(SourceLocation Loc, unsigned DiagID) {
   return Diags.Report(getFullLoc(Loc), DiagID);
 }
 
-DiagnosticInfo Preprocessor::Diag(const Token &Tok, unsigned DiagID) {
+DiagnosticBuilder Preprocessor::Diag(const Token &Tok, unsigned DiagID) {
   return Diags.Report(getFullLoc(Tok.getLocation()), DiagID);
 }
 
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 86c2976..ae75266 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -41,11 +41,11 @@
 Action::~Action() {}
 
 
-DiagnosticInfo Parser::Diag(SourceLocation Loc, unsigned DiagID) {
+DiagnosticBuilder Parser::Diag(SourceLocation Loc, unsigned DiagID) {
   return Diags.Report(FullSourceLoc(Loc,PP.getSourceManager()), DiagID);
 }
 
-DiagnosticInfo Parser::Diag(const Token &Tok, unsigned DiagID) {
+DiagnosticBuilder Parser::Diag(const Token &Tok, unsigned DiagID) {
   return Diag(Tok.getLocation(), DiagID);
 }
 
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 44e5891..7c49844 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -157,7 +157,7 @@
 // Helper functions.
 //===----------------------------------------------------------------------===//
 
-DiagnosticInfo Sema::Diag(SourceLocation Loc, unsigned DiagID) {
+DiagnosticBuilder Sema::Diag(SourceLocation Loc, unsigned DiagID) {
   return PP.getDiagnostics().Report(FullSourceLoc(Loc, PP.getSourceManager()),
                                     DiagID);
 }
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index d569994..6d9e582 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -226,7 +226,7 @@
   const LangOptions &getLangOptions() const;
   
   /// The primitive diagnostic helpers.
-  DiagnosticInfo Diag(SourceLocation Loc, unsigned DiagID);
+  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
 
   virtual void DeleteExpr(ExprTy *E);
   virtual void DeleteStmt(StmtTy *S);