Change: 'next()->next()'->'tokAt(2)', 'previous()->previous()'->'tokAt(-2)'.

This commit is contained in:
Edoardo Prezioso 2011-11-12 22:33:03 +01:00
parent ed6a0e14c4
commit b28a44dc3b
6 changed files with 27 additions and 27 deletions

View File

@ -45,7 +45,7 @@ void CheckObsoleteFunctions::obsoleteFunctions()
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (tok->isName() && tok->varId()==0 && (tok->next() && tok->next()->str() == "(") &&
(!Token::Match(tok->previous(), ".|::|:|,") || Token::simpleMatch(tok->previous()->previous(), "std :: gets"))) {
(!Token::Match(tok->previous(), ".|::|:|,") || Token::simpleMatch(tok->tokAt(-2), "std :: gets"))) {
// c function declaration?
if ((tok->next()->link()->next() && tok->next()->link()->next()->str() == ";") && (tok->previous() && (tok->previous()->str() == "*" || tok->previous()->isName()))) {
continue;

View File

@ -47,7 +47,7 @@ void CheckPostfixOperator::postfixOperator()
for (; tok; tok = tok->next()) {
bool result = false;
if (Token::Match(tok, "++|--")) {
if (Token::Match(tok->previous()->previous(), ";|{|}") && Token::Match(tok->next(), ";|)|,")) {
if (Token::Match(tok->tokAt(-2), ";|{|}") && Token::Match(tok->next(), ";|)|,")) {
result = true;
} else if (tok->strAt(-2) == ",") {
int i(1);

View File

@ -787,7 +787,7 @@ bool CheckStl::isStlContainer(unsigned int varid)
// discard namespace if supplied
if (Token::simpleMatch(type, "std ::"))
type = type->next()->next();
type = type->tokAt(2);
// all possible stl containers
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)
{
const Token *end = Token::findsimplematch(tok1, ";");
return (end && end->previous() &&
Token::simpleMatch(end->previous()->previous(), "] ) ;"));
Token::simpleMatch(end->tokAt(-2), "] ) ;"));
}
//---------------------------------------------------------------------------
@ -1109,10 +1109,10 @@ void CheckStl::checkAutoPointer()
(Token::simpleMatch(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) {
autoPointerContainerError(tok);
} else {
const Token *tok2 = tok->next()->next();
const Token *tok2 = tok->tokAt(2);
while (tok2) {
if (Token::Match(tok2, "> %var%")) {
const Token *tok3 = tok2->next()->next();
const Token *tok3 = tok2->tokAt(2);
if (Token::Match(tok3, "( new %type%") && hasArrayEndParen(tok3)) {
autoPointerArrayError(tok2->next());
break;
@ -1121,7 +1121,7 @@ void CheckStl::checkAutoPointer()
tok3 = tok3->next();
}
if (tok3) {
tok3 = tok3->previous()->previous();
tok3 = tok3->tokAt(-2);
if (Token::simpleMatch(tok3->previous(), "[ ] )")) {
autoPointerArrayError(tok2->next());
} else if (tok3->varId()) {
@ -1142,9 +1142,9 @@ void CheckStl::checkAutoPointer()
} else {
if (Token::Match(tok, "%var% = %var% ;")) {
if (_settings->isEnabled("style")) {
iter = autoPtrVarId.find(tok->next()->next()->varId());
iter = autoPtrVarId.find(tok->tokAt(2)->varId());
if (iter != autoPtrVarId.end()) {
autoPointerError(tok->next()->next());
autoPointerError(tok->tokAt(2));
}
}
} else if ((Token::Match(tok, "%var% = new %type% ") && hasArrayEnd(tok)) ||

View File

@ -722,7 +722,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
// standard const type declaration
// const int i = x;
else if (Token::Match(tok, "[;{}] const %type% %var% =")) {
tok = tok->next()->next();
tok = tok->tokAt(2);
if (tok->isStandardType() || isRecordTypeWithoutSideEffects(tok->next()))
variables.addVar(tok->next(), Variables::standard, info, true);

View File

@ -375,7 +375,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// class destructor
else if (tok->previous() && tok->previous()->str() == "~" &&
tok->previous()->previous() && tok->previous()->previous()->str() == "::")
tok->tokAt(-2) && tok->tokAt(-2)->str() == "::")
addFunction(&scope, &tok, argStart);
// regular function
@ -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->next()->next()->link(), ") {")) {
const Token *tok1 = tok->next()->next()->link()->next();
Token::simpleMatch(tok->tokAt(2)->link(), ") {")) {
const Token *tok1 = tok->tokAt(2)->link()->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()->next()->next()->link()->next();
const Token *start = argStart->link()->tokAt(2)->link()->next();
while (start && start->str() != "{")
start = start->next();
func->start = start;
@ -1436,7 +1436,7 @@ void Scope::getVariableList()
} else
break;
} else if (Token::Match(tok, "struct|union {") && Token::Match(tok->next()->link(), "} %var% ;|[")) {
tok = tok->next()->link()->next()->next();
tok = tok->next()->link()->tokAt(2);
continue;
} else if (Token::Match(tok, "struct|union {") && Token::simpleMatch(tok->next()->link(), "} ;")) {
level++;
@ -1494,7 +1494,7 @@ void Scope::getVariableList()
else if (Token::Match(tok, ";|{|}"))
continue;
else if (Token::Match(tok, "goto %var% ;")) {
tok = tok->next()->next();
tok = tok->tokAt(2);
continue;
}

View File

@ -1402,7 +1402,7 @@ void Tokenizer::simplifyTypedef()
if (pattern1.find("::") != std::string::npos) { // has a "something ::"
if (Token::simpleMatch(tok2->previous(), "::")) {
tok2->previous()->previous()->deleteNext();
tok2->tokAt(-2)->deleteNext();
globalScope = true;
}
@ -1743,7 +1743,7 @@ void Tokenizer::simplifyTypedef()
if (tok2->next()->str() == "{")
tok2 = tok2->next()->link()->next();
else if (tok2->next()->str().at(0) == '\"')
tok2 = tok2->next()->next();
tok2 = tok2->tokAt(2);
}
} while (Token::Match(tok2, ", %var% ;|'|=|,"));
}
@ -1897,7 +1897,7 @@ bool Tokenizer::tokenize(std::istream &code,
if (_files[0].find(".cs")) {
for (Token *tok = _tokens; tok; tok = tok->next()) {
if (Token::Match(tok, "[;{}] %type% [ ] %var% [=;]")) {
tok = tok->next()->next();
tok = tok->tokAt(2);
tok->str("*");
tok->deleteNext();
}
@ -6323,7 +6323,7 @@ void Tokenizer::simplifyIfNot()
if (Token::Match(tok->link()->tokAt(-2), "( %var%")) {
Token::eraseTokens(tok, tok->tokAt(3));
tok->link()->previous()->insertToken(tok->link()->previous()->str().c_str());
tok->link()->previous()->previous()->str("!");
tok->link()->tokAt(-2)->str("!");
}
// if( (x) == 0 )
@ -7012,7 +7012,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
};
for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) {
if (tok3->str() == functionName[i]) {
Token *par1 = tok3->next()->next();
Token *par1 = tok3->tokAt(2);
if (!structname.empty()) {
par1->deleteThis();
par1->deleteThis();
@ -7376,7 +7376,7 @@ bool Tokenizer::simplifyCalculations()
tok = tok->previous();
if (Token::Match(tok->tokAt(-4), "[;{}] %var% = %var% [+-|] 0 ;") &&
tok->strAt(-3) == tok->previous()->str()) {
tok = tok->previous()->previous()->previous();
tok = tok->tokAt(-3);
tok->deleteThis();
tok->deleteThis();
tok->deleteThis();
@ -8432,9 +8432,9 @@ void Tokenizer::simplifyMathFunctions()
}
if (tok->previous() &&
Token::simpleMatch(tok->previous()->previous(), "std ::")) {
Token::simpleMatch(tok->tokAt(-2), "std ::")) {
// Delete "std ::"
tok = tok->previous()->previous();
tok = tok->tokAt(-2);
tok->deleteNext();
tok->deleteThis();
}
@ -8496,8 +8496,8 @@ void Tokenizer::simplifyComma()
tok->str(";");
}
if (tok->previous() && tok->previous()->previous()) {
if (Token::Match(tok->previous()->previous(), "delete %var% , %var% ;") &&
if (tok->previous() && tok->tokAt(-2)) {
if (Token::Match(tok->tokAt(-2), "delete %var% , %var% ;") &&
tok->next()->varId() != 0) {
// Handle "delete a, b;"
tok->str(";");
@ -9645,7 +9645,7 @@ void Tokenizer::simplifyOperatorName()
}
if (Token::simpleMatch(par, "[ ]")) {
op += "[]";
par = par->next()->next();
par = par->tokAt(2);
done = false;
}
if (Token::Match(par, "( *| )")) {