Refactorization: Prefer Token::simpleMatch over Token::Match also for non-const patterns.
This commit is contained in:
parent
00662ec484
commit
32e2fb2f78
|
@ -555,7 +555,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
||||||
|
|
||||||
// ValueFlow array index..
|
// ValueFlow array index..
|
||||||
if ((declarationId > 0 && Token::Match(tok, "%varid% [", declarationId)) ||
|
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();
|
const Token *tok2 = tok->next();
|
||||||
while (tok2->str() != "[")
|
while (tok2->str() != "[")
|
||||||
|
|
|
@ -1315,7 +1315,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (startTok->next() == last) {
|
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
|
// Typical wrong way to suppress default assignment operator by declaring it and leaving empty
|
||||||
operatorEqMissingReturnStatementError(func->token, func->access == Public);
|
operatorEqMissingReturnStatementError(func->token, func->access == Public);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1620,7 +1620,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
|
||||||
else if (depth && Token::Match(first->next(), "%name%")) {
|
else if (depth && Token::Match(first->next(), "%name%")) {
|
||||||
std::string param = path + first->next()->str();
|
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);
|
second = second->tokAt(int(depth) * 2);
|
||||||
} else if (depth > 1) {
|
} else if (depth > 1) {
|
||||||
std::string short_path = path;
|
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);
|
short_path.resize(lastSpace+1);
|
||||||
|
|
||||||
param = short_path + first->next()->str();
|
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);
|
second = second->tokAt((int(depth) - 1) * 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,7 +452,7 @@ std::set<std::string> TemplateSimplifier::expandSpecialized(Token *tokens)
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
|
|
||||||
// Use this special template in the code..
|
// 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());
|
Token::eraseTokens(tok2, Token::findsimplematch(tok2, "<")->findClosingBracket()->next());
|
||||||
tok2->str(name);
|
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) {
|
for (std::list<Token *>::const_iterator iter2 = templateInstantiations->begin(); iter2 != templateInstantiations->end(); ++iter2) {
|
||||||
Token *tok = *iter2;
|
Token *tok = *iter2;
|
||||||
|
|
||||||
if (!Token::Match(tok, (classname + " < %any%").c_str()))
|
if (!Token::simpleMatch(tok, (classname + " <").c_str()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// count the parameters..
|
// count the parameters..
|
||||||
|
|
|
@ -7730,7 +7730,7 @@ void Tokenizer::simplifyEnum()
|
||||||
// skip ( .. )
|
// skip ( .. )
|
||||||
tok2 = tok2->next()->link();
|
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;
|
const Token* tok3 = tok2;
|
||||||
while (tok3->strAt(1) == "::")
|
while (tok3->strAt(1) == "::")
|
||||||
tok3 = tok3->tokAt(2);
|
tok3 = tok3->tokAt(2);
|
||||||
|
@ -7847,7 +7847,7 @@ void Tokenizer::simplifyEnum()
|
||||||
}
|
}
|
||||||
} else if (tok2->str() == "{")
|
} else if (tok2->str() == "{")
|
||||||
++level;
|
++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;
|
simplify = true;
|
||||||
hasClass = true;
|
hasClass = true;
|
||||||
} else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) {
|
} else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) {
|
||||||
|
|
Loading…
Reference in New Issue