Fixed #1872 (Confused -v switch)
This commit is contained in:
parent
1938b8a423
commit
f490ebcf88
|
@ -830,5 +830,7 @@ void CppCheck::getErrorMessages()
|
||||||
Tokenizer tokenizer(&_settings, 0);
|
Tokenizer tokenizer(&_settings, 0);
|
||||||
tokenizer.getErrorMessages();
|
tokenizer.getErrorMessages();
|
||||||
|
|
||||||
|
Preprocessor::getErrorMessages(std::cout);
|
||||||
|
|
||||||
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
|
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -602,6 +602,9 @@ void Preprocessor::preprocessWhitespaces(std::string &processedFile)
|
||||||
|
|
||||||
void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths)
|
void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths)
|
||||||
{
|
{
|
||||||
|
if (file0.empty())
|
||||||
|
file0 = filename;
|
||||||
|
|
||||||
processedFile = read(srcCodeStream, filename, _settings);
|
processedFile = read(srcCodeStream, filename, _settings);
|
||||||
|
|
||||||
// normalize the whitespaces of the file
|
// normalize the whitespaces of the file
|
||||||
|
@ -1439,10 +1442,10 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
|
|
||||||
if (headerType == UserHeader && !fileOpened)
|
if (headerType == UserHeader && !fileOpened)
|
||||||
{
|
{
|
||||||
filename = paths.back() + filename;
|
fin.open((paths.back() + filename).c_str());
|
||||||
fin.open(filename.c_str());
|
|
||||||
if (fin.is_open())
|
if (fin.is_open())
|
||||||
{
|
{
|
||||||
|
filename = paths.back() + filename;
|
||||||
fileOpened = true;
|
fileOpened = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1464,7 +1467,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
fin.close();
|
fin.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processedFile.length() > 0)
|
if (!processedFile.empty())
|
||||||
{
|
{
|
||||||
// Replace all tabs with spaces..
|
// Replace all tabs with spaces..
|
||||||
std::replace(processedFile.begin(), processedFile.end(), '\t', ' ');
|
std::replace(processedFile.begin(), processedFile.end(), '\t', ' ');
|
||||||
|
@ -1484,10 +1487,39 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
}
|
}
|
||||||
else if (!fileOpened)
|
else if (!fileOpened)
|
||||||
{
|
{
|
||||||
if (headerType == UserHeader && _errorLogger && _settings && _settings->_verbose)
|
if (headerType == UserHeader && _errorLogger && _settings && _settings->isEnabled("missingInclude"))
|
||||||
{
|
{
|
||||||
std::string fixedpath = Path::toNativeSeparators(filename);
|
// Determine line number of include
|
||||||
_errorLogger->reportOut("Include file: \"" + fixedpath + "\" not found.");
|
unsigned int linenr = 1;
|
||||||
|
unsigned int level = 0;
|
||||||
|
for (std::string::size_type p = 0; p < pos; ++p)
|
||||||
|
{
|
||||||
|
if (level == 0 && code[pos-p] == '\n')
|
||||||
|
++linenr;
|
||||||
|
else if (code.compare(pos-p, 9, "#endfile\n") == 0)
|
||||||
|
{
|
||||||
|
++level;
|
||||||
|
}
|
||||||
|
else if (code.compare(pos-p, 6, "#file ") == 0)
|
||||||
|
{
|
||||||
|
if (level == 0)
|
||||||
|
{
|
||||||
|
--linenr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
--level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||||
|
loc.line = linenr; /** @todo set correct line */
|
||||||
|
loc.setfile(Path::toNativeSeparators(filePath));
|
||||||
|
locationList.push_back(loc);
|
||||||
|
|
||||||
|
ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "Include file: \"" + filename + "\" not found.", "missingInclude");
|
||||||
|
errmsg.file0 = file0;
|
||||||
|
_errorLogger->reportErr(errmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2259,3 +2291,12 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
|
||||||
return ostr.str();
|
return ostr.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Preprocessor::getErrorMessages(std::ostream &ostr)
|
||||||
|
{
|
||||||
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
|
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||||
|
Severity::style,
|
||||||
|
"Include file: \"\" not found.",
|
||||||
|
"missingInclude");
|
||||||
|
ostr << errmsg.toXML() << std::endl;
|
||||||
|
}
|
||||||
|
|
|
@ -195,6 +195,8 @@ public:
|
||||||
*/
|
*/
|
||||||
static bool match_cfg_def(const std::map<std::string, std::string> &cfg, std::string def);
|
static bool match_cfg_def(const std::map<std::string, std::string> &cfg, std::string def);
|
||||||
|
|
||||||
|
static void getErrorMessages(std::ostream &ostr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Search includes from code and append code from the included
|
* Search includes from code and append code from the included
|
||||||
|
@ -212,6 +214,9 @@ private:
|
||||||
|
|
||||||
Settings *_settings;
|
Settings *_settings;
|
||||||
ErrorLogger *_errorLogger;
|
ErrorLogger *_errorLogger;
|
||||||
|
|
||||||
|
/** filename for cpp/c file - useful when reporting errors */
|
||||||
|
std::string file0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -188,7 +188,8 @@ std::string Settings::addEnabled(const std::string &str)
|
||||||
handled = _checkCodingStyle = true;
|
handled = _checkCodingStyle = true;
|
||||||
|
|
||||||
std::set<std::string> id;
|
std::set<std::string> id;
|
||||||
id.insert("unusedFunctions");
|
id.insert("missingInclude");
|
||||||
|
id.insert("unusedFunction");
|
||||||
|
|
||||||
if (str == "all")
|
if (str == "all")
|
||||||
{
|
{
|
||||||
|
|
|
@ -1100,7 +1100,7 @@ private:
|
||||||
std::map<std::string, std::string> actual;
|
std::map<std::string, std::string> actual;
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.debug = settings.debugwarnings = true;
|
settings.debug = settings.debugwarnings = true;
|
||||||
settings._verbose = true;
|
settings.addEnabled("missingInclude");;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
preprocessor.preprocess(istr, actual, "file.c");
|
preprocessor.preprocess(istr, actual, "file.c");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue