Use Token::simpleMatch instead of Token::Match for simple patterns
This commit is contained in:
parent
5f4c882b08
commit
54adb910ec
|
@ -139,7 +139,7 @@ void CheckAutoVariables::autoVariables()
|
||||||
else if (Token::Match(tok, "return & %var% ;") && isAutoVar(tok->tokAt(2)->varId())) {
|
else if (Token::Match(tok, "return & %var% ;") && isAutoVar(tok->tokAt(2)->varId())) {
|
||||||
errorReturnAddressToAutoVariable(tok);
|
errorReturnAddressToAutoVariable(tok);
|
||||||
} else if (Token::Match(tok, "return & %var% [") &&
|
} else if (Token::Match(tok, "return & %var% [") &&
|
||||||
Token::Match(tok->tokAt(3)->link(), "] ;") &&
|
Token::simpleMatch(tok->tokAt(3)->link(), "] ;") &&
|
||||||
isAutoVarArray(tok->tokAt(2)->varId())) {
|
isAutoVarArray(tok->tokAt(2)->varId())) {
|
||||||
errorReturnAddressToAutoVariable(tok);
|
errorReturnAddressToAutoVariable(tok);
|
||||||
} else if (Token::Match(tok, "return & %var% ;") && tok->tokAt(2)->varId()) {
|
} else if (Token::Match(tok, "return & %var% ;") && tok->tokAt(2)->varId()) {
|
||||||
|
@ -275,7 +275,7 @@ void CheckAutoVariables::returnReference()
|
||||||
|
|
||||||
// have we reached a function that returns a reference?
|
// have we reached a function that returns a reference?
|
||||||
if (Token::Match(tok->tokAt(-2), "%type% &") ||
|
if (Token::Match(tok->tokAt(-2), "%type% &") ||
|
||||||
Token::Match(tok->tokAt(-2), "> &")) {
|
Token::simpleMatch(tok->tokAt(-2), "> &")) {
|
||||||
// go to the '('
|
// go to the '('
|
||||||
const Token *tok2 = scope->classDef->next();
|
const Token *tok2 = scope->classDef->next();
|
||||||
|
|
||||||
|
|
|
@ -874,7 +874,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
||||||
tok3 = tok3->tokAt(-2);
|
tok3 = tok3->tokAt(-2);
|
||||||
|
|
||||||
// just taking the address?
|
// just taking the address?
|
||||||
const bool addr(Token::Match(tok3, "&") ||
|
const bool addr(Token::simpleMatch(tok3, "&") ||
|
||||||
Token::simpleMatch(tok3->tokAt(-1), "& ("));
|
Token::simpleMatch(tok3->tokAt(-1), "& ("));
|
||||||
|
|
||||||
// taking address of 1 past end?
|
// taking address of 1 past end?
|
||||||
|
@ -1065,7 +1065,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
||||||
tok2 = tok2->tokAt(-2);
|
tok2 = tok2->tokAt(-2);
|
||||||
|
|
||||||
// just taking the address?
|
// just taking the address?
|
||||||
const bool addr(Token::Match(tok2, "&") ||
|
const bool addr(Token::simpleMatch(tok2, "&") ||
|
||||||
Token::simpleMatch(tok2->tokAt(-1), "& ("));
|
Token::simpleMatch(tok2->tokAt(-1), "& ("));
|
||||||
|
|
||||||
// taking address of 1 past end?
|
// taking address of 1 past end?
|
||||||
|
|
|
@ -814,7 +814,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
|
||||||
if (tok->str() == "return") {
|
if (tok->str() == "return") {
|
||||||
foundReturn = true;
|
foundReturn = true;
|
||||||
std::string cast("( " + scope->className + " & )");
|
std::string cast("( " + scope->className + " & )");
|
||||||
if (Token::Match(tok->next(), cast.c_str()))
|
if (Token::simpleMatch(tok->next(), cast.c_str()))
|
||||||
tok = tok->tokAt(4);
|
tok = tok->tokAt(4);
|
||||||
|
|
||||||
// check if a function is called
|
// check if a function is called
|
||||||
|
@ -1277,7 +1277,7 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok)
|
||||||
|
|
||||||
if (tok->str() == "this") {
|
if (tok->str() == "this") {
|
||||||
return true;
|
return true;
|
||||||
} else if (Token::Match(tok->tokAt(-3), "( * this )")) {
|
} else if (Token::simpleMatch(tok->tokAt(-3), "( * this )")) {
|
||||||
return true;
|
return true;
|
||||||
} else if (Token::Match(tok->tokAt(-2), "%var% . %var%")) {
|
} else if (Token::Match(tok->tokAt(-2), "%var% . %var%")) {
|
||||||
tok = tok->tokAt(-2);
|
tok = tok->tokAt(-2);
|
||||||
|
|
|
@ -1737,7 +1737,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "; if(!var) exit ;" => ";"
|
// Reduce "; if(!var) exit ;" => ";"
|
||||||
if (Token::Match(tok2, "; if(!var) exit ;")) {
|
if (Token::simpleMatch(tok2, "; if(!var) exit ;")) {
|
||||||
Token::eraseTokens(tok2, tok2->tokAt(3));
|
Token::eraseTokens(tok2, tok2->tokAt(3));
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
@ -1899,7 +1899,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete if block in "alloc ; if(!var) return ;"
|
// Delete if block in "alloc ; if(!var) return ;"
|
||||||
if (Token::Match(tok2, "alloc ; if(!var) return ;")) {
|
if (Token::simpleMatch(tok2, "alloc ; if(!var) return ;")) {
|
||||||
Token::eraseTokens(tok2, tok2->tokAt(4));
|
Token::eraseTokens(tok2, tok2->tokAt(4));
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
@ -2505,7 +2505,7 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate..
|
// Allocate..
|
||||||
if (indent == 0 || Token::Match(tok, (varname + " =").c_str())) {
|
if (indent == 0 || Token::simpleMatch(tok, (varname + " =").c_str())) {
|
||||||
// var1 = var2 = ...
|
// var1 = var2 = ...
|
||||||
// bail out
|
// bail out
|
||||||
if (Token::simpleMatch(tok->previous(), "="))
|
if (Token::simpleMatch(tok->previous(), "="))
|
||||||
|
|
|
@ -178,7 +178,7 @@ void CheckOther::clarifyCondition()
|
||||||
if (Token::Match(tok2, "[&|^]")) {
|
if (Token::Match(tok2, "[&|^]")) {
|
||||||
// don't write false positives when templates are used
|
// don't write false positives when templates are used
|
||||||
if (Token::Match(tok, "<|>") && (Token::Match(tok2, "& ,|>") ||
|
if (Token::Match(tok, "<|>") && (Token::Match(tok2, "& ,|>") ||
|
||||||
Token::Match(tok2->previous(), "const &")))
|
Token::simpleMatch(tok2->previous(), "const &")))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
clarifyConditionError(tok,false,true);
|
clarifyConditionError(tok,false,true);
|
||||||
|
|
|
@ -1028,10 +1028,10 @@ void CheckStl::string_c_str()
|
||||||
localvar.find(tok->next()->varId()) != localvar.end()) {
|
localvar.find(tok->next()->varId()) != localvar.end()) {
|
||||||
string_c_strError(tok);
|
string_c_strError(tok);
|
||||||
} else if (Token::simpleMatch(tok, "return std :: string (") &&
|
} else if (Token::simpleMatch(tok, "return std :: string (") &&
|
||||||
Token::Match(tok->tokAt(4)->link(), ") . c_str ( ) ;")) {
|
Token::simpleMatch(tok->tokAt(4)->link(), ") . c_str ( ) ;")) {
|
||||||
string_c_strError(tok);
|
string_c_strError(tok);
|
||||||
} else if (Token::simpleMatch(tok, "return (") &&
|
} else if (Token::simpleMatch(tok, "return (") &&
|
||||||
Token::Match(tok->next()->link(), ") . c_str ( ) ;")) {
|
Token::simpleMatch(tok->next()->link(), ") . c_str ( ) ;")) {
|
||||||
// Check for "+ localvar" or "+ std::string(" inside the bracket
|
// Check for "+ localvar" or "+ std::string(" inside the bracket
|
||||||
bool is_implicit_std_string = false;
|
bool is_implicit_std_string = false;
|
||||||
const Token *search_end = tok->next()->link();
|
const Token *search_end = tok->next()->link();
|
||||||
|
@ -1082,7 +1082,7 @@ void CheckStl::checkAutoPointer()
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::simpleMatch(tok, "auto_ptr <")) {
|
if (Token::simpleMatch(tok, "auto_ptr <")) {
|
||||||
if ((tok->previous() && tok->previous()->str() == "<" && Token::Match(tok->tokAt(-2), STL_CONTAINER_LIST)) ||
|
if ((tok->previous() && tok->previous()->str() == "<" && Token::Match(tok->tokAt(-2), STL_CONTAINER_LIST)) ||
|
||||||
(Token::Match(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) {
|
(Token::simpleMatch(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) {
|
||||||
autoPointerContainerError(tok);
|
autoPointerContainerError(tok);
|
||||||
} else {
|
} else {
|
||||||
const Token *tok2 = tok->next()->next();
|
const Token *tok2 = tok->next()->next();
|
||||||
|
|
|
@ -1086,8 +1086,8 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
||||||
const Token *type = start->tokAt(3);
|
const Token *type = start->tokAt(3);
|
||||||
|
|
||||||
// skip nothrow
|
// skip nothrow
|
||||||
if (Token::Match(type, "( nothrow )") ||
|
if (Token::simpleMatch(type, "( nothrow )") ||
|
||||||
Token::Match(type, "( std :: nothrow )"))
|
Token::simpleMatch(type, "( std :: nothrow )"))
|
||||||
type = type->link()->next();
|
type = type->link()->next();
|
||||||
|
|
||||||
// is it a user defined type?
|
// is it a user defined type?
|
||||||
|
|
|
@ -1438,7 +1438,7 @@ void Scope::getVariableList()
|
||||||
} else if (Token::Match(tok, "struct|union {") && Token::Match(tok->next()->link(), "} %var% ;|[")) {
|
} else if (Token::Match(tok, "struct|union {") && Token::Match(tok->next()->link(), "} %var% ;|[")) {
|
||||||
tok = tok->next()->link()->next()->next();
|
tok = tok->next()->link()->next()->next();
|
||||||
continue;
|
continue;
|
||||||
} else if (Token::Match(tok, "struct|union {") && Token::Match(tok->next()->link(), "} ;")) {
|
} else if (Token::Match(tok, "struct|union {") && Token::simpleMatch(tok->next()->link(), "} ;")) {
|
||||||
level++;
|
level++;
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1198,7 +1198,7 @@ void Tokenizer::simplifyTypedef()
|
||||||
|
|
||||||
// pointer to function returning pointer to function
|
// pointer to function returning pointer to function
|
||||||
else if (Token::Match(tok->tokAt(offset), "( * ( * %type% ) (") &&
|
else if (Token::Match(tok->tokAt(offset), "( * ( * %type% ) (") &&
|
||||||
Token::Match(tok->tokAt(offset + 6)->link(), ") ) (") &&
|
Token::simpleMatch(tok->tokAt(offset + 6)->link(), ") ) (") &&
|
||||||
Token::Match(tok->tokAt(offset + 6)->link()->tokAt(2)->link(), ") ;|,")) {
|
Token::Match(tok->tokAt(offset + 6)->link()->tokAt(2)->link(), ") ;|,")) {
|
||||||
functionPtrRetFuncPtr = true;
|
functionPtrRetFuncPtr = true;
|
||||||
|
|
||||||
|
@ -3075,7 +3075,7 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
|
||||||
// copy
|
// copy
|
||||||
addtoken(tok3, tok3->linenr(), tok3->fileIndex());
|
addtoken(tok3, tok3->linenr(), tok3->fileIndex());
|
||||||
if (Token::Match(tok3, "%type% <")) {
|
if (Token::Match(tok3, "%type% <")) {
|
||||||
if (!Token::Match(tok3, (name + " <").c_str()))
|
if (!Token::simpleMatch(tok3, (name + " <").c_str()))
|
||||||
done = false;
|
done = false;
|
||||||
used.push_back(_tokensBack);
|
used.push_back(_tokensBack);
|
||||||
}
|
}
|
||||||
|
@ -3280,7 +3280,7 @@ void Tokenizer::setVarId()
|
||||||
if (tok->strAt(-1) == "return")
|
if (tok->strAt(-1) == "return")
|
||||||
continue;
|
continue;
|
||||||
if (tok->link() && !Token::Match(tok->link()->tokAt(1), "const| {") &&
|
if (tok->link() && !Token::Match(tok->link()->tokAt(1), "const| {") &&
|
||||||
!Token::Match(tok->link()->tokAt(1), ":"))
|
!Token::simpleMatch(tok->link()->tokAt(1), ":"))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3325,7 +3325,7 @@ void Tokenizer::setVarId()
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
// skip global namespace prefix
|
// skip global namespace prefix
|
||||||
if (Token::Match(tok, "::"))
|
if (Token::simpleMatch(tok, "::"))
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
while (Token::Match(tok, "%var% ::"))
|
while (Token::Match(tok, "%var% ::"))
|
||||||
|
@ -4409,7 +4409,7 @@ void Tokenizer::simplifyFlowControl()
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
}
|
}
|
||||||
for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||||
if (Token::Match(tok2, ": ;")) {
|
if (Token::simpleMatch(tok2, ": ;")) {
|
||||||
if (indentlevel == indentcase) {
|
if (indentlevel == indentcase) {
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
}
|
}
|
||||||
|
@ -6203,8 +6203,8 @@ void Tokenizer::simplifyIfNotNull()
|
||||||
if (Token::Match(tok->tokAt(-2), "[;{}] %var%")) {
|
if (Token::Match(tok->tokAt(-2), "[;{}] %var%")) {
|
||||||
const std::string varname(tok->previous()->str());
|
const std::string varname(tok->previous()->str());
|
||||||
|
|
||||||
if (Token::Match(tok->tokAt(2), (varname + " != 0 ) ;").c_str()) ||
|
if (Token::simpleMatch(tok->tokAt(2), (varname + " != 0 ) ;").c_str()) ||
|
||||||
Token::Match(tok->tokAt(2), ("0 != " + varname + " ) ;").c_str())) {
|
Token::simpleMatch(tok->tokAt(2), ("0 != " + varname + " ) ;").c_str())) {
|
||||||
tok = tok->tokAt(-2);
|
tok = tok->tokAt(-2);
|
||||||
Token::eraseTokens(tok, tok->tokAt(9));
|
Token::eraseTokens(tok, tok->tokAt(9));
|
||||||
}
|
}
|
||||||
|
@ -7397,7 +7397,7 @@ void Tokenizer::simplifyGoto()
|
||||||
|
|
||||||
if (tok->str() == "{") {
|
if (tok->str() == "{") {
|
||||||
if ((tok->tokAt(-2) && Token::Match(tok->tokAt(-2),"namespace|struct|class|union %var% {")) ||
|
if ((tok->tokAt(-2) && Token::Match(tok->tokAt(-2),"namespace|struct|class|union %var% {")) ||
|
||||||
(tok->previous() && Token::Match(tok->previous(),"namespace {")))
|
(tok->previous() && Token::simpleMatch(tok->previous(),"namespace {")))
|
||||||
++indentspecial;
|
++indentspecial;
|
||||||
else if (!beginfunction && !indentlevel)
|
else if (!beginfunction && !indentlevel)
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
|
|
Loading…
Reference in New Issue