diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index ed4033ced..819a0c281 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -336,7 +336,7 @@ unsigned int CppCheck::check() try { - Preprocessor preprocessor(_settings._debug); + Preprocessor preprocessor(&_settings, this); std::list configurations; std::string filedata = ""; @@ -473,10 +473,9 @@ void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) _errout << errmsg2 << std::endl; } -void CppCheck::reportOut(const std::string & /*outmsg*/) +void CppCheck::reportOut(const std::string &outmsg) { - // This is currently never called. It is here just to comply with - // the interface. + _errorLogger->reportOut(outmsg); } const std::vector &CppCheck::filenames() const diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index 3d909e9c6..47adb03b7 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -33,7 +33,7 @@ #include #include -Preprocessor::Preprocessor(bool debug) : _debug(debug) +Preprocessor::Preprocessor(const Settings *settings, ErrorLogger *errorLogger) : _settings(settings), _errorLogger(errorLogger) { } @@ -434,13 +434,13 @@ std::string Preprocessor::removeComments(const std::string &str) return code.str(); } -void Preprocessor::preprocess(std::istream &istr, std::map &result, const std::string &filename, const std::list &includePaths, ErrorLogger *errorLogger) +void Preprocessor::preprocess(std::istream &istr, std::map &result, const std::string &filename, const std::list &includePaths) { std::list configs; std::string data; preprocess(istr, data, configs, filename, includePaths); for (std::list::const_iterator it = configs.begin(); it != configs.end(); ++it) - result[ *it ] = Preprocessor::getcode(data, *it, filename, errorLogger); + result[ *it ] = Preprocessor::getcode(data, *it, filename, _errorLogger); } std::string Preprocessor::removeSpaceNearNL(const std::string &str) @@ -770,7 +770,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata) if (s.find("&&") != std::string::npos || s.find("||") != std::string::npos) { // unhandled ifdef configuration.. - if (_debug) + if (_settings && _settings->_debug) std::cout << "unhandled configuration: " << s << std::endl; ret.erase(it++); @@ -1079,6 +1079,13 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename path.erase(1 + path.find_last_of("\\/")); paths.push_back(path); } + else + { + if (_errorLogger && _settings && _settings->_verbose) + { + _errorLogger->reportOut("Include file: \"" + paths.back() + filename + "\" not found."); + } + } } } diff --git a/src/preprocessor.h b/src/preprocessor.h index 26e1d29a9..7cf430b94 100644 --- a/src/preprocessor.h +++ b/src/preprocessor.h @@ -26,6 +26,7 @@ #include #include #include "errorlogger.h" +#include "settings.h" /// @addtogroup Core /// @{ @@ -34,7 +35,7 @@ class Preprocessor { public: - Preprocessor(bool debug = false); + Preprocessor(const Settings *settings = 0, ErrorLogger *errorLogger = 0); /** * Extract the code for each configuration @@ -47,7 +48,7 @@ public: * Note that if path from given filename is also extracted and that is used as * a last include path if include file was not found from earlier paths. */ - void preprocess(std::istream &istr, std::map &result, const std::string &filename, const std::list &includePaths = std::list(), ErrorLogger *errorLogger = 0); + void preprocess(std::istream &istr, std::map &result, const std::string &filename, const std::list &includePaths = std::list()); /** * Extract the code for each configuration. Use this with getcode() to get the @@ -108,9 +109,6 @@ protected: static int getHeaderFileName(std::string &str); private: - /** Show debug information when bailing out */ - const bool _debug; - /** * Remove space that has new line character on left or right side of it. * @@ -148,8 +146,10 @@ private: * a last include path if include file was not found from earlier paths. * @return modified source code */ - static void handleIncludes(std::string &code, const std::string &filename, const std::list &includePaths); + void handleIncludes(std::string &code, const std::string &filename, const std::list &includePaths); + const Settings *_settings; + ErrorLogger *_errorLogger; }; /// @} diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index ee6c55ef3..772ff1f93 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -1197,8 +1197,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; - preprocessor.preprocess(istr, actual, "file.c", std::list(), this); + Preprocessor preprocessor(0, this); + preprocessor.preprocess(istr, actual, "file.c", std::list()); // Compare results.. ASSERT_EQUALS(1, static_cast(actual.size())); @@ -1218,8 +1218,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; - preprocessor.preprocess(istr, actual, "file.c", std::list(), this); + Preprocessor preprocessor(0, this); + preprocessor.preprocess(istr, actual, "file.c", std::list()); // Compare results.. ASSERT_EQUALS(1, static_cast(actual.size()));