Applied patch 0001-Use-Token-simpleMatch-instead-of-Token-Match-w

Author: php-coder

Ticket: http://apps.sourceforge.net/trac/cppcheck/ticket/323
This commit is contained in:
Daniel Marjamäki 2009-05-21 17:55:52 +02:00
parent 47e10b75e3
commit f182365bd2
9 changed files with 71 additions and 71 deletions

View File

@ -119,11 +119,11 @@ bool isStatic(const Token *tok)
{
bool res = false;
if (Token::Match(tok->tokAt(-1), "static "))
if (Token::simpleMatch(tok->tokAt(-1), "static "))
res = true;
else if (Token::Match(tok->tokAt(-2), "static "))
else if (Token::simpleMatch(tok->tokAt(-2), "static"))
res = true;
else if (Token::Match(tok->tokAt(-3), "static "))
else if (Token::simpleMatch(tok->tokAt(-3), "static"))
res = true;
//std::cout << __PRETTY_FUNCTION__ << " " << tok->str() << " " << res << std::endl;
@ -168,15 +168,15 @@ void CheckAutoVariables::autoVariables()
var_name = tok->tokAt(2)->str();
fp_list.push_back(var_name);
}
else if (begin_function && Token::Match(tok, "("))
else if (begin_function && Token::simpleMatch(tok, "("))
begin_function_decl = true;
else if (begin_function && Token::Match(tok, ")"))
else if (begin_function && Token::simpleMatch(tok, ")"))
{
begin_function_decl = false;
}
else if (begin_function && Token::Match(tok, "{"))
else if (begin_function && Token::simpleMatch(tok, "{"))
bindent++;
else if (begin_function && Token::Match(tok, "}"))
else if (begin_function && Token::simpleMatch(tok, "}"))
{
bindent--;
}

View File

@ -318,7 +318,7 @@ void CheckClass::constructors()
// Are there a class constructor?
std::string tempPattern = "%any% " + classNameToken->str() + " (";
const Token *constructor_token = Token::findmatch(tok1, tempPattern.c_str());
while (Token::Match(constructor_token, "~"))
while (Token::simpleMatch(constructor_token, "~"))
constructor_token = Token::findmatch(constructor_token->next(), tempPattern.c_str());
// There are no constructor.
@ -662,7 +662,7 @@ void CheckClass::virtualDestructor()
derived = derived->tokAt(3);
while (Token::Match(derived, "%var%"))
{
bool isPublic = Token::Match(derived, "public");
bool isPublic = Token::simpleMatch(derived, "public");
// What kind of inheritance is it.. public|protected|private
if (Token::Match(derived, "public|protected|private"))
@ -675,7 +675,7 @@ void CheckClass::virtualDestructor()
// Update derived so it's ready for the next loop.
derived = derived->next();
if (Token::Match(derived, ","))
if (Token::simpleMatch(derived, ","))
derived = derived->next();
// If not public inheritance, skip checking of this base class..
@ -684,7 +684,7 @@ void CheckClass::virtualDestructor()
// Find the destructor declaration for the base class.
const Token *base = Token::findmatch(_tokenizer->tokens(), (std::string("%any% ~ ") + baseName[0] + " (").c_str());
while (Token::Match(base, "::"))
while (Token::simpleMatch(base, "::"))
base = Token::findmatch(base->next(), (std::string("%any% ~ ") + baseName[0] + " (").c_str());
const Token *reverseTok = base;

View File

@ -68,9 +68,9 @@ void CheckFunctionUsage::parseTokens(const Tokenizer &tokenizer)
// Check that ") {" is found..
for (const Token *tok2 = funcname; tok2; tok2 = tok2->next())
{
if (Token::Match(tok2, ")"))
if (Token::simpleMatch(tok2, ")"))
{
if (! Token::Match(tok2, ") {") && ! Token::Match(tok2, ") const {"))
if (! Token::simpleMatch(tok2, ") {") && ! Token::simpleMatch(tok2, ") const {"))
funcname = NULL;
break;
}
@ -120,7 +120,7 @@ void CheckFunctionUsage::parseTokens(const Tokenizer &tokenizer)
else if (tok2->str() == ")")
{
--parlevel;
if (parlevel == 0 && (Token::Match(tok2, ") {") || Token::Match(tok2, ") const")))
if (parlevel == 0 && (Token::simpleMatch(tok2, ") {") || Token::simpleMatch(tok2, ") const")))
funcname = NULL;
if (parlevel <= 0)
break;

View File

@ -56,7 +56,7 @@ void CheckHeaders::WarningHeaderWithImplementation()
if (tok->fileIndex() == 0)
continue;
if (Token::Match(tok, ") {"))
if (Token::simpleMatch(tok, ") {"))
{
std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Found implementation in header";

View File

@ -110,10 +110,10 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType(const To
if (Token::Match(tok2, "new %type% ["))
return NewArray;
if (Token::Match(tok2, "fopen ("))
if (Token::simpleMatch(tok2, "fopen ("))
return File;
if (Token::Match(tok2, "popen ("))
if (Token::simpleMatch(tok2, "popen ("))
return Pipe;
// Userdefined allocation function..
@ -143,7 +143,7 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetReallocationType(const
if (! tok2)
return No;
if (Token::Match(tok2, "realloc"))
if (Token::simpleMatch(tok2, "realloc"))
return Malloc;
// GTK memory reallocation..
@ -810,7 +810,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Replace "{ }" with ";"
if (Token::Match(tok2->next(), "{ }"))
if (Token::simpleMatch(tok2->next(), "{ }"))
{
tok2->next()->str(";");
erase(tok2->next(), tok2->tokAt(3));
@ -842,7 +842,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Delete "if ; else ;"
else if (Token::Match(tok2->next(), "if ; else ;"))
else if (Token::simpleMatch(tok2->next(), "if ; else ;"))
{
erase(tok2, tok2->tokAt(4));
done = false;
@ -882,7 +882,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Reduce "if if" => "if"
else if (Token::Match(tok2, "if if"))
else if (Token::simpleMatch(tok2, "if if"))
{
erase(tok2, tok2->tokAt(2));
done = false;
@ -911,14 +911,14 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Reduce "if ; else return use ;" => "if return use ;"
else if (Token::Match(tok2->next(), "if ; else return use ;"))
else if (Token::simpleMatch(tok2->next(), "if ; else return use ;"))
{
erase(tok2->next(), tok2->tokAt(4));
done = false;
}
// Reduce "if return ; if return ;" => "if return ;"
else if (Token::Match(tok2->next(), "if return ; if return ;"))
else if (Token::simpleMatch(tok2->next(), "if return ; if return ;"))
{
erase(tok2, tok2->tokAt(4));
done = false;
@ -987,7 +987,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Reduce "else ;" => ";"
if (Token::Match(tok2->next(), "else ;"))
if (Token::simpleMatch(tok2->next(), "else ;"))
{
erase(tok2, tok2->tokAt(2));
done = false;
@ -1002,7 +1002,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
// Replace "dealloc use ;" with "dealloc ;"
if (Token::Match(tok2, "dealloc use ;"))
if (Token::simpleMatch(tok2, "dealloc use ;"))
{
erase(tok2, tok2->tokAt(2));
done = false;
@ -1018,7 +1018,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
// Reduce "do { alloc ; } " => "alloc ;"
// TODO: If the loop can be executed twice reduce to "loop alloc ;" instead
if (Token::Match(tok2->next(), "do { alloc ; }"))
if (Token::simpleMatch(tok2->next(), "do { alloc ; }"))
{
erase(tok2, tok2->tokAt(3));
erase(tok2->next()->next(), tok2->tokAt(4));
@ -1052,7 +1052,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Replace "loop ;" with ";"
if (Token::Match(tok2->next(), "loop ;"))
if (Token::simpleMatch(tok2->next(), "loop ;"))
{
erase(tok2, tok2->tokAt(2));
done = false;
@ -1073,7 +1073,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Replace "loop if return ;" with "if return ;"
if (Token::Match(tok2->next(), "loop if return"))
if (Token::simpleMatch(tok2->next(), "loop if return"))
{
erase(tok2, tok2->tokAt(2));
done = false;
@ -1130,7 +1130,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Reduce "if* alloc ; dealloc ;" => ";"
if (Token::Match(tok2->tokAt(2), "alloc ; dealloc ;") &&
if (Token::simpleMatch(tok2->tokAt(2), "alloc ; dealloc ;") &&
tok2->next()->str().find("if") == 0)
{
erase(tok2, tok2->tokAt(5));
@ -1159,14 +1159,14 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
}
// Delete second case in "case ; case ;"
while (Token::Match(tok2, "case ; case ;"))
while (Token::simpleMatch(tok2, "case ; case ;"))
{
erase(tok2, tok2->tokAt(3));
done = false;
}
// Replace switch with if (if not complicated)
if (Token::Match(tok2, "switch {"))
if (Token::simpleMatch(tok2, "switch {"))
{
// Right now, I just handle if there are a few case and perhaps a default.
bool valid = false;
@ -1191,11 +1191,11 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
else if (_tok->str() == "loop")
break;
else if (incase && Token::Match(_tok, "case"))
else if (incase && Token::simpleMatch(_tok, "case"))
break;
incase |= Token::Match(_tok, "case");
incase &= !Token::Match(_tok, "break");
incase |= Token::simpleMatch(_tok, "case");
incase &= !Token::simpleMatch(_tok, "break");
}
if (!incase && valid)
@ -1205,9 +1205,9 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
erase(tok2, tok2->tokAt(2));
tok2 = tok2->next();
bool first = true;
while (Token::Match(tok2, "case") || Token::Match(tok2, "default"))
while (Token::simpleMatch(tok2, "case") || Token::simpleMatch(tok2, "default"))
{
bool def = Token::Match(tok2, "default");
bool def = Token::simpleMatch(tok2, "default");
tok2->str(first ? "if" : "}");
if (first)
{
@ -1223,9 +1223,9 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
tok2->insertToken("else");
tok2 = tok2->next();
}
while (tok2 && tok2->str() != "}" && ! Token::Match(tok2, "break ;"))
while (tok2 && tok2->str() != "}" && ! Token::simpleMatch(tok2, "break ;"))
tok2 = tok2->next();
if (Token::Match(tok2, "break ;"))
if (Token::simpleMatch(tok2, "break ;"))
{
tok2->str(";");
tok2 = tok2->next()->next();
@ -1349,16 +1349,16 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
first = first->next();
bool noerr = false;
noerr |= Token::Match(first, "alloc ; }");
noerr |= Token::Match(first, "alloc ; dealloc ; }");
noerr |= Token::Match(first, "alloc ; return use ; }");
noerr |= Token::Match(first, "alloc ; use ; }");
noerr |= Token::Match(first, "alloc ; use ; return ; }");
noerr |= Token::Match(first, "if alloc ; dealloc ; }");
noerr |= Token::Match(first, "if alloc ; return use ; }");
noerr |= Token::Match(first, "if alloc ; use ; }");
noerr |= Token::Match(first, "alloc ; ifv return ; dealloc ; }");
noerr |= Token::Match(first, "alloc ; if return ; dealloc; }");
noerr |= Token::simpleMatch(first, "alloc ; }");
noerr |= Token::simpleMatch(first, "alloc ; dealloc ; }");
noerr |= Token::simpleMatch(first, "alloc ; return use ; }");
noerr |= Token::simpleMatch(first, "alloc ; use ; }");
noerr |= Token::simpleMatch(first, "alloc ; use ; return ; }");
noerr |= Token::simpleMatch(first, "if alloc ; dealloc ; }");
noerr |= Token::simpleMatch(first, "if alloc ; return use ; }");
noerr |= Token::simpleMatch(first, "if alloc ; use ; }");
noerr |= Token::simpleMatch(first, "alloc ; ifv return ; dealloc ; }");
noerr |= Token::simpleMatch(first, "alloc ; if return ; dealloc; }");
// Unhandled case..
if (! noerr)
@ -1397,7 +1397,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
// In function..
if (indentlevel == 0)
{
if (Token::Match(tok, ") {"))
if (Token::simpleMatch(tok, ") {"))
infunc = true;
else if (tok->str() == "::")

View File

@ -157,7 +157,7 @@ void CheckOther::redundantCondition2()
const Token *tok = Token::findmatch(_tokenizer->tokens(), pattern);
while (tok)
{
bool b = Token::Match(tok->tokAt(15), "{");
bool b = Token::simpleMatch(tok->tokAt(15), "{");
// Get tokens for the fields %var% and %any%
const Token *var1 = tok->tokAt(2);
@ -317,11 +317,11 @@ void CheckOther::InvalidFunctionUsage()
int param = 1;
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next())
{
if (Token::Match(tok2, "("))
if (Token::simpleMatch(tok2, "("))
++parlevel;
else if (Token::Match(tok2, ")"))
else if (Token::simpleMatch(tok2, ")"))
--parlevel;
else if (parlevel == 1 && Token::Match(tok2, ","))
else if (parlevel == 1 && Token::simpleMatch(tok2, ","))
{
++param;
if (param == 3)
@ -508,7 +508,7 @@ void CheckOther::CheckVariableScope()
if (indentlevel == 0)
func = false;
}
if (indentlevel == 0 && Token::Match(tok, ") {"))
if (indentlevel == 0 && Token::simpleMatch(tok, ") {"))
{
func = true;
}
@ -543,7 +543,7 @@ void CheckOther::CheckVariableScope_LookupVar(const Token *tok1, const char varn
const Token *tok = tok1;
// Skip the variable declaration..
while (tok && !Token::Match(tok, ";"))
while (tok && !Token::simpleMatch(tok, ";"))
tok = tok->next();
// Check if the variable is used in this indentlevel..
@ -778,12 +778,12 @@ void CheckOther::CheckIncompleteStatement()
if (parlevel != 0)
continue;
if (Token::Match(tok, "= {"))
if (Token::simpleMatch(tok, "= {"))
{
/* We are in an assignment, so it's not a statement.
* Skip until ";" */
while (!Token::Match(tok, ";"))
while (!Token::simpleMatch(tok, ";"))
{
int level = 0;
do

View File

@ -141,7 +141,7 @@ void CheckStl::erase()
{
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (Token::Match(tok, "for ("))
if (Token::simpleMatch(tok, "for ("))
{
for (const Token *tok2 = tok->tokAt(2); tok2 && tok2->str() != ";"; tok2 = tok2->next())
{
@ -262,7 +262,7 @@ void CheckStl::pushback()
// Iterator becomes invalid after push_back or push_front..
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (Token::Match(tok, "vector <"))
if (Token::simpleMatch(tok, "vector <"))
{
while (tok && tok->str() != ">")
tok = tok->next();
@ -336,7 +336,7 @@ void CheckStl::stlBoundries()
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
// Declaring iterator..
if (Token::Match(tok, "list <"))
if (Token::simpleMatch(tok, "list <"))
{
while (tok && tok->str() != ">")
tok = tok->next();

View File

@ -861,7 +861,7 @@ public:
{
if (tok->str() == ")")
break;
if (Token::Match(tok, ". . . )"))
if (Token::simpleMatch(tok, ". . . )"))
{
_variadic = true;
break;
@ -959,7 +959,7 @@ public:
}
}
}
if (_variadic && Token::Match(tok, ",") && tok->next() && Token::Match(tok->next(), "##"))
if (_variadic && Token::simpleMatch(tok, ",") && tok->next() && Token::simpleMatch(tok->next(), "##"))
{
optcomma = true;
continue;

View File

@ -1159,26 +1159,26 @@ void Tokenizer::simplifyTokenList()
{
if (Token::Match(tempToken, "%var%"))
{
if (Token::Match(tempToken->next(), "."))
if (Token::simpleMatch(tempToken->next(), "."))
{
// We are checking a class or struct, search next varname
tempToken = tempToken->tokAt(1);
continue;
}
else if (Token::Match(tempToken->next(), "- >"))
else if (Token::simpleMatch(tempToken->next(), "- >"))
{
// We are checking a class or struct, search next varname
tempToken = tempToken->tokAt(2);
continue;
}
else if (Token::Match(tempToken->next(), "++") ||
Token::Match(tempToken->next(), "--"))
else if (Token::simpleMatch(tempToken->next(), "++") ||
Token::simpleMatch(tempToken->next(), "--"))
{
// We have variable++ or variable--, there should be
// nothing after this
tempToken = tempToken->tokAt(2);
}
else if (Token::Match(tempToken->next(), "["))
else if (Token::simpleMatch(tempToken->next(), "["))
{
// TODO: We need to find closing ], then check for
// dots and arrows "var[some[0]]->other"
@ -2136,7 +2136,7 @@ bool Tokenizer::simplifyIfNot()
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "0 == (") ||
if (Token::simpleMatch(tok, "0 == (") ||
Token::Match(tok, "0 == %var%"))
{
tok->deleteNext();
@ -2152,7 +2152,7 @@ bool Tokenizer::simplifyIfNot()
ret = true;
}
if (tok->link() && Token::Match(tok, ") == 0"))
if (tok->link() && Token::simpleMatch(tok, ") == 0"))
{
tok->deleteNext();
tok->deleteNext();
@ -2220,13 +2220,13 @@ bool Tokenizer::simplifyKnownVariables()
continue;
}
else if (tok3->str() == "{" && Token::Match(tok3->previous(), ")"))
else if (tok3->str() == "{" && Token::simpleMatch(tok3->previous(), ")"))
{
// There is a possible loop after the assignment. Try to skip it.
bailOutFromLoop = tok3->link();
continue;
}
else if (tok3->str() == "}" && Token::Match(tok3->link()->previous(), ")"))
else if (tok3->str() == "}" && Token::simpleMatch(tok3->link()->previous(), ")"))
{
// Assignment was in the middle of possible loop, bail out.
break;