Change every 'tokAt(..)->link()' to 'linkAt(..)'.

This commit is contained in:
Edoardo Prezioso 2011-11-20 14:22:39 +01:00
parent 690702a742
commit 42e369a4b4
14 changed files with 139 additions and 139 deletions

View File

@ -146,7 +146,7 @@ void CheckAssignIf::multiCondition()
if (num1 < 0)
continue;
const Token *tok2 = tok->tokAt(6)->link();
const Token *tok2 = tok->linkAt(6);
while (Token::simpleMatch(tok2, "} else { if (")) {
// Goto '('
const Token * const opar = tok2->tokAt(4);

View File

@ -139,7 +139,7 @@ void CheckAutoVariables::autoVariables()
else if (Token::Match(tok, "return & %var% ;") && isAutoVar(tok->tokAt(2)->varId())) {
errorReturnAddressToAutoVariable(tok);
} else if (Token::Match(tok, "return & %var% [") &&
Token::simpleMatch(tok->tokAt(3)->link(), "] ;") &&
Token::simpleMatch(tok->linkAt(3), "] ;") &&
isAutoVarArray(tok->tokAt(2)->varId())) {
errorReturnAddressToAutoVariable(tok);
} else if (Token::Match(tok, "return & %var% ;") && tok->tokAt(2)->varId()) {

View File

@ -654,7 +654,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
// goto end of if block..
ftok = ftok->next()->link()->next()->link();
if (Token::simpleMatch(ftok, "} else {"))
ftok = ftok->tokAt(2)->link();
ftok = ftok->linkAt(2);
if (!ftok)
break;
continue;
@ -1438,13 +1438,13 @@ void CheckBufferOverrun::checkStructVariable()
// check for allocation
if ((Token::Match(tok3->tokAt(3), "; %var% = malloc ( %num% ) ;") ||
(Token::Match(tok3->tokAt(3), "; %var% = (") &&
Token::Match(tok3->tokAt(6)->link(), ") malloc ( %num% ) ;"))) &&
Token::Match(tok3->linkAt(6), ") malloc ( %num% ) ;"))) &&
(tok3->strAt(4) == tok3->strAt(2))) {
MathLib::bigint size;
// find size of allocation
if (tok3->strAt(3) == "(") // has cast
size = MathLib::toLongNumber(tok3->tokAt(6)->link()->strAt(3));
size = MathLib::toLongNumber(tok3->linkAt(6)->strAt(3));
else
size = MathLib::toLongNumber(tok3->strAt(8));

View File

@ -336,7 +336,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
else if (Token::Match(ftok, "::| memset ( %var% ,")) {
const int offset = ftok->str() == "::" ? 1 : 0;
assignVar(ftok->strAt(2 + offset), scope, usage);
ftok = ftok->tokAt(1 + offset)->link();
ftok = ftok->linkAt(1 + offset);
continue;
}
@ -819,7 +819,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
// check if a function is called
if (Token::Match(tok->tokAt(1), "%any% (") &&
tok->tokAt(2)->link()->next()->str() == ";") {
tok->linkAt(2)->next()->str() == ";") {
std::list<Function>::const_iterator it;
// check if it is a member function
@ -1037,7 +1037,7 @@ void CheckClass::virtualDestructor()
continue;
// Empty destructor
if (destructor->token->tokAt(3)->link() == destructor->token->tokAt(4))
if (destructor->token->linkAt(3) == destructor->token->tokAt(4))
continue;
const Token *derived = scope->classDef;
@ -1283,7 +1283,7 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok)
tok = tok->tokAt(-2);
again = true;
} else if (Token::Match(tok->tokAt(-2), "] . %var%")) {
tok = tok->tokAt(-2)->link()->previous();
tok = tok->linkAt(-2)->previous();
again = true;
} else if (tok->str() == "]") {
tok = tok->link()->previous();

View File

@ -923,7 +923,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
// var = strcpy|.. ( var ,
if (Token::Match(tok, "[;{}] %varid% = memcpy|memmove|memset|strcpy|strncpy|strcat|strncat ( %varid% ,", varid)) {
tok = tok->tokAt(4)->link();
tok = tok->linkAt(4);
continue;
}
@ -1002,7 +1002,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
alloctype = alloc;
if (Token::Match(tok, "%var% = %type% (")) {
tok = tok->tokAt(3)->link();
tok = tok->linkAt(3);
continue;
}
}
@ -1053,7 +1053,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
dealloctype = dealloc;
if (tok->strAt(2) == "(")
tok = tok->tokAt(2)->link();
tok = tok->linkAt(2);
continue;
}
}
@ -2265,12 +2265,12 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
Token::findmatch(startOfFunction, "[{};] %varid% = %var% [;=]", tok->varId()))
continue;
const Token* tokEndRealloc = tok->tokAt(3)->link();
const Token* tokEndRealloc = tok->linkAt(3);
// 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->varId())) {
const Token* tokEndBrace = tokEndRealloc->tokAt(7)->link();
const Token* tokEndBrace = tokEndRealloc->linkAt(7);
if (tokEndBrace && Token::simpleMatch(tokEndBrace->tokAt(-2), ") ;") &&
Token::Match(tokEndBrace->tokAt(-2)->link()->tokAt(-2), "{|}|; %var% ("))
Token::Match(tokEndBrace->linkAt(-2)->tokAt(-2), "{|}|; %var% ("))
continue;
}
@ -2284,12 +2284,12 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
Token::findmatch(startOfFunction, "[{};] * %varid% = %var% [;=]", tok->tokAt(1)->varId()))
continue;
const Token* tokEndRealloc = tok->tokAt(4)->link();
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())) {
const Token* tokEndBrace = tokEndRealloc->tokAt(8)->link();
const Token* tokEndBrace = tokEndRealloc->linkAt(8);
if (tokEndBrace && Token::simpleMatch(tokEndBrace->tokAt(-2), ") ;") &&
Token::Match(tokEndBrace->tokAt(-2)->link()->tokAt(-2), "{|}|; %var% ("))
Token::Match(tokEndBrace->linkAt(-2)->tokAt(-2), "{|}|; %var% ("))
continue;
}
memleakUponReallocFailureError(tok->tokAt(1), tok->strAt(1));
@ -2887,7 +2887,7 @@ void CheckMemoryLeakNoVar::check()
// parse the executable scope until tok is reached...
for (const Token *tok2 = tok->link(); tok2 && tok2 != tok; tok2 = tok2->next()) {
// allocating memory in parameter for function call..
if (Token::Match(tok2, "[(,] %var% (") && Token::Match(tok2->tokAt(2)->link(), ") [,)]")) {
if (Token::Match(tok2, "[(,] %var% (") && Token::Match(tok2->linkAt(2), ") [,)]")) {
const AllocType allocType = getAllocationType(tok2->next(), 0);
if (allocType != No) {
// locate outer function call..

View File

@ -561,7 +561,7 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
// Function call: If the pointer is not a local variable it
// might be changed by the call.
else if (Token::Match(tok2, "[;{}] %var% (") &&
Token::simpleMatch(tok2->tokAt(2)->link(), ") ;") && !isLocal) {
Token::simpleMatch(tok2->linkAt(2), ") ;") && !isLocal) {
break;
}
@ -794,7 +794,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
if (null && indentlevel == 0) {
// skip all "else" blocks because they are not executed in this execution path
while (Token::simpleMatch(tok2, "} else {"))
tok2 = tok2->tokAt(2)->link();
tok2 = tok2->linkAt(2);
null = false;
}
}

View File

@ -769,10 +769,10 @@ void CheckOther::checkSelfAssignment()
// check if the linenr is the same for all the tokens.
if (Token::Match(tok->tokAt(-2), ") { %var% = %var% ; } else { %varid% =", tok->varId())) {
// Find the 'if' token
const Token *tokif = tok->tokAt(-2)->link()->previous();
const Token *tokif = tok->linkAt(-2)->previous();
// find the '}' that terminates the 'else'-block
const Token *else_end = tok->tokAt(6)->link();
const Token *else_end = tok->linkAt(6);
if (tokif && else_end && tokif->linenr() == else_end->linenr())
err = false;
@ -1048,7 +1048,7 @@ void CheckOther::checkCatchExceptionByValue()
const char catchPattern[] = "} catch (";
const Token *tok = Token::findmatch(_tokenizer->tokens(), catchPattern);
const Token *endTok = tok ? tok->tokAt(2)->link() : NULL;
const Token *endTok = tok ? tok->linkAt(2) : NULL;
while (tok && endTok) {
// Find a pass-by-value declaration in the catch(), excluding basic types
@ -1059,7 +1059,7 @@ void CheckOther::checkCatchExceptionByValue()
}
tok = Token::findmatch(endTok->next(), catchPattern);
endTok = tok ? tok->tokAt(2)->link() : NULL;
endTok = tok ? tok->linkAt(2) : NULL;
}
}
@ -2069,7 +2069,7 @@ static bool isFunction(const std::string &name, const Token *startToken)
if (Token::simpleMatch(tok, ") {"))
tok = tok->next()->link();
else if (Token::simpleMatch(tok, ") const {"))
tok = tok->tokAt(2)->link();
tok = tok->linkAt(2);
}
// function declaration/implementation found
@ -2108,7 +2108,7 @@ void CheckOther::checkMisusedScopedObject()
}
if (Token::Match(tok, "[;{}] %var% (")
&& Token::simpleMatch(tok->tokAt(2)->link(), ") ;")
&& Token::simpleMatch(tok->linkAt(2), ") ;")
&& symbolDatabase->isClassOrStruct(tok->next()->str())
&& !isFunction(tok->next()->str(), _tokenizer->tokens())) {
tok = tok->next();
@ -2146,7 +2146,7 @@ void CheckOther::checkIncorrectStringCompare()
}
if (Token::Match(tok, "&&|%oror% %str% &&|%oror%|)")) {
// assert(condition && "debug message") would be considered a fp.
if (tok->str() == "&&" && tok->strAt(2) == ")" && tok->tokAt(2)->link()->previous()->str() == "assert")
if (tok->str() == "&&" && tok->strAt(2) == ")" && tok->linkAt(2)->previous()->str() == "assert")
continue;
incorrectStringBooleanError(tok->tokAt(1), tok->strAt(1));
}
@ -2256,9 +2256,9 @@ void CheckOther::checkDuplicateIf()
// check all the else if (...) statements
while (Token::simpleMatch(tok1, "} else if (") &&
Token::simpleMatch(tok1->tokAt(3)->link(), ") {")) {
Token::simpleMatch(tok1->linkAt(3), ") {")) {
// get the expression from the token stream
expression = stringifyTokens(tok1->tokAt(4), tok1->tokAt(3)->link()->previous());
expression = stringifyTokens(tok1->tokAt(4), tok1->linkAt(3)->previous());
// try to look up the expression to check for duplicates
std::map<std::string, const Token *>::iterator it = expressionMap.find(expression);
@ -2266,7 +2266,7 @@ void CheckOther::checkDuplicateIf()
// found a duplicate
if (it != expressionMap.end()) {
// check for expressions that have side effects and ignore them
if (!expressionHasSideEffects(tok1->tokAt(4), tok1->tokAt(3)->link()->previous()))
if (!expressionHasSideEffects(tok1->tokAt(4), tok1->linkAt(3)->previous()))
duplicateIfError(it->second, tok1->next());
}
@ -2275,7 +2275,7 @@ void CheckOther::checkDuplicateIf()
expressionMap.insert(std::make_pair(expression, tok1->next()));
// find the next else if (...) statement
tok1 = tok1->tokAt(3)->link()->next()->link();
tok1 = tok1->linkAt(3)->next()->link();
}
tok = tok->next()->link()->next();
@ -2329,7 +2329,7 @@ void CheckOther::checkDuplicateBranch()
const Token *tok1 = tok->next()->link()->next()->link();
// save else branch code
std::string branch2 = stringifyTokens(tok1->tokAt(3), tok1->tokAt(2)->link()->previous());
std::string branch2 = stringifyTokens(tok1->tokAt(3), tok1->linkAt(2)->previous());
// check for duplicates
if (branch1 == branch2)

View File

@ -120,7 +120,7 @@ void CheckStl::iterators()
validIterator = true;
// skip the operation
tok2 = tok2->tokAt(5)->link();
tok2 = tok2->linkAt(5);
if (!tok2)
break;
}
@ -621,7 +621,7 @@ void CheckStl::pushback()
}
invalidIterator = tok2->strAt(2);
tok2 = tok2->tokAt(3)->link();
tok2 = tok2->linkAt(3);
}
// TODO: instead of bail out for 'else' try to check all execution paths.
@ -958,7 +958,7 @@ void CheckStl::missingComparison()
incrementToken = 0;
else if (Token::Match(tok3, "%varid% = %var% . insert ( ++| %varid% ++| ,", iteratorId)) {
// skip insertion..
tok3 = tok3->tokAt(6)->link();
tok3 = tok3->linkAt(6);
if (!tok3)
break;
}
@ -1024,7 +1024,7 @@ void CheckStl::string_c_str()
pointers.find(tok->next()->varId()) != pointers.end()) {
string_c_strError(tok);
} else if (Token::Match(tok, "[;{}] %var% = %var% (") &&
Token::simpleMatch(tok->tokAt(4)->link(), ") . c_str ( ) ;") &&
Token::simpleMatch(tok->linkAt(4), ") . c_str ( ) ;") &&
tok->next()->varId() > 0 &&
pointers.find(tok->next()->varId()) != pointers.end() &&
Token::findmatch(_tokenizer->tokens(), ("std :: string " + tok->strAt(3) + " (").c_str())) {
@ -1047,7 +1047,7 @@ void CheckStl::string_c_str()
localvar.find(tok->next()->varId()) != localvar.end()) {
string_c_strError(tok, true);
} else if (Token::simpleMatch(tok, "return std :: string (") &&
Token::simpleMatch(tok->tokAt(4)->link(), ") . c_str ( ) ;")) {
Token::simpleMatch(tok->linkAt(4), ") . c_str ( ) ;")) {
string_c_strError(tok, true);
} else if (Token::simpleMatch(tok, "return (") &&
Token::simpleMatch(tok->next()->link(), ") . c_str ( ) ;")) {
@ -1189,7 +1189,7 @@ void CheckStl::uselessCalls()
if (tok->varId() == 0)
continue;
/*if (Token::Match(tok, "%var% . compare (") &&
tok->varId() == tok->tokAt(3)->link()->tokAt(-1)->varId()) {
tok->varId() == tok->linkAt(3)->tokAt(-1)->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% [,)]") &&
@ -1202,7 +1202,7 @@ void CheckStl::uselessCalls()
uselessCallsSubstrError(tok, tok->str());
} else if (Token::Match(tok, "%var% . substr ( 0")) {
if (tok->strAt(5) == ")" ||
tok->tokAt(3)->link()->strAt(-1) == "npos")
tok->linkAt(3)->strAt(-1) == "npos")
uselessCallsSubstrError(tok, tok->str());
}
}

View File

@ -409,7 +409,7 @@ private:
// Variable declaration..
if (Token::Match(tok.previous(), "[;{}] %var%") && tok.str() != "return") {
if (Token::Match(&tok, "enum %type% {"))
return tok.tokAt(2)->link();
return tok.linkAt(2);
const Token * vartok = &tok;
while (Token::Match(vartok, "const|struct"))
@ -427,7 +427,7 @@ private:
// Variable declaration for array..
if (Token::Match(vartok, "%type% %var% [") &&
vartok->isStandardType() &&
Token::simpleMatch(vartok->tokAt(2)->link(), "] ;")) {
Token::simpleMatch(vartok->linkAt(2), "] ;")) {
vartok = vartok->next();
declare(checks, vartok, tok, false, true);
return vartok->next()->link();
@ -916,7 +916,7 @@ public:
continue;
}
if (tok->str() != "::" && Token::Match(tok->next(), "%var% ( %type%")) {
if (!Token::Match(tok->tokAt(2)->link(), ") [{;]"))
if (!Token::Match(tok->linkAt(2), ") [{;]"))
continue;
const Token *tok2 = tok->tokAt(3);
while (tok2 && tok2->str() != ")") {

View File

@ -1294,7 +1294,7 @@ void CheckUnusedVar::checkStructMemberUsage()
structname.clear();
if (Token::simpleMatch(tok->previous(), "extern"))
continue;
if ((!tok->previous() || Token::simpleMatch(tok->previous(), ";")) && Token::Match(tok->tokAt(2)->link(), ("} ; " + tok->strAt(1) + " %var% ;").c_str()))
if ((!tok->previous() || Token::simpleMatch(tok->previous(), ";")) && Token::Match(tok->linkAt(2), ("} ; " + tok->strAt(1) + " %var% ;").c_str()))
continue;
structname = tok->strAt(1);

View File

@ -138,8 +138,8 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
for (; tok; tok = tok->next()) {
// might be a noreturn function..
if (Token::simpleMatch(tok->tokAt(-2), ") ; }") &&
Token::Match(tok->tokAt(-2)->link()->tokAt(-2), "[;{}] %var% (") &&
tok->tokAt(-2)->link()->previous()->varId() == 0) {
Token::Match(tok->linkAt(-2)->tokAt(-2), "[;{}] %var% (") &&
tok->linkAt(-2)->previous()->varId() == 0) {
ExecutionPath::bailOut(checks);
return;
}
@ -161,9 +161,9 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
// skip "while (fgets()!=NULL)"
if (Token::simpleMatch(tok, "while ( fgets (")) {
const Token *tok2 = tok->tokAt(3)->link();
const Token *tok2 = tok->linkAt(3);
if (Token::simpleMatch(tok2, ") ) {")) {
tok = tok2->tokAt(2)->link();
tok = tok2->linkAt(2);
if (!tok)
break;
continue;
@ -252,7 +252,7 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
// #2231 - loop body only contains a conditional initialization..
if (Token::simpleMatch(tok2->next(), "if (")) {
// Start { for the if block
const Token *tok3 = tok2->tokAt(2)->link();
const Token *tok3 = tok2->linkAt(2);
if (Token::simpleMatch(tok3,") {")) {
tok3 = tok3->next();
@ -286,7 +286,7 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
// if "do { .. } while ( .." , goto end of while..
if (Token::simpleMatch(tok, "do {") && Token::simpleMatch(tok2, "} while ("))
tok2 = tok2->tokAt(2)->link();
tok2 = tok2->linkAt(2);
// bail out all variables if the scope contains a "return"
// bail out all variables used in this for/while/switch/do

View File

@ -420,7 +420,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// function returning function pointer with body
else if (Token::simpleMatch(argStart->link(), ") ) (") &&
Token::Match(argStart->link()->tokAt(2)->link(), ") const| {")) {
Token::Match(argStart->link()->linkAt(2), ") const| {")) {
const Token *tok1 = funcStart;
Scope *old_scope = scope;
@ -480,9 +480,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// function returning function pointer prototype
else if (Token::simpleMatch(argStart->link(), ") ) (") &&
Token::simpleMatch(argStart->link()->tokAt(2)->link(), ") ;")) {
Token::simpleMatch(argStart->link()->linkAt(2), ") ;")) {
/** @todo save function prototypes in database someday */
tok = argStart->link()->tokAt(2)->link()->next();
tok = argStart->link()->linkAt(2)->next();
continue;
}
}
@ -501,8 +501,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
scope = &scopeList.back();
scope->nestedIn->nestedList.push_back(scope);
} else if (Token::simpleMatch(tok, "else if (") &&
Token::simpleMatch(tok->tokAt(2)->link(), ") {")) {
const Token *tok1 = tok->tokAt(2)->link()->next();
Token::simpleMatch(tok->linkAt(2), ") {")) {
const Token *tok1 = tok->linkAt(2)->next();
scopeList.push_back(Scope(this, tok, scope, Scope::eElseIf, tok1));
tok = tok1;
scope = &scopeList.back();
@ -989,7 +989,7 @@ void SymbolDatabase::addFunction(Scope **scope, const Token **tok, const Token *
func->hasBody = true;
func->token = *tok;
func->arg = argStart;
const Token *start = argStart->link()->tokAt(2)->link()->next();
const Token *start = argStart->link()->linkAt(2)->next();
while (start && start->str() != "{")
start = start->next();
func->start = start;

View File

@ -748,7 +748,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
}
if (tok->strAt(2) == "{") { // unnamed
tok1 = tok->tokAt(2)->link();
tok1 = tok->linkAt(2);
if (tok1 && tok1->next()) {
// use typedef name if available
@ -772,7 +772,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
name = tok->strAt(2);
} else { // has a name
tok1 = tok->tokAt(3)->link();
tok1 = tok->linkAt(3);
if (!tok1)
return NULL;
@ -816,18 +816,18 @@ static Token *processFunc(Token *tok2, bool inOperator)
tok2->next()->str() != ",") {
// skip over tokens for some types of canonicalization
if (Token::Match(tok2->next(), "( * %type% ) ("))
tok2 = tok2->tokAt(5)->link();
tok2 = tok2->linkAt(5);
else if (Token::Match(tok2->next(), "* ( * %type% ) ("))
tok2 = tok2->tokAt(6)->link();
tok2 = tok2->linkAt(6);
else if (Token::Match(tok2->next(), "* ( * %type% ) ;"))
tok2 = tok2->tokAt(5);
else if (Token::Match(tok2->next(), "* ( %type% [") &&
Token::Match(tok2->tokAt(4)->link(), "] ) ;|="))
tok2 = tok2->tokAt(4)->link()->next();
Token::Match(tok2->linkAt(4), "] ) ;|="))
tok2 = tok2->linkAt(4)->next();
else if (Token::Match(tok2->next(), "* ( * %type% ("))
tok2 = tok2->tokAt(5)->link()->next();
tok2 = tok2->linkAt(5)->next();
else if (Token::Match(tok2->next(), "* [") &&
Token::simpleMatch(tok2->tokAt(2)->link(), "] ;"))
Token::simpleMatch(tok2->linkAt(2), "] ;"))
tok2 = tok2->next();
else {
if (tok2->next()->str() == "(")
@ -1100,7 +1100,7 @@ void Tokenizer::simplifyTypedef()
// unhandled function pointer, skip it and continue
// TODO: handle such typedefs. See ticket #3314
else if (Token::Match(tok->tokAt(offset), "( %type% ::") &&
Token::Match(tok->tokAt(offset)->link()->tokAt(-3), ":: * %var% ) (")) {
Token::Match(tok->linkAt(offset)->tokAt(-3), ":: * %var% ) (")) {
unsupportedTypedef(typeDef);
tok = deleteInvalidTypedef(typeDef);
continue;
@ -1115,19 +1115,19 @@ void Tokenizer::simplifyTypedef()
funcEnd = tok->tokAt(offset + 1);
typeName = tok->tokAt(offset + 2);
argStart = tok->tokAt(offset + 4);
argEnd = tok->tokAt(offset + 4)->link();
argEnd = tok->linkAt(offset + 4);
tok = argEnd->next();
}
// function
else if (Token::Match(tok->tokAt(offset)->link(), ") const| ;|,")) {
else if (Token::Match(tok->linkAt(offset), ") const| ;|,")) {
function = true;
if (tok->tokAt(offset)->link()->next()->str() == "const") {
specStart = tok->tokAt(offset)->link()->next();
if (tok->linkAt(offset)->next()->str() == "const") {
specStart = tok->linkAt(offset)->next();
specEnd = specStart;
}
argStart = tok->tokAt(offset);
argEnd = tok->tokAt(offset)->link();
argEnd = tok->linkAt(offset);
tok = argEnd->next();
if (specStart)
tok = tok->next();
@ -1150,10 +1150,10 @@ void Tokenizer::simplifyTypedef()
// typeof: typedef __typeof__ ( ... ) type;
else if (Token::simpleMatch(tok->tokAt(offset - 1), "__typeof__ (") &&
Token::Match(tok->tokAt(offset)->link(), ") %type% ;")) {
Token::Match(tok->linkAt(offset), ") %type% ;")) {
argStart = tok->tokAt(offset);
argEnd = tok->tokAt(offset)->link();
typeName = tok->tokAt(offset)->link()->next();
argEnd = tok->linkAt(offset);
typeName = tok->linkAt(offset)->next();
tok = typeName->next();
typeOf = true;
}
@ -1162,14 +1162,14 @@ void Tokenizer::simplifyTypedef()
// typedef ... (( .... type )( ... ));
// typedef ... ( * ( .... type )( ... ));
else if ((tok->strAt(offset) == "(" &&
Token::Match(tok->tokAt(offset)->link()->previous(), "%type% ) (") &&
Token::Match(tok->tokAt(offset)->link()->next()->link(), ") const|volatile|;")) ||
Token::Match(tok->linkAt(offset)->previous(), "%type% ) (") &&
Token::Match(tok->linkAt(offset)->next()->link(), ") const|volatile|;")) ||
(Token::simpleMatch(tok->tokAt(offset), "( (") &&
Token::Match(tok->tokAt(offset + 1)->link()->previous(), "%type% ) (") &&
Token::Match(tok->tokAt(offset + 1)->link()->next()->link(), ") const|volatile| ) ;|,")) ||
Token::Match(tok->linkAt(offset + 1)->previous(), "%type% ) (") &&
Token::Match(tok->linkAt(offset + 1)->next()->link(), ") const|volatile| ) ;|,")) ||
(Token::simpleMatch(tok->tokAt(offset), "( * (") &&
Token::Match(tok->tokAt(offset + 2)->link()->previous(), "%type% ) (") &&
Token::Match(tok->tokAt(offset + 2)->link()->next()->link(), ") const|volatile| ) ;|,"))) {
Token::Match(tok->linkAt(offset + 2)->previous(), "%type% ) (") &&
Token::Match(tok->linkAt(offset + 2)->next()->link(), ") const|volatile| ) ;|,"))) {
if (tok->strAt(offset + 1) == "(")
++offset;
else if (Token::simpleMatch(tok->tokAt(offset), "( * (")) {
@ -1178,15 +1178,15 @@ void Tokenizer::simplifyTypedef()
++offset;
}
if (tok->tokAt(offset)->link()->strAt(-2) == "*")
if (tok->linkAt(offset)->strAt(-2) == "*")
functionPtr = true;
else
function = true;
funcStart = tok->tokAt(offset + 1);
funcEnd = tok->tokAt(offset)->link()->tokAt(-2);
typeName = tok->tokAt(offset)->link()->previous();
argStart = tok->tokAt(offset)->link()->next();
argEnd = tok->tokAt(offset)->link()->next()->link();
funcEnd = tok->linkAt(offset)->tokAt(-2);
typeName = tok->linkAt(offset)->previous();
argStart = tok->linkAt(offset)->next();
argEnd = tok->linkAt(offset)->next()->link();
tok = argEnd->next();
Token *spec = tok;
if (Token::Match(spec, "const|volatile")) {
@ -1204,11 +1204,11 @@ void Tokenizer::simplifyTypedef()
else if (Token::Match(tok->tokAt(offset), "( %type% (")) {
function = true;
if (tok->tokAt(offset)->link()->next()) {
if (tok->linkAt(offset)->next()) {
typeName = tok->tokAt(offset + 1);
argStart = tok->tokAt(offset + 2);
argEnd = tok->tokAt(offset + 2)->link();
tok = tok->tokAt(offset)->link()->next();
argEnd = tok->linkAt(offset + 2);
tok = tok->linkAt(offset)->next();
} else {
// internal error
continue;
@ -1217,32 +1217,32 @@ void Tokenizer::simplifyTypedef()
// pointer to function returning pointer to function
else if (Token::Match(tok->tokAt(offset), "( * ( * %type% ) (") &&
Token::simpleMatch(tok->tokAt(offset + 6)->link(), ") ) (") &&
Token::Match(tok->tokAt(offset + 6)->link()->tokAt(2)->link(), ") ;|,")) {
Token::simpleMatch(tok->linkAt(offset + 6), ") ) (") &&
Token::Match(tok->linkAt(offset + 6)->linkAt(2), ") ;|,")) {
functionPtrRetFuncPtr = true;
typeName = tok->tokAt(offset + 4);
argStart = tok->tokAt(offset + 6);
argEnd = tok->tokAt(offset + 6)->link();
argEnd = tok->linkAt(offset + 6);
argFuncRetStart = argEnd->tokAt(2);
argFuncRetEnd = argEnd->tokAt(2)->link();
argFuncRetEnd = argEnd->linkAt(2);
tok = argFuncRetEnd->next();
}
// function returning pointer to function
else if (Token::Match(tok->tokAt(offset), "( * %type% (") &&
Token::simpleMatch(tok->tokAt(offset + 3)->link(), ") ) (") &&
Token::Match(tok->tokAt(offset + 3)->link()->tokAt(2)->link(), ") ;|,")) {
Token::simpleMatch(tok->linkAt(offset + 3), ") ) (") &&
Token::Match(tok->linkAt(offset + 3)->linkAt(2), ") ;|,")) {
functionRetFuncPtr = true;
typeName = tok->tokAt(offset + 2);
argStart = tok->tokAt(offset + 3);
argEnd = tok->tokAt(offset + 3)->link();
argEnd = tok->linkAt(offset + 3);
argFuncRetStart = argEnd->tokAt(2);
argFuncRetEnd = argEnd->tokAt(2)->link();
argFuncRetEnd = argEnd->linkAt(2);
tok = argFuncRetEnd->next();
} else if (Token::Match(tok->tokAt(offset), "( * ( %type% ) (")) {
@ -1250,10 +1250,10 @@ void Tokenizer::simplifyTypedef()
typeName = tok->tokAt(offset + 3);
argStart = tok->tokAt(offset + 5);
argEnd = tok->tokAt(offset + 5)->link();
argEnd = tok->linkAt(offset + 5);
argFuncRetStart = argEnd->tokAt(2);
argFuncRetEnd = argEnd->tokAt(2)->link();
argFuncRetEnd = argEnd->linkAt(2);
tok = argFuncRetEnd->next();
}
@ -1334,7 +1334,7 @@ void Tokenizer::simplifyTypedef()
else if (tok2->str() == "operator" &&
tok2->next()->str() == typeName->str() &&
tok2->strAt(2) == "(" &&
Token::Match(tok2->tokAt(2)->link(), ") const| {")) {
Token::Match(tok2->linkAt(2), ") const| {")) {
// check for qualifier
if (tok2->previous()->str() == "::") {
// check for available and matching class name
@ -1706,7 +1706,7 @@ void Tokenizer::simplifyTypedef()
tok2 = copyTokens(tok2, argStart, argEnd);
} else if (tok2->tokAt(2) && tok2->strAt(2) == "[") {
while (tok2->tokAt(2) && tok2->strAt(2) == "[")
tok2 = tok2->tokAt(2)->link()->previous();
tok2 = tok2->linkAt(2)->previous();
}
if (arrayStart && arrayEnd) {
@ -1971,7 +1971,7 @@ bool Tokenizer::tokenize(std::istream &code,
// check for simple syntax errors..
for (const Token *tok = _tokens; tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "> struct {") &&
Token::simpleMatch(tok->tokAt(2)->link(), "} ;")) {
Token::simpleMatch(tok->linkAt(2), "} ;")) {
syntaxError(tok);
deallocateTokens();
return false;
@ -2077,7 +2077,7 @@ bool Tokenizer::tokenize(std::istream &code,
if (Token::simpleMatch(tok, "try {")) {
tok = tok->next()->link();
while (Token::simpleMatch(tok, "} catch (")) {
tok = tok->tokAt(2)->link();
tok = tok->linkAt(2);
if (Token::simpleMatch(tok, ") {"))
tok = tok->next()->link();
}
@ -3731,7 +3731,7 @@ void Tokenizer::setVarId()
// Found a class function..
if (Token::Match(tok2, funcpattern.c_str())) {
// Goto the end parenthesis..
tok2 = tok2->tokAt(3)->link();
tok2 = tok2->linkAt(3);
if (!tok2)
break;
@ -3983,7 +3983,7 @@ void Tokenizer::simplifySizeof()
}
// sizeof * (...) -> sizeof(*...)
if (Token::simpleMatch(tok->next(), "* (") && !Token::simpleMatch(tok->tokAt(2)->link(), ") .")) {
if (Token::simpleMatch(tok->next(), "* (") && !Token::simpleMatch(tok->linkAt(2), ") .")) {
tok->deleteNext();
tok->next()->insertToken("*");
}
@ -4641,7 +4641,7 @@ bool Tokenizer::removeRedundantConditions()
const Token *elseTag = 0;
// Find the closing "}"
elseTag = tok->tokAt(4)->link()->next();
elseTag = tok->linkAt(4)->next();
bool boolValue = false;
if (tok->strAt(2) == "true")
@ -4759,7 +4759,7 @@ void Tokenizer::removeRedundantFor()
bool read = false;
bool write = false;
unsigned int indentlevel = 0;
for (const Token *tok2 = tok->tokAt(2)->link(); tok2; tok2 = tok2->next()) {
for (const Token *tok2 = tok->linkAt(2); tok2; tok2 = tok2->next()) {
if (tok2->str() == "{")
++indentlevel;
else if (tok2->str() == "}") {
@ -4894,7 +4894,7 @@ bool Tokenizer::simplifyIfAddBraces()
bool innerIf = Token::simpleMatch(tempToken->next(), "if");
if (Token::simpleMatch(tempToken->next(), "do {"))
tempToken = tempToken->tokAt(2)->link();
tempToken = tempToken->linkAt(2);
// insert close brace..
// In most cases it would work to just search for the next ';' and insert a closing brace after it.
@ -5421,7 +5421,7 @@ void Tokenizer::simplifyCasts()
// #2897 : don't remove cast in such cases:
// *((char *)a + 1) = 0;
if (!tok->isName() && Token::simpleMatch(tok->next(), "* (")) {
tok = tok->tokAt(2)->link();
tok = tok->linkAt(2);
continue;
}
@ -5619,13 +5619,13 @@ void Tokenizer:: simplifyFunctionPointers()
tok1 = tok1->next();
// check that the cast ends
if (!Token::Match(tok1->tokAt(4)->link(), ") )|>"))
if (!Token::Match(tok1->linkAt(4), ") )|>"))
continue;
// ok simplify this function pointer cast to an ordinary pointer cast
tok1->deleteNext();
tok1->next()->deleteNext();
const Token *tok2 = tok1->tokAt(2)->link();
const Token *tok2 = tok1->linkAt(2);
Token::eraseTokens(tok1->next(), tok2 ? tok2->next() : 0);
continue;
}
@ -5645,13 +5645,13 @@ void Tokenizer:: simplifyFunctionPointers()
tok = tok->next();
// check that the declaration ends
if (!Token::Match(tok->tokAt(5)->link(), ") ;|,|)|=|["))
if (!Token::Match(tok->linkAt(5), ") ;|,|)|=|["))
continue;
// ok simplify this function pointer to an ordinary pointer
tok->deleteNext();
tok->tokAt(2)->deleteNext();
const Token *tok2 = tok->tokAt(3)->link();
const Token *tok2 = tok->linkAt(3);
Token::eraseTokens(tok->tokAt(2), tok2 ? tok2->next() : 0);
}
}
@ -7245,7 +7245,7 @@ bool Tokenizer::simplifyRedundantParenthesis()
}
while (Token::Match(tok->previous(), "[,;{}(] ( %var% (") &&
tok->link()->previous() == tok->tokAt(2)->link()) {
tok->link()->previous() == tok->linkAt(2)) {
// We have "( func ( *something* ))", remove the outer
// parenthesis
tok->link()->deleteThis();
@ -8622,10 +8622,10 @@ void Tokenizer::removeExceptionSpecifications(Token *tok) const
else if (Token::Match(tok, ") const| throw (")) {
if (tok->next()->str() == "const") {
Token::eraseTokens(tok->next(), tok->tokAt(3)->link());
Token::eraseTokens(tok->next(), tok->linkAt(3));
tok = tok->next();
} else
Token::eraseTokens(tok, tok->tokAt(2)->link());
Token::eraseTokens(tok, tok->linkAt(2));
tok->deleteNext();
}
@ -8947,7 +8947,7 @@ void Tokenizer::simplifyFuncInWhile()
Token *func = tok->tokAt(2);
Token *var = tok->tokAt(4);
Token *end = tok->tokAt(7)->link();
Token *end = tok->linkAt(7);
if (!end)
break;
@ -9176,7 +9176,7 @@ void Tokenizer::simplifyAssignmentInFunctionCall()
// Find 'foo(var='. Exclude 'assert(var=' to allow tests to check that assert(...) does not contain side-effects
else if (Token::Match(tok, "[;{}] %var% ( %var% =") &&
Token::simpleMatch(tok->tokAt(2)->link(), ") ;") &&
Token::simpleMatch(tok->linkAt(2), ") ;") &&
tok->next()->str() != "assert") {
const std::string funcname(tok->next()->str());
const Token * const vartok = tok->tokAt(3);
@ -9194,7 +9194,7 @@ void Tokenizer::simplifyAssignmentInFunctionCall()
tok2->next()->varId(vartok->varId());
tok2->insertToken("(");
Token::createMutualLinks(tok2->next(), tok->tokAt(2)->link());
Token::createMutualLinks(tok2->next(), tok->linkAt(2));
tok2->insertToken(funcname);
tok2->insertToken(";");
@ -9212,8 +9212,8 @@ void Tokenizer::simplifyAsm()
{
for (Token *tok = _tokens; tok; tok = tok->next()) {
if (Token::Match(tok->next(), "__asm|_asm|asm {") &&
tok->tokAt(2)->link()->next()) {
Token::eraseTokens(tok, tok->tokAt(2)->link()->next());
tok->linkAt(2)->next()) {
Token::eraseTokens(tok, tok->linkAt(2)->next());
}
else if (Token::Match(tok->next(), "asm|__asm|__asm__ volatile|__volatile__| (")) {
@ -9314,7 +9314,7 @@ void Tokenizer::simplifyBuiltinExpect()
}
} else if (Token::Match(tok->next(), "likely|unlikely (")) {
// remove closing ')'
tok->tokAt(2)->link()->previous()->deleteNext();
tok->linkAt(2)->previous()->deleteNext();
// remove "likely|unlikely ("
tok->deleteNext();
@ -9582,7 +9582,7 @@ void Tokenizer::simplifyQtSignalsSlots()
for (Token *tok = _tokens; tok; tok = tok->next()) {
// check for emit which can be outside of class
if (Token::Match(tok, "emit|Q_EMIT %var% (") &&
Token::simpleMatch(tok->tokAt(2)->link(), ") ;")) {
Token::simpleMatch(tok->linkAt(2), ") ;")) {
tok->deleteThis();
} else if (!Token::Match(tok, "class %var% :"))
continue;
@ -9620,7 +9620,7 @@ void Tokenizer::simplifyQtSignalsSlots()
tok2->str("protected:");
tok2->deleteNext();
} else if (Token::Match(tok2->next(), "emit|Q_EMIT %var% (") &&
Token::simpleMatch(tok2->tokAt(3)->link(), ") ;")) {
Token::simpleMatch(tok2->linkAt(3), ") ;")) {
tok2->deleteNext();
}
}
@ -9734,7 +9734,7 @@ void Tokenizer::removeUnnecessaryQualification()
} else if (tok->strAt(2) == "~")
++offset;
if (tok->tokAt(offset) && Token::Match(tok->tokAt(offset)->link(), ") const| {|;|:")) {
if (tok->tokAt(offset) && Token::Match(tok->linkAt(offset), ") const| {|;|:")) {
std::string qualification = tok->str() + "::";
// check for extra qualification

View File

@ -4677,16 +4677,16 @@ private:
tokenizer.tokenize(istr, "test.cpp");
const Token *tok = tokenizer.tokens();
// A body {}
ASSERT_EQUALS(true, tok->tokAt(2)->link() == tok->tokAt(9));
ASSERT_EQUALS(true, tok->tokAt(9)->link() == tok->tokAt(2));
ASSERT_EQUALS(true, tok->linkAt(2) == tok->tokAt(9));
ASSERT_EQUALS(true, tok->linkAt(9) == tok->tokAt(2));
// f body {}
ASSERT_EQUALS(true, tok->tokAt(7)->link() == tok->tokAt(8));
ASSERT_EQUALS(true, tok->tokAt(8)->link() == tok->tokAt(7));
ASSERT_EQUALS(true, tok->linkAt(7) == tok->tokAt(8));
ASSERT_EQUALS(true, tok->linkAt(8) == tok->tokAt(7));
// f ()
ASSERT_EQUALS(true, tok->tokAt(5)->link() == tok->tokAt(6));
ASSERT_EQUALS(true, tok->tokAt(6)->link() == tok->tokAt(5));
ASSERT_EQUALS(true, tok->linkAt(5) == tok->tokAt(6));
ASSERT_EQUALS(true, tok->linkAt(6) == tok->tokAt(5));
}
{
@ -4701,16 +4701,16 @@ private:
tokenizer.tokenize(istr, "test.cpp");
const Token *tok = tokenizer.tokens();
// a[10]
ASSERT_EQUALS(true, tok->tokAt(7)->link() == tok->tokAt(9));
ASSERT_EQUALS(true, tok->tokAt(9)->link() == tok->tokAt(7));
ASSERT_EQUALS(true, tok->linkAt(7) == tok->tokAt(9));
ASSERT_EQUALS(true, tok->linkAt(9) == tok->tokAt(7));
// new char[]
ASSERT_EQUALS(true, tok->tokAt(19)->link() == tok->tokAt(24));
ASSERT_EQUALS(true, tok->tokAt(24)->link() == tok->tokAt(19));
ASSERT_EQUALS(true, tok->linkAt(19) == tok->tokAt(24));
ASSERT_EQUALS(true, tok->linkAt(24) == tok->tokAt(19));
// a[0]
ASSERT_EQUALS(true, tok->tokAt(21)->link() == tok->tokAt(23));
ASSERT_EQUALS(true, tok->tokAt(23)->link() == tok->tokAt(21));
ASSERT_EQUALS(true, tok->linkAt(21) == tok->tokAt(23));
ASSERT_EQUALS(true, tok->linkAt(23) == tok->tokAt(21));
}
{
@ -4724,12 +4724,12 @@ private:
tokenizer.tokenize(istr, "test.cpp");
const Token *tok = tokenizer.tokens();
// foo(
ASSERT_EQUALS(true, tok->tokAt(6)->link() == tok->tokAt(10));
ASSERT_EQUALS(true, tok->tokAt(10)->link() == tok->tokAt(6));
ASSERT_EQUALS(true, tok->linkAt(6) == tok->tokAt(10));
ASSERT_EQUALS(true, tok->linkAt(10) == tok->tokAt(6));
// g(
ASSERT_EQUALS(true, tok->tokAt(8)->link() == tok->tokAt(9));
ASSERT_EQUALS(true, tok->tokAt(9)->link() == tok->tokAt(8));
ASSERT_EQUALS(true, tok->linkAt(8) == tok->tokAt(9));
ASSERT_EQUALS(true, tok->linkAt(9) == tok->tokAt(8));
}
}