Skip to content

Commit 32e2fb2

Browse files
committed
Refactorization: Prefer Token::simpleMatch over Token::Match also for non-const patterns.
1 parent 00662ec commit 32e2fb2

5 files changed

Lines changed: 8 additions & 8 deletions

File tree

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
555555

556556
// ValueFlow array index..
557557
if ((declarationId > 0 && Token::Match(tok, "%varid% [", declarationId)) ||
558-
(declarationId == 0 && Token::Match(tok, (varnames + " [").c_str()))) {
558+
(declarationId == 0 && Token::simpleMatch(tok, (varnames + " [").c_str()))) {
559559

560560
const Token *tok2 = tok->next();
561561
while (tok2->str() != "[")

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
13151315
return;
13161316
}
13171317
if (startTok->next() == last) {
1318-
if (Token::Match(func->argDef, std::string("( const " + scope->className + " &").c_str())) {
1318+
if (Token::simpleMatch(func->argDef, std::string("( const " + scope->className + " &").c_str())) {
13191319
// Typical wrong way to suppress default assignment operator by declaring it and leaving empty
13201320
operatorEqMissingReturnStatementError(func->token, func->access == Public);
13211321
} else {

lib/symboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
16201620
else if (depth && Token::Match(first->next(), "%name%")) {
16211621
std::string param = path + first->next()->str();
16221622

1623-
if (Token::Match(second->next(), param.c_str())) {
1623+
if (Token::simpleMatch(second->next(), param.c_str())) {
16241624
second = second->tokAt(int(depth) * 2);
16251625
} else if (depth > 1) {
16261626
std::string short_path = path;
@@ -1634,7 +1634,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
16341634
short_path.resize(lastSpace+1);
16351635

16361636
param = short_path + first->next()->str();
1637-
if (Token::Match(second->next(), param.c_str())) {
1637+
if (Token::simpleMatch(second->next(), param.c_str())) {
16381638
second = second->tokAt((int(depth) - 1) * 2);
16391639
}
16401640
}

lib/templatesimplifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ std::set<std::string> TemplateSimplifier::expandSpecialized(Token *tokens)
452452
tok->deleteThis();
453453

454454
// Use this special template in the code..
455-
while (nullptr != (tok2 = const_cast<Token *>(Token::findmatch(tok2, pattern.c_str())))) {
455+
while (nullptr != (tok2 = const_cast<Token *>(Token::findsimplematch(tok2, pattern.c_str())))) {
456456
Token::eraseTokens(tok2, Token::findsimplematch(tok2, "<")->findClosingBracket()->next());
457457
tok2->str(name);
458458
}
@@ -608,7 +608,7 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list<Token *> &temp
608608
for (std::list<Token *>::const_iterator iter2 = templateInstantiations->begin(); iter2 != templateInstantiations->end(); ++iter2) {
609609
Token *tok = *iter2;
610610

611-
if (!Token::Match(tok, (classname + " < %any%").c_str()))
611+
if (!Token::simpleMatch(tok, (classname + " <").c_str()))
612612
continue;
613613

614614
// count the parameters..

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7730,7 +7730,7 @@ void Tokenizer::simplifyEnum()
77307730
// skip ( .. )
77317731
tok2 = tok2->next()->link();
77327732
}
7733-
} else if (!pattern.empty() && Token::Match(tok2, pattern.c_str())) {
7733+
} else if (!pattern.empty() && Token::simpleMatch(tok2, pattern.c_str())) {
77347734
const Token* tok3 = tok2;
77357735
while (tok3->strAt(1) == "::")
77367736
tok3 = tok3->tokAt(2);
@@ -7847,7 +7847,7 @@ void Tokenizer::simplifyEnum()
78477847
}
78487848
} else if (tok2->str() == "{")
78497849
++level;
7850-
else if (!pattern.empty() && ((tok2->str() == "enum" && Token::Match(tok2->next(), pattern.c_str())) || Token::Match(tok2, pattern.c_str()))) {
7850+
else if (!pattern.empty() && ((tok2->str() == "enum" && Token::simpleMatch(tok2->next(), pattern.c_str())) || Token::simpleMatch(tok2, pattern.c_str()))) {
78517851
simplify = true;
78527852
hasClass = true;
78537853
} else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) {

0 commit comments

Comments
 (0)