Refactoring: Use SymbolDatabase to determine if variable is a iterator

This commit is contained in:
Daniel Marjamäki 2011-03-13 09:48:53 +01:00
parent 85daa26fdf
commit 384729204f
1 changed files with 12 additions and 2 deletions

View File

@ -439,8 +439,18 @@ void CheckStl::erase()
{ {
if (Token::Match(tok2, "; %var% !=")) if (Token::Match(tok2, "; %var% !="))
{ {
const unsigned int varid = tok2->next()->varId(); // Get declaration token for var..
if (varid > 0 && Token::findmatch(_tokenizer->tokens(), "> :: iterator %varid%", varid)) const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const Variable *variableInfo = symbolDatabase->getVariableFromVarId(tok2->next()->varId());
const Token *decltok = variableInfo ? variableInfo->typeEndToken() : NULL;
// Is variable an iterator?
bool isIterator = false;
if (decltok && Token::Match(decltok->tokAt(-2), "> :: iterator %varid%", tok2->next()->varId()))
isIterator = true;
// If tok2->next() is an iterator, check scope
if (isIterator)
EraseCheckLoop::checkScope(this, tok2->next()); EraseCheckLoop::checkScope(this, tok2->next());
} }
break; break;