Skip to content

Commit

Permalink
put the suppressions together in a single type / renamed individual o…
Browse files Browse the repository at this point in the history
…ne to `SuppressionList` (#6004)
  • Loading branch information
firewave committed Feb 24, 2024
1 parent c40a92a commit 9780847
Show file tree
Hide file tree
Showing 41 changed files with 252 additions and 250 deletions.
11 changes: 5 additions & 6 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ namespace {
};
}

CmdLineParser::CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions, Suppressions &suppressionsNoFail)
CmdLineParser::CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions)
: mLogger(logger)
, mSettings(settings)
, mSuppressions(suppressions)
, mSuppressionsNoFail(suppressionsNoFail)
{}

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

else if (std::strncmp(argv[i], "--suppress=", 11) == 0) {
const std::string suppression = argv[i]+11;
const std::string errmsg(mSuppressions.addSuppressionLine(suppression));
const std::string errmsg(mSuppressions.nomsg.addSuppressionLine(suppression));
if (!errmsg.empty()) {
mLogger.printError(errmsg);
return Result::Fail;
Expand All @@ -1166,7 +1165,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mLogger.printError(message);
return Result::Fail;
}
const std::string errmsg(mSuppressions.parseFile(f));
const std::string errmsg(mSuppressions.nomsg.parseFile(f));
if (!errmsg.empty()) {
mLogger.printError(errmsg);
return Result::Fail;
Expand All @@ -1175,7 +1174,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a

else if (std::strncmp(argv[i], "--suppress-xml=", 15) == 0) {
const char * filename = argv[i] + 15;
const std::string errmsg(mSuppressions.parseXmlFile(filename));
const std::string errmsg(mSuppressions.nomsg.parseXmlFile(filename));
if (!errmsg.empty()) {
mLogger.printError(errmsg);
return Result::Fail;
Expand Down
6 changes: 2 additions & 4 deletions cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "utils.h"

class Settings;
class Suppressions;
struct Suppressions;
class Library;

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

enum class Result { Success, Exit, Fail };

Expand Down Expand Up @@ -160,7 +159,6 @@ class CmdLineParser {
std::vector<std::string> mIgnoredPaths;
Settings &mSettings;
Suppressions &mSuppressions;
Suppressions &mSuppressionsNoFail;
std::string mVSConfig;
};

Expand Down
18 changes: 9 additions & 9 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
{
Settings settings;
CmdLineLoggerStd logger;
CmdLineParser parser(logger, settings, settings.nomsg, settings.nofail);
CmdLineParser parser(logger, settings, settings.supprs);
if (!parser.fillSettingsFromArgs(argc, argv)) {
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -212,10 +212,10 @@ int CppCheckExecutor::check_wrapper(const Settings& settings)
return check_internal(settings);
}

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) {
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) {
const auto& suppr = suppressions.getSuppressions();
if (std::any_of(suppr.begin(), suppr.end(), [](const Suppressions::Suppression& s) {
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
if (std::any_of(suppr.begin(), suppr.end(), [](const SuppressionList::Suppression& s) {
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == SuppressionList::Suppression::NO_LINE;
}))
return false;

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

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

for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
err |= Suppressions::reportUnmatchedSuppressions(
err |= SuppressionList::reportUnmatchedSuppressions(
suppressions.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
}
}
err |= Suppressions::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
err |= SuppressionList::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
return err;
}

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

CppCheck cppcheck(stdLogger, true, executeCommand);
cppcheck.settings() = settings; // this is a copy
auto& suppressions = cppcheck.settings().nomsg;
auto& suppressions = cppcheck.settings().supprs.nomsg;

unsigned int returnValue;
if (settings.useSingleJob()) {
Expand Down Expand Up @@ -312,7 +312,7 @@ void StdLogger::writeCheckersReport()
CheckersReport checkersReport(mSettings, mActiveCheckers);

bool suppressed = false;
for (const Suppressions::Suppression& s : mSettings.nomsg.getSuppressions()) {
for (const SuppressionList::Suppression& s : mSettings.supprs.nomsg.getSuppressions()) {
if (s.errorId == "checkersReport")
suppressed = true;
}
Expand Down
4 changes: 2 additions & 2 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class Settings;
class ErrorLogger;
class Suppressions;
class SuppressionList;

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

protected:

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);
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);

/**
* Wrapper around check_internal
Expand Down
2 changes: 1 addition & 1 deletion cli/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

struct FileSettings;

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)
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)
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
{
// the two inputs may only be used exclusively
Expand Down
6 changes: 3 additions & 3 deletions cli/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class Settings;
class ErrorLogger;
class ErrorMessage;
class Suppressions;
class SuppressionList;
struct FileSettings;

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

Executor(const Executor &) = delete;
Expand Down Expand Up @@ -70,7 +70,7 @@ class Executor {
const std::list<std::pair<std::string, std::size_t>> &mFiles;
const std::list<FileSettings>& mFileSettings;
const Settings &mSettings;
Suppressions &mSuppressions;
SuppressionList &mSuppressions;
ErrorLogger &mErrorLogger;

private:
Expand Down
2 changes: 1 addition & 1 deletion cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum class Color;
using std::memset;


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)
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)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
, mExecuteCommand(std::move(executeCommand))
{
Expand Down
4 changes: 2 additions & 2 deletions cli/processexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class Settings;
class ErrorLogger;
class Suppressions;
class SuppressionList;
struct FileSettings;

/// @addtogroup CLI
Expand All @@ -41,7 +41,7 @@ struct FileSettings;
*/
class ProcessExecutor : public Executor {
public:
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);
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);
ProcessExecutor(const ProcessExecutor &) = delete;
ProcessExecutor& operator=(const ProcessExecutor &) = delete;

Expand Down
2 changes: 1 addition & 1 deletion cli/singleexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class ErrorLogger;

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)
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)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
, mCppcheck(cppcheck)
{
Expand Down
4 changes: 2 additions & 2 deletions cli/singleexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
class ErrorLogger;
class Settings;
class CppCheck;
class Suppressions;
class SuppressionList;
struct FileSettings;

class SingleExecutor : public Executor
{
public:
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);
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);
SingleExecutor(const SingleExecutor &) = delete;
SingleExecutor& operator=(const SingleExecutor &) = delete;

Expand Down
2 changes: 1 addition & 1 deletion cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

enum class Color;

ThreadExecutor::ThreadExecutor(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)
ThreadExecutor::ThreadExecutor(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)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
, mExecuteCommand(std::move(executeCommand))
{
Expand Down
4 changes: 2 additions & 2 deletions cli/threadexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class Settings;
class ErrorLogger;
class Suppressions;
class SuppressionList;
struct FileSettings;

/// @addtogroup CLI
Expand All @@ -43,7 +43,7 @@ class ThreadExecutor : public Executor {
friend class SyncLogForwarder;

public:
ThreadExecutor(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);
ThreadExecutor(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);
ThreadExecutor(const ThreadExecutor &) = delete;
ThreadExecutor& operator=(const ThreadExecutor &) = delete;

Expand Down
6 changes: 3 additions & 3 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
for (const ErrorItem &e : errorItems) {
if (e.errorPath.isEmpty())
continue;
Suppressions::ErrorMessage errorMessage;
SuppressionList::ErrorMessage errorMessage;
errorMessage.setFileName(e.errorPath.back().file.toStdString());
errorMessage.lineNumber = e.errorPath.back().line;
errorMessage.errorId = e.errorId.toStdString();
Expand All @@ -410,9 +410,9 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
}
}

bool CheckThread::isSuppressed(const Suppressions::ErrorMessage &errorMessage) const
bool CheckThread::isSuppressed(const SuppressionList::ErrorMessage &errorMessage) const
{
return std::any_of(mSuppressions.cbegin(), mSuppressions.cend(), [&](const Suppressions::Suppression& s) {
return std::any_of(mSuppressions.cbegin(), mSuppressions.cend(), [&](const SuppressionList::Suppression& s) {
return s.isSuppressed(errorMessage);
});
}
Expand Down
6 changes: 3 additions & 3 deletions gui/checkthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CheckThread : public QThread {
mClangIncludePaths = s;
}

void setSuppressions(const QList<Suppressions::Suppression> &s) {
void setSuppressions(const QList<SuppressionList::Suppression> &s) {
mSuppressions = s;
}

Expand Down Expand Up @@ -136,13 +136,13 @@ class CheckThread : public QThread {

void parseClangErrors(const QString &tool, const QString &file0, QString err);

bool isSuppressed(const Suppressions::ErrorMessage &errorMessage) const;
bool isSuppressed(const SuppressionList::ErrorMessage &errorMessage) const;

QStringList mFiles;
bool mAnalyseWholeProgram{};
QStringList mAddonsAndTools;
QStringList mClangIncludePaths;
QList<Suppressions::Suppression> mSuppressions;
QList<SuppressionList::Suppression> mSuppressions;
};
/// @}
#endif // CHECKTHREAD_H
10 changes: 5 additions & 5 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
mThread->setFiles(fileNames);
if (mProjectFile && !checkConfiguration)
mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools());
mThread->setSuppressions(mProjectFile ? mProjectFile->getSuppressions() : QList<Suppressions::Suppression>());
mThread->setSuppressions(mProjectFile ? mProjectFile->getSuppressions() : QList<SuppressionList::Suppression>());
QDir inf(mCurrentDirectory);
const QString checkPath = inf.canonicalPath();
setPath(SETTINGS_LAST_CHECK_PATH, checkPath);
Expand Down Expand Up @@ -1021,8 +1021,8 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
tryLoadLibrary(&result.library, filename);
}

for (const Suppressions::Suppression &suppression : mProjectFile->getSuppressions()) {
result.nomsg.addSuppression(suppression);
for (const SuppressionList::Suppression &suppression : mProjectFile->getSuppressions()) {
result.supprs.nomsg.addSuppression(suppression);
}

// Only check the given -D configuration
Expand Down Expand Up @@ -2066,7 +2066,7 @@ void MainWindow::suppressIds(QStringList ids)
return;
ids.removeDuplicates();

QList<Suppressions::Suppression> suppressions = mProjectFile->getSuppressions();
QList<SuppressionList::Suppression> suppressions = mProjectFile->getSuppressions();
for (const QString& id : ids) {
// Remove all matching suppressions
std::string id2 = id.toStdString();
Expand All @@ -2077,7 +2077,7 @@ void MainWindow::suppressIds(QStringList ids)
++i;
}

Suppressions::Suppression newSuppression;
SuppressionList::Suppression newSuppression;
newSuppression.errorId = id2;
suppressions << newSuppression;
}
Expand Down
6 changes: 3 additions & 3 deletions gui/newsuppressiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ NewSuppressionDialog::~NewSuppressionDialog()
delete mUI;
}

Suppressions::Suppression NewSuppressionDialog::getSuppression() const
SuppressionList::Suppression NewSuppressionDialog::getSuppression() const
{
Suppressions::Suppression ret;
SuppressionList::Suppression ret;
ret.errorId = mUI->mComboErrorId->currentText().toStdString();
if (ret.errorId.empty())
ret.errorId = "*";
Expand All @@ -75,7 +75,7 @@ Suppressions::Suppression NewSuppressionDialog::getSuppression() const
return ret;
}

void NewSuppressionDialog::setSuppression(const Suppressions::Suppression &suppression)
void NewSuppressionDialog::setSuppression(const SuppressionList::Suppression &suppression)
{
setWindowTitle(tr("Edit suppression"));
mUI->mComboErrorId->setCurrentText(QString::fromStdString(suppression.errorId));
Expand Down
4 changes: 2 additions & 2 deletions gui/newsuppressiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class NewSuppressionDialog : public QDialog {
* @brief Translate the user input in the GUI into a suppression
* @return Cppcheck suppression
*/
Suppressions::Suppression getSuppression() const;
SuppressionList::Suppression getSuppression() const;

/**
* @brief Update the GUI so it corresponds with the given
* Cppcheck suppression
* @param suppression Cppcheck suppression
*/
void setSuppression(const Suppressions::Suppression &suppression);
void setSuppression(const SuppressionList::Suppression &suppression);

private:
Ui::NewSuppressionDialog *mUI;
Expand Down
Loading

0 comments on commit 9780847

Please sign in to comment.