Generalize the skipping logic to allow skipping until any one of a set of

tokens is found.

llvm-svn: 39419
This commit is contained in:
Chris Lattner 2007-04-27 19:12:15 +00:00
parent e471889d53
commit 83b94e0967
2 changed files with 22 additions and 10 deletions

View File

@ -92,19 +92,22 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID,
///
/// If SkipUntil finds the specified token, it returns true, otherwise it
/// returns false.
bool Parser::SkipUntil(tok::TokenKind T, bool StopAtSemi, bool DontConsume) {
bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
bool StopAtSemi, bool DontConsume) {
// We always want this function to skip at least one token if the first token
// isn't T and if not at EOF.
bool isFirstTokenSkipped = true;
while (1) {
// If we found the token, stop and return true.
if (Tok.getKind() == T) {
if (DontConsume) {
// Noop, don't consume the token.
} else {
ConsumeAnyToken();
// If we found one of the tokens, stop and return true.
for (unsigned i = 0; i != NumToks; ++i) {
if (Tok.getKind() == Toks[i]) {
if (DontConsume) {
// Noop, don't consume the token.
} else {
ConsumeAnyToken();
}
return true;
}
return true;
}
switch (Tok.getKind()) {

View File

@ -228,8 +228,17 @@ private:
/// If SkipUntil finds the specified token, it returns true, otherwise it
/// returns false.
bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
bool DontConsume = false);
bool DontConsume = false) {
return SkipUntil(&T, 1, StopAtSemi, DontConsume);
}
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
bool DontConsume = false) {
tok::TokenKind TokArray[] = {T1, T2};
return SkipUntil(TokArray, 2, StopAtSemi, DontConsume);
}
bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
bool StopAtSemi = true, bool DontConsume = false);
//===--------------------------------------------------------------------===//
// C99 6.9: External Definitions.
DeclTy *ParseExternalDeclaration();