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

Function valueFlowAfterSwap

lib/valueflow.cpp:4263–4289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4261}
4262
4263static void valueFlowAfterSwap(const TokenList& tokenlist,
4264 const SymbolDatabase& symboldatabase,
4265 ErrorLogger& errorLogger,
4266 const Settings& settings)
4267{
4268 for (const Scope* scope : symboldatabase.functionScopes) {
4269 for (auto* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
4270 if (!Token::simpleMatch(tok, "swap ("))
4271 continue;
4272 if (!Token::simpleMatch(tok->next()->astOperand2(), ","))
4273 continue;
4274 std::vector<Token*> args = astFlatten(tok->next()->astOperand2(), ",");
4275 if (args.size() != 2)
4276 continue;
4277 if (args[0]->exprId() == 0)
4278 continue;
4279 if (args[1]->exprId() == 0)
4280 continue;
4281 for (int i = 0; i < 2; i++) {
4282 std::vector<const Variable*> vars = getVariables(args[0]);
4283 const std::list<ValueFlow::Value>& values = args[0]->values();
4284 valueFlowForwardAssign(args[0], args[1], std::move(vars), values, false, tokenlist, errorLogger, settings);
4285 std::swap(args[0], args[1]);
4286 }
4287 }
4288 }
4289}
4290
4291static void valueFlowSetConditionToKnown(const Token* tok, std::list<ValueFlow::Value>& values, bool then)
4292{

Callers 1

setValuesMethod · 0.85

Calls 8

astFlattenFunction · 0.85
getVariablesFunction · 0.85
valueFlowForwardAssignFunction · 0.85
nextMethod · 0.80
astOperand2Method · 0.80
simpleMatchFunction · 0.70
swapFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected