Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ Library::Container::Yield astContainerYield(const Token* tok, const Library& lib
return ftokCont.second->getYield(ftokCont.first->str());
}

Library::Container::Yield astFunctionYield(const Token* tok, const Settings& settings, const Token** ftok)
Library::Container::Yield astFunctionYield(const Token* tok, const Library& library, const Token** ftok)
{
if (!tok)
return Library::Container::Yield::NO_YIELD;

const auto* function = settings.library.getFunction(tok);
const auto* function = library.getFunction(tok);
if (!function)
return Library::Container::Yield::NO_YIELD;

Expand Down
2 changes: 1 addition & 1 deletion lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool astIsContainerString(const Token* tok);
Library::Container::Action astContainerAction(const Token* tok, const Library& library, const Token** ftok = nullptr);
Library::Container::Yield astContainerYield(const Token* tok, const Library& library, const Token** ftok = nullptr);

Library::Container::Yield astFunctionYield(const Token* tok, const Settings& settings, const Token** ftok = nullptr);
Library::Container::Yield astFunctionYield(const Token* tok, const Library& library, const Token** ftok = nullptr);

/** Is given token a range-declaration in a range-based for loop */
bool astIsRangeBasedForDecl(const Token* tok);
Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8048,7 +8048,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
continue;
}

const auto yield = astFunctionYield(tok->previous(), mSettings);
const auto yield = astFunctionYield(tok->previous(), mSettings.library);
if (yield == Library::Container::Yield::START_ITERATOR ||
yield == Library::Container::Yield::END_ITERATOR ||
yield == Library::Container::Yield::ITERATOR) {
Expand Down
22 changes: 11 additions & 11 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10332,23 +10332,23 @@ void Tokenizer::simplifyBitfields()
}
}

static bool isStdContainerOrIterator(const Token* tok, const Settings& settings)
static bool isStdContainerOrIterator(const Token* tok, const Library& library)
{
const Library::Container* ctr = settings.library.detectContainerOrIterator(tok, nullptr, /*withoutStd*/ true);
const Library::Container* ctr = library.detectContainerOrIterator(tok, nullptr, /*withoutStd*/ true);
return ctr && startsWith(ctr->startPattern, "std ::");
}

static bool isStdSmartPointer(const Token* tok, const Settings& settings)
static bool isStdSmartPointer(const Token* tok, const Library& library)
{
const Library::SmartPointer* ptr = settings.library.detectSmartPointer(tok, /*withoutStd*/ true);
const Library::SmartPointer* ptr = library.detectSmartPointer(tok, /*withoutStd*/ true);
return ptr && startsWith(ptr->name, "std::");
}

static bool isLibraryType(const Token* tok, const Settings& settings)
static bool isLibraryType(const Token* tok, const Library& library)
{
return settings.library.hasAnyTypeCheck("std::" + tok->str()) ||
settings.library.podtype("std::" + tok->str()) ||
isStdContainerOrIterator(tok, settings);
return library.hasAnyTypeCheck("std::" + tok->str()) ||
library.podtype("std::" + tok->str()) ||
isStdContainerOrIterator(tok, library);
}

// Add std:: in front of std classes, when using namespace std; was given
Expand Down Expand Up @@ -10379,12 +10379,12 @@ void Tokenizer::simplifyNamespaceStd()
userFunctions.insert(tok->str());
}
if ((userFunctions.find(tok->str()) == userFunctions.end() && mSettings.library.matchArguments(tok, "std::" + tok->str())) ||
(tok->tokAt(-1)->isKeyword() && isLibraryType(tok, mSettings)))
(tok->tokAt(-1)->isKeyword() && isLibraryType(tok, mSettings.library)))
insert = true;
} else if (Token::simpleMatch(tok->next(), "<") &&
(isStdContainerOrIterator(tok, mSettings) || isStdSmartPointer(tok, mSettings)))
(isStdContainerOrIterator(tok, mSettings.library) || isStdSmartPointer(tok, mSettings.library)))
insert = true;
else if (isLibraryType(tok, mSettings))
else if (isLibraryType(tok, mSettings.library))
insert = true;
else if (Token::simpleMatch(tok, "aligned_storage"))
insert = true;
Expand Down
18 changes: 9 additions & 9 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ const Token *ValueFlow::parseCompareInt(const Token *tok, ValueFlow::Value &true
});
}

static bool isEscapeScope(const Token* tok, const Settings& settings, bool unknown = false)
static bool isEscapeScope(const Token* tok, const Library& library, bool unknown = false)
{
if (!Token::simpleMatch(tok, "{"))
return false;
Expand All @@ -374,7 +374,7 @@ static bool isEscapeScope(const Token* tok, const Settings& settings, bool unkno
if (termTok && termTok->scope() == tok->scope())
return true;
std::string unknownFunction;
if (settings.library.isScopeNoReturn(tok->link(), &unknownFunction))
if (library.isScopeNoReturn(tok->link(), &unknownFunction))
return unknownFunction.empty() || unknown;
return false;
}
Expand Down Expand Up @@ -3044,7 +3044,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger &errorLogger, co
// Skip if its a free function that doesnt yield an iterator to the container
if (Token::Match(parent->previous(), "%name% (") &&
!contains({Library::Container::Yield::START_ITERATOR, Library::Container::Yield::END_ITERATOR},
astFunctionYield(parent->previous(), settings)))
astFunctionYield(parent->previous(), settings.library)))
continue;

ValueFlow::Value master;
Expand All @@ -3056,7 +3056,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger &errorLogger, co
master.lifetimeKind = ValueFlow::Value::LifetimeKind::Iterator;
} else if (astIsIterator(parent) && Token::Match(parent->previous(), "%name% (") &&
contains({Library::Container::Yield::START_ITERATOR, Library::Container::Yield::END_ITERATOR},
astFunctionYield(parent->previous(), settings))) {
astFunctionYield(parent->previous(), settings.library))) {
master.errorPath.emplace_back(parent, "Iterator to container is created here.");
master.lifetimeKind = ValueFlow::Value::LifetimeKind::Iterator;
} else if ((astIsPointer(parent->tokAt(2)) &&
Expand Down Expand Up @@ -3479,7 +3479,7 @@ static void valueFlowConditionExpressions(const TokenList& tokenlist,
}

// Check if the block terminates early
if (isEscapeScope(blockTok, settings)) {
if (isEscapeScope(blockTok, settings.library)) {
const Scope* scope2 = scope;
// If escaping a loop then only use the loop scope
if (isBreakOrContinueScope(blockTok->link())) {
Expand Down Expand Up @@ -6339,17 +6339,17 @@ static void valueFlowSmartPointer(TokenList &tokenlist, ErrorLogger & errorLogge
}
}

static Library::Container::Yield findIteratorYield(Token* tok, const Token*& ftok, const Settings& settings)
static Library::Container::Yield findIteratorYield(Token* tok, const Token*& ftok, const Library& library)
{
auto yield = astContainerYield(tok, settings.library, &ftok);
auto yield = astContainerYield(tok, library, &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(), library, &ftok);
}

static void valueFlowIterators(TokenList& tokenlist, const Settings& settings)
Expand All @@ -6362,7 +6362,7 @@ static void valueFlowIterators(TokenList& tokenlist, const Settings& settings)
if (!astIsContainer(tok))
continue;
const Token* ftok = nullptr;
const Library::Container::Yield yield = findIteratorYield(tok, ftok, settings);
const Library::Container::Yield yield = findIteratorYield(tok, ftok, settings.library);
if (!ftok)
continue;
if (yield == Library::Container::Yield::START_ITERATOR) {
Expand Down
12 changes: 6 additions & 6 deletions lib/vf_settokenvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

namespace ValueFlow
{
static Library::Container::Yield getContainerYield(Token* tok, const Settings& settings, Token*& parent)
static Library::Container::Yield getContainerYield(Token* tok, const Library& library, Token*& parent)
{
if (Token::Match(tok, ". %name% (") && tok->astParent() == tok->tokAt(2) && tok->astOperand1() &&
tok->astOperand1()->valueType()) {
Expand All @@ -57,7 +57,7 @@ namespace ValueFlow
}
if (Token::Match(tok->previous(), "%name% (")) {
parent = tok;
if (const Library::Function* f = settings.library.getFunction(tok->previous())) {
if (const Library::Function* f = library.getFunction(tok->previous())) {
return f->containerYield;
}
}
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace ValueFlow
return v;
}

static const Token *getCastTypeStartToken(const Token *parent, const Settings& settings)
static const Token *getCastTypeStartToken(const Token *parent, const Library& library)
{
// TODO: This might be a generic utility function?
if (!Token::Match(parent, "{|("))
Expand All @@ -114,7 +114,7 @@ namespace ValueFlow
ftok = ftok->next();
while (Token::Match(ftok, "%name% ::"))
ftok = ftok->tokAt(2);
if (settings.library.isNotLibraryFunction(ftok))
if (library.isNotLibraryFunction(ftok))
return parent->next();
}
if (parent->astOperand2() && Token::Match(parent->astOperand1(), "const_cast|dynamic_cast|reinterpret_cast|static_cast <"))
Expand Down Expand Up @@ -301,7 +301,7 @@ namespace ValueFlow
}
}
Token* next = nullptr;
const Library::Container::Yield yields = getContainerYield(parent, settings, next);
const Library::Container::Yield yields = getContainerYield(parent, settings.library, next);
if (yields == Library::Container::Yield::SIZE) {
value.valueType = Value::ValueType::INT;
setTokenValue(next, std::move(value), settings);
Expand Down Expand Up @@ -371,7 +371,7 @@ namespace ValueFlow
}

// cast..
if (const Token *castType = getCastTypeStartToken(parent, settings)) {
if (const Token *castType = getCastTypeStartToken(parent, settings.library)) {
if (contains({Value::ValueType::INT, Value::ValueType::SYMBOLIC}, value.valueType) &&
Token::simpleMatch(parent->astOperand1(), "dynamic_cast"))
return;
Expand Down
Loading