Skip to content

Commit

Permalink
cleaned up CppCheck usage in GUI code
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Nov 20, 2024
1 parent 8f40b82 commit 0d246a9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
28 changes: 15 additions & 13 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <list>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include <QByteArray>
Expand Down Expand Up @@ -106,15 +107,13 @@ int CheckThread::executeCommand(std::string exe, std::vector<std::string> args,


CheckThread::CheckThread(ThreadResult &result) :
mResult(result),
mCppcheck(result, true, executeCommand)
mResult(result)
{}

void CheckThread::check(const Settings &settings)
void CheckThread::setSettings(const Settings &settings)
{
mFiles.clear();
mCppcheck.settings() = settings;
start();
mSettings = settings; // this is a copy
}

void CheckThread::analyseWholeProgram(const QStringList &files, const std::string& ctuInfo)
Expand All @@ -130,6 +129,9 @@ void CheckThread::run()
{
mState = Running;

CppCheck cppcheck(mResult, true, executeCommand);
cppcheck.settings() = std::move(mSettings);

if (!mFiles.isEmpty() || mAnalyseWholeProgram) {
mAnalyseWholeProgram = false;
std::string ctuInfo;
Expand All @@ -139,7 +141,7 @@ void CheckThread::run()
std::transform(mFiles.cbegin(), mFiles.cend(), std::back_inserter(files2), [&](const QString& file) {
return FileWithDetails{file.toStdString(), 0};
});
mCppcheck.analyseWholeProgram(mCppcheck.settings().buildDir, files2, {}, ctuInfo);
cppcheck.analyseWholeProgram(cppcheck.settings().buildDir, files2, {}, ctuInfo);
mFiles.clear();
emit done();
return;
Expand All @@ -148,8 +150,8 @@ void CheckThread::run()
QString file = mResult.getNextFile();
while (!file.isEmpty() && mState == Running) {
qDebug() << "Checking file" << file;
mCppcheck.check(FileWithDetails(file.toStdString()));
runAddonsAndTools(nullptr, file);
cppcheck.check(FileWithDetails(file.toStdString()));
runAddonsAndTools(cppcheck.settings(), nullptr, file);
emit fileChecked(file);

if (mState == Running)
Expand All @@ -161,8 +163,8 @@ void CheckThread::run()
while (fileSettings && mState == Running) {
file = QString::fromStdString(fileSettings->filename());
qDebug() << "Checking file" << file;
mCppcheck.check(*fileSettings);
runAddonsAndTools(fileSettings, QString::fromStdString(fileSettings->filename()));
cppcheck.check(*fileSettings);
runAddonsAndTools(cppcheck.settings(), fileSettings, QString::fromStdString(fileSettings->filename()));
emit fileChecked(file);

if (mState == Running)
Expand All @@ -177,7 +179,7 @@ void CheckThread::run()
emit done();
}

void CheckThread::runAddonsAndTools(const FileSettings *fileSettings, const QString &fileName)
void CheckThread::runAddonsAndTools(const Settings& settings, const FileSettings *fileSettings, const QString &fileName)
{
for (const QString& addon : mAddonsAndTools) {
if (addon == CLANG_ANALYZER || addon == CLANG_TIDY) {
Expand Down Expand Up @@ -229,15 +231,15 @@ void CheckThread::runAddonsAndTools(const FileSettings *fileSettings, const QStr
args << ("-std=" + QString::fromStdString(fileSettings->standard));
else {
// TODO: pass C or C++ standard based on file type
const std::string std = mCppcheck.settings().standards.getCPP();
const std::string std = settings.standards.getCPP();
if (!std.empty()) {
args << ("-std=" + QString::fromStdString(std));
}
}

QString analyzerInfoFile;

const std::string &buildDir = mCppcheck.settings().buildDir;
const std::string &buildDir = settings.buildDir;
if (!buildDir.empty()) {
analyzerInfoFile = QString::fromStdString(AnalyzerInformation::getAnalyzerInfoFile(buildDir, fileSettings->filename(), fileSettings->cfg));

Expand Down
13 changes: 5 additions & 8 deletions gui/checkthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef CHECKTHREAD_H
#define CHECKTHREAD_H

#include "cppcheck.h"
#include "settings.h"
#include "suppressions.h"

#include <atomic>
Expand All @@ -34,7 +34,6 @@
#include <QStringList>
#include <QThread>

class Settings;
class ThreadResult;
struct FileSettings;

Expand All @@ -55,7 +54,7 @@ class CheckThread : public QThread {
*
* @param settings settings for cppcheck
*/
void check(const Settings &settings);
void setSettings(const Settings &settings);

/**
* @brief Run whole program analysis
Expand Down Expand Up @@ -130,13 +129,11 @@ class CheckThread : public QThread {
std::atomic<State> mState{Ready};

ThreadResult &mResult;
/**
* @brief Cppcheck itself
*/
CppCheck mCppcheck;

Settings mSettings;

private:
void runAddonsAndTools(const FileSettings *fileSettings, const QString &fileName);
void runAddonsAndTools(const Settings& settings, const FileSettings *fileSettings, const QString &fileName);

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

Expand Down
3 changes: 2 additions & 1 deletion gui/threadhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void ThreadHandler::check(const Settings &settings)
mThreads[i]->setAddonsAndTools(addonsAndTools);
mThreads[i]->setSuppressions(mSuppressions);
mThreads[i]->setClangIncludePaths(mClangIncludePaths);
mThreads[i]->check(settings);
mThreads[i]->setSettings(settings);
mThreads[i]->start();
}

// Date and time when checking starts..
Expand Down
1 change: 1 addition & 0 deletions gui/threadhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "threadresult.h"

#include <set>
#include <string>

#include <QDateTime>
#include <QElapsedTimer>
Expand Down

0 comments on commit 0d246a9

Please sign in to comment.