| 1212 | } |
| 1213 | |
| 1214 | static 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 | |
| 1241 | static void valueFlowGlobalStaticVar(TokenList& tokenList, const Settings& settings) |
| 1242 | { |
no test coverage detected