From f8e2d50e6fbb8b27ac215348962d866bba34b1c5 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Wed, 2 Feb 2011 10:12:46 -0600 Subject: [PATCH] Use Token::simpleMatch where no special patterns are needed --- lib/checkbufferoverrun.cpp | 2 +- lib/checkclass.cpp | 6 +++--- lib/checkmemoryleak.cpp | 6 +++--- lib/checknullpointer.cpp | 2 +- lib/checkother.cpp | 2 +- lib/checkstl.cpp | 2 +- lib/symboldatabase.cpp | 2 +- lib/tokenize.cpp | 34 +++++++++++++++++----------------- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index d4340048c..c0afdce94 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -828,7 +828,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(3)); if (index < 0 || index >= size) { - if (index > size || !Token::Match(tok->previous(), "& (")) + if (index > size || !Token::simpleMatch(tok->previous(), "& (")) { arrayIndexOutOfBounds(tok->next(), size, index); } diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 8f71226ad..53dd353a2 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -799,7 +799,7 @@ void CheckClass::noMemset() if (Token::Match(tstruct->next(), "std :: %type% %var% ;")) memsetStructError(tok, tok->str(), tstruct->strAt(3)); - else if (Token::Match(tstruct->next(), "std :: %type% < ")) + else if (Token::Match(tstruct->next(), "std :: %type% <")) { // backup the type const std::string typestr(tstruct->strAt(3)); @@ -1132,7 +1132,7 @@ bool CheckClass::hasAssignSelf(const Token *first, const Token *last, const Toke { for (const Token *tok = first; tok && tok != last; tok = tok->next()) { - if (Token::Match(tok, "if (")) + if (Token::simpleMatch(tok, "if (")) { const Token *tok1 = tok->tokAt(2); const Token *tok2 = tok->tokAt(1)->link(); @@ -1412,7 +1412,7 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) while (tok->previous() && !Token::Match(tok->previous(), "}|{|;|public:|protected:|private:|return|:|?")) { - if (Token::Match(tok->previous(), "* this")) + if (Token::simpleMatch(tok->previous(), "* this")) return true; tok = tok->previous(); diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index f539e431c..97a8ea249 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1445,7 +1445,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr(";"); Token::eraseTokens(tok2, tok2->tokAt(4)); @@ -1820,7 +1820,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) } // Reduce "if continue ; if continue ;" => "if continue ;" - else if (Token::Match(tok2->next(), "if continue ; if continue ;")) + else if (Token::simpleMatch(tok2->next(), "if continue ; if continue ;")) { Token::eraseTokens(tok2, tok2->tokAt(4)); done = false; diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index df8c49495..ff951f5ba 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -617,7 +617,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() if (null && indentlevel == 0) { // skip all "else" blocks because they are not executed in this execution path - while (Token::Match(tok2, "} else {")) + while (Token::simpleMatch(tok2, "} else {")) tok2 = tok2->tokAt(2)->link(); null = false; } diff --git a/lib/checkother.cpp b/lib/checkother.cpp index bf96eedf7..4e5ff04cd 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2705,7 +2705,7 @@ void CheckOther::checkMisusedScopedObject() } if (Token::Match(tok, "[;{}] %var% (") - && Token::Match(tok->tokAt(2)->link(), ") ;") + && Token::simpleMatch(tok->tokAt(2)->link(), ") ;") && symbolDatabase->isClassOrStruct(tok->next()->str()) ) { diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 6ae97742b..a2c871db3 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1038,7 +1038,7 @@ void CheckStl::string_c_str() string_c_strError(tok); } else if (Token::Match(tok, "[;{}] %var% = %var% (") && - Token::Match(tok->tokAt(4)->link(), ") . c_str ( ) ;") && + Token::simpleMatch(tok->tokAt(4)->link(), ") . c_str ( ) ;") && tok->next()->varId() > 0 && pointers.find(tok->next()->varId()) != pointers.end() && Token::findmatch(_tokenizer->tokens(), ("std :: string " + tok->strAt(3) + " (").c_str())) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index cf69b6196..b7e9f8ea3 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1238,7 +1238,7 @@ bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const const Token* localTypeTok = skipScopeIdentifiers(tok); const Token* localVarTok = NULL; - if (Token::Match(localTypeTok, "%type% < ")) + if (Token::Match(localTypeTok, "%type% <")) { const Token* closeTok = NULL; bool found = findClosingBracket(localTypeTok->next(), closeTok); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 210fe3702..f747e4a06 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -588,7 +588,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) (tok->previous()->str() == "*" && tok->next()->str() != "(") || (Token::Match(tok->previous(), "%type%") && (!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected|throw|extern") && - !Token::Match(tok->tokAt(-2), "friend class")))) + !Token::simpleMatch(tok->tokAt(-2), "friend class")))) { // scan backwards for the end of the previous statement int level = (tok->previous()->str() == "}") ? 1 : 0; @@ -926,7 +926,7 @@ void Tokenizer::simplifyTypedef() Token *namespaceStart = 0; Token *namespaceEnd = 0; - if (Token::Match(tok->next(), "::") || + if (Token::simpleMatch(tok->next(), "::") || Token::Match(tok->next(), "%type%")) { typeStart = tok->next(); @@ -940,13 +940,13 @@ void Tokenizer::simplifyTypedef() bool atEnd = false; while (!atEnd) { - if (Token::Match(tok->tokAt(offset), "::")) + if (Token::simpleMatch(tok->tokAt(offset), "::")) typeEnd = tok->tokAt(offset++); if (Token::Match(tok->tokAt(offset), "%type%") && tok->tokAt(offset + 1) && !Token::Match(tok->tokAt(offset + 1), "[|;|,|(")) typeEnd = tok->tokAt(offset++); - else if (Token::Match(tok->tokAt(offset), "const (")) + else if (Token::simpleMatch(tok->tokAt(offset), "const (")) { typeEnd = tok->tokAt(offset++); atEnd = true; @@ -1040,7 +1040,7 @@ void Tokenizer::simplifyTypedef() tok = tok->tokAt(offset); // or a function typedef - else if (Token::Match(tok->tokAt(offset), "(")) + else if (Token::simpleMatch(tok->tokAt(offset), "(")) { // unhandled typedef, skip it and continue if (typeName->str() == "void") @@ -1143,7 +1143,7 @@ void Tokenizer::simplifyTypedef() // function returning pointer to function else if (Token::Match(tok->tokAt(offset), "( * %type% (") && - Token::Match(tok->tokAt(offset + 3)->link(), ") ) (")) + Token::simpleMatch(tok->tokAt(offset + 3)->link(), ") ) (")) { functionRetFuncPtr = true; @@ -1397,8 +1397,8 @@ void Tokenizer::simplifyTypedef() inTemplate = true; // check for operator - if (Token::Match(tok2->previous(), "operator") || - Token::Match(tok2->tokAt(-2), "operator const")) + if (Token::simpleMatch(tok2->previous(), "operator") || + Token::simpleMatch(tok2->tokAt(-2), "operator const")) inOperator = true; // skip over class or struct in derived class declaration @@ -2717,7 +2717,7 @@ void Tokenizer::simplifyTemplates() ostr << " "; ostr << tok3->str(); } - if (!Token::Match(tok3, "> (")) + if (!Token::simpleMatch(tok3, "> (")) continue; s = ostr.str(); } @@ -3999,7 +3999,7 @@ void Tokenizer::simplifySizeof() tok->next()->deleteNext(); } - if (Token::Match(tok->next(), "( * )")) + if (Token::simpleMatch(tok->next(), "( * )")) { tok->str(MathLib::toString(sizeOfType(tok->tokAt(2)))); Token::eraseTokens(tok, tok->tokAt(4)); @@ -4711,7 +4711,7 @@ void Tokenizer::simplifyIfAddBraces() if (!innerIf) break; - if (Token::Match(tempToken, "; else if")) + if (Token::simpleMatch(tempToken, "; else if")) ; else if (Token::Match(tempToken, "; else")) innerIf = false; @@ -4754,7 +4754,7 @@ bool Tokenizer::simplifyDoWhileAddBracesHelper(Token *tok) tok2 = tok3; break; } - else if (Token::Match(tok3, "do {")) + else if (Token::simpleMatch(tok3, "do {")) { // Skip do{}while inside the current "do" tok3 = tok3->next()->link(); @@ -5758,7 +5758,7 @@ void Tokenizer::simplifyStdType() tok->isSigned(!isUnsigned); } - if (Token::Match(tok, "__int8")) + if (Token::simpleMatch(tok, "__int8")) tok->str("char"); else if (Token::Match(tok, "__int16")) tok->str("short"); @@ -7492,7 +7492,7 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name) if (end) { - if (Token::Match(end, ") {")) // function parameter ? + if (Token::simpleMatch(end, ") {")) // function parameter ? { // look backwards if (tok->previous()->str() == "enum" || @@ -7908,7 +7908,7 @@ void Tokenizer::simplifyEnum() } else if (tok2->str() == "{") ++level; - else if (!pattern.empty() && ((Token::Match(tok2, "enum") && Token::Match(tok2->next(), pattern.c_str())) || Token::Match(tok2, pattern.c_str()))) + else if (!pattern.empty() && ((Token::simpleMatch(tok2, "enum") && Token::Match(tok2->next(), pattern.c_str())) || Token::Match(tok2, pattern.c_str()))) { simplify = true; hasClass = true; @@ -8243,7 +8243,7 @@ void Tokenizer::simplifyComma() // We must not accept just any keyword, e.g. accepting int // would cause function parameters to corrupt. - if (Token::Match(tok->next(), "delete")) + if (Token::simpleMatch(tok->next(), "delete")) { // Handle "delete a, delete b;" tok->str(";"); @@ -8566,7 +8566,7 @@ void Tokenizer::simplifyStructInit() if (Token::simpleMatch(tok2, ", .")) tok2 = tok2->next(); } - if (!Token::Match(tok2, "} ;")) + if (!Token::simpleMatch(tok2, "} ;")) continue; // Known expression format => Perform simplification