Refactorization: Prefer Token::simpleMatch over Token::Match also for non-const patterns.

This commit is contained in:
PKEuS 2015-12-03 13:04:55 +01:00
parent 00662ec484
commit 32e2fb2f78
5 changed files with 8 additions and 8 deletions

View File

@ -555,7 +555,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
// ValueFlow array index..
if ((declarationId > 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() != "[")

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -452,7 +452,7 @@ std::set<std::string> TemplateSimplifier::expandSpecialized(Token *tokens)
tok->deleteThis();
// Use this special template in the code..
while (nullptr != (tok2 = const_cast<Token *>(Token::findmatch(tok2, pattern.c_str())))) {
while (nullptr != (tok2 = const_cast<Token *>(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<Token *> &temp
for (std::list<Token *>::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..

View File

@ -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()))) {