[PATCH] D50662: Add dump() method for SourceRange

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 20 14:51:13 PDT 2018


steveire updated this revision to Diff 161570.
steveire added a comment.

Add dump() and supporting methods to SourceRange


Repository:
  rC Clang

https://reviews.llvm.org/D50662

Files:
  include/clang/Basic/SourceLocation.h
  lib/Basic/SourceLocation.cpp


Index: lib/Basic/SourceLocation.cpp
===================================================================
--- lib/Basic/SourceLocation.cpp
+++ lib/Basic/SourceLocation.cpp
@@ -80,6 +80,26 @@
   llvm::errs() << '\n';
 }
 
+LLVM_DUMP_METHOD void SourceRange::dump(const SourceManager &SM) const {
+  print(llvm::errs(), SM);
+}
+
+void SourceRange::print(raw_ostream &OS, const SourceManager &SM) const {
+  OS << '[';
+  B.print(OS, SM);
+  OS << ",\n ";
+  E.print(OS, SM);
+  OS << "]\n";
+}
+
+LLVM_DUMP_METHOD std::string
+SourceRange::printToString(const SourceManager &SM) const {
+  std::string S;
+  llvm::raw_string_ostream OS(S);
+  print(OS, SM);
+  return OS.str();
+}
+
 //===----------------------------------------------------------------------===//
 // FullSourceLoc
 //===----------------------------------------------------------------------===//
Index: include/clang/Basic/SourceLocation.h
===================================================================
--- include/clang/Basic/SourceLocation.h
+++ include/clang/Basic/SourceLocation.h
@@ -220,6 +220,10 @@
   bool operator!=(const SourceRange &X) const {
     return B != X.B || E != X.E;
   }
+
+  void print(raw_ostream &OS, const SourceManager &SM) const;
+  std::string printToString(const SourceManager &SM) const;
+  void dump(const SourceManager &SM) const;
 };
 
 /// Represents a character-granular source range.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50662.161570.patch
Type: text/x-patch
Size: 1393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180820/867bf19b/attachment.bin>


More information about the cfe-commits mailing list