From dc6bb4982fa74d9faf8350793ba589a0cd06c959 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 9 Nov 2012 19:40:48 +0000 Subject: [PATCH] Add a SourceLocation::printToString() that returns in a std::string what dump() writes to stderr; for debugging purposes. llvm-svn: 167629 --- clang/include/clang/Basic/SourceLocation.h | 1 + clang/lib/Basic/SourceLocation.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h index d6bba38..0bd0c92 100644 --- a/clang/include/clang/Basic/SourceLocation.h +++ b/clang/include/clang/Basic/SourceLocation.h @@ -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; }; diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp index bb5a10a..0d62f7b 100644 --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -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); } -- 2.7.4