From 54adb910ec50d64f0b3d81587de23ea12579c02a Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Thu, 27 Oct 2011 10:41:34 +0200 Subject: [PATCH] Use Token::simpleMatch instead of Token::Match for simple patterns --- lib/checkautovariables.cpp | 4 ++-- lib/checkbufferoverrun.cpp | 4 ++-- lib/checkclass.cpp | 4 ++-- lib/checkmemoryleak.cpp | 6 +++--- lib/checkother.cpp | 2 +- lib/checkstl.cpp | 6 +++--- lib/checkunusedvar.cpp | 4 ++-- lib/symboldatabase.cpp | 2 +- lib/tokenize.cpp | 16 ++++++++-------- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 93ff29b8e..cd6660ef3 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -139,7 +139,7 @@ void CheckAutoVariables::autoVariables() else if (Token::Match(tok, "return & %var% ;") && isAutoVar(tok->tokAt(2)->varId())) { errorReturnAddressToAutoVariable(tok); } else if (Token::Match(tok, "return & %var% [") && - Token::Match(tok->tokAt(3)->link(), "] ;") && + Token::simpleMatch(tok->tokAt(3)->link(), "] ;") && isAutoVarArray(tok->tokAt(2)->varId())) { errorReturnAddressToAutoVariable(tok); } else if (Token::Match(tok, "return & %var% ;") && tok->tokAt(2)->varId()) { @@ -275,7 +275,7 @@ void CheckAutoVariables::returnReference() // have we reached a function that returns a reference? if (Token::Match(tok->tokAt(-2), "%type% &") || - Token::Match(tok->tokAt(-2), "> &")) { + Token::simpleMatch(tok->tokAt(-2), "> &")) { // go to the '(' const Token *tok2 = scope->classDef->next(); diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index c79923706..28e525523 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -874,7 +874,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectortokAt(-2); // just taking the address? - const bool addr(Token::Match(tok3, "&") || + const bool addr(Token::simpleMatch(tok3, "&") || Token::simpleMatch(tok3->tokAt(-1), "& (")); // taking address of 1 past end? @@ -1065,7 +1065,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo tok2 = tok2->tokAt(-2); // just taking the address? - const bool addr(Token::Match(tok2, "&") || + const bool addr(Token::simpleMatch(tok2, "&") || Token::simpleMatch(tok2->tokAt(-1), "& (")); // taking address of 1 past end? diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 7b1720241..73bd38aee 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -814,7 +814,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co if (tok->str() == "return") { foundReturn = true; std::string cast("( " + scope->className + " & )"); - if (Token::Match(tok->next(), cast.c_str())) + if (Token::simpleMatch(tok->next(), cast.c_str())) tok = tok->tokAt(4); // check if a function is called @@ -1277,7 +1277,7 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) if (tok->str() == "this") { return true; - } else if (Token::Match(tok->tokAt(-3), "( * this )")) { + } else if (Token::simpleMatch(tok->tokAt(-3), "( * this )")) { return true; } else if (Token::Match(tok->tokAt(-2), "%var% . %var%")) { tok = tok->tokAt(-2); diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index c89fb8081..48365b253 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1737,7 +1737,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) } // Reduce "; if(!var) exit ;" => ";" - if (Token::Match(tok2, "; if(!var) exit ;")) { + if (Token::simpleMatch(tok2, "; if(!var) exit ;")) { Token::eraseTokens(tok2, tok2->tokAt(3)); done = false; } @@ -1899,7 +1899,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) } // Delete if block in "alloc ; if(!var) return ;" - if (Token::Match(tok2, "alloc ; if(!var) return ;")) { + if (Token::simpleMatch(tok2, "alloc ; if(!var) return ;")) { Token::eraseTokens(tok2, tok2->tokAt(4)); done = false; } @@ -2505,7 +2505,7 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam } // Allocate.. - if (indent == 0 || Token::Match(tok, (varname + " =").c_str())) { + if (indent == 0 || Token::simpleMatch(tok, (varname + " =").c_str())) { // var1 = var2 = ... // bail out if (Token::simpleMatch(tok->previous(), "=")) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b9c027a8e..616d3606c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -178,7 +178,7 @@ void CheckOther::clarifyCondition() if (Token::Match(tok2, "[&|^]")) { // don't write false positives when templates are used if (Token::Match(tok, "<|>") && (Token::Match(tok2, "& ,|>") || - Token::Match(tok2->previous(), "const &"))) + Token::simpleMatch(tok2->previous(), "const &"))) continue; clarifyConditionError(tok,false,true); diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 366b5b8ed..d04d4e9cc 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1028,10 +1028,10 @@ void CheckStl::string_c_str() localvar.find(tok->next()->varId()) != localvar.end()) { string_c_strError(tok); } else if (Token::simpleMatch(tok, "return std :: string (") && - Token::Match(tok->tokAt(4)->link(), ") . c_str ( ) ;")) { + Token::simpleMatch(tok->tokAt(4)->link(), ") . c_str ( ) ;")) { string_c_strError(tok); } else if (Token::simpleMatch(tok, "return (") && - Token::Match(tok->next()->link(), ") . c_str ( ) ;")) { + Token::simpleMatch(tok->next()->link(), ") . c_str ( ) ;")) { // Check for "+ localvar" or "+ std::string(" inside the bracket bool is_implicit_std_string = false; const Token *search_end = tok->next()->link(); @@ -1082,7 +1082,7 @@ void CheckStl::checkAutoPointer() for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { if (Token::simpleMatch(tok, "auto_ptr <")) { if ((tok->previous() && tok->previous()->str() == "<" && Token::Match(tok->tokAt(-2), STL_CONTAINER_LIST)) || - (Token::Match(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) { + (Token::simpleMatch(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) { autoPointerContainerError(tok); } else { const Token *tok2 = tok->next()->next(); diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index d96828e8b..b394f6d7b 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1086,8 +1086,8 @@ void CheckUnusedVar::checkFunctionVariableUsage() const Token *type = start->tokAt(3); // skip nothrow - if (Token::Match(type, "( nothrow )") || - Token::Match(type, "( std :: nothrow )")) + if (Token::simpleMatch(type, "( nothrow )") || + Token::simpleMatch(type, "( std :: nothrow )")) type = type->link()->next(); // is it a user defined type? diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 2b05909cd..c61e370b5 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1438,7 +1438,7 @@ void Scope::getVariableList() } else if (Token::Match(tok, "struct|union {") && Token::Match(tok->next()->link(), "} %var% ;|[")) { tok = tok->next()->link()->next()->next(); continue; - } else if (Token::Match(tok, "struct|union {") && Token::Match(tok->next()->link(), "} ;")) { + } else if (Token::Match(tok, "struct|union {") && Token::simpleMatch(tok->next()->link(), "} ;")) { level++; tok = tok->next(); continue; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 517e48304..f003a34d7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1198,7 +1198,7 @@ void Tokenizer::simplifyTypedef() // pointer to function returning pointer to function else if (Token::Match(tok->tokAt(offset), "( * ( * %type% ) (") && - Token::Match(tok->tokAt(offset + 6)->link(), ") ) (") && + Token::simpleMatch(tok->tokAt(offset + 6)->link(), ") ) (") && Token::Match(tok->tokAt(offset + 6)->link()->tokAt(2)->link(), ") ;|,")) { functionPtrRetFuncPtr = true; @@ -3075,7 +3075,7 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok, // copy addtoken(tok3, tok3->linenr(), tok3->fileIndex()); if (Token::Match(tok3, "%type% <")) { - if (!Token::Match(tok3, (name + " <").c_str())) + if (!Token::simpleMatch(tok3, (name + " <").c_str())) done = false; used.push_back(_tokensBack); } @@ -3280,7 +3280,7 @@ void Tokenizer::setVarId() if (tok->strAt(-1) == "return") continue; if (tok->link() && !Token::Match(tok->link()->tokAt(1), "const| {") && - !Token::Match(tok->link()->tokAt(1), ":")) + !Token::simpleMatch(tok->link()->tokAt(1), ":")) continue; } @@ -3325,7 +3325,7 @@ void Tokenizer::setVarId() tok = tok->next(); // skip global namespace prefix - if (Token::Match(tok, "::")) + if (Token::simpleMatch(tok, "::")) tok = tok->next(); while (Token::Match(tok, "%var% ::")) @@ -4409,7 +4409,7 @@ void Tokenizer::simplifyFlowControl() --indentlevel; } for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { - if (Token::Match(tok2, ": ;")) { + if (Token::simpleMatch(tok2, ": ;")) { if (indentlevel == indentcase) { ++indentlevel; } @@ -6203,8 +6203,8 @@ void Tokenizer::simplifyIfNotNull() if (Token::Match(tok->tokAt(-2), "[;{}] %var%")) { const std::string varname(tok->previous()->str()); - if (Token::Match(tok->tokAt(2), (varname + " != 0 ) ;").c_str()) || - Token::Match(tok->tokAt(2), ("0 != " + varname + " ) ;").c_str())) { + if (Token::simpleMatch(tok->tokAt(2), (varname + " != 0 ) ;").c_str()) || + Token::simpleMatch(tok->tokAt(2), ("0 != " + varname + " ) ;").c_str())) { tok = tok->tokAt(-2); Token::eraseTokens(tok, tok->tokAt(9)); } @@ -7397,7 +7397,7 @@ void Tokenizer::simplifyGoto() if (tok->str() == "{") { if ((tok->tokAt(-2) && Token::Match(tok->tokAt(-2),"namespace|struct|class|union %var% {")) || - (tok->previous() && Token::Match(tok->previous(),"namespace {"))) + (tok->previous() && Token::simpleMatch(tok->previous(),"namespace {"))) ++indentspecial; else if (!beginfunction && !indentlevel) tok = tok->link();