Refactor isContainerSizeSlow() to use Variable::isStlType()

This commit is contained in:
Lucas Manuel Rodriguez 2014-01-28 13:31:23 -03:00
parent 312780b6fc
commit 7fdc4ab6cc
1 changed files with 11 additions and 16 deletions

View File

@ -929,24 +929,19 @@ void CheckStl::if_findError(const Token *tok, bool str)
*/ */
static bool isContainerSizeSlow(const Token *tok) static bool isContainerSizeSlow(const Token *tok)
{ {
// find where this token is defined // THIS ARRAY MUST BE ORDERED ALPHABETICALLY
const Variable *var = tok->variable(); static const char* stl_size_slow[] = {
"array", "bitset",
if (!var) "forward_list", "hash_map", "hash_multimap", "hash_set",
return false; "list", "map", "multimap", "multiset",
"priority_queue", "queue", "set", "stack", "unordered_map",
// find where this tokens type starts "unordered_multimap", "unordered_multiset", "unordered_set"
const Token *type = var->typeStartToken(); };
// discard namespace if supplied
if (Token::simpleMatch(type, "std ::"))
type = type->tokAt(2);
// check if it's an stl template
if (Token::Match(type, "array|bitset|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string"))
return true;
if (!tok)
return false; return false;
const Variable* var = tok->variable();
return var && var->isStlType(stl_size_slow);
} }
void CheckStl::size() void CheckStl::size()