Skip to content

Commit 58c7279

Browse files
committed
Fix
1 parent c1c10f1 commit 58c7279

27 files changed

+289
-289
lines changed

lib/astutils.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ bool isTemporary(const Token* tok, const Library* library, bool unknown)
453453
return tok->valueType()->reference == Reference::None && tok->valueType()->pointer == 0;
454454
}
455455
const Token* ftok = nullptr;
456-
if (Token::simpleMatch(tok->previous(), ">") && tok->previous()->link())
457-
ftok = tok->previous()->link()->previous();
456+
if (Token::simpleMatch(tok->previous(), ">") && tok->linkAt(-1))
457+
ftok = tok->linkAt(-1)->previous();
458458
else
459459
ftok = tok->previous();
460460
if (!ftok)
@@ -568,7 +568,7 @@ Token* astParentSkipParens(Token* tok)
568568
if (parent->link() != nextAfterAstRightmostLeaf(tok))
569569
return parent;
570570
if (Token::Match(parent->previous(), "%name% (") ||
571-
(Token::simpleMatch(parent->previous(), "> (") && parent->previous()->link()))
571+
(Token::simpleMatch(parent->previous(), "> (") && parent->linkAt(-1)))
572572
return parent;
573573
return astParentSkipParens(parent);
574574
}
@@ -839,7 +839,7 @@ static T* getCondTokFromEndImpl(T* endBlock)
839839
if (Token::simpleMatch(startBlock->previous(), "do"))
840840
return getCondTok(startBlock->previous());
841841
if (Token::simpleMatch(startBlock->previous(), ")"))
842-
return getCondTok(startBlock->previous()->link());
842+
return getCondTok(startBlock->linkAt(-1));
843843
if (Token::simpleMatch(startBlock->tokAt(-2), "} else {"))
844844
return getCondTokFromEnd(startBlock->tokAt(-2));
845845
return nullptr;
@@ -1669,7 +1669,7 @@ bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Se
16691669
if (!compareTokenFlags(tok1, tok2, macro))
16701670
return false;
16711671

1672-
if (pure && tok1->isName() && tok1->next()->str() == "(" && tok1->str() != "sizeof" && !(tok1->variable() && tok1 == tok1->variable()->nameToken())) {
1672+
if (pure && tok1->isName() && tok1->strAt(1) == "(" && tok1->str() != "sizeof" && !(tok1->variable() && tok1 == tok1->variable()->nameToken())) {
16731673
if (!tok1->function()) {
16741674
if (Token::simpleMatch(tok1->previous(), ".")) {
16751675
const Token *lhs = tok1->previous();
@@ -1725,7 +1725,7 @@ bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Se
17251725
// cast => assert that the casts are equal
17261726
if (tok1->str() == "(" && tok1->previous() &&
17271727
!tok1->previous()->isName() &&
1728-
!(tok1->previous()->str() == ">" && tok1->previous()->link())) {
1728+
!(tok1->strAt(-1) == ">" && tok1->linkAt(-1))) {
17291729
const Token *t1 = tok1->next();
17301730
const Token *t2 = tok2->next();
17311731
while (t1 && t2 &&
@@ -2052,7 +2052,7 @@ bool isConstExpression(const Token *tok, const Library& library)
20522052
return true;
20532053
if (tok->variable() && tok->variable()->isVolatile())
20542054
return false;
2055-
if (tok->isName() && tok->next()->str() == "(") {
2055+
if (tok->isName() && tok->strAt(1) == "(") {
20562056
if (!isConstFunctionCall(tok, library))
20572057
return false;
20582058
}
@@ -2233,8 +2233,8 @@ bool isReturnScope(const Token* const endToken, const Library& library, const To
22332233
*unknownFunc = prev->previous();
22342234
return false;
22352235
}
2236-
if (Token::simpleMatch(prev->previous(), ") ;") && prev->previous()->link() &&
2237-
isEscaped(prev->previous()->link()->astTop(), functionScope, library))
2236+
if (Token::simpleMatch(prev->previous(), ") ;") && prev->linkAt(-1) &&
2237+
isEscaped(prev->linkAt(-1)->astTop(), functionScope, library))
22382238
return true;
22392239
if (isEscaped(prev->previous()->astTop(), functionScope, library))
22402240
return true;
@@ -2740,7 +2740,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings,
27402740

27412741
// structured binding, nonconst reference variable in lhs
27422742
if (Token::Match(tok2->astParent(), ":|=") && tok2 == tok2->astParent()->astOperand2() && Token::simpleMatch(tok2->astParent()->previous(), "]")) {
2743-
const Token *typeStart = tok2->astParent()->previous()->link()->previous();
2743+
const Token *typeStart = tok2->astParent()->linkAt(-1)->previous();
27442744
if (Token::simpleMatch(typeStart, "&"))
27452745
typeStart = typeStart->previous();
27462746
if (typeStart && Token::Match(typeStart->previous(), "[;{}(] auto &| [")) {
@@ -3095,7 +3095,7 @@ int numberOfArgumentsWithoutAst(const Token* start)
30953095
const Token* openBracket = start->next();
30963096
while (Token::simpleMatch(openBracket, ")"))
30973097
openBracket = openBracket->next();
3098-
if (openBracket && openBracket->str()=="(" && openBracket->next() && openBracket->next()->str()!=")") {
3098+
if (openBracket && openBracket->str()=="(" && openBracket->next() && openBracket->strAt(1)!=")") {
30993099
const Token* argument=openBracket->next();
31003100
while (argument) {
31013101
++arguments;
@@ -3595,7 +3595,7 @@ bool isGlobalData(const Token *expr)
35953595
return ChildrenToVisit::none;
35963596
}
35973597
}
3598-
if (tok->varId() == 0 && tok->isName() && tok->previous()->str() != ".") {
3598+
if (tok->varId() == 0 && tok->isName() && tok->strAt(-1) != ".") {
35993599
globalData = true;
36003600
return ChildrenToVisit::none;
36013601
}
@@ -3609,7 +3609,7 @@ bool isGlobalData(const Token *expr)
36093609
globalData = true;
36103610
return ChildrenToVisit::none;
36113611
}
3612-
if (tok->previous()->str() != "." && !tok->variable()->isLocal() && !tok->variable()->isArgument()) {
3612+
if (tok->strAt(-1) != "." && !tok->variable()->isLocal() && !tok->variable()->isArgument()) {
36133613
globalData = true;
36143614
return ChildrenToVisit::none;
36153615
}

lib/checkclass.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
983983
tok2 = tok2->next();
984984
if (tok2->str() == "&")
985985
tok2 = tok2->next();
986-
if (isVariableChangedByFunctionCall(tok2, tok2->previous()->str() == "&", tok2->varId(), *mSettings, nullptr))
986+
if (isVariableChangedByFunctionCall(tok2, tok2->strAt(-1) == "&", tok2->varId(), *mSettings, nullptr))
987987
assignVar(usage, tok2->varId());
988988
}
989989
}
@@ -1622,14 +1622,14 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
16221622

16231623
// check if a function is called
16241624
if (tok->strAt(2) == "(" &&
1625-
tok->linkAt(2)->next()->str() == ";") {
1625+
tok->linkAt(2)->strAt(1) == ";") {
16261626
// check if it is a member function
16271627
for (std::list<Function>::const_iterator it = scope->functionList.cbegin(); it != scope->functionList.cend(); ++it) {
16281628
// check for a regular function with the same name and a body
16291629
if (it->type == Function::eFunction && it->hasBody() &&
1630-
it->token->str() == tok->next()->str()) {
1630+
it->token->str() == tok->strAt(1)) {
16311631
// check for the proper return type
1632-
if (it->tokenDef->previous()->str() == "&" &&
1632+
if (it->tokenDef->strAt(-1) == "&" &&
16331633
it->tokenDef->strAt(-2) == scope->className) {
16341634
// make sure it's not a const function
16351635
if (!it->isConst()) {
@@ -1653,7 +1653,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
16531653
else if (!(Token::simpleMatch(tok->next(), "operator= (") ||
16541654
Token::simpleMatch(tok->next(), "this . operator= (") ||
16551655
(Token::Match(tok->next(), "%type% :: operator= (") &&
1656-
tok->next()->str() == scope->className)))
1656+
tok->strAt(1) == scope->className)))
16571657
operatorEqRetRefThisError(func->token);
16581658
}
16591659
if (foundReturn) {
@@ -2848,11 +2848,11 @@ const std::list<const Token *> & CheckClass::getVirtualFunctionCalls(const Funct
28482848
continue;
28492849

28502850
if (tok->previous() &&
2851-
tok->previous()->str() == "(") {
2851+
tok->strAt(-1) == "(") {
28522852
const Token * prev = tok->previous();
28532853
if (prev->previous() &&
28542854
(mSettings->library.ignorefunction(tok->str())
2855-
|| mSettings->library.ignorefunction(prev->previous()->str())))
2855+
|| mSettings->library.ignorefunction(prev->strAt(-1))))
28562856
continue;
28572857
}
28582858

lib/checkcondition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void CheckCondition::assignIf()
106106

107107
if (Token::Match(tok->next(), "%num% [&|]")) {
108108
bitop = tok->strAt(2).at(0);
109-
num = MathLib::toBigNumber(tok->next()->str());
109+
num = MathLib::toBigNumber(tok->strAt(1));
110110
} else {
111111
const Token *endToken = Token::findsimplematch(tok, ";");
112112

@@ -116,7 +116,7 @@ void CheckCondition::assignIf()
116116

117117
if (endToken && Token::Match(endToken->tokAt(-2), "[&|] %num% ;")) {
118118
bitop = endToken->strAt(-2).at(0);
119-
num = MathLib::toBigNumber(endToken->previous()->str());
119+
num = MathLib::toBigNumber(endToken->strAt(-1));
120120
}
121121
}
122122

lib/checkfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static bool isForwardJump(const Token *gotoToken)
335335
if (!Token::Match(gotoToken, "goto %name% ;"))
336336
return false;
337337
for (const Token *prev = gotoToken; gotoToken; gotoToken = gotoToken->previous()) {
338-
if (Token::Match(prev, "%name% :") && prev->str() == gotoToken->next()->str())
338+
if (Token::Match(prev, "%name% :") && prev->str() == gotoToken->strAt(1))
339339
return true;
340340
if (prev->str() == "{" && prev->scope()->type == Scope::eFunction)
341341
return false;

lib/checkio.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings &settings,
14341434
const Token *tok1 = arg->next();
14351435
for (; tok1; tok1 = tok1->next()) {
14361436
if (tok1->str() == "," || tok1->str() == ")") {
1437-
if (tok1->previous()->str() == "]") {
1437+
if (tok1->strAt(-1) == "]") {
14381438
varTok = tok1->linkAt(-1)->previous();
14391439
if (varTok->str() == ")" && varTok->link()->previous()->tokType() == Token::eFunction) {
14401440
const Function * function = varTok->link()->previous()->function();
@@ -1455,7 +1455,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings &settings,
14551455
}
14561456
return;
14571457
}
1458-
} else if (tok1->previous()->str() == ")" && tok1->linkAt(-1)->previous()->tokType() == Token::eFunction) {
1458+
} else if (tok1->strAt(-1) == ")" && tok1->linkAt(-1)->previous()->tokType() == Token::eFunction) {
14591459
const Function * function = tok1->linkAt(-1)->previous()->function();
14601460
if (function && function->retType && function->retType->isEnumType()) {
14611461
if (function->retType->classScope->enumType)
@@ -1484,9 +1484,9 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings &settings,
14841484

14851485
// check for some common well known functions
14861486
else if (isCPP && ((Token::Match(tok1->previous(), "%var% . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous())) ||
1487-
(Token::Match(tok1->previous(), "] . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous()->link()->previous())))) {
1487+
(Token::Match(tok1->previous(), "] . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->linkAt(-1)->previous())))) {
14881488
tempToken = new Token(tok1);
1489-
if (tok1->next()->str() == "size") {
1489+
if (tok1->strAt(1) == "size") {
14901490
// size_t is platform dependent
14911491
if (settings.platform.sizeof_size_t == 8) {
14921492
tempToken->str("long");
@@ -1502,9 +1502,9 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings &settings,
15021502

15031503
tempToken->originalName("size_t");
15041504
tempToken->isUnsigned(true);
1505-
} else if (tok1->next()->str() == "empty") {
1505+
} else if (tok1->strAt(1) == "empty") {
15061506
tempToken->str("bool");
1507-
} else if (tok1->next()->str() == "c_str") {
1507+
} else if (tok1->strAt(1) == "c_str") {
15081508
tempToken->str("const");
15091509
tempToken->insertToken("*");
15101510
if (typeToken->strAt(2) == "string")
@@ -1534,7 +1534,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings &settings,
15341534

15351535
if (varTok) {
15361536
variableInfo = varTok->variable();
1537-
element = tok1->previous()->str() == "]";
1537+
element = tok1->strAt(-1) == "]";
15381538

15391539
// look for std::vector operator [] and use template type as return type
15401540
if (variableInfo) {

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ void CheckLeakAutoVar::changeAllocStatus(VarInfo &varInfo, const VarInfo::AllocI
923923
if (allocation.status == VarInfo::NOALLOC) {
924924
// possible usage
925925
varInfo.possibleUsage[arg->varId()] = { tok, VarInfo::USED };
926-
if (var->second.status == VarInfo::DEALLOC && arg->previous()->str() == "&")
926+
if (var->second.status == VarInfo::DEALLOC && arg->strAt(-1) == "&")
927927
varInfo.erase(arg->varId());
928928
} else if (var->second.managed()) {
929929
doubleFreeError(tok, var->second.allocTok, arg->str(), allocation.type);

lib/checknullpointer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ void CheckNullPointer::nullConstantDereference()
355355
}
356356
}
357357

358-
else if (Token::Match(tok, "0 [") && (tok->previous()->str() != "&" || !Token::Match(tok->linkAt(1)->next(), "[.(]")))
358+
else if (Token::Match(tok, "0 [") && (tok->strAt(-1) != "&" || !Token::Match(tok->linkAt(1)->next(), "[.(]")))
359359
nullPointerError(tok);
360360

361-
else if (Token::Match(tok->previous(), "!!. %name% (|{") && (tok->previous()->str() != "::" || tok->strAt(-2) == "std")) {
361+
else if (Token::Match(tok->previous(), "!!. %name% (|{") && (tok->strAt(-1) != "::" || tok->strAt(-2) == "std")) {
362362
if (Token::Match(tok->tokAt(2), "0|NULL|nullptr )|}") && tok->varId()) { // constructor call
363363
const Variable *var = tok->variable();
364364
if (var && !var->isPointer() && !var->isArray() && var->isStlStringType())
@@ -395,7 +395,7 @@ void CheckNullPointer::nullConstantDereference()
395395
if (Token::Match(tok2->previous(), ";|{|}|:|("))
396396
break;
397397
}
398-
if (tok2 && tok2->previous() && tok2->previous()->str()=="(")
398+
if (tok2 && tok2->previous() && tok2->strAt(-1)=="(")
399399
continue;
400400
if (Token::simpleMatch(tok2, "std :: cin"))
401401
nullPointerError(tok);

lib/checkother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ static bool isVoidStmt(const Token *tok)
18861886
const Token *tok2 = tok;
18871887
while (tok2->astOperand1())
18881888
tok2 = tok2->astOperand1();
1889-
if (Token::simpleMatch(tok2->previous(), ")") && Token::simpleMatch(tok2->previous()->link(), "( void"))
1889+
if (Token::simpleMatch(tok2->previous(), ")") && Token::simpleMatch(tok2->linkAt(-1), "( void"))
18901890
return true;
18911891
if (Token::simpleMatch(tok2, "( void"))
18921892
return true;
@@ -2540,7 +2540,7 @@ void CheckOther::checkDuplicateExpression()
25402540
while (parent && parent->astParent()) {
25412541
parent = parent->astParent();
25422542
}
2543-
if (parent && parent->previous() && parent->previous()->str() == "static_assert") {
2543+
if (parent && parent->previous() && parent->strAt(-1) == "static_assert") {
25442544
continue;
25452545
}
25462546
}

lib/checksizeof.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void CheckSizeof::sizeofCalculation()
326326
// ignore if the `sizeof` result is cast to void inside a macro, i.e. the calculation is
327327
// expected to be parsed but skipped, such as in a disabled custom ASSERT() macro
328328
if (tok->isExpandedMacro() && tok->previous()) {
329-
const Token *cast_end = (tok->previous()->str() == "(") ? tok->previous() : tok;
329+
const Token *cast_end = (tok->strAt(-1) == "(") ? tok->previous() : tok;
330330
if (Token::simpleMatch(cast_end->tokAt(-3), "( void )") ||
331331
Token::simpleMatch(cast_end->tokAt(-4), "static_cast < void >")) {
332332
continue;
@@ -369,7 +369,7 @@ void CheckSizeof::sizeofFunction()
369369
// ignore if the `sizeof` result is cast to void inside a macro, i.e. the calculation is
370370
// expected to be parsed but skipped, such as in a disabled custom ASSERT() macro
371371
if (tok->isExpandedMacro() && tok->previous()) {
372-
const Token *cast_end = (tok->previous()->str() == "(") ? tok->previous() : tok;
372+
const Token *cast_end = (tok->strAt(-1) == "(") ? tok->previous() : tok;
373373
if (Token::simpleMatch(cast_end->tokAt(-3), "( void )") ||
374374
Token::simpleMatch(cast_end->tokAt(-4), "static_cast < void >")) {
375375
continue;

lib/checkstl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ bool CheckStl::isContainerSize(const Token *containerToken, const Token *expr) c
284284
return false;
285285
if (!isSameExpression(false, containerToken, expr->astOperand1()->astOperand1(), *mSettings, false, false))
286286
return false;
287-
return containerToken->valueType()->container->getYield(expr->previous()->str()) == Library::Container::Yield::SIZE;
287+
return containerToken->valueType()->container->getYield(expr->strAt(-1)) == Library::Container::Yield::SIZE;
288288
}
289289

290290
bool CheckStl::isContainerSizeGE(const Token * containerToken, const Token *expr) const
@@ -537,7 +537,7 @@ void CheckStl::iterators()
537537
continue; // No warning
538538

539539
// skip error message if the iterator is erased/inserted by value
540-
if (itTok->previous()->str() == "*")
540+
if (itTok->strAt(-1) == "*")
541541
continue;
542542

543543
// inserting iterator range..
@@ -2885,7 +2885,7 @@ void CheckStl::useStlAlgorithm()
28852885
auto isConditionWithoutSideEffects = [this](const Token* tok) -> bool {
28862886
if (!Token::simpleMatch(tok, "{") || !Token::simpleMatch(tok->previous(), ")"))
28872887
return false;
2888-
return isConstExpression(tok->previous()->link()->astOperand2(), mSettings->library);
2888+
return isConstExpression(tok->linkAt(-1)->astOperand2(), mSettings->library);
28892889
};
28902890

28912891
for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) {

0 commit comments

Comments
 (0)