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

Function valueFlowGlobalConstVar

lib/valueflow.cpp:1214–1239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1212}
1213
1214static void valueFlowGlobalConstVar(TokenList& tokenList, const Settings& settings)
1215{
1216 // Get variable values...
1217 std::map<const Variable*, ValueFlow::Value> vars;
1218 for (const Token* tok = tokenList.front(); tok; tok = tok->next()) {
1219 if (!tok->variable())
1220 continue;
1221 // Initialization...
1222 if (tok == tok->variable()->nameToken() && !tok->variable()->isVolatile() && !tok->variable()->isArgument() &&
1223 tok->variable()->isConst() && tok->valueType() && tok->valueType()->isIntegral() &&
1224 tok->valueType()->pointer == 0 && tok->valueType()->constness == 1 && Token::Match(tok, "%name% =") &&
1225 tok->next()->astOperand2() && tok->next()->astOperand2()->hasKnownIntValue()) {
1226 vars[tok->variable()] = *tok->next()->astOperand2()->getKnownValue(ValueFlow::Value::ValueType::INT);
1227 }
1228 }
1229
1230 // Set values..
1231 for (Token* tok = tokenList.front(); tok; tok = tok->next()) {
1232 if (!tok->variable())
1233 continue;
1234 const auto var = utils::as_const(vars).find(tok->variable());
1235 if (var == vars.end())
1236 continue;
1237 setTokenValue(tok, var->second, settings);
1238 }
1239}
1240
1241static void valueFlowGlobalStaticVar(TokenList& tokenList, const Settings& settings)
1242{

Callers 1

setValuesMethod · 0.85

Calls 13

setTokenValueFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
variableMethod · 0.80
isVolatileMethod · 0.80
isConstMethod · 0.80
isIntegralMethod · 0.80
astOperand2Method · 0.80
getKnownValueMethod · 0.80
nameTokenMethod · 0.45
hasKnownIntValueMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected