Skip to content

Commit da124d1

Browse files
Fix #12737 Consolidate isEnumScope() and isEnumStart() in tokenize.cpp (#6407)
1 parent c318cf6 commit da124d1

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

lib/tokenize.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ namespace {
7979
/** Return whether tok is the "{" that starts an enumerator list */
8080
static bool isEnumStart(const Token* tok)
8181
{
82-
if (!tok || tok->str() != "{")
82+
if (!Token::simpleMatch(tok, "{"))
8383
return false;
84-
return (tok->strAt(-1) == "enum") || (tok->strAt(-2) == "enum") || Token::Match(tok->tokAt(-3), "enum class %name%");
84+
tok = tok->previous();
85+
while (tok && !tok->isKeyword() && Token::Match(tok, "%name%|::|:"))
86+
tok = tok->previous();
87+
if (Token::simpleMatch(tok, "class"))
88+
tok = tok->previous();
89+
return Token::simpleMatch(tok, "enum");
8590
}
8691

8792
template<typename T>
@@ -1132,18 +1137,6 @@ void Tokenizer::simplifyTypedef()
11321137
simplifyTypedefCpp();
11331138
}
11341139

1135-
static bool isEnumScope(const Token* tok)
1136-
{
1137-
if (!Token::simpleMatch(tok, "{"))
1138-
return false;
1139-
tok = tok->previous();
1140-
while (tok && !tok->isKeyword() && Token::Match(tok, "%name%|::|:"))
1141-
tok = tok->previous();
1142-
if (Token::simpleMatch(tok, "class"))
1143-
tok = tok->previous();
1144-
return Token::simpleMatch(tok, "enum");
1145-
}
1146-
11471140
void Tokenizer::simplifyTypedefCpp()
11481141
{
11491142
bool isNamespace = false;
@@ -1755,7 +1748,7 @@ void Tokenizer::simplifyTypedefCpp()
17551748
}
17561749
++scope;
17571750
}
1758-
if (isEnumScope(tok2))
1751+
if (isEnumStart(tok2))
17591752
inEnum = true;
17601753
}
17611754

0 commit comments

Comments
 (0)