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

Function getCondTokImpl

lib/astutils.cpp:839–859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

837}
838
839template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
840static T* getCondTokImpl(T* tok)
841{
842 if (!tok)
843 return nullptr;
844 if (Token::simpleMatch(tok, "("))
845 return getCondTok(tok->previous());
846 if (Token::simpleMatch(tok, "do {")) {
847 T* endTok = tok->linkAt(1);
848 if (Token::simpleMatch(endTok, "} while ("))
849 return endTok->tokAt(2)->astOperand2();
850 }
851 if (Token::simpleMatch(tok, "for") && Token::simpleMatch(tok->next()->astOperand2(), ";") &&
852 tok->next()->astOperand2()->astOperand2())
853 return tok->next()->astOperand2()->astOperand2()->astOperand1();
854 if (Token::simpleMatch(tok->next()->astOperand2(), ";"))
855 return tok->next()->astOperand2()->astOperand1();
856 if (tok->isName() && !tok->isControlFlowKeyword())
857 return nullptr;
858 return tok->next()->astOperand2();
859}
860
861template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
862static T* getCondTokFromEndImpl(T* endBlock)

Callers 1

getCondTokFunction · 0.85

Calls 7

getCondTokFunction · 0.85
linkAtMethod · 0.80
astOperand2Method · 0.80
nextMethod · 0.80
astOperand1Method · 0.80
simpleMatchFunction · 0.70
tokAtMethod · 0.45

Tested by

no test coverage detected