Skip to content

Commit afd13ea

Browse files
authored
ValueFlow: some interface and namespace cleanups (#4746)
1 parent 464fbe8 commit afd13ea

9 files changed

Lines changed: 143 additions & 159 deletions

lib/astutils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ bool extractForLoopValues(const Token *forToken,
879879
const Token *incExpr = forToken->next()->astOperand2()->astOperand2()->astOperand2();
880880
if (!initExpr || !initExpr->isBinaryOp() || initExpr->str() != "=" || !Token::Match(initExpr->astOperand1(), "%var%"))
881881
return false;
882-
std::vector<MathLib::bigint> minInitValue = getMinValue(makeIntegralInferModel(), initExpr->astOperand2()->values());
882+
std::vector<MathLib::bigint> minInitValue = getMinValue(ValueFlow::makeIntegralInferModel(), initExpr->astOperand2()->values());
883883
*varid = initExpr->astOperand1()->varId();
884884
*knownInitValue = initExpr->astOperand2()->hasKnownIntValue();
885885
*initValue = minInitValue.empty() ? 0 : minInitValue.front();
@@ -1289,10 +1289,10 @@ const Token* followReferences(const Token* tok, ErrorPath* errors)
12891289

12901290
static bool isSameLifetime(const Token * const tok1, const Token * const tok2)
12911291
{
1292-
ValueFlow::Value v1 = getLifetimeObjValue(tok1);
1292+
ValueFlow::Value v1 = ValueFlow::getLifetimeObjValue(tok1);
12931293
if (!v1.isLifetimeValue())
12941294
return false;
1295-
ValueFlow::Value v2 = getLifetimeObjValue(tok2);
1295+
ValueFlow::Value v2 = ValueFlow::getLifetimeObjValue(tok2);
12961296
if (!v2.isLifetimeValue())
12971297
return false;
12981298
return v1.tokvalue == v2.tokvalue;

lib/checkautovariables.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
518518
for (const Token *tok = start; tok && tok != end; tok = tok->next()) {
519519
// Return reference from function
520520
if (returnRef && Token::simpleMatch(tok->astParent(), "return")) {
521-
for (const LifetimeToken& lt : getLifetimeTokens(tok, true)) {
521+
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(tok, true)) {
522522
if (!printInconclusive && lt.inconclusive)
523523
continue;
524524
const Variable* var = lt.token->variable();
@@ -537,14 +537,14 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
537537
tok->variable()->declarationId() == tok->varId() && tok->variable()->isStatic() &&
538538
!tok->variable()->isArgument()) {
539539
ErrorPath errorPath;
540-
const Variable *var = getLifetimeVariable(tok, errorPath);
540+
const Variable *var = ValueFlow::getLifetimeVariable(tok, errorPath);
541541
if (var && isInScope(var->nameToken(), tok->scope())) {
542542
errorDanglingReference(tok, var, errorPath);
543543
continue;
544544
}
545545
// Reference to temporary
546546
} else if (tok->variable() && (tok->variable()->isReference() || tok->variable()->isRValueReference())) {
547-
for (const LifetimeToken& lt : getLifetimeTokens(getParentLifetime(tok))) {
547+
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(getParentLifetime(tok))) {
548548
if (!printInconclusive && lt.inconclusive)
549549
continue;
550550
const Token * tokvalue = lt.token;
@@ -565,13 +565,13 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
565565
const Token* parent = getParentLifetime(mTokenizer->isCPP(), val.tokvalue, &mSettings->library);
566566
if (!exprs.insert(parent).second)
567567
continue;
568-
for (const LifetimeToken& lt : getLifetimeTokens(parent, escape || isAssignedToNonLocal(tok))) {
568+
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(parent, escape || isAssignedToNonLocal(tok))) {
569569
const Token * tokvalue = lt.token;
570570
if (val.isLocalLifetimeValue()) {
571571
if (escape) {
572572
if (getPointerDepth(tok) < getPointerDepth(tokvalue))
573573
continue;
574-
if (!isLifetimeBorrowed(tok, mSettings))
574+
if (!ValueFlow::isLifetimeBorrowed(tok, mSettings))
575575
continue;
576576
if (tokvalue->exprId() == tok->exprId() && !(tok->variable() && tok->variable()->isArray()) &&
577577
!astIsContainerView(tok->astParent()))
@@ -604,7 +604,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
604604
} else if (tok->variable() && tok->variable()->declarationId() == tok->varId()) {
605605
var = tok->variable();
606606
}
607-
if (!isLifetimeBorrowed(tok, mSettings))
607+
if (!ValueFlow::isLifetimeBorrowed(tok, mSettings))
608608
continue;
609609
const Token* nextTok = nextAfterAstRightmostLeaf(tok->astTop());
610610
if (!nextTok)

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ void CheckBufferOverrun::objectIndex()
10301030
if (idx->hasKnownIntValue() && idx->getKnownIntValue() == 0)
10311031
continue;
10321032

1033-
std::vector<ValueFlow::Value> values = getLifetimeObjValues(obj, false, -1);
1033+
std::vector<ValueFlow::Value> values = ValueFlow::getLifetimeObjValues(obj, false, -1);
10341034
for (const ValueFlow::Value& v:values) {
10351035
if (v.lifetimeKind != ValueFlow::Value::LifetimeKind::Address)
10361036
continue;

lib/checkother.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ void CheckOther::checkConstVariable()
14461446
retTok = retTok->astOperand2();
14471447
while (Token::simpleMatch(retTok, "."))
14481448
retTok = retTok->astOperand2();
1449-
return hasLifetimeToken(getParentLifetime(retTok), var->nameToken());
1449+
return ValueFlow::hasLifetimeToken(getParentLifetime(retTok), var->nameToken());
14501450
}))
14511451
continue;
14521452
}
@@ -3671,8 +3671,8 @@ void CheckOther::checkComparePointers()
36713671
const Token *tok2 = tok->astOperand2();
36723672
if (!astIsPointer(tok1) || !astIsPointer(tok2))
36733673
continue;
3674-
ValueFlow::Value v1 = getLifetimeObjValue(tok1);
3675-
ValueFlow::Value v2 = getLifetimeObjValue(tok2);
3674+
ValueFlow::Value v1 = ValueFlow::getLifetimeObjValue(tok1);
3675+
ValueFlow::Value v2 = ValueFlow::getLifetimeObjValue(tok2);
36763676
if (!v1.isLocalLifetimeValue() || !v2.isLocalLifetimeValue())
36773677
continue;
36783678
const Variable *var1 = v1.tokvalue->variable();

lib/checkstl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static bool isSameIteratorContainerExpression(const Token* tok1,
727727

728728
static ValueFlow::Value getLifetimeIteratorValue(const Token* tok, MathLib::bigint path = 0)
729729
{
730-
std::vector<ValueFlow::Value> values = getLifetimeObjValues(tok, false, path);
730+
std::vector<ValueFlow::Value> values = ValueFlow::getLifetimeObjValues(tok, false, path);
731731
auto it = std::find_if(values.cbegin(), values.cend(), [](const ValueFlow::Value& v) {
732732
return v.lifetimeKind == ValueFlow::Value::LifetimeKind::Iterator;
733733
});
@@ -1155,7 +1155,7 @@ void CheckStl::invalidContainer()
11551155

11561156
ErrorPath ep;
11571157
bool addressOf = false;
1158-
const Variable* var = getLifetimeVariable(info.tok, ep, &addressOf);
1158+
const Variable* var = ValueFlow::getLifetimeVariable(info.tok, ep, &addressOf);
11591159
// Check the reference is created before the change
11601160
if (var && var->declarationId() == r.tok->varId() && !addressOf) {
11611161
// An argument always reaches

lib/checkunusedvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
12871287
continue;
12881288

12891289
FwdAnalysis fwdAnalysis(mTokenizer->isCPP(), mSettings->library);
1290-
const Token* scopeEnd = getEndOfExprScope(expr, scope, /*smallest*/ false);
1290+
const Token* scopeEnd = ValueFlow::getEndOfExprScope(expr, scope, /*smallest*/ false);
12911291
if (fwdAnalysis.unusedValue(expr, start, scopeEnd)) {
12921292
if (!bailoutTypeName.empty()) {
12931293
if (bailoutTypeName != "auto")

lib/programmemory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,13 +1274,13 @@ static ValueFlow::Value executeImpl(const Token* expr, ProgramMemory& pm, const
12741274
if (expr->isComparisonOp()) {
12751275
if (rhs.isIntValue()) {
12761276
std::vector<ValueFlow::Value> result =
1277-
infer(makeIntegralInferModel(), expr->str(), expr->astOperand1()->values(), {rhs});
1277+
infer(ValueFlow::makeIntegralInferModel(), expr->str(), expr->astOperand1()->values(), {rhs});
12781278
if (result.empty() || !result.front().isKnown())
12791279
return unknown;
12801280
return result.front();
12811281
} else if (lhs.isIntValue()) {
12821282
std::vector<ValueFlow::Value> result =
1283-
infer(makeIntegralInferModel(), expr->str(), {lhs}, expr->astOperand2()->values());
1283+
infer(ValueFlow::makeIntegralInferModel(), expr->str(), {lhs}, expr->astOperand2()->values());
12841284
if (result.empty() || !result.front().isKnown())
12851285
return unknown;
12861286
return result.front();
@@ -1353,7 +1353,7 @@ static ValueFlow::Value executeImpl(const Token* expr, ProgramMemory& pm, const
13531353
if (child->exprId() > 0 && pm.hasValue(child->exprId())) {
13541354
ValueFlow::Value& v = pm.at(child->exprId());
13551355
if (v.valueType == ValueFlow::Value::ValueType::CONTAINER_SIZE) {
1356-
if (isContainerSizeChanged(child, v.indirect, settings))
1356+
if (ValueFlow::isContainerSizeChanged(child, v.indirect, settings))
13571357
v = unknown;
13581358
} else if (v.valueType != ValueFlow::Value::ValueType::UNINIT) {
13591359
if (isVariableChanged(child, v.indirect, settings, true))

0 commit comments

Comments
 (0)