Skip to content

Commit

Permalink
CppcheckExecutor: use dedicated ErrorLogger for printing error messag…
Browse files Browse the repository at this point in the history
…es XML (danmar#4985)

This starts to untangle the `ErrorLogger` implementation in
`CppcheckExecutor` which handles three different cases and makes things
unnecessarily complicated.
  • Loading branch information
firewave authored Aug 8, 2023
1 parent 5ea1bca commit f1749ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
26 changes: 18 additions & 8 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,23 @@
#include <windows.h>
#endif

// TODO: do not directly write to stdout
class XMLErrorMessagesLogger : public ErrorLogger
{
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
{
std::cout << outmsg << std::endl;
}

void reportErr(const ErrorMessage &msg) override
{
reportOut(msg.toXML());
}

void reportProgress(const std::string & /*filename*/, const char /*stage*/[], const std::size_t /*value*/) override
{}
};

// TODO: do not directly write to stdout

/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;

Expand Down Expand Up @@ -97,9 +112,9 @@ bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* c
}

if (parser.getShowErrorMessages()) {
mShowAllErrors = true;
XMLErrorMessagesLogger xmlLogger;
std::cout << ErrorMessage::getXMLHeader(settings.cppcheckCfgProductName);
CppCheck::getErrorMessages(*this);
CppCheck::getErrorMessages(xmlLogger);
std::cout << ErrorMessage::getXMLFooter() << std::endl;
}

Expand Down Expand Up @@ -409,11 +424,6 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st

void CppCheckExecutor::reportErr(const ErrorMessage &msg)
{
if (mShowAllErrors) {
reportOut(msg.toXML());
return;
}

assert(mSettings != nullptr);

// Alert only about unique errors
Expand Down
5 changes: 0 additions & 5 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ class CppCheckExecutor : public ErrorLogger {
* Error output
*/
std::ofstream* mErrorOutput{};

/**
* Has --errorlist been given?
*/
bool mShowAllErrors{};
};

#endif // CPPCHECKEXECUTOR_H

0 comments on commit f1749ab

Please sign in to comment.