ValueFlow: pass `SymbolDatabase` by reference into `ValueFlow::setValues()` (#5295)
This commit is contained in:
parent
a17f6e89d1
commit
e38a031ae6
|
@ -545,7 +545,7 @@ unsigned int CppCheck::check(const std::string &path)
|
||||||
tokenizer.list.appendFileIfNew(path);
|
tokenizer.list.appendFileIfNew(path);
|
||||||
clangimport::parseClangAstDump(&tokenizer, ast);
|
clangimport::parseClangAstDump(&tokenizer, ast);
|
||||||
ValueFlow::setValues(tokenizer.list,
|
ValueFlow::setValues(tokenizer.list,
|
||||||
const_cast<SymbolDatabase*>(tokenizer.getSymbolDatabase()),
|
const_cast<SymbolDatabase&>(*tokenizer.getSymbolDatabase()),
|
||||||
this,
|
this,
|
||||||
&mSettings,
|
&mSettings,
|
||||||
&s_timerResults);
|
&s_timerResults);
|
||||||
|
|
|
@ -3361,9 +3361,9 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
|
||||||
if (doValueFlow) {
|
if (doValueFlow) {
|
||||||
if (mTimerResults) {
|
if (mTimerResults) {
|
||||||
Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings->showtime, mTimerResults);
|
Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings->showtime, mTimerResults);
|
||||||
ValueFlow::setValues(list, mSymbolDatabase, mErrorLogger, mSettings, mTimerResults);
|
ValueFlow::setValues(list, *mSymbolDatabase, mErrorLogger, mSettings, mTimerResults);
|
||||||
} else {
|
} else {
|
||||||
ValueFlow::setValues(list, mSymbolDatabase, mErrorLogger, mSettings, mTimerResults);
|
ValueFlow::setValues(list, *mSymbolDatabase, mErrorLogger, mSettings, mTimerResults);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1925,10 +1925,9 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings* sett
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowEnumValue(SymbolDatabase * symboldatabase, const Settings * settings)
|
static void valueFlowEnumValue(SymbolDatabase & symboldatabase, const Settings * settings)
|
||||||
{
|
{
|
||||||
|
for (Scope & scope : symboldatabase.scopeList) {
|
||||||
for (Scope & scope : symboldatabase->scopeList) {
|
|
||||||
if (scope.type != Scope::eEnum)
|
if (scope.type != Scope::eEnum)
|
||||||
continue;
|
continue;
|
||||||
MathLib::bigint value = 0;
|
MathLib::bigint value = 0;
|
||||||
|
@ -4745,7 +4744,7 @@ static bool isContainerOfPointers(const Token* tok, const Settings* settings)
|
||||||
return vt.pointer > 0;
|
return vt.pointer > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowLifetime(TokenList &tokenlist, SymbolDatabase* /*db*/, ErrorLogger *errorLogger, const Settings *settings)
|
static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
|
for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
|
||||||
if (!tok->scope())
|
if (!tok->scope())
|
||||||
|
@ -5076,11 +5075,11 @@ static const Token * findEndOfFunctionCallForParameter(const Token * parameterTo
|
||||||
return nextAfterAstRightmostLeaf(parent);
|
return nextAfterAstRightmostLeaf(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowAfterMove(TokenList& tokenlist, const SymbolDatabase* symboldatabase, const Settings* settings)
|
static void valueFlowAfterMove(TokenList& tokenlist, const SymbolDatabase& symboldatabase, const Settings* settings)
|
||||||
{
|
{
|
||||||
if (!tokenlist.isCPP() || settings->standards.cpp < Standards::CPP11)
|
if (!tokenlist.isCPP() || settings->standards.cpp < Standards::CPP11)
|
||||||
return;
|
return;
|
||||||
for (const Scope * scope : symboldatabase->functionScopes) {
|
for (const Scope * scope : symboldatabase.functionScopes) {
|
||||||
if (!scope)
|
if (!scope)
|
||||||
continue;
|
continue;
|
||||||
const Token * start = scope->bodyStart;
|
const Token * start = scope->bodyStart;
|
||||||
|
@ -5215,9 +5214,9 @@ static const Scope* getLoopScope(const Token* tok)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
static void valueFlowConditionExpressions(TokenList &tokenlist, const SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings &settings)
|
static void valueFlowConditionExpressions(TokenList &tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger *errorLogger, const Settings &settings)
|
||||||
{
|
{
|
||||||
for (const Scope * scope : symboldatabase->functionScopes) {
|
for (const Scope * scope : symboldatabase.functionScopes) {
|
||||||
if (const Token* incompleteTok = findIncompleteVar(scope->bodyStart, scope->bodyEnd)) {
|
if (const Token* incompleteTok = findIncompleteVar(scope->bodyStart, scope->bodyEnd)) {
|
||||||
if (incompleteTok->isIncompleteVar()) {
|
if (incompleteTok->isIncompleteVar()) {
|
||||||
if (settings.debugwarnings)
|
if (settings.debugwarnings)
|
||||||
|
@ -5345,9 +5344,9 @@ static std::set<nonneg int> getVarIds(const Token* tok)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase* symboldatabase, const Settings* settings)
|
static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase& symboldatabase, const Settings* settings)
|
||||||
{
|
{
|
||||||
for (const Scope* scope : symboldatabase->functionScopes) {
|
for (const Scope* scope : symboldatabase.functionScopes) {
|
||||||
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (!Token::simpleMatch(tok, "="))
|
if (!Token::simpleMatch(tok, "="))
|
||||||
continue;
|
continue;
|
||||||
|
@ -5438,9 +5437,9 @@ static const Token* isStrlenOf(const Token* tok, const Token* expr, int depth =
|
||||||
|
|
||||||
static ValueFlow::Value inferCondition(const std::string& op, const Token* varTok, MathLib::bigint val);
|
static ValueFlow::Value inferCondition(const std::string& op, const Token* varTok, MathLib::bigint val);
|
||||||
|
|
||||||
static void valueFlowSymbolicOperators(const SymbolDatabase* symboldatabase, const Settings* settings)
|
static void valueFlowSymbolicOperators(const SymbolDatabase& symboldatabase, const Settings* settings)
|
||||||
{
|
{
|
||||||
for (const Scope* scope : symboldatabase->functionScopes) {
|
for (const Scope* scope : symboldatabase.functionScopes) {
|
||||||
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (tok->hasKnownIntValue())
|
if (tok->hasKnownIntValue())
|
||||||
continue;
|
continue;
|
||||||
|
@ -5549,9 +5548,9 @@ struct SymbolicInferModel : InferModel {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void valueFlowSymbolicInfer(const SymbolDatabase* symboldatabase, const Settings* settings)
|
static void valueFlowSymbolicInfer(const SymbolDatabase& symboldatabase, const Settings* settings)
|
||||||
{
|
{
|
||||||
for (const Scope* scope : symboldatabase->functionScopes) {
|
for (const Scope* scope : symboldatabase.functionScopes) {
|
||||||
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (!Token::Match(tok, "-|%comp%"))
|
if (!Token::Match(tok, "-|%comp%"))
|
||||||
continue;
|
continue;
|
||||||
|
@ -5829,12 +5828,12 @@ static bool intersects(const C1& c1, const C2& c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowAfterAssign(TokenList &tokenlist,
|
static void valueFlowAfterAssign(TokenList &tokenlist,
|
||||||
const SymbolDatabase* symboldatabase,
|
const SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger *errorLogger,
|
ErrorLogger *errorLogger,
|
||||||
const Settings *settings,
|
const Settings *settings,
|
||||||
const std::set<const Scope*>& skippedFunctions)
|
const std::set<const Scope*>& skippedFunctions)
|
||||||
{
|
{
|
||||||
for (const Scope * scope : symboldatabase->functionScopes) {
|
for (const Scope * scope : symboldatabase.functionScopes) {
|
||||||
if (skippedFunctions.count(scope))
|
if (skippedFunctions.count(scope))
|
||||||
continue;
|
continue;
|
||||||
std::unordered_map<nonneg int, std::unordered_set<nonneg int>> backAssigns;
|
std::unordered_map<nonneg int, std::unordered_set<nonneg int>> backAssigns;
|
||||||
|
@ -5966,11 +5965,11 @@ static std::vector<const Variable*> getVariables(const Token* tok)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowAfterSwap(TokenList& tokenlist,
|
static void valueFlowAfterSwap(TokenList& tokenlist,
|
||||||
const SymbolDatabase* symboldatabase,
|
const SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger* errorLogger,
|
ErrorLogger* errorLogger,
|
||||||
const Settings* settings)
|
const Settings* settings)
|
||||||
{
|
{
|
||||||
for (const Scope* scope : symboldatabase->functionScopes) {
|
for (const Scope* scope : symboldatabase.functionScopes) {
|
||||||
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (!Token::simpleMatch(tok, "swap ("))
|
if (!Token::simpleMatch(tok, "swap ("))
|
||||||
continue;
|
continue;
|
||||||
|
@ -6140,12 +6139,12 @@ struct ConditionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
void traverseCondition(const TokenList& tokenlist,
|
void traverseCondition(const TokenList& tokenlist,
|
||||||
const SymbolDatabase* symboldatabase,
|
const SymbolDatabase& symboldatabase,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
const std::set<const Scope*>& skippedFunctions,
|
const std::set<const Scope*>& skippedFunctions,
|
||||||
const std::function<void(const Condition& cond, Token* tok, const Scope* scope)>& f) const
|
const std::function<void(const Condition& cond, Token* tok, const Scope* scope)>& f) const
|
||||||
{
|
{
|
||||||
for (const Scope *scope : symboldatabase->functionScopes) {
|
for (const Scope *scope : symboldatabase.functionScopes) {
|
||||||
if (skippedFunctions.count(scope))
|
if (skippedFunctions.count(scope))
|
||||||
continue;
|
continue;
|
||||||
for (Token *tok = const_cast<Token *>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
for (Token *tok = const_cast<Token *>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
|
@ -6178,7 +6177,7 @@ struct ConditionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
void beforeCondition(TokenList& tokenlist,
|
void beforeCondition(TokenList& tokenlist,
|
||||||
const SymbolDatabase* symboldatabase,
|
const SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger* errorLogger,
|
ErrorLogger* errorLogger,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
const std::set<const Scope*>& skippedFunctions) const {
|
const std::set<const Scope*>& skippedFunctions) const {
|
||||||
|
@ -6326,7 +6325,7 @@ struct ConditionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
void afterCondition(TokenList& tokenlist,
|
void afterCondition(TokenList& tokenlist,
|
||||||
const SymbolDatabase* symboldatabase,
|
const SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger* errorLogger,
|
ErrorLogger* errorLogger,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
const std::set<const Scope*>& skippedFunctions) const {
|
const std::set<const Scope*>& skippedFunctions) const {
|
||||||
|
@ -6659,7 +6658,7 @@ protected:
|
||||||
|
|
||||||
static void valueFlowCondition(const ValuePtr<ConditionHandler>& handler,
|
static void valueFlowCondition(const ValuePtr<ConditionHandler>& handler,
|
||||||
TokenList& tokenlist,
|
TokenList& tokenlist,
|
||||||
SymbolDatabase* symboldatabase,
|
SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger* errorLogger,
|
ErrorLogger* errorLogger,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
const std::set<const Scope*>& skippedFunctions)
|
const std::set<const Scope*>& skippedFunctions)
|
||||||
|
@ -7082,9 +7081,9 @@ static void valueFlowForLoopSimplifyAfter(Token* fortok, nonneg int varid, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowForLoop(TokenList &tokenlist, const SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings)
|
static void valueFlowForLoop(TokenList &tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
for (const Scope &scope : symboldatabase->scopeList) {
|
for (const Scope &scope : symboldatabase.scopeList) {
|
||||||
if (scope.type != Scope::eFor)
|
if (scope.type != Scope::eFor)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -7158,10 +7157,9 @@ static void valueFlowForLoop(TokenList &tokenlist, const SymbolDatabase* symbold
|
||||||
struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
|
struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
|
||||||
std::unordered_map<nonneg int, ValueFlow::Value> values;
|
std::unordered_map<nonneg int, ValueFlow::Value> values;
|
||||||
std::unordered_map<nonneg int, const Variable*> vars;
|
std::unordered_map<nonneg int, const Variable*> vars;
|
||||||
SymbolDatabase* symboldatabase;
|
|
||||||
|
|
||||||
MultiValueFlowAnalyzer(const std::unordered_map<const Variable*, ValueFlow::Value>& args, const TokenList& t, const Settings* set, SymbolDatabase* s)
|
MultiValueFlowAnalyzer(const std::unordered_map<const Variable*, ValueFlow::Value>& args, const TokenList& t, const Settings* set)
|
||||||
: ValueFlowAnalyzer(t, set), values(), vars(), symboldatabase(s) {
|
: ValueFlowAnalyzer(t, set), values(), vars() {
|
||||||
for (const auto& p:args) {
|
for (const auto& p:args) {
|
||||||
values[p.first->declarationId()] = p.second;
|
values[p.first->declarationId()] = p.second;
|
||||||
vars[p.first->declarationId()] = p.first;
|
vars[p.first->declarationId()] = p.first;
|
||||||
|
@ -7357,14 +7355,13 @@ bool productParams(const Settings* settings, const std::unordered_map<Key, std::
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowInjectParameter(TokenList& tokenlist,
|
static void valueFlowInjectParameter(TokenList& tokenlist,
|
||||||
SymbolDatabase* symboldatabase,
|
|
||||||
ErrorLogger* errorLogger,
|
ErrorLogger* errorLogger,
|
||||||
const Settings& settings,
|
const Settings& settings,
|
||||||
const Scope* functionScope,
|
const Scope* functionScope,
|
||||||
const std::unordered_map<const Variable*, std::list<ValueFlow::Value>>& vars)
|
const std::unordered_map<const Variable*, std::list<ValueFlow::Value>>& vars)
|
||||||
{
|
{
|
||||||
const bool r = productParams(&settings, vars, [&](const std::unordered_map<const Variable*, ValueFlow::Value>& arg) {
|
const bool r = productParams(&settings, vars, [&](const std::unordered_map<const Variable*, ValueFlow::Value>& arg) {
|
||||||
MultiValueFlowAnalyzer a(arg, tokenlist, &settings, symboldatabase);
|
MultiValueFlowAnalyzer a(arg, tokenlist, &settings);
|
||||||
valueFlowGenericForward(const_cast<Token*>(functionScope->bodyStart), functionScope->bodyEnd, a, settings);
|
valueFlowGenericForward(const_cast<Token*>(functionScope->bodyStart), functionScope->bodyEnd, a, settings);
|
||||||
});
|
});
|
||||||
if (!r) {
|
if (!r) {
|
||||||
|
@ -7399,9 +7396,9 @@ static void valueFlowInjectParameter(const TokenList& tokenlist,
|
||||||
settings);
|
settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowSwitchVariable(TokenList &tokenlist, const SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings)
|
static void valueFlowSwitchVariable(TokenList &tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
for (const Scope &scope : symboldatabase->scopeList) {
|
for (const Scope &scope : symboldatabase.scopeList) {
|
||||||
if (scope.type != Scope::ScopeType::eSwitch)
|
if (scope.type != Scope::ScopeType::eSwitch)
|
||||||
continue;
|
continue;
|
||||||
if (!Token::Match(scope.classDef, "switch ( %var% ) {"))
|
if (!Token::Match(scope.classDef, "switch ( %var% ) {"))
|
||||||
|
@ -7535,10 +7532,10 @@ IteratorRange<Iterator> MakeIteratorRange(Iterator start, Iterator last)
|
||||||
return {start, last};
|
return {start, last};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowSubFunction(TokenList& tokenlist, SymbolDatabase* symboldatabase, ErrorLogger* errorLogger, const Settings& settings)
|
static void valueFlowSubFunction(TokenList& tokenlist, SymbolDatabase& symboldatabase, ErrorLogger* errorLogger, const Settings& settings)
|
||||||
{
|
{
|
||||||
int id = 0;
|
int id = 0;
|
||||||
for (const Scope* scope : MakeIteratorRange(symboldatabase->functionScopes.crbegin(), symboldatabase->functionScopes.crend())) {
|
for (const Scope* scope : MakeIteratorRange(symboldatabase.functionScopes.crbegin(), symboldatabase.functionScopes.crend())) {
|
||||||
const Function* function = scope->function;
|
const Function* function = scope->function;
|
||||||
if (!function)
|
if (!function)
|
||||||
continue;
|
continue;
|
||||||
|
@ -7612,17 +7609,17 @@ static void valueFlowSubFunction(TokenList& tokenlist, SymbolDatabase* symboldat
|
||||||
|
|
||||||
argvars[argvar] = argvalues;
|
argvars[argvar] = argvalues;
|
||||||
}
|
}
|
||||||
valueFlowInjectParameter(tokenlist, symboldatabase, errorLogger, settings, calledFunctionScope, argvars);
|
valueFlowInjectParameter(tokenlist, errorLogger, settings, calledFunctionScope, argvars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowFunctionDefaultParameter(const TokenList& tokenlist, const SymbolDatabase* symboldatabase, const Settings* settings)
|
static void valueFlowFunctionDefaultParameter(const TokenList& tokenlist, const SymbolDatabase& symboldatabase, const Settings* settings)
|
||||||
{
|
{
|
||||||
if (!tokenlist.isCPP())
|
if (!tokenlist.isCPP())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (const Scope* scope : symboldatabase->functionScopes) {
|
for (const Scope* scope : symboldatabase.functionScopes) {
|
||||||
const Function* function = scope->function;
|
const Function* function = scope->function;
|
||||||
if (!function)
|
if (!function)
|
||||||
continue;
|
continue;
|
||||||
|
@ -7947,7 +7944,7 @@ static Token* findStartToken(const Variable* var, Token* start, const Library* l
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowUninit(TokenList& tokenlist, SymbolDatabase* /*symbolDatabase*/, const Settings* settings)
|
static void valueFlowUninit(TokenList& tokenlist, const Settings* settings)
|
||||||
{
|
{
|
||||||
for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
|
for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
|
||||||
if (!tok->scope()->isExecutable())
|
if (!tok->scope()->isExecutable())
|
||||||
|
@ -8677,13 +8674,13 @@ static const Scope* getFunctionScope(const Scope* scope) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowContainerSize(TokenList& tokenlist,
|
static void valueFlowContainerSize(TokenList& tokenlist,
|
||||||
const SymbolDatabase* symboldatabase,
|
const SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger* /*errorLogger*/,
|
ErrorLogger* /*errorLogger*/,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
const std::set<const Scope*>& skippedFunctions)
|
const std::set<const Scope*>& skippedFunctions)
|
||||||
{
|
{
|
||||||
// declaration
|
// declaration
|
||||||
for (const Variable *var : symboldatabase->variableList()) {
|
for (const Variable *var : symboldatabase.variableList()) {
|
||||||
if (!var)
|
if (!var)
|
||||||
continue;
|
continue;
|
||||||
if (!var->scope() || !var->scope()->bodyEnd || !var->scope()->bodyStart)
|
if (!var->scope() || !var->scope()->bodyEnd || !var->scope()->bodyStart)
|
||||||
|
@ -8754,7 +8751,7 @@ static void valueFlowContainerSize(TokenList& tokenlist,
|
||||||
}
|
}
|
||||||
|
|
||||||
// after assignment
|
// after assignment
|
||||||
for (const Scope *functionScope : symboldatabase->functionScopes) {
|
for (const Scope *functionScope : symboldatabase.functionScopes) {
|
||||||
for (Token* tok = const_cast<Token*>(functionScope->bodyStart); tok != functionScope->bodyEnd; tok = tok->next()) {
|
for (Token* tok = const_cast<Token*>(functionScope->bodyStart); tok != functionScope->bodyEnd; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "%name%|;|{|} %var% = %str% ;")) {
|
if (Token::Match(tok, "%name%|;|{|} %var% = %str% ;")) {
|
||||||
Token* containerTok = tok->next();
|
Token* containerTok = tok->next();
|
||||||
|
@ -8891,7 +8888,7 @@ struct ContainerConditionHandler : ConditionHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void valueFlowDynamicBufferSize(const TokenList& tokenlist, const SymbolDatabase* symboldatabase, const Settings* settings)
|
static void valueFlowDynamicBufferSize(const TokenList& tokenlist, const SymbolDatabase& symboldatabase, const Settings* settings)
|
||||||
{
|
{
|
||||||
auto getBufferSizeFromAllocFunc = [&](const Token* funcTok) -> MathLib::bigint {
|
auto getBufferSizeFromAllocFunc = [&](const Token* funcTok) -> MathLib::bigint {
|
||||||
MathLib::bigint sizeValue = -1;
|
MathLib::bigint sizeValue = -1;
|
||||||
|
@ -8962,7 +8959,7 @@ static void valueFlowDynamicBufferSize(const TokenList& tokenlist, const SymbolD
|
||||||
return sizeValue;
|
return sizeValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const Scope *functionScope : symboldatabase->functionScopes) {
|
for (const Scope *functionScope : symboldatabase.functionScopes) {
|
||||||
for (const Token *tok = functionScope->bodyStart; tok != functionScope->bodyEnd; tok = tok->next()) {
|
for (const Token *tok = functionScope->bodyStart; tok != functionScope->bodyEnd; tok = tok->next()) {
|
||||||
if (!Token::Match(tok, "[;{}] %var% ="))
|
if (!Token::Match(tok, "[;{}] %var% ="))
|
||||||
continue;
|
continue;
|
||||||
|
@ -8976,7 +8973,7 @@ static void valueFlowDynamicBufferSize(const TokenList& tokenlist, const SymbolD
|
||||||
if (!rhs)
|
if (!rhs)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const bool isNew = symboldatabase->isCPP() && rhs->str() == "new";
|
const bool isNew = symboldatabase.isCPP() && rhs->str() == "new";
|
||||||
if (!isNew && !Token::Match(rhs->previous(), "%name% ("))
|
if (!isNew && !Token::Match(rhs->previous(), "%name% ("))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -9060,9 +9057,9 @@ static bool getMinMaxValues(const std::string &typestr, const Settings *settings
|
||||||
return getMinMaxValues(&vt, settings->platform, minvalue, maxvalue);
|
return getMinMaxValues(&vt, settings->platform, minvalue, maxvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowSafeFunctions(TokenList& tokenlist, const SymbolDatabase* symboldatabase, const Settings* settings)
|
static void valueFlowSafeFunctions(TokenList& tokenlist, const SymbolDatabase& symboldatabase, const Settings* settings)
|
||||||
{
|
{
|
||||||
for (const Scope *functionScope : symboldatabase->functionScopes) {
|
for (const Scope *functionScope : symboldatabase.functionScopes) {
|
||||||
if (!functionScope->bodyStart)
|
if (!functionScope->bodyStart)
|
||||||
continue;
|
continue;
|
||||||
const Function *function = functionScope->function;
|
const Function *function = functionScope->function;
|
||||||
|
@ -9216,14 +9213,14 @@ const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(Token *expr, const S
|
||||||
|
|
||||||
struct ValueFlowState {
|
struct ValueFlowState {
|
||||||
explicit ValueFlowState(TokenList& tokenlist,
|
explicit ValueFlowState(TokenList& tokenlist,
|
||||||
SymbolDatabase* symboldatabase = nullptr,
|
SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger* errorLogger = nullptr,
|
ErrorLogger* errorLogger = nullptr,
|
||||||
const Settings* settings = nullptr)
|
const Settings* settings = nullptr)
|
||||||
: tokenlist(tokenlist), symboldatabase(symboldatabase), errorLogger(errorLogger), settings(settings)
|
: tokenlist(tokenlist), symboldatabase(symboldatabase), errorLogger(errorLogger), settings(settings)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
TokenList& tokenlist;
|
TokenList& tokenlist;
|
||||||
SymbolDatabase* symboldatabase = nullptr;
|
SymbolDatabase& symboldatabase;
|
||||||
ErrorLogger* errorLogger = nullptr;
|
ErrorLogger* errorLogger = nullptr;
|
||||||
const Settings* settings = nullptr;
|
const Settings* settings = nullptr;
|
||||||
std::set<const Scope*> skippedFunctions = {};
|
std::set<const Scope*> skippedFunctions = {};
|
||||||
|
@ -9313,7 +9310,7 @@ struct ValueFlowPassRunner {
|
||||||
void setSkippedFunctions()
|
void setSkippedFunctions()
|
||||||
{
|
{
|
||||||
if (state.settings->performanceValueFlowMaxIfCount > 0) {
|
if (state.settings->performanceValueFlowMaxIfCount > 0) {
|
||||||
for (const Scope* functionScope : state.symboldatabase->functionScopes) {
|
for (const Scope* functionScope : state.symboldatabase.functionScopes) {
|
||||||
int countIfScopes = 0;
|
int countIfScopes = 0;
|
||||||
std::vector<const Scope*> scopes{functionScope};
|
std::vector<const Scope*> scopes{functionScope};
|
||||||
while (!scopes.empty()) {
|
while (!scopes.empty()) {
|
||||||
|
@ -9386,7 +9383,7 @@ ValueFlowPassAdaptor<F> makeValueFlowPassAdaptor(const char* name, bool cpp, F r
|
||||||
makeValueFlowPassAdaptor(#__VA_ARGS__, \
|
makeValueFlowPassAdaptor(#__VA_ARGS__, \
|
||||||
cpp, \
|
cpp, \
|
||||||
[](TokenList& tokenlist, \
|
[](TokenList& tokenlist, \
|
||||||
SymbolDatabase* symboldatabase, \
|
SymbolDatabase& symboldatabase, \
|
||||||
ErrorLogger* errorLogger, \
|
ErrorLogger* errorLogger, \
|
||||||
const Settings* settings, \
|
const Settings* settings, \
|
||||||
const std::set<const Scope*>& skippedFunctions) { \
|
const std::set<const Scope*>& skippedFunctions) { \
|
||||||
|
@ -9402,7 +9399,7 @@ ValueFlowPassAdaptor<F> makeValueFlowPassAdaptor(const char* name, bool cpp, F r
|
||||||
#define VFA_CPP(...) VALUEFLOW_ADAPTOR(true, __VA_ARGS__)
|
#define VFA_CPP(...) VALUEFLOW_ADAPTOR(true, __VA_ARGS__)
|
||||||
|
|
||||||
void ValueFlow::setValues(TokenList& tokenlist,
|
void ValueFlow::setValues(TokenList& tokenlist,
|
||||||
SymbolDatabase* symboldatabase,
|
SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger* errorLogger,
|
ErrorLogger* errorLogger,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
TimerResultsIntf* timerResults)
|
TimerResultsIntf* timerResults)
|
||||||
|
@ -9422,7 +9419,7 @@ void ValueFlow::setValues(TokenList& tokenlist,
|
||||||
VFA(valueFlowNumber(tokenlist, settings)),
|
VFA(valueFlowNumber(tokenlist, settings)),
|
||||||
VFA(valueFlowGlobalStaticVar(tokenlist, settings)),
|
VFA(valueFlowGlobalStaticVar(tokenlist, settings)),
|
||||||
VFA(valueFlowPointerAlias(tokenlist, settings)),
|
VFA(valueFlowPointerAlias(tokenlist, settings)),
|
||||||
VFA(valueFlowLifetime(tokenlist, symboldatabase, errorLogger, settings)),
|
VFA(valueFlowLifetime(tokenlist, errorLogger, settings)),
|
||||||
VFA(valueFlowSymbolic(tokenlist, symboldatabase, settings)),
|
VFA(valueFlowSymbolic(tokenlist, symboldatabase, settings)),
|
||||||
VFA(valueFlowBitAnd(tokenlist, settings)),
|
VFA(valueFlowBitAnd(tokenlist, settings)),
|
||||||
VFA(valueFlowSameExpressions(tokenlist, settings)),
|
VFA(valueFlowSameExpressions(tokenlist, settings)),
|
||||||
|
@ -9445,9 +9442,9 @@ void ValueFlow::setValues(TokenList& tokenlist,
|
||||||
VFA(valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings)),
|
VFA(valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings)),
|
||||||
VFA(valueFlowSubFunction(tokenlist, symboldatabase, errorLogger, *settings)),
|
VFA(valueFlowSubFunction(tokenlist, symboldatabase, errorLogger, *settings)),
|
||||||
VFA(valueFlowFunctionReturn(tokenlist, errorLogger, settings)),
|
VFA(valueFlowFunctionReturn(tokenlist, errorLogger, settings)),
|
||||||
VFA(valueFlowLifetime(tokenlist, symboldatabase, errorLogger, settings)),
|
VFA(valueFlowLifetime(tokenlist, errorLogger, settings)),
|
||||||
VFA(valueFlowFunctionDefaultParameter(tokenlist, symboldatabase, settings)),
|
VFA(valueFlowFunctionDefaultParameter(tokenlist, symboldatabase, settings)),
|
||||||
VFA(valueFlowUninit(tokenlist, symboldatabase, settings)),
|
VFA(valueFlowUninit(tokenlist, settings)),
|
||||||
VFA_CPP(valueFlowAfterMove(tokenlist, symboldatabase, settings)),
|
VFA_CPP(valueFlowAfterMove(tokenlist, symboldatabase, settings)),
|
||||||
VFA_CPP(valueFlowSmartPointer(tokenlist, errorLogger, settings)),
|
VFA_CPP(valueFlowSmartPointer(tokenlist, errorLogger, settings)),
|
||||||
VFA_CPP(valueFlowIterators(tokenlist, settings)),
|
VFA_CPP(valueFlowIterators(tokenlist, settings)),
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace ValueFlow {
|
||||||
|
|
||||||
/// Perform valueflow analysis.
|
/// Perform valueflow analysis.
|
||||||
void setValues(TokenList& tokenlist,
|
void setValues(TokenList& tokenlist,
|
||||||
SymbolDatabase* symboldatabase,
|
SymbolDatabase& symboldatabase,
|
||||||
ErrorLogger* errorLogger,
|
ErrorLogger* errorLogger,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
TimerResultsIntf* timerResults);
|
TimerResultsIntf* timerResults);
|
||||||
|
|
Loading…
Reference in New Issue