Skip to content

Commit ed8b09d

Browse files
committed
pass Library instead of Settings
1 parent aec1a7f commit ed8b09d

6 files changed

Lines changed: 30 additions & 30 deletions

File tree

lib/astutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ Library::Container::Yield astContainerYield(const Token* tok, const Library& lib
320320
return ftokCont.second->getYield(ftokCont.first->str());
321321
}
322322

323-
Library::Container::Yield astFunctionYield(const Token* tok, const Settings& settings, const Token** ftok)
323+
Library::Container::Yield astFunctionYield(const Token* tok, const Library& library, const Token** ftok)
324324
{
325325
if (!tok)
326326
return Library::Container::Yield::NO_YIELD;
327327

328-
const auto* function = settings.library.getFunction(tok);
328+
const auto* function = library.getFunction(tok);
329329
if (!function)
330330
return Library::Container::Yield::NO_YIELD;
331331

lib/astutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool astIsContainerString(const Token* tok);
166166
Library::Container::Action astContainerAction(const Token* tok, const Library& library, const Token** ftok = nullptr);
167167
Library::Container::Yield astContainerYield(const Token* tok, const Library& library, const Token** ftok = nullptr);
168168

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

171171
/** Is given token a range-declaration in a range-based for loop */
172172
bool astIsRangeBasedForDecl(const Token* tok);

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8048,7 +8048,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
80488048
continue;
80498049
}
80508050

8051-
const auto yield = astFunctionYield(tok->previous(), mSettings);
8051+
const auto yield = astFunctionYield(tok->previous(), mSettings.library);
80528052
if (yield == Library::Container::Yield::START_ITERATOR ||
80538053
yield == Library::Container::Yield::END_ITERATOR ||
80548054
yield == Library::Container::Yield::ITERATOR) {

lib/tokenize.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10332,23 +10332,23 @@ void Tokenizer::simplifyBitfields()
1033210332
}
1033310333
}
1033410334

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

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

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

1035410354
// Add std:: in front of std classes, when using namespace std; was given
@@ -10379,12 +10379,12 @@ void Tokenizer::simplifyNamespaceStd()
1037910379
userFunctions.insert(tok->str());
1038010380
}
1038110381
if ((userFunctions.find(tok->str()) == userFunctions.end() && mSettings.library.matchArguments(tok, "std::" + tok->str())) ||
10382-
(tok->tokAt(-1)->isKeyword() && isLibraryType(tok, mSettings)))
10382+
(tok->tokAt(-1)->isKeyword() && isLibraryType(tok, mSettings.library)))
1038310383
insert = true;
1038410384
} else if (Token::simpleMatch(tok->next(), "<") &&
10385-
(isStdContainerOrIterator(tok, mSettings) || isStdSmartPointer(tok, mSettings)))
10385+
(isStdContainerOrIterator(tok, mSettings.library) || isStdSmartPointer(tok, mSettings.library)))
1038610386
insert = true;
10387-
else if (isLibraryType(tok, mSettings))
10387+
else if (isLibraryType(tok, mSettings.library))
1038810388
insert = true;
1038910389
else if (Token::simpleMatch(tok, "aligned_storage"))
1039010390
insert = true;

lib/valueflow.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ const Token *ValueFlow::parseCompareInt(const Token *tok, ValueFlow::Value &true
365365
});
366366
}
367367

368-
static bool isEscapeScope(const Token* tok, const Settings& settings, bool unknown = false)
368+
static bool isEscapeScope(const Token* tok, const Library& library, bool unknown = false)
369369
{
370370
if (!Token::simpleMatch(tok, "{"))
371371
return false;
@@ -374,7 +374,7 @@ static bool isEscapeScope(const Token* tok, const Settings& settings, bool unkno
374374
if (termTok && termTok->scope() == tok->scope())
375375
return true;
376376
std::string unknownFunction;
377-
if (settings.library.isScopeNoReturn(tok->link(), &unknownFunction))
377+
if (library.isScopeNoReturn(tok->link(), &unknownFunction))
378378
return unknownFunction.empty() || unknown;
379379
return false;
380380
}
@@ -3044,7 +3044,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger &errorLogger, co
30443044
// Skip if its a free function that doesnt yield an iterator to the container
30453045
if (Token::Match(parent->previous(), "%name% (") &&
30463046
!contains({Library::Container::Yield::START_ITERATOR, Library::Container::Yield::END_ITERATOR},
3047-
astFunctionYield(parent->previous(), settings)))
3047+
astFunctionYield(parent->previous(), settings.library)))
30483048
continue;
30493049

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

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

6342-
static Library::Container::Yield findIteratorYield(Token* tok, const Token*& ftok, const Settings& settings)
6342+
static Library::Container::Yield findIteratorYield(Token* tok, const Token*& ftok, const Library& library)
63436343
{
6344-
auto yield = astContainerYield(tok, settings.library, &ftok);
6344+
auto yield = astContainerYield(tok, library, &ftok);
63456345
if (ftok)
63466346
return yield;
63476347

63486348
if (!tok->astParent())
63496349
return yield;
63506350

63516351
// begin/end free functions
6352-
return astFunctionYield(tok->astParent()->previous(), settings, &ftok);
6352+
return astFunctionYield(tok->astParent()->previous(), library, &ftok);
63536353
}
63546354

63556355
static void valueFlowIterators(TokenList& tokenlist, const Settings& settings)
@@ -6362,7 +6362,7 @@ static void valueFlowIterators(TokenList& tokenlist, const Settings& settings)
63626362
if (!astIsContainer(tok))
63636363
continue;
63646364
const Token* ftok = nullptr;
6365-
const Library::Container::Yield yield = findIteratorYield(tok, ftok, settings);
6365+
const Library::Container::Yield yield = findIteratorYield(tok, ftok, settings.library);
63666366
if (!ftok)
63676367
continue;
63686368
if (yield == Library::Container::Yield::START_ITERATOR) {

lib/vf_settokenvalue.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
namespace ValueFlow
4949
{
50-
static Library::Container::Yield getContainerYield(Token* tok, const Settings& settings, Token*& parent)
50+
static Library::Container::Yield getContainerYield(Token* tok, const Library& library, Token*& parent)
5151
{
5252
if (Token::Match(tok, ". %name% (") && tok->astParent() == tok->tokAt(2) && tok->astOperand1() &&
5353
tok->astOperand1()->valueType()) {
@@ -57,7 +57,7 @@ namespace ValueFlow
5757
}
5858
if (Token::Match(tok->previous(), "%name% (")) {
5959
parent = tok;
60-
if (const Library::Function* f = settings.library.getFunction(tok->previous())) {
60+
if (const Library::Function* f = library.getFunction(tok->previous())) {
6161
return f->containerYield;
6262
}
6363
}
@@ -95,7 +95,7 @@ namespace ValueFlow
9595
return v;
9696
}
9797

98-
static const Token *getCastTypeStartToken(const Token *parent, const Settings& settings)
98+
static const Token *getCastTypeStartToken(const Token *parent, const Library& library)
9999
{
100100
// TODO: This might be a generic utility function?
101101
if (!Token::Match(parent, "{|("))
@@ -114,7 +114,7 @@ namespace ValueFlow
114114
ftok = ftok->next();
115115
while (Token::Match(ftok, "%name% ::"))
116116
ftok = ftok->tokAt(2);
117-
if (settings.library.isNotLibraryFunction(ftok))
117+
if (library.isNotLibraryFunction(ftok))
118118
return parent->next();
119119
}
120120
if (parent->astOperand2() && Token::Match(parent->astOperand1(), "const_cast|dynamic_cast|reinterpret_cast|static_cast <"))
@@ -301,7 +301,7 @@ namespace ValueFlow
301301
}
302302
}
303303
Token* next = nullptr;
304-
const Library::Container::Yield yields = getContainerYield(parent, settings, next);
304+
const Library::Container::Yield yields = getContainerYield(parent, settings.library, next);
305305
if (yields == Library::Container::Yield::SIZE) {
306306
value.valueType = Value::ValueType::INT;
307307
setTokenValue(next, std::move(value), settings);
@@ -371,7 +371,7 @@ namespace ValueFlow
371371
}
372372

373373
// cast..
374-
if (const Token *castType = getCastTypeStartToken(parent, settings)) {
374+
if (const Token *castType = getCastTypeStartToken(parent, settings.library)) {
375375
if (contains({Value::ValueType::INT, Value::ValueType::SYMBOLIC}, value.valueType) &&
376376
Token::simpleMatch(parent->astOperand1(), "dynamic_cast"))
377377
return;

0 commit comments

Comments
 (0)