From: Argyrios Kyrtzidis Date: Fri, 9 Nov 2012 19:40:48 +0000 (+0000) Subject: Add a SourceLocation::printToString() that returns in a std::string what dump() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9410928fb8434e8d26364cee45ebc1b798aafe41;p=clang Add a SourceLocation::printToString() that returns in a std::string what dump() writes to stderr; for debugging purposes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167629 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index d6bba38563..0bd0c92b00 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/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/lib/Basic/SourceLocation.cpp b/lib/Basic/SourceLocation.cpp index bb5a10a9c7..0d62f7bb4b 100644 --- a/lib/Basic/SourceLocation.cpp +++ b/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); }