Skip to content

Commit

Permalink
Refactoring information messages.
Browse files Browse the repository at this point in the history
Currently the information severity messages are outputted as error
messages with Severity::Information. This causes constant confusion
as people think it as mildest error severity (and rightfully so).
When it was meant to be for printing messages about the checking
procedure itself (like missing header files etc).

So I'm adding a new function for the ErrorLogger for printing these
informative messages. This makes clear the distinction of errors
found from the code and messages related to the checking itself.
It also makes it easier for clients to handle these separately.
  • Loading branch information
kimmov committed Jun 18, 2012
1 parent 14591b3 commit 68c52dd
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
"--check-config.",
"missingInclude",
false);
reportErr(msg);
reportInfo(msg);
}
}

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

void CppCheckExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
{
reportOut(msg.toXML(false, _settings._xml_version));
}

void CppCheckExecutor::reportStatus(size_t fileindex, size_t filecount, size_t sizedone, size_t sizetotal)
{
if (filecount > 1) {
Expand Down
5 changes: 5 additions & 0 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class CppCheckExecutor : public ErrorLogger {

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

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

/**
* Information about how many files have been checked
*
Expand Down
10 changes: 10 additions & 0 deletions cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ void ThreadExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
writeToPipe(REPORT_ERROR, msg.serialize());
}

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

#else

void ThreadExecutor::addFileContent(const std::string &/*path*/, const std::string &/*content*/)
Expand All @@ -311,4 +316,9 @@ void ThreadExecutor::reportErr(const ErrorLogger::ErrorMessage &/*msg*/)

}

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

}

#endif
1 change: 1 addition & 0 deletions cli/threadexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ThreadExecutor : public ErrorLogger {
unsigned int check();
virtual void reportOut(const std::string &outmsg);
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
virtual void reportInfo(const ErrorLogger::ErrorMessage &msg);

/**
* @brief Add content to a file, to be used in unit testing.
Expand Down
8 changes: 6 additions & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ unsigned int CppCheck::processFile(const std::string& filename)
"toomanyconfigs",
false);

reportErr(errmsg);

reportInfo(errmsg);
break;
}

Expand Down Expand Up @@ -512,6 +511,11 @@ void CppCheck::reportProgress(const std::string &filename, const char stage[], c
_errorLogger.reportProgress(filename, stage, value);
}

void CppCheck::reportInfo(const ErrorLogger::ErrorMessage &msg)
{
_errorLogger.reportInfo(msg);
}

void CppCheck::reportStatus(unsigned int /*fileindex*/, unsigned int /*filecount*/, size_t /*sizedone*/, size_t /*sizetotal*/)
{

Expand Down
5 changes: 5 additions & 0 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ class CPPCHECKLIB CppCheck : ErrorLogger {

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

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

CheckUnusedFunctions _checkUnusedFunctions;
ErrorLogger &_errorLogger;

Expand Down
9 changes: 7 additions & 2 deletions lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ class CPPCHECKLIB ErrorLogger {
* Information about found errors and warnings is directed
* here. Override this to receive the errormessages.
*
* @param msg Location and other information about the found.
* error
* @param msg Location and other information about the found error.
*/
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) = 0;

Expand All @@ -283,6 +282,12 @@ class CPPCHECKLIB ErrorLogger {
(void)value;
}

/**
* Output information messages.
* @param msg Location and other information about the found error.
*/
virtual void reportInfo(const ErrorLogger::ErrorMessage &msg) = 0;

/**
* Report list of unmatched suppressions
* @param unmatched list of unmatched suppressions (from Settings::Suppressions::getUnmatched(Local|Global)Suppressions)
Expand Down
2 changes: 1 addition & 1 deletion lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
const std::string id = userheader ? "missingInclude" : "debug";
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id, false);
errmsg.file0 = file0;
_errorLogger->reportErr(errmsg);
errorLogger->reportInfo(errmsg);
}

/**
Expand Down

0 comments on commit 68c52dd

Please sign in to comment.