Revert "bump simplecpp"

This reverts commit 383e1b7cd1.
This commit is contained in:
Daniel Marjamäki 2019-05-02 06:50:29 +02:00
parent 202d38b9eb
commit 4a8fe3fb23
2 changed files with 25 additions and 31 deletions

View File

@ -446,23 +446,16 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U)); location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
location.line = 1U; location.line = 1U;
} else if (lastline == "# line %num%") { } else if (lastline == "# line %num%") {
const Location loc1 = location; loc.push(location);
location.line = std::atol(cback()->str().c_str()); location.line = std::atol(cback()->str().c_str());
if (location.line < loc1.line)
location.line = loc1.line;
} else if (lastline == "# line %num% %str%") { } else if (lastline == "# line %num% %str%") {
const Location loc1 = location;
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
location.line = std::atol(cback()->previous->str().c_str());
if (loc1.fileIndex == location.fileIndex && location.line < loc1.line)
location.line = loc1.line;
} else if (lastline == "# %num% %str%") {
const Location loc1 = location;
loc.push(location); loc.push(location);
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U)); location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
location.line = std::atol(cback()->previous->str().c_str()); location.line = std::atol(cback()->previous->str().c_str());
if (loc1.fileIndex == location.fileIndex && location.line < loc1.line) } else if (lastline == "# %num% %str%") {
location.line = loc1.line; loc.push(location);
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
location.line = std::atol(cback()->previous->str().c_str());
} }
// #endfile // #endfile
else if (lastline == "# endfile" && !loc.empty()) { else if (lastline == "# endfile" && !loc.empty()) {
@ -555,8 +548,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
else if (ch == '\"' || ch == '\'') { else if (ch == '\"' || ch == '\'') {
std::string prefix; std::string prefix;
if (cback() && cback()->name && isStringLiteralPrefix(cback()->str()) && if (cback() && cback()->name && isStringLiteralPrefix(cback()->str()) &&
((cback()->location.col + cback()->str().size()) == location.col) && ((cback()->location.col + cback()->str().size()) == location.col)) {
(cback()->location.line == location.line)) {
prefix = cback()->str(); prefix = cback()->str();
} }
// C++11 raw string literal // C++11 raw string literal
@ -1124,9 +1116,9 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const
if (tok->comment) if (tok->comment)
continue; continue;
if (!ret.empty()) if (!ret.empty())
ret.insert(0, 1, ' '); ret = ' ' + ret;
ret.insert(0, tok->str()[0] == '\"' ? std::string("%str%") ret = (tok->str()[0] == '\"' ? std::string("%str%")
: tok->number ? std::string("%num%") : tok->str()); : tok->number ? std::string("%num%") : tok->str()) + ret;
if (++count > maxsize) if (++count > maxsize)
return ""; return "";
} }
@ -2024,7 +2016,7 @@ static std::string realFilename(const std::string &f)
continue; continue;
} }
bool isDriveSpecification = bool isDriveSpecification =
(pos == 2 && subpath.size() == 2 && std::isalpha(subpath[0]) && subpath[1] == ':'); (pos == 2 && subpath.size() == 2 && std::isalpha(subpath[0]) && subpath[1] == ':');
// Append real filename (proper case) // Append real filename (proper case)
@ -2290,21 +2282,23 @@ static std::string _openHeader(std::ifstream &f, const std::string &path)
#endif #endif
} }
static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header) static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader)
{ {
if (isAbsolutePath(header)) { if (isAbsolutePath(header)) {
return _openHeader(f, header); return _openHeader(f, header);
} }
if (sourcefile.find_first_of("\\/") != std::string::npos) { if (!systemheader) {
const std::string s = sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header; if (sourcefile.find_first_of("\\/") != std::string::npos) {
const std::string simplePath = _openHeader(f, s); const std::string s = sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header;
if (!simplePath.empty()) std::string simplePath = _openHeader(f, s);
return simplePath; if (!simplePath.empty())
} else { return simplePath;
const std::string simplePath = _openHeader(f, header); } else {
if (!simplePath.empty()) std::string simplePath = _openHeader(f, header);
return simplePath; if (!simplePath.empty())
return simplePath;
}
} }
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) {
@ -2413,7 +2407,7 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
continue; continue;
std::ifstream f; std::ifstream f;
const std::string header2 = openHeader(f,dui,sourcefile,header); const std::string header2 = openHeader(f,dui,sourcefile,header,systemheader);
if (!f.is_open()) if (!f.is_open())
continue; continue;
@ -2634,7 +2628,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
if (header2.empty()) { if (header2.empty()) {
// try to load file.. // try to load file..
std::ifstream f; std::ifstream f;
header2 = openHeader(f, dui, rawtok->location.file(), header); header2 = openHeader(f, dui, rawtok->location.file(), header, systemheader);
if (f.is_open()) { if (f.is_open()) {
TokenList *tokens = new TokenList(f, files, header2, outputList); TokenList *tokens = new TokenList(f, files, header2, outputList);
filedata[header2] = tokens; filedata[header2] = tokens;

View File

@ -108,7 +108,7 @@ namespace simplecpp {
void flags() { void flags() {
name = (std::isalpha((unsigned char)string[0]) || string[0] == '_' || string[0] == '$'); name = (std::isalpha((unsigned char)string[0]) || string[0] == '_' || string[0] == '$');
comment = string.size() > 1U && string[0] == '/' && (string[1] == '/' || string[1] == '*'); comment = (string.compare(0, 2, "//") == 0 || string.compare(0, 2, "/*") == 0);
number = std::isdigit((unsigned char)string[0]) || (string.size() > 1U && string[0] == '-' && std::isdigit((unsigned char)string[1])); number = std::isdigit((unsigned char)string[0]) || (string.size() > 1U && string[0] == '-' && std::isdigit((unsigned char)string[1]));
op = (string.size() == 1U) ? string[0] : '\0'; op = (string.size() == 1U) ? string[0] : '\0';
} }