Skip to content

Commit 9780847

Browse files
authored
put the suppressions together in a single type / renamed individual one to SuppressionList (#6004)
1 parent c40a92a commit 9780847

41 files changed

Lines changed: 252 additions & 250 deletions

Some content is hidden

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

cli/cmdlineparser.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ namespace {
135135
};
136136
}
137137

138-
CmdLineParser::CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions, Suppressions &suppressionsNoFail)
138+
CmdLineParser::CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions)
139139
: mLogger(logger)
140140
, mSettings(settings)
141141
, mSuppressions(suppressions)
142-
, mSuppressionsNoFail(suppressionsNoFail)
143142
{}
144143

145144
bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
@@ -625,7 +624,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
625624
mLogger.printError("couldn't open the file: \"" + filename + "\".");
626625
return Result::Fail;
627626
}
628-
const std::string errmsg(mSuppressionsNoFail.parseFile(f));
627+
const std::string errmsg(mSuppressions.nofail.parseFile(f));
629628
if (!errmsg.empty()) {
630629
mLogger.printError(errmsg);
631630
return Result::Fail;
@@ -1139,7 +1138,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11391138

11401139
else if (std::strncmp(argv[i], "--suppress=", 11) == 0) {
11411140
const std::string suppression = argv[i]+11;
1142-
const std::string errmsg(mSuppressions.addSuppressionLine(suppression));
1141+
const std::string errmsg(mSuppressions.nomsg.addSuppressionLine(suppression));
11431142
if (!errmsg.empty()) {
11441143
mLogger.printError(errmsg);
11451144
return Result::Fail;
@@ -1166,7 +1165,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11661165
mLogger.printError(message);
11671166
return Result::Fail;
11681167
}
1169-
const std::string errmsg(mSuppressions.parseFile(f));
1168+
const std::string errmsg(mSuppressions.nomsg.parseFile(f));
11701169
if (!errmsg.empty()) {
11711170
mLogger.printError(errmsg);
11721171
return Result::Fail;
@@ -1175,7 +1174,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11751174

11761175
else if (std::strncmp(argv[i], "--suppress-xml=", 15) == 0) {
11771176
const char * filename = argv[i] + 15;
1178-
const std::string errmsg(mSuppressions.parseXmlFile(filename));
1177+
const std::string errmsg(mSuppressions.nomsg.parseXmlFile(filename));
11791178
if (!errmsg.empty()) {
11801179
mLogger.printError(errmsg);
11811180
return Result::Fail;

cli/cmdlineparser.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "utils.h"
3131

3232
class Settings;
33-
class Suppressions;
33+
struct Suppressions;
3434
class Library;
3535

3636
/// @addtogroup CLI
@@ -53,9 +53,8 @@ class CmdLineParser {
5353
* @param settings Settings instance that will be modified according to
5454
* options user has given.
5555
* @param suppressions Suppressions instance that keeps the suppressions
56-
* @param suppressionsNoFail Suppressions instance that keeps the "do not fail" suppressions
5756
*/
58-
CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions, Suppressions &suppressionsNoFail);
57+
CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions);
5958

6059
enum class Result { Success, Exit, Fail };
6160

@@ -160,7 +159,6 @@ class CmdLineParser {
160159
std::vector<std::string> mIgnoredPaths;
161160
Settings &mSettings;
162161
Suppressions &mSuppressions;
163-
Suppressions &mSuppressionsNoFail;
164162
std::string mVSConfig;
165163
};
166164

cli/cppcheckexecutor.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
180180
{
181181
Settings settings;
182182
CmdLineLoggerStd logger;
183-
CmdLineParser parser(logger, settings, settings.nomsg, settings.nofail);
183+
CmdLineParser parser(logger, settings, settings.supprs);
184184
if (!parser.fillSettingsFromArgs(argc, argv)) {
185185
return EXIT_FAILURE;
186186
}
@@ -212,10 +212,10 @@ int CppCheckExecutor::check_wrapper(const Settings& settings)
212212
return check_internal(settings);
213213
}
214214

215-
bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
215+
bool CppCheckExecutor::reportSuppressions(const Settings &settings, const SuppressionList& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
216216
const auto& suppr = suppressions.getSuppressions();
217-
if (std::any_of(suppr.begin(), suppr.end(), [](const Suppressions::Suppression& s) {
218-
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
217+
if (std::any_of(suppr.begin(), suppr.end(), [](const SuppressionList::Suppression& s) {
218+
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == SuppressionList::Suppression::NO_LINE;
219219
}))
220220
return false;
221221

@@ -225,16 +225,16 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppre
225225
assert(!(!files.empty() && !fileSettings.empty()));
226226

227227
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
228-
err |= Suppressions::reportUnmatchedSuppressions(
228+
err |= SuppressionList::reportUnmatchedSuppressions(
229229
suppressions.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
230230
}
231231

232232
for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
233-
err |= Suppressions::reportUnmatchedSuppressions(
233+
err |= SuppressionList::reportUnmatchedSuppressions(
234234
suppressions.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
235235
}
236236
}
237-
err |= Suppressions::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
237+
err |= SuppressionList::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
238238
return err;
239239
}
240240

@@ -264,7 +264,7 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
264264

265265
CppCheck cppcheck(stdLogger, true, executeCommand);
266266
cppcheck.settings() = settings; // this is a copy
267-
auto& suppressions = cppcheck.settings().nomsg;
267+
auto& suppressions = cppcheck.settings().supprs.nomsg;
268268

269269
unsigned int returnValue;
270270
if (settings.useSingleJob()) {
@@ -312,7 +312,7 @@ void StdLogger::writeCheckersReport()
312312
CheckersReport checkersReport(mSettings, mActiveCheckers);
313313

314314
bool suppressed = false;
315-
for (const Suppressions::Suppression& s : mSettings.nomsg.getSuppressions()) {
315+
for (const SuppressionList::Suppression& s : mSettings.supprs.nomsg.getSuppressions()) {
316316
if (s.errorId == "checkersReport")
317317
suppressed = true;
318318
}

cli/cppcheckexecutor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class Settings;
3232
class ErrorLogger;
33-
class Suppressions;
33+
class SuppressionList;
3434

3535
/**
3636
* This class works as an example of how CppCheck can be used in external
@@ -81,7 +81,7 @@ class CppCheckExecutor {
8181

8282
protected:
8383

84-
static bool reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger);
84+
static bool reportSuppressions(const Settings &settings, const SuppressionList& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger);
8585

8686
/**
8787
* Wrapper around check_internal

cli/executor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
struct FileSettings;
3232

33-
Executor::Executor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
33+
Executor::Executor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger)
3434
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
3535
{
3636
// the two inputs may only be used exclusively

cli/executor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
class Settings;
3030
class ErrorLogger;
3131
class ErrorMessage;
32-
class Suppressions;
32+
class SuppressionList;
3333
struct FileSettings;
3434

3535
/// @addtogroup CLI
@@ -41,7 +41,7 @@ struct FileSettings;
4141
*/
4242
class Executor {
4343
public:
44-
Executor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
44+
Executor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger);
4545
virtual ~Executor() = default;
4646

4747
Executor(const Executor &) = delete;
@@ -70,7 +70,7 @@ class Executor {
7070
const std::list<std::pair<std::string, std::size_t>> &mFiles;
7171
const std::list<FileSettings>& mFileSettings;
7272
const Settings &mSettings;
73-
Suppressions &mSuppressions;
73+
SuppressionList &mSuppressions;
7474
ErrorLogger &mErrorLogger;
7575

7676
private:

cli/processexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ enum class Color;
6161
using std::memset;
6262

6363

64-
ProcessExecutor::ProcessExecutor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
64+
ProcessExecutor::ProcessExecutor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
6565
: Executor(files, fileSettings, settings, suppressions, errorLogger)
6666
, mExecuteCommand(std::move(executeCommand))
6767
{

cli/processexecutor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class Settings;
3131
class ErrorLogger;
32-
class Suppressions;
32+
class SuppressionList;
3333
struct FileSettings;
3434

3535
/// @addtogroup CLI
@@ -41,7 +41,7 @@ struct FileSettings;
4141
*/
4242
class ProcessExecutor : public Executor {
4343
public:
44-
ProcessExecutor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
44+
ProcessExecutor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
4545
ProcessExecutor(const ProcessExecutor &) = delete;
4646
ProcessExecutor& operator=(const ProcessExecutor &) = delete;
4747

cli/singleexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class ErrorLogger;
3232

33-
SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
33+
SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger)
3434
: Executor(files, fileSettings, settings, suppressions, errorLogger)
3535
, mCppcheck(cppcheck)
3636
{

cli/singleexecutor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
class ErrorLogger;
3030
class Settings;
3131
class CppCheck;
32-
class Suppressions;
32+
class SuppressionList;
3333
struct FileSettings;
3434

3535
class SingleExecutor : public Executor
3636
{
3737
public:
38-
SingleExecutor(CppCheck &cppcheck, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
38+
SingleExecutor(CppCheck &cppcheck, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger);
3939
SingleExecutor(const SingleExecutor &) = delete;
4040
SingleExecutor& operator=(const SingleExecutor &) = delete;
4141

0 commit comments

Comments
 (0)