Skip to content

Commit b28a44d

Browse files
committed
Change: 'next()->next()'->'tokAt(2)', 'previous()->previous()'->'tokAt(-2)'.
1 parent ed6a0e1 commit b28a44d

6 files changed

Lines changed: 27 additions & 27 deletions

File tree

lib/checkobsoletefunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void CheckObsoleteFunctions::obsoleteFunctions()
4545
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
4646

4747
if (tok->isName() && tok->varId()==0 && (tok->next() && tok->next()->str() == "(") &&
48-
(!Token::Match(tok->previous(), ".|::|:|,") || Token::simpleMatch(tok->previous()->previous(), "std :: gets"))) {
48+
(!Token::Match(tok->previous(), ".|::|:|,") || Token::simpleMatch(tok->tokAt(-2), "std :: gets"))) {
4949
// c function declaration?
5050
if ((tok->next()->link()->next() && tok->next()->link()->next()->str() == ";") && (tok->previous() && (tok->previous()->str() == "*" || tok->previous()->isName()))) {
5151
continue;

lib/checkpostfixoperator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void CheckPostfixOperator::postfixOperator()
4747
for (; tok; tok = tok->next()) {
4848
bool result = false;
4949
if (Token::Match(tok, "++|--")) {
50-
if (Token::Match(tok->previous()->previous(), ";|{|}") && Token::Match(tok->next(), ";|)|,")) {
50+
if (Token::Match(tok->tokAt(-2), ";|{|}") && Token::Match(tok->next(), ";|)|,")) {
5151
result = true;
5252
} else if (tok->strAt(-2) == ",") {
5353
int i(1);

lib/checkstl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ bool CheckStl::isStlContainer(unsigned int varid)
787787

788788
// discard namespace if supplied
789789
if (Token::simpleMatch(type, "std ::"))
790-
type = type->next()->next();
790+
type = type->tokAt(2);
791791

792792
// all possible stl containers
793793
static const char STL_CONTAINER_LIST[] = "bitset|deque|list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|vector";
@@ -1091,7 +1091,7 @@ static bool hasArrayEndParen(const Token *tok1)
10911091
{
10921092
const Token *end = Token::findsimplematch(tok1, ";");
10931093
return (end && end->previous() &&
1094-
Token::simpleMatch(end->previous()->previous(), "] ) ;"));
1094+
Token::simpleMatch(end->tokAt(-2), "] ) ;"));
10951095
}
10961096

10971097
//---------------------------------------------------------------------------
@@ -1109,10 +1109,10 @@ void CheckStl::checkAutoPointer()
11091109
(Token::simpleMatch(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) {
11101110
autoPointerContainerError(tok);
11111111
} else {
1112-
const Token *tok2 = tok->next()->next();
1112+
const Token *tok2 = tok->tokAt(2);
11131113
while (tok2) {
11141114
if (Token::Match(tok2, "> %var%")) {
1115-
const Token *tok3 = tok2->next()->next();
1115+
const Token *tok3 = tok2->tokAt(2);
11161116
if (Token::Match(tok3, "( new %type%") && hasArrayEndParen(tok3)) {
11171117
autoPointerArrayError(tok2->next());
11181118
break;
@@ -1121,7 +1121,7 @@ void CheckStl::checkAutoPointer()
11211121
tok3 = tok3->next();
11221122
}
11231123
if (tok3) {
1124-
tok3 = tok3->previous()->previous();
1124+
tok3 = tok3->tokAt(-2);
11251125
if (Token::simpleMatch(tok3->previous(), "[ ] )")) {
11261126
autoPointerArrayError(tok2->next());
11271127
} else if (tok3->varId()) {
@@ -1142,9 +1142,9 @@ void CheckStl::checkAutoPointer()
11421142
} else {
11431143
if (Token::Match(tok, "%var% = %var% ;")) {
11441144
if (_settings->isEnabled("style")) {
1145-
iter = autoPtrVarId.find(tok->next()->next()->varId());
1145+
iter = autoPtrVarId.find(tok->tokAt(2)->varId());
11461146
if (iter != autoPtrVarId.end()) {
1147-
autoPointerError(tok->next()->next());
1147+
autoPointerError(tok->tokAt(2));
11481148
}
11491149
}
11501150
} else if ((Token::Match(tok, "%var% = new %type% ") && hasArrayEnd(tok)) ||

lib/checkunusedvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
722722
// standard const type declaration
723723
// const int i = x;
724724
else if (Token::Match(tok, "[;{}] const %type% %var% =")) {
725-
tok = tok->next()->next();
725+
tok = tok->tokAt(2);
726726

727727
if (tok->isStandardType() || isRecordTypeWithoutSideEffects(tok->next()))
728728
variables.addVar(tok->next(), Variables::standard, info, true);

lib/symboldatabase.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
375375

376376
// class destructor
377377
else if (tok->previous() && tok->previous()->str() == "~" &&
378-
tok->previous()->previous() && tok->previous()->previous()->str() == "::")
378+
tok->tokAt(-2) && tok->tokAt(-2)->str() == "::")
379379
addFunction(&scope, &tok, argStart);
380380

381381
// regular function
@@ -501,8 +501,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
501501
scope = &scopeList.back();
502502
scope->nestedIn->nestedList.push_back(scope);
503503
} else if (Token::simpleMatch(tok, "else if (") &&
504-
Token::simpleMatch(tok->next()->next()->link(), ") {")) {
505-
const Token *tok1 = tok->next()->next()->link()->next();
504+
Token::simpleMatch(tok->tokAt(2)->link(), ") {")) {
505+
const Token *tok1 = tok->tokAt(2)->link()->next();
506506
scopeList.push_back(Scope(this, tok, scope, Scope::eElseIf, tok1));
507507
tok = tok1;
508508
scope = &scopeList.back();
@@ -989,7 +989,7 @@ void SymbolDatabase::addFunction(Scope **scope, const Token **tok, const Token *
989989
func->hasBody = true;
990990
func->token = *tok;
991991
func->arg = argStart;
992-
const Token *start = argStart->link()->next()->next()->link()->next();
992+
const Token *start = argStart->link()->tokAt(2)->link()->next();
993993
while (start && start->str() != "{")
994994
start = start->next();
995995
func->start = start;
@@ -1436,7 +1436,7 @@ void Scope::getVariableList()
14361436
} else
14371437
break;
14381438
} else if (Token::Match(tok, "struct|union {") && Token::Match(tok->next()->link(), "} %var% ;|[")) {
1439-
tok = tok->next()->link()->next()->next();
1439+
tok = tok->next()->link()->tokAt(2);
14401440
continue;
14411441
} else if (Token::Match(tok, "struct|union {") && Token::simpleMatch(tok->next()->link(), "} ;")) {
14421442
level++;
@@ -1494,7 +1494,7 @@ void Scope::getVariableList()
14941494
else if (Token::Match(tok, ";|{|}"))
14951495
continue;
14961496
else if (Token::Match(tok, "goto %var% ;")) {
1497-
tok = tok->next()->next();
1497+
tok = tok->tokAt(2);
14981498
continue;
14991499
}
15001500

lib/tokenize.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ void Tokenizer::simplifyTypedef()
14021402

14031403
if (pattern1.find("::") != std::string::npos) { // has a "something ::"
14041404
if (Token::simpleMatch(tok2->previous(), "::")) {
1405-
tok2->previous()->previous()->deleteNext();
1405+
tok2->tokAt(-2)->deleteNext();
14061406
globalScope = true;
14071407
}
14081408

@@ -1743,7 +1743,7 @@ void Tokenizer::simplifyTypedef()
17431743
if (tok2->next()->str() == "{")
17441744
tok2 = tok2->next()->link()->next();
17451745
else if (tok2->next()->str().at(0) == '\"')
1746-
tok2 = tok2->next()->next();
1746+
tok2 = tok2->tokAt(2);
17471747
}
17481748
} while (Token::Match(tok2, ", %var% ;|'|=|,"));
17491749
}
@@ -1897,7 +1897,7 @@ bool Tokenizer::tokenize(std::istream &code,
18971897
if (_files[0].find(".cs")) {
18981898
for (Token *tok = _tokens; tok; tok = tok->next()) {
18991899
if (Token::Match(tok, "[;{}] %type% [ ] %var% [=;]")) {
1900-
tok = tok->next()->next();
1900+
tok = tok->tokAt(2);
19011901
tok->str("*");
19021902
tok->deleteNext();
19031903
}
@@ -6323,7 +6323,7 @@ void Tokenizer::simplifyIfNot()
63236323
if (Token::Match(tok->link()->tokAt(-2), "( %var%")) {
63246324
Token::eraseTokens(tok, tok->tokAt(3));
63256325
tok->link()->previous()->insertToken(tok->link()->previous()->str().c_str());
6326-
tok->link()->previous()->previous()->str("!");
6326+
tok->link()->tokAt(-2)->str("!");
63276327
}
63286328

63296329
// if( (x) == 0 )
@@ -7012,7 +7012,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
70127012
};
70137013
for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
70147014
if (tok3->str() == functionName[i]) {
7015-
Token *par1 = tok3->next()->next();
7015+
Token *par1 = tok3->tokAt(2);
70167016
if (!structname.empty()) {
70177017
par1->deleteThis();
70187018
par1->deleteThis();
@@ -7376,7 +7376,7 @@ bool Tokenizer::simplifyCalculations()
73767376
tok = tok->previous();
73777377
if (Token::Match(tok->tokAt(-4), "[;{}] %var% = %var% [+-|] 0 ;") &&
73787378
tok->strAt(-3) == tok->previous()->str()) {
7379-
tok = tok->previous()->previous()->previous();
7379+
tok = tok->tokAt(-3);
73807380
tok->deleteThis();
73817381
tok->deleteThis();
73827382
tok->deleteThis();
@@ -8432,9 +8432,9 @@ void Tokenizer::simplifyMathFunctions()
84328432
}
84338433

84348434
if (tok->previous() &&
8435-
Token::simpleMatch(tok->previous()->previous(), "std ::")) {
8435+
Token::simpleMatch(tok->tokAt(-2), "std ::")) {
84368436
// Delete "std ::"
8437-
tok = tok->previous()->previous();
8437+
tok = tok->tokAt(-2);
84388438
tok->deleteNext();
84398439
tok->deleteThis();
84408440
}
@@ -8496,8 +8496,8 @@ void Tokenizer::simplifyComma()
84968496
tok->str(";");
84978497
}
84988498

8499-
if (tok->previous() && tok->previous()->previous()) {
8500-
if (Token::Match(tok->previous()->previous(), "delete %var% , %var% ;") &&
8499+
if (tok->previous() && tok->tokAt(-2)) {
8500+
if (Token::Match(tok->tokAt(-2), "delete %var% , %var% ;") &&
85018501
tok->next()->varId() != 0) {
85028502
// Handle "delete a, b;"
85038503
tok->str(";");
@@ -9645,7 +9645,7 @@ void Tokenizer::simplifyOperatorName()
96459645
}
96469646
if (Token::simpleMatch(par, "[ ]")) {
96479647
op += "[]";
9648-
par = par->next()->next();
9648+
par = par->tokAt(2);
96499649
done = false;
96509650
}
96519651
if (Token::Match(par, "( *| )")) {

0 commit comments

Comments
 (0)