Replace simpleMatch() to operator==() from std::string.

No functional change.
This commit is contained in:
Slava Semushin 2009-07-27 16:24:24 +07:00
parent 1ac496e707
commit 5ce151983e
8 changed files with 47 additions and 47 deletions

View File

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

View File

@ -321,7 +321,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::simpleMatch(constructor_token, "~"))
while (constructor_token && constructor_token->str() == "~")
constructor_token = Token::findmatch(constructor_token->next(), tempPattern.c_str());
// There are no constructor.
@ -687,7 +687,7 @@ void CheckClass::virtualDestructor()
derived = derived->tokAt(3);
while (Token::Match(derived, "%var%"))
{
bool isPublic = Token::simpleMatch(derived, "public");
bool isPublic(derived->str() == "public");
// What kind of inheritance is it.. public|protected|private
if (Token::Match(derived, "public|protected|private"))
@ -700,7 +700,7 @@ void CheckClass::virtualDestructor()
// Update derived so it's ready for the next loop.
derived = derived->next();
if (Token::simpleMatch(derived, ","))
if (derived->str() == ",")
derived = derived->next();
// If not public inheritance, skip checking of this base class..
@ -709,7 +709,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::simpleMatch(base, "::"))
while (base && base->str() == "::")
base = Token::findmatch(base->next(), (std::string("%any% ~ ") + baseName[0] + " (").c_str());
const Token *reverseTok = base;

View File

@ -146,7 +146,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
if (! tok2)
return No;
if (Token::simpleMatch(tok2, "realloc"))
if (tok2->str() == "realloc")
return Malloc;
// GTK memory reallocation..
@ -1062,7 +1062,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
done = false;
}
else if (Token::simpleMatch(tok2->next(), "if"))
else if (tok2->next() && tok2->next()->str() == "if")
{
// Delete empty if that is not followed by an else
if (Token::Match(tok2->next(), "if ; !!else"))
@ -1427,11 +1427,11 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
else if (_tok->str() == "loop")
break;
else if (incase && Token::simpleMatch(_tok, "case"))
else if (incase && _tok->str() == "case")
break;
incase |= Token::simpleMatch(_tok, "case");
incase &= !Token::simpleMatch(_tok, "break");
incase |= (_tok->str() == "case");
incase &= (_tok->str() != "break");
}
if (!incase && valid)
@ -1443,7 +1443,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
bool first = true;
while (Token::Match(tok2, "case|default"))
{
bool def = Token::simpleMatch(tok2, "default");
bool def(tok2->str() == "default");
tok2->str(first ? "if" : "}");
if (first)
{

View File

@ -49,10 +49,10 @@ void CheckOther::warningOldStylePointerCast()
continue;
int addToIndex = 0;
if (Token::simpleMatch(tok->tokAt(1), "const"))
if (tok->tokAt(1)->str() == "const")
addToIndex = 1;
if (Token::simpleMatch(tok->tokAt(4 + addToIndex), "const"))
if (tok->tokAt(4 + addToIndex)->str() == "const")
continue;
// Is "type" a class?
@ -223,7 +223,7 @@ void CheckOther::redundantCondition2()
const Token *tok = Token::findmatch(_tokenizer->tokens(), pattern);
while (tok)
{
bool b = Token::simpleMatch(tok->tokAt(15), "{");
bool b(tok->tokAt(15)->str() == "{");
// Get tokens for the fields %var% and %any%
const Token *var1 = tok->tokAt(2);
@ -383,11 +383,11 @@ void CheckOther::invalidFunctionUsage()
int param = 1;
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next())
{
if (Token::simpleMatch(tok2, "("))
if (tok2->str() == "(")
++parlevel;
else if (Token::simpleMatch(tok2, ")"))
else if (tok2->str() == ")")
--parlevel;
else if (parlevel == 1 && Token::simpleMatch(tok2, ","))
else if (parlevel == 1 && tok2->str() == ",")
{
++param;
if (param == 3)
@ -607,7 +607,7 @@ void CheckOther::lookupVar(const Token *tok1, const char varname[])
const Token *tok = tok1;
// Skip the variable declaration..
while (tok && !Token::simpleMatch(tok, ";"))
while (tok && tok->str() != ";")
tok = tok->next();
// Check if the variable is used in this indentlevel..
@ -873,7 +873,7 @@ void CheckOther::checkIncompleteStatement()
/* We are in an assignment, so it's not a statement.
* Skip until ";" */
while (!Token::simpleMatch(tok, ";"))
while (tok->str() != ";")
{
int level = 0;
do
@ -1092,7 +1092,7 @@ void CheckOther::nullPointer()
{
if (tok1->varId() == varid)
{
if (tok1->previous() && tok1->previous()->str() == "*" && !Token::simpleMatch(tok1->tokAt(-2), "*"))
if (tok1->previous() && tok1->previous()->str() == "*" && tok1->tokAt(-2)->str() != "*")
{
nullPointerError(tok1);
break;

View File

@ -251,9 +251,9 @@ void CheckStl::pushback()
// Using invalid pointer..
if (invalidPointer && tok2->varId() == pointerId)
{
if (Token::simpleMatch(tok2->previous(), "*"))
if (tok2->previous()->str() == "*")
invalidPointerError(tok2, tok2->str());
else if (Token::simpleMatch(tok2->next(), "."))
else if (tok2->next()->str() == ".")
invalidPointerError(tok2, tok2->str());
break;
}

View File

@ -57,7 +57,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer)
continue;
// If this is a template function, skip it
if (Token::simpleMatch(tok->previous(), ">"))
if (tok->previous() && tok->previous()->str() == ">")
continue;
const Token *funcname = 0;
@ -72,7 +72,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer)
// Check that ") {" is found..
for (const Token *tok2 = funcname; tok2; tok2 = tok2->next())
{
if (Token::simpleMatch(tok2, ")"))
if (tok2->str() == ")")
{
if (! Token::simpleMatch(tok2, ") {") && ! Token::simpleMatch(tok2, ") const {"))
funcname = NULL;

View File

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

View File

@ -450,7 +450,7 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
{
while (tok->next())
{
bool last = Token::simpleMatch(tok->next(), "}");
bool last(tok->next()->str() == "}");
// Unlink and delete tok->next()
tok->deleteNext();
@ -745,7 +745,7 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "else|return|typedef|delete"))
continue;
if (Token::simpleMatch(tok, "const"))
if (tok->str() == "const")
tok = tok->next();
if (Token::simpleMatch(tok, "std ::"))
@ -1236,7 +1236,7 @@ void Tokenizer::simplifyTokenList()
{
if (Token::Match(tempToken, "%var%"))
{
if (Token::simpleMatch(tempToken->next(), "."))
if (tempToken->next()->str() == ".")
{
// We are checking a class or struct, search next varname
tempToken = tempToken->tokAt(1);
@ -1254,7 +1254,7 @@ void Tokenizer::simplifyTokenList()
// nothing after this
tempToken = tempToken->tokAt(2);
}
else if (Token::simpleMatch(tempToken->next(), "["))
else if (tempToken->next()->str() == "[")
{
/** @todo We need to find closing ], then check for
* dots and arrows "var[some[0]]->other" */
@ -1468,7 +1468,7 @@ void Tokenizer::simplifyTokenList()
{
if (Token::Match(tok->next(), "( %type% * ) 0") || Token::Match(tok->next(), "( %type% %type% * ) 0"))
{
while (!Token::simpleMatch(tok->next(), "0"))
while (tok->next()->str() != "0")
tok->deleteNext();
}
}
@ -1581,7 +1581,7 @@ bool Tokenizer::removeReduntantConditions()
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (!Token::simpleMatch(tok, "if"))
if (tok->str() != "if")
continue;
if (!Token::Match(tok->tokAt(1), "( %bool% ) {"))
@ -1602,7 +1602,7 @@ bool Tokenizer::removeReduntantConditions()
// Handle if with else
if (elseTag && elseTag->str() == "else")
{
if (Token::simpleMatch(elseTag->next(), "if"))
if (elseTag->next()->str() == "if")
{
// Handle "else if"
if (boolValue == false)
@ -1625,11 +1625,11 @@ bool Tokenizer::removeReduntantConditions()
lastTagInIf = Tokenizer::findClosing(lastTagInIf, "{", "}");
lastTagInIf = lastTagInIf->next();
if (!Token::simpleMatch(lastTagInIf, "else"))
if (lastTagInIf->str() != "else")
break;
lastTagInIf = lastTagInIf->next();
if (Token::simpleMatch(lastTagInIf, "if"))
if (lastTagInIf->str() == "if")
lastTagInIf = lastTagInIf->next();
}
@ -1652,7 +1652,7 @@ bool Tokenizer::removeReduntantConditions()
}
else
{
if (Token::simpleMatch(elseTag->tokAt(1), "{"))
if (elseTag->tokAt(1)->str() == "{")
{
// Convert "if( true ) {aaa;} else {bbb;}" => "{aaa;}"
const Token *end = Tokenizer::findClosing(elseTag->tokAt(1), "{", "}");
@ -2076,9 +2076,9 @@ bool Tokenizer::simplifyCasts()
while (tok2->next() && parlevel >= 0)
{
tok2 = tok2->next();
if (Token::simpleMatch(tok2->next(), "("))
if (tok2->next()->str() == "(")
++parlevel;
else if (Token::simpleMatch(tok2->next(), ")"))
else if (tok2->next()->str() == ")")
--parlevel;
}
if (tok2->next())
@ -2412,7 +2412,7 @@ bool Tokenizer::simplifyIfAssign()
// Remember if there is a "!" or not. And delete it if there are.
bool isNot = false;
if (Token::simpleMatch(tok->tokAt(2), "!"))
if (tok->tokAt(2)->str() == "!")
{
isNot = true;
tok->next()->deleteNext();
@ -2674,13 +2674,13 @@ bool Tokenizer::simplifyKnownVariables()
continue;
}
else if (tok3->str() == "{" && Token::simpleMatch(tok3->previous(), ")"))
else if (tok3->str() == "{" && tok3->previous()->str() == ")")
{
// There is a possible loop after the assignment. Try to skip it.
bailOutFromLoop = tok3->link();
continue;
}
else if (tok3->str() == "}" && Token::simpleMatch(tok3->link()->previous(), ")"))
else if (tok3->str() == "}" && tok3->link()->previous()->str() == ")")
{
// Assignment was in the middle of possible loop, bail out.
break;
@ -2768,7 +2768,7 @@ bool Tokenizer::elseif()
if (indent == 0 && Token::Match(tok2, "}|;"))
{
if (!Token::simpleMatch(tok2->next(), "else"))
if (tok2->next()->str() != "else")
{
tok->insertToken("{");
tok2->insertToken("}");