bump simplecpp (fix hang when systemheader includes itself)

This commit is contained in:
Daniel Marjamäki 2020-09-14 15:43:43 +02:00
parent 8a90e55ece
commit 566e74fae0
1 changed files with 24 additions and 33 deletions

View File

@ -2363,30 +2363,30 @@ static std::string _openHeader(std::ifstream &f, const std::string &path)
#endif #endif
} }
static std::string getRelativeFileName(const std::string &sourcefile, const std::string &header)
{
if (sourcefile.find_first_of("\\/") != std::string::npos)
return simplecpp::simplifyPath(sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header);
return simplecpp::simplifyPath(header);
}
static std::string openHeaderRelative(std::ifstream &f, const std::string &sourcefile, const std::string &header) static std::string openHeaderRelative(std::ifstream &f, const std::string &sourcefile, const std::string &header)
{ {
if (sourcefile.find_first_of("\\/") != std::string::npos) { return _openHeader(f, getRelativeFileName(sourcefile, header));
const std::string s = sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header; }
std::string simplePath = _openHeader(f, s);
if (!simplePath.empty()) static std::string getIncludePathFileName(const std::string &includePath, const std::string &header)
return simplePath; {
} else { std::string path = includePath;
std::string simplePath = _openHeader(f, header); if (!path.empty() && path[path.size()-1U]!='/' && path[path.size()-1U]!='\\')
if (!simplePath.empty()) path += '/';
return simplePath; return path + header;
}
return "";
} }
static std::string openHeaderIncludePath(std::ifstream &f, const simplecpp::DUI &dui, const std::string &header) static std::string openHeaderIncludePath(std::ifstream &f, const simplecpp::DUI &dui, const std::string &header)
{ {
for (std::list<std::string>::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) { for (std::list<std::string>::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) {
std::string s = *it; std::string simplePath = _openHeader(f, getIncludePathFileName(*it, header));
if (!s.empty() && s[s.size()-1U]!='/' && s[s.size()-1U]!='\\')
s += '/';
s += header;
std::string simplePath = _openHeader(f, s);
if (!simplePath.empty()) if (!simplePath.empty())
return simplePath; return simplePath;
} }
@ -2418,28 +2418,19 @@ static std::string getFileName(const std::map<std::string, simplecpp::TokenList
return (filedata.find(header) != filedata.end()) ? simplecpp::simplifyPath(header) : ""; return (filedata.find(header) != filedata.end()) ? simplecpp::simplifyPath(header) : "";
} }
if (!systemheader) { const std::string relativeFilename = getRelativeFileName(sourcefile, header);
if (sourcefile.find_first_of("\\/") != std::string::npos) { if (!systemheader && filedata.find(relativeFilename) != filedata.end())
const std::string s(simplecpp::simplifyPath(sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header)); return relativeFilename;
if (filedata.find(s) != filedata.end())
return s;
} else {
std::string s = simplecpp::simplifyPath(header);
if (filedata.find(s) != filedata.end())
return s;
}
}
for (std::list<std::string>::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) { for (std::list<std::string>::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) {
std::string s = *it; std::string s = simplecpp::simplifyPath(getIncludePathFileName(*it, header));
if (!s.empty() && s[s.size()-1U]!='/' && s[s.size()-1U]!='\\')
s += '/';
s += header;
s = simplecpp::simplifyPath(s);
if (filedata.find(s) != filedata.end()) if (filedata.find(s) != filedata.end())
return s; return s;
} }
if (filedata.find(relativeFilename) != filedata.end())
return relativeFilename;
return ""; return "";
} }