Skip to content

Commit d015007

Browse files
authored
pass Settings by reference into Tokenizer (cppcheck-opensource#5857)
We already were enforcing that it is provided via an assert. Back when I added that I did not change it yet because of all the files affected.
1 parent 48f8f82 commit d015007

50 files changed

Lines changed: 357 additions & 361 deletions

Some content is hidden

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

lib/cppcheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ unsigned int CppCheck::checkClang(const std::string &path)
495495

496496
try {
497497
std::istringstream ast(output2);
498-
Tokenizer tokenizer(&mSettings, this);
498+
Tokenizer tokenizer(mSettings, this);
499499
tokenizer.list.appendFileIfNew(path);
500500
clangimport::parseClangAstDump(tokenizer, ast);
501501
ValueFlow::setValues(tokenizer.list,
@@ -663,7 +663,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
663663
}
664664

665665
if (mSettings.library.markupFile(filename)) {
666-
Tokenizer tokenizer(&mSettings, this, &preprocessor);
666+
Tokenizer tokenizer(mSettings, this, &preprocessor);
667667
tokenizer.createTokens(std::move(tokens1));
668668
checkUnusedFunctions.getFileInfo(&tokenizer, &mSettings);
669669
return EXIT_SUCCESS;
@@ -795,7 +795,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
795795
if (startsWith(dir.str,"#define ") || startsWith(dir.str,"#include "))
796796
code += "#line " + std::to_string(dir.linenr) + " \"" + dir.file + "\"\n" + dir.str + '\n';
797797
}
798-
Tokenizer tokenizer2(&mSettings, this);
798+
Tokenizer tokenizer2(mSettings, this);
799799
std::istringstream istr2(code);
800800
tokenizer2.list.createTokens(istr2);
801801
executeRules("define", tokenizer2);
@@ -856,7 +856,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
856856
continue;
857857
}
858858

859-
Tokenizer tokenizer(&mSettings, this, &preprocessor);
859+
Tokenizer tokenizer(mSettings, this, &preprocessor);
860860
if (mSettings.showtime != SHOWTIME_MODES::SHOWTIME_NONE)
861861
tokenizer.setTimerResults(&s_timerResults);
862862

lib/importproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ namespace {
563563
// TODO : Better evaluation
564564
Settings s;
565565
std::istringstream istr(c);
566-
Tokenizer tokenizer(&s);
566+
Tokenizer tokenizer(s);
567567
tokenizer.tokenize(istr,"vcxproj");
568568
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
569569
if (tok->str() == "(" && tok->astOperand1() && tok->astOperand2()) {

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ bool TemplateSimplifier::TokenAndName::isAliasToken(const Token *tok) const
274274
}
275275

276276
TemplateSimplifier::TemplateSimplifier(Tokenizer &tokenizer)
277-
: mTokenizer(tokenizer), mTokenList(mTokenizer.list), mSettings(*mTokenizer.mSettings),
277+
: mTokenizer(tokenizer), mTokenList(mTokenizer.list), mSettings(*mTokenizer.getSettings()),
278278
mErrorLogger(mTokenizer.mErrorLogger)
279279
{}
280280

lib/tokenize.cpp

Lines changed: 107 additions & 112 deletions
Large diffs are not rendered by default.

lib/tokenize.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CPPCHECKLIB Tokenizer {
5959
friend class TemplateSimplifier;
6060

6161
public:
62-
explicit Tokenizer(const Settings * settings, ErrorLogger *errorLogger = nullptr, const Preprocessor *preprocessor = nullptr);
62+
explicit Tokenizer(const Settings & settings, ErrorLogger *errorLogger = nullptr, const Preprocessor *preprocessor = nullptr);
6363
~Tokenizer();
6464

6565
void setTimerResults(TimerResults *tr) {
@@ -640,8 +640,9 @@ class CPPCHECKLIB Tokenizer {
640640
*/
641641
static const Token * startOfExecutableScope(const Token * tok);
642642

643+
// TODO: return reference
643644
const Settings *getSettings() const {
644-
return mSettings;
645+
return &mSettings;
645646
}
646647

647648
void calculateScopes();
@@ -668,7 +669,7 @@ class CPPCHECKLIB Tokenizer {
668669
void setPodTypes();
669670

670671
/** settings */
671-
const Settings * const mSettings;
672+
const Settings & mSettings;
672673

673674
/** errorlogger */
674675
ErrorLogger* const mErrorLogger;

test/helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class givenACodeSampleToTokenize {
4242

4343
public:
4444
explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true)
45-
: tokenizer(&settings, nullptr) {
45+
: tokenizer(settings, nullptr) {
4646
std::istringstream iss(sample);
4747
if (createOnly)
4848
tokenizer.list.createTokens(iss, cpp ? "test.cpp" : "test.c");

test/test64bit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Test64BitPortability : public TestFixture {
4848
errout.str("");
4949

5050
// Tokenize..
51-
Tokenizer tokenizer(&settings, this);
51+
Tokenizer tokenizer(settings, this);
5252
std::istringstream istr(code);
5353
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
5454

test/testassert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TestAssert : public TestFixture {
3939
errout.str("");
4040

4141
// Tokenize..
42-
Tokenizer tokenizer(&settings, this);
42+
Tokenizer tokenizer(settings, this);
4343
std::istringstream istr(code);
4444
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
4545

test/testastutils.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TestAstUtils : public TestFixture {
5151
#define findLambdaEndToken(...) findLambdaEndToken_(__FILE__, __LINE__, __VA_ARGS__)
5252
bool findLambdaEndToken_(const char* file, int line, const char code[], const char pattern[] = nullptr, bool checkNext = true) {
5353
const Settings settings;
54-
Tokenizer tokenizer(&settings, this);
54+
Tokenizer tokenizer(settings, this);
5555
std::istringstream istr(code);
5656
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
5757
const Token* const tokStart = pattern ? Token::findsimplematch(tokenizer.tokens(), pattern, strlen(pattern)) : tokenizer.tokens();
@@ -90,7 +90,7 @@ class TestAstUtils : public TestFixture {
9090
#define findLambdaStartToken(code) findLambdaStartToken_(code, __FILE__, __LINE__)
9191
bool findLambdaStartToken_(const char code[], const char* file, int line) {
9292
const Settings settings;
93-
Tokenizer tokenizer(&settings, this);
93+
Tokenizer tokenizer(settings, this);
9494
std::istringstream istr(code);
9595
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
9696
const Token * const tokStart = (::findLambdaStartToken)(tokenizer.list.back());
@@ -123,7 +123,7 @@ class TestAstUtils : public TestFixture {
123123
#define isNullOperand(code) isNullOperand_(code, __FILE__, __LINE__)
124124
bool isNullOperand_(const char code[], const char* file, int line) {
125125
const Settings settings;
126-
Tokenizer tokenizer(&settings, this);
126+
Tokenizer tokenizer(settings, this);
127127
std::istringstream istr(code);
128128
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
129129
return (::isNullOperand)(tokenizer.tokens());
@@ -145,7 +145,7 @@ class TestAstUtils : public TestFixture {
145145
#define isReturnScope(code, offset) isReturnScope_(code, offset, __FILE__, __LINE__)
146146
bool isReturnScope_(const char code[], int offset, const char* file, int line) {
147147
const Settings settings;
148-
Tokenizer tokenizer(&settings, this);
148+
Tokenizer tokenizer(settings, this);
149149
std::istringstream istr(code);
150150
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
151151
const Token * const tok = (offset < 0)
@@ -177,7 +177,7 @@ class TestAstUtils : public TestFixture {
177177
bool isSameExpression_(const char* file, int line, const char code[], const char tokStr1[], const char tokStr2[]) {
178178
const Settings settings;
179179
Library library;
180-
Tokenizer tokenizer(&settings, this);
180+
Tokenizer tokenizer(settings, this);
181181
std::istringstream istr(code);
182182
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
183183
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), tokStr1, strlen(tokStr1));
@@ -215,7 +215,7 @@ class TestAstUtils : public TestFixture {
215215
#define isVariableChanged(code, startPattern, endPattern) isVariableChanged_(code, startPattern, endPattern, __FILE__, __LINE__)
216216
bool isVariableChanged_(const char code[], const char startPattern[], const char endPattern[], const char* file, int line) {
217217
const Settings settings;
218-
Tokenizer tokenizer(&settings, this);
218+
Tokenizer tokenizer(settings, this);
219219
std::istringstream istr(code);
220220
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
221221
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern));
@@ -250,7 +250,7 @@ class TestAstUtils : public TestFixture {
250250
#define isVariableChangedByFunctionCall(code, pattern, inconclusive) isVariableChangedByFunctionCall_(code, pattern, inconclusive, __FILE__, __LINE__)
251251
bool isVariableChangedByFunctionCall_(const char code[], const char pattern[], bool *inconclusive, const char* file, int line) {
252252
const Settings settings;
253-
Tokenizer tokenizer(&settings, this);
253+
Tokenizer tokenizer(settings, this);
254254
std::istringstream istr(code);
255255
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
256256
const Token * const argtok = Token::findmatch(tokenizer.tokens(), pattern);
@@ -393,7 +393,7 @@ class TestAstUtils : public TestFixture {
393393
int line)
394394
{
395395
const Settings settings = settingsBuilder().library("std.cfg").build();
396-
Tokenizer tokenizer(&settings, this);
396+
Tokenizer tokenizer(settings, this);
397397
std::istringstream istr(code);
398398
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
399399
const Token* const start = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern));
@@ -425,7 +425,7 @@ class TestAstUtils : public TestFixture {
425425
#define nextAfterAstRightmostLeaf(code, parentPattern, rightPattern) nextAfterAstRightmostLeaf_(code, parentPattern, rightPattern, __FILE__, __LINE__)
426426
bool nextAfterAstRightmostLeaf_(const char code[], const char parentPattern[], const char rightPattern[], const char* file, int line) {
427427
const Settings settings;
428-
Tokenizer tokenizer(&settings, this);
428+
Tokenizer tokenizer(settings, this);
429429
std::istringstream istr(code);
430430
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
431431
const Token * tok = Token::findsimplematch(tokenizer.tokens(), parentPattern, strlen(parentPattern));
@@ -450,7 +450,7 @@ class TestAstUtils : public TestFixture {
450450

451451
Result isUsedAsBool(const char code[], const char pattern[]) {
452452
const Settings settings;
453-
Tokenizer tokenizer(&settings, this);
453+
Tokenizer tokenizer(settings, this);
454454
std::istringstream istr(code);
455455
if (!tokenizer.tokenize(istr, "test.cpp"))
456456
return Result::Fail;

test/testautovariables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TestAutoVariables : public TestFixture {
4040
const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, inconclusive).build();
4141

4242
// Tokenize..
43-
Tokenizer tokenizer(&settings1, this);
43+
Tokenizer tokenizer(settings1, this);
4444
std::istringstream istr(code);
4545
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
4646

0 commit comments

Comments
 (0)