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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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