Skip to content

Commit 777afff

Browse files
committed
only provide Preprocessor in tests if necessary
1 parent 680902c commit 777afff

File tree

7 files changed

+77
-34
lines changed

7 files changed

+77
-34
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ test/testbool.o: test/testbool.cpp lib/check.h lib/checkbool.h lib/color.h lib/c
690690
test/testboost.o: test/testboost.cpp lib/check.h lib/checkboost.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
691691
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testboost.cpp
692692

693-
test/testbufferoverrun.o: test/testbufferoverrun.cpp externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/check.h lib/checkbufferoverrun.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.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/vfvalue.h test/fixture.h
693+
test/testbufferoverrun.o: test/testbufferoverrun.cpp externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/check.h lib/checkbufferoverrun.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.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/vfvalue.h test/fixture.h
694694
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testbufferoverrun.cpp
695695

696696
test/testcharvar.o: test/testcharvar.cpp lib/check.h lib/checkother.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
@@ -699,7 +699,7 @@ test/testcharvar.o: test/testcharvar.cpp lib/check.h lib/checkother.h lib/color.
699699
test/testclangimport.o: test/testclangimport.cpp lib/check.h lib/clangimport.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.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/vfvalue.h test/fixture.h
700700
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testclangimport.cpp
701701

702-
test/testclass.o: test/testclass.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.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/vfvalue.h test/fixture.h
702+
test/testclass.o: test/testclass.cpp externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.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/vfvalue.h test/fixture.h
703703
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testclass.cpp
704704

705705
test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlineparser.h cli/cppcheckexecutor.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/fixture.h test/redirect.h
@@ -726,7 +726,7 @@ test/testfilelister.o: test/testfilelister.cpp cli/filelister.h lib/check.h lib/
726726
test/testfunctions.o: test/testfunctions.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/checkfunctions.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
727727
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfunctions.cpp
728728

729-
test/testgarbage.o: test/testgarbage.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
729+
test/testgarbage.o: test/testgarbage.cpp externals/simplecpp/simplecpp.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
730730
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testgarbage.cpp
731731

732732
test/testimportproject.o: test/testimportproject.cpp lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/fixture.h

lib/tokenize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9841,8 +9841,7 @@ void Tokenizer::simplifyNamespaceAliases()
98419841
bool Tokenizer::hasIfdef(const Token *start, const Token *end) const
98429842
{
98439843
assert(mPreprocessor);
9844-
if (!mPreprocessor)
9845-
return false;
9844+
98469845
return std::any_of(mPreprocessor->getDirectives().cbegin(), mPreprocessor->getDirectives().cend(), [&](const Directive& d) {
98479846
return d.str.compare(0, 3, "#if") == 0 &&
98489847
d.linenr >= start->linenr() &&

lib/tokenize.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "errortypes.h"
2626
#include "tokenlist.h"
2727

28+
#include <cassert>
2829
#include <iosfwd>
2930
#include <list>
3031
#include <map>
@@ -377,6 +378,7 @@ class CPPCHECKLIB Tokenizer {
377378
static const Token * isFunctionHead(const Token *tok, const std::string &endsWith, bool cpp);
378379

379380
const Preprocessor *getPreprocessor() const {
381+
assert(mPreprocessor);
380382
return mPreprocessor;
381383
}
382384

test/testbufferoverrun.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "errortypes.h"
2424
#include "standards.h"
2525
#include "library.h"
26-
#include "preprocessor.h"
2726
#include "settings.h"
2827
#include "fixture.h"
2928
#include "tokenize.h"
@@ -99,11 +98,8 @@ class TestBufferOverrun : public TestFixture {
9998
std::map<std::string, simplecpp::TokenList*> filedata;
10099
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
101100

102-
Preprocessor preprocessor(*settings, nullptr);
103-
preprocessor.setDirectives(tokens1);
104-
105101
// Tokenizer..
106-
Tokenizer tokenizer(settings, this, &preprocessor);
102+
Tokenizer tokenizer(settings, this);
107103
tokenizer.createTokens(std::move(tokens2));
108104
tokenizer.simplifyTokens1("");
109105

test/testclass.cpp

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "checkclass.h"
2121
#include "errortypes.h"
2222
#include "library.h"
23+
#include "preprocessor.h"
2324
#include "settings.h"
2425
#include "fixture.h"
2526
#include "tokenize.h"
@@ -262,8 +263,10 @@ class TestClass : public TestFixture {
262263
Settings settings;
263264
settings.severity.enable(Severity::warning);
264265

266+
Preprocessor preprocessor(settings, nullptr);
267+
265268
// Tokenize..
266-
Tokenizer tokenizer(&settings, this);
269+
Tokenizer tokenizer(&settings, this, &preprocessor);
267270
std::istringstream istr(code);
268271
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
269272

@@ -366,8 +369,10 @@ class TestClass : public TestFixture {
366369
// Clear the error log
367370
errout.str("");
368371

372+
Preprocessor preprocessor(settings0, nullptr);
373+
369374
// Tokenize..
370-
Tokenizer tokenizer(&settings0, this);
375+
Tokenizer tokenizer(&settings0, this, &preprocessor);
371376
std::istringstream istr(code);
372377
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
373378

@@ -518,8 +523,10 @@ class TestClass : public TestFixture {
518523
// Clear the error log
519524
errout.str("");
520525

526+
Preprocessor preprocessor(settings1, nullptr);
527+
521528
// Tokenize..
522-
Tokenizer tokenizer(&settings1, this);
529+
Tokenizer tokenizer(&settings1, this, &preprocessor);
523530
std::istringstream istr(code);
524531
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
525532

@@ -679,8 +686,10 @@ class TestClass : public TestFixture {
679686
// Clear the error log
680687
errout.str("");
681688

689+
Preprocessor preprocessor(settings0, nullptr);
690+
682691
// Tokenize..
683-
Tokenizer tokenizer(&settings0, this);
692+
Tokenizer tokenizer(&settings0, this, &preprocessor);
684693
std::istringstream istr(code);
685694
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
686695

@@ -1126,8 +1135,10 @@ class TestClass : public TestFixture {
11261135
// Clear the error log
11271136
errout.str("");
11281137

1138+
Preprocessor preprocessor(settings0, nullptr);
1139+
11291140
// Tokenize..
1130-
Tokenizer tokenizer(&settings0, this);
1141+
Tokenizer tokenizer(&settings0, this, &preprocessor);
11311142
std::istringstream istr(code);
11321143
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
11331144

@@ -1600,8 +1611,10 @@ class TestClass : public TestFixture {
16001611
// Clear the error log
16011612
errout.str("");
16021613

1614+
Preprocessor preprocessor(settings1, nullptr);
1615+
16031616
// Tokenize..
1604-
Tokenizer tokenizer(&settings1, this);
1617+
Tokenizer tokenizer(&settings1, this, &preprocessor);
16051618
std::istringstream istr(code);
16061619
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
16071620

@@ -2562,8 +2575,10 @@ class TestClass : public TestFixture {
25622575
settings0.certainty.setEnabled(Certainty::inconclusive, inconclusive);
25632576
settings0.severity.enable(Severity::warning);
25642577

2578+
Preprocessor preprocessor(settings0, nullptr);
2579+
25652580
// Tokenize..
2566-
Tokenizer tokenizer(&settings0, this);
2581+
Tokenizer tokenizer(&settings0, this, &preprocessor);
25672582
std::istringstream istr(code);
25682583
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
25692584

@@ -2879,12 +2894,14 @@ class TestClass : public TestFixture {
28792894
checkNoMemset_(file, line, code, settings);
28802895
}
28812896

2882-
void checkNoMemset_(const char* file, int line, const char code[], const Settings &settings) {
2897+
void checkNoMemset_(const char* file, int line, const char code[], Settings &settings) {
28832898
// Clear the error log
28842899
errout.str("");
28852900

2901+
Preprocessor preprocessor(settings, nullptr);
2902+
28862903
// Tokenize..
2887-
Tokenizer tokenizer(&settings, this);
2904+
Tokenizer tokenizer(&settings, this, &preprocessor);
28882905
std::istringstream istr(code);
28892906
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
28902907

@@ -3516,8 +3533,10 @@ class TestClass : public TestFixture {
35163533
// Clear the error log
35173534
errout.str("");
35183535

3536+
Preprocessor preprocessor(settings1, nullptr);
3537+
35193538
// Tokenize..
3520-
Tokenizer tokenizer(&settings1, this);
3539+
Tokenizer tokenizer(&settings1, this, &preprocessor);
35213540
std::istringstream istr(code);
35223541
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
35233542

@@ -3554,8 +3573,10 @@ class TestClass : public TestFixture {
35543573
s = &settings0;
35553574
s->certainty.setEnabled(Certainty::inconclusive, inconclusive);
35563575

3576+
Preprocessor preprocessor(*s, nullptr);
3577+
35573578
// Tokenize..
3558-
Tokenizer tokenizer(s, this);
3579+
Tokenizer tokenizer(s, this, &preprocessor);
35593580
std::istringstream istr(code);
35603581
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
35613582

@@ -7064,8 +7085,10 @@ class TestClass : public TestFixture {
70647085
// Check..
70657086
settings0.certainty.setEnabled(Certainty::inconclusive, true);
70667087

7088+
Preprocessor preprocessor(settings0, nullptr);
7089+
70677090
// Tokenize..
7068-
Tokenizer tokenizer(&settings0, this);
7091+
Tokenizer tokenizer(&settings0, this, &preprocessor);
70697092
std::istringstream istr(code);
70707093
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
70717094

@@ -7100,8 +7123,10 @@ class TestClass : public TestFixture {
71007123
Settings settings;
71017124
settings.severity.enable(Severity::performance);
71027125

7126+
Preprocessor preprocessor(settings, nullptr);
7127+
71037128
// Tokenize..
7104-
Tokenizer tokenizer(&settings, this);
7129+
Tokenizer tokenizer(&settings, this, &preprocessor);
71057130
std::istringstream istr(code);
71067131
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
71077132

@@ -7312,8 +7337,10 @@ class TestClass : public TestFixture {
73127337
// Clear the error log
73137338
errout.str("");
73147339

7340+
Preprocessor preprocessor(settings0, nullptr);
7341+
73157342
// Tokenize..
7316-
Tokenizer tokenizer(&settings0, this);
7343+
Tokenizer tokenizer(&settings0, this, &preprocessor);
73177344
std::istringstream istr(code);
73187345
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
73197346

@@ -7428,8 +7455,10 @@ class TestClass : public TestFixture {
74287455
settings.severity.enable(Severity::warning);
74297456
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
74307457

7458+
Preprocessor preprocessor(settings, nullptr);
7459+
74317460
// Tokenize..
7432-
Tokenizer tokenizer(&settings, this);
7461+
Tokenizer tokenizer(&settings, this, &preprocessor);
74337462
std::istringstream istr(code);
74347463
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
74357464

@@ -7775,8 +7804,10 @@ class TestClass : public TestFixture {
77757804
Settings settings;
77767805
settings.severity.enable(Severity::style);
77777806

7807+
Preprocessor preprocessor(settings, nullptr);
7808+
77787809
// Tokenize..
7779-
Tokenizer tokenizer(&settings, this);
7810+
Tokenizer tokenizer(&settings, this, &preprocessor);
77807811
std::istringstream istr(code);
77817812
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
77827813

@@ -7951,8 +7982,10 @@ class TestClass : public TestFixture {
79517982
settings.safeChecks.classes = true;
79527983
settings.severity.enable(Severity::warning);
79537984

7985+
Preprocessor preprocessor(settings, nullptr);
7986+
79547987
// Tokenize..
7955-
Tokenizer tokenizer(&settings, this);
7988+
Tokenizer tokenizer(&settings, this, &preprocessor);
79567989
std::istringstream istr(code);
79577990
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
79587991

@@ -7972,8 +8005,10 @@ class TestClass : public TestFixture {
79728005
// Clear the error log
79738006
errout.str("");
79748007

8008+
Preprocessor preprocessor(settings1, nullptr);
8009+
79758010
// Tokenize..
7976-
Tokenizer tokenizer(&settings1, this);
8011+
Tokenizer tokenizer(&settings1, this, &preprocessor);
79778012
std::istringstream istr(code);
79788013
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
79798014

@@ -8169,8 +8204,10 @@ class TestClass : public TestFixture {
81698204
// Clear the error log
81708205
errout.str("");
81718206

8207+
Preprocessor preprocessor(settings1, nullptr);
8208+
81728209
// Tokenize..
8173-
Tokenizer tokenizer(&settings1, this);
8210+
Tokenizer tokenizer(&settings1, this, &preprocessor);
81748211
std::istringstream istr(code);
81758212
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
81768213

test/testgarbage.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "check.h"
2020
#include "errortypes.h"
2121
#include "mathlib.h"
22+
#include "preprocessor.h"
2223
#include "settings.h"
2324
#include "fixture.h"
2425
#include "token.h"
@@ -286,8 +287,10 @@ class TestGarbage : public TestFixture {
286287
std::string checkCodeInternal_(const std::string &code, const char* filename, const char* file, int line) {
287288
errout.str("");
288289

290+
Preprocessor preprocessor(settings, nullptr);
291+
289292
// tokenize..
290-
Tokenizer tokenizer(&settings, this);
293+
Tokenizer tokenizer(&settings, this, &preprocessor);
291294
std::istringstream istr(code);
292295
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
293296

test/testother.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ class TestOther : public TestFixture {
306306
settings->certainty.setEnabled(Certainty::experimental, experimental);
307307
settings->verbose = verbose;
308308

309+
Preprocessor preprocessor(*settings, nullptr);
310+
309311
// Tokenize..
310-
Tokenizer tokenizer(settings, this);
312+
Tokenizer tokenizer(settings, this, &preprocessor);
311313
std::istringstream istr(code);
312314
ASSERT_LOC(tokenizer.tokenize(istr, filename ? filename : "test.cpp"), file, line);
313315

@@ -1546,8 +1548,10 @@ class TestOther : public TestFixture {
15461548
settings.severity.enable(Severity::style);
15471549
settings.standards.cpp = Standards::CPP03; // #5560
15481550

1551+
Preprocessor preprocessor(settings, nullptr);
1552+
15491553
// Tokenize..
1550-
Tokenizer tokenizerCpp(&settings, this);
1554+
Tokenizer tokenizerCpp(&settings, this, &preprocessor);
15511555
std::istringstream istr(code);
15521556
ASSERT_LOC(tokenizerCpp.tokenize(istr, "test.cpp"), file, line);
15531557

@@ -1748,10 +1752,12 @@ class TestOther : public TestFixture {
17481752
if (portability)
17491753
settings.severity.enable(Severity::portability);
17501754
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
1751-
17521755
settings.defaultSign = 's';
1756+
1757+
Preprocessor preprocessor(settings, nullptr);
1758+
17531759
// Tokenize..
1754-
Tokenizer tokenizer(&settings, this);
1760+
Tokenizer tokenizer(&settings, this, &preprocessor);
17551761
std::istringstream istr(code);
17561762
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
17571763

0 commit comments

Comments
 (0)