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

Function getVariableValues

lib/checkuninitvar.cpp:80–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80static std::map<nonneg int, VariableValue> getVariableValues(const Token* tok) {
81 std::map<nonneg int, VariableValue> ret;
82 if (!tok || !tok->scope()->isExecutable())
83 return ret;
84 while (tok && tok->str() != "{") {
85 if (tok->str() == "}") {
86 if (tok->link()->isBinaryOp())
87 tok = tok->link()->previous();
88 else
89 break;
90 }
91 if (Token::Match(tok, "%var% =|{") && tok->next()->isBinaryOp() && tok->varId() && ret.count(tok->varId()) == 0) {
92 const Token* rhs = tok->next()->astOperand2();
93 if (rhs && rhs->hasKnownIntValue())
94 ret[tok->varId()] = VariableValue(rhs->getKnownIntValue());
95 }
96 tok = tok->previous();
97 }
98 return ret;
99}
100
101bool CheckUninitVarImpl::diag(const Token* tok)
102{

Callers 2

checkScopeMethod · 0.85
checkStructMethod · 0.85

Calls 8

VariableValueClass · 0.85
scopeMethod · 0.80
isBinaryOpMethod · 0.80
nextMethod · 0.80
astOperand2Method · 0.80
getKnownIntValueMethod · 0.80
strMethod · 0.45
hasKnownIntValueMethod · 0.45

Tested by

no test coverage detected