From 776ad32a0b832758eb1520289a791b206d28bdf9 Mon Sep 17 00:00:00 2001 From: Philipp Kloke Date: Sat, 12 Apr 2014 22:24:31 +0200 Subject: [PATCH] Refactorized CheckStl::redundantCondition(): - Use symboldatabase - Support erase() method --- lib/checkstl.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 001d6bc28..5cf42970c 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -981,17 +981,23 @@ void CheckStl::sizeError(const Token *tok) "guaranteed to take constant time."); } -static inline const Token *findRedundantCondition(const Token *start) -{ - return Token::findmatch(start, "if ( %var% . find ( %any% ) != %var% . end|rend|cend|crend ( ) ) { %var% . remove ( %any% ) ;"); -} - void CheckStl::redundantCondition() { - const Token *tok = findRedundantCondition(_tokenizer->tokens()); - while (tok) { + const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); + + for (std::list::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) { + if (i->type != Scope::eIf && i->type != Scope::eElseIf) + continue; + + const Token* tok = i->classDef->tokAt(2); + if (i->type == Scope::eElseIf) + tok = tok->next(); + + if (!Token::Match(tok, "%var% . find ( %any% ) != %var% . end|rend|cend|crend ( ) ) { %var% . remove|erase ( %any% ) ;")) + continue; + // Get tokens for the fields %var% and %any% - const Token *var1 = tok->tokAt(2); + const Token *var1 = tok; const Token *any1 = var1->tokAt(4); const Token *var2 = any1->tokAt(3); const Token *var3 = var2->tokAt(7); @@ -1003,8 +1009,6 @@ void CheckStl::redundantCondition() any1->str() == any2->str()) { redundantIfRemoveError(tok); } - - tok = findRedundantCondition(tok->next()); } }