Fix ticket #265 (Log a warning when an include file is not found)

http://sourceforge.net/apps/trac/cppcheck/ticket/265
This commit is contained in:
Reijo Tomperi 2009-07-25 22:10:30 +03:00
parent a6d696bf40
commit a07b7635c0
4 changed files with 24 additions and 18 deletions

View File

@ -336,7 +336,7 @@ unsigned int CppCheck::check()
try
{
Preprocessor preprocessor(_settings._debug);
Preprocessor preprocessor(&_settings, this);
std::list<std::string> 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<std::string> &CppCheck::filenames() const

View File

@ -33,7 +33,7 @@
#include <vector>
#include <set>
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<std::string, std::string> &result, const std::string &filename, const std::list<std::string> &includePaths, ErrorLogger *errorLogger)
void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::string> &result, const std::string &filename, const std::list<std::string> &includePaths)
{
std::list<std::string> configs;
std::string data;
preprocess(istr, data, configs, filename, includePaths);
for (std::list<std::string>::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<std::string> 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.");
}
}
}
}

View File

@ -26,6 +26,7 @@
#include <string>
#include <list>
#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<std::string, std::string> &result, const std::string &filename, const std::list<std::string> &includePaths = std::list<std::string>(), ErrorLogger *errorLogger = 0);
void preprocess(std::istream &istr, std::map<std::string, std::string> &result, const std::string &filename, const std::list<std::string> &includePaths = std::list<std::string>());
/**
* 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<std::string> &includePaths);
void handleIncludes(std::string &code, const std::string &filename, const std::list<std::string> &includePaths);
const Settings *_settings;
ErrorLogger *_errorLogger;
};
/// @}

View File

@ -1197,8 +1197,8 @@ private:
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Preprocessor preprocessor;
preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>(), this);
Preprocessor preprocessor(0, this);
preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>());
// Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size()));
@ -1218,8 +1218,8 @@ private:
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Preprocessor preprocessor;
preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>(), this);
Preprocessor preprocessor(0, this);
preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>());
// Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size()));