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

Method solveExprValue

lib/valueflow.cpp:6189–6231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6187}
6188
6189const Token* ValueFlow::solveExprValue(const Token* expr,
6190 const std::function<std::vector<MathLib::bigint>(const Token*)>& eval,
6191 ValueFlow::Value& value)
6192{
6193 if (!expr)
6194 return nullptr;
6195 if (!value.isIntValue() && !value.isIteratorValue() && !value.isSymbolicValue())
6196 return expr;
6197 if (value.isSymbolicValue() && !Token::Match(expr, "+|-"))
6198 return expr;
6199 MathLib::bigint intval = 0;
6200 const Token* binaryTok = parseBinaryIntOp(expr, eval, intval);
6201 const bool rhs = astIsRHS(binaryTok);
6202 // If its on the rhs, then -1 multiplication is needed, which is not possible with simple delta analysis used currently for symbolic values
6203 if (value.isSymbolicValue() && rhs && Token::simpleMatch(expr, "-"))
6204 return expr;
6205 if (binaryTok && expr->str().size() == 1) {
6206 switch (expr->str()[0]) {
6207 case '+': {
6208 value.intvalue -= intval;
6209 return ValueFlow::solveExprValue(binaryTok, eval, value);
6210 }
6211 case '-': {
6212 if (rhs)
6213 value.intvalue = intval - value.intvalue;
6214 else
6215 value.intvalue += intval;
6216 return ValueFlow::solveExprValue(binaryTok, eval, value);
6217 }
6218 case '*': {
6219 if (intval == 0)
6220 break;
6221 value.intvalue /= intval;
6222 return ValueFlow::solveExprValue(binaryTok, eval, value);
6223 }
6224 case '^': {
6225 value.intvalue ^= intval;
6226 return ValueFlow::solveExprValue(binaryTok, eval, value);
6227 }
6228 }
6229 }
6230 return expr;
6231}
6232
6233bool ValueFlow::isContainerSizeChanged(const Token* tok, int indirect, const Settings& settings, int depth)
6234{

Callers

nothing calls this directly

Calls 6

parseBinaryIntOpFunction · 0.85
astIsRHSFunction · 0.85
solveExprValueFunction · 0.85
simpleMatchFunction · 0.70
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected