| 1516 | } |
| 1517 | |
| 1518 | void CheckStlImpl::if_find() |
| 1519 | { |
| 1520 | const bool printWarning = mSettings.severity.isEnabled(Severity::warning); |
| 1521 | const bool printPerformance = mSettings.severity.isEnabled(Severity::performance); |
| 1522 | if (!printWarning && !printPerformance) |
| 1523 | return; |
| 1524 | |
| 1525 | logChecker("CheckStl::if_find"); // warning,performance |
| 1526 | |
| 1527 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 1528 | |
| 1529 | for (const Scope &scope : symbolDatabase->scopeList) { |
| 1530 | if ((scope.type != ScopeType::eIf && scope.type != ScopeType::eWhile) || !scope.classDef) |
| 1531 | continue; |
| 1532 | |
| 1533 | const Token *conditionStart = scope.classDef->next(); |
| 1534 | if (Token::simpleMatch(conditionStart->astOperand2(), ";")) |
| 1535 | conditionStart = conditionStart->astOperand2(); |
| 1536 | |
| 1537 | for (const Token *tok = conditionStart; tok->str() != "{"; tok = tok->next()) { |
| 1538 | const Token* funcTok = nullptr; |
| 1539 | const Library::Container* container = nullptr; |
| 1540 | |
| 1541 | if (Token::Match(tok, "%name% (")) |
| 1542 | tok = tok->linkAt(1); |
| 1543 | |
| 1544 | else if (tok->variable() && Token::Match(tok, "%var% . %name% (")) { |
| 1545 | container = mSettings.library.detectContainer(tok->variable()->typeStartToken()); |
| 1546 | funcTok = tok->tokAt(2); |
| 1547 | } |
| 1548 | |
| 1549 | // check also for vector-like or pointer containers |
| 1550 | else if (tok->variable() && tok->astParent() && (tok->astParent()->str() == "*" || tok->astParent()->str() == "[")) { |
| 1551 | const Token *tok2 = tok->astParent(); |
| 1552 | |
| 1553 | if (!Token::Match(tok2->astParent(), ". %name% (")) |
| 1554 | continue; |
| 1555 | |
| 1556 | funcTok = tok2->astParent()->next(); |
| 1557 | |
| 1558 | if (tok->variable()->isArrayOrPointer()) |
| 1559 | container = mSettings.library.detectContainer(tok->variable()->typeStartToken()); |
| 1560 | else { // Container of container - find the inner container |
| 1561 | container = mSettings.library.detectContainer(tok->variable()->typeStartToken()); // outer container |
| 1562 | tok2 = Token::findsimplematch(tok->variable()->typeStartToken(), "<", tok->variable()->typeEndToken()); |
| 1563 | if (container && container->type_templateArgNo >= 0 && tok2) { |
| 1564 | tok2 = tok2->next(); |
| 1565 | for (int j = 0; j < container->type_templateArgNo; j++) |
| 1566 | tok2 = tok2->nextTemplateArgument(); |
| 1567 | |
| 1568 | container = mSettings.library.detectContainer(tok2); // inner container |
| 1569 | } else |
| 1570 | container = nullptr; |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | Library::Container::Action action{}; |
| 1575 | if (container && |
no test coverage detected