From 7de545f0fec85345a714361322b13275963d48e4 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 6 Apr 2012 18:16:59 +0200 Subject: [PATCH] Refactorizations: - Added forgotten initialization of Settings::_relativePaths - Some PCRE-Rules specific code hidden behind HAVE_RULES - Use initialization list in ErrorLogger::ErrorMessage::ErrorMessage() and CppCheck::CppCheck - Avoided unnecessary copies of std::strings in cppcheck.cpp - Moved "// Alert only about unique errors"-code to make it work in debugFalsePositive mode --- lib/cppcheck.cpp | 22 ++++++++++------------ lib/errorlogger.cpp | 17 +++++------------ lib/settings.cpp | 1 + lib/settings.h | 2 ++ 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index e307a6142..5c100d29b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -39,9 +39,8 @@ static const char ExtraVersion[] = ""; static TimerResults S_timerResults; CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions) - : _useGlobalSuppressions(useGlobalSuppressions), _errorLogger(errorLogger) + : _useGlobalSuppressions(useGlobalSuppressions), _errorLogger(errorLogger), exitcode(0) { - exitcode = 0; } CppCheck::~CppCheck() @@ -154,8 +153,7 @@ unsigned int CppCheck::processFile(const std::string& filename) return exitcode; if (_settings._errorsOnly == false) { - std::string fixedpath(filename); - fixedpath = Path::simplifyPath(fixedpath.c_str()); + std::string fixedpath = Path::simplifyPath(filename.c_str()); fixedpath = Path::toNativeSeparators(fixedpath); _errorLogger.reportOut(std::string("Checking ") + fixedpath + std::string("...")); } @@ -460,20 +458,20 @@ Settings &CppCheck::settings() void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) { - const std::string errmsg = msg.toString(_settings._verbose); + std::string errmsg = msg.toString(_settings._verbose); if (errmsg.empty()) return; + // Alert only about unique errors + if (std::find(_errorList.begin(), _errorList.end(), errmsg) != _errorList.end()) + return; + if (_settings.debugFalsePositive) { // Don't print out error _errorList.push_back(errmsg); return; } - // Alert only about unique errors - if (std::find(_errorList.begin(), _errorList.end(), errmsg) != _errorList.end()) - return; - std::string file; unsigned int line(0); if (!msg._callStack.empty()) { @@ -493,14 +491,14 @@ void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) exitcode = 1; _errorList.push_back(errmsg); - std::string errmsg2(errmsg); + if (_settings._verbose) { - errmsg2 += "\n Defines=\'" + cfg + "\'\n"; + errmsg += "\n Defines=\'" + cfg + "\'\n"; } _errorLogger.reportErr(msg); - _errout << errmsg2 << std::endl; + _errout << errmsg << std::endl; } void CppCheck::reportOut(const std::string &outmsg) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index f3e81d96c..5c1b63c84 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -34,21 +34,14 @@ ErrorLogger::ErrorMessage::ErrorMessage() { } -ErrorLogger::ErrorMessage::ErrorMessage(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) +ErrorLogger::ErrorMessage::ErrorMessage(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) : + _callStack(callStack), // locations for this error message + _severity(severity), // severity for this error message + _id(id), // set the message id + _inconclusive(inconclusive) { - // locations for this error message - _callStack = callStack; - - // severity for this error message - _severity = severity; - // set the summary and verbose messages setmsg(msg); - - // set the message id - _id = id; - - _inconclusive = inconclusive; } void ErrorLogger::ErrorMessage::setmsg(const std::string &msg) diff --git a/lib/settings.cpp b/lib/settings.cpp index f9fb5e8e1..65dd1840f 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -31,6 +31,7 @@ Settings::Settings() _inlineSuppressions(false), _verbose(false), _force(false), + _relativePaths(false), _xml(false), _xml_version(1), _jobs(1), _exitCode(0), diff --git a/lib/settings.h b/lib/settings.h index b9d6ab076..4c4bd409f 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -166,6 +166,7 @@ public: /** @brief --report-progress */ bool reportProgress; +#ifdef HAVE_RULES /** Rule */ class Rule { public: @@ -184,6 +185,7 @@ public: * @brief Extra rules */ std::list rules; +#endif /** Is the 'configuration checking' wanted? */ bool checkConfiguration;