Skip to content

Commit 81b0219

Browse files
committed
bump simplecpp
1 parent b1cb03b commit 81b0219

2 files changed

Lines changed: 69 additions & 30 deletions

File tree

externals/simplecpp/simplecpp.cpp

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ simplecpp::TokenList::TokenList(const TokenList &other) : frontToken(NULL), back
200200
*this = other;
201201
}
202202

203+
#if __cplusplus >= 201103L
204+
simplecpp::TokenList::TokenList(TokenList &&other) : frontToken(NULL), backToken(NULL), files(other.files)
205+
{
206+
*this = std::move(other);
207+
}
208+
#endif
209+
203210
simplecpp::TokenList::~TokenList()
204211
{
205212
clear();
@@ -216,6 +223,21 @@ simplecpp::TokenList &simplecpp::TokenList::operator=(const TokenList &other)
216223
return *this;
217224
}
218225

226+
#if __cplusplus >= 201103L
227+
simplecpp::TokenList &simplecpp::TokenList::operator=(TokenList &&other)
228+
{
229+
if (this != &other) {
230+
clear();
231+
backToken = other.backToken;
232+
other.backToken = NULL;
233+
frontToken = other.frontToken;
234+
other.frontToken = NULL;
235+
sizeOfType = std::move(other.sizeOfType);
236+
}
237+
return *this;
238+
}
239+
#endif
240+
219241
void simplecpp::TokenList::clear()
220242
{
221243
backToken = NULL;
@@ -390,6 +412,23 @@ static bool isStringLiteralPrefix(const std::string &str)
390412
str == "R" || str == "uR" || str == "UR" || str == "LR" || str == "u8R";
391413
}
392414

415+
void simplecpp::TokenList::lineDirective(unsigned int fileIndex, unsigned int line, Location *location)
416+
{
417+
if (fileIndex != location->fileIndex || line >= location->line) {
418+
location->fileIndex = fileIndex;
419+
location->line = line;
420+
return;
421+
}
422+
423+
if (line + 2 >= location->line) {
424+
location->line = line;
425+
while (cback()->op != '#')
426+
deleteToken(back());
427+
deleteToken(back());
428+
return;
429+
}
430+
}
431+
393432
void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filename, OutputList *outputList)
394433
{
395434
std::stack<simplecpp::Location> loc;
@@ -446,16 +485,10 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
446485
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
447486
location.line = 1U;
448487
} else if (lastline == "# line %num%") {
449-
loc.push(location);
450-
location.line = std::atol(cback()->str().c_str());
451-
} else if (lastline == "# line %num% %str%") {
452-
loc.push(location);
453-
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
454-
location.line = std::atol(cback()->previous->str().c_str());
455-
} else if (lastline == "# %num% %str%") {
456-
loc.push(location);
457-
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
458-
location.line = std::atol(cback()->previous->str().c_str());
488+
lineDirective(location.fileIndex, std::atol(cback()->str().c_str()), &location);
489+
} else if (lastline == "# %num% %str%" || lastline == "# line %num% %str%") {
490+
lineDirective(fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U)),
491+
std::atol(cback()->previous->str().c_str()), &location);
459492
}
460493
// #endfile
461494
else if (lastline == "# endfile" && !loc.empty()) {
@@ -548,7 +581,8 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
548581
else if (ch == '\"' || ch == '\'') {
549582
std::string prefix;
550583
if (cback() && cback()->name && isStringLiteralPrefix(cback()->str()) &&
551-
((cback()->location.col + cback()->str().size()) == location.col)) {
584+
((cback()->location.col + cback()->str().size()) == location.col) &&
585+
(cback()->location.line == location.line)) {
552586
prefix = cback()->str();
553587
}
554588
// C++11 raw string literal
@@ -1116,9 +1150,9 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const
11161150
if (tok->comment)
11171151
continue;
11181152
if (!ret.empty())
1119-
ret = ' ' + ret;
1120-
ret = (tok->str()[0] == '\"' ? std::string("%str%")
1121-
: tok->number ? std::string("%num%") : tok->str()) + ret;
1153+
ret.insert(0, 1, ' ');
1154+
ret.insert(0, tok->str()[0] == '\"' ? std::string("%str%")
1155+
: tok->number ? std::string("%num%") : tok->str());
11221156
if (++count > maxsize)
11231157
return "";
11241158
}
@@ -2016,7 +2050,7 @@ static std::string realFilename(const std::string &f)
20162050
continue;
20172051
}
20182052

2019-
bool isDriveSpecification =
2053+
bool isDriveSpecification =
20202054
(pos == 2 && subpath.size() == 2 && std::isalpha(subpath[0]) && subpath[1] == ':');
20212055

20222056
// Append real filename (proper case)
@@ -2282,23 +2316,21 @@ static std::string _openHeader(std::ifstream &f, const std::string &path)
22822316
#endif
22832317
}
22842318

2285-
static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader)
2319+
static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header)
22862320
{
22872321
if (isAbsolutePath(header)) {
22882322
return _openHeader(f, header);
22892323
}
22902324

2291-
if (!systemheader) {
2292-
if (sourcefile.find_first_of("\\/") != std::string::npos) {
2293-
const std::string s = sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header;
2294-
std::string simplePath = _openHeader(f, s);
2295-
if (!simplePath.empty())
2296-
return simplePath;
2297-
} else {
2298-
std::string simplePath = _openHeader(f, header);
2299-
if (!simplePath.empty())
2300-
return simplePath;
2301-
}
2325+
if (sourcefile.find_first_of("\\/") != std::string::npos) {
2326+
const std::string s = sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header;
2327+
const std::string simplePath = _openHeader(f, s);
2328+
if (!simplePath.empty())
2329+
return simplePath;
2330+
} else {
2331+
const std::string simplePath = _openHeader(f, header);
2332+
if (!simplePath.empty())
2333+
return simplePath;
23022334
}
23032335

23042336
for (std::list<std::string>::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) {
@@ -2407,7 +2439,7 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
24072439
continue;
24082440

24092441
std::ifstream f;
2410-
const std::string header2 = openHeader(f,dui,sourcefile,header,systemheader);
2442+
const std::string header2 = openHeader(f,dui,sourcefile,header);
24112443
if (!f.is_open())
24122444
continue;
24132445

@@ -2628,7 +2660,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
26282660
if (header2.empty()) {
26292661
// try to load file..
26302662
std::ifstream f;
2631-
header2 = openHeader(f, dui, rawtok->location.file(), header, systemheader);
2663+
header2 = openHeader(f, dui, rawtok->location.file(), header);
26322664
if (f.is_open()) {
26332665
TokenList *tokens = new TokenList(f, files, header2, outputList);
26342666
filedata[header2] = tokens;

externals/simplecpp/simplecpp.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace simplecpp {
108108

109109
void flags() {
110110
name = (std::isalpha((unsigned char)string[0]) || string[0] == '_' || string[0] == '$');
111-
comment = (string.compare(0, 2, "//") == 0 || string.compare(0, 2, "/*") == 0);
111+
comment = string.size() > 1U && string[0] == '/' && (string[1] == '/' || string[1] == '*');
112112
number = std::isdigit((unsigned char)string[0]) || (string.size() > 1U && string[0] == '-' && std::isdigit((unsigned char)string[1]));
113113
op = (string.size() == 1U) ? string[0] : '\0';
114114
}
@@ -181,8 +181,14 @@ namespace simplecpp {
181181
explicit TokenList(std::vector<std::string> &filenames);
182182
TokenList(std::istream &istr, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = 0);
183183
TokenList(const TokenList &other);
184+
#if __cplusplus >= 201103L
185+
TokenList(TokenList &&other);
186+
#endif
184187
~TokenList();
185188
TokenList &operator=(const TokenList &other);
189+
#if __cplusplus >= 201103L
190+
TokenList &operator=(TokenList &&other);
191+
#endif
186192

187193
void clear();
188194
bool empty() const {
@@ -259,6 +265,7 @@ namespace simplecpp {
259265
void constFoldQuestionOp(Token **tok1);
260266

261267
std::string readUntil(std::istream &istr, const Location &location, const char start, const char end, OutputList *outputList, unsigned int bom);
268+
void lineDirective(unsigned int fileIndex, unsigned int line, Location *location);
262269

263270
std::string lastLine(int maxsize=100000) const;
264271

0 commit comments

Comments
 (0)