aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Preprocessor.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-03-08 04:06:57 +0000
committerJohn McCall <rjmccall@apple.com>2011-03-08 04:06:57 +0000
commit30900dafbe972f4802c2663262b4393edab0d1cd (patch)
tree6459592b24d4cf2c25a643e194c1051ec03933a8 /lib/Lex/Preprocessor.cpp
parentdb93fdee6c5a24e86ee5ed8c1d3b597e17d5893b (diff)
Add an API call to retrieve the spelling data of a token from its SourceLocation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127216 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Preprocessor.cpp')
-rw-r--r--lib/Lex/Preprocessor.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 6fe414b664..40227dc5e6 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -278,6 +278,16 @@ void Preprocessor::CodeCompleteNaturalLanguage() {
CodeComplete->CodeCompleteNaturalLanguage();
}
+llvm::StringRef Preprocessor::getSpelling(SourceLocation loc,
+ bool *invalid) const {
+ bool invalidTemp = false;
+ if (!invalid) invalid = &invalidTemp;
+ const char *begin = SourceMgr.getCharacterData(loc, invalid);
+ if (*invalid) return llvm::StringRef();
+
+ unsigned length = Lexer::MeasureTokenLength(loc, SourceMgr, Features);
+ return llvm::StringRef(begin, length);
+}
/// getSpelling - This method is used to get the spelling of a token into a
/// SmallVector. Note that the returned StringRef may not point to the