Skip to content

Commit

Permalink
Update tokenize.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed May 16, 2024
1 parent b5cb0f8 commit 44bbfa1
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ namespace {
/** Return whether tok is the "{" that starts an enumerator list */
static bool isEnumStart(const Token* tok)
{
if (!tok || tok->str() != "{")
if (!Token::simpleMatch(tok, "{"))
return false;
return (tok->strAt(-1) == "enum") || (tok->strAt(-2) == "enum") || Token::Match(tok->tokAt(-3), "enum class %name%");
tok = tok->previous();
while (tok && !tok->isKeyword() && Token::Match(tok, "%name%|::|:"))
tok = tok->previous();
if (Token::simpleMatch(tok, "class"))
tok = tok->previous();
return Token::simpleMatch(tok, "enum");
}

template<typename T>
Expand Down Expand Up @@ -1132,18 +1137,6 @@ void Tokenizer::simplifyTypedef()
simplifyTypedefCpp();
}

static bool isEnumScope(const Token* tok)
{
if (!Token::simpleMatch(tok, "{"))
return false;
tok = tok->previous();
while (tok && !tok->isKeyword() && Token::Match(tok, "%name%|::|:"))
tok = tok->previous();
if (Token::simpleMatch(tok, "class"))
tok = tok->previous();
return Token::simpleMatch(tok, "enum");
}

void Tokenizer::simplifyTypedefCpp()
{
bool isNamespace = false;
Expand Down Expand Up @@ -1755,7 +1748,7 @@ void Tokenizer::simplifyTypedefCpp()
}
++scope;
}
if (isEnumScope(tok2))
if (isEnumStart(tok2))
inEnum = true;
}

Expand Down

0 comments on commit 44bbfa1

Please sign in to comment.