summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-11-09 19:40:48 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-11-09 19:40:48 +0000
commit9410928fb8434e8d26364cee45ebc1b798aafe41 (patch)
treef337382602732ff6f284e8ee5b2daa9f6d7debda
parentecd27bf256c92f56c7c7ede6f40ec5d31a40b35e (diff)
downloadclang-9410928fb8434e8d26364cee45ebc1b798aafe41.tar.gz
clang-9410928fb8434e8d26364cee45ebc1b798aafe41.tar.bz2
clang-9410928fb8434e8d26364cee45ebc1b798aafe41.tar.xz
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
-rw-r--r--include/clang/Basic/SourceLocation.h1
-rw-r--r--lib/Basic/SourceLocation.cpp7
2 files changed, 8 insertions, 0 deletions
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);
}