MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / findInsertValue

Function findInsertValue

lib/checkstl.cpp:1652–1684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1650}
1651
1652static const Token *findInsertValue(const Token *tok, const Token *containerTok, const Token *keyTok, const Settings &settings)
1653{
1654 const Token *startTok = skipLocalVars(tok);
1655 const Token *top = startTok->astTop();
1656
1657 const Token *icontainerTok = nullptr;
1658 const Token *ikeyTok = nullptr;
1659 const Token *ivalueTok = nullptr;
1660 if (Token::simpleMatch(top, "=") && Token::simpleMatch(top->astOperand1(), "[")) {
1661 icontainerTok = top->astOperand1()->astOperand1();
1662 ikeyTok = top->astOperand1()->astOperand2();
1663 ivalueTok = top->astOperand2();
1664 }
1665 if (Token::simpleMatch(top, "(") && Token::Match(top->astOperand1(), ". insert|emplace (") && !astIsIterator(top->astOperand1()->tokAt(2))) {
1666 icontainerTok = top->astOperand1()->astOperand1();
1667 const Token *itok = top->astOperand1()->tokAt(2)->astOperand2();
1668 if (Token::simpleMatch(itok, ",")) {
1669 ikeyTok = itok->astOperand1();
1670 ivalueTok = itok->astOperand2();
1671 } else {
1672 ikeyTok = itok;
1673 }
1674 }
1675 if (!ikeyTok || !icontainerTok)
1676 return nullptr;
1677 if (isSameExpression(true, containerTok, icontainerTok, settings, true, false) &&
1678 isSameExpression(true, keyTok, ikeyTok, settings, true, true)) {
1679 if (ivalueTok)
1680 return ivalueTok;
1681 return ikeyTok;
1682 }
1683 return nullptr;
1684}
1685
1686void CheckStlImpl::checkFindInsert()
1687{

Callers 1

checkFindInsertMethod · 0.85

Calls 8

skipLocalVarsFunction · 0.85
astIsIteratorFunction · 0.85
isSameExpressionFunction · 0.85
astTopMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
simpleMatchFunction · 0.70
tokAtMethod · 0.45

Tested by

no test coverage detected