Skip to content

Commit

Permalink
changed most Settings pointers to references (#6298)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 26, 2024
1 parent 047b608 commit b7360ce
Show file tree
Hide file tree
Showing 35 changed files with 498 additions and 494 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ $(libcppdir)/errortypes.o: lib/errortypes.cpp lib/config.h lib/errortypes.h lib/
$(libcppdir)/forwardanalyzer.o: lib/forwardanalyzer.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueptr.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/forwardanalyzer.cpp

$(libcppdir)/fwdanalysis.o: lib/fwdanalysis.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/fwdanalysis.h lib/library.h lib/mathlib.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
$(libcppdir)/fwdanalysis.o: lib/fwdanalysis.cpp lib/addoninfo.h lib/astutils.h lib/config.h lib/errortypes.h lib/fwdanalysis.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/fwdanalysis.cpp

$(libcppdir)/importproject.o: lib/importproject.cpp externals/picojson/picojson.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/config.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/json.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
Expand Down
193 changes: 96 additions & 97 deletions lib/astutils.cpp

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const Token* getParentLifetime(const Token* tok);
const Token* getParentLifetime(const Token* tok, const Library& library);

std::vector<ValueType> getParentValueTypes(const Token* tok,
const Settings* settings = nullptr,
const Settings& settings,
const Token** parent = nullptr);

bool astIsLHS(const Token* tok);
Expand Down Expand Up @@ -262,7 +262,7 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
int depth = 20);
const Token* followReferences(const Token* tok, ErrorPath* errors = nullptr);

CPPCHECKLIB bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
CPPCHECKLIB bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Settings& settings, bool pure, bool followVar, ErrorPath* errors=nullptr);

bool isEqualKnownValue(const Token * const tok1, const Token * const tok2);

Expand All @@ -273,7 +273,7 @@ const Token* isInLoopCondition(const Token* tok);
/**
* Is token used as boolean, that is to say cast to a bool, or used as a condition in a if/while/for
*/
CPPCHECKLIB bool isUsedAsBool(const Token* const tok, const Settings* settings = nullptr);
CPPCHECKLIB bool isUsedAsBool(const Token* const tok, const Settings& settings);

/**
* Are the tokens' flags equal?
Expand All @@ -285,12 +285,12 @@ bool compareTokenFlags(const Token* tok1, const Token* tok2, bool macro);
* @param isNot do you want to know if cond1 is !cond2 or if cond1 and cond2 are non-overlapping. true: cond1==!cond2 false: cond1==true => cond2==false
* @param cond1 condition1
* @param cond2 condition2
* @param library files data
* @param settings settings
* @param pure boolean
*/
bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const Settings& settings, bool pure, bool followVar, ErrorPath* errors=nullptr);

bool isOppositeExpression(const Token * const tok1, const Token * const tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors=nullptr);
bool isOppositeExpression(const Token * const tok1, const Token * const tok2, const Settings& settings, bool pure, bool followVar, ErrorPath* errors=nullptr);

bool isConstFunctionCall(const Token* ftok, const Library& library);

Expand Down Expand Up @@ -328,7 +328,7 @@ std::vector<const Variable*> getArgumentVars(const Token* tok, int argnr);
* @param settings program settings
* @param inconclusive pointer to output variable which indicates that the answer of the question is inconclusive
*/
bool isVariableChangedByFunctionCall(const Token *tok, int indirect, nonneg int varid, const Settings *settings, bool *inconclusive);
bool isVariableChangedByFunctionCall(const Token *tok, int indirect, nonneg int varid, const Settings &settings, bool *inconclusive);

/** Is variable changed by function call?
* In case the answer of the question is inconclusive, e.g. because the function declaration is not known
Expand All @@ -338,46 +338,45 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, nonneg int
* @param settings program settings
* @param inconclusive pointer to output variable which indicates that the answer of the question is inconclusive
*/
CPPCHECKLIB bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Settings *settings, bool *inconclusive);
CPPCHECKLIB bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Settings &settings, bool *inconclusive);

/** Is variable changed in block of code? */
CPPCHECKLIB bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
CPPCHECKLIB bool isVariableChanged(const Token *start, const Token *end, const nonneg int exprid, bool globalvar, const Settings &settings, int depth = 20);
bool isVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth = 20);

bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, int depth = 20);
bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, int depth = 20);

bool isVariableChanged(const Variable * var, const Settings *settings, int depth = 20);
bool isVariableChanged(const Variable * var, const Settings &settings, int depth = 20);

bool isVariablesChanged(const Token* start,
const Token* end,
int indirect,
const std::vector<const Variable*> &vars,
const Settings* settings);
const Settings& settings);

bool isThisChanged(const Token* tok, int indirect, const Settings* settings);
const Token* findThisChanged(const Token* start, const Token* end, int indirect, const Settings* settings);
bool isThisChanged(const Token* tok, int indirect, const Settings& settings);

const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings *settings, int depth = 20);
const Token* findVariableChanged(const Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth = 20);
Token* findVariableChanged(Token *start, const Token *end, int indirect, const nonneg int exprid, bool globalvar, const Settings &settings, int depth = 20);

CPPCHECKLIB const Token* findExpressionChanged(const Token* expr,
const Token* start,
const Token* end,
const Settings* settings,
const Settings& settings,
int depth = 20);

const Token* findExpressionChangedSkipDeadCode(const Token* expr,
const Token* start,
const Token* end,
const Settings* settings,
const Settings& settings,
const std::function<std::vector<MathLib::bigint>(const Token* tok)>& evaluate,
int depth = 20);

bool isExpressionChangedAt(const Token* expr,
const Token* tok,
int indirect,
bool globalvar,
const Settings* settings,
const Settings& settings,
int depth = 20);

/// If token is an alias if another variable
Expand Down
16 changes: 8 additions & 8 deletions lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ static bool isPtrArg(const Token *tok)
return (var && var->isArgument() && var->isPointer());
}

static bool isArrayArg(const Token *tok, const Settings* settings)
static bool isArrayArg(const Token *tok, const Settings& settings)
{
const Variable *var = tok->variable();
return (var && var->isArgument() && var->isArray() && !settings->library.isentrypoint(var->scope()->className));
return (var && var->isArgument() && var->isArray() && !settings.library.isentrypoint(var->scope()->className));
}

static bool isArrayVar(const Token *tok)
Expand Down Expand Up @@ -290,7 +290,7 @@ void CheckAutoVariables::autoVariables()
checkAutoVariableAssignment(tok->next(), inconclusive);
tok = tok->tokAt(5);
} else if (Token::Match(tok, "[;{}] %var% [") && Token::simpleMatch(tok->linkAt(2), "] =") &&
(isPtrArg(tok->next()) || isArrayArg(tok->next(), mSettings)) &&
(isPtrArg(tok->next()) || isArrayArg(tok->next(), *mSettings)) &&
isAutoVariableRHS(tok->linkAt(2)->next()->astOperand2())) {
errorAutoVariableAssignment(tok->next(), false);
}
Expand Down Expand Up @@ -553,7 +553,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
for (const Token *tok = start; tok && tok != end; tok = tok->next()) {
// Return reference from function
if (returnRef && Token::simpleMatch(tok->astParent(), "return")) {
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(tok, true)) {
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(tok, *mSettings, true)) {
if (!printInconclusive && lt.inconclusive)
continue;
const Variable* var = lt.token->variable();
Expand All @@ -573,14 +573,14 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
tok->variable()->declarationId() == tok->varId() && tok->variable()->isStatic() &&
!tok->variable()->isArgument()) {
ErrorPath errorPath;
const Variable *var = ValueFlow::getLifetimeVariable(tok, errorPath);
const Variable *var = ValueFlow::getLifetimeVariable(tok, errorPath, *mSettings);
if (var && isInScope(var->nameToken(), tok->scope())) {
errorDanglingReference(tok, var, std::move(errorPath));
continue;
}
// Reference to temporary
} else if (tok->variable() && (tok->variable()->isReference() || tok->variable()->isRValueReference())) {
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(getParentLifetime(tok))) {
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(getParentLifetime(tok), *mSettings)) {
if (!printInconclusive && lt.inconclusive)
continue;
const Token * tokvalue = lt.token;
Expand All @@ -601,7 +601,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
const Token* parent = getParentLifetime(val.tokvalue, mSettings->library);
if (!exprs.insert(parent).second)
continue;
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(parent, escape || isAssignedToNonLocal(tok))) {
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(parent, *mSettings, escape || isAssignedToNonLocal(tok))) {
const Token * tokvalue = lt.token;
if (val.isLocalLifetimeValue()) {
if (escape) {
Expand Down Expand Up @@ -650,7 +650,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
tok->scope()->bodyEnd,
var->declarationId(),
var->isGlobal(),
mSettings)) {
*mSettings)) {
errorDanglngLifetime(tok2, &val);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checkbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
if (astIsBool(numTok))
continue;

const ValueFlow::Value *minval = numTok->getValueLE(0, mSettings);
const ValueFlow::Value *minval = numTok->getValueLE(0, *mSettings);
if (minval && minval->intvalue == 0 &&
(numInRhs ? Token::Match(tok, ">|==|!=")
: Token::Match(tok, "<|==|!=")))
minval = nullptr;

const ValueFlow::Value *maxval = numTok->getValueGE(1, mSettings);
const ValueFlow::Value *maxval = numTok->getValueGE(1, *mSettings);
if (maxval && maxval->intvalue == 1 &&
(numInRhs ? Token::Match(tok, "<|==|!=")
: Token::Match(tok, ">|==|!=")))
Expand Down Expand Up @@ -506,7 +506,7 @@ void CheckBool::returnValueOfFunctionReturningBool()
else if (tok->scope() && tok->scope()->isClassOrStruct())
tok = tok->scope()->bodyEnd;
else if (Token::simpleMatch(tok, "return") && tok->astOperand1() &&
(tok->astOperand1()->getValueGE(2, mSettings) || tok->astOperand1()->getValueLE(-1, mSettings)) &&
(tok->astOperand1()->getValueGE(2, *mSettings) || tok->astOperand1()->getValueLE(-1, *mSettings)) &&
!(tok->astOperand1()->astOperand1() && Token::Match(tok->astOperand1(), "&|%or%")))
returnValueBoolError(tok);
}
Expand Down
Loading

0 comments on commit b7360ce

Please sign in to comment.