Skip to content

Commit 5e1db12

Browse files
authored
ValueFlow: some small cleanups (danmar#6737)
1 parent 94e9a72 commit 5e1db12

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

lib/vf_iterators.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131

3232
namespace ValueFlow
3333
{
34-
static Library::Container::Yield findIteratorYield(Token* tok, const Token** ftok, const Settings &settings)
34+
static Library::Container::Yield findIteratorYield(Token* tok, const Token*& ftok, const Settings &settings)
3535
{
36-
auto yield = astContainerYield(tok, ftok);
37-
if (ftok && *ftok)
36+
auto yield = astContainerYield(tok, &ftok);
37+
if (ftok)
3838
return yield;
3939

4040
if (!tok->astParent())
4141
return yield;
4242

4343
//begin/end free functions
44-
return astFunctionYield(tok->astParent()->previous(), settings, ftok);
44+
return astFunctionYield(tok->astParent()->previous(), settings, &ftok);
4545
}
4646

4747
void analyzeIterators(TokenList &tokenlist, const Settings &settings)
@@ -53,18 +53,18 @@ namespace ValueFlow
5353
continue;
5454
if (!astIsContainer(tok))
5555
continue;
56-
Token* ftok = nullptr;
57-
const Library::Container::Yield yield = findIteratorYield(tok, const_cast<const Token**>(&ftok), settings);
58-
if (ftok) {
59-
Value v(0);
60-
v.setKnown();
61-
if (yield == Library::Container::Yield::START_ITERATOR) {
62-
v.valueType = Value::ValueType::ITERATOR_START;
63-
setTokenValue(ftok->next(), std::move(v), settings);
64-
} else if (yield == Library::Container::Yield::END_ITERATOR) {
65-
v.valueType = Value::ValueType::ITERATOR_END;
66-
setTokenValue(ftok->next(), std::move(v), settings);
67-
}
56+
const Token* ftok = nullptr;
57+
const Library::Container::Yield yield = findIteratorYield(tok, ftok, settings);
58+
if (!ftok)
59+
continue;
60+
Value v(0);
61+
v.setKnown();
62+
if (yield == Library::Container::Yield::START_ITERATOR) {
63+
v.valueType = Value::ValueType::ITERATOR_START;
64+
setTokenValue(const_cast<Token*>(ftok)->next(), std::move(v), settings);
65+
} else if (yield == Library::Container::Yield::END_ITERATOR) {
66+
v.valueType = Value::ValueType::ITERATOR_END;
67+
setTokenValue(const_cast<Token*>(ftok)->next(), std::move(v), settings);
6868
}
6969
}
7070
}

lib/vf_settokenvalue.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@
4646

4747
namespace ValueFlow
4848
{
49-
static Library::Container::Yield getContainerYield(Token* tok, const Settings& settings, Token** parent = nullptr)
49+
static Library::Container::Yield getContainerYield(Token* tok, const Settings& settings, Token*& parent)
5050
{
5151
if (Token::Match(tok, ". %name% (") && tok->astParent() == tok->tokAt(2) && tok->astOperand1() &&
5252
tok->astOperand1()->valueType()) {
5353
const Library::Container* c = getLibraryContainer(tok->astOperand1());
54-
if (parent)
55-
*parent = tok->astParent();
54+
parent = tok->astParent();
5655
return c ? c->getYield(tok->strAt(1)) : Library::Container::Yield::NO_YIELD;
5756
}
5857
if (Token::Match(tok->previous(), "%name% (")) {
59-
if (parent)
60-
*parent = tok;
58+
parent = tok;
6159
if (const Library::Function* f = settings.library.getFunction(tok->previous())) {
6260
return f->containerYield;
6361
}
@@ -302,7 +300,7 @@ namespace ValueFlow
302300
}
303301
}
304302
Token* next = nullptr;
305-
const Library::Container::Yield yields = getContainerYield(parent, settings, &next);
303+
const Library::Container::Yield yields = getContainerYield(parent, settings, next);
306304
if (yields == Library::Container::Yield::SIZE) {
307305
Value v(value);
308306
v.valueType = Value::ValueType::INT;

0 commit comments

Comments
 (0)