Author: christof
Date: Mon Jun 19 07:41:22 2017
New Revision: 305688

URL: http://llvm.org/viewvc/llvm-project?rev=305688&view=rev
Log:
Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"

This reverts commit 305684.
This patch breaks extra/tools/clang-tidy

Modified:
    cfe/trunk/include/clang/Basic/SourceLocation.h
    cfe/trunk/include/clang/Frontend/DiagnosticRenderer.h
    cfe/trunk/include/clang/Frontend/TextDiagnostic.h
    cfe/trunk/lib/Basic/SourceLocation.cpp
    cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
    cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
    cfe/trunk/lib/Frontend/TextDiagnostic.cpp
    cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
    cfe/trunk/tools/libclang/CIndexDiagnostic.cpp

Modified: cfe/trunk/include/clang/Basic/SourceLocation.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Mon Jun 19 07:41:22 2017
@@ -262,65 +262,6 @@ public:
   bool isInvalid() const { return !isValid(); }
 };
 
-/// \brief Represents an unpacked "presumed" location which can be presented
-/// to the user.
-///
-/// A 'presumed' location can be modified by \#line and GNU line marker
-/// directives and is always the expansion point of a normal location.
-///
-/// You can get a PresumedLoc from a SourceLocation with SourceManager.
-class PresumedLoc {
-  const char *Filename;
-  unsigned Line, Col;
-  SourceLocation IncludeLoc;
-
-public:
-  PresumedLoc() : Filename(nullptr) {}
-  PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
-      : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {}
-
-  /// \brief Return true if this object is invalid or uninitialized.
-  ///
-  /// This occurs when created with invalid source locations or when walking
-  /// off the top of a \#include stack.
-  bool isInvalid() const { return Filename == nullptr; }
-  bool isValid() const { return Filename != nullptr; }
-
-  /// \brief Return the presumed filename of this location.
-  ///
-  /// This can be affected by \#line etc.
-  const char *getFilename() const {
-    assert(isValid());
-    return Filename;
-  }
-
-  /// \brief Return the presumed line number of this location.
-  ///
-  /// This can be affected by \#line etc.
-  unsigned getLine() const {
-    assert(isValid());
-    return Line;
-  }
-
-  /// \brief Return the presumed column number of this location.
-  ///
-  /// This cannot be affected by \#line, but is packaged here for convenience.
-  unsigned getColumn() const {
-    assert(isValid());
-    return Col;
-  }
-
-  /// \brief Return the presumed include location of this location.
-  ///
-  /// This can be affected by GNU linemarker directives.
-  SourceLocation getIncludeLoc() const {
-    assert(isValid());
-    return IncludeLoc;
-  }
-};
-
-class FileEntry;
-
 /// \brief A SourceLocation and its associated SourceManager.
 ///
 /// This is useful for argument passing to functions that expect both objects.
@@ -333,12 +274,6 @@ public:
   explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
     : SourceLocation(Loc), SrcMgr(&SM) {}
 
-  bool hasManager() const {
-      bool hasSrcMgr =  SrcMgr != nullptr;
-      assert(hasSrcMgr == isValid() && "FullSourceLoc has location but no 
manager");
-      return hasSrcMgr;
-  }
-
   /// \pre This FullSourceLoc has an associated SourceManager.
   const SourceManager &getManager() const {
     assert(SrcMgr && "SourceManager is NULL.");
@@ -349,13 +284,6 @@ public:
 
   FullSourceLoc getExpansionLoc() const;
   FullSourceLoc getSpellingLoc() const;
-  FullSourceLoc getFileLoc() const;
-  std::pair<FullSourceLoc, FullSourceLoc> getImmediateExpansionRange() const;
-  PresumedLoc getPresumedLoc(bool UseLineDirectives = true) const;
-  bool isMacroArgExpansion(FullSourceLoc *StartLoc = nullptr) const;
-  FullSourceLoc getImmediateMacroCallerLoc() const;
-  std::pair<FullSourceLoc, StringRef> getModuleImportLoc() const;
-  unsigned getFileOffset() const;
 
   unsigned getExpansionLineNumber(bool *Invalid = nullptr) const;
   unsigned getExpansionColumnNumber(bool *Invalid = nullptr) const;
@@ -365,12 +293,6 @@ public:
 
   const char *getCharacterData(bool *Invalid = nullptr) const;
 
-  unsigned getLineNumber(bool *Invalid = nullptr) const;
-  unsigned getColumnNumber(bool *Invalid = nullptr) const;
-
-  std::pair<FullSourceLoc, FullSourceLoc> getExpansionRange() const;
-
-  const FileEntry *getFileEntry() const;
 
   /// \brief Return a StringRef to the source buffer data for the
   /// specified FileID.
@@ -423,6 +345,50 @@ public:
 
 };
 
+/// \brief Represents an unpacked "presumed" location which can be presented
+/// to the user.
+///
+/// A 'presumed' location can be modified by \#line and GNU line marker
+/// directives and is always the expansion point of a normal location.
+///
+/// You can get a PresumedLoc from a SourceLocation with SourceManager.
+class PresumedLoc {
+  const char *Filename;
+  unsigned Line, Col;
+  SourceLocation IncludeLoc;
+public:
+  PresumedLoc() : Filename(nullptr) {}
+  PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
+    : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {
+  }
+
+  /// \brief Return true if this object is invalid or uninitialized.
+  ///
+  /// This occurs when created with invalid source locations or when walking
+  /// off the top of a \#include stack.
+  bool isInvalid() const { return Filename == nullptr; }
+  bool isValid() const { return Filename != nullptr; }
+
+  /// \brief Return the presumed filename of this location.
+  ///
+  /// This can be affected by \#line etc.
+  const char *getFilename() const { assert(isValid()); return Filename; }
+
+  /// \brief Return the presumed line number of this location.
+  ///
+  /// This can be affected by \#line etc.
+  unsigned getLine() const { assert(isValid()); return Line; }
+
+  /// \brief Return the presumed column number of this location.
+  ///
+  /// This cannot be affected by \#line, but is packaged here for convenience.
+  unsigned getColumn() const { assert(isValid()); return Col; }
+
+  /// \brief Return the presumed include location of this location.
+  ///
+  /// This can be affected by GNU linemarker directives.
+  SourceLocation getIncludeLoc() const { assert(isValid()); return IncludeLoc; 
}
+};
 
 
 }  // end namespace clang

Modified: cfe/trunk/include/clang/Frontend/DiagnosticRenderer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/DiagnosticRenderer.h?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/DiagnosticRenderer.h (original)
+++ cfe/trunk/include/clang/Frontend/DiagnosticRenderer.h Mon Jun 19 07:41:22 
2017
@@ -70,27 +70,33 @@ protected:
                      DiagnosticOptions *DiagOpts);
   
   virtual ~DiagnosticRenderer();
-
-  virtual void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
+  
+  virtual void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
                                      DiagnosticsEngine::Level Level,
                                      StringRef Message,
                                      ArrayRef<CharSourceRange> Ranges,
+                                     const SourceManager *SM,
                                      DiagOrStoredDiag Info) = 0;
-
-  virtual void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
+  
+  virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
                                  DiagnosticsEngine::Level Level,
-                                 ArrayRef<CharSourceRange> Ranges) = 0;
+                                 ArrayRef<CharSourceRange> Ranges,
+                                 const SourceManager &SM) = 0;
 
-  virtual void emitCodeContext(FullSourceLoc Loc,
+  virtual void emitCodeContext(SourceLocation Loc,
                                DiagnosticsEngine::Level Level,
-                               SmallVectorImpl<CharSourceRange> &Ranges,
-                               ArrayRef<FixItHint> Hints) = 0;
-
-  virtual void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) = 0;
-  virtual void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
-                                  StringRef ModuleName) = 0;
-  virtual void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
-                                          StringRef ModuleName) = 0;
+                               SmallVectorImpl<CharSourceRange>& Ranges,
+                               ArrayRef<FixItHint> Hints,
+                               const SourceManager &SM) = 0;
+  
+  virtual void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc,
+                                   const SourceManager &SM) = 0;
+  virtual void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc,
+                                  StringRef ModuleName,
+                                  const SourceManager &SM) = 0;
+  virtual void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc,
+                                          StringRef ModuleName,
+                                          const SourceManager &SM) = 0;
 
   virtual void beginDiagnostic(DiagOrStoredDiag D,
                                DiagnosticsEngine::Level Level) {}
@@ -100,21 +106,25 @@ protected:
   
 private:
   void emitBasicNote(StringRef Message);
-  void emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc,
-                        DiagnosticsEngine::Level Level);
-  void emitIncludeStackRecursively(FullSourceLoc Loc);
-  void emitImportStack(FullSourceLoc Loc);
-  void emitImportStackRecursively(FullSourceLoc Loc, StringRef ModuleName);
+  void emitIncludeStack(SourceLocation Loc, PresumedLoc PLoc,
+                        DiagnosticsEngine::Level Level, const SourceManager 
&SM);
+  void emitIncludeStackRecursively(SourceLocation Loc, const SourceManager 
&SM);
+  void emitImportStack(SourceLocation Loc, const SourceManager &SM);
+  void emitImportStackRecursively(SourceLocation Loc, StringRef ModuleName,
+                                  const SourceManager &SM);
   void emitModuleBuildStack(const SourceManager &SM);
-  void emitCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
-                 ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints);
-  void emitSingleMacroExpansion(FullSourceLoc Loc,
+  void emitCaret(SourceLocation Loc, DiagnosticsEngine::Level Level,
+                 ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints,
+                 const SourceManager &SM);
+  void emitSingleMacroExpansion(SourceLocation Loc,
                                 DiagnosticsEngine::Level Level,
-                                ArrayRef<CharSourceRange> Ranges);
-  void emitMacroExpansions(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
+                                ArrayRef<CharSourceRange> Ranges,
+                                const SourceManager &SM);
+  void emitMacroExpansions(SourceLocation Loc,
+                           DiagnosticsEngine::Level Level,
                            ArrayRef<CharSourceRange> Ranges,
-                           ArrayRef<FixItHint> Hints);
-
+                           ArrayRef<FixItHint> Hints,
+                           const SourceManager &SM);
 public:
   /// \brief Emit a diagnostic.
   ///
@@ -130,9 +140,10 @@ public:
   /// \param FixItHints The FixIt hints active for this diagnostic.
   /// \param SM The SourceManager; will be null if the diagnostic came from the
   ///        frontend, thus \p Loc will be invalid.
-  void emitDiagnostic(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
+  void emitDiagnostic(SourceLocation Loc, DiagnosticsEngine::Level Level,
                       StringRef Message, ArrayRef<CharSourceRange> Ranges,
                       ArrayRef<FixItHint> FixItHints,
+                      const SourceManager *SM,
                       DiagOrStoredDiag D = (Diagnostic *)nullptr);
 
   void emitStoredDiagnostic(StoredDiagnostic &Diag);
@@ -148,15 +159,19 @@ public:
 
   ~DiagnosticNoteRenderer() override;
 
-  void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
-
-  void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
-                          StringRef ModuleName) override;
+  void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc,
+                           const SourceManager &SM) override;
 
-  void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
-                                  StringRef ModuleName) override;
+  void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc,
+                          StringRef ModuleName,
+                          const SourceManager &SM) override;
+
+  void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc,
+                                  StringRef ModuleName,
+                                  const SourceManager &SM) override;
 
-  virtual void emitNote(FullSourceLoc Loc, StringRef Message) = 0;
+  virtual void emitNote(SourceLocation Loc, StringRef Message,
+                        const SourceManager *SM) = 0;
 };
 } // end clang namespace
 #endif

Modified: cfe/trunk/include/clang/Frontend/TextDiagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TextDiagnostic.h?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/TextDiagnostic.h (original)
+++ cfe/trunk/include/clang/Frontend/TextDiagnostic.h Mon Jun 19 07:41:22 2017
@@ -75,35 +75,44 @@ public:
                                      unsigned Columns, bool ShowColors);
 
 protected:
-  void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
-                             DiagnosticsEngine::Level Level, StringRef Message,
+  void emitDiagnosticMessage(SourceLocation Loc,PresumedLoc PLoc,
+                             DiagnosticsEngine::Level Level,
+                             StringRef Message,
                              ArrayRef<CharSourceRange> Ranges,
+                             const SourceManager *SM,
                              DiagOrStoredDiag D) override;
 
-  void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
+  void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
                          DiagnosticsEngine::Level Level,
-                         ArrayRef<CharSourceRange> Ranges) override;
+                         ArrayRef<CharSourceRange> Ranges,
+                         const SourceManager &SM) override;
 
-  void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
-                       SmallVectorImpl<CharSourceRange> &Ranges,
-                       ArrayRef<FixItHint> Hints) override {
-    emitSnippetAndCaret(Loc, Level, Ranges, Hints);
+  void emitCodeContext(SourceLocation Loc,
+                       DiagnosticsEngine::Level Level,
+                       SmallVectorImpl<CharSourceRange>& Ranges,
+                       ArrayRef<FixItHint> Hints,
+                       const SourceManager &SM) override {
+    emitSnippetAndCaret(Loc, Level, Ranges, Hints, SM);
   }
 
-  void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
+  void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc,
+                           const SourceManager &SM) override;
 
-  void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
-                          StringRef ModuleName) override;
-
-  void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
-                                  StringRef ModuleName) override;
+  void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc,
+                          StringRef ModuleName,
+                          const SourceManager &SM) override;
+
+  void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc,
+                                  StringRef ModuleName,
+                                  const SourceManager &SM) override;
 
 private:
   void emitFilename(StringRef Filename, const SourceManager &SM);
 
-  void emitSnippetAndCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
-                           SmallVectorImpl<CharSourceRange> &Ranges,
-                           ArrayRef<FixItHint> Hints);
+  void emitSnippetAndCaret(SourceLocation Loc, DiagnosticsEngine::Level Level,
+                           SmallVectorImpl<CharSourceRange>& Ranges,
+                           ArrayRef<FixItHint> Hints,
+                           const SourceManager &SM);
 
   void emitSnippet(StringRef SourceLine);
 

Modified: cfe/trunk/lib/Basic/SourceLocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceLocation.cpp?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceLocation.cpp (original)
+++ cfe/trunk/lib/Basic/SourceLocation.cpp Mon Jun 19 07:41:22 2017
@@ -92,76 +92,6 @@ FullSourceLoc FullSourceLoc::getSpelling
   return FullSourceLoc(SrcMgr->getSpellingLoc(*this), *SrcMgr);
 }
 
-FullSourceLoc FullSourceLoc::getFileLoc() const {
-  assert(isValid());
-  return FullSourceLoc(SrcMgr->getFileLoc(*this), *SrcMgr);
-}
-
-std::pair<FullSourceLoc, FullSourceLoc>
-FullSourceLoc::getImmediateExpansionRange() const {
-  assert(isValid());
-  std::pair<SourceLocation, SourceLocation> Range =
-      SrcMgr->getImmediateExpansionRange(*this);
-  return std::make_pair(FullSourceLoc(Range.first, *SrcMgr),
-                        FullSourceLoc(Range.second, *SrcMgr));
-}
-
-PresumedLoc FullSourceLoc::getPresumedLoc(bool UseLineDirectives) const {
-  if (!isValid())
-    return PresumedLoc();
-
-  return SrcMgr->getPresumedLoc(*this, UseLineDirectives);
-}
-
-bool FullSourceLoc::isMacroArgExpansion(FullSourceLoc *StartLoc) const {
-  assert(isValid());
-  return SrcMgr->isMacroArgExpansion(*this, StartLoc);
-}
-
-FullSourceLoc FullSourceLoc::getImmediateMacroCallerLoc() const {
-  assert(isValid());
-  return FullSourceLoc(SrcMgr->getImmediateMacroCallerLoc(*this), *SrcMgr);
-}
-
-std::pair<FullSourceLoc, StringRef> FullSourceLoc::getModuleImportLoc() const {
-  if (!isValid())
-    return std::make_pair(FullSourceLoc(), StringRef());
-
-  std::pair<SourceLocation, StringRef> ImportLoc =
-      SrcMgr->getModuleImportLoc(*this);
-  return std::make_pair(FullSourceLoc(ImportLoc.first, *SrcMgr),
-                        ImportLoc.second);
-}
-
-unsigned FullSourceLoc::getFileOffset() const {
-  assert(isValid());
-  return SrcMgr->getFileOffset(*this);
-}
-
-unsigned FullSourceLoc::getLineNumber(bool *Invalid) const {
-  assert(isValid());
-  return SrcMgr->getLineNumber(getFileID(), getFileOffset(), Invalid);
-}
-
-unsigned FullSourceLoc::getColumnNumber(bool *Invalid) const {
-  assert(isValid());
-  return SrcMgr->getColumnNumber(getFileID(), getFileOffset(), Invalid);
-}
-
-std::pair<FullSourceLoc, FullSourceLoc>
-FullSourceLoc::getExpansionRange() const {
-  assert(isValid());
-  std::pair<SourceLocation, SourceLocation> Range =
-      SrcMgr->getExpansionRange(*this);
-  return std::make_pair(FullSourceLoc(Range.first, *SrcMgr),
-                        FullSourceLoc(Range.second, *SrcMgr));
-}
-
-const FileEntry *FullSourceLoc::getFileEntry() const {
-  assert(isValid());
-  return SrcMgr->getFileEntryForID(getFileID());
-}
-
 unsigned FullSourceLoc::getExpansionLineNumber(bool *Invalid) const {
   assert(isValid());
   return SrcMgr->getExpansionLineNumber(*this, Invalid);

Modified: cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp (original)
+++ cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp Mon Jun 19 07:41:22 2017
@@ -76,19 +76,20 @@ static void mergeFixits(ArrayRef<FixItHi
   }
 }
 
-void DiagnosticRenderer::emitDiagnostic(FullSourceLoc Loc,
+void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc,
                                         DiagnosticsEngine::Level Level,
                                         StringRef Message,
                                         ArrayRef<CharSourceRange> Ranges,
                                         ArrayRef<FixItHint> FixItHints,
+                                        const SourceManager *SM,
                                         DiagOrStoredDiag D) {
-  assert(Loc.hasManager() || Loc.isInvalid());
+  assert(SM || Loc.isInvalid());
 
   beginDiagnostic(D, Level);
 
   if (!Loc.isValid())
     // If we have no source location, just emit the diagnostic message.
-    emitDiagnosticMessage(Loc, PresumedLoc(), Level, Message, Ranges, D);
+    emitDiagnosticMessage(Loc, PresumedLoc(), Level, Message, Ranges, SM, D);
   else {
     // Get the ranges into a local array we can hack on.
     SmallVector<CharSourceRange, 20> MutableRanges(Ranges.begin(),
@@ -96,7 +97,7 @@ void DiagnosticRenderer::emitDiagnostic(
 
     SmallVector<FixItHint, 8> MergedFixits;
     if (!FixItHints.empty()) {
-      mergeFixits(FixItHints, Loc.getManager(), LangOpts, MergedFixits);
+      mergeFixits(FixItHints, *SM, LangOpts, MergedFixits);
       FixItHints = MergedFixits;
     }
 
@@ -106,25 +107,25 @@ void DiagnosticRenderer::emitDiagnostic(
       if (I->RemoveRange.isValid())
         MutableRanges.push_back(I->RemoveRange);
 
-    FullSourceLoc UnexpandedLoc = Loc;
+    SourceLocation UnexpandedLoc = Loc;
 
     // Find the ultimate expansion location for the diagnostic.
-    Loc = Loc.getFileLoc();
+    Loc = SM->getFileLoc(Loc);
 
-    PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc);
+    PresumedLoc PLoc = SM->getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc);
 
     // First, if this diagnostic is not in the main file, print out the
     // "included from" lines.
-    emitIncludeStack(Loc, PLoc, Level);
+    emitIncludeStack(Loc, PLoc, Level, *SM);
 
     // Next, emit the actual diagnostic message and caret.
-    emitDiagnosticMessage(Loc, PLoc, Level, Message, Ranges, D);
-    emitCaret(Loc, Level, MutableRanges, FixItHints);
+    emitDiagnosticMessage(Loc, PLoc, Level, Message, Ranges, SM, D);
+    emitCaret(Loc, Level, MutableRanges, FixItHints, *SM);
 
     // If this location is within a macro, walk from UnexpandedLoc up to Loc
     // and produce a macro backtrace.
     if (UnexpandedLoc.isValid() && UnexpandedLoc.isMacroID()) {
-      emitMacroExpansions(UnexpandedLoc, Level, MutableRanges, FixItHints);
+      emitMacroExpansions(UnexpandedLoc, Level, MutableRanges, FixItHints, 
*SM);
     }
   }
 
@@ -138,12 +139,15 @@ void DiagnosticRenderer::emitDiagnostic(
 void DiagnosticRenderer::emitStoredDiagnostic(StoredDiagnostic &Diag) {
   emitDiagnostic(Diag.getLocation(), Diag.getLevel(), Diag.getMessage(),
                  Diag.getRanges(), Diag.getFixIts(),
+                 Diag.getLocation().isValid() ? 
&Diag.getLocation().getManager()
+                                              : nullptr,
                  &Diag);
 }
 
 void DiagnosticRenderer::emitBasicNote(StringRef Message) {
-  emitDiagnosticMessage(FullSourceLoc(), PresumedLoc(), 
DiagnosticsEngine::Note,
-                        Message, None, DiagOrStoredDiag());
+  emitDiagnosticMessage(
+      SourceLocation(), PresumedLoc(), DiagnosticsEngine::Note, Message,
+      None, nullptr, DiagOrStoredDiag());
 }
 
 /// \brief Prints an include stack when appropriate for a particular
@@ -157,11 +161,12 @@ void DiagnosticRenderer::emitBasicNote(S
 /// \param Loc   The diagnostic location.
 /// \param PLoc  The presumed location of the diagnostic location.
 /// \param Level The diagnostic level of the message this stack pertains to.
-void DiagnosticRenderer::emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc,
-                                          DiagnosticsEngine::Level Level) {
-  FullSourceLoc IncludeLoc =
-      PLoc.isInvalid() ? FullSourceLoc()
-                       : FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
+void DiagnosticRenderer::emitIncludeStack(SourceLocation Loc,
+                                          PresumedLoc PLoc,
+                                          DiagnosticsEngine::Level Level,
+                                          const SourceManager &SM) {
+  SourceLocation IncludeLoc =
+      PLoc.isInvalid() ? SourceLocation() : PLoc.getIncludeLoc();
 
   // Skip redundant include stacks altogether.
   if (LastIncludeLoc == IncludeLoc)
@@ -173,70 +178,74 @@ void DiagnosticRenderer::emitIncludeStac
     return;
 
   if (IncludeLoc.isValid())
-    emitIncludeStackRecursively(IncludeLoc);
+    emitIncludeStackRecursively(IncludeLoc, SM);
   else {
-    emitModuleBuildStack(Loc.getManager());
-    emitImportStack(Loc);
+    emitModuleBuildStack(SM);
+    emitImportStack(Loc, SM);
   }
 }
 
 /// \brief Helper to recursivly walk up the include stack and print each layer
 /// on the way back down.
-void DiagnosticRenderer::emitIncludeStackRecursively(FullSourceLoc Loc) {
+void DiagnosticRenderer::emitIncludeStackRecursively(SourceLocation Loc,
+                                                     const SourceManager &SM) {
   if (Loc.isInvalid()) {
-    emitModuleBuildStack(Loc.getManager());
+    emitModuleBuildStack(SM);
     return;
   }
-
-  PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc);
+  
+  PresumedLoc PLoc = SM.getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc);
   if (PLoc.isInvalid())
     return;
 
   // If this source location was imported from a module, print the module
   // import stack rather than the 
   // FIXME: We want submodule granularity here.
-  std::pair<FullSourceLoc, StringRef> Imported = Loc.getModuleImportLoc();
+  std::pair<SourceLocation, StringRef> Imported = SM.getModuleImportLoc(Loc);
   if (!Imported.second.empty()) {
     // This location was imported by a module. Emit the module import stack.
-    emitImportStackRecursively(Imported.first, Imported.second);
+    emitImportStackRecursively(Imported.first, Imported.second, SM);
     return;
   }
 
   // Emit the other include frames first.
-  emitIncludeStackRecursively(
-      FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager()));
-
+  emitIncludeStackRecursively(PLoc.getIncludeLoc(), SM);
+  
   // Emit the inclusion text/note.
-  emitIncludeLocation(Loc, PLoc);
+  emitIncludeLocation(Loc, PLoc, SM);
 }
 
 /// \brief Emit the module import stack associated with the current location.
-void DiagnosticRenderer::emitImportStack(FullSourceLoc Loc) {
+void DiagnosticRenderer::emitImportStack(SourceLocation Loc,
+                                         const SourceManager &SM) {
   if (Loc.isInvalid()) {
-    emitModuleBuildStack(Loc.getManager());
+    emitModuleBuildStack(SM);
     return;
   }
 
-  std::pair<FullSourceLoc, StringRef> NextImportLoc = Loc.getModuleImportLoc();
-  emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second);
+  std::pair<SourceLocation, StringRef> NextImportLoc
+    = SM.getModuleImportLoc(Loc);
+  emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second, SM);
 }
 
 /// \brief Helper to recursivly walk up the import stack and print each layer
 /// on the way back down.
-void DiagnosticRenderer::emitImportStackRecursively(FullSourceLoc Loc,
-                                                    StringRef ModuleName) {
+void DiagnosticRenderer::emitImportStackRecursively(SourceLocation Loc,
+                                                    StringRef ModuleName,
+                                                    const SourceManager &SM) {
   if (ModuleName.empty()) {
     return;
   }
 
-  PresumedLoc PLoc = Loc.getPresumedLoc(DiagOpts->ShowPresumedLoc);
+  PresumedLoc PLoc = SM.getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc);
 
   // Emit the other import frames first.
-  std::pair<FullSourceLoc, StringRef> NextImportLoc = Loc.getModuleImportLoc();
-  emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second);
+  std::pair<SourceLocation, StringRef> NextImportLoc
+    = SM.getModuleImportLoc(Loc);
+  emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second, SM);
 
   // Emit the inclusion text/note.
-  emitImportLocation(Loc, PLoc, ModuleName);
+  emitImportLocation(Loc, PLoc, ModuleName, SM);
 }
 
 /// \brief Emit the module build stack, for cases where a module is (re-)built
@@ -244,9 +253,13 @@ void DiagnosticRenderer::emitImportStack
 void DiagnosticRenderer::emitModuleBuildStack(const SourceManager &SM) {
   ModuleBuildStack Stack = SM.getModuleBuildStack();
   for (unsigned I = 0, N = Stack.size(); I != N; ++I) {
-    emitBuildingModuleLocation(Stack[I].second, Stack[I].second.getPresumedLoc(
+    const SourceManager &CurSM = Stack[I].second.getManager();
+    SourceLocation CurLoc = Stack[I].second;
+    emitBuildingModuleLocation(CurLoc,
+                               CurSM.getPresumedLoc(CurLoc,
                                                     DiagOpts->ShowPresumedLoc),
-                               Stack[I].first);
+                               Stack[I].first,
+                               CurSM);
   }
 }
 
@@ -335,12 +348,12 @@ static void computeCommonMacroArgExpansi
 // in the same expansion as the caret; otherwise, we crawl to the top of
 // each chain. Two locations are part of the same macro expansion
 // iff the FileID is the same.
-static void
-mapDiagnosticRanges(FullSourceLoc CaretLoc, ArrayRef<CharSourceRange> Ranges,
-                    SmallVectorImpl<CharSourceRange> &SpellingRanges) {
-  FileID CaretLocFileID = CaretLoc.getFileID();
-
-  const SourceManager *SM = &CaretLoc.getManager();
+static void mapDiagnosticRanges(
+    SourceLocation CaretLoc,
+    ArrayRef<CharSourceRange> Ranges,
+    SmallVectorImpl<CharSourceRange> &SpellingRanges,
+    const SourceManager *SM) {
+  FileID CaretLocFileID = SM->getFileID(CaretLoc);
 
   for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) {
     if (I->isInvalid()) continue;
@@ -391,39 +404,42 @@ mapDiagnosticRanges(FullSourceLoc CaretL
   }
 }
 
-void DiagnosticRenderer::emitCaret(FullSourceLoc Loc,
+void DiagnosticRenderer::emitCaret(SourceLocation Loc,
                                    DiagnosticsEngine::Level Level,
                                    ArrayRef<CharSourceRange> Ranges,
-                                   ArrayRef<FixItHint> Hints) {
+                                   ArrayRef<FixItHint> Hints,
+                                   const SourceManager &SM) {
   SmallVector<CharSourceRange, 4> SpellingRanges;
-  mapDiagnosticRanges(Loc, Ranges, SpellingRanges);
-  emitCodeContext(Loc, Level, SpellingRanges, Hints);
+  mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM);
+  emitCodeContext(Loc, Level, SpellingRanges, Hints, SM);
 }
 
 /// \brief A helper function for emitMacroExpansion to print the
 /// macro expansion message
 void DiagnosticRenderer::emitSingleMacroExpansion(
-    FullSourceLoc Loc, DiagnosticsEngine::Level Level,
-    ArrayRef<CharSourceRange> Ranges) {
+    SourceLocation Loc,
+    DiagnosticsEngine::Level Level,
+    ArrayRef<CharSourceRange> Ranges,
+    const SourceManager &SM) {
   // Find the spelling location for the macro definition. We must use the
   // spelling location here to avoid emitting a macro backtrace for the note.
-  FullSourceLoc SpellingLoc = Loc.getSpellingLoc();
+  SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
 
   // Map the ranges into the FileID of the diagnostic location.
   SmallVector<CharSourceRange, 4> SpellingRanges;
-  mapDiagnosticRanges(Loc, Ranges, SpellingRanges);
+  mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM);
 
   SmallString<100> MessageStorage;
   llvm::raw_svector_ostream Message(MessageStorage);
-  StringRef MacroName = Lexer::getImmediateMacroNameForDiagnostics(
-      Loc, Loc.getManager(), LangOpts);
+  StringRef MacroName =
+      Lexer::getImmediateMacroNameForDiagnostics(Loc, SM, LangOpts);
   if (MacroName.empty())
     Message << "expanded from here";
   else
     Message << "expanded from macro '" << MacroName << "'";
 
   emitDiagnostic(SpellingLoc, DiagnosticsEngine::Note, Message.str(),
-                 SpellingRanges, None);
+                 SpellingRanges, None, &SM);
 }
 
 /// Check that the macro argument location of Loc starts with ArgumentLoc.
@@ -457,12 +473,13 @@ static bool checkRangeForMacroArgExpansi
 
 /// A helper function to check if the current ranges are all inside the same
 /// macro argument expansion as Loc.
-static bool checkRangesForMacroArgExpansion(FullSourceLoc Loc,
-                                            ArrayRef<CharSourceRange> Ranges) {
+static bool checkRangesForMacroArgExpansion(SourceLocation Loc,
+                                            ArrayRef<CharSourceRange> Ranges,
+                                            const SourceManager &SM) {
   assert(Loc.isMacroID() && "Must be a macro expansion!");
 
   SmallVector<CharSourceRange, 4> SpellingRanges;
-  mapDiagnosticRanges(Loc, Ranges, SpellingRanges);
+  mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM);
 
   /// Count all valid ranges.
   unsigned ValidCount = 0;
@@ -473,15 +490,15 @@ static bool checkRangesForMacroArgExpans
     return false;
 
   /// To store the source location of the argument location.
-  FullSourceLoc ArgumentLoc;
+  SourceLocation ArgumentLoc;
 
   /// Set the ArgumentLoc to the beginning location of the expansion of Loc
   /// so to check if the ranges expands to the same beginning location.
-  if (!Loc.isMacroArgExpansion(&ArgumentLoc))
+  if (!SM.isMacroArgExpansion(Loc,&ArgumentLoc))
     return false;
 
   for (auto I = SpellingRanges.begin(), E = SpellingRanges.end(); I != E; ++I) 
{
-    if (!checkRangeForMacroArgExpansion(*I, Loc.getManager(), ArgumentLoc))
+    if (!checkRangeForMacroArgExpansion(*I, SM, ArgumentLoc))
       return false;
   }
 
@@ -499,33 +516,34 @@ static bool checkRangesForMacroArgExpans
 /// \param Level The diagnostic level currently being emitted.
 /// \param Ranges The underlined ranges for this code snippet.
 /// \param Hints The FixIt hints active for this diagnostic.
-void DiagnosticRenderer::emitMacroExpansions(FullSourceLoc Loc,
+void DiagnosticRenderer::emitMacroExpansions(SourceLocation Loc,
                                              DiagnosticsEngine::Level Level,
                                              ArrayRef<CharSourceRange> Ranges,
-                                             ArrayRef<FixItHint> Hints) {
+                                             ArrayRef<FixItHint> Hints,
+                                             const SourceManager &SM) {
   assert(Loc.isValid() && "must have a valid source location here");
 
   // Produce a stack of macro backtraces.
-  SmallVector<FullSourceLoc, 8> LocationStack;
+  SmallVector<SourceLocation, 8> LocationStack;
   unsigned IgnoredEnd = 0;
   while (Loc.isMacroID()) {
     // If this is the expansion of a macro argument, point the caret at the
     // use of the argument in the definition of the macro, not the expansion.
-    if (Loc.isMacroArgExpansion())
-      LocationStack.push_back(Loc.getImmediateExpansionRange().first);
+    if (SM.isMacroArgExpansion(Loc))
+      LocationStack.push_back(SM.getImmediateExpansionRange(Loc).first);
     else
       LocationStack.push_back(Loc);
 
-    if (checkRangesForMacroArgExpansion(Loc, Ranges))
+    if (checkRangesForMacroArgExpansion(Loc, Ranges, SM))
       IgnoredEnd = LocationStack.size();
 
-    Loc = Loc.getImmediateMacroCallerLoc();
+    Loc = SM.getImmediateMacroCallerLoc(Loc);
 
     // Once the location no longer points into a macro, try stepping through
     // the last found location.  This sometimes produces additional useful
     // backtraces.
     if (Loc.isFileID())
-      Loc = LocationStack.back().getImmediateMacroCallerLoc();
+      Loc = SM.getImmediateMacroCallerLoc(LocationStack.back());
     assert(Loc.isValid() && "must have a valid source location here");
   }
 
@@ -537,7 +555,7 @@ void DiagnosticRenderer::emitMacroExpans
   if (MacroDepth <= MacroLimit || MacroLimit == 0) {
     for (auto I = LocationStack.rbegin(), E = LocationStack.rend();
          I != E; ++I)
-      emitSingleMacroExpansion(*I, Level, Ranges);
+      emitSingleMacroExpansion(*I, Level, Ranges, SM);
     return;
   }
 
@@ -547,7 +565,7 @@ void DiagnosticRenderer::emitMacroExpans
   for (auto I = LocationStack.rbegin(),
             E = LocationStack.rbegin() + MacroStartMessages;
        I != E; ++I)
-    emitSingleMacroExpansion(*I, Level, Ranges);
+    emitSingleMacroExpansion(*I, Level, Ranges, SM);
 
   SmallString<200> MessageStorage;
   llvm::raw_svector_ostream Message(MessageStorage);
@@ -559,24 +577,26 @@ void DiagnosticRenderer::emitMacroExpans
   for (auto I = LocationStack.rend() - MacroEndMessages,
             E = LocationStack.rend();
        I != E; ++I)
-    emitSingleMacroExpansion(*I, Level, Ranges);
+    emitSingleMacroExpansion(*I, Level, Ranges, SM);
 }
 
 DiagnosticNoteRenderer::~DiagnosticNoteRenderer() {}
 
-void DiagnosticNoteRenderer::emitIncludeLocation(FullSourceLoc Loc,
-                                                 PresumedLoc PLoc) {
+void DiagnosticNoteRenderer::emitIncludeLocation(SourceLocation Loc,
+                                                 PresumedLoc PLoc,
+                                                 const SourceManager &SM) {
   // Generate a note indicating the include location.
   SmallString<200> MessageStorage;
   llvm::raw_svector_ostream Message(MessageStorage);
   Message << "in file included from " << PLoc.getFilename() << ':'
           << PLoc.getLine() << ":";
-  emitNote(Loc, Message.str());
+  emitNote(Loc, Message.str(), &SM);
 }
 
-void DiagnosticNoteRenderer::emitImportLocation(FullSourceLoc Loc,
+void DiagnosticNoteRenderer::emitImportLocation(SourceLocation Loc,
                                                 PresumedLoc PLoc,
-                                                StringRef ModuleName) {
+                                                StringRef ModuleName,
+                                                const SourceManager &SM) {
   // Generate a note indicating the include location.
   SmallString<200> MessageStorage;
   llvm::raw_svector_ostream Message(MessageStorage);
@@ -585,12 +605,14 @@ void DiagnosticNoteRenderer::emitImportL
     Message << "' imported from " << PLoc.getFilename() << ':'
             << PLoc.getLine();
   Message << ":";
-  emitNote(Loc, Message.str());
+  emitNote(Loc, Message.str(), &SM);
 }
 
-void DiagnosticNoteRenderer::emitBuildingModuleLocation(FullSourceLoc Loc,
-                                                        PresumedLoc PLoc,
-                                                        StringRef ModuleName) {
+void
+DiagnosticNoteRenderer::emitBuildingModuleLocation(SourceLocation Loc,
+                                                   PresumedLoc PLoc,
+                                                   StringRef ModuleName,
+                                                   const SourceManager &SM) {
   // Generate a note indicating the include location.
   SmallString<200> MessageStorage;
   llvm::raw_svector_ostream Message(MessageStorage);
@@ -599,5 +621,5 @@ void DiagnosticNoteRenderer::emitBuildin
             << PLoc.getFilename() << ':' << PLoc.getLine() << ":";
   else
     Message << "while building module '" << ModuleName << "':";
-  emitNote(Loc, Message.str());
+  emitNote(Loc, Message.str(), &SM);
 }

Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp Mon Jun 19 07:41:22 
2017
@@ -63,20 +63,27 @@ public:
   ~SDiagsRenderer() override {}
 
 protected:
-  void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
-                             DiagnosticsEngine::Level Level, StringRef Message,
+  void emitDiagnosticMessage(SourceLocation Loc,
+                             PresumedLoc PLoc,
+                             DiagnosticsEngine::Level Level,
+                             StringRef Message,
                              ArrayRef<CharSourceRange> Ranges,
+                             const SourceManager *SM,
                              DiagOrStoredDiag D) override;
 
-  void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
+  void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
                          DiagnosticsEngine::Level Level,
-                         ArrayRef<CharSourceRange> Ranges) override {}
+                         ArrayRef<CharSourceRange> Ranges,
+                         const SourceManager &SM) override {}
 
-  void emitNote(FullSourceLoc Loc, StringRef Message) override;
+  void emitNote(SourceLocation Loc, StringRef Message,
+                const SourceManager *SM) override;
 
-  void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
-                       SmallVectorImpl<CharSourceRange> &Ranges,
-                       ArrayRef<FixItHint> Hints) override;
+  void emitCodeContext(SourceLocation Loc,
+                       DiagnosticsEngine::Level Level,
+                       SmallVectorImpl<CharSourceRange>& Ranges,
+                       ArrayRef<FixItHint> Hints,
+                       const SourceManager &SM) override;
 
   void beginDiagnostic(DiagOrStoredDiag D,
                        DiagnosticsEngine::Level Level) override;
@@ -186,8 +193,11 @@ private:
   void ExitDiagBlock();
 
   /// \brief Emit a DIAG record.
-  void EmitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
-                             DiagnosticsEngine::Level Level, StringRef Message,
+  void EmitDiagnosticMessage(SourceLocation Loc,
+                             PresumedLoc PLoc,
+                             DiagnosticsEngine::Level Level,
+                             StringRef Message,
+                             const SourceManager *SM,
                              DiagOrStoredDiag D);
 
   /// \brief Emit FIXIT and SOURCE_RANGE records for a diagnostic.
@@ -210,14 +220,16 @@ private:
   /// \brief Emit (lazily) the file string and retrieved the file identifier.
   unsigned getEmitFile(const char *Filename);
 
-  /// \brief Add SourceLocation information the specified record.
-  void AddLocToRecord(FullSourceLoc Loc, PresumedLoc PLoc,
-                      RecordDataImpl &Record, unsigned TokSize = 0);
+  /// \brief Add SourceLocation information the specified record.  
+  void AddLocToRecord(SourceLocation Loc, const SourceManager *SM,
+                      PresumedLoc PLoc, RecordDataImpl &Record,
+                      unsigned TokSize = 0);
 
   /// \brief Add SourceLocation information the specified record.
-  void AddLocToRecord(FullSourceLoc Loc, RecordDataImpl &Record,
+  void AddLocToRecord(SourceLocation Loc, RecordDataImpl &Record,
+                      const SourceManager *SM,
                       unsigned TokSize = 0) {
-    AddLocToRecord(Loc, Loc.hasManager() ? Loc.getPresumedLoc() : 
PresumedLoc(),
+    AddLocToRecord(Loc, SM, SM ? SM->getPresumedLoc(Loc) : PresumedLoc(),
                    Record, TokSize);
   }
 
@@ -338,8 +350,11 @@ static void EmitRecordID(unsigned ID, co
   Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
 }
 
-void SDiagsWriter::AddLocToRecord(FullSourceLoc Loc, PresumedLoc PLoc,
-                                  RecordDataImpl &Record, unsigned TokSize) {
+void SDiagsWriter::AddLocToRecord(SourceLocation Loc,
+                                  const SourceManager *SM,
+                                  PresumedLoc PLoc,
+                                  RecordDataImpl &Record,
+                                  unsigned TokSize) {
   if (PLoc.isInvalid()) {
     // Emit a "sentinel" location.
     Record.push_back((unsigned)0); // File.
@@ -352,19 +367,19 @@ void SDiagsWriter::AddLocToRecord(FullSo
   Record.push_back(getEmitFile(PLoc.getFilename()));
   Record.push_back(PLoc.getLine());
   Record.push_back(PLoc.getColumn()+TokSize);
-  Record.push_back(Loc.getFileOffset());
+  Record.push_back(SM->getFileOffset(Loc));
 }
 
 void SDiagsWriter::AddCharSourceRangeToRecord(CharSourceRange Range,
                                               RecordDataImpl &Record,
                                               const SourceManager &SM) {
-  AddLocToRecord(FullSourceLoc(Range.getBegin(), SM), Record);
+  AddLocToRecord(Range.getBegin(), Record, &SM);
   unsigned TokSize = 0;
   if (Range.isTokenRange())
     TokSize = Lexer::MeasureTokenLength(Range.getEnd(),
                                         SM, *LangOpts);
-
-  AddLocToRecord(FullSourceLoc(Range.getEnd(), SM), Record, TokSize);
+  
+  AddLocToRecord(Range.getEnd(), Record, &SM, TokSize);
 }
 
 unsigned SDiagsWriter::getEmitFile(const char *FileName){
@@ -591,8 +606,8 @@ void SDiagsWriter::HandleDiagnostic(Diag
     if (DiagLevel == DiagnosticsEngine::Note)
       EnterDiagBlock();
 
-    EmitDiagnosticMessage(FullSourceLoc(), PresumedLoc(), DiagLevel,
-                          State->diagBuf, &Info);
+    EmitDiagnosticMessage(SourceLocation(), PresumedLoc(), DiagLevel,
+                          State->diagBuf, nullptr, &Info);
 
     if (DiagLevel == DiagnosticsEngine::Note)
       ExitDiagBlock();
@@ -603,9 +618,12 @@ void SDiagsWriter::HandleDiagnostic(Diag
   assert(Info.hasSourceManager() && LangOpts &&
          "Unexpected diagnostic with valid location outside of a source file");
   SDiagsRenderer Renderer(*this, *LangOpts, &*State->DiagOpts);
-  Renderer.emitDiagnostic(
-      FullSourceLoc(Info.getLocation(), Info.getSourceManager()), DiagLevel,
-      State->diagBuf, Info.getRanges(), Info.getFixItHints(), &Info);
+  Renderer.emitDiagnostic(Info.getLocation(), DiagLevel,
+                          State->diagBuf,
+                          Info.getRanges(),
+                          Info.getFixItHints(),
+                          &Info.getSourceManager(),
+                          &Info);
 }
 
 static serialized_diags::Level getStableLevel(DiagnosticsEngine::Level Level) {
@@ -623,9 +641,11 @@ static serialized_diags::Level getStable
   llvm_unreachable("invalid diagnostic level");
 }
 
-void SDiagsWriter::EmitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
+void SDiagsWriter::EmitDiagnosticMessage(SourceLocation Loc,
+                                         PresumedLoc PLoc,
                                          DiagnosticsEngine::Level Level,
                                          StringRef Message,
+                                         const SourceManager *SM,
                                          DiagOrStoredDiag D) {
   llvm::BitstreamWriter &Stream = State->Stream;
   RecordData &Record = State->Record;
@@ -635,7 +655,7 @@ void SDiagsWriter::EmitDiagnosticMessage
   Record.clear();
   Record.push_back(RECORD_DIAG);
   Record.push_back(getStableLevel(Level));
-  AddLocToRecord(Loc, PLoc, Record);
+  AddLocToRecord(Loc, SM, PLoc, Record);
 
   if (const Diagnostic *Info = D.dyn_cast<const Diagnostic*>()) {
     // Emit the category string lazily and get the category ID.
@@ -652,11 +672,15 @@ void SDiagsWriter::EmitDiagnosticMessage
   Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_DIAG), Record, Message);
 }
 
-void SDiagsRenderer::emitDiagnosticMessage(
-    FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level,
-    StringRef Message, ArrayRef<clang::CharSourceRange> Ranges,
-    DiagOrStoredDiag D) {
-  Writer.EmitDiagnosticMessage(Loc, PLoc, Level, Message, D);
+void
+SDiagsRenderer::emitDiagnosticMessage(SourceLocation Loc,
+                                      PresumedLoc PLoc,
+                                      DiagnosticsEngine::Level Level,
+                                      StringRef Message,
+                                      ArrayRef<clang::CharSourceRange> Ranges,
+                                      const SourceManager *SM,
+                                      DiagOrStoredDiag D) {
+  Writer.EmitDiagnosticMessage(Loc, PLoc, Level, Message, SM, D);
 }
 
 void SDiagsWriter::EnterDiagBlock() {
@@ -709,18 +733,20 @@ void SDiagsWriter::EmitCodeContext(Small
   }
 }
 
-void SDiagsRenderer::emitCodeContext(FullSourceLoc Loc,
+void SDiagsRenderer::emitCodeContext(SourceLocation Loc,
                                      DiagnosticsEngine::Level Level,
                                      SmallVectorImpl<CharSourceRange> &Ranges,
-                                     ArrayRef<FixItHint> Hints) {
-  Writer.EmitCodeContext(Ranges, Hints, Loc.getManager());
+                                     ArrayRef<FixItHint> Hints,
+                                     const SourceManager &SM) {
+  Writer.EmitCodeContext(Ranges, Hints, SM);
 }
 
-void SDiagsRenderer::emitNote(FullSourceLoc Loc, StringRef Message) {
+void SDiagsRenderer::emitNote(SourceLocation Loc, StringRef Message,
+                              const SourceManager *SM) {
   Writer.EnterDiagBlock();
-  PresumedLoc PLoc = Loc.hasManager() ? Loc.getPresumedLoc() : PresumedLoc();
-  Writer.EmitDiagnosticMessage(Loc, PLoc, DiagnosticsEngine::Note, Message,
-                               DiagOrStoredDiag());
+  PresumedLoc PLoc = SM ? SM->getPresumedLoc(Loc) : PresumedLoc();
+  Writer.EmitDiagnosticMessage(Loc, PLoc, DiagnosticsEngine::Note,
+                               Message, SM, DiagOrStoredDiag());
   Writer.ExitDiagBlock();
 }
 

Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Mon Jun 19 07:41:22 2017
@@ -672,16 +672,20 @@ TextDiagnostic::TextDiagnostic(raw_ostre
 
 TextDiagnostic::~TextDiagnostic() {}
 
-void TextDiagnostic::emitDiagnosticMessage(
-    FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level,
-    StringRef Message, ArrayRef<clang::CharSourceRange> Ranges,
-    DiagOrStoredDiag D) {
+void
+TextDiagnostic::emitDiagnosticMessage(SourceLocation Loc,
+                                      PresumedLoc PLoc,
+                                      DiagnosticsEngine::Level Level,
+                                      StringRef Message,
+                                      ArrayRef<clang::CharSourceRange> Ranges,
+                                      const SourceManager *SM,
+                                      DiagOrStoredDiag D) {
   uint64_t StartOfLocationInfo = OS.tell();
 
   // Emit the location of this particular diagnostic.
   if (Loc.isValid())
-    emitDiagnosticLoc(Loc, PLoc, Level, Ranges);
-
+    emitDiagnosticLoc(Loc, PLoc, Level, Ranges, *SM);
+  
   if (DiagOpts->ShowColors)
     OS.resetColor();
   
@@ -783,16 +787,17 @@ void TextDiagnostic::emitFilename(String
 /// This includes extracting as much location information as is present for
 /// the diagnostic and printing it, as well as any include stack or source
 /// ranges necessary.
-void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
+void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
                                        DiagnosticsEngine::Level Level,
-                                       ArrayRef<CharSourceRange> Ranges) {
+                                       ArrayRef<CharSourceRange> Ranges,
+                                       const SourceManager &SM) {
   if (PLoc.isInvalid()) {
     // At least print the file name if available:
-    FileID FID = Loc.getFileID();
+    FileID FID = SM.getFileID(Loc);
     if (FID.isValid()) {
-      const FileEntry *FE = Loc.getFileEntry();
+      const FileEntry* FE = SM.getFileEntryForID(FID);
       if (FE && FE->isValid()) {
-        emitFilename(FE->getName(), Loc.getManager());
+        emitFilename(FE->getName(), SM);
         if (FE->isInPCH())
           OS << " (in PCH)";
         OS << ": ";
@@ -808,7 +813,7 @@ void TextDiagnostic::emitDiagnosticLoc(F
   if (DiagOpts->ShowColors)
     OS.changeColor(savedColor, true);
 
-  emitFilename(PLoc.getFilename(), Loc.getManager());
+  emitFilename(PLoc.getFilename(), SM);
   switch (DiagOpts->getFormat()) {
   case DiagnosticOptions::Clang: OS << ':'  << LineNo; break;
   case DiagnosticOptions::MSVC:  OS << '('  << LineNo; break;
@@ -843,7 +848,8 @@ void TextDiagnostic::emitDiagnosticLoc(F
   }
 
   if (DiagOpts->ShowSourceRanges && !Ranges.empty()) {
-    FileID CaretFileID = Loc.getExpansionLoc().getFileID();
+    FileID CaretFileID =
+      SM.getFileID(SM.getExpansionLoc(Loc));
     bool PrintedRange = false;
 
     for (ArrayRef<CharSourceRange>::const_iterator RI = Ranges.begin(),
@@ -852,10 +858,8 @@ void TextDiagnostic::emitDiagnosticLoc(F
       // Ignore invalid ranges.
       if (!RI->isValid()) continue;
 
-      FullSourceLoc B =
-          FullSourceLoc(RI->getBegin(), Loc.getManager()).getExpansionLoc();
-      FullSourceLoc E =
-          FullSourceLoc(RI->getEnd(), Loc.getManager()).getExpansionLoc();
+      SourceLocation B = SM.getExpansionLoc(RI->getBegin());
+      SourceLocation E = SM.getExpansionLoc(RI->getEnd());
 
       // If the End location and the start location are the same and are a
       // macro location, then the range was something that came from a
@@ -863,12 +867,10 @@ void TextDiagnostic::emitDiagnosticLoc(F
       // best we can do is to highlight the range.  If this is a
       // function-like macro, we'd also like to highlight the arguments.
       if (B == E && RI->getEnd().isMacroID())
-        E = FullSourceLoc(RI->getEnd(), Loc.getManager())
-                .getExpansionRange()
-                .second;
+        E = SM.getExpansionRange(RI->getEnd()).second;
 
-      std::pair<FileID, unsigned> BInfo = B.getDecomposedLoc();
-      std::pair<FileID, unsigned> EInfo = E.getDecomposedLoc();
+      std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B);
+      std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E);
 
       // If the start or end of the range is in another file, just discard
       // it.
@@ -879,10 +881,13 @@ void TextDiagnostic::emitDiagnosticLoc(F
       // tokens.
       unsigned TokSize = 0;
       if (RI->isTokenRange())
-        TokSize = Lexer::MeasureTokenLength(E, E.getManager(), LangOpts);
+        TokSize = Lexer::MeasureTokenLength(E, SM, LangOpts);
 
-      OS << '{' << B.getLineNumber() << ':' << B.getColumnNumber() << '-'
-         << E.getLineNumber() << ':' << (E.getColumnNumber() + TokSize) << '}';
+      OS << '{' << SM.getLineNumber(BInfo.first, BInfo.second) << ':'
+        << SM.getColumnNumber(BInfo.first, BInfo.second) << '-'
+        << SM.getLineNumber(EInfo.first, EInfo.second) << ':'
+        << (SM.getColumnNumber(EInfo.first, EInfo.second)+TokSize)
+        << '}';
       PrintedRange = true;
     }
 
@@ -892,7 +897,9 @@ void TextDiagnostic::emitDiagnosticLoc(F
   OS << ' ';
 }
 
-void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
+void TextDiagnostic::emitIncludeLocation(SourceLocation Loc,
+                                         PresumedLoc PLoc,
+                                         const SourceManager &SM) {
   if (DiagOpts->ShowLocation && PLoc.isValid())
     OS << "In file included from " << PLoc.getFilename() << ':'
        << PLoc.getLine() << ":\n";
@@ -900,8 +907,9 @@ void TextDiagnostic::emitIncludeLocation
     OS << "In included file:\n"; 
 }
 
-void TextDiagnostic::emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
-                                        StringRef ModuleName) {
+void TextDiagnostic::emitImportLocation(SourceLocation Loc, PresumedLoc PLoc,
+                                        StringRef ModuleName,
+                                        const SourceManager &SM) {
   if (DiagOpts->ShowLocation && PLoc.isValid())
     OS << "In module '" << ModuleName << "' imported from "
        << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n";
@@ -909,9 +917,10 @@ void TextDiagnostic::emitImportLocation(
     OS << "In module '" << ModuleName << "':\n";
 }
 
-void TextDiagnostic::emitBuildingModuleLocation(FullSourceLoc Loc,
+void TextDiagnostic::emitBuildingModuleLocation(SourceLocation Loc,
                                                 PresumedLoc PLoc,
-                                                StringRef ModuleName) {
+                                                StringRef ModuleName,
+                                                const SourceManager &SM) {
   if (DiagOpts->ShowLocation && PLoc.isValid())
     OS << "While building module '" << ModuleName << "' imported from "
       << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n";
@@ -1125,8 +1134,10 @@ static std::string buildFixItInsertionLi
 /// \param Ranges The underlined ranges for this code snippet.
 /// \param Hints The FixIt hints active for this diagnostic.
 void TextDiagnostic::emitSnippetAndCaret(
-    FullSourceLoc Loc, DiagnosticsEngine::Level Level,
-    SmallVectorImpl<CharSourceRange> &Ranges, ArrayRef<FixItHint> Hints) {
+    SourceLocation Loc, DiagnosticsEngine::Level Level,
+    SmallVectorImpl<CharSourceRange>& Ranges,
+    ArrayRef<FixItHint> Hints,
+    const SourceManager &SM) {
   assert(Loc.isValid() && "must have a valid source location here");
   assert(Loc.isFileID() && "must have a file location here");
 
@@ -1143,18 +1154,18 @@ void TextDiagnostic::emitSnippetAndCaret
     return;
 
   // Decompose the location into a FID/Offset pair.
-  std::pair<FileID, unsigned> LocInfo = Loc.getDecomposedLoc();
+  std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
   FileID FID = LocInfo.first;
-  const SourceManager &SM = Loc.getManager();
+  unsigned CaretFileOffset = LocInfo.second;
 
   // Get information about the buffer it points into.
   bool Invalid = false;
-  StringRef BufData = Loc.getBufferData(&Invalid);
+  StringRef BufData = SM.getBufferData(FID, &Invalid);
   if (Invalid)
     return;
 
-  unsigned CaretLineNo = Loc.getLineNumber();
-  unsigned CaretColNo = Loc.getColumnNumber();
+  unsigned CaretLineNo = SM.getLineNumber(FID, CaretFileOffset);
+  unsigned CaretColNo = SM.getColumnNumber(FID, CaretFileOffset);
 
   // Arbitrarily stop showing snippets when the line is too long.
   static const size_t MaxLineLengthToPrint = 4096;

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Mon Jun 19 07:41:22 2017
@@ -150,9 +150,10 @@ void TextDiagnosticPrinter::HandleDiagno
          "Unexpected diagnostic with no source manager");
   assert(TextDiag && "Unexpected diagnostic outside source file processing");
 
-  TextDiag->emitDiagnostic(
-      FullSourceLoc(Info.getLocation(), Info.getSourceManager()), Level,
-      DiagMessageStream.str(), Info.getRanges(), Info.getFixItHints());
+  TextDiag->emitDiagnostic(Info.getLocation(), Level, DiagMessageStream.str(),
+                           Info.getRanges(),
+                           Info.getFixItHints(),
+                           &Info.getSourceManager());
 
   OS.flush();
 }

Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=305688&r1=305687&r2=305688&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Mon Jun 19 07:41:22 2017
@@ -110,34 +110,40 @@ public:
       CurrentSet = &CD.getChildDiagnostics();
   }
 
-  void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
-                             DiagnosticsEngine::Level Level, StringRef Message,
+  void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
+                             DiagnosticsEngine::Level Level,
+                             StringRef Message,
                              ArrayRef<CharSourceRange> Ranges,
+                             const SourceManager *SM,
                              DiagOrStoredDiag D) override {
     if (!D.isNull())
       return;
     
     CXSourceLocation L;
-    if (Loc.hasManager())
-      L = translateSourceLocation(Loc.getManager(), LangOpts, Loc);
+    if (SM)
+      L = translateSourceLocation(*SM, LangOpts, Loc);
     else
       L = clang_getNullLocation();
     CurrentSet->appendDiagnostic(
         llvm::make_unique<CXDiagnosticCustomNoteImpl>(Message, L));
   }
 
-  void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
+  void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
                          DiagnosticsEngine::Level Level,
-                         ArrayRef<CharSourceRange> Ranges) override {}
+                         ArrayRef<CharSourceRange> Ranges,
+                         const SourceManager &SM) override {}
 
-  void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
-                       SmallVectorImpl<CharSourceRange> &Ranges,
-                       ArrayRef<FixItHint> Hints) override {}
+  void emitCodeContext(SourceLocation Loc,
+                       DiagnosticsEngine::Level Level,
+                       SmallVectorImpl<CharSourceRange>& Ranges,
+                       ArrayRef<FixItHint> Hints,
+                       const SourceManager &SM) override {}
 
-  void emitNote(FullSourceLoc Loc, StringRef Message) override {
+  void emitNote(SourceLocation Loc, StringRef Message,
+                const SourceManager *SM) override {
     CXSourceLocation L;
-    if (Loc.hasManager())
-      L = translateSourceLocation(Loc.getManager(), LangOpts, Loc);
+    if (SM)
+      L = translateSourceLocation(*SM, LangOpts, Loc);
     else
       L = clang_getNullLocation();
     CurrentSet->appendDiagnostic(


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to