Refactorizations in CheckStl:

- Improved detection of "auto" iterators in CheckStl::iterators()
- Improved performance of CheckStl::pushback()
- Added more containers to std.cfg
This commit is contained in:
PKEuS 2015-11-13 13:22:47 +01:00
parent c10a10c26f
commit da6b17d176
2 changed files with 31 additions and 6 deletions

View File

@ -4028,18 +4028,30 @@
<function name="data" yields="buffer"/>
</access>
</container>
<container id="stdSet" startPattern="std :: set &lt;" inherits="stdContainer">
<container id="stdSet" startPattern="std :: set|unoredered_set|multiset|unoredered_multiset &lt;" inherits="stdContainer">
<access>
<function name="find" action="find"/>
</access>
</container>
<container id="stdMap" startPattern="std :: map &lt;" inherits="stdContainer">
<container id="stdMap" startPattern="std :: map|unordered_map|multimap|unordered_multimap &lt;" inherits="stdContainer">
<type templateParameter="1"/>
<access>
<function name="at" yields="at_index"/>
<function name="find" action="find"/>
</access>
</container>
<container id="stdList" startPattern="std :: list &lt;" inherits="stdContainer">
<size>
<function name="push_back" action="push"/>
<function name="pop_back" action="pop"/>
<function name="push_front" action="push"/>
<function name="pop_front" action="pop"/>
</size>
<access>
<function name="front" yields="item"/>
<function name="back" yields="item"/>
</access>
</container>
<container id="stdComplex" startPattern="std :: complex &lt;" endPattern="&gt; !!::">
<type templateParameter="1"/>
</container>

View File

@ -68,8 +68,6 @@ void CheckStl::iterators()
{
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
// Using same iterator against different containers.
// for (it = foo.begin(); it != bar.end(); ++it)
for (unsigned int iteratorId = 1; iteratorId < symbolDatabase->getVariableListSize(); iteratorId++) {
const Variable* var = symbolDatabase->getVariableFromVarId(iteratorId);
@ -77,9 +75,20 @@ void CheckStl::iterators()
if (!var || !var->isLocal() || !Token::Match(var->typeEndToken(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator|auto"))
continue;
if (var->typeEndToken()->str() == "auto" && !Token::Match(var->typeEndToken(), "auto %name% ; %name% = %name% . begin|end ( )"))
if (var->typeEndToken()->str() == "auto") {
if (Token::Match(var->typeEndToken(), "auto %name% ; %name% = %var% . %name% ( )")) {
const Token* containertok = var->typeEndToken()->tokAt(5);
const Library::Container* container = _settings->library.detectContainer(containertok->variable()->typeStartToken());
if (!container)
continue;
Library::Container::Yield yield = container->getYield(containertok->strAt(2));
if (yield != Library::Container::END_ITERATOR && yield != Library::Container::START_ITERATOR)
continue;
} else
continue;
}
if (var->type()) { // If it is defined, ensure that it is defined like an iterator
// look for operator* and operator++
const Function* end = var->type()->getFunction("operator*");
@ -437,6 +446,10 @@ void CheckStl::pushback()
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "%var% = & %var% [")) {
// Skip it directly if it is a pointer or an array
if (tok->tokAt(3)->variable()->isArrayOrPointer())
continue;
// Variable id for pointer
const unsigned int pointerId(tok->varId());