Modified the internals of Diagnostic and DiagnosticClient to use
SourceManager*'s instead of SourceManager&'s. This allows the client specify a
NULL SourceManager when using a default constructed SourceLocation. Thus the
SourceManager can be NULL when the SourceLocation's isValid() == false.

The interface to most clients of Diagnostic remains the same.
Diagnostic::Report() is overload to either accept a SourceLocation and a
SourceManager&, or neither. Thus clients that do not have a SourceManager
cannot specify a SourceLocation.

Modified TextDiagnostics* to use this new interface.
Modified the driver to not passed in SourceManager when warning about "-I-".


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44887 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/TextDiagnosticBuffer.cpp b/Driver/TextDiagnosticBuffer.cpp
index c77801b..f644c3f 100644
--- a/Driver/TextDiagnosticBuffer.cpp
+++ b/Driver/TextDiagnosticBuffer.cpp
@@ -21,7 +21,7 @@
                                             Diagnostic::Level Level,
                                             SourceLocation Pos,
                                             diag::kind ID,
-                                            SourceManager& SrcMgr,
+                                            SourceManager* SrcMgr,
                                             const std::string *Strs,
                                             unsigned NumStrs,
                                             const SourceRange *,
diff --git a/Driver/TextDiagnosticBuffer.h b/Driver/TextDiagnosticBuffer.h
index 5da37c3..53a6cb7 100644
--- a/Driver/TextDiagnosticBuffer.h
+++ b/Driver/TextDiagnosticBuffer.h
@@ -41,7 +41,7 @@
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
                                 diag::kind ID,
-                                SourceManager& SrcMgr,
+                                SourceManager* SrcMgr,
                                 const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
diff --git a/Driver/TextDiagnosticPrinter.cpp b/Driver/TextDiagnosticPrinter.cpp
index d2eaaca..3df1515 100644
--- a/Driver/TextDiagnosticPrinter.cpp
+++ b/Driver/TextDiagnosticPrinter.cpp
@@ -47,24 +47,24 @@
 /// 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,
+                                           SourceManager* SourceMgr,
                                            unsigned LineNo,
                                            std::string &CaratLine,
-                                           const std::string &SourceLine) {
+                                           const std::string &SourceLine) {  
   assert(CaratLine.size() == SourceLine.size() &&
          "Expect a correspondence between source and carat line!");
   if (!R.isValid()) return;
 
-  unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.getBegin());
+  unsigned StartLineNo = SourceMgr->getLogicalLineNumber(R.getBegin());
   if (StartLineNo > LineNo) return;  // No intersection.
   
-  unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.getEnd());
+  unsigned EndLineNo = SourceMgr->getLogicalLineNumber(R.getEnd());
   if (EndLineNo < LineNo) return;  // No intersection.
   
   // Compute the column number of the start.
   unsigned StartColNo = 0;
   if (StartLineNo == LineNo) {
-    StartColNo = SourceMgr.getLogicalColumnNumber(R.getBegin());
+    StartColNo = SourceMgr->getLogicalColumnNumber(R.getBegin());
     if (StartColNo) --StartColNo;  // Zero base the col #.
   }
 
@@ -76,12 +76,12 @@
   // Compute the column number of the end.
   unsigned EndColNo = CaratLine.size();
   if (EndLineNo == LineNo) {
-    EndColNo = SourceMgr.getLogicalColumnNumber(R.getEnd());
+    EndColNo = SourceMgr->getLogicalColumnNumber(R.getEnd());
     if (EndColNo) {
       --EndColNo;  // Zero base the col #.
       
       // Add in the length of the token, so that we cover multi-char tokens.
-      EndColNo += Lexer::MeasureTokenLength(R.getEnd(), SourceMgr);
+      EndColNo += Lexer::MeasureTokenLength(R.getEnd(), *SourceMgr);
     } else {
       EndColNo = CaratLine.size();
     }
@@ -102,7 +102,7 @@
                                              Diagnostic::Level Level, 
                                              SourceLocation Pos,
                                              diag::kind ID,
-                                             SourceManager& SourceMgr,
+                                             SourceManager* SourceMgr,
                                              const std::string *Strs,
                                              unsigned NumStrs,
                                              const SourceRange *Ranges,
@@ -111,25 +111,25 @@
   const char *LineStart = 0, *LineEnd = 0;
   
   if (Pos.isValid()) {
-    SourceLocation LPos = SourceMgr.getLogicalLoc(Pos);
-    LineNo = SourceMgr.getLineNumber(LPos);
+    SourceLocation LPos = SourceMgr->getLogicalLoc(Pos);
+    LineNo = SourceMgr->getLineNumber(LPos);
     
     // First, if this diagnostic is not in the main file, print out the
     // "included from" lines.
-    if (LastWarningLoc != SourceMgr.getIncludeLoc(LPos)) {
-      LastWarningLoc = SourceMgr.getIncludeLoc(LPos);
-      PrintIncludeStack(LastWarningLoc,SourceMgr);
+    if (LastWarningLoc != SourceMgr->getIncludeLoc(LPos)) {
+      LastWarningLoc = SourceMgr->getIncludeLoc(LPos);
+      PrintIncludeStack(LastWarningLoc,*SourceMgr);
     }
   
     // Compute the column number.  Rewind from the current position to the start
     // of the line.
-    ColNo = SourceMgr.getColumnNumber(LPos);
-    const char *TokLogicalPtr = SourceMgr.getCharacterData(LPos);
+    ColNo = SourceMgr->getColumnNumber(LPos);
+    const char *TokLogicalPtr = SourceMgr->getCharacterData(LPos);
     LineStart = TokLogicalPtr-ColNo+1;  // Column # is 1-based
   
     // Compute the line end.  Scan forward from the error position to the end of
     // the line.
-    const llvm::MemoryBuffer *Buffer = SourceMgr.getBuffer(LPos.getFileID());
+    const llvm::MemoryBuffer *Buffer = SourceMgr->getBuffer(LPos.getFileID());
     const char *BufEnd = Buffer->getBufferEnd();
     LineEnd = TokLogicalPtr;
     while (LineEnd != BufEnd && 
diff --git a/Driver/TextDiagnosticPrinter.h b/Driver/TextDiagnosticPrinter.h
index c87c20e..1f0a52c 100644
--- a/Driver/TextDiagnosticPrinter.h
+++ b/Driver/TextDiagnosticPrinter.h
@@ -28,7 +28,7 @@
 
   void PrintIncludeStack(SourceLocation Pos, SourceManager& SrcMgr);
   void HighlightRange(const SourceRange &R,
-                      SourceManager& SrcMgr,
+                      SourceManager* SrcMgr,
                       unsigned LineNo,
                       std::string &CaratLine,
                       const std::string &SourceLine);
@@ -36,7 +36,7 @@
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
                                 diag::kind ID,
-                                SourceManager& SrcMgr,
+                                SourceManager* SrcMgr,
                                 const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
diff --git a/Driver/TextDiagnostics.cpp b/Driver/TextDiagnostics.cpp
index 46e535d..052ea6b 100644
--- a/Driver/TextDiagnostics.cpp
+++ b/Driver/TextDiagnostics.cpp
@@ -41,12 +41,12 @@
 
 bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
                                        SourceLocation Pos,
-                                       SourceManager& SourceMgr) {
+                                       SourceManager* SourceMgr) {
   if (Pos.isValid()) {
     // If this is a warning or note, and if it a system header, suppress the
     // diagnostic.
     if (Level == Diagnostic::Warning || Level == Diagnostic::Note) {
-      if (const FileEntry *F = SourceMgr.getFileEntryForLoc(Pos)) {
+      if (const FileEntry *F = SourceMgr->getFileEntryForLoc(Pos)) {
         DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
         if (DirInfo == DirectoryLookup::SystemHeaderDir ||
             DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
diff --git a/Driver/TextDiagnostics.h b/Driver/TextDiagnostics.h
index ad5e4cb..7741ab9 100644
--- a/Driver/TextDiagnostics.h
+++ b/Driver/TextDiagnostics.h
@@ -36,12 +36,12 @@
 
   virtual bool IgnoreDiagnostic(Diagnostic::Level Level, 
                                 SourceLocation Pos,
-                                SourceManager& SrcMgr);
+                                SourceManager* SrcMgr);
 
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
                                 diag::kind ID,
-                                SourceManager& SrcMgr,
+                                SourceManager* SrcMgr,
                                 const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index c009e06..f9b79d7 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -1026,9 +1026,7 @@
   // -I- is a deprecated GCC feature, scan for it and reject it.
   for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) {
     if (I_dirs[i] == "-") {
-      Diags.Report(SourceLocation(), diag::err_pp_I_dash_not_supported,
-                   SourceMgr);
-      
+      Diags.Report(diag::err_pp_I_dash_not_supported);      
       I_dirs.erase(I_dirs.begin()+i);
       --i;
     }