Merge pull request #674 from Dmitry-Me/omitUnneededActions5

Omit unneeded match checks
This commit is contained in:
orbitcowboy 2015-09-07 17:54:24 +02:00
commit 4f1e7ec9d3
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) { for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i]; const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { 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; continue;
const Token * const functionToken = tok; const Token * const functionToken = tok;
int argnr = 1; int argnr = 1;
@ -2605,7 +2605,7 @@ void CheckOther::checkInterlockedDecrement()
} }
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { 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* interlockedVarTok = tok->tokAt(3);
const Token* checkStartTok = interlockedVarTok->tokAt(5); const Token* checkStartTok = interlockedVarTok->tokAt(5);
if ((Token::Match(checkStartTok, "0 %comp% %name% )") && checkStartTok->strAt(2) == interlockedVarTok->str()) || if ((Token::Match(checkStartTok, "0 %comp% %name% )") && checkStartTok->strAt(2) == interlockedVarTok->str()) ||

View File

@ -81,7 +81,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
return; return;
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) { 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% ,|)")) { if (Token::Match(tok->tokAt(2), "%str% , %str% ,|)")) {
const std::string &str1 = tok->strAt(2); const std::string &str1 = tok->strAt(2);
const std::string &str2 = tok->strAt(4); const std::string &str2 = tok->strAt(4);
@ -100,7 +100,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
alwaysTrueStringVariableCompareError(tok, str1, str2); alwaysTrueStringVariableCompareError(tok, str1, str2);
tok = tok->tokAt(13); 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 &str1 = tok->strAt(4);
const std::string &str2 = tok->strAt(6); const std::string &str2 = tok->strAt(6);
alwaysTrueFalseStringCompareError(tok, str1, str2); alwaysTrueFalseStringCompareError(tok, str1, str2);

View File

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