@@ -602,6 +602,9 @@ void Preprocessor::preprocessWhitespaces(std::string &processedFile)
602602
603603void Preprocessor::preprocess (std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths)
604604{
605+ if (file0.empty ())
606+ file0 = filename;
607+
605608 processedFile = read (srcCodeStream, filename, _settings);
606609
607610 // normalize the whitespaces of the file
@@ -1439,10 +1442,10 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
14391442
14401443 if (headerType == UserHeader && !fileOpened)
14411444 {
1442- filename = paths.back () + filename;
1443- fin.open (filename.c_str ());
1445+ fin.open ((paths.back () + filename).c_str ());
14441446 if (fin.is_open ())
14451447 {
1448+ filename = paths.back () + filename;
14461449 fileOpened = true ;
14471450 }
14481451 }
@@ -1464,7 +1467,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
14641467 fin.close ();
14651468 }
14661469
1467- if (processedFile.length () > 0 )
1470+ if (! processedFile.empty () )
14681471 {
14691472 // Replace all tabs with spaces..
14701473 std::replace (processedFile.begin (), processedFile.end (), ' \t ' , ' ' );
@@ -1484,10 +1487,39 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
14841487 }
14851488 else if (!fileOpened)
14861489 {
1487- if (headerType == UserHeader && _errorLogger && _settings && _settings->_verbose )
1490+ if (headerType == UserHeader && _errorLogger && _settings && _settings->isEnabled ( " missingInclude " ) )
14881491 {
1489- std::string fixedpath = Path::toNativeSeparators (filename);
1490- _errorLogger->reportOut (" Include file: \" " + fixedpath + " \" not found." );
1492+ // Determine line number of include
1493+ unsigned int linenr = 1 ;
1494+ unsigned int level = 0 ;
1495+ for (std::string::size_type p = 0 ; p < pos; ++p)
1496+ {
1497+ if (level == 0 && code[pos-p] == ' \n ' )
1498+ ++linenr;
1499+ else if (code.compare (pos-p, 9 , " #endfile\n " ) == 0 )
1500+ {
1501+ ++level;
1502+ }
1503+ else if (code.compare (pos-p, 6 , " #file " ) == 0 )
1504+ {
1505+ if (level == 0 )
1506+ {
1507+ --linenr;
1508+ break ;
1509+ }
1510+ --level;
1511+ }
1512+ }
1513+
1514+ std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
1515+ ErrorLogger::ErrorMessage::FileLocation loc;
1516+ loc.line = linenr; /* * @todo set correct line */
1517+ loc.setfile (Path::toNativeSeparators (filePath));
1518+ locationList.push_back (loc);
1519+
1520+ ErrorLogger::ErrorMessage errmsg (locationList, Severity::style, " Include file: \" " + filename + " \" not found." , " missingInclude" );
1521+ errmsg.file0 = file0;
1522+ _errorLogger->reportErr (errmsg);
14911523 }
14921524 }
14931525 }
@@ -2259,3 +2291,12 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
22592291 return ostr.str ();
22602292}
22612293
2294+ void Preprocessor::getErrorMessages (std::ostream &ostr)
2295+ {
2296+ std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
2297+ const ErrorLogger::ErrorMessage errmsg (locationList,
2298+ Severity::style,
2299+ " Include file: \"\" not found." ,
2300+ " missingInclude" );
2301+ ostr << errmsg.toXML () << std::endl;
2302+ }
0 commit comments