diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-01-07 19:16:18 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-01-07 19:16:18 +0000 |
commit | d93335c43fd462145fee3ea8f4d84d430577c821 (patch) | |
tree | 31a20c98152dbf33271e98cddf019434eb0f654c /lib/Lex/Lexer.cpp | |
parent | 0b67c75c988f7188743059713a04ca2320c9f15a (diff) |
Pull the bulk of Lexer::MeasureTokenLength() out into a new function,
Lexer::getRawToken().
No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171771 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r-- | lib/Lex/Lexer.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 1bcff98cf4..15b1061d05 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -414,6 +414,17 @@ static bool isWhitespace(unsigned char c); unsigned Lexer::MeasureTokenLength(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts) { + Token TheTok; + if (getRawToken(Loc, TheTok, SM, LangOpts)) + return 0; + return TheTok.getLength(); +} + +/// \brief Relex the token at the specified location. +/// \returns true if there was a failure, false on success. +bool Lexer::getRawToken(SourceLocation Loc, Token &Result, + const SourceManager &SM, + const LangOptions &LangOpts) { // TODO: this could be special cased for common tokens like identifiers, ')', // etc to make this faster, if it mattered. Just look at StrData[0] to handle // all obviously single-char tokens. This could use @@ -427,20 +438,19 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc, bool Invalid = false; StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); if (Invalid) - return 0; + return true; const char *StrData = Buffer.data()+LocInfo.second; if (isWhitespace(StrData[0])) - return 0; + return true; // Create a lexer starting at the beginning of this token. Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, Buffer.begin(), StrData, Buffer.end()); TheLexer.SetCommentRetentionState(true); - Token TheTok; - TheLexer.LexFromRawLexer(TheTok); - return TheTok.getLength(); + TheLexer.LexFromRawLexer(Result); + return false; } static SourceLocation getBeginningOfFileToken(SourceLocation Loc, |