Refactoring: Changed order of parameters in Match() and findMatch() (deprecated parameter moved to last)

This commit is contained in:
Reijo Tomperi 2009-01-03 21:05:47 +00:00
parent fee4d77e7b
commit 1594f453cc
7 changed files with 48 additions and 48 deletions

View File

@ -75,7 +75,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
// Array index..
if ( varid > 0 )
{
if ( Token::Match(tok, "%varid% [ %num% ]", 0, varid) )
if ( Token::Match(tok, "%varid% [ %num% ]", varid) )
{
const char *num = tok->strAt(2);
if (strtol(num, NULL, 10) >= size)
@ -84,7 +84,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
}
}
}
else if ( Token::Match(tok, "%var1% [ %num% ]", varname) )
else if ( Token::Match(tok, "%var1% [ %num% ]", 0, varname) )
{
const char *num = tok->strAt(2 + varc);
if (strtol(num, NULL, 10) >= size)
@ -112,7 +112,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
// Array index..
if ( varid > 0 )
{
if ( !tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), "%varid% [ %num% ]", 0, varid) )
if ( !tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), "%varid% [ %num% ]", varid) )
{
const char *num = tok->strAt(3);
if (strtol(num, NULL, 10) >= size)
@ -121,7 +121,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
}
}
}
else if ( !tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), "%var1% [ %num% ]", varname) )
else if ( !tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), "%var1% [ %num% ]", 0, varname) )
{
const char *num = tok->next()->strAt(2 + varc);
if (strtol(num, NULL, 10) >= size)
@ -138,8 +138,8 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
{
if ( Token::Match(tok, "memset|memcpy|memmove|memcmp|strncpy|fgets") )
{
if ( Token::Match(tok->next(), "( %varid% , %num% , %num% )", 0, varid) ||
Token::Match(tok->next(), "( %var% , %varid% , %num% )", 0, varid) )
if ( Token::Match(tok->next(), "( %varid% , %num% , %num% )", varid) ||
Token::Match(tok->next(), "( %var% , %varid% , %num% )", varid) )
{
const char *num = tok->strAt(6);
if ( atoi(num) > total_size )
@ -152,8 +152,8 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
}
else if (Token::Match(tok,"memset|memcpy|memmove|memcmp|strncpy|fgets") )
{
if ( Token::Match(tok->next(), "( %var1% , %num% , %num% )", varname) ||
Token::Match(tok->next(), "( %var% , %var1% , %num% )", varname) )
if ( Token::Match(tok->next(), "( %var1% , %num% , %num% )", 0, varname) ||
Token::Match(tok->next(), "( %var% , %var1% , %num% )", 0, varname) )
{
const char *num = tok->strAt(varc + 6);
if ( atoi(num) > total_size )
@ -215,7 +215,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
break;
}
if ( Token::Match(tok2, pattern.str().c_str(), varname) )
if ( Token::Match(tok2, pattern.str().c_str(), 0, varname) )
{
ReportError(tok2, "Buffer overrun");
break;
@ -227,7 +227,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
// Writing data into array..
if ( Token::Match(tok, "strcpy ( %var1% , %str% )", varname) )
if ( Token::Match(tok, "strcpy ( %var1% , %str% )", 0, varname) )
{
int len = 0;
const char *str = tok->strAt(varc + 4 );
@ -282,7 +282,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
++par;
}
if ( parlevel == 1 && Token::Match(tok2, "[(,] %var1% [,)]", varname) )
if ( parlevel == 1 && Token::Match(tok2, "[(,] %var1% [,)]", 0, varname) )
{
++par;
break;

View File

@ -351,7 +351,7 @@ void CheckClass::constructors()
isPrivate = false;
// Is there a private constructor?
else if ( isPrivate && Token::Match(tok, "%var1% (", className) )
else if ( isPrivate && Token::Match(tok, "%var1% (", 0, className) )
{
hasPrivateConstructor = true;
break;

View File

@ -162,25 +162,25 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetReallocationType( const
CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetDeallocationType( const Token *tok, const char *varnames[] )
{
if ( Token::Match(tok, "delete %var1% ;", varnames) )
if ( Token::Match(tok, "delete %var1% ;", 0, varnames) )
return New;
if ( Token::Match(tok, "delete [ ] %var1% ;", varnames) )
if ( Token::Match(tok, "delete [ ] %var1% ;", 0, varnames) )
return NewA;
if ( Token::Match(tok, "free ( %var1% ) ;", varnames) ||
Token::Match(tok, "kfree ( %var1% ) ;", varnames) )
if ( Token::Match(tok, "free ( %var1% ) ;", 0, varnames) ||
Token::Match(tok, "kfree ( %var1% ) ;", 0, varnames) )
{
return Malloc;
}
if ( Token::Match(tok, "g_free ( %var1% ) ;", varnames) )
if ( Token::Match(tok, "g_free ( %var1% ) ;", 0, varnames) )
return gMalloc;
if ( Token::Match(tok, "fclose ( %var1% )", varnames) )
if ( Token::Match(tok, "fclose ( %var1% )", 0, varnames) )
return FOPEN;
if ( Token::Match(tok, "pclose ( %var1% )", varnames) )
if ( Token::Match(tok, "pclose ( %var1% )", 0, varnames) )
return POPEN;
return No;
@ -240,7 +240,7 @@ const char * CheckMemoryLeakClass::call_func( const Token *tok, std::list<const
{
if ( tok->str() == "," )
++par;
if ( Token::Match(tok, "[,()] %var1% [,()]", varnames) )
if ( Token::Match(tok, "[,()] %var1% [,()]", 0, varnames) )
{
const Token *ftok = _tokenizer->GetFunctionTokenByName(funcname);
const char *parname = Tokenizer::getParameterName( ftok, par );
@ -308,12 +308,12 @@ void CheckMemoryLeakClass::instoken(Token *tok, const char str[])
bool CheckMemoryLeakClass::notvar(const Token *tok, const char *varnames[])
{
return bool( Token::Match(tok, "! %var1% [;)&|]", varnames) ||
Token::Match(tok, "! ( %var1% )", varnames) ||
Token::Match(tok, "unlikely ( ! %var1% )", varnames) ||
Token::Match(tok, "unlikely ( %var1% == 0 )", varnames) ||
Token::Match(tok, "0 == %var1% [;)&|]", varnames) ||
Token::Match(tok, "%var1% == 0", varnames) );
return bool( Token::Match(tok, "! %var1% [;)&|]", 0, varnames) ||
Token::Match(tok, "! ( %var1% )", 0, varnames) ||
Token::Match(tok, "unlikely ( ! %var1% )", 0, varnames) ||
Token::Match(tok, "unlikely ( %var1% == 0 )", 0, varnames) ||
Token::Match(tok, "0 == %var1% [;)&|]", 0, varnames) ||
Token::Match(tok, "%var1% == 0", 0, varnames) );
}
Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *> callstack, const char varname[], AllocType &alloctype, AllocType &dealloctype)
@ -372,7 +372,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
if ( parlevel == 0 && tok->str()==";")
addtoken(";");
if (Token::Match(tok, "[(;{}] %var1% =", varnames))
if (Token::Match(tok, "[(;{}] %var1% =", 0, varnames))
{
AllocType alloc = GetAllocationType(tok->tokAt(3));
bool realloc = false;
@ -447,9 +447,9 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
}
// if else switch
if ( Token::Match(tok, "if ( %var1% )", varnames) ||
Token::Match(tok, "if ( %var1% != 0 )", varnames) ||
Token::Match(tok, "if ( 0 != %var1% )", varnames) )
if ( Token::Match(tok, "if ( %var1% )", 0, varnames) ||
Token::Match(tok, "if ( %var1% != 0 )", 0, varnames) ||
Token::Match(tok, "if ( 0 != %var1% )", 0, varnames) )
{
addtoken("if(var)");
@ -476,7 +476,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
if ( parlevel <= 0 )
break;
}
if ( Token::Match(tok2, "fclose ( %var1% )", varnames) )
if ( Token::Match(tok2, "fclose ( %var1% )", 0, varnames) )
{
addtoken( "dealloc" );
addtoken( ";" );
@ -484,8 +484,8 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
break;
}
if ( (tok2->str() != ".") &&
Token::Match(tok2->next(), "%var1%", varnames) &&
!Token::Match(tok2->next(), "%var1% .", varnames) )
Token::Match(tok2->next(), "%var1%", 0, varnames) &&
!Token::Match(tok2->next(), "%var1% .", 0, varnames) )
{
dep = true;
break;
@ -539,8 +539,8 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
if ( tok->str() == "return" )
{
addtoken("return");
if ( Token::Match(tok, "return %var1%", varnames) ||
Token::Match(tok, "return & %var1%", varnames) )
if ( Token::Match(tok, "return %var1%", 0, varnames) ||
Token::Match(tok, "return & %var1%", 0, varnames) )
addtoken("use");
if (Token::simpleMatch(tok->next(), "("))
{
@ -563,13 +563,13 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
addtoken(tok->strAt(0));
// Assignment..
if ( Token::Match(tok,"[)=] %var1% [+;)]", varnames) ||
Token::Match(tok, "%var1% +=|-=", varnames) ||
Token::Match(tok, "+=|<< %var1% ;", varnames) )
if ( Token::Match(tok,"[)=] %var1% [+;)]", 0, varnames) ||
Token::Match(tok, "%var1% +=|-=", 0, varnames) ||
Token::Match(tok, "+=|<< %var1% ;", 0, varnames) )
{
addtoken("use");
}
else if ( Token::Match(tok, "[;{}=(,+-*/] %var1% [", varnames) )
else if ( Token::Match(tok, "[;{}=(,+-*/] %var1% [", 0, varnames) )
{
addtoken("use_");
}
@ -609,11 +609,11 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
}
// Linux lists..
if ( Token::Match( tok, "[=(,] & %var1% [.[]", varnames ) )
if ( Token::Match( tok, "[=(,] & %var1% [.[]", 0, varnames ) )
{
addtoken("&use");
}
else if ( Token::Match( tok, "[=(,] & %var1% [,)]", varnames ) )
else if ( Token::Match( tok, "[=(,] & %var1% [,)]", 0, varnames ) )
{
addtoken("&use2");
}

View File

@ -646,7 +646,7 @@ void CheckOther::CheckStructMemberUsage()
if ( tok->fileIndex() != 0 )
continue;
if (Token::Match(tok2, ". %var%", varnames))
if (Token::Match(tok2, ". %var%", 0, varnames))
{
if ( strcmp("=", tok2->strAt(2)) == 0 )
continue;
@ -697,7 +697,7 @@ void CheckOther::CheckCharVariable()
break;
}
if ((tok2->str() != ".") && Token::Match(tok2->next(), "%var% [ %varid% ]", 0, tok->varId()))
if ((tok2->str() != ".") && Token::Match(tok2->next(), "%var% [ %varid% ]", tok->varId()))
{
std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok2->next()) << ": Warning - using char variable as array index";
@ -705,7 +705,7 @@ void CheckOther::CheckCharVariable()
break;
}
if ( Token::Match(tok2, "%var% [&|] %varid%", 0, tok->varId()) || Token::Match(tok2, "%varid% [&|]", 0, tok->varId()) )
if ( Token::Match(tok2, "%var% [&|] %varid%", tok->varId()) || Token::Match(tok2, "%varid% [&|]", tok->varId()) )
{
std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok2) << ": Warning - using char variable in bit operation";

View File

@ -164,7 +164,7 @@ bool Token::simpleMatch(const Token *tok, const char pattern[])
return true;
}
bool Token::Match(const Token *tok, const char pattern[], const char *varname1[], unsigned int varid)
bool Token::Match(const Token *tok, const char pattern[], unsigned int varid, const char *varname1[] )
{
const char *p = pattern;
while ( *p )
@ -353,7 +353,7 @@ const Token *Token::findmatch(const Token *tok, const char pattern[], const char
{
for ( ; tok; tok = tok->next())
{
if ( Token::Match(tok, pattern, varname1) )
if ( Token::Match(tok, pattern, 0, varname1) )
return tok;
}
return 0;

View File

@ -105,7 +105,7 @@ public:
* @return true if given token matches with given pattern
* false if given token does not match with given pattern
*/
static bool Match(const Token *tok, const char pattern[], const char *varname1[]=0, unsigned int varid=0);
static bool Match(const Token *tok, const char pattern[], unsigned int varid=0, const char *varname1[]=0 );
bool isName() const;
bool isNumber() const;

View File

@ -1479,7 +1479,7 @@ bool Tokenizer::simplifyKnownVariables()
break;
// Replace variable with numeric constant..
if ( Token::Match(tok3, "if ( %varid% )", 0, varid) )
if ( Token::Match(tok3, "if ( %varid% )", varid) )
{
tok3 = tok3->next()->next();
tok3->str( tok2->strAt(2) );