From f336c2efe778cd24d2c9f4ddddb553c24fc205fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 27 Apr 2018 22:36:30 +0200 Subject: [PATCH] Refactoring; Renamed Scope::classStart and Scope::classEnd --- lib/check64bit.cpp | 4 +- lib/checkassert.cpp | 4 +- lib/checkautovariables.cpp | 16 +++---- lib/checkbool.cpp | 18 ++++---- lib/checkboost.cpp | 2 +- lib/checkbufferoverrun.cpp | 32 +++++++------- lib/checkclass.cpp | 44 +++++++++---------- lib/checkcondition.cpp | 20 ++++----- lib/checkexceptionsafety.cpp | 22 +++++----- lib/checkfunctions.cpp | 14 +++--- lib/checkinternal.cpp | 14 +++--- lib/checkio.cpp | 8 ++-- lib/checkleakautovar.cpp | 8 ++-- lib/checkmemoryleak.cpp | 42 +++++++++--------- lib/checknullpointer.cpp | 10 ++--- lib/checkother.cpp | 84 ++++++++++++++++++------------------ lib/checkpostfixoperator.cpp | 2 +- lib/checksizeof.cpp | 6 +-- lib/checkstl.cpp | 38 ++++++++-------- lib/checkstring.cpp | 12 +++--- lib/checktype.cpp | 2 +- lib/checkuninitvar.cpp | 10 ++--- lib/checkunusedfunctions.cpp | 2 +- lib/checkunusedvar.cpp | 22 +++++----- lib/checkvaarg.cpp | 8 ++-- lib/symboldatabase.cpp | 78 ++++++++++++++++----------------- lib/symboldatabase.h | 4 +- lib/templatesimplifier.cpp | 6 +-- lib/tokenize.cpp | 22 +++++----- lib/valueflow.cpp | 44 +++++++++---------- test/testmemleak.cpp | 2 +- test/testsymboldatabase.cpp | 6 +-- 32 files changed, 303 insertions(+), 303 deletions(-) diff --git a/lib/check64bit.cpp b/lib/check64bit.cpp index 26b2786ee..619613a1f 100644 --- a/lib/check64bit.cpp +++ b/lib/check64bit.cpp @@ -61,7 +61,7 @@ void Check64BitPortability::pointerassignment() else continue; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // skip nested functions if (tok->str() == "{") { if (tok->scope()->type == Scope::ScopeType::eFunction || tok->scope()->type == Scope::ScopeType::eLambda) @@ -88,7 +88,7 @@ void Check64BitPortability::pointerassignment() // Check assignments for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() != "=") continue; diff --git a/lib/checkassert.cpp b/lib/checkassert.cpp index a478944f2..e7c576a2d 100644 --- a/lib/checkassert.cpp +++ b/lib/checkassert.cpp @@ -63,7 +63,7 @@ void CheckAssert::assertWithSideEffects() const Scope* scope = f->functionScope; if (!scope) continue; - for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) { + for (const Token *tok2 = scope->bodyStart; tok2 != scope->bodyEnd; tok2 = tok2->next()) { if (tok2->tokType() != Token::eAssignmentOp && tok2->tokType() != Token::eIncDecOp) continue; @@ -74,7 +74,7 @@ void CheckAssert::assertWithSideEffects() continue; // Pointers need to be dereferenced, otherwise there is no error bool noReturnInScope = true; - for (const Token *rt = scope->classStart; rt != scope->classEnd; rt = rt->next()) { + for (const Token *rt = scope->bodyStart; rt != scope->bodyEnd; rt = rt->next()) { if (rt->str() != "return") continue; // find all return statements if (inSameScope(rt, tok2)) { noReturnInScope = false; diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index b8824d9cb..cb55cc224 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -165,7 +165,7 @@ static bool variableIsUsedInScope(const Token* start, unsigned int varId, const if (!start) // Ticket #5024 return false; - for (const Token *tok = start; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = start; tok && tok != scope->bodyEnd; tok = tok->next()) { if (tok->varId() == varId) return true; const Scope::ScopeType scopeType = tok->scope()->type; @@ -186,7 +186,7 @@ void CheckAutoVariables::assignFunctionArg() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { // TODO: What happens if this is removed? if (tok->astParent()) continue; @@ -196,7 +196,7 @@ void CheckAutoVariables::assignFunctionArg() if (isNonReferenceArg(vartok) && !Token::Match(vartok->next(), "= %varid% ;", vartok->varId()) && !variableIsUsedInScope(Token::findsimplematch(vartok->next(), ";"), vartok->varId(), scope) && - !Token::findsimplematch(vartok, "goto", scope->classEnd)) { + !Token::findsimplematch(vartok, "goto", scope->bodyEnd)) { if (vartok->variable()->isPointer() && printWarning) errorUselessAssignmentPtrArg(vartok); else if (printStyle) @@ -208,7 +208,7 @@ void CheckAutoVariables::assignFunctionArg() static bool reassignedGlobalPointer(const Token *vartok, unsigned int pointerVarId) { - const Token * const end = vartok->variable()->typeStartToken()->scope()->classEnd; + const Token * const end = vartok->variable()->typeStartToken()->scope()->bodyEnd; for (const Token *tok2 = vartok; tok2 != nullptr && tok2 != end; tok2 = tok2->next()) { if (Token::Match(tok2, "%varid% =", pointerVarId)) return true; @@ -227,7 +227,7 @@ void CheckAutoVariables::autoVariables() const bool printInconclusive = _settings->inconclusive; const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { // Critical assignment if (Token::Match(tok, "[;{}] %var% = & %var%") && isRefPtrArg(tok->next()) && isAutoVar(tok->tokAt(4))) { if (checkRvalueExpression(tok->tokAt(4))) @@ -335,7 +335,7 @@ void CheckAutoVariables::returnPointerToLocalArray() // have we reached a function that returns a pointer if (tok->previous() && tok->previous()->str() == "*") { - for (const Token *tok2 = scope->classStart->next(); tok2 && tok2 != scope->classEnd; tok2 = tok2->next()) { + for (const Token *tok2 = scope->bodyStart->next(); tok2 && tok2 != scope->bodyEnd; tok2 = tok2->next()) { // Return pointer to local array variable.. if (tok2 ->str() == "return" && isAutoVarArray(tok2->astOperand1())) { errorReturnPointerToLocalArray(tok2); @@ -519,9 +519,9 @@ void CheckAutoVariables::returnReference() // have we reached a function that returns a reference? if (tok->previous() && tok->previous()->str() == "&") { - for (const Token *tok2 = scope->classStart->next(); tok2 && tok2 != scope->classEnd; tok2 = tok2->next()) { + for (const Token *tok2 = scope->bodyStart->next(); tok2 && tok2 != scope->bodyEnd; tok2 = tok2->next()) { if (!tok2->scope()->isExecutable()) { - tok2 = tok2->scope()->classEnd; + tok2 = tok2->scope()->bodyEnd; if (!tok2) break; continue; diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index 3beef1c33..cf809e7fd 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -59,7 +59,7 @@ void CheckBool::checkIncrementBoolean() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%var% ++")) { const Variable *var = tok->variable(); if (isBool(var)) @@ -97,7 +97,7 @@ void CheckBool::checkBitwiseOnBoolean() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "(|.|return|&&|%oror%|throw|, %var% [&|]")) { const Variable *var = tok->next()->variable(); if (isBool(var)) { @@ -134,7 +134,7 @@ void CheckBool::checkComparisonOfBoolWithInt() const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { const Token* const left = tok->astOperand1(); const Token* const right = tok->astOperand2(); if (left && right && tok->isComparisonOp()) { @@ -187,7 +187,7 @@ void CheckBool::checkComparisonOfFuncReturningBool() const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=") continue; const Token *firstToken = tok->previous(); @@ -249,7 +249,7 @@ void CheckBool::checkComparisonOfBoolWithBool() const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=") continue; bool firstTokenBool = false; @@ -291,7 +291,7 @@ void CheckBool::checkAssignBoolToPointer() { const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() == "=" && astIsBool(tok->astOperand2())) { const Token *lhs = tok->astOperand1(); while (lhs && (lhs->str() == "." || lhs->str() == "::")) @@ -321,7 +321,7 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt() const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!tok->isComparisonOp()) continue; @@ -391,7 +391,7 @@ void CheckBool::pointerArithBool() if (tok) tok = tok->astOperand1(); } else if (scope.type == Scope::eDo) - tok = (scope.classEnd->tokAt(2)) ? scope.classEnd->tokAt(2)->astOperand2() : nullptr; + tok = (scope.bodyEnd->tokAt(2)) ? scope.bodyEnd->tokAt(2)->astOperand2() : nullptr; pointerArithBoolCond(tok); } @@ -435,7 +435,7 @@ void CheckBool::checkAssignBoolToFloat() return; const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() == "=" && astIsBool(tok->astOperand2())) { const Token *lhs = tok->astOperand1(); while (lhs && (lhs->str() == "." || lhs->str() == "::")) diff --git a/lib/checkboost.cpp b/lib/checkboost.cpp index 7aaf9a438..4b3a4c181 100644 --- a/lib/checkboost.cpp +++ b/lib/checkboost.cpp @@ -35,7 +35,7 @@ void CheckBoost::checkBoostForeachModification() { const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token *tok = scope->classStart->next(); tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart->next(); tok && tok != scope->bodyEnd; tok = tok->next()) { if (!Token::simpleMatch(tok, "BOOST_FOREACH (")) continue; diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index daa2da5d0..60ec1b48d 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -461,7 +461,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int return; // Check the parameter usage in the function scope.. - for (const Token* ftok2 = func->functionScope->classStart; ftok2 != func->functionScope->classEnd; ftok2 = ftok2->next()) { + for (const Token* ftok2 = func->functionScope->bodyStart; ftok2 != func->functionScope->bodyEnd; ftok2 = ftok2->next()) { if (Token::Match(ftok2, "if|for|switch|while (")) { // bailout if there is buffer usage.. if (bailoutIfSwitch(ftok2, parameter->declarationId())) { @@ -614,7 +614,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorisEnabled(Settings::PORTABILITY); - for (const Token* const end = tok->scope()->classEnd; tok && tok != end; tok = tok->next()) { + for (const Token* const end = tok->scope()->bodyEnd; tok && tok != end; tok = tok->next()) { if (declarationId != 0 && Token::Match(tok, "%varid% = new|malloc|realloc", declarationId)) { // Abort break; @@ -899,7 +899,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo { bool reassigned = false; - for (const Token* const end = tok->scope()->classEnd; tok != end; tok = tok->next()) { + for (const Token* const end = tok->scope()->bodyEnd; tok != end; tok = tok->next()) { if (reassigned && tok->str() == ";") break; @@ -918,7 +918,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, std::mapscope()->classEnd; tok != end; tok = tok->next()) { + for (const Token* const end = tok->scope()->bodyEnd; tok != end; tok = tok->next()) { if (reassigned && tok->str() == ";") { arrayInfos.erase(reassigned); reassigned = 0; @@ -1233,7 +1233,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() arrayInfos[var->declarationId()] = ArrayInfo(&*var, symbolDatabase, var->declarationId()); } if (!arrayInfos.empty()) - checkScope(scope->classStart ? scope->classStart : _tokenizer->tokens(), arrayInfos); + checkScope(scope->bodyStart ? scope->bodyStart : _tokenizer->tokens(), arrayInfos); } const std::vector v; @@ -1243,7 +1243,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "[*;{}] %var% =")) continue; @@ -1355,9 +1355,9 @@ void CheckBufferOverrun::checkStructVariable() // check for member variables if (func_scope->functionOf == scope) { // only check non-empty function - if (func_scope->classStart->next() != func_scope->classEnd) { + if (func_scope->bodyStart->next() != func_scope->bodyEnd) { // start checking after the { - const Token *tok = func_scope->classStart->next(); + const Token *tok = func_scope->bodyStart->next(); checkScope(tok, arrayInfo); } } @@ -1370,7 +1370,7 @@ void CheckBufferOverrun::checkStructVariable() std::vector varname = { nullptr, &arrayInfo.varname() }; // search the function and it's parameters - for (const Token *tok3 = func_scope->classDef; tok3 && tok3 != func_scope->classEnd; tok3 = tok3->next()) { + for (const Token *tok3 = func_scope->classDef; tok3 && tok3 != func_scope->bodyEnd; tok3 = tok3->next()) { // search for the class/struct name if (tok3->str() != scope->className) continue; @@ -1442,7 +1442,7 @@ void CheckBufferOverrun::checkStructVariable() // Goto end of statement. const Token *checkTok = nullptr; - while (tok3 && tok3 != func_scope->classEnd) { + while (tok3 && tok3 != func_scope->bodyEnd) { // End of statement. if (tok3->str() == ";") { checkTok = tok3; @@ -1703,7 +1703,7 @@ void CheckBufferOverrun::checkBufferAllocatedWithStrlen() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token *tok = scope->classStart->next(); tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart->next(); tok && tok != scope->bodyEnd; tok = tok->next()) { const unsigned int dstVarId = tok->varId(); if (!dstVarId || tok->strAt(1) != "=") continue; @@ -1729,7 +1729,7 @@ void CheckBufferOverrun::checkBufferAllocatedWithStrlen() // To avoid false positives and added complexity, we will only look for // improper usage of the buffer within the block that it was allocated - for (const Token* const end = tok->scope()->classEnd; tok && tok->next() && tok != end; tok = tok->next()) { + for (const Token* const end = tok->scope()->bodyEnd; tok && tok->next() && tok != end; tok = tok->next()) { // If the buffers are modified, we can't be sure of their sizes if (tok->varId() == srcVarId || tok->varId() == dstVarId) break; @@ -1753,7 +1753,7 @@ void CheckBufferOverrun::checkStringArgument() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t functionIndex = 0; functionIndex < functions; ++functionIndex) { const Scope * const scope = symbolDatabase->functionScopes[functionIndex]; - for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%name% (") || !_settings->library.hasminsize(tok->str())) continue; @@ -1804,7 +1804,7 @@ void CheckBufferOverrun::checkInsecureCmdLineArgs() continue; // Jump to the opening curly brace - tok = symbolDatabase->functionScopes[i]->classStart; + tok = symbolDatabase->functionScopes[i]->bodyStart; // Search within main() for possible buffer overruns involving argv for (const Token* end = tok->link(); tok != end; tok = tok->next()) { @@ -1925,7 +1925,7 @@ void CheckBufferOverrun::arrayIndexThenCheck() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * const scope = symbolDatabase->functionScopes[i]; - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if (Token::simpleMatch(tok, "sizeof (")) { tok = tok->linkAt(1); continue; @@ -2000,7 +2000,7 @@ Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con const std::size_t functions = symbolDB->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * const scope = symbolDB->functionScopes[i]; - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%var% [") && Token::Match(tok->linkAt(1), "] !![") && tok->variable() && diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index b644d3e3e..625eda294 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -216,8 +216,8 @@ void CheckClass::constructors() if (func->type == Function::eConstructor && func->nestedIn && (func->nestedIn->numConstructors - func->nestedIn->numCopyOrMoveConstructors) > 1 && func->argCount() == 0 && func->functionScope && - func->arg && func->arg->link()->next() == func->functionScope->classStart && - func->functionScope->classStart->link() == func->functionScope->classStart->next()) { + func->arg && func->arg->link()->next() == func->functionScope->bodyStart && + func->functionScope->bodyStart->link() == func->functionScope->bodyStart->next()) { // don't warn about user defined default constructor when there are other constructors if (printInconclusive) uninitVarError(func->token, func->access == Private, scope->className, var->name(), true); @@ -286,14 +286,14 @@ void CheckClass::copyconstructors() for (std::list::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { if (func->type == Function::eConstructor && func->functionScope) { const Token* tok = func->functionScope->classDef->linkAt(1); - for (const Token* const end = func->functionScope->classStart; tok != end; tok = tok->next()) { + for (const Token* const end = func->functionScope->bodyStart; tok != end; tok = tok->next()) { if (Token::Match(tok, "%var% ( new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) { const Variable* var = tok->variable(); if (var && var->isPointer() && var->scope() == scope) allocatedVars[tok->varId()] = tok; } } - for (const Token* const end = func->functionScope->classEnd; tok != end; tok = tok->next()) { + for (const Token* const end = func->functionScope->bodyEnd; tok != end; tok = tok->next()) { if (Token::Match(tok, "%var% = new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) { const Variable* var = tok->variable(); if (var && var->isPointer() && var->scope() == scope && !var->isStatic()) @@ -326,7 +326,7 @@ void CheckClass::copyconstructors() tok = tok->linkAt(1)->tokAt(2); } } - for (tok = func.functionScope->classStart; tok != func.functionScope->classEnd; tok = tok->next()) { + for (tok = func.functionScope->bodyStart; tok != func.functionScope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%var% = new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) { allocatedVars.erase(tok->varId()); } else if (Token::Match(tok, "%var% = %name% . %name% ;") && allocatedVars.find(tok->varId()) != allocatedVars.end()) { @@ -497,7 +497,7 @@ void CheckClass::initializeVarList(const Function &func, std::listlink()->next(); int level = 0; - for (; ftok && ftok != func.functionScope->classEnd; ftok = ftok->next()) { + for (; ftok && ftok != func.functionScope->bodyEnd; ftok = ftok->next()) { // Class constructor.. initializing variables like this // clKalle::clKalle() : var(value) { } if (initList) { @@ -833,7 +833,7 @@ void CheckClass::initializationListUsage() continue; const Scope* owner = scope->functionOf; - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%name% (")) // Assignments might depend on this function call or if/for/while/switch statement from now on. break; if (Token::Match(tok, "try|do {")) @@ -900,7 +900,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope) ftok = ftok->link(); } } - for (const Token *ftok = func->functionScope->classDef->linkAt(1); ftok != func->functionScope->classEnd; ftok = ftok->next()) { + for (const Token *ftok = func->functionScope->classDef->linkAt(1); ftok != func->functionScope->bodyEnd; ftok = ftok->next()) { if (ftok->function() == privfunc) return true; if (ftok->varId() == 0U && ftok->str() == privfunc->name()) // TODO: This condition should be redundant @@ -921,7 +921,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope) for (std::list::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) { if (i->isStatic()) { - const Token* tok = Token::findmatch(scope->classEnd, "%varid% =|(|{", i->declarationId()); + const Token* tok = Token::findmatch(scope->bodyEnd, "%varid% =|(|{", i->declarationId()); if (tok) tok = tok->tokAt(2); while (tok && tok->str() != ";") { @@ -943,7 +943,7 @@ void CheckClass::privateFunctions() for (const Scope * scope : symbolDatabase->classAndStructScopes) { // do not check borland classes with properties.. - if (Token::findsimplematch(scope->classStart, "; __property ;", scope->classEnd)) + if (Token::findsimplematch(scope->bodyStart, "; __property ;", scope->bodyEnd)) continue; std::list privateFuncs; @@ -1007,7 +1007,7 @@ void CheckClass::checkMemset() { const bool printWarnings = _settings->isEnabled(Settings::WARNING); for (const Scope *scope : symbolDatabase->functionScopes) { - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "memset|memcpy|memmove (")) { const Token* arg1 = tok->tokAt(2); const Token* arg3 = arg1->nextArgument(); @@ -1258,7 +1258,7 @@ void CheckClass::operatorEqRetRefThis() if (func->type == Function::eOperatorEqual && func->hasBody()) { // make sure return signature is correct if (Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className) { - checkReturnPtrThis(scope, &(*func), func->functionScope->classStart, func->functionScope->classEnd); + checkReturnPtrThis(scope, &(*func), func->functionScope->bodyStart, func->functionScope->bodyEnd); } } } @@ -1423,8 +1423,8 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope) const // - alloc member // That is not ideal because it can cause false negatives but its currently // necessary to prevent false positives. - const Token *last = func->functionScope->classEnd; - for (const Token *tok = func->functionScope->classStart; tok && (tok != last); tok = tok->next()) { + const Token *last = func->functionScope->bodyEnd; + for (const Token *tok = func->functionScope->bodyStart; tok && (tok != last); tok = tok->next()) { if (Token::Match(tok, "%var% = malloc|realloc|calloc|new") && isMemberVar(scope, tok)) return true; @@ -1454,8 +1454,8 @@ bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs) { if (!rhs) return false; - const Token *last = func->functionScope->classEnd; - for (const Token *tok = func->functionScope->classStart; tok && tok != last; tok = tok->next()) { + const Token *last = func->functionScope->bodyEnd; + for (const Token *tok = func->functionScope->bodyStart; tok && tok != last; tok = tok->next()) { if (!Token::simpleMatch(tok, "if (")) continue; @@ -1884,7 +1884,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& { // if the function doesn't have any assignment nor function call, // it can be a const function.. - for (const Token *tok1 = func->functionScope->classStart; tok1 && tok1 != func->functionScope->classEnd; tok1 = tok1->next()) { + for (const Token *tok1 = func->functionScope->bodyStart; tok1 && tok1 != func->functionScope->bodyEnd; tok1 = tok1->next()) { if (tok1->isName() && isMemberVar(scope, tok1)) { memberAccessed = true; const Variable* v = tok1->variable(); @@ -2081,7 +2081,7 @@ void CheckClass::initializerListOrder() tok = tok->next(); // find all variable initializations in list - while (tok && tok != func->functionScope->classStart) { + while (tok && tok != func->functionScope->bodyStart) { if (Token::Match(tok, "%name% (|{")) { const Variable *var = scope->getVariable(tok->str()); if (var) @@ -2139,7 +2139,7 @@ void CheckClass::checkSelfInitialization() if (tok->str() != ":") continue; - for (; tok != scope->classStart; tok = tok->next()) { + for (; tok != scope->bodyStart; tok = tok->next()) { if (Token::Match(tok, "[:,] %var% (|{ %var% )|}") && tok->next()->varId() == tok->tokAt(3)->varId()) { selfInitializationError(tok, tok->strAt(1)); } @@ -2196,7 +2196,7 @@ const std::list & CheckClass::getVirtualFunctionCalls(const Funct if (!function.hasBody()) return virtualFunctionCalls; - for (const Token *tok = function.arg->link(); tok != function.functionScope->classEnd; tok = tok->next()) { + for (const Token *tok = function.arg->link(); tok != function.functionScope->bodyEnd; tok = tok->next()) { if (function.type != Function::eConstructor && function.type != Function::eCopyConstructor && function.type != Function::eMoveConstructor && @@ -2209,7 +2209,7 @@ const std::list & CheckClass::getVirtualFunctionCalls(const Funct } } if (tok->scope()->type == Scope::eLambda) - tok = tok->scope()->classEnd->next(); + tok = tok->scope()->bodyEnd->next(); const Function * callFunction = tok->function(); if (!callFunction || @@ -2460,7 +2460,7 @@ void CheckClass::checkUnsafeClassDivZero(bool test) continue; if (func.name().compare(0,8,"operator")==0) continue; - for (const Token *tok = func.functionScope->classStart; tok; tok = tok->next()) { + for (const Token *tok = func.functionScope->bodyStart; tok; tok = tok->next()) { if (Token::Match(tok, "if|switch|while|for|do|}")) break; if (tok->str() != "/") diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 61db3fe12..57b589a49 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -534,14 +534,14 @@ void CheckCondition::multiCondition2() // parse until second condition is reached.. enum MULTICONDITIONTYPE { INNER, AFTER } type; const Token *tok; - if (Token::Match(scope->classStart, "{ return|throw|continue|break")) { - tok = scope->classEnd->next(); + if (Token::Match(scope->bodyStart, "{ return|throw|continue|break")) { + tok = scope->bodyEnd->next(); type = MULTICONDITIONTYPE::AFTER; } else { - tok = scope->classStart; + tok = scope->bodyStart; type = MULTICONDITIONTYPE::INNER; } - const Token * const endToken = tok->scope()->classEnd; + const Token * const endToken = tok->scope()->bodyEnd; for (; tok && tok != endToken; tok = tok->next()) { if (Token::simpleMatch(tok, "if (")) { @@ -875,7 +875,7 @@ void CheckCondition::checkIncorrectLogicOperator() for (std::size_t ii = 0; ii < functions; ++ii) { const Scope * scope = symbolDatabase->functionScopes[ii]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%oror%|&&") || !tok->astOperand1() || !tok->astOperand2()) continue; @@ -1066,7 +1066,7 @@ void CheckCondition::checkModuloAlwaysTrueFalse() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!tok->isComparisonOp()) continue; const Token *num, *modulo; @@ -1122,7 +1122,7 @@ void CheckCondition::clarifyCondition() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "( %name% [=&|^]")) { for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) { if (tok2->str() == "(" || tok2->str() == "[") @@ -1188,7 +1188,7 @@ void CheckCondition::alwaysTrueFalse() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->link()) // don't write false positives when templates are used continue; @@ -1299,7 +1299,7 @@ void CheckCondition::checkInvalidTestForOverflow() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2()) continue; @@ -1363,7 +1363,7 @@ void CheckCondition::checkPointerAdditionResultNotNull() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2()) continue; diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index e6a88f1ac..6b3ed32b9 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -52,7 +52,7 @@ void CheckExceptionSafety::destructors() // only looking for destructors if (function->type == Function::eDestructor) { // Inspect this destructor. - for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // Skip try blocks if (Token::simpleMatch(tok, "try {")) { tok = tok->next()->link(); @@ -91,7 +91,7 @@ void CheckExceptionSafety::deallocThrow() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // only looking for delete now if (tok->str() != "delete") continue; @@ -100,7 +100,7 @@ void CheckExceptionSafety::deallocThrow() tok = tok->next(); if (Token::simpleMatch(tok, "[ ]")) tok = tok->tokAt(2); - if (!tok || tok == scope->classEnd) + if (!tok || tok == scope->bodyEnd) break; if (!Token::Match(tok, "%var% ;")) continue; @@ -116,7 +116,7 @@ void CheckExceptionSafety::deallocThrow() const Token *throwToken = nullptr; // is there a throw after the deallocation? - const Token* const end2 = tok->scope()->classEnd; + const Token* const end2 = tok->scope()->bodyEnd; for (const Token *tok2 = tok; tok2 != end2; tok2 = tok2->next()) { // Throw after delete -> Dead pointer if (tok2->str() == "throw") { @@ -158,9 +158,9 @@ void CheckExceptionSafety::checkRethrowCopy() if (i->type != Scope::eCatch) continue; - const unsigned int varid = i->classStart->tokAt(-2)->varId(); + const unsigned int varid = i->bodyStart->tokAt(-2)->varId(); if (varid) { - for (const Token* tok = i->classStart->next(); tok && tok != i->classEnd; tok = tok->next()) { + for (const Token* tok = i->bodyStart->next(); tok && tok != i->bodyEnd; tok = tok->next()) { if (Token::simpleMatch(tok, "catch (") && tok->next()->link() && tok->next()->link()->next()) { // Don't check inner catch - it is handled in another iteration of outer loop. tok = tok->next()->link()->next()->link(); if (!tok) @@ -188,7 +188,7 @@ void CheckExceptionSafety::checkCatchExceptionByValue() // Find a pass-by-value declaration in the catch(), excluding basic types // e.g. catch (std::exception err) - const Variable *var = i->classStart->tokAt(-2)->variable(); + const Variable *var = i->bodyStart->tokAt(-2)->variable(); if (var && var->isClass() && !var->isPointer() && !var->isReference()) catchExceptionByValueError(i->classDef); } @@ -204,8 +204,8 @@ static const Token * functionThrowsRecursive(const Function * function, std::set if (!function->functionScope) return nullptr; - for (const Token *tok = function->functionScope->classStart->next(); - tok != function->functionScope->classEnd; tok = tok->next()) { + for (const Token *tok = function->functionScope->bodyStart->next(); + tok != function->functionScope->bodyEnd; tok = tok->next()) { if (tok->str() == "try") { // just bail for now break; @@ -293,8 +293,8 @@ void CheckExceptionSafety::unhandledExceptionSpecification() if (scope->function && !scope->function->isThrow() && scope->className != "main" && scope->className != "wmain" && scope->className != "_tmain" && scope->className != "WinMain") { - for (const Token *tok = scope->function->functionScope->classStart->next(); - tok != scope->function->functionScope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->function->functionScope->bodyStart->next(); + tok != scope->function->functionScope->bodyEnd; tok = tok->next()) { if (tok->str() == "try") { break; } else if (tok->function()) { diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 55fe817b3..83ed8b1f1 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -57,7 +57,7 @@ void CheckFunctions::checkProhibitedFunctions() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope *scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%name% (") && tok->varId() == 0) continue; // alloca() is special as it depends on the code being C or C++, so it is not in Library @@ -99,7 +99,7 @@ void CheckFunctions::invalidFunctionUsage() { const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope *scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%name% ( !!)")) continue; const Token * const functionToken = tok; @@ -176,7 +176,7 @@ void CheckFunctions::checkIgnoredReturnValue() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope *scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // skip c++11 initialization, ({...}) if (Token::Match(tok, "%var%|(|, {")) tok = tok->linkAt(1); @@ -190,7 +190,7 @@ void CheckFunctions::checkIgnoredReturnValue() continue; if (!tok->scope()->isExecutable()) { - tok = tok->scope()->classEnd; + tok = tok->scope()->bodyEnd; continue; } @@ -217,7 +217,7 @@ void CheckFunctions::checkMathFunctions() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope *scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->varId()) continue; if (printWarnings && Token::Match(tok, "%name% ( !!)")) { @@ -314,7 +314,7 @@ void CheckFunctions::memsetZeroBytes() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope *scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "memset|wmemset (") && (numberOfArguments(tok)==3)) { const std::vector &arguments = getArguments(tok); if (WRONG_DATA(arguments.size() != 3U, tok)) @@ -353,7 +353,7 @@ void CheckFunctions::memsetInvalid2ndParam() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope *scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok && (tok != scope->classEnd); tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok && (tok != scope->bodyEnd); tok = tok->next()) { if (!Token::simpleMatch(tok, "memset (")) continue; diff --git a/lib/checkinternal.cpp b/lib/checkinternal.cpp index e8ef04d23..79e98b8bf 100644 --- a/lib/checkinternal.cpp +++ b/lib/checkinternal.cpp @@ -38,7 +38,7 @@ void CheckInternal::checkTokenMatchPatterns() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::simpleMatch(tok, "Token :: Match (") && !Token::simpleMatch(tok, "Token :: findmatch (")) continue; @@ -126,7 +126,7 @@ void CheckInternal::checkTokenSimpleMatchPatterns() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::simpleMatch(tok, "Token :: simpleMatch (") && !Token::simpleMatch(tok, "Token :: findsimplematch (")) continue; @@ -215,7 +215,7 @@ void CheckInternal::checkMissingPercentCharacter() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::simpleMatch(tok, "Token :: Match (") && !Token::simpleMatch(tok, "Token :: findmatch (")) continue; @@ -258,7 +258,7 @@ void CheckInternal::checkUnknownPattern() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::simpleMatch(tok, "Token :: Match (") && !Token::simpleMatch(tok, "Token :: findmatch (")) continue; @@ -293,7 +293,7 @@ void CheckInternal::checkRedundantNextPrevious() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() != ".") continue; tok = tok->next(); @@ -325,7 +325,7 @@ void CheckInternal::checkExtraWhitespace() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "Token :: simpleMatch|findsimplematch|Match|findmatch (")) continue; @@ -351,7 +351,7 @@ void CheckInternal::checkStlUsage() { const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope *scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::simpleMatch(tok, ". emplace (")) reportError(tok, Severity::error, "internalStlUsage", "The 'emplace' function shall be avoided for now. 'emplace_back' is fine"); //if (Token::simpleMatch(tok, ". back ( )") && tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->container && Token::simpleMatch(tok->astOperand1()->valueType()->container, "std :: string")) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index fd2a907c3..a47b1bcdb 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -65,7 +65,7 @@ void CheckIO::checkCoutCerrMisusage() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "std :: cout|cerr !!.") && tok->next()->astParent() && tok->next()->astParent()->astOperand1() == tok->next()) { const Token* tok2 = tok->next(); while (tok2->astParent() && tok2->astParent()->str() == "<<") { @@ -147,7 +147,7 @@ void CheckIO::checkFileUsage() for (std::size_t j = 0; j < functions; ++j) { const Scope * scope = symbolDatabase->functionScopes[j]; unsigned int indent = 0; - for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() == "{") indent++; else if (tok->str() == "}") { @@ -389,7 +389,7 @@ void CheckIO::invalidScanf() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t j = 0; j < functions; ++j) { const Scope * scope = symbolDatabase->functionScopes[j]; - for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { const Token *formatToken = nullptr; if (Token::Match(tok, "scanf|vscanf ( %str% ,")) formatToken = tok->tokAt(2); @@ -504,7 +504,7 @@ void CheckIO::checkWrongPrintfScanfArguments() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t j = 0; j < functions; ++j) { const Scope * scope = symbolDatabase->functionScopes[j]; - for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!tok->isName()) continue; const Token* argListTok = nullptr; // Points to first va_list argument diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index ff37165f9..1a205cbd4 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -164,7 +164,7 @@ void CheckLeakAutoVar::check() // Empty variable info VarInfo varInfo; - checkScope(scope->classStart, &varInfo, notzero); + checkScope(scope->bodyStart, &varInfo, notzero); varInfo.conditionalAlloc.clear(); @@ -180,7 +180,7 @@ void CheckLeakAutoVar::check() ++it; } - ret(scope->classEnd, varInfo); + ret(scope->bodyEnd, varInfo); } } @@ -205,7 +205,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, const Token * const endToken = startToken->link(); for (const Token *tok = startToken; tok && tok != endToken; tok = tok->next()) { if (!tok->scope()->isExecutable()) { - tok = tok->scope()->classEnd; + tok = tok->scope()->bodyEnd; if (!tok) // Ticket #6666 (crash upon invalid code) break; } @@ -590,7 +590,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, dtok = Token::findmatch(deleterToken, "%type%", endDeleterToken); if (dtok && dtok->type()) { const Scope * tscope = dtok->type()->classScope; - for (const Token *tok2 = tscope->classStart; tok2 != tscope->classEnd; tok2 = tok2->next()) { + for (const Token *tok2 = tscope->bodyStart; tok2 != tscope->bodyEnd; tok2 = tok2->next()) { af = _settings->library.dealloc(tok2); if (af) break; diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 69e1d049d..0bb498e65 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -352,7 +352,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f // Get return pointer.. unsigned int varid = 0; - for (const Token *tok2 = func->functionScope->classStart; tok2 != func->functionScope->classEnd; tok2 = tok2->next()) { + for (const Token *tok2 = func->functionScope->bodyStart; tok2 != func->functionScope->bodyEnd; tok2 = tok2->next()) { if (tok2->str() == "return") { const AllocType allocType = getAllocationType(tok2->next(), 0, callstack); if (allocType != No) @@ -382,7 +382,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f // Check if return pointer is allocated.. AllocType allocType = No; - for (const Token* tok = func->functionScope->classStart; tok != func->functionScope->classEnd; tok = tok->next()) { + for (const Token* tok = func->functionScope->bodyStart; tok != func->functionScope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%varid% =", varid)) { allocType = getAllocationType(tok->tokAt(2), varid, callstack); } @@ -434,7 +434,7 @@ const char *CheckMemoryLeak::functionArgAlloc(const Function *func, unsigned int // Check if pointer is allocated. bool realloc = false; - for (tok = func->functionScope->classStart; tok && tok != func->functionScope->classEnd; tok = tok->next()) { + for (tok = func->functionScope->bodyStart; tok && tok != func->functionScope->bodyEnd; tok = tok->next()) { if (tok->varId() == arg->declarationId()) { if (Token::Match(tok->tokAt(-3), "free ( * %name% )")) { realloc = true; @@ -572,7 +572,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listhasBody()) return nullptr; - Token *ftok = getcode(func->functionScope->classStart->next(), callstack, 0, alloctype, dealloctype, false, 1); + Token *ftok = getcode(func->functionScope->bodyStart->next(), callstack, 0, alloctype, dealloctype, false, 1); simplifycode(ftok); const char *ret = nullptr; if (Token::simpleMatch(ftok, "; alloc ; }")) @@ -593,7 +593,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listfunction() && tok->function()->functionScope) { std::string temp; - if (!_settings->library.isScopeNoReturn(tok->function()->functionScope->classEnd, &temp) && temp.empty()) + if (!_settings->library.isScopeNoReturn(tok->function()->functionScope->bodyEnd, &temp) && temp.empty()) return nullptr; } else if (_settings->library.isnotnoreturn(tok)) return nullptr; @@ -631,7 +631,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listgetArgumentVar(par-1); if (!param || !param->nameToken()) return "use"; - Token *func = getcode(function->functionScope->classStart->next(), callstack, param->declarationId(), alloctype, dealloctype, false, sz); + Token *func = getcode(function->functionScope->bodyStart->next(), callstack, param->declarationId(), alloctype, dealloctype, false, sz); //simplifycode(func); const Token *func_ = func; while (func_ && func_->str() == ";") @@ -2141,14 +2141,14 @@ void CheckMemoryLeakInFunction::checkReallocUsage() const Scope * scope = symbolDatabase->functionScopes[i]; // Search for the "var = realloc(var, 100" pattern within this function - for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->varId() > 0 && Token::Match(tok, "%name% = realloc|g_try_realloc ( %name% ,") && tok->varId() == tok->tokAt(4)->varId() && isNoArgument(symbolDatabase, tok->varId())) { // Check that another copy of the pointer wasn't saved earlier in the function - if (Token::findmatch(scope->classStart, "%name% = %varid% ;", tok, tok->varId()) || - Token::findmatch(scope->classStart, "[{};] %varid% = %name% [;=]", tok, tok->varId())) + if (Token::findmatch(scope->bodyStart, "%name% = %varid% ;", tok, tok->varId()) || + Token::findmatch(scope->bodyStart, "[{};] %varid% = %name% [;=]", tok, tok->varId())) continue; const Token* tokEndRealloc = tok->linkAt(3); @@ -2166,8 +2166,8 @@ void CheckMemoryLeakInFunction::checkReallocUsage() tok->next()->varId() == tok->tokAt(6)->varId()) && isNoArgument(symbolDatabase, tok->next()->varId())) { // Check that another copy of the pointer wasn't saved earlier in the function - if (Token::findmatch(scope->classStart, "%name% = * %varid% ;", tok, tok->next()->varId()) || - Token::findmatch(scope->classStart, "[{};] * %varid% = %name% [;=]", tok, tok->next()->varId())) + if (Token::findmatch(scope->bodyStart, "%name% = * %varid% ;", tok, tok->next()->varId()) || + Token::findmatch(scope->bodyStart, "[{};] * %varid% = %name% [;=]", tok, tok->next()->varId())) continue; const Token* tokEndRealloc = tok->linkAt(4); @@ -2205,7 +2205,7 @@ void CheckMemoryLeakInFunction::check() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; if (!scope->hasInlineOrLambdaFunction()) - checkScope(scope->classStart->next(), emptyString, 0, scope->functionOf != nullptr, 1); + checkScope(scope->bodyStart->next(), emptyString, 0, scope->functionOf != nullptr, 1); } // Check variables.. @@ -2232,7 +2232,7 @@ void CheckMemoryLeakInFunction::check() sz = 1; if (var->isArgument()) - checkScope(var->scope()->classStart->next(), var->name(), i, isInMemberFunc(var->scope()), sz); + checkScope(var->scope()->bodyStart->next(), var->name(), i, isInMemberFunc(var->scope()), sz); else checkScope(var->nameToken(), var->name(), i, isInMemberFunc(var->scope()), sz); } @@ -2296,9 +2296,9 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam continue; } bool body = false; - const Token *end = func->functionScope->classEnd; + const Token *end = func->functionScope->bodyEnd; for (const Token *tok = func->arg->link(); tok != end; tok = tok->next()) { - if (tok == func->functionScope->classStart) + if (tok == func->functionScope->bodyStart) body = true; else { if (!body) { @@ -2410,7 +2410,7 @@ void CheckMemoryLeakInClass::checkPublicFunctions(const Scope *scope, const Toke for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { if ((func->type == Function::eFunction || func->type == Function::eOperatorEqual) && func->access == Public && func->hasBody()) { - const Token *tok2 = func->functionScope->classStart->next(); + const Token *tok2 = func->functionScope->bodyStart->next(); if (Token::Match(tok2, "%varid% =", varid)) { const CheckMemoryLeak::AllocType alloc = getAllocationType(tok2->tokAt(2), varid); if (alloc != CheckMemoryLeak::No) @@ -2448,7 +2448,7 @@ bool CheckMemoryLeakStructMember::isMalloc(const Variable *variable) { const unsigned int declarationId(variable->declarationId()); bool alloc = false; - for (const Token *tok2 = variable->nameToken(); tok2 && tok2 != variable->scope()->classEnd; tok2 = tok2->next()) { + for (const Token *tok2 = variable->nameToken(); tok2 && tok2 != variable->scope()->bodyEnd; tok2 = tok2->next()) { if (Token::Match(tok2, "= %varid% [;=]", declarationId)) { return false; } else if (Token::Match(tok2, "%varid% = malloc|kmalloc (", declarationId)) { @@ -2472,7 +2472,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable * const var // Check struct.. unsigned int indentlevel2 = 0; - for (const Token *tok2 = variable->nameToken(); tok2 && tok2 != variable->scope()->classEnd; tok2 = tok2->next()) { + for (const Token *tok2 = variable->nameToken(); tok2 && tok2 != variable->scope()->bodyEnd; tok2 = tok2->next()) { if (tok2->str() == "{") ++indentlevel2; @@ -2648,7 +2648,7 @@ void CheckMemoryLeakNoVar::check() checkForUnsafeArgAlloc(scope); // parse the executable scope until tok is reached... - for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { // allocating memory in parameter for function call.. if (!(Token::Match(tok, "[(,] %name% (") && Token::Match(tok->linkAt(2), ") [,)]"))) continue; @@ -2682,7 +2682,7 @@ void CheckMemoryLeakNoVar::check() //--------------------------------------------------------------------------- void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) { - for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%name% (")) continue; @@ -2730,7 +2730,7 @@ void CheckMemoryLeakNoVar::checkForUnsafeArgAlloc(const Scope *scope) if (!_tokenizer->isCPP() || !_settings->inconclusive || !_settings->isEnabled(Settings::WARNING)) return; - for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%name% (")) { const Token *endParamToken = tok->next()->link(); const Token* pointerType = nullptr; diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 440b82074..986820f2e 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -297,8 +297,8 @@ void CheckNullPointer::nullPointerLinkedList() // Make sure there is a "break" or "return" inside the loop. // Without the "break" a null pointer could be dereferenced in the // for statement. - for (const Token *tok4 = scope->classStart; tok4; tok4 = tok4->next()) { - if (tok4 == i->classEnd) { + for (const Token *tok4 = scope->bodyStart; tok4; tok4 = tok4->next()) { + if (tok4 == i->bodyEnd) { const ValueFlow::Value v(scope->classDef, 0LL); nullPointerError(tok1, var->name(), &v, false); break; @@ -393,12 +393,12 @@ void CheckNullPointer::nullConstantDereference() if (scope->function == nullptr || !scope->function->hasBody()) // We only look for functions with a body continue; - const Token *tok = scope->classStart; + const Token *tok = scope->bodyStart; if (scope->function->isConstructor()) tok = scope->function->token; // Check initialization list - for (; tok != scope->classEnd; tok = tok->next()) { + for (; tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "sizeof|decltype|typeid|typeof (")) tok = tok->next()->link(); @@ -524,7 +524,7 @@ void CheckNullPointer::arithmetic() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "-|+|+=|-=|++|--")) continue; const Token *pointerOperand; diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 67e34b9de..7483199d8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -86,7 +86,7 @@ void CheckOther::checkCastIntToCharAndBack() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { std::map vars; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // Quick check to see if any of the matches below have any chances if (!Token::Match(tok, "%var%|EOF %comp%|=")) continue; @@ -153,7 +153,7 @@ void CheckOther::clarifyCalculation() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // ? operator where lhs is arithmetical expression if (tok->str() != "?" || !tok->astOperand1() || !tok->astOperand1()->isCalculation()) continue; @@ -205,7 +205,7 @@ void CheckOther::clarifyStatement() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "* %name%") && tok->astOperand1()) { const Token *tok2 = tok->previous(); @@ -244,9 +244,9 @@ void CheckOther::checkSuspiciousSemicolon() if (i->type == Scope::eIf || i->type == Scope::eElse || i->type == Scope::eWhile || i->type == Scope::eFor) { // Ensure the semicolon is at the same line number as the if/for/while statement // and the {..} block follows it without an extra empty line. - if (Token::simpleMatch(i->classStart, "{ ; } {") && - i->classStart->previous()->linenr() == i->classStart->tokAt(2)->linenr() - && i->classStart->linenr()+1 >= i->classStart->tokAt(3)->linenr()) { + if (Token::simpleMatch(i->bodyStart, "{ ; } {") && + i->bodyStart->previous()->linenr() == i->bodyStart->tokAt(2)->linenr() + && i->bodyStart->linenr()+1 >= i->bodyStart->tokAt(3)->linenr()) { SuspiciousSemicolonError(i->classDef); } } @@ -275,8 +275,8 @@ void CheckOther::warningOldStylePointerCast() if (scope->function && scope->function->isConstructor()) tok = scope->classDef; else - tok = scope->classStart; - for (; tok && tok != scope->classEnd; tok = tok->next()) { + tok = scope->bodyStart; + for (; tok && tok != scope->bodyEnd; tok = tok->next()) { // Old style pointer casting.. if (!Token::Match(tok, "( const| %type% * const| ) (| %name%|%num%|%bool%|%char%|%str%")) continue; @@ -322,7 +322,7 @@ void CheckOther::invalidPointerCast() const bool printInconclusive = _settings->inconclusive; const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { const Token* toTok = nullptr; const Token* fromTok = nullptr; // Find cast @@ -382,7 +382,7 @@ void CheckOther::checkPipeParameterSize() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "pipe ( %var% )") || Token::Match(tok, "pipe2 ( %var% ,")) { const Token * const varTok = tok->tokAt(2); @@ -459,7 +459,7 @@ static bool checkExceptionHandling(const Token* tok) } if (var && upperScope && upperScope->type == Scope::eTry) { // Check all exception han - const Token* tok2 = upperScope->classEnd; + const Token* tok2 = upperScope->bodyEnd; while (Token::simpleMatch(tok2, "} catch (")) { tok2 = tok2->linkAt(2)->next(); if (Token::findmatch(tok2, "%varid%", tok2->link(), var->declarationId())) @@ -491,7 +491,7 @@ void CheckOther::checkRedundantAssignment() std::set initialized; const Token* writtenArgumentsEnd = nullptr; - for (const Token* tok = scope->classStart->next(); tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok && tok != scope->bodyEnd; tok = tok->next()) { if (tok == writtenArgumentsEnd) writtenArgumentsEnd = nullptr; @@ -681,7 +681,7 @@ void CheckOther::checkRedundantAssignment() memAssignments.clear(); continue; } - const Token* funcEnd = func->functionScope->classEnd; + const Token* funcEnd = func->functionScope->bodyEnd; bool noreturn; if (!_tokenizer->IsScopeNoReturn(funcEnd, &noreturn) && !noreturn) { eraseNotLocalArg(varAssignments, symbolDatabase); @@ -765,14 +765,14 @@ void CheckOther::checkRedundantAssignmentInSwitch() // Find the beginning of a switch. E.g.: // switch (var) { ... for (std::list::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) { - if (i->type != Scope::eSwitch || !i->classStart) + if (i->type != Scope::eSwitch || !i->bodyStart) continue; // Check the contents of the switch statement std::map varsWithBitsSet; std::map bitOperations; - for (const Token *tok2 = i->classStart->next(); tok2 != i->classEnd; tok2 = tok2->next()) { + for (const Token *tok2 = i->bodyStart->next(); tok2 != i->bodyEnd; tok2 = tok2->next()) { if (tok2->str() == "{") { // Inside a conditional or loop. Don't mark variable accesses as being redundant. E.g.: // case 3: b = 1; @@ -893,7 +893,7 @@ void CheckOther::checkSuspiciousCaseInSwitch() if (scope.type != Scope::eSwitch) continue; - for (const Token* tok = scope.classStart->next(); tok != scope.classEnd; tok = tok->next()) { + for (const Token* tok = scope.bodyStart->next(); tok != scope.bodyEnd; tok = tok->next()) { if (tok->str() == "case") { const Token* finding = nullptr; for (const Token* tok2 = tok->next(); tok2; tok2 = tok2->next()) { @@ -932,7 +932,7 @@ void CheckOther::checkSuspiciousEqualityComparison() const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (Token::simpleMatch(tok, "for (")) { const Token* const openParen = tok->next(); const Token* const closeParen = tok->linkAt(1); @@ -985,7 +985,7 @@ void CheckOther::checkUnreachableCode() const bool printInconclusive = _settings->inconclusive; const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { const Token* secondBreak = nullptr; const Token* labelName = nullptr; if (tok->link() && Token::Match(tok, "(|[|<")) @@ -1050,7 +1050,7 @@ void CheckOther::checkUnreachableCode() if (Token::Match(silencedWarning, "( void ) %name% ;")) { silencedWarning = silencedWarning->tokAt(5); continue; - } else if (silencedWarning && silencedWarning == scope->classEnd) + } else if (silencedWarning && silencedWarning == scope->bodyEnd) silencedCompilerWarningOnly = true; break; @@ -1126,7 +1126,7 @@ void CheckOther::checkVariableScope() continue; bool reduce = true; bool used = false; // Don't warn about unused variables - for (; tok && tok != var->scope()->classEnd; tok = tok->next()) { + for (; tok && tok != var->scope()->bodyEnd; tok = tok->next()) { if (tok->str() == "{" && tok->scope() != tok->previous()->scope() && !tok->isExpandedMacro() && tok->scope()->type != Scope::eLambda) { if (used) { bool used2 = false; @@ -1182,10 +1182,10 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us for (std::list::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) { if (used) { bool used2 = false; - if (!checkInnerScope((*i)->classStart, var, used2) || used2) { + if (!checkInnerScope((*i)->bodyStart, var, used2) || used2) { return false; } - } else if (!checkInnerScope((*i)->classStart, var, used)) { + } else if (!checkInnerScope((*i)->bodyStart, var, used)) { return false; } } @@ -1354,7 +1354,7 @@ static std::size_t estimateSize(const Type* type, const Settings* settings, cons static bool canBeConst(const Variable *var) { - for (const Token* tok2 = var->scope()->classStart; tok2 != var->scope()->classEnd; tok2 = tok2->next()) { + for (const Token* tok2 = var->scope()->bodyStart; tok2 != var->scope()->bodyEnd; tok2 = tok2->next()) { if (tok2->varId() == var->declarationId()) { const Token* parent = tok2->astParent(); if (!parent) @@ -1481,7 +1481,7 @@ void CheckOther::checkCharVariable() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%var% [")) { if (!tok->variable()) continue; @@ -1710,7 +1710,7 @@ void CheckOther::checkMisusedScopedObject() const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if ((tok->next()->type() || (tok->next()->function() && tok->next()->function()->isConstructor())) // TODO: The rhs of || should be removed; It is a workaround for a symboldatabase bug && Token::Match(tok, "[;{}] %name% (") && Token::Match(tok->linkAt(2), ") ; !!}") @@ -1756,11 +1756,11 @@ void CheckOther::checkDuplicateBranch() continue; // check all the code in the function for if (..) else - if (Token::simpleMatch(scope.classEnd, "} else {")) { + if (Token::simpleMatch(scope.bodyEnd, "} else {")) { // Make sure there are no macros (different macros might be expanded // to the same code) bool macro = false; - for (const Token *tok = scope.classStart; tok != scope.classEnd->linkAt(2); tok = tok->next()) { + for (const Token *tok = scope.bodyStart; tok != scope.bodyEnd->linkAt(2); tok = tok->next()) { if (tok->isExpandedMacro()) { macro = true; break; @@ -1770,17 +1770,17 @@ void CheckOther::checkDuplicateBranch() continue; // save if branch code - const std::string branch1 = scope.classStart->next()->stringifyList(scope.classEnd); + const std::string branch1 = scope.bodyStart->next()->stringifyList(scope.bodyEnd); if (branch1.empty()) continue; // save else branch code - const std::string branch2 = scope.classEnd->tokAt(3)->stringifyList(scope.classEnd->linkAt(2)); + const std::string branch2 = scope.bodyEnd->tokAt(3)->stringifyList(scope.bodyEnd->linkAt(2)); // check for duplicates if (branch1 == branch2) - duplicateBranchError(scope.classDef, scope.classEnd->next()); + duplicateBranchError(scope.classDef, scope.bodyEnd->next()); } } } @@ -1808,7 +1808,7 @@ void CheckOther::checkInvalidFree() const bool printInconclusive = _settings->inconclusive; const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // Keep track of which variables were assigned addresses to newly-allocated memory if (Token::Match(tok, "%var% = malloc|g_malloc|new")) { @@ -1924,7 +1924,7 @@ void CheckOther::checkDuplicateExpression() if (scope->type != Scope::eFunction) continue; - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() == "=" && Token::Match(tok->astOperand1(), "%var%")) { const Token * endStatement = Token::findsimplematch(tok, ";"); if (Token::Match(endStatement, "; %type% %var% ;")) { @@ -2077,7 +2077,7 @@ void CheckOther::checkComparisonFunctionIsAlwaysTrueOrFalse() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->isName() && Token::Match(tok, "isgreater|isless|islessgreater|isgreaterequal|islessequal ( %var% , %var% )")) { const unsigned int varidLeft = tok->tokAt(2)->varId();// get the left varid const unsigned int varidRight = tok->tokAt(4)->varId();// get the right varid @@ -2126,7 +2126,7 @@ void CheckOther::checkSignOfUnsignedVariable() for (const Scope * scope : symbolDatabase->functionScopes) { // check all the code in the function - for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2()) continue; @@ -2348,7 +2348,7 @@ void CheckOther::checkIncompleteArrayFill() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "memset|memcpy|memmove ( %var% ,") && Token::Match(tok->linkAt(1)->tokAt(-2), ", %num% )")) { const Variable *var = tok->tokAt(2)->variable(); if (!var || !var->isArray() || var->dimensions().empty() || !var->dimension(0)) @@ -2396,7 +2396,7 @@ void CheckOther::checkVarFuncNullUB() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { // Is NULL passed to a function? if (Token::Match(tok,"[(,] NULL [,)]")) { // Locate function name in this function call. @@ -2561,12 +2561,12 @@ void CheckOther::checkUnusedLabel() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (!tok->scope()->isExecutable()) - tok = tok->scope()->classEnd; + tok = tok->scope()->bodyEnd; if (Token::Match(tok, "{|}|; %name% :") && tok->strAt(1) != "default") { - if (!Token::findsimplematch(scope->classStart->next(), ("goto " + tok->strAt(1)).c_str(), scope->classEnd->previous())) + if (!Token::findsimplematch(scope->bodyStart->next(), ("goto " + tok->strAt(1)).c_str(), scope->bodyEnd->previous())) unusedLabelError(tok->next(), tok->next()->scope()->type == Scope::eSwitch); } } @@ -2597,7 +2597,7 @@ void CheckOther::checkEvaluationOrder() const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * functionScope : symbolDatabase->functionScopes) { - for (const Token* tok = functionScope->classStart; tok != functionScope->classEnd; tok = tok->next()) { + for (const Token* tok = functionScope->bodyStart; tok != functionScope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "++|--") && !tok->isAssignmentOp()) continue; if (!tok->astOperand1()) @@ -2682,13 +2682,13 @@ void CheckOther::checkAccessOfMovedVariable() const bool reportInconclusive = _settings->inconclusive; const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { - const Token * scopeStart = scope->classStart; + const Token * scopeStart = scope->bodyStart; if (scope->function) { const Token * memberInitializationStart = scope->function->constructorMemberInitialization(); if (memberInitializationStart) scopeStart = memberInitializationStart; } - for (const Token* tok = scopeStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scopeStart->next(); tok != scope->bodyEnd; tok = tok->next()) { const ValueFlow::Value * movedValue = tok->getMovedValue(); if (!movedValue || movedValue->moveKind == ValueFlow::Value::NonMovedVariable) continue; diff --git a/lib/checkpostfixoperator.cpp b/lib/checkpostfixoperator.cpp index 131aa3ac7..a8105926c 100644 --- a/lib/checkpostfixoperator.cpp +++ b/lib/checkpostfixoperator.cpp @@ -53,7 +53,7 @@ void CheckPostfixOperator::postfixOperator() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { const Variable *var = tok->variable(); if (!var || !Token::Match(tok, "%var% ++|--")) continue; diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index aef609216..3335eb707 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -49,7 +49,7 @@ void CheckSizeof::checkSizeofForNumericParameter() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "sizeof ( %num% )") || Token::Match(tok, "sizeof %num%")) { sizeofForNumericParameterError(tok); @@ -78,7 +78,7 @@ void CheckSizeof::checkSizeofForArrayParameter() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "sizeof ( %var% )") || Token::Match(tok, "sizeof %var% !![")) { const Token* varTok = tok->next(); @@ -119,7 +119,7 @@ void CheckSizeof::checkSizeofForPointerSize() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { const Token* tokSize; const Token* tokFunc; const Token *variable = nullptr; diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index ca96b428a..f9f004d14 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -152,10 +152,10 @@ void CheckStl::iterators() // Scan through the rest of the code and see if the iterator is // used against other containers. - for (const Token *tok2 = var->nameToken(); tok2 && tok2 != var->scope()->classEnd; tok2 = tok2->next()) { - if (invalidationScope && tok2 == invalidationScope->classEnd) + for (const Token *tok2 = var->nameToken(); tok2 && tok2 != var->scope()->bodyEnd; tok2 = tok2->next()) { + if (invalidationScope && tok2 == invalidationScope->bodyEnd) validIterator = true; // Assume that the iterator becomes valid again - if (containerAssignScope && tok2 == containerAssignScope->classEnd) + if (containerAssignScope && tok2 == containerAssignScope->bodyEnd) containerToken = nullptr; // We don't know which containers might be used with the iterator if (tok2 == validatingToken) { @@ -348,7 +348,7 @@ void CheckStl::mismatchingContainers() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t ii = 0; ii < functions; ++ii) { const Scope * scope = symbolDatabase->functionScopes[ii]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%name% ( !!)")) continue; const Token * const ftok = tok; @@ -443,7 +443,7 @@ void CheckStl::stlOutOfBounds() // variable id for the container variable const unsigned int declarationId = var->declarationId(); - for (const Token *tok3 = i->classStart; tok3 && tok3 != i->classEnd; tok3 = tok3->next()) { + for (const Token *tok3 = i->bodyStart; tok3 && tok3 != i->bodyEnd; tok3 = tok3->next()) { if (tok3->varId() == declarationId) { tok3 = tok3->next(); if (Token::Match(tok3, ". %name% ( )")) { @@ -476,7 +476,7 @@ void CheckStl::negativeIndex() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t ii = 0; ii < functions; ++ii) { const Scope * scope = symbolDatabase->functionScopes[ii]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "%var% [") || WRONG_DATA(!tok->next()->astOperand2(), tok)) continue; const Variable * const var = tok->variable(); @@ -529,7 +529,7 @@ void CheckStl::eraseCheckLoopVar(const Scope &scope, const Variable *var) bool inconclusiveType=false; if (!isIterator(var, inconclusiveType)) return; - for (const Token *tok = scope.classStart; tok != scope.classEnd; tok = tok->next()) { + for (const Token *tok = scope.bodyStart; tok != scope.bodyEnd; tok = tok->next()) { if (tok->str() != "(") continue; if (!Token::Match(tok->tokAt(-2), ". erase ( ++| %varid% )", var->declarationId())) @@ -539,7 +539,7 @@ void CheckStl::eraseCheckLoopVar(const Scope &scope, const Variable *var) // Iterator is invalid.. unsigned int indentlevel = 0U; const Token *tok2 = tok->link(); - for (; tok2 != scope.classEnd; tok2 = tok2->next()) { + for (; tok2 != scope.bodyEnd; tok2 = tok2->next()) { if (tok2->str() == "{") { ++indentlevel; continue; @@ -560,7 +560,7 @@ void CheckStl::eraseCheckLoopVar(const Scope &scope, const Variable *var) if (indentlevel == 0U && Token::Match(tok2, "break|return|goto")) break; } - if (tok2 == scope.classEnd) + if (tok2 == scope.bodyEnd) dereferenceErasedError(tok, scope.classDef, var->nameToken()->str(), inconclusiveType); } } @@ -572,7 +572,7 @@ void CheckStl::pushback() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%var% = & %var% [")) { // Skip it directly if it is a pointer or an array const Token* containerTok = tok->tokAt(3); @@ -584,7 +584,7 @@ void CheckStl::pushback() bool invalidPointer = false; const Token* function = nullptr; - const Token* end2 = tok->scope()->classEnd; + const Token* end2 = tok->scope()->bodyEnd; for (const Token *tok2 = tok; tok2 != end2; tok2 = tok2->next()) { // push_back on vector.. if (Token::Match(tok2, "%varid% . push_front|push_back|insert|reserve|resize|clear", containerTok->varId())) { @@ -622,7 +622,7 @@ void CheckStl::pushback() const Token* validatingToken = nullptr; std::string invalidIterator; - const Token* end2 = var->scope()->classEnd; + const Token* end2 = var->scope()->bodyEnd; for (const Token *tok2 = var->nameToken(); tok2 != end2; tok2 = tok2->next()) { if (validatingToken == tok2) { @@ -735,7 +735,7 @@ void CheckStl::stlBoundaries() if (!container || container->opLessAllowed) continue; - const Token* const end = var->scope()->classEnd; + const Token* const end = var->scope()->bodyEnd; for (const Token *tok = var->nameToken(); tok != end; tok = tok->next()) { if (Token::Match(tok, "!!* %varid% <", var->declarationId())) { stlBoundariesError(tok); @@ -877,7 +877,7 @@ void CheckStl::size() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%var% . size ( )") || Token::Match(tok, "%name% . %var% . size ( )")) { // get the variable @@ -976,7 +976,7 @@ void CheckStl::missingComparison() if (i->type != Scope::eFor || !i->classDef) continue; - for (const Token *tok2 = i->classDef->tokAt(2); tok2 != i->classStart; tok2 = tok2->next()) { + for (const Token *tok2 = i->classDef->tokAt(2); tok2 != i->bodyStart; tok2 = tok2->next()) { if (tok2->str() == ";") break; @@ -1002,7 +1002,7 @@ void CheckStl::missingComparison() const Token *incrementToken = nullptr; // Parse loop.. - for (const Token *tok3 = i->classStart; tok3 != i->classEnd; tok3 = tok3->next()) { + for (const Token *tok3 = i->bodyStart; tok3 != i->bodyEnd; tok3 = tok3->next()) { if (Token::Match(tok3, "%varid% ++", iteratorId)) incrementToken = tok3; else if (Token::Match(tok3->previous(), "++ %varid% !!.", iteratorId)) @@ -1097,7 +1097,7 @@ void CheckStl::string_c_str() else if (Token::Match(scope->function->tokenDef->tokAt(-3), "std :: string|wstring !!&")) returnType = stdString; - for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { // Invalid usage.. if (Token::Match(tok, "throw %var% . c_str|data ( ) ;") && isLocal(tok->next()) && tok->next()->variable() && tok->next()->variable()->isStlStringType()) { @@ -1408,7 +1408,7 @@ void CheckStl::uselessCalls() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (printWarning && Token::Match(tok, "%var% . compare|find|rfind|find_first_not_of|find_first_of|find_last_not_of|find_last_of ( %name% [,)]") && tok->varId() == tok->tokAt(4)->varId()) { const Variable* var = tok->variable(); @@ -1617,7 +1617,7 @@ void CheckStl::readingEmptyStlContainer() if (i->type != Scope::eFunction) continue; - for (const Token *tok = i->classStart->next(); tok != i->classEnd; tok = tok->next()) { + for (const Token *tok = i->bodyStart->next(); tok != i->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "for|while")) { // Loops and end of scope clear the sets. const Token* tok2 = tok->linkAt(1); if (!tok2) diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index 6049a4fd2..e02e1763d 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -59,7 +59,7 @@ void CheckString::stringLiteralWrite() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!tok->variable() || !tok->variable()->isPointer()) continue; const Token *str = tok->getValueTokenMinStrSize(); @@ -172,7 +172,7 @@ void CheckString::checkSuspiciousStringCompare() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->tokType() != Token::eComparisonOp) continue; @@ -253,7 +253,7 @@ void CheckString::strPlusChar() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() == "+") { if (tok->astOperand1() && (tok->astOperand1()->tokType() == Token::eString)) { // string literal... if (tok->astOperand2() && (tok->astOperand2()->tokType() == Token::eChar || isChar(tok->astOperand2()->variable()))) // added to char variable or char constant @@ -282,7 +282,7 @@ void CheckString::checkIncorrectStringCompare() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // skip "assert(str && ..)" and "assert(.. && str)" if ((endsWith(tok->str(), "assert", 6) || endsWith(tok->str(), "ASSERT", 6)) && Token::Match(tok, "%name% (") && @@ -345,7 +345,7 @@ void CheckString::overlappingStrcmp() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() != "||") continue; std::list equals0; @@ -428,7 +428,7 @@ void CheckString::sprintfOverlappingData() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "sprintf|snprintf|swprintf (")) continue; diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 808392a69..3a0453b85 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -306,7 +306,7 @@ void CheckType::checkLongCast() // return statements const Token *ret = nullptr; - for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() == "return") { if (Token::Match(tok->astOperand1(), "<<|*")) { const ValueType *type = tok->astOperand1()->valueType(); diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index a4ec1af09..477f3a5f9 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -143,7 +143,7 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set const Variable *arg = scope->function->getArgumentVar(i); if (arg && arg->declarationId() && Token::Match(arg->typeStartToken(), "%type% * %name% [,)]")) { // Treat the pointer as initialized until it is assigned by malloc - for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "[;{}] %varid% = %name% (", arg->declarationId()) && _settings->library.returnuninitdata.count(tok->strAt(3)) == 1U) { if (arg->typeStartToken()->strAt(-1) == "struct" || (arg->type() && arg->type()->isStructType())) @@ -178,8 +178,8 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar) for (std::list::const_iterator it2 = symbolDatabase->scopeList.begin(); it2 != symbolDatabase->scopeList.end(); ++it2) { const Scope &innerScope = *it2; if (innerScope.type == Scope::eUnion && innerScope.nestedIn == scope2) { - if (var.typeStartToken()->linenr() >= innerScope.classStart->linenr() && - var.typeStartToken()->linenr() <= innerScope.classEnd->linenr()) { + if (var.typeStartToken()->linenr() >= innerScope.bodyStart->linenr() && + var.typeStartToken()->linenr() <= innerScope.bodyEnd->linenr()) { innerunion = true; break; } @@ -1230,7 +1230,7 @@ void CheckUninitVar::valueFlowUninit() for (std::list::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { if (!scope->isExecutable()) continue; - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (Token::simpleMatch(tok, "sizeof (")) { tok = tok->linkAt(1); continue; @@ -1256,7 +1256,7 @@ void CheckUninitVar::deadPointer() if (!scope->isExecutable()) continue; // Dead pointers.. - for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (tok->variable() && tok->variable()->isPointer() && isVariableUsage(tok, true, NO_ALLOC)) { diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 05cf15f29..331e84d53 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -57,7 +57,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); i++) { const Scope* scope = symbolDatabase->functionScopes[i]; const Function* func = scope->function; - if (!func || !func->token || scope->classStart->fileIndex() != 0) + if (!func || !func->token || scope->bodyStart->fileIndex() != 0) continue; // Don't warn about functions that are marked by __attribute__((constructor)) or __attribute__((destructor)) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index a0ce6b7d1..004a087a1 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -789,24 +789,24 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const // Check variable usage const Token *tok; if (scope->type == Scope::eFunction) - tok = scope->classStart->next(); + tok = scope->bodyStart->next(); else tok = scope->classDef->next(); - for (; tok && tok != scope->classEnd; tok = tok->next()) { + for (; tok && tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() == "for" || tok->str() == "while" || tok->str() == "do") { for (std::list::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) { if ((*i)->classDef == tok) { // Find associated scope checkFunctionVariableUsage_iterateScopes(*i, variables, true); // Scan child scope - tok = (*i)->classStart->link(); + tok = (*i)->bodyStart->link(); break; } } if (!tok) break; } - if (tok->str() == "{" && tok != scope->classStart && !tok->previous()->varId()) { + if (tok->str() == "{" && tok != scope->bodyStart && !tok->previous()->varId()) { for (std::list::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) { - if ((*i)->classStart == tok) { // Find associated scope + if ((*i)->bodyStart == tok) { // Find associated scope checkFunctionVariableUsage_iterateScopes(*i, variables, false); // Scan child scope tok = tok->link(); break; @@ -1315,11 +1315,11 @@ void CheckUnusedVar::checkStructMemberUsage() if (scope->type != Scope::eStruct && scope->type != Scope::eUnion) continue; - if (scope->classStart->fileIndex() != 0 || scope->className.empty()) + if (scope->bodyStart->fileIndex() != 0 || scope->className.empty()) continue; // Packed struct => possibly used by lowlevel code. Struct members might be required by hardware. - if (scope->classEnd->isAttributePacked()) + if (scope->bodyEnd->isAttributePacked()) continue; // Bail out if struct/union contains any functions @@ -1354,16 +1354,16 @@ void CheckUnusedVar::checkStructMemberUsage() // Bail out if some data is casted to struct.. const std::string castPattern("( struct| " + scope->className + " * ) & %name% ["); - if (Token::findmatch(scope->classEnd, castPattern.c_str())) + if (Token::findmatch(scope->bodyEnd, castPattern.c_str())) continue; // (struct S){..} const std::string initPattern("( struct| " + scope->className + " ) {"); - if (Token::findmatch(scope->classEnd, initPattern.c_str())) + if (Token::findmatch(scope->bodyEnd, initPattern.c_str())) continue; // Bail out if struct is used in sizeof.. - for (const Token *tok = scope->classEnd; nullptr != (tok = Token::findsimplematch(tok, "sizeof ("));) { + for (const Token *tok = scope->bodyEnd; nullptr != (tok = Token::findsimplematch(tok, "sizeof ("));) { tok = tok->tokAt(2); if (Token::Match(tok, ("struct| " + scope->className).c_str())) { bailout = true; @@ -1374,7 +1374,7 @@ void CheckUnusedVar::checkStructMemberUsage() continue; // Try to prevent false positives when struct members are not used directly. - if (Token::findmatch(scope->classEnd, (scope->className + " %type%| *").c_str())) + if (Token::findmatch(scope->bodyEnd, (scope->className + " %type%| *").c_str())) continue; for (std::list::const_iterator var = scope->varlist.cbegin(); var != scope->varlist.cend(); ++var) { diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 4570848f6..716f72526 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -55,9 +55,9 @@ void CheckVaarg::va_start_argument() const Function* function = scope->function; if (!function) continue; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (!tok->scope()->isExecutable()) - tok = tok->scope()->classEnd; + tok = tok->scope()->bodyEnd; else if (Token::simpleMatch(tok, "va_start (")) { const Token* param2 = tok->tokAt(2)->nextArgument(); if (!param2) @@ -107,7 +107,7 @@ void CheckVaarg::va_list_usage() bool exitOnEndOfStatement = false; const Token* tok = var->nameToken()->next(); - for (; tok && tok != var->scope()->classEnd; tok = tok->next()) { + for (; tok && tok != var->scope()->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "va_start ( %varid%", var->declarationId())) { if (open) va_start_subsequentCallsError(tok, var->name()); @@ -137,7 +137,7 @@ void CheckVaarg::va_list_usage() const Scope* scope = tok->scope(); while (scope->nestedIn && scope->type != Scope::eFor && scope->type != Scope::eWhile && scope->type != Scope::eDo && scope->type != Scope::eSwitch) scope = scope->nestedIn; - tok = scope->classEnd; + tok = scope->bodyEnd; if (!tok) return; } else if (tok->str() == "goto" || (_tokenizer->isCPP() && tok->str() == "try")) { diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 5eb03eb27..88f4c4a1a 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -160,10 +160,10 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } new_scope->classDef = tok; - new_scope->classStart = tok2; - new_scope->classEnd = tok2->link(); + new_scope->bodyStart = tok2; + new_scope->bodyEnd = tok2->link(); // make sure we have valid code - if (!new_scope->classEnd) { + if (!new_scope->bodyEnd) { _tokenizer->syntaxError(tok); } scope = new_scope; @@ -203,11 +203,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() tok2 = tok2->tokAt(2); } - new_scope->classStart = tok2; - new_scope->classEnd = tok2->link(); + new_scope->bodyStart = tok2; + new_scope->bodyEnd = tok2->link(); // make sure we have valid code - if (!new_scope->classEnd) { + if (!new_scope->bodyEnd) { _tokenizer->syntaxError(tok); } @@ -239,11 +239,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() const Token *tok2 = tok->linkAt(3)->next(); - new_scope->classStart = tok2; - new_scope->classEnd = tok2->link(); + new_scope->bodyStart = tok2; + new_scope->bodyEnd = tok2->link(); // make sure we have valid code - if (!new_scope->classEnd) { + if (!new_scope->bodyEnd) { scopeList.pop_back(); break; } @@ -328,11 +328,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() const Token *tok2 = tok->next(); - new_scope->classStart = tok2; - new_scope->classEnd = tok2->link(); + new_scope->bodyStart = tok2; + new_scope->bodyEnd = tok2->link(); // make sure we have valid code - if (!new_scope->classEnd) { + if (!new_scope->bodyEnd) { scopeList.pop_back(); break; } @@ -355,8 +355,8 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() const Token *tok2 = tok->next(); - new_scope->classStart = tok2; - new_scope->classEnd = tok2->link(); + new_scope->bodyStart = tok2; + new_scope->bodyEnd = tok2->link(); typeList.emplace_back(tok, new_scope, scope); { @@ -366,7 +366,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // make sure we have valid code - if (!new_scope->classEnd) { + if (!new_scope->bodyEnd) { scopeList.pop_back(); break; } @@ -387,7 +387,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } // check for end of scope - else if (tok == scope->classEnd) { + else if (tok == scope->bodyEnd) { access.erase(scope); scope = const_cast(scope->nestedIn); continue; @@ -907,7 +907,7 @@ void SymbolDatabase::createSymbolDatabaseVariableSymbolTable() const std::size_t functions = functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope *func = functionScopes[i]; - for (const Token *tok = func->classStart->next(); tok && tok != func->classEnd; tok = tok->next()) { + for (const Token *tok = func->bodyStart->next(); tok && tok != func->bodyEnd; tok = tok->next()) { // check for member variable if (tok->varId() && tok->next() && (tok->next()->str() == "." || @@ -933,8 +933,8 @@ void SymbolDatabase::createSymbolDatabaseSetScopePointers() { // Set scope pointers for (std::list::iterator it = scopeList.begin(); it != scopeList.end(); ++it) { - Token* start = const_cast(it->classStart); - Token* end = const_cast(it->classEnd); + Token* start = const_cast(it->bodyStart); + Token* end = const_cast(it->bodyEnd); if (it->type == Scope::eGlobal) { start = const_cast(_tokenizer->list.front()); end = const_cast(_tokenizer->list.back()); @@ -947,7 +947,7 @@ void SymbolDatabase::createSymbolDatabaseSetScopePointers() if (start != end && tok->str() == "{") { bool isEndOfScope = false; for (std::list::const_iterator innerScope = it->nestedList.begin(); innerScope != it->nestedList.end(); ++innerScope) { - if (tok == (*innerScope)->classStart) { // Is begin of inner scope + if (tok == (*innerScope)->bodyStart) { // Is begin of inner scope tok = tok->link(); if (tok->next() == end || !tok->next()) { isEndOfScope = true; @@ -1006,7 +1006,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass) continue; } tok = tok->next(); - while (tok && tok != func->functionScope->classStart) { + while (tok && tok != func->functionScope->bodyStart) { if (Token::Match(tok, "%name% {|(")) { if (tok->str() == func->tokenDef->str()) { const Function *function = func->functionScope->functionOf->findFunction(tok); @@ -1958,7 +1958,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se const Token * Function::constructorMemberInitialization() const { - if (!isConstructor() || !functionScope || !functionScope->classStart) + if (!isConstructor() || !functionScope || !functionScope->bodyStart) return nullptr; if (Token::Match(token, "%name% (") && Token::simpleMatch(token->linkAt(1), ") :")) return token->linkAt(1)->next(); @@ -2182,11 +2182,11 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok) } if (tok1 && tok1->str() == "{") { - newScope->classStart = tok1; - newScope->classEnd = tok1->link(); + newScope->bodyStart = tok1; + newScope->bodyEnd = tok1->link(); // syntax error? - if (!newScope->classEnd) { + if (!newScope->bodyEnd) { scopeList.pop_back(); while (tok1->next()) tok1 = tok1->next(); @@ -2612,8 +2612,8 @@ void SymbolDatabase::printOut(const char *title) const std::cout << "Scope: " << &*scope << " " << scope->type << std::endl; std::cout << " className: " << scope->className << std::endl; std::cout << " classDef: " << tokenToString(scope->classDef, _tokenizer) << std::endl; - std::cout << " classStart: " << tokenToString(scope->classStart, _tokenizer) << std::endl; - std::cout << " classEnd: " << tokenToString(scope->classEnd, _tokenizer) << std::endl; + std::cout << " bodyStart: " << tokenToString(scope->bodyStart, _tokenizer) << std::endl; + std::cout << " bodyEnd: " << tokenToString(scope->bodyEnd, _tokenizer) << std::endl; std::list::const_iterator func; @@ -2858,10 +2858,10 @@ void SymbolDatabase::printXml(std::ostream &out) const out << " type=\"" << scope->type << "\""; if (!scope->className.empty()) out << " className=\"" << ErrorLogger::toxml(scope->className) << "\""; - if (scope->classStart) - out << " classStart=\"" << scope->classStart << '\"'; - if (scope->classEnd) - out << " classEnd=\"" << scope->classEnd << '\"'; + if (scope->bodyStart) + out << " bodyStart=\"" << scope->bodyStart << '\"'; + if (scope->bodyEnd) + out << " bodyEnd=\"" << scope->bodyEnd << '\"'; if (scope->nestedIn) out << " nestedIn=\"" << scope->nestedIn << "\""; if (scope->function) @@ -3153,8 +3153,8 @@ const Variable* Function::getArgumentVar(std::size_t num) const Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_) : check(check_), classDef(classDef_), - classStart(start_), - classEnd(start_->link()), + bodyStart(start_), + bodyEnd(start_->link()), nestedIn(nestedIn_), numConstructors(0), numCopyOrMoveConstructors(0), @@ -3170,8 +3170,8 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope * Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_) : check(check_), classDef(classDef_), - classStart(nullptr), - classEnd(nullptr), + bodyStart(nullptr), + bodyEnd(nullptr), nestedIn(nestedIn_), numConstructors(0), numCopyOrMoveConstructors(0), @@ -3252,8 +3252,8 @@ void Scope::getVariableList(const Library* lib) { const Token *start; - if (classStart) - start = classStart->next(); + if (bodyStart) + start = bodyStart->next(); // global scope else if (className.empty()) @@ -3264,7 +3264,7 @@ void Scope::getVariableList(const Library* lib) return; AccessControl varaccess = defaultAccess(); - for (const Token *tok = start; tok && tok != classEnd; tok = tok->next()) { + for (const Token *tok = start; tok && tok != bodyEnd; tok = tok->next()) { // syntax error? if (tok->next() == nullptr) break; @@ -3831,7 +3831,7 @@ bool Scope::hasInlineOrLambdaFunction() const for (std::list::const_iterator it = nestedList.begin(); it != nestedList.end(); ++it) { const Scope *s = *it; // Inline function - if (s->type == Scope::eUnconditional && Token::simpleMatch(s->classStart->previous(), ") {")) + if (s->type == Scope::eUnconditional && Token::simpleMatch(s->bodyStart->previous(), ") {")) return true; // Lambda function if (s->type == Scope::eLambda) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index bf6164b68..4c6cff683 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -930,8 +930,8 @@ public: const SymbolDatabase *check; std::string className; const Token *classDef; ///< class/struct/union/namespace token - const Token *classStart; ///< '{' token - const Token *classEnd; ///< '}' token + const Token *bodyStart; ///< '{' token + const Token *bodyEnd; ///< '}' token std::list functionList; std::multimap functionMap; std::list varlist; diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 6507dd466..f9035e9a3 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -448,9 +448,9 @@ std::set TemplateSimplifier::expandSpecialized(Token *tokens) /// TODO: This is copy pasted from Tokenizer. We should reuse this code. namespace { struct ScopeInfo2 { - ScopeInfo2(const std::string &name_, const Token *classEnd_) : name(name_), classEnd(classEnd_) {} + ScopeInfo2(const std::string &name_, const Token *bodyEnd_) : name(name_), bodyEnd(bodyEnd_) {} const std::string name; - const Token * const classEnd; + const Token * const bodyEnd; }; } static std::string getScopeName(const std::list &scopeInfo) @@ -468,7 +468,7 @@ static std::string getFullName(const std::list &scopeInfo, const std static void setScopeInfo(const Token *tok, std::list *scopeInfo) { - while (tok->str() == "}" && !scopeInfo->empty() && tok == scopeInfo->back().classEnd) + while (tok->str() == "}" && !scopeInfo->empty() && tok == scopeInfo->back().bodyEnd) scopeInfo->pop_back(); if (!Token::Match(tok, "namespace|class|struct %name% {|:|::")) return; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0ae535f81..d604a3bc5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -397,9 +397,9 @@ Token * Tokenizer::deleteInvalidTypedef(Token *typeDef) namespace { struct Space { - Space() : classEnd(nullptr), isNamespace(false) { } + Space() : bodyEnd(nullptr), isNamespace(false) { } std::string className; - const Token * classEnd; + const Token * bodyEnd; bool isNamespace; }; } @@ -574,11 +574,11 @@ void Tokenizer::simplifyTypedef() Space info; info.isNamespace = isNamespace; info.className = className; - info.classEnd = tok->link(); + info.bodyEnd = tok->link(); spaceInfo.push_back(info); hasClass = false; - } else if (!spaceInfo.empty() && tok->str() == "}" && spaceInfo.back().classEnd == tok) { + } else if (!spaceInfo.empty() && tok->str() == "}" && spaceInfo.back().bodyEnd == tok) { spaceInfo.pop_back(); } continue; @@ -1026,7 +1026,7 @@ void Tokenizer::simplifyTypedef() inMemberFunc = false; } - if (classLevel > 0 && tok2 == spaceInfo[classLevel - 1].classEnd) { + if (classLevel > 0 && tok2 == spaceInfo[classLevel - 1].bodyEnd) { --classLevel; pattern.clear(); @@ -1079,7 +1079,7 @@ void Tokenizer::simplifyTypedef() if (classLevel < spaceInfo.size() && spaceInfo[classLevel].isNamespace && spaceInfo[classLevel].className == tok2->previous()->str()) { - spaceInfo[classLevel].classEnd = tok2->link(); + spaceInfo[classLevel].bodyEnd = tok2->link(); ++classLevel; pattern.clear(); for (std::size_t i = classLevel; i < spaceInfo.size(); ++i) @@ -2859,9 +2859,9 @@ namespace { }; struct ScopeInfo2 { - ScopeInfo2(const std::string &name_, const Token *classEnd_) : name(name_), classEnd(classEnd_) {} + ScopeInfo2(const std::string &name_, const Token *bodyEnd_) : name(name_), bodyEnd(bodyEnd_) {} const std::string name; - const Token * const classEnd; + const Token * const bodyEnd; }; } @@ -3015,7 +3015,7 @@ void Tokenizer::setVarIdPass2() // class members.. std::map > varsByClass; for (Token *tok = list.front(); tok; tok = tok->next()) { - while (tok->str() == "}" && !scopeInfo.empty() && tok == scopeInfo.back().classEnd) + while (tok->str() == "}" && !scopeInfo.empty() && tok == scopeInfo.back().bodyEnd) scopeInfo.pop_back(); if (!Token::Match(tok, "namespace|class|struct %name% {|:|::")) @@ -9787,10 +9787,10 @@ void Tokenizer::removeUnnecessaryQualification() tok = tok->next(); if (!tok) return; - info.classEnd = tok->link(); + info.bodyEnd = tok->link(); classInfo.push_back(info); } else if (!classInfo.empty()) { - if (tok == classInfo.back().classEnd) + if (tok == classInfo.back().bodyEnd) classInfo.pop_back(); else if (tok->str() == classInfo.back().className && !classInfo.back().isNamespace && tok->previous()->str() != ":" && diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 3403de624..0c69372f7 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1271,7 +1271,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symbo const std::size_t functions = symboldatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symboldatabase->functionScopes[i]; - for (Token* tok = const_cast(scope->classStart); tok != scope->classEnd; tok = tok->next()) { + for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { MathLib::bigint num = 0; const Token *vartok = nullptr; if (tok->isComparisonOp() && tok->astOperand1() && tok->astOperand2()) { @@ -1816,8 +1816,8 @@ static bool valueFlowForward(Token * const startToken, if (loopCondition) { const Token *tok3 = Token::findmatch(start, "%varid%", end, varid); if (Token::Match(tok3, "%varid% =", varid) && - tok3->scope()->classEnd && - Token::Match(tok3->scope()->classEnd->tokAt(-3), "[;}] break ;") && + tok3->scope()->bodyEnd && + Token::Match(tok3->scope()->bodyEnd->tokAt(-3), "[;}] break ;") && !Token::findmatch(tok3->next(), "%varid%", end, varid)) { bail = false; tok2 = end; @@ -1880,7 +1880,7 @@ static bool valueFlowForward(Token * const startToken, } if (tok2->str() == "break") { if (scope && scope->type == Scope::eSwitch) { - tok2 = const_cast(scope->classEnd); + tok2 = const_cast(scope->bodyEnd); if (tok2 == endToken) break; --indentlevel; @@ -2206,14 +2206,14 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab const Scope * scope = symboldatabase->functionScopes[i]; if (!scope) continue; - const Token * start = scope->classStart; + const Token * start = scope->bodyStart; if (scope->function) { const Token * memberInitializationTok = scope->function->constructorMemberInitialization(); if (memberInitializationTok) start = memberInitializationTok; } - for (Token* tok = const_cast(start); tok != scope->classEnd; tok = tok->next()) { + for (Token* tok = const_cast(start); tok != scope->bodyEnd; tok = tok->next()) { Token * varTok; if (Token::Match(tok, "%var% . reset|clear (") && tok->next()->originalName() == emptyString) { varTok = tok; @@ -2229,7 +2229,7 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab if (!var || (!var->isLocal() && !var->isArgument())) continue; const unsigned int varId = varTok->varId(); - const Token * const endOfVarScope = var->typeStartToken()->scope()->classEnd; + const Token * const endOfVarScope = var->typeStartToken()->scope()->bodyEnd; setTokenValue(varTok, value, settings); valueFlowForward(varTok->next(), endOfVarScope, var, varId, values, false, false, tokenlist, errorLogger, settings); continue; @@ -2252,7 +2252,7 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab const Variable *var = varTok->variable(); if (!var) continue; - const Token * const endOfVarScope = var->typeStartToken()->scope()->classEnd; + const Token * const endOfVarScope = var->typeStartToken()->scope()->bodyEnd; ValueFlow::Value value; value.valueType = ValueFlow::Value::MOVED; @@ -2278,7 +2278,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat for (std::size_t i = 0; i < functions; ++i) { std::set aliased; const Scope * scope = symboldatabase->functionScopes[i]; - for (Token* tok = const_cast(scope->classStart); tok != scope->classEnd; tok = tok->next()) { + for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { // Alias if (tok->str() == "&" && !tok->astOperand2() && tok->astOperand1()) { aliased.insert(tok->astOperand1()->varId()); @@ -2299,7 +2299,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat if (!var || (!var->isLocal() && !var->isGlobal() && !var->isArgument())) continue; - const Token * const endOfVarScope = var->typeStartToken()->scope()->classEnd; + const Token * const endOfVarScope = var->typeStartToken()->scope()->bodyEnd; // Rhs values.. if (!tok->astOperand2() || tok->astOperand2()->values().empty()) @@ -2340,7 +2340,7 @@ static void valueFlowAfterCondition(TokenList *tokenlist, SymbolDatabase* symbol for (std::size_t func = 0; func < functions; ++func) { const Scope * scope = symboldatabase->functionScopes[func]; std::set aliased; - for (Token* tok = const_cast(scope->classStart); tok != scope->classEnd; tok = tok->next()) { + for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { const Token * vartok = nullptr; const Token * numtok = nullptr; const Token * lowertok = nullptr; @@ -2584,7 +2584,7 @@ static void valueFlowAfterCondition(TokenList *tokenlist, SymbolDatabase* symbol // TODO: constValue could be true if there are no assignments in the conditional blocks and // perhaps if there are no && and no || in the condition bool constValue = false; - valueFlowForward(after->next(), top->scope()->classEnd, var, varid, *values, constValue, false, tokenlist, errorLogger, settings); + valueFlowForward(after->next(), top->scope()->bodyEnd, var, varid, *values, constValue, false, tokenlist, errorLogger, settings); } } } @@ -2949,9 +2949,9 @@ static void valueFlowForLoopSimplifyAfter(Token *fortok, unsigned int varid, con const Variable *var = vartok->variable(); const Token *endToken = nullptr; if (var->isLocal()) - endToken = var->typeStartToken()->scope()->classEnd; + endToken = var->typeStartToken()->scope()->bodyEnd; else - endToken = fortok->scope()->classEnd; + endToken = fortok->scope()->bodyEnd; std::list values; values.emplace_back(num); @@ -2976,7 +2976,7 @@ static void valueFlowForLoop(TokenList *tokenlist, SymbolDatabase* symboldatabas continue; Token* tok = const_cast(scope->classDef); - Token* const bodyStart = const_cast(scope->classStart); + Token* const bodyStart = const_cast(scope->bodyStart); if (!Token::simpleMatch(tok->next()->astOperand2(), ";") || !Token::simpleMatch(tok->next()->astOperand2()->astOperand2(), ";")) @@ -3027,7 +3027,7 @@ static void valueFlowInjectParameter(TokenList* tokenlist, ErrorLogger* errorLog if (!varid2) return; - valueFlowForward(const_cast(functionScope->classStart->next()), functionScope->classEnd, arg, varid2, argvalues, false, true, tokenlist, errorLogger, settings); + valueFlowForward(const_cast(functionScope->bodyStart->next()), functionScope->bodyEnd, arg, varid2, argvalues, false, true, tokenlist, errorLogger, settings); } static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings) @@ -3049,7 +3049,7 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol continue; } - for (Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { if (tok->str() == "{") { tok = tok->link(); continue; @@ -3085,7 +3085,7 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol if (vartok->variable()->scope()) { if (known) values.back().setKnown(); - valueFlowForward(tok->tokAt(3), vartok->variable()->scope()->classEnd, vartok->variable(), vartok->varId(), values, values.back().isKnown(), false, tokenlist, errorLogger, settings); + valueFlowForward(tok->tokAt(3), vartok->variable()->scope()->bodyEnd, vartok->variable(), vartok->varId(), values, values.back().isKnown(), false, tokenlist, errorLogger, settings); } } } @@ -3279,8 +3279,8 @@ static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogg // Get scope and args of function const Function * const function = tok->astOperand1()->function(); const Scope * const functionScope = function->functionScope; - if (!functionScope || !Token::simpleMatch(functionScope->classStart, "{ return")) { - if (functionScope && tokenlist->getSettings()->debugwarnings && Token::findsimplematch(functionScope->classStart, "return", functionScope->classEnd)) + if (!functionScope || !Token::simpleMatch(functionScope->bodyStart, "{ return")) { + if (functionScope && tokenlist->getSettings()->debugwarnings && Token::findsimplematch(functionScope->bodyStart, "return", functionScope->bodyEnd)) bailout(tokenlist, errorLogger, tok, "function return; nontrivial function body"); continue; } @@ -3302,7 +3302,7 @@ static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogg // Determine return value of subfunction.. MathLib::bigint result = 0; bool error = false; - execute(functionScope->classStart->next()->astOperand1(), + execute(functionScope->bodyStart->next()->astOperand1(), &programMemory, &result, &error); @@ -3354,7 +3354,7 @@ static void valueFlowUninit(TokenList *tokenlist, SymbolDatabase * /*symbolDatab const bool constValue = true; const bool subFunction = false; - valueFlowForward(vardecl->next(), vardecl->scope()->classEnd, var, vardecl->varId(), values, constValue, subFunction, tokenlist, errorLogger, settings); + valueFlowForward(vardecl->next(), vardecl->scope()->bodyEnd, var, vardecl->varId(), values, constValue, subFunction, tokenlist, errorLogger, settings); } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index fc71e444c..11fb5b88d 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -398,7 +398,7 @@ private: const Token * start = tokenizer.tokens(); const SymbolDatabase * db = tokenizer.getSymbolDatabase(); if (db && db->functionScopes.size()) - start = db->functionScopes[0]->classStart->next(); + start = db->functionScopes[0]->bodyStart->next(); const unsigned int varId(Token::findmatch(start, varname)->varId()); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 4e4402036..678b5aba9 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -1596,7 +1596,7 @@ private: GET_SYMBOL_DB("void func();\n" "int bar() {}\n" "void func() {}") - ASSERT_EQUALS(3, db->findScopeByName("func")->classStart->linenr()); + ASSERT_EQUALS(3, db->findScopeByName("func")->bodyStart->linenr()); } void Cpp11InitInInitList() { @@ -1605,7 +1605,7 @@ private: " Foo() : bar({\"a\", \"b\"})\n" " {}\n" "};"); - ASSERT_EQUALS(4, db->scopeList.front().nestedList.front()->nestedList.front()->classStart->linenr()); + ASSERT_EQUALS(4, db->scopeList.front().nestedList.front()->nestedList.front()->bodyStart->linenr()); } void hasGlobalVariables1() { @@ -3793,7 +3793,7 @@ private: if (bar) { unsigned int linenrs[] = { 2, 1 }; unsigned int index = 0; - for (const Token * tok = bar->classStart->next(); tok != bar->classEnd; tok = tok->next()) { + for (const Token * tok = bar->bodyStart->next(); tok != bar->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%name% (") && !tok->varId() && Token::simpleMatch(tok->linkAt(1), ") ;")) { const Function * function = db->findFunction(tok); ASSERT(function != nullptr);