Preprocessor: Don't include system headers twice.

This commit is contained in:
Daniel Marjamäki 2010-12-02 18:07:32 +01:00
parent eda4bcae29
commit 66f0948395
2 changed files with 12 additions and 4 deletions

View File

@ -699,7 +699,8 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe
processedFile = ostr.str(); processedFile = ostr.str();
} }
handleIncludes(processedFile, filename, includePaths); std::set<std::string> systemIncludes;
handleIncludes(processedFile, filename, includePaths, systemIncludes);
processedFile = replaceIfDefined(processedFile); processedFile = replaceIfDefined(processedFile);
@ -1476,6 +1477,7 @@ static int tolowerWrapper(int c)
void Preprocessor::handleIncludes(std::string &code, void Preprocessor::handleIncludes(std::string &code,
const std::string &filePath, const std::string &filePath,
const std::list<std::string> &includePaths, const std::list<std::string> &includePaths,
std::set<std::string> &systemIncludes,
std::set<std::string> handledFiles) std::set<std::string> handledFiles)
{ {
std::string::size_type pos = 0; std::string::size_type pos = 0;
@ -1540,7 +1542,8 @@ void Preprocessor::handleIncludes(std::string &code,
filename = Path::simplifyPath(filename.c_str()); filename = Path::simplifyPath(filename.c_str());
std::string tempFile = filename; std::string tempFile = filename;
std::transform(tempFile.begin(), tempFile.end(), tempFile.begin(), tolowerWrapper); std::transform(tempFile.begin(), tempFile.end(), tempFile.begin(), tolowerWrapper);
if (handledFiles.find(tempFile) != handledFiles.end()) if (handledFiles.find(tempFile) != handledFiles.end() ||
(headerType == SystemHeader && systemIncludes.find(tempFile) != systemIncludes.end()))
{ {
// We have processed this file already once, skip // We have processed this file already once, skip
// it this time to avoid ethernal loop. // it this time to avoid ethernal loop.
@ -1548,7 +1551,10 @@ void Preprocessor::handleIncludes(std::string &code,
continue; continue;
} }
handledFiles.insert(tempFile); if (headerType == SystemHeader)
systemIncludes.insert(tempFile);
else
handledFiles.insert(tempFile);
processedFile = Preprocessor::read(fin, filename, _settings); processedFile = Preprocessor::read(fin, filename, _settings);
fin.close(); fin.close();
} }
@ -1564,7 +1570,7 @@ void Preprocessor::handleIncludes(std::string &code,
// Remove space characters that are after or before new line character // Remove space characters that are after or before new line character
processedFile = removeSpaceNearNL(processedFile); processedFile = removeSpaceNearNL(processedFile);
handleIncludes(processedFile, filename, includePaths, handledFiles); handleIncludes(processedFile, filename, includePaths, systemIncludes, handledFiles);
processedFile = "#file \"" + filename + "\"\n" + processedFile + "\n#endfile"; processedFile = "#file \"" + filename + "\"\n" + processedFile + "\n#endfile";
code.insert(pos, processedFile); code.insert(pos, processedFile);
pos += processedFile.size(); pos += processedFile.size();

View File

@ -209,6 +209,7 @@ private:
* There must be a path separator at the end. Default parameter is empty list. * There must be a path separator at the end. Default parameter is empty list.
* Note that if path from given filename is also extracted and that is used as * 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. * a last include path if include file was not found from earlier paths.
* @param systemIncludes System includes
* @param handledFiles used in the recursive handling. Should be empty unless * @param handledFiles used in the recursive handling. Should be empty unless
* a recursive call is made. * a recursive call is made.
* @return modified source code * @return modified source code
@ -216,6 +217,7 @@ private:
void handleIncludes(std::string &code, void handleIncludes(std::string &code,
const std::string &filePath, const std::string &filePath,
const std::list<std::string> &includePaths, const std::list<std::string> &includePaths,
std::set<std::string> &systemIncludes,
std::set<std::string> handledFiles = std::set<std::string>()); std::set<std::string> handledFiles = std::set<std::string>());
Settings *_settings; Settings *_settings;