Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 9410928

Browse files
committed
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
1 parent ecd27bf commit 9410928

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Diff for: include/clang/Basic/SourceLocation.h

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class SourceLocation {
171171
}
172172

173173
void print(raw_ostream &OS, const SourceManager &SM) const;
174+
LLVM_ATTRIBUTE_USED std::string printToString(const SourceManager &SM) const;
174175
void dump(const SourceManager &SM) const;
175176
};
176177

Diff for: lib/Basic/SourceLocation.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ void SourceLocation::print(raw_ostream &OS, const SourceManager &SM)const{
6161
OS << '>';
6262
}
6363

64+
std::string SourceLocation::printToString(const SourceManager &SM) const {
65+
std::string S;
66+
llvm::raw_string_ostream OS(S);
67+
print(OS, SM);
68+
return S;
69+
}
70+
6471
void SourceLocation::dump(const SourceManager &SM) const {
6572
print(llvm::errs(), SM);
6673
}

0 commit comments

Comments
 (0)