From 32e2fb2f7804e37e2498c7d0c438ac7fb9c356f7 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 3 Dec 2015 13:04:55 +0100 Subject: [PATCH] Refactorization: Prefer Token::simpleMatch over Token::Match also for non-const patterns. --- lib/checkbufferoverrun.cpp | 2 +- lib/checkclass.cpp | 2 +- lib/symboldatabase.cpp | 4 ++-- lib/templatesimplifier.cpp | 4 ++-- lib/tokenize.cpp | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 22433df82..c0ae2a669 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -555,7 +555,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector 0 && Token::Match(tok, "%varid% [", declarationId)) || - (declarationId == 0 && Token::Match(tok, (varnames + " [").c_str()))) { + (declarationId == 0 && Token::simpleMatch(tok, (varnames + " [").c_str()))) { const Token *tok2 = tok->next(); while (tok2->str() != "[") diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 654dddb88..195cc5b71 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1315,7 +1315,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co return; } if (startTok->next() == last) { - if (Token::Match(func->argDef, std::string("( const " + scope->className + " &").c_str())) { + if (Token::simpleMatch(func->argDef, std::string("( const " + scope->className + " &").c_str())) { // Typical wrong way to suppress default assignment operator by declaring it and leaving empty operatorEqMissingReturnStatementError(func->token, func->access == Public); } else { diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 9503bfd34..86b75dec4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1620,7 +1620,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se else if (depth && Token::Match(first->next(), "%name%")) { std::string param = path + first->next()->str(); - if (Token::Match(second->next(), param.c_str())) { + if (Token::simpleMatch(second->next(), param.c_str())) { second = second->tokAt(int(depth) * 2); } else if (depth > 1) { std::string short_path = path; @@ -1634,7 +1634,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se short_path.resize(lastSpace+1); param = short_path + first->next()->str(); - if (Token::Match(second->next(), param.c_str())) { + if (Token::simpleMatch(second->next(), param.c_str())) { second = second->tokAt((int(depth) - 1) * 2); } } diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 9fb054663..f34b58d3e 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -452,7 +452,7 @@ std::set TemplateSimplifier::expandSpecialized(Token *tokens) tok->deleteThis(); // Use this special template in the code.. - while (nullptr != (tok2 = const_cast(Token::findmatch(tok2, pattern.c_str())))) { + while (nullptr != (tok2 = const_cast(Token::findsimplematch(tok2, pattern.c_str())))) { Token::eraseTokens(tok2, Token::findsimplematch(tok2, "<")->findClosingBracket()->next()); tok2->str(name); } @@ -608,7 +608,7 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list &temp for (std::list::const_iterator iter2 = templateInstantiations->begin(); iter2 != templateInstantiations->end(); ++iter2) { Token *tok = *iter2; - if (!Token::Match(tok, (classname + " < %any%").c_str())) + if (!Token::simpleMatch(tok, (classname + " <").c_str())) continue; // count the parameters.. diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bcb50f00c..5d745500a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7730,7 +7730,7 @@ void Tokenizer::simplifyEnum() // skip ( .. ) tok2 = tok2->next()->link(); } - } else if (!pattern.empty() && Token::Match(tok2, pattern.c_str())) { + } else if (!pattern.empty() && Token::simpleMatch(tok2, pattern.c_str())) { const Token* tok3 = tok2; while (tok3->strAt(1) == "::") tok3 = tok3->tokAt(2); @@ -7847,7 +7847,7 @@ void Tokenizer::simplifyEnum() } } else if (tok2->str() == "{") ++level; - else if (!pattern.empty() && ((tok2->str() == "enum" && Token::Match(tok2->next(), pattern.c_str())) || Token::Match(tok2, pattern.c_str()))) { + else if (!pattern.empty() && ((tok2->str() == "enum" && Token::simpleMatch(tok2->next(), pattern.c_str())) || Token::simpleMatch(tok2, pattern.c_str()))) { simplify = true; hasClass = true; } else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) {