This commit is contained in:
Paul 2020-09-09 21:32:07 -05:00
parent 75b955b9c6
commit bb9dbaa8f5
3 changed files with 54 additions and 51 deletions

View File

@ -555,7 +555,10 @@ struct ForwardTraversal {
}; };
ForwardAnalyzer::Action valueFlowGenericForward(Token* start, const Token* end, const ValuePtr<ForwardAnalyzer>& fa, const Settings* settings) ForwardAnalyzer::Action valueFlowGenericForward(Token* start,
const Token* end,
const ValuePtr<ForwardAnalyzer>& fa,
const Settings* settings)
{ {
ForwardTraversal ft{fa, settings}; ForwardTraversal ft{fa, settings};
ft.updateRange(start, end); ft.updateRange(start, end);

View File

@ -113,6 +113,9 @@ struct ForwardAnalyzer {
virtual ~ForwardAnalyzer() {} virtual ~ForwardAnalyzer() {}
}; };
ForwardAnalyzer::Action valueFlowGenericForward(Token* start, const Token* end, const ValuePtr<ForwardAnalyzer>& fa, const Settings* settings); ForwardAnalyzer::Action valueFlowGenericForward(Token* start,
const Token* end,
const ValuePtr<ForwardAnalyzer>& fa,
const Settings* settings);
#endif #endif

View File

@ -1711,11 +1711,11 @@ static void valueFlowGlobalStaticVar(TokenList *tokenList, const Settings *setti
} }
static ForwardAnalyzer::Action valueFlowForwardVariable(Token* const startToken, static ForwardAnalyzer::Action valueFlowForwardVariable(Token* const startToken,
const Token* const endToken, const Token* const endToken,
const Variable* const var, const Variable* const var,
std::list<ValueFlow::Value> values, std::list<ValueFlow::Value> values,
TokenList* const tokenlist, TokenList* const tokenlist,
const Settings* const settings); const Settings* const settings);
// Old deprecated version // Old deprecated version
static void valueFlowForward(Token* startToken, static void valueFlowForward(Token* startToken,
@ -2698,12 +2698,12 @@ static std::vector<const Variable*> getAliasesFromValues(std::list<ValueFlow::Va
} }
static ForwardAnalyzer::Action valueFlowForwardVariable(Token* const startToken, static ForwardAnalyzer::Action valueFlowForwardVariable(Token* const startToken,
const Token* const endToken, const Token* const endToken,
const Variable* const var, const Variable* const var,
std::list<ValueFlow::Value> values, std::list<ValueFlow::Value> values,
std::vector<const Variable*> aliases, std::vector<const Variable*> aliases,
TokenList* const tokenlist, TokenList* const tokenlist,
const Settings* const settings) const Settings* const settings)
{ {
ForwardAnalyzer::Action actions; ForwardAnalyzer::Action actions;
for (ValueFlow::Value& v : values) { for (ValueFlow::Value& v : values) {
@ -2714,13 +2714,14 @@ static ForwardAnalyzer::Action valueFlowForwardVariable(Token* const startToken,
} }
static ForwardAnalyzer::Action valueFlowForwardVariable(Token* const startToken, static ForwardAnalyzer::Action valueFlowForwardVariable(Token* const startToken,
const Token* const endToken, const Token* const endToken,
const Variable* const var, const Variable* const var,
std::list<ValueFlow::Value> values, std::list<ValueFlow::Value> values,
TokenList* const tokenlist, TokenList* const tokenlist,
const Settings* const settings) const Settings* const settings)
{ {
return valueFlowForwardVariable(startToken, endToken, var, std::move(values), getAliasesFromValues(values), tokenlist, settings); return valueFlowForwardVariable(
startToken, endToken, var, std::move(values), getAliasesFromValues(values), tokenlist, settings);
} }
// Old deprecated version // Old deprecated version
@ -2808,11 +2809,11 @@ struct ExpressionForwardAnalyzer : SingleValueFlowForwardAnalyzer {
}; };
static ForwardAnalyzer::Action valueFlowForwardExpression(Token* startToken, static ForwardAnalyzer::Action valueFlowForwardExpression(Token* startToken,
const Token* endToken, const Token* endToken,
const Token* exprTok, const Token* exprTok,
const std::list<ValueFlow::Value>& values, const std::list<ValueFlow::Value>& values,
const TokenList* const tokenlist, const TokenList* const tokenlist,
const Settings* settings) const Settings* settings)
{ {
ForwardAnalyzer::Action actions; ForwardAnalyzer::Action actions;
for (const ValueFlow::Value& v : values) { for (const ValueFlow::Value& v : values) {
@ -2884,20 +2885,15 @@ static const Token* solveExprValues(const Token* expr, std::list<ValueFlow::Valu
} }
static ForwardAnalyzer::Action valueFlowForward(Token* startToken, static ForwardAnalyzer::Action valueFlowForward(Token* startToken,
const Token* endToken, const Token* endToken,
const Token* exprTok, const Token* exprTok,
std::list<ValueFlow::Value> values, std::list<ValueFlow::Value> values,
TokenList* const tokenlist, TokenList* const tokenlist,
const Settings* settings) const Settings* settings)
{ {
const Token* expr = solveExprValues(exprTok, values); const Token* expr = solveExprValues(exprTok, values);
if (expr->variable()) { if (expr->variable()) {
return valueFlowForwardVariable(startToken, return valueFlowForwardVariable(startToken, endToken, expr->variable(), values, tokenlist, settings);
endToken,
expr->variable(),
values,
tokenlist,
settings);
} else { } else {
return valueFlowForwardExpression(startToken, endToken, expr, values, tokenlist, settings); return valueFlowForwardExpression(startToken, endToken, expr, values, tokenlist, settings);
} }
@ -4553,13 +4549,10 @@ static void valueFlowAfterCondition(TokenList *tokenlist,
const Settings *settings) const Settings *settings)
{ {
ValueFlowConditionHandler handler; ValueFlowConditionHandler handler;
handler.forward = [&](Token* start, handler.forward =
const Token* stop, [&](Token* start, const Token* stop, const Token* vartok, const std::list<ValueFlow::Value>& values, bool) {
const Token* vartok, return valueFlowForward(start->next(), stop, vartok, values, tokenlist, settings).isModified();
const std::list<ValueFlow::Value>& values, };
bool) {
return valueFlowForward(start->next(), stop, vartok, values, tokenlist, settings).isModified();
};
handler.parse = [&](const Token *tok) { handler.parse = [&](const Token *tok) {
ValueFlowConditionHandler::Condition cond; ValueFlowConditionHandler::Condition cond;
ValueFlow::Value true_value; ValueFlow::Value true_value;
@ -5889,12 +5882,19 @@ struct ContainerVariableForwardAnalyzer : VariableForwardAnalyzer {
} }
}; };
static ForwardAnalyzer::Action valueFlowContainerForward(Token *tok, const Token* endToken, const Variable* var, ValueFlow::Value value, TokenList *tokenlist) static ForwardAnalyzer::Action valueFlowContainerForward(Token* tok,
const Token* endToken,
const Variable* var,
ValueFlow::Value value,
TokenList* tokenlist)
{ {
ContainerVariableForwardAnalyzer a(var, value, getAliasesFromValues({value}), tokenlist); ContainerVariableForwardAnalyzer a(var, value, getAliasesFromValues({value}), tokenlist);
return valueFlowGenericForward(tok, endToken, a, tokenlist->getSettings()); return valueFlowGenericForward(tok, endToken, a, tokenlist->getSettings());
} }
static ForwardAnalyzer::Action valueFlowContainerForward(Token *tok, const Variable* var, ValueFlow::Value value, TokenList *tokenlist) static ForwardAnalyzer::Action valueFlowContainerForward(Token* tok,
const Variable* var,
ValueFlow::Value value,
TokenList* tokenlist)
{ {
const Token * endOfVarScope = nullptr; const Token * endOfVarScope = nullptr;
if (var->isLocal() || var->isArgument()) if (var->isLocal() || var->isArgument())
@ -6050,13 +6050,10 @@ static void valueFlowIteratorAfterCondition(TokenList *tokenlist,
const Settings *settings) const Settings *settings)
{ {
ValueFlowConditionHandler handler; ValueFlowConditionHandler handler;
handler.forward = [&](Token* start, handler.forward =
const Token* stop, [&](Token* start, const Token* stop, const Token* vartok, const std::list<ValueFlow::Value>& values, bool) {
const Token* vartok, return valueFlowForward(start->next(), stop, vartok, values, tokenlist, settings).isModified();
const std::list<ValueFlow::Value>& values, };
bool) {
return valueFlowForward(start->next(), stop, vartok, values, tokenlist, settings).isModified();
};
handler.parse = [&](const Token *tok) { handler.parse = [&](const Token *tok) {
ValueFlowConditionHandler::Condition cond; ValueFlowConditionHandler::Condition cond;