From 53d036fadf189817a87e61e1f7c9e8409534c909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 18 Jan 2010 20:23:50 +0100 Subject: [PATCH] Added Cppcheck::terminate function that will terminate the checking ASAP --- lib/cppcheck.cpp | 14 +++++++++++++- lib/cppcheck.h | 8 ++++++++ lib/settings.cpp | 1 + lib/settings.h | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 5dc83b6b6..5a524edb5 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -436,7 +436,10 @@ unsigned int CppCheck::check() for (unsigned int c = 0; c < _filenames.size(); c++) { _errout.str(""); - std::string fname = _filenames[c]; + const std::string fname = _filenames[c]; + + if (_settings.terminated()) + break; if (_settings._errorsOnly == false) _errorLogger.reportOut(std::string("Checking ") + fname + std::string("...")); @@ -519,6 +522,9 @@ unsigned int CppCheck::check() void CppCheck::checkFile(const std::string &code, const char FileName[]) { + if (_settings.terminated()) + return; + Tokenizer _tokenizer(&_settings, this); // Tokenize the file @@ -542,6 +548,9 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) // call all "runChecks" in all registered Check classes for (std::list::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { + if (_settings.terminated()) + return; + TIMER_START(); (*it)->runChecks(&_tokenizer, &_settings, this); TIMER_END((*it)->name() << "::runChecks"); @@ -567,6 +576,9 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) // call all "runSimplifiedChecks" in all registered Check classes for (std::list::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { + if (_settings.terminated()) + return; + TIMER_START(); (*it)->runSimplifiedChecks(&_tokenizer, &_settings, this); TIMER_END((*it)->name() << "::runSimplifiedChecks"); diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 844fe25e9..9d08db721 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -116,6 +116,14 @@ public: virtual void reportStatus(unsigned int index, unsigned int max); + /** + * Terminate checking. The checking will be terminated ASAP. + */ + void terminate() + { + _settings.terminate(); + } + private: void checkFile(const std::string &code, const char FileName[]); diff --git a/lib/settings.cpp b/lib/settings.cpp index d7cfdbc75..4a48e68f4 100755 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -37,6 +37,7 @@ Settings::Settings() _exitCode = 0; _showtime = false; _append = ""; + _terminate = false; } Settings::~Settings() diff --git a/lib/settings.h b/lib/settings.h index 728c2f681..74efbb20c 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -45,6 +45,9 @@ private: /** enable extra checks by id */ std::map _enabled; + + /** terminate checking */ + bool _terminate; public: Settings(); virtual ~Settings(); @@ -56,6 +59,18 @@ public: bool _inlineSuppressions; bool _verbose; + /** Request termination of checking */ + void terminate() + { + _terminate = true; + } + + /** termination? */ + bool terminated() const + { + return _terminate; + } + /** Force checking t he files with "too many" configurations. */ bool _force;