Remove unexpected code completion handling from ConsumeToken()

With this change tok::code_completion is finally handled exclusively as a
special token kind like other tokens that need special treatment.

All callers have been updated to use the specific token consumption methods and
the parser has a clear idea the current token isn't special by the time
ConsumeToken() gets called, so this has been unreachable for some time.

ConsumeAnyToken() behaviour is unchanged and will continue to support
unexpected code completion as part of the special token path.

This survived an amount of fuzzing and validation, but please ping the list if
you hit a code path that previously relied on the old unexpected handler and
now asserts.

llvm-svn: 198942
This commit is contained in:
Alp Toker 2014-01-10 14:37:02 +00:00
parent 90ff80e329
commit 9f1d619c07
1 changed files with 4 additions and 8 deletions

View File

@ -273,16 +273,12 @@ public:
bool ParseTopLevelDecl(DeclGroupPtrTy &Result); bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
/// ConsumeToken - Consume the current 'peek token' and lex the next one. /// ConsumeToken - Consume the current 'peek token' and lex the next one.
/// This does not work with all kinds of tokens: strings and specific other /// This does not work with special tokens: string literals, code completion
/// tokens must be consumed with custom methods below. This returns the /// and balanced tokens must be handled using the specific consume methods.
/// location of the consumed token. /// Returns the location of the consumed token.
SourceLocation ConsumeToken() { SourceLocation ConsumeToken() {
assert(!isTokenSpecial() && assert(!isTokenSpecial() &&
"Should consume special tokens with Consume*Token"); "Should consume special tokens with Consume*Token");
if (LLVM_UNLIKELY(Tok.is(tok::code_completion)))
return handleUnexpectedCodeCompletionToken();
PrevTokLocation = Tok.getLocation(); PrevTokLocation = Tok.getLocation();
PP.Lex(Tok); PP.Lex(Tok);
return PrevTokLocation; return PrevTokLocation;
@ -329,7 +325,7 @@ private:
/// isTokenSpecial - True if this token requires special consumption methods. /// isTokenSpecial - True if this token requires special consumption methods.
bool isTokenSpecial() const { bool isTokenSpecial() const {
return isTokenStringLiteral() || isTokenParen() || isTokenBracket() || return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
isTokenBrace(); isTokenBrace() || Tok.is(tok::code_completion);
} }
/// \brief Returns true if the current token is '=' or is a type of '='. /// \brief Returns true if the current token is '=' or is a type of '='.