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

Function isPrefixUnary

lib/tokenlist.cpp:941–968  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

939}
940
941static bool isPrefixUnary(const Token* tok, bool cpp)
942{
943 if (cpp && Token::simpleMatch(tok->previous(), "* [") && Token::simpleMatch(tok->link(), "] {")) {
944 for (const Token* prev = tok->previous(); Token::Match(prev, "%name%|::|*|&|>|>>"); prev = prev->previous()) {
945 if (Token::Match(prev, ">|>>")) {
946 if (!prev->link())
947 break;
948 prev = prev->link();
949 }
950 if (prev->str() == "new")
951 return false;
952 }
953 }
954 if (!tok->previous()
955 || ((Token::Match(tok->previous(), "(|[|{|%op%|;|?|:|,|.|case|return|::") || (cpp && tok->strAt(-1) == "throw"))
956 && (tok->previous()->tokType() != Token::eIncDecOp || tok->tokType() == Token::eIncDecOp)))
957 return true;
958
959 if (tok->strAt(-1) == "}") {
960 const Token* parent = tok->linkAt(-1)->tokAt(-1);
961 return !Token::Match(parent, "%type%") || parent->isKeyword();
962 }
963
964 if (tok->str() == "*" && tok->previous()->tokType() == Token::eIncDecOp && isPrefixUnary(tok->previous(), cpp))
965 return true;
966
967 return tok->strAt(-1) == ")" && iscast(tok->linkAt(-1), cpp);
968}
969
970/**
971 * @throws InternalError thrown if unexpected tokens are encountered

Callers 2

compilePrecedence2Function · 0.85
compilePrecedence3Function · 0.85

Calls 6

iscastFunction · 0.85
linkAtMethod · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45
tokAtMethod · 0.45
isKeywordMethod · 0.45

Tested by

no test coverage detected