Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueFlow: some small cleanups #6737

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions lib/vf_iterators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -53,18 +53,18 @@ namespace ValueFlow
continue;
if (!astIsContainer(tok))
continue;
Token* ftok = nullptr;
const Library::Container::Yield yield = findIteratorYield(tok, const_cast<const Token**>(&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);
Copy link
Collaborator Author

@firewave firewave Aug 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The obvious partially unnecessary creation of the object will be addressed in a follow-up PR which contains more such cases in the split out ValueFlow code. I want to profile those changes in detail to see if it might have an impact and also wait until the remaining open refactoring has been merged.

v.setKnown();
if (yield == Library::Container::Yield::START_ITERATOR) {
v.valueType = Value::ValueType::ITERATOR_START;
setTokenValue(const_cast<Token*>(ftok)->next(), std::move(v), settings);
} else if (yield == Library::Container::Yield::END_ITERATOR) {
v.valueType = Value::ValueType::ITERATOR_END;
setTokenValue(const_cast<Token*>(ftok)->next(), std::move(v), settings);
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions lib/vf_settokenvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Loading