diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index 9f767c759..7ab820ecd 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -35,7 +35,6 @@ //--------------------------------------------------------------------------- CppCheck::CppCheck(ErrorLogger &errorLogger) - : ErrorLogger(errorLogger) { _errorLogger = &errorLogger; } @@ -196,12 +195,6 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[]) } } - // Use visual studio compliant output format - else if (strcmp(argv[i], "--output-format=VS") == 0) - { - _settings._outputFormat = "file(line)"; - } - // auto deallocated classes.. else if (strcmp(argv[i], "--auto-dealloc") == 0) { @@ -301,7 +294,6 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[]) " several paths. First given path is checked first. If\n" " paths are relative to source files, this is not needed\n" " -j [jobs] Start [jobs] threads to do the checking simultaneously.\n" - " --output-format=VS Use Visual Studio compliant output format.\n" " -q, --quiet Only print error messages\n" " -s, --style Check coding style\n" " --unused-functions Check if there are unused functions\n" @@ -332,7 +324,6 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[]) unsigned int CppCheck::check() { - _errorLogger->outputFormat(_settings._outputFormat); _checkUnusedFunctions.setErrorLogger(this); std::sort(_filenames.begin(), _filenames.end()); for (unsigned int c = 0; c < _filenames.size(); c++) @@ -464,7 +455,7 @@ Settings CppCheck::settings() const void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) { - std::string errmsg = toText(msg); + std::string errmsg = msg.toText(); // Alert only about unique errors if (std::find(_errorList.begin(), _errorList.end(), errmsg) != _errorList.end()) diff --git a/src/cppcheckexecutor.cpp b/src/cppcheckexecutor.cpp index f436804a2..3707b807d 100644 --- a/src/cppcheckexecutor.cpp +++ b/src/cppcheckexecutor.cpp @@ -112,6 +112,6 @@ void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg) } else { - reportErr(toText(msg)); + reportErr(msg.toText()); } } diff --git a/src/errorlogger.cpp b/src/errorlogger.cpp index f56998a1e..e5c316075 100644 --- a/src/errorlogger.cpp +++ b/src/errorlogger.cpp @@ -158,14 +158,14 @@ std::string ErrorLogger::ErrorMessage::toXML() const return xml.str(); } -std::string ErrorLogger::toText(const ErrorLogger::ErrorMessage &msg) const +std::string ErrorLogger::ErrorMessage::toText() const { std::ostringstream text; - if (!msg._callStack.empty()) - text << callStackToString(msg._callStack) << ": "; - if (!msg._severity.empty()) - text << "(" << msg._severity << ") "; - text << msg._msg; + if (!_callStack.empty()) + text << callStackToString(_callStack) << ": "; + if (!_severity.empty()) + text << "(" << _severity << ") "; + text << _msg; return text.str(); } @@ -191,30 +191,13 @@ void ErrorLogger::_writemsg(const Tokenizer *tokenizer, const std::list &callStack) const +std::string ErrorLogger::callStackToString(const std::list &callStack) { std::ostringstream ostr; for (std::list::const_iterator tok = callStack.begin(); tok != callStack.end(); ++tok) - { - if (tok != callStack.begin()) - ostr << " -> "; - std::string s = _outputFormat; - replace(s, "file", (*tok).getfile()); - std::ostringstream line; - line << (*tok).line; - replace(s, "line", line.str()); - ostr << s; - } + ostr << (tok == callStack.begin() ? "" : " -> ") << "[" << (*tok).getfile() << ":" << (*tok).line << "]"; return ostr.str(); } diff --git a/src/errorlogger.h b/src/errorlogger.h index d6a81bbaa..8232118ca 100644 --- a/src/errorlogger.h +++ b/src/errorlogger.h @@ -63,7 +63,7 @@ public: static std::string getXMLHeader(); static std::string getXMLFooter(); - //std::string toText() const; + std::string toText() const; std::string serialize() const; bool deserialize(const std::string &data); std::list _callStack; @@ -72,17 +72,9 @@ public: std::string _id; }; - ErrorLogger() : _outputFormat("[file:line]") { } + ErrorLogger() { } virtual ~ErrorLogger() { } - /** Change the output format */ - void outputFormat(const std::string &of) - { - _outputFormat = of; - } - - std::string toText(const ErrorMessage &msg) const; - /** * Information about progress is directed here. * Override this to receive the progress messages. @@ -342,12 +334,10 @@ public: } - std::string callStackToString(const std::list &callStack) const; + static std::string callStackToString(const std::list &callStack); private: void _writemsg(const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string &msg, const std::string &id); void _writemsg(const Tokenizer *tokenizer, const std::list &callstack, const char severity[], const std::string &msg, const std::string &id); - - std::string _outputFormat; }; #endif diff --git a/src/settings.cpp b/src/settings.cpp index e21c04290..087019b83 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -33,7 +33,6 @@ Settings::Settings() _security = false; _jobs = 1; _exitCode = 0; - _outputFormat = "[file:line]"; } Settings::~Settings() diff --git a/src/settings.h b/src/settings.h index 2d569d667..2d5549c0a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -50,9 +50,6 @@ public: /** write xml results */ bool _xml; - /** output formatting */ - std::string _outputFormat; - /** Checking if there are unused functions */ bool _unusedFunctions; diff --git a/src/threadexecutor.cpp b/src/threadexecutor.cpp index dbbfba4d4..3a4c83493 100644 --- a/src/threadexecutor.cpp +++ b/src/threadexecutor.cpp @@ -30,7 +30,7 @@ #endif ThreadExecutor::ThreadExecutor(const std::vector &filenames, const Settings &settings, ErrorLogger &errorLogger) - : ErrorLogger(errorLogger), _filenames(filenames), _settings(settings), _errorLogger(errorLogger), _fileCount(0) + : _filenames(filenames), _settings(settings), _errorLogger(errorLogger), _fileCount(0) { } @@ -84,7 +84,7 @@ bool ThreadExecutor::handleRead(unsigned int &result) msg.deserialize(buf); // Alert only about unique errors - std::string errmsg = toText(msg); + std::string errmsg = msg.toText(); if (std::find(_errorList.begin(), _errorList.end(), errmsg) == _errorList.end()) { _errorList.push_back(errmsg); diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 643f3df95..c6edb17bc 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -101,7 +101,7 @@ private: loc.file = "ab/cd/../ef.h"; errmsg._callStack.push_back(loc); ASSERT_EQUALS("", errmsg.toXML()); - //ASSERT_EQUALS("[ab/ef.h:0]: ", errorLogger.toText(errmsg)); + ASSERT_EQUALS("[ab/ef.h:0]: ", errmsg.toText()); } }; diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 8144013d5..04c5d01ea 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -179,5 +179,5 @@ void TestFixture::reportOut(const std::string & /*outmsg*/) void TestFixture::reportErr(const ErrorLogger::ErrorMessage &msg) { - errout << toText(msg) << std::endl; + errout << msg.toText() << std::endl; }