Add a SourceLocation::printToString() that returns in a std::string what dump()
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 9 Nov 2012 19:40:48 +0000 (19:40 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 9 Nov 2012 19:40:48 +0000 (19:40 +0000)
writes to stderr; for debugging purposes.

llvm-svn: 167629

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

index d6bba38..0bd0c92 100644 (file)
@@ -171,6 +171,7 @@ public:
   }
 
   void print(raw_ostream &OS, const SourceManager &SM) const;
+  LLVM_ATTRIBUTE_USED std::string printToString(const SourceManager &SM) const;
   void dump(const SourceManager &SM) const;
 };
 
index bb5a10a..0d62f7b 100644 (file)
@@ -61,6 +61,13 @@ void SourceLocation::print(raw_ostream &OS, const SourceManager &SM)const{
   OS << '>';
 }
 
+std::string SourceLocation::printToString(const SourceManager &SM) const {
+  std::string S;
+  llvm::raw_string_ostream OS(S);
+  print(OS, SM);
+  return S;
+}
+
 void SourceLocation::dump(const SourceManager &SM) const {
   print(llvm::errs(), SM);
 }