Omit unneeded match checks

This commit is contained in:
Dmitry-Me 2015-09-07 18:35:15 +03:00
parent d88dc3ed3e
commit 662e3c8b8c
3 changed files with 9 additions and 5 deletions

View File

@ -933,7 +933,7 @@ void CheckOther::invalidFunctionUsage()
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (!Token::Match(tok, "%name% ( !!)"))
if (!tok->isName() || !Token::Match(tok, "%name% ( !!)"))
continue;
const Token * const functionToken = tok;
int argnr = 1;
@ -2605,7 +2605,7 @@ void CheckOther::checkInterlockedDecrement()
}
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "InterlockedDecrement ( & %name% ) ; if ( %name%|!|0")) {
if (tok->isName() && Token::Match(tok, "InterlockedDecrement ( & %name% ) ; if ( %name%|!|0")) {
const Token* interlockedVarTok = tok->tokAt(3);
const Token* checkStartTok = interlockedVarTok->tokAt(5);
if ((Token::Match(checkStartTok, "0 %comp% %name% )") && checkStartTok->strAt(2) == interlockedVarTok->str()) ||

View File

@ -81,7 +81,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
return;
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "memcmp|strncmp|strcmp|stricmp|strverscmp|bcmp|strcmpi|strcasecmp|strncasecmp|strncasecmp_l|strcasecmp_l|wcsncasecmp|wcscasecmp|wmemcmp|wcscmp|wcscasecmp_l|wcsncasecmp_l|wcsncmp|_mbscmp|_memicmp|_memicmp_l|_stricmp|_wcsicmp|_mbsicmp|_stricmp_l|_wcsicmp_l|_mbsicmp_l (")) {
if (tok->isName() && Token::Match(tok, "memcmp|strncmp|strcmp|stricmp|strverscmp|bcmp|strcmpi|strcasecmp|strncasecmp|strncasecmp_l|strcasecmp_l|wcsncasecmp|wcscasecmp|wmemcmp|wcscmp|wcscasecmp_l|wcsncasecmp_l|wcsncmp|_mbscmp|_memicmp|_memicmp_l|_stricmp|_wcsicmp|_mbsicmp|_stricmp_l|_wcsicmp_l|_mbsicmp_l (")) {
if (Token::Match(tok->tokAt(2), "%str% , %str% ,|)")) {
const std::string &str1 = tok->strAt(2);
const std::string &str2 = tok->strAt(4);
@ -100,7 +100,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
alwaysTrueStringVariableCompareError(tok, str1, str2);
tok = tok->tokAt(13);
}
} else if (Token::Match(tok, "QString :: compare ( %str% , %str% )")) {
} else if (tok->isName() && Token::Match(tok, "QString :: compare ( %str% , %str% )")) {
const std::string &str1 = tok->strAt(4);
const std::string &str2 = tok->strAt(6);
alwaysTrueFalseStringCompareError(tok, str1, str2);

View File

@ -2051,7 +2051,7 @@ void Tokenizer::simplifyArrayAccessSyntax()
{
// 0[a] -> a[0]
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "%num% [ %name% ]")) {
if (tok->isNumber() && Token::Match(tok, "%num% [ %name% ]")) {
std::string temp = tok->str();
tok->str(tok->strAt(2));
tok->varId(tok->tokAt(2)->varId());
@ -2128,6 +2128,8 @@ void Tokenizer::simplifyDoublePlusAndDoubleMinus()
void Tokenizer::arraySize()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (!tok->isName() || !Token::Match( tok, "%name% [ ] =" ) )
continue;
bool addlength = false;
if (Token::Match(tok, "%name% [ ] = { %str% } ;")) {
Token *t = tok->tokAt(3);
@ -8762,6 +8764,8 @@ void Tokenizer::simplifyStructDecl()
// Add names for anonymous structs
for (Token *tok = list.front(); tok; tok = tok->next()) {
if(!tok->isName() )
continue;
// check for anonymous struct/union
if (Token::Match(tok, "struct|union {")) {
if (Token::Match(tok->next()->link(), "} *|&| %type% ,|;|[")) {