Skip to content

Commit

Permalink
made check.h less heavy (danmar#2633)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored May 23, 2020
1 parent 0832830 commit 37bc048
Show file tree
Hide file tree
Showing 91 changed files with 855 additions and 765 deletions.
232 changes: 118 additions & 114 deletions Makefile

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <cstring>
#include <iostream>
#include <list>
#include <memory>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -106,9 +107,9 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c

if (parser.getShowErrorMessages()) {
mShowAllErrors = true;
std::cout << ErrorLogger::ErrorMessage::getXMLHeader();
std::cout << ErrorMessage::getXMLHeader();
cppcheck->getErrorMessages();
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
std::cout << ErrorMessage::getXMLFooter() << std::endl;
}

if (parser.exitAfterPrinting()) {
Expand Down Expand Up @@ -851,8 +852,8 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
for (const std::string &lib : settings.libraries) {
if (!tryLoadLibrary(settings.library, argv[0], lib.c_str())) {
const std::string msg("Failed to load the library " + lib);
const std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
ErrorLogger::ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", false);
const std::list<ErrorMessage::FileLocation> callstack;
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", false);
reportErr(errmsg);
return EXIT_FAILURE;
}
Expand All @@ -866,7 +867,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
windows = tryLoadLibrary(settings.library, argv[0], "windows.cfg");

if (!std || !posix || !windows) {
const std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
const std::list<ErrorMessage::FileLocation> callstack;
const std::string msg("Failed to load " + std::string(!std ? "std.cfg" : !posix ? "posix.cfg" : "windows.cfg") + ". Your Cppcheck installation is broken, please re-install.");
#ifdef FILESDIR
const std::string details("The Cppcheck binary was compiled with FILESDIR set to \""
Expand All @@ -878,7 +879,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
"std.cfg should be available in " + cfgfolder + " or the FILESDIR "
"should be configured.");
#endif
ErrorLogger::ErrorMessage errmsg(callstack, emptyString, Severity::information, msg+" "+details, "failedToLoadCfg", false);
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg+" "+details, "failedToLoadCfg", false);
reportErr(errmsg);
return EXIT_FAILURE;
}
Expand All @@ -891,7 +892,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
}

if (settings.xml) {
reportErr(ErrorLogger::ErrorMessage::getXMLHeader());
reportErr(ErrorMessage::getXMLHeader());
}

if (!settings.buildDir.empty()) {
Expand Down Expand Up @@ -980,24 +981,24 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
cppcheck.tooManyConfigsError("",0U);

if (settings.isEnabled(Settings::MISSING_INCLUDE) && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) {
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
ErrorLogger::ErrorMessage msg(callStack,
emptyString,
Severity::information,
"Cppcheck cannot find all the include files (use --check-config for details)\n"
"Cppcheck cannot find all the include files. Cppcheck can check the code without the "
"include files found. But the results will probably be more accurate if all the include "
"files are found. Please check your project's include directories and add all of them "
"as include directories for Cppcheck. To see what files Cppcheck cannot find use "
"--check-config.",
Preprocessor::missingIncludeFlag ? "missingInclude" : "missingIncludeSystem",
false);
const std::list<ErrorMessage::FileLocation> callStack;
ErrorMessage msg(callStack,
emptyString,
Severity::information,
"Cppcheck cannot find all the include files (use --check-config for details)\n"
"Cppcheck cannot find all the include files. Cppcheck can check the code without the "
"include files found. But the results will probably be more accurate if all the include "
"files are found. Please check your project's include directories and add all of them "
"as include directories for Cppcheck. To see what files Cppcheck cannot find use "
"--check-config.",
Preprocessor::missingIncludeFlag ? "missingInclude" : "missingIncludeSystem",
false);
reportInfo(msg);
}
}

if (settings.xml) {
reportErr(ErrorLogger::ErrorMessage::getXMLFooter());
reportErr(ErrorMessage::getXMLFooter());
}

mSettings = nullptr;
Expand Down Expand Up @@ -1072,7 +1073,7 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
}
}

void CppCheckExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
void CppCheckExecutor::reportInfo(const ErrorMessage &msg)
{
reportErr(msg);
}
Expand All @@ -1089,7 +1090,7 @@ void CppCheckExecutor::reportStatus(std::size_t fileindex, std::size_t filecount
}
}

void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
void CppCheckExecutor::reportErr(const ErrorMessage &msg)
{
if (mShowAllErrors) {
reportOut(msg.toXML());
Expand Down
4 changes: 2 additions & 2 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ class CppCheckExecutor : public ErrorLogger {
void reportOut(const std::string &outmsg) OVERRIDE;

/** xml output of errors */
void reportErr(const ErrorLogger::ErrorMessage &msg) OVERRIDE;
void reportErr(const ErrorMessage &msg) OVERRIDE;

void reportProgress(const std::string &filename, const char stage[], const std::size_t value) OVERRIDE;

/**
* Output information messages.
*/
void reportInfo(const ErrorLogger::ErrorMessage &msg) OVERRIDE;
void reportInfo(const ErrorMessage &msg) OVERRIDE;

void bughuntingReport(const std::string &str) OVERRIDE;

Expand Down
30 changes: 15 additions & 15 deletions cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int ThreadExecutor::handleRead(int rpipe, unsigned int &result)
if (type == REPORT_OUT) {
mErrorLogger.reportOut(buf);
} else if (type == REPORT_ERROR || type == REPORT_INFO) {
ErrorLogger::ErrorMessage msg;
ErrorMessage msg;
msg.deserialize(buf);

if (!mSettings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage())) {
Expand Down Expand Up @@ -299,14 +299,14 @@ unsigned int ThreadExecutor::check()
std::ostringstream oss;
oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat);

std::list<ErrorLogger::ErrorMessage::FileLocation> locations;
std::list<ErrorMessage::FileLocation> locations;
locations.emplace_back(childname, 0, 0);
const ErrorLogger::ErrorMessage errmsg(locations,
emptyString,
Severity::error,
oss.str(),
"cppcheckError",
false);
const ErrorMessage errmsg(locations,
emptyString,
Severity::error,
oss.str(),
"cppcheckError",
false);

if (!mSettings.nomsg.isSuppressed(errmsg.toSuppressionsErrorMessage()))
mErrorLogger.reportErr(errmsg);
Expand Down Expand Up @@ -344,12 +344,12 @@ void ThreadExecutor::reportOut(const std::string &outmsg)
writeToPipe(REPORT_OUT, outmsg);
}

void ThreadExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
void ThreadExecutor::reportErr(const ErrorMessage &msg)
{
writeToPipe(REPORT_ERROR, msg.serialize());
}

void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
void ThreadExecutor::reportInfo(const ErrorMessage &msg)
{
writeToPipe(REPORT_INFO, msg.serialize());
}
Expand Down Expand Up @@ -496,12 +496,12 @@ void ThreadExecutor::reportOut(const std::string &outmsg)

LeaveCriticalSection(&mReportSync);
}
void ThreadExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
void ThreadExecutor::reportErr(const ErrorMessage &msg)
{
report(msg, MessageType::REPORT_ERROR);
}

void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
void ThreadExecutor::reportInfo(const ErrorMessage &msg)
{

}
Expand All @@ -511,7 +511,7 @@ void ThreadExecutor::bughuntingReport(const std::string &/*str*/)
// TODO
}

void ThreadExecutor::report(const ErrorLogger::ErrorMessage &msg, MessageType msgType)
void ThreadExecutor::report(const ErrorMessage &msg, MessageType msgType)
{
if (mSettings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage()))
return;
Expand Down Expand Up @@ -559,12 +559,12 @@ void ThreadExecutor::reportOut(const std::string &/*outmsg*/)
{

}
void ThreadExecutor::reportErr(const ErrorLogger::ErrorMessage &/*msg*/)
void ThreadExecutor::reportErr(const ErrorMessage &/*msg*/)
{

}

void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &/*msg*/)
void ThreadExecutor::reportInfo(const ErrorMessage &/*msg*/)
{

}
Expand Down
6 changes: 3 additions & 3 deletions cli/threadexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class ThreadExecutor : public ErrorLogger {
unsigned int check();

void reportOut(const std::string &outmsg) OVERRIDE;
void reportErr(const ErrorLogger::ErrorMessage &msg) OVERRIDE;
void reportInfo(const ErrorLogger::ErrorMessage &msg) OVERRIDE;
void reportErr(const ErrorMessage &msg) OVERRIDE;
void reportInfo(const ErrorMessage &msg) OVERRIDE;
void bughuntingReport(const std::string &str) OVERRIDE;

/**
Expand Down Expand Up @@ -129,7 +129,7 @@ class ThreadExecutor : public ErrorLogger {

CRITICAL_SECTION mReportSync;

void report(const ErrorLogger::ErrorMessage &msg, MessageType msgType);
void report(const ErrorMessage &msg, MessageType msgType);

static unsigned __stdcall threadProc(void*);

Expand Down
2 changes: 1 addition & 1 deletion democlient/democlient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CppcheckExecutor : public ErrorLogger {
}

void reportOut(const std::string &outmsg) override { }
void reportErr(const ErrorLogger::ErrorMessage &msg) override {
void reportErr(const ErrorMessage &msg) override {
const std::string s = msg.toString(true);

std::cout << s << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion gui/applicationdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

#include <QDialog>
#include <QString>
#include "application.h"
#include "ui_application.h"

class QWidget;
class Application;

/// @addtogroup GUI
/// @{
Expand Down
6 changes: 3 additions & 3 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,14 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
if (isSuppressed(errorMessage))
continue;

std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
std::list<ErrorMessage::FileLocation> callstack;
foreach (const QErrorPathItem &path, e.errorPath) {
callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(path.file.toStdString(), path.info.toStdString(), path.line, path.column));
callstack.push_back(ErrorMessage::FileLocation(path.file.toStdString(), path.info.toStdString(), path.line, path.column));
}
const std::string f0 = file0.toStdString();
const std::string msg = e.message.toStdString();
const std::string id = e.errorId.toStdString();
ErrorLogger::ErrorMessage errmsg(callstack, f0, e.severity, msg, id, false);
ErrorMessage errmsg(callstack, f0, e.severity, msg, id, false);
mResult.reportErr(errmsg);
}
}
Expand Down
6 changes: 3 additions & 3 deletions gui/erroritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "erroritem.h"
#include "common.h"

QErrorPathItem::QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc)
QErrorPathItem::QErrorPathItem(const ErrorMessage::FileLocation &loc)
: file(QString::fromStdString(loc.getfile(false)))
, line(loc.line)
, column(loc.column)
Expand All @@ -40,7 +40,7 @@ ErrorItem::ErrorItem()
{
}

ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg)
ErrorItem::ErrorItem(const ErrorMessage &errmsg)
: file0(QString::fromStdString(errmsg.file0))
, function(QString::fromStdString(errmsg.function))
, errorId(QString::fromStdString(errmsg.id))
Expand All @@ -52,7 +52,7 @@ ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg)
, cwe(errmsg.cwe.id)
, symbolNames(QString::fromStdString(errmsg.symbolNames()))
{
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = errmsg.callStack.begin();
for (std::list<ErrorMessage::FileLocation>::const_iterator loc = errmsg.callStack.begin();
loc != errmsg.callStack.end();
++loc) {
errorPath << QErrorPathItem(*loc);
Expand Down
4 changes: 2 additions & 2 deletions gui/erroritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GuiSeverity {
class QErrorPathItem {
public:
QErrorPathItem() : line(0), column(-1) {}
explicit QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc);
explicit QErrorPathItem(const ErrorMessage::FileLocation &loc);
QString file;
int line;
int column;
Expand All @@ -70,7 +70,7 @@ bool operator==(const QErrorPathItem &i1, const QErrorPathItem &i2);
class ErrorItem {
public:
ErrorItem();
explicit ErrorItem(const ErrorLogger::ErrorMessage &errmsg);
explicit ErrorItem(const ErrorMessage &errmsg);

/**
* @brief Convert error item to string.
Expand Down
2 changes: 1 addition & 1 deletion gui/newsuppressiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
class QErrorLogger : public ErrorLogger {
public:
void reportOut(const std::string &/*outmsg*/) override {}
void reportErr(const ErrorLogger::ErrorMessage &msg) override {
void reportErr(const ErrorMessage &msg) override {
errorIds << QString::fromStdString(msg.id);
}
void bughuntingReport(const std::string &/*str*/) override {}
Expand Down
2 changes: 1 addition & 1 deletion gui/resultstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QStandardItem>
#include <QSettings>
#include <QContextMenuEvent>
#include "errorlogger.h" // Severity
#include "errortypes.h"
#include "showtypes.h"

class ApplicationList;
Expand Down
1 change: 0 additions & 1 deletion gui/showtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <QSettings>
#include "common.h"
#include "showtypes.h"
#include "errorlogger.h"

ShowTypes::ShowTypes()
{
Expand Down
3 changes: 2 additions & 1 deletion gui/showtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#ifndef SHOWTYPES_H
#define SHOWTYPES_H

#include "errortypes.h"

#include <QVariant>
#include "errorlogger.h"

/// @addtogroup GUI
/// @{
Expand Down
1 change: 0 additions & 1 deletion gui/test/benchmark/simple/benchmarksimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "tokenize.h"
#include "token.h"
#include "settings.h"
#include "errorlogger.h"

void BenchmarkSimple::tokenize()
{
Expand Down
2 changes: 1 addition & 1 deletion gui/test/benchmark/simple/benchmarksimple.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ private slots:
// We don't care about the output in the benchmark tests.
void reportOut(const std::string & outmsg) override {
}
void reportErr(const ErrorLogger::ErrorMessage &msg) override {
void reportErr(const ErrorMessage &msg) override {
}
};
1 change: 0 additions & 1 deletion gui/test/xmlreportv2/testxmlreportv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "testxmlreportv2.h"
#include "xmlreportv2.h"
#include "erroritem.h"
#include "errorlogger.h"

void TestXmlReportV2::readXml()
{
Expand Down
2 changes: 1 addition & 1 deletion gui/threadresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void ThreadResult::fileChecked(const QString &file)
}
}

void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
void ThreadResult::reportErr(const ErrorMessage &msg)
{
QMutexLocker locker(&mutex);
const ErrorItem item(msg);
Expand Down
2 changes: 1 addition & 1 deletion gui/threadresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ThreadResult : public QObject, public ErrorLogger {
* ErrorLogger methods
*/
void reportOut(const std::string &outmsg) override;
void reportErr(const ErrorLogger::ErrorMessage &msg) override;
void reportErr(const ErrorMessage &msg) override;
void bughuntingReport(const std::string &str) override;

public slots:
Expand Down
Loading

0 comments on commit 37bc048

Please sign in to comment.