From ed6567e2ec8ad9f6e7f6320aa6ad91c609d9ae9f Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 29 Aug 2024 14:19:09 +0200 Subject: [PATCH 1/2] vf_settokenvalue.cpp; got rid of default parameter / use reference --- lib/vf_settokenvalue.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index b6c4ac255d8..4ddf9d356df 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -46,18 +46,16 @@ namespace ValueFlow { - static Library::Container::Yield getContainerYield(Token* tok, const Settings& settings, Token** parent = nullptr) + static Library::Container::Yield getContainerYield(Token* tok, const Settings& settings, Token*& parent) { if (Token::Match(tok, ". %name% (") && tok->astParent() == tok->tokAt(2) && tok->astOperand1() && tok->astOperand1()->valueType()) { const Library::Container* c = getLibraryContainer(tok->astOperand1()); - if (parent) - *parent = tok->astParent(); + parent = tok->astParent(); return c ? c->getYield(tok->strAt(1)) : Library::Container::Yield::NO_YIELD; } if (Token::Match(tok->previous(), "%name% (")) { - if (parent) - *parent = tok; + parent = tok; if (const Library::Function* f = settings.library.getFunction(tok->previous())) { return f->containerYield; } @@ -302,7 +300,7 @@ namespace ValueFlow } } Token* next = nullptr; - const Library::Container::Yield yields = getContainerYield(parent, settings, &next); + const Library::Container::Yield yields = getContainerYield(parent, settings, next); if (yields == Library::Container::Yield::SIZE) { Value v(value); v.valueType = Value::ValueType::INT; From a0e9d729637e0f4cf2c1af984572b7225f78b00b Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 29 Aug 2024 14:22:28 +0200 Subject: [PATCH 2/2] vf_iterators.cpp: use reference / small cleanup --- lib/vf_iterators.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/vf_iterators.cpp b/lib/vf_iterators.cpp index 1f85a27873a..6e813c19bf8 100644 --- a/lib/vf_iterators.cpp +++ b/lib/vf_iterators.cpp @@ -31,17 +31,17 @@ namespace ValueFlow { - static Library::Container::Yield findIteratorYield(Token* tok, const Token** ftok, const Settings &settings) + static Library::Container::Yield findIteratorYield(Token* tok, const Token*& ftok, const Settings &settings) { - auto yield = astContainerYield(tok, ftok); - if (ftok && *ftok) + auto yield = astContainerYield(tok, &ftok); + if (ftok) return yield; if (!tok->astParent()) return yield; //begin/end free functions - return astFunctionYield(tok->astParent()->previous(), settings, ftok); + return astFunctionYield(tok->astParent()->previous(), settings, &ftok); } void analyzeIterators(TokenList &tokenlist, const Settings &settings) @@ -53,18 +53,18 @@ namespace ValueFlow continue; if (!astIsContainer(tok)) continue; - Token* ftok = nullptr; - const Library::Container::Yield yield = findIteratorYield(tok, const_cast(&ftok), settings); - if (ftok) { - Value v(0); - v.setKnown(); - if (yield == Library::Container::Yield::START_ITERATOR) { - v.valueType = Value::ValueType::ITERATOR_START; - setTokenValue(ftok->next(), std::move(v), settings); - } else if (yield == Library::Container::Yield::END_ITERATOR) { - v.valueType = Value::ValueType::ITERATOR_END; - setTokenValue(ftok->next(), std::move(v), settings); - } + const Token* ftok = nullptr; + const Library::Container::Yield yield = findIteratorYield(tok, ftok, settings); + if (!ftok) + continue; + Value v(0); + v.setKnown(); + if (yield == Library::Container::Yield::START_ITERATOR) { + v.valueType = Value::ValueType::ITERATOR_START; + setTokenValue(const_cast(ftok)->next(), std::move(v), settings); + } else if (yield == Library::Container::Yield::END_ITERATOR) { + v.valueType = Value::ValueType::ITERATOR_END; + setTokenValue(const_cast(ftok)->next(), std::move(v), settings); } } }