Skip to content

Commit bfb50ca

Browse files
authored
removed unnecessary Settings parameter from Check::runChecks() and made Tokenizer a reference (#5308)
There was no need for the `Tokenizer` parameter to be a pointer as it could never be `nullptr` and was also dereferenced without checking first. As a reference to the `Settings` was already available via the `Tokenizer` there was no need to pass it separately. In the production code there will only be one instance of it but in the tests we could have accidentally passed a different one.
1 parent 1bedf44 commit bfb50ca

47 files changed

Lines changed: 114 additions & 114 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ $(libcppdir)/tokenlist.o: lib/tokenlist.cpp externals/simplecpp/simplecpp.h lib/
629629
$(libcppdir)/utils.o: lib/utils.cpp lib/config.h lib/utils.h
630630
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/utils.cpp
631631

632-
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
632+
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
633633
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp
634634

635635
$(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h

lib/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CPPCHECKLIB Check {
7777
static std::list<Check *> &instances();
7878

7979
/** run checks, the token list is not simplified */
80-
virtual void runChecks(const Tokenizer *, const Settings *, ErrorLogger *) = 0;
80+
virtual void runChecks(const Tokenizer &, ErrorLogger *) = 0;
8181

8282
/** get error messages */
8383
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const = 0;

lib/check64bit.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
#include "check.h"
2626
#include "config.h"
27+
#include "tokenize.h"
2728

2829
#include <string>
2930

3031
class ErrorLogger;
3132
class Settings;
3233
class Token;
33-
class Tokenizer;
3434

3535

3636
/// @addtogroup Checks
@@ -50,8 +50,8 @@ class CPPCHECKLIB Check64BitPortability : public Check {
5050
: Check(myName(), tokenizer, settings, errorLogger) {}
5151

5252
/** @brief Run checks against the normal token list */
53-
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
54-
Check64BitPortability check64BitPortability(tokenizer, settings, errorLogger);
53+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
54+
Check64BitPortability check64BitPortability(&tokenizer, tokenizer.getSettings(), errorLogger);
5555
check64BitPortability.pointerassignment();
5656
}
5757

lib/checkassert.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
#include "check.h"
2626
#include "config.h"
27+
#include "tokenize.h"
2728

2829
#include <string>
2930

3031
class ErrorLogger;
3132
class Scope;
3233
class Settings;
3334
class Token;
34-
class Tokenizer;
3535

3636
/// @addtogroup Checks
3737
/// @{
@@ -48,8 +48,8 @@ class CPPCHECKLIB CheckAssert : public Check {
4848
: Check(myName(), tokenizer, settings, errorLogger) {}
4949

5050
/** run checks, the token list is not simplified */
51-
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
52-
CheckAssert checkAssert(tokenizer, settings, errorLogger);
51+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
52+
CheckAssert checkAssert(&tokenizer, tokenizer.getSettings(), errorLogger);
5353
checkAssert.assertWithSideEffects();
5454
}
5555

lib/checkautovariables.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
#include "check.h"
2626
#include "config.h"
2727
#include "errortypes.h"
28+
#include "tokenize.h"
2829

2930
#include <string>
3031
#include <set>
3132

3233
class Settings;
3334
class Token;
34-
class Tokenizer;
3535
class ErrorLogger;
3636
class Variable;
3737

@@ -54,8 +54,8 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
5454
: Check(myName(), tokenizer, settings, errorLogger) {}
5555

5656
/** @brief Run checks against the normal token list */
57-
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
58-
CheckAutoVariables checkAutoVariables(tokenizer, settings, errorLogger);
57+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
58+
CheckAutoVariables checkAutoVariables(&tokenizer, tokenizer.getSettings(), errorLogger);
5959
checkAutoVariables.assignFunctionArg();
6060
checkAutoVariables.checkVarLifetime();
6161
checkAutoVariables.autoVariables();

lib/checkbool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
#include "check.h"
2626
#include "config.h"
27+
#include "tokenize.h"
2728

2829
#include <string>
2930

3031
class ErrorLogger;
3132
class Settings;
3233
class Token;
33-
class Tokenizer;
3434

3535
/// @addtogroup Checks
3636
/// @{
@@ -48,8 +48,8 @@ class CPPCHECKLIB CheckBool : public Check {
4848
: Check(myName(), tokenizer, settings, errorLogger) {}
4949

5050
/** @brief Run checks against the normal token list */
51-
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
52-
CheckBool checkBool(tokenizer, settings, errorLogger);
51+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
52+
CheckBool checkBool(&tokenizer, tokenizer.getSettings(), errorLogger);
5353

5454
// Checks
5555
checkBool.checkComparisonOfBoolExpressionWithInt();

lib/checkboost.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class CPPCHECKLIB CheckBoost : public Check {
4747
: Check(myName(), tokenizer, settings, errorLogger) {}
4848

4949
/** @brief Run checks against the normal token list */
50-
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
51-
if (!tokenizer->isCPP())
50+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
51+
if (!tokenizer.isCPP())
5252
return;
5353

54-
CheckBoost checkBoost(tokenizer, settings, errorLogger);
54+
CheckBoost checkBoost(&tokenizer, tokenizer.getSettings(), errorLogger);
5555
checkBoost.checkBoostForeachModification();
5656
}
5757

lib/checkbufferoverrun.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "errortypes.h"
2929
#include "mathlib.h"
3030
#include "symboldatabase.h"
31+
#include "tokenize.h"
3132
#include "vfvalue.h"
3233

3334
#include <list>
@@ -42,7 +43,6 @@ namespace tinyxml2 {
4243
class ErrorLogger;
4344
class Settings;
4445
class Token;
45-
class Tokenizer;
4646

4747
/// @addtogroup Checks
4848
/// @{
@@ -66,8 +66,8 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
6666
CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
6767
: Check(myName(), tokenizer, settings, errorLogger) {}
6868

69-
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
70-
CheckBufferOverrun checkBufferOverrun(tokenizer, settings, errorLogger);
69+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
70+
CheckBufferOverrun checkBufferOverrun(&tokenizer, tokenizer.getSettings(), errorLogger);
7171
checkBufferOverrun.arrayIndex();
7272
checkBufferOverrun.pointerArithmetic();
7373
checkBufferOverrun.bufferOverflow();

lib/checkclass.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class CPPCHECKLIB CheckClass : public Check {
5959
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);
6060

6161
/** @brief Run checks on the normal token list */
62-
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
63-
if (tokenizer->isC())
62+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
63+
if (tokenizer.isC())
6464
return;
6565

66-
CheckClass checkClass(tokenizer, settings, errorLogger);
66+
CheckClass checkClass(&tokenizer, tokenizer.getSettings(), errorLogger);
6767

6868
// can't be a simplified check .. the 'sizeof' is used.
6969
checkClass.checkMemset();

lib/checkcondition.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
#include "config.h"
2727
#include "mathlib.h"
2828
#include "errortypes.h"
29+
#include "tokenize.h"
2930

3031
#include <set>
3132
#include <string>
3233

3334
class Settings;
3435
class Token;
35-
class Tokenizer;
3636
class ErrorLogger;
3737
class ValueType;
3838

@@ -56,8 +56,8 @@ class CPPCHECKLIB CheckCondition : public Check {
5656
CheckCondition(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
5757
: Check(myName(), tokenizer, settings, errorLogger) {}
5858

59-
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
60-
CheckCondition checkCondition(tokenizer, settings, errorLogger);
59+
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
60+
CheckCondition checkCondition(&tokenizer, tokenizer.getSettings(), errorLogger);
6161
checkCondition.multiCondition();
6262
checkCondition.clarifyCondition(); // not simplified because ifAssign
6363
checkCondition.multiCondition2();

0 commit comments

Comments
 (0)