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
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 6fe414b..40227dc 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -278,6 +278,16 @@
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