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

Function findUnmatchedTernaryOp

lib/tokenize.cpp:8514–8530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8512}
8513
8514static const Token *findUnmatchedTernaryOp(const Token * const begin, const Token * const end, int depth = 0)
8515{
8516 std::stack<const Token *> ternaryOp;
8517 for (const Token *tok = begin; tok != end && tok->str() != ";"; tok = tok->next()) {
8518 if (tok->str() == "?")
8519 ternaryOp.push(tok);
8520 else if (!ternaryOp.empty() && tok->str() == ":")
8521 ternaryOp.pop();
8522 else if (depth < 100 && Token::Match(tok,"(|[")) {
8523 const Token *inner = findUnmatchedTernaryOp(tok->next(), tok->link(), depth+1);
8524 if (inner)
8525 return inner;
8526 tok = tok->link();
8527 }
8528 }
8529 return ternaryOp.empty() ? nullptr : ternaryOp.top();
8530}
8531
8532static bool isCPPAttribute(const Token * tok)
8533{

Callers 1

findGarbageCodeMethod · 0.85

Calls 3

nextMethod · 0.80
strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected