Skip to content

Commit 4b4f7ea

Browse files
committed
Verification; Updated report
1 parent 147cf93 commit 4b4f7ea

17 files changed

+89
-26
lines changed

cli/cmdlineparser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
192192
// Experimental: Verify
193193
else if (std::strcmp(argv[i], "--verify") == 0)
194194
mSettings->verification = true;
195+
else if (std::strcmp(argv[i], "--verify-report") == 0)
196+
mSettings->verification = mSettings->verificationReport = true;
195197
else if (std::strcmp(argv[i], "--debug-verify") == 0)
196198
mSettings->debugVerification = true;
197199

cli/cppcheckexecutor.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@
7979
/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;
8080

8181
CppCheckExecutor::CppCheckExecutor()
82-
: mSettings(nullptr), mLatestProgressOutputTime(0), mErrorOutput(nullptr), mShowAllErrors(false)
82+
: mSettings(nullptr), mLatestProgressOutputTime(0), mErrorOutput(nullptr), mVerificationOutput(nullptr), mShowAllErrors(false)
8383
{
8484
}
8585

8686
CppCheckExecutor::~CppCheckExecutor()
8787
{
8888
delete mErrorOutput;
89+
delete mVerificationOutput;
8990
}
9091

9192
bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[])
@@ -1063,6 +1064,13 @@ void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
10631064
}
10641065
}
10651066

1067+
void CppCheckExecutor::reportVerification(const std::string &str)
1068+
{
1069+
if (!mVerificationOutput)
1070+
mVerificationOutput = new std::ofstream("verification-report.txt");
1071+
(*mVerificationOutput) << str << std::endl;
1072+
}
1073+
10661074
void CppCheckExecutor::setExceptionOutput(FILE* exceptionOutput)
10671075
{
10681076
mExceptionOutput = exceptionOutput;

cli/cppcheckexecutor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class CppCheckExecutor : public ErrorLogger {
8181
*/
8282
void reportInfo(const ErrorLogger::ErrorMessage &msg) OVERRIDE;
8383

84+
void reportVerification(const std::string &str) OVERRIDE;
85+
8486
/**
8587
* Information about how many files have been checked
8688
*
@@ -187,6 +189,11 @@ class CppCheckExecutor : public ErrorLogger {
187189
*/
188190
std::ofstream *mErrorOutput;
189191

192+
/**
193+
* Verification report
194+
*/
195+
std::ostream *mVerificationOutput;
196+
190197
/**
191198
* Has --errorlist been given?
192199
*/

cli/threadexecutor.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
348348
writeToPipe(REPORT_INFO, msg.serialize());
349349
}
350350

351+
void ThreadExecutor::reportVerification(const std::string &str)
352+
{
353+
writeToPipe(REPORT_VERIFICATION, str.c_str());
354+
}
355+
351356
#elif defined(THREADING_MODEL_WIN)
352357

353358
void ThreadExecutor::addFileContent(const std::string &path, const std::string &content)
@@ -490,7 +495,12 @@ void ThreadExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
490495

491496
void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
492497
{
493-
report(msg, MessageType::REPORT_INFO);
498+
499+
}
500+
501+
void ThreadExecutor::reportVerification(const std::string &/*str*/)
502+
{
503+
// TODO
494504
}
495505

496506
void ThreadExecutor::report(const ErrorLogger::ErrorMessage &msg, MessageType msgType)
@@ -551,4 +561,8 @@ void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &/*msg*/)
551561

552562
}
553563

564+
void ThreadExecutor::reportVerification(const std::string &/*str*/)
565+
{
566+
}
567+
554568
#endif

cli/threadexecutor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class ThreadExecutor : public ErrorLogger {
5454
void reportOut(const std::string &outmsg) OVERRIDE;
5555
void reportErr(const ErrorLogger::ErrorMessage &msg) OVERRIDE;
5656
void reportInfo(const ErrorLogger::ErrorMessage &msg) OVERRIDE;
57+
void reportVerification(const std::string &str) OVERRIDE;
5758

5859
/**
5960
* @brief Add content to a file, to be used in unit testing.
@@ -75,7 +76,7 @@ class ThreadExecutor : public ErrorLogger {
7576
/** @brief Key is file name, and value is the content of the file */
7677
std::map<std::string, std::string> mFileContents;
7778
private:
78-
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', REPORT_INFO='3', CHILD_END='4'};
79+
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', REPORT_INFO='3', REPORT_VERIFICATION='4', CHILD_END='5'};
7980

8081
/**
8182
* Read from the pipe, parse and handle what ever is in there.

gui/newsuppressiondialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
1212

1313
class QErrorLogger : public ErrorLogger {
1414
public:
15-
virtual void reportOut(const std::string &/*outmsg*/) {}
16-
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) {
15+
void reportOut(const std::string &/*outmsg*/) override {}
16+
void reportErr(const ErrorLogger::ErrorMessage &msg) override {
1717
errorIds << QString::fromStdString(msg.id);
1818
}
19+
void reportVerification(const std::string &/*str*/) override {}
1920
QStringList errorIds;
2021
};
2122

gui/threadresult.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ThreadResult : public QObject, public ErrorLogger {
7474
*/
7575
void reportOut(const std::string &outmsg) override;
7676
void reportErr(const ErrorLogger::ErrorMessage &msg) override;
77+
void reportVerification(const std::string &/*str*/) override {}
7778

7879
public slots:
7980

lib/cppcheck.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,8 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
766766
}
767767

768768
// Verification using ExprEngine..
769-
if (mSettings.verification) {
769+
if (mSettings.verification)
770770
ExprEngine::runChecks(this, &tokenizer, &mSettings);
771-
}
772771

773772
// Analyse the tokens..
774773

@@ -1202,6 +1201,11 @@ void CppCheck::reportStatus(unsigned int /*fileindex*/, unsigned int /*filecount
12021201

12031202
}
12041203

1204+
void CppCheck::reportVerification(const std::string &str)
1205+
{
1206+
mErrorLogger.reportVerification(str);
1207+
}
1208+
12051209
void CppCheck::getErrorMessages()
12061210
{
12071211
Settings s(mSettings);

lib/cppcheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
195195
*/
196196
void reportOut(const std::string &outmsg) OVERRIDE;
197197

198+
void reportVerification(const std::string &str) OVERRIDE;
199+
198200
std::list<std::string> mErrorList;
199201
Settings mSettings;
200202

lib/errorlogger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ class CPPCHECKLIB ErrorLogger {
401401
reportErr(msg);
402402
}
403403

404+
virtual void reportVerification(const std::string &str) = 0;
405+
404406
/**
405407
* Report unmatched suppressions
406408
* @param unmatched list of unmatched suppressions (from Settings::Suppressions::getUnmatched(Local|Global)Suppressions)

0 commit comments

Comments
 (0)