diff --git a/lib/check64bit.cpp b/lib/check64bit.cpp index b664ba5f8..c1acc3fbc 100644 --- a/lib/check64bit.cpp +++ b/lib/check64bit.cpp @@ -52,7 +52,7 @@ void Check64BitPortability::pointerassignment() if (Token::Match(tok, "[;{}] %var% = %var% [;+]")) { const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); - const Variable *var1(symbolDatabase->getVariableFromVarId(tok->tokAt(1)->varId())); + const Variable *var1(symbolDatabase->getVariableFromVarId(tok->next()->varId())); const Variable *var2(symbolDatabase->getVariableFromVarId(tok->tokAt(3)->varId())); if (isaddr(var1) && isint(var2) && tok->strAt(4) != "+") diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index c9ecfff90..f5e320133 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -105,7 +105,7 @@ void CheckAutoVariables::autoVariables() } else if (Token::Match(tok, "[;{}] %var% . %var% = & %var%")) { // TODO: check if the parameter is only changed temporarily (#2969) if (_settings->inconclusive) { - const Variable * var1 = symbolDatabase->getVariableFromVarId(tok->tokAt(1)->varId()); + const Variable * var1 = symbolDatabase->getVariableFromVarId(tok->next()->varId()); if (var1 && var1->isArgument() && Token::Match(var1->nameToken()->tokAt(-2), "%type% *")) { const Variable * var2 = symbolDatabase->getVariableFromVarId(tok->tokAt(6)->varId()); if (var2 && var2->isLocal() && !var2->isStatic() && !Token::simpleMatch(var2->typeEndToken(), "*")) @@ -116,7 +116,7 @@ void CheckAutoVariables::autoVariables() } else if (Token::Match(tok, "[;{}] %var% . %var% = %var% ;")) { // TODO: check if the parameter is only changed temporarily (#2969) if (_settings->inconclusive) { - const Variable * var1 = symbolDatabase->getVariableFromVarId(tok->tokAt(1)->varId()); + const Variable * var1 = symbolDatabase->getVariableFromVarId(tok->next()->varId()); if (var1 && var1->isArgument() && Token::Match(var1->nameToken()->tokAt(-2), "%type% *")) { const Variable * var2 = symbolDatabase->getVariableFromVarId(tok->tokAt(5)->varId()); if (var2 && var2->isLocal() && var2->isArray() && !var2->isStatic()) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index db564be5b..407d76346 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1301,12 +1301,12 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() if (indentlevel > 0 && Token::Match(tok, "[*;{}] %var% = new %type% [ %num% ]")) { size = MathLib::toLongNumber(tok->strAt(6)); type = tok->strAt(4); - varid = tok->tokAt(1)->varId(); + varid = tok->next()->varId(); nextTok = 8; } else if (indentlevel > 0 && Token::Match(tok, "[*;{}] %var% = new %type% ( %num% )")) { size = 1; type = tok->strAt(4); - varid = tok->tokAt(1)->varId(); + varid = tok->next()->varId(); nextTok = 8; } else if (indentlevel > 0 && Token::Match(tok, "[;{}] %var% = %str% ;") && @@ -1319,7 +1319,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() } else if (indentlevel > 0 && Token::Match(tok, "[*;{}] %var% = malloc|alloca ( %num% ) ;")) { size = MathLib::toLongNumber(tok->strAt(5)); type = "char"; // minimum type, typesize=1 - varid = tok->tokAt(1)->varId(); + varid = tok->next()->varId(); nextTok = 7; if (varid > 0) { diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index cd40e7ac4..c8fc867e6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -985,7 +985,7 @@ bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs) for (const Token *tok = func->start; tok && tok != last; tok = tok->next()) { if (Token::simpleMatch(tok, "if (")) { const Token *tok1 = tok->tokAt(2); - const Token *tok2 = tok->tokAt(1)->link(); + const Token *tok2 = tok->next()->link(); if (tok1 && tok2) { for (; tok1 && tok1 != tok2; tok1 = tok1->next()) { diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 399011266..a20cd9890 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2275,18 +2275,18 @@ void CheckMemoryLeakInFunction::checkReallocUsage() } memleakUponReallocFailureError(tok, tok->str()); - } else if (tok->tokAt(1)->varId() > 0 && + } else if (tok->next()->varId() > 0 && (Token::Match(tok, "* %var% = realloc|g_try_realloc ( * %var% , %any%") && - tok->tokAt(1)->varId() == tok->tokAt(6)->varId())&& - parameterVarIds.find(tok->tokAt(1)->varId()) == parameterVarIds.end()) { + tok->next()->varId() == tok->tokAt(6)->varId())&& + parameterVarIds.find(tok->next()->varId()) == parameterVarIds.end()) { // Check that another copy of the pointer wasn't saved earlier in the function - if (Token::findmatch(startOfFunction, "%var% = * %varid% ;", tok->tokAt(1)->varId()) || - Token::findmatch(startOfFunction, "[{};] * %varid% = %var% [;=]", tok->tokAt(1)->varId())) + if (Token::findmatch(startOfFunction, "%var% = * %varid% ;", tok->next()->varId()) || + Token::findmatch(startOfFunction, "[{};] * %varid% = %var% [;=]", tok->next()->varId())) continue; const Token* tokEndRealloc = tok->linkAt(4); // Check that the allocation isn't followed immediately by an 'if (!var) { error(); }' that might handle failure - if (Token::Match(tokEndRealloc->tokAt(1), "; if ( ! * %varid% ) {", tok->tokAt(1)->varId())) { + if (Token::Match(tokEndRealloc->tokAt(1), "; if ( ! * %varid% ) {", tok->next()->varId())) { const Token* tokEndBrace = tokEndRealloc->linkAt(8); if (tokEndBrace && Token::simpleMatch(tokEndBrace->tokAt(-2), ") ;") && Token::Match(tokEndBrace->linkAt(-2)->tokAt(-2), "{|}|; %var% (")) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 377fa4c07..e90d03380 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -587,9 +587,9 @@ void CheckOther::checkSwitchCaseFallThrough() std::stack scopenest; bool justbreak = true; bool firstcase = true; - for (const Token *tok2 = tok->tokAt(1)->link()->tokAt(2); tok2; tok2 = tok2->next()) { + for (const Token *tok2 = tok->next()->link()->tokAt(2); tok2; tok2 = tok2->next()) { if (Token::simpleMatch(tok2, "if (")) { - tok2 = tok2->tokAt(1)->link()->next(); + tok2 = tok2->next()->link()->next(); if (tok2->link() == NULL) { std::ostringstream errmsg; errmsg << "unmatched if in switch: " << tok2->linenr(); @@ -599,7 +599,7 @@ void CheckOther::checkSwitchCaseFallThrough() ifnest.push(std::make_pair(tok2->link(), false)); justbreak = false; } else if (Token::simpleMatch(tok2, "while (")) { - tok2 = tok2->tokAt(1)->link()->next(); + tok2 = tok2->next()->link()->next(); // skip over "do { } while ( ) ;" case if (tok2->str() == "{") { if (tok2->link() == NULL) { @@ -622,7 +622,7 @@ void CheckOther::checkSwitchCaseFallThrough() loopnest.push(tok2->link()); justbreak = false; } else if (Token::simpleMatch(tok2, "for (")) { - tok2 = tok2->tokAt(1)->link()->next(); + tok2 = tok2->next()->link()->next(); if (tok2->link() == NULL) { std::ostringstream errmsg; errmsg << "unmatched for in switch: " << tok2->linenr(); @@ -633,7 +633,7 @@ void CheckOther::checkSwitchCaseFallThrough() justbreak = false; } else if (Token::Match(tok2, switchPattern)) { // skip over nested switch, we'll come to that soon - tok2 = tok2->tokAt(1)->link()->next()->link(); + tok2 = tok2->next()->link()->next()->link(); } else if (Token::Match(tok2, breakPattern)) { if (loopnest.empty()) { justbreak = true; @@ -1330,7 +1330,7 @@ void CheckOther::checkComparisonOfBoolWithInt() std::map boolvars; // Contains all declarated standard type variables and indicates whether its a bool or not. for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { - if (Token::Match(tok, "[{};(,] %type% %var% [;=,)]") && tok->tokAt(1)->isStandardType()) { // Declaration of standard type variable + if (Token::Match(tok, "[{};(,] %type% %var% [;=,)]") && tok->next()->isStandardType()) { // Declaration of standard type variable boolvars[tok->tokAt(2)->varId()] = (tok->strAt(1) == "bool"); } else if (Token::Match(tok, "%var% >|>=|==|!=|<=|< %num%")) { // Comparing variable with number const Token *varTok = tok; @@ -1444,7 +1444,7 @@ void CheckOther::checkUnsignedDivision() std::map varsign; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { if (Token::Match(tok, "[{};(,] %type% %var% [;=,)]")) { - if (tok->tokAt(1)->isUnsigned()) + if (tok->next()->isUnsigned()) varsign[tok->tokAt(2)->varId()] = 'u'; else varsign[tok->tokAt(2)->varId()] = 's'; @@ -1452,7 +1452,7 @@ void CheckOther::checkUnsignedDivision() else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %num%")) { if (tok->strAt(3)[0] == '-') { - char sign1 = varsign[tok->tokAt(1)->varId()]; + char sign1 = varsign[tok->next()->varId()]; if (sign1 == 'u') { udivError(tok->next()); } @@ -1482,7 +1482,7 @@ void CheckOther::checkMemsetZeroBytes() { for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) { if (Token::simpleMatch(tok, "memset (")) { - const Token* lastParamTok = tok->tokAt(1)->link()->tokAt(-1); + const Token* lastParamTok = tok->next()->link()->tokAt(-1); if (lastParamTok->str() == "0") memsetZeroBytesError(tok, tok->strAt(2)); } diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 6afaa8910..972076b24 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -261,7 +261,7 @@ void CheckStl::stlOutOfBounds() unsigned int indent3 = 0; // variable id for loop variable. - unsigned int numId = tok2->tokAt(1)->varId(); + unsigned int numId = tok2->next()->varId(); // variable id for the container variable unsigned int varId = tok2->tokAt(3)->varId(); @@ -1189,7 +1189,7 @@ void CheckStl::uselessCalls() if (tok->varId() == 0) continue; /*if (Token::Match(tok, "%var% . compare (") && - tok->varId() == tok->linkAt(3)->tokAt(-1)->varId()) { + tok->varId() == tok->linkAt(3)->previous()->varId()) { uselessCallsReturnValueError(tok, tok->tokAt(2)); } else */ if (Token::Match(tok, "%var% . compare|find|rfind|find_first_not_of|find_first_of|find_last_not_of|find_last_of ( %var% [,)]") && diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 02c60df6f..e9df251ff 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -371,7 +371,7 @@ private: reset(); givenACodeSampleToTokenize var("X< 1>2 > x1;\n"); - found = si.findClosingBracket(var.tokens()->tokAt(1), t); + found = si.findClosingBracket(var.tokens()->next(), t); ASSERT(found); ASSERT_EQUALS(">", t->str()); ASSERT_EQUALS(var.tokens()->strAt(3), t->str()); @@ -381,7 +381,7 @@ private: reset(); givenACodeSampleToTokenize var("X < (2 < 1) > x1;\n"); - found = si.findClosingBracket(var.tokens()->tokAt(1), t); + found = si.findClosingBracket(var.tokens()->next(), t); ASSERT(!found); } @@ -392,14 +392,14 @@ private: ASSERT(db && db->scopeList.size() == 2 && tokenizer.getFunctionTokenByName("func")); if (db) { - const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(1)); + const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->next()); ASSERT(scope && scope->className == "func"); - const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(1)); + const Function *function = db->findFunctionByToken(tokenizer.tokens()->next()); ASSERT(function && function->token->str() == "func"); - ASSERT(function && function->token == tokenizer.tokens()->tokAt(1)); + ASSERT(function && function->token == tokenizer.tokens()->next()); ASSERT(function && function->hasBody); } }