Skip to content

Commit ffb0b49

Browse files
committed
Preprocessor: provide suppressions separately from settings
1 parent f2238e7 commit ffb0b49

File tree

10 files changed

+69
-66
lines changed

10 files changed

+69
-66
lines changed

lib/cppcheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
663663
CheckUnusedFunctions checkUnusedFunctions(nullptr, nullptr, nullptr);
664664

665665
try {
666-
Preprocessor preprocessor(mSettings, this);
666+
Preprocessor preprocessor(mSettings, mSettings.nomsg, this);
667667
std::set<std::string> configurations;
668668

669669
simplecpp::OutputList outputList;

lib/preprocessor.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Directive::Directive(std::string _file, const int _linenr, const std::string &_s
6464

6565
char Preprocessor::macroChar = char(1);
6666

67-
Preprocessor::Preprocessor(Settings& settings, ErrorLogger *errorLogger) : mSettings(settings), mErrorLogger(errorLogger)
67+
Preprocessor::Preprocessor(const Settings& settings, Suppressions &suppressions, ErrorLogger *errorLogger) : mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
6868
{}
6969

7070
Preprocessor::~Preprocessor()
@@ -129,7 +129,7 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std:
129129
return true;
130130
}
131131

132-
static void addinlineSuppressions(const simplecpp::TokenList &tokens, Settings &mSettings, std::list<BadInlineSuppression> &bad)
132+
static void addinlineSuppressions(const simplecpp::TokenList &tokens, const Settings &settings, Suppressions &suppressions, std::list<BadInlineSuppression> &bad)
133133
{
134134
for (const simplecpp::Token *tok = tokens.cfront(); tok; tok = tok->next) {
135135
if (!tok->comment)
@@ -155,8 +155,8 @@ static void addinlineSuppressions(const simplecpp::TokenList &tokens, Settings &
155155

156156
// Relative filename
157157
std::string relativeFilename(tok->location.file());
158-
if (mSettings.relativePaths) {
159-
for (const std::string & basePath : mSettings.basePaths) {
158+
if (settings.relativePaths) {
159+
for (const std::string & basePath : settings.basePaths) {
160160
const std::string bp = basePath + "/";
161161
if (relativeFilename.compare(0,bp.size(),bp)==0) {
162162
relativeFilename = relativeFilename.substr(bp.size());
@@ -179,7 +179,7 @@ static void addinlineSuppressions(const simplecpp::TokenList &tokens, Settings &
179179
suppr.fileName = relativeFilename;
180180
suppr.lineNumber = tok->location.line;
181181
suppr.thisAndNextLine = thisAndNextLine;
182-
mSettings.nomsg.addSuppression(suppr);
182+
suppressions.addSuppression(suppr);
183183
}
184184
}
185185
}
@@ -189,10 +189,10 @@ void Preprocessor::inlineSuppressions(const simplecpp::TokenList &tokens)
189189
if (!mSettings.inlineSuppressions)
190190
return;
191191
std::list<BadInlineSuppression> err;
192-
::addinlineSuppressions(tokens, mSettings, err);
192+
::addinlineSuppressions(tokens, mSettings, mSuppressions, err);
193193
for (std::map<std::string,simplecpp::TokenList*>::const_iterator it = mTokenLists.cbegin(); it != mTokenLists.cend(); ++it) {
194194
if (it->second)
195-
::addinlineSuppressions(*it->second, mSettings, err);
195+
::addinlineSuppressions(*it->second, mSettings, mSuppressions, err);
196196
}
197197
for (const BadInlineSuppression &bad : err) {
198198
error(bad.location.file(), bad.location.line, bad.errmsg);
@@ -842,7 +842,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
842842
errorMessage.errorId = errorId;
843843
errorMessage.setFileName(std::move(fname));
844844
errorMessage.lineNumber = linenr;
845-
if (mSettings.nomsg.isSuppressed(errorMessage))
845+
if (mSuppressions.isSuppressed(errorMessage))
846846
return;
847847

848848
if (mErrorLogger) {
@@ -866,7 +866,8 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
866866
void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
867867
{
868868
Settings settings2(*settings);
869-
Preprocessor preprocessor(settings2, errorLogger);
869+
Suppressions supressions2;
870+
Preprocessor preprocessor(settings2, supressions2, errorLogger);
870871
preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader);
871872
preprocessor.missingInclude(emptyString, 1, emptyString, SystemHeader);
872873
preprocessor.error(emptyString, 1, "#error message"); // #error ..

lib/preprocessor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
class ErrorLogger;
3737
class Settings;
38+
class Suppressions;
3839

3940
/**
4041
* @brief A preprocessor directive
@@ -83,7 +84,7 @@ class CPPCHECKLIB Preprocessor {
8384
/** character that is inserted in expanded macros */
8485
static char macroChar;
8586

86-
explicit Preprocessor(Settings& settings, ErrorLogger *errorLogger = nullptr);
87+
explicit Preprocessor(const Settings& settings, Suppressions &suppressions, ErrorLogger *errorLogger = nullptr);
8788
virtual ~Preprocessor();
8889

8990
void inlineSuppressions(const simplecpp::TokenList &tokens);
@@ -187,7 +188,8 @@ class CPPCHECKLIB Preprocessor {
187188
void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType);
188189
void error(const std::string &filename, unsigned int linenr, const std::string &msg);
189190

190-
Settings& mSettings;
191+
const Settings& mSettings;
192+
Suppressions &mSuppressions;
191193
ErrorLogger *mErrorLogger;
192194

193195
/** list of all directives met while preprocessing file */

test/testclass.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class TestClass : public TestFixture {
259259
Settings settings;
260260
settings.severity.enable(Severity::warning);
261261

262-
Preprocessor preprocessor(settings, nullptr);
262+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
263263

264264
// Tokenize..
265265
Tokenizer tokenizer(&settings, this, &preprocessor);
@@ -365,7 +365,7 @@ class TestClass : public TestFixture {
365365
// Clear the error log
366366
errout.str("");
367367

368-
Preprocessor preprocessor(settings0, nullptr);
368+
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);
369369

370370
// Tokenize..
371371
Tokenizer tokenizer(&settings0, this, &preprocessor);
@@ -519,7 +519,7 @@ class TestClass : public TestFixture {
519519
// Clear the error log
520520
errout.str("");
521521

522-
Preprocessor preprocessor(settings1, nullptr);
522+
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);
523523

524524
// Tokenize..
525525
Tokenizer tokenizer(&settings1, this, &preprocessor);
@@ -682,7 +682,7 @@ class TestClass : public TestFixture {
682682
// Clear the error log
683683
errout.str("");
684684

685-
Preprocessor preprocessor(settings0, nullptr);
685+
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);
686686

687687
// Tokenize..
688688
Tokenizer tokenizer(&settings0, this, &preprocessor);
@@ -1131,7 +1131,7 @@ class TestClass : public TestFixture {
11311131
// Clear the error log
11321132
errout.str("");
11331133

1134-
Preprocessor preprocessor(settings0, nullptr);
1134+
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);
11351135

11361136
// Tokenize..
11371137
Tokenizer tokenizer(&settings0, this, &preprocessor);
@@ -1607,7 +1607,7 @@ class TestClass : public TestFixture {
16071607
// Clear the error log
16081608
errout.str("");
16091609

1610-
Preprocessor preprocessor(settings1, nullptr);
1610+
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);
16111611

16121612
// Tokenize..
16131613
Tokenizer tokenizer(&settings1, this, &preprocessor);
@@ -2571,7 +2571,7 @@ class TestClass : public TestFixture {
25712571
settings0.certainty.setEnabled(Certainty::inconclusive, inconclusive);
25722572
settings0.severity.enable(Severity::warning);
25732573

2574-
Preprocessor preprocessor(settings0, nullptr);
2574+
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);
25752575

25762576
// Tokenize..
25772577
Tokenizer tokenizer(&settings0, this, &preprocessor);
@@ -2894,7 +2894,7 @@ class TestClass : public TestFixture {
28942894
// Clear the error log
28952895
errout.str("");
28962896

2897-
Preprocessor preprocessor(settings, nullptr);
2897+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
28982898

28992899
// Tokenize..
29002900
Tokenizer tokenizer(&settings, this, &preprocessor);
@@ -3527,7 +3527,7 @@ class TestClass : public TestFixture {
35273527
// Clear the error log
35283528
errout.str("");
35293529

3530-
Preprocessor preprocessor(settings1, nullptr);
3530+
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);
35313531

35323532
// Tokenize..
35333533
Tokenizer tokenizer(&settings1, this, &preprocessor);
@@ -3567,7 +3567,7 @@ class TestClass : public TestFixture {
35673567
s = &settings0;
35683568
s->certainty.setEnabled(Certainty::inconclusive, inconclusive);
35693569

3570-
Preprocessor preprocessor(*s, nullptr);
3570+
Preprocessor preprocessor(*s, s->nomsg, nullptr);
35713571

35723572
// Tokenize..
35733573
Tokenizer tokenizer(s, this, &preprocessor);
@@ -7167,7 +7167,7 @@ class TestClass : public TestFixture {
71677167
// Check..
71687168
settings0.certainty.setEnabled(Certainty::inconclusive, true);
71697169

7170-
Preprocessor preprocessor(settings0, nullptr);
7170+
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);
71717171

71727172
// Tokenize..
71737173
Tokenizer tokenizer(&settings0, this, &preprocessor);
@@ -7205,7 +7205,7 @@ class TestClass : public TestFixture {
72057205
Settings settings;
72067206
settings.severity.enable(Severity::performance);
72077207

7208-
Preprocessor preprocessor(settings, nullptr);
7208+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
72097209

72107210
// Tokenize..
72117211
Tokenizer tokenizer(&settings, this, &preprocessor);
@@ -7419,7 +7419,7 @@ class TestClass : public TestFixture {
74197419
// Clear the error log
74207420
errout.str("");
74217421

7422-
Preprocessor preprocessor(settings0, nullptr);
7422+
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);
74237423

74247424
// Tokenize..
74257425
Tokenizer tokenizer(&settings0, this, &preprocessor);
@@ -7537,7 +7537,7 @@ class TestClass : public TestFixture {
75377537
settings.severity.enable(Severity::warning);
75387538
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
75397539

7540-
Preprocessor preprocessor(settings, nullptr);
7540+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
75417541

75427542
// Tokenize..
75437543
Tokenizer tokenizer(&settings, this, &preprocessor);
@@ -7886,7 +7886,7 @@ class TestClass : public TestFixture {
78867886
Settings settings;
78877887
settings.severity.enable(Severity::style);
78887888

7889-
Preprocessor preprocessor(settings, nullptr);
7889+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
78907890

78917891
// Tokenize..
78927892
Tokenizer tokenizer(&settings, this, &preprocessor);
@@ -8064,7 +8064,7 @@ class TestClass : public TestFixture {
80648064
settings.safeChecks.classes = true;
80658065
settings.severity.enable(Severity::warning);
80668066

8067-
Preprocessor preprocessor(settings, nullptr);
8067+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
80688068

80698069
// Tokenize..
80708070
Tokenizer tokenizer(&settings, this, &preprocessor);
@@ -8087,7 +8087,7 @@ class TestClass : public TestFixture {
80878087
// Clear the error log
80888088
errout.str("");
80898089

8090-
Preprocessor preprocessor(settings1, nullptr);
8090+
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);
80918091

80928092
// Tokenize..
80938093
Tokenizer tokenizer(&settings1, this, &preprocessor);
@@ -8286,7 +8286,7 @@ class TestClass : public TestFixture {
82868286
// Clear the error log
82878287
errout.str("");
82888288

8289-
Preprocessor preprocessor(settings1, nullptr);
8289+
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);
82908290

82918291
// Tokenize..
82928292
Tokenizer tokenizer(&settings1, this, &preprocessor);

test/testcondition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class TestCondition : public TestFixture {
155155
std::map<std::string, simplecpp::TokenList*> filedata;
156156
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
157157

158-
Preprocessor preprocessor(*settings, nullptr);
158+
Preprocessor preprocessor(*settings, settings->nomsg, nullptr);
159159
preprocessor.setDirectives(tokens1);
160160

161161
// Tokenizer..

test/testgarbage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class TestGarbage : public TestFixture {
287287
std::string checkCodeInternal_(const std::string &code, const char* filename, const char* file, int line) {
288288
errout.str("");
289289

290-
Preprocessor preprocessor(settings, nullptr);
290+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
291291

292292
// tokenize..
293293
Tokenizer tokenizer(&settings, this, &preprocessor);

test/testother.cpp

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

309-
Preprocessor preprocessor(*settings, nullptr);
309+
Preprocessor preprocessor(*settings, settings->nomsg, nullptr);
310310

311311
// Tokenize..
312312
Tokenizer tokenizer(settings, this, &preprocessor);
@@ -347,7 +347,7 @@ class TestOther : public TestFixture {
347347
std::map<std::string, simplecpp::TokenList*> filedata;
348348
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
349349

350-
Preprocessor preprocessor(*settings, nullptr);
350+
Preprocessor preprocessor(*settings, settings->nomsg, nullptr);
351351
preprocessor.setDirectives(tokens1);
352352

353353
// Tokenizer..
@@ -1548,7 +1548,7 @@ class TestOther : public TestFixture {
15481548
settings.severity.enable(Severity::style);
15491549
settings.standards.cpp = Standards::CPP03; // #5560
15501550

1551-
Preprocessor preprocessor(settings, nullptr);
1551+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
15521552

15531553
// Tokenize..
15541554
Tokenizer tokenizerCpp(&settings, this, &preprocessor);
@@ -1754,7 +1754,7 @@ class TestOther : public TestFixture {
17541754
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
17551755
settings.platform.defaultSign = 's';
17561756

1757-
Preprocessor preprocessor(settings, nullptr);
1757+
Preprocessor preprocessor(settings, settings.nomsg, nullptr);
17581758

17591759
// Tokenize..
17601760
Tokenizer tokenizer(&settings, this, &preprocessor);

0 commit comments

Comments
 (0)