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

Function visitAstNodes

lib/astutils.h:59–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 */
58template<class T, class TFunc, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
59void visitAstNodes(T *ast, const TFunc &visitor)
60{
61 if (!ast)
62 return;
63
64 // the size of 8 was determined in tests to be sufficient to avoid excess allocations. also add 1 as a buffer.
65 // we might need to increase that value in the future.
66 SmallVector<T *, 8 + 1> tokens;
67 T *tok = ast;
68 do {
69 const ChildrenToVisit c = visitor(tok);
70 if (c == ChildrenToVisit::done)
71 break;
72
73 if (c == ChildrenToVisit::op2 || c == ChildrenToVisit::op1_and_op2) {
74 T *t2 = tok->astOperand2();
75 if (t2)
76 tokens.push_back(t2);
77 }
78 if (c == ChildrenToVisit::op1 || c == ChildrenToVisit::op1_and_op2) {
79 T *t1 = tok->astOperand1();
80 if (t1)
81 tokens.push_back(t1);
82 }
83
84 if (tokens.empty())
85 break;
86
87 tok = tokens.back();
88 tokens.pop_back();
89 } while (true);
90}
91
92template<class TFunc>
93const Token* findAstNode(const Token* ast, const TFunc& pred)

Callers 15

hasVolatileCastOrVarFunction · 0.85
fwdanalysis.cppFile · 0.85
getDimensionsEtcFunction · 0.85
createAstMethod · 0.85
setTokenValueFunction · 0.85
getEndOfExprScopeMethod · 0.85
getVarIdsFunction · 0.85
getVariablesFunction · 0.85
fillFromPathMethod · 0.85
valueFlowForLoop2Function · 0.85
multiCondition2Method · 0.85
alwaysTrueFalseMethod · 0.85

Calls 4

astOperand2Method · 0.80
astOperand1Method · 0.80
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected