Skip to content

Commit 658c182

Browse files
author
William Jakobsson
committed
bump files
1 parent 96d4a96 commit 658c182

2 files changed

Lines changed: 53 additions & 19 deletions

File tree

externals/simplecpp/simplecpp.cpp

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ class simplecpp::TokenList::Stream {
275275
return ch;
276276
}
277277

278-
unsigned char peekChar() {
279-
auto ch = static_cast<unsigned char>(peek());
278+
int peekChar() {
279+
int ch = peek();
280+
if (ch == EOF)
281+
return ch;
280282

281283
// For UTF-16 encoded files the BOM is 0xfeff/0xfffe. If the
282284
// character is non-ASCII character then replace it with 0xff
@@ -285,7 +287,7 @@ class simplecpp::TokenList::Stream {
285287
const auto ch2 = static_cast<unsigned char>(peek());
286288
unget();
287289
const int ch16 = makeUtf16Char(ch, ch2);
288-
ch = static_cast<unsigned char>(((ch16 >= 0x80) ? 0xff : ch16));
290+
ch = (ch16 >= 0x80) ? 0xff : ch16;
289291
}
290292

291293
// Handling of newlines..
@@ -598,7 +600,7 @@ std::string simplecpp::TokenList::stringify(bool linenrs) const
598600
return ret.str();
599601
}
600602

601-
static bool isNameChar(unsigned char ch)
603+
static bool isNameChar(int ch)
602604
{
603605
return std::isalnum(ch) || ch == '_' || ch == '$';
604606
}
@@ -635,10 +637,10 @@ static bool isStringLiteralPrefix(const std::string &str)
635637
str == "R" || str == "uR" || str == "UR" || str == "LR" || str == "u8R";
636638
}
637639

638-
void simplecpp::TokenList::lineDirective(unsigned int fileIndex, unsigned int line, Location &location)
640+
void simplecpp::TokenList::lineDirective(unsigned int fileIndex_, unsigned int line, Location &location)
639641
{
640-
if (fileIndex != location.fileIndex || line >= location.line) {
641-
location.fileIndex = fileIndex;
642+
if (fileIndex_ != location.fileIndex || line >= location.line) {
643+
location.fileIndex = fileIndex_;
642644
location.line = line;
643645
return;
644646
}
@@ -771,8 +773,21 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
771773
ch = stream.readChar();
772774
}
773775
stream.ungetChar();
774-
push_back(new Token(currentToken, location));
775-
location.adjust(currentToken);
776+
std::string::size_type pos = 0;
777+
unsigned int spliced = 0;
778+
while ((pos = currentToken.find('\\', pos)) != std::string::npos) {
779+
if (pos + 1 < currentToken.size() && currentToken[pos + 1] == '\n') {
780+
currentToken.erase(pos, 2);
781+
++spliced;
782+
} else {
783+
++pos;
784+
}
785+
}
786+
if (!currentToken.empty()) {
787+
push_back(new Token(currentToken, location));
788+
location.adjust(currentToken);
789+
}
790+
location.line += spliced;
776791
continue;
777792
}
778793
}
@@ -1739,6 +1754,9 @@ namespace simplecpp {
17391754
return tok;
17401755
}
17411756

1757+
/**
1758+
* @throws Error thrown in case of __VA_OPT__ issues
1759+
*/
17421760
bool parseDefine(const Token *nametoken) {
17431761
nameTokDef = nametoken;
17441762
variadic = false;
@@ -2201,6 +2219,8 @@ namespace simplecpp {
22012219
}
22022220

22032221
output.push_back(newMacroToken(tok->str(), loc, true, tok));
2222+
if (it != macros.end())
2223+
output.back()->markExpandedFrom(&it->second);
22042224
return tok->next;
22052225
}
22062226

@@ -3379,6 +3399,17 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33793399
}
33803400
output.clear();
33813401
return;
3402+
} catch (const simplecpp::Macro::Error& e) {
3403+
if (outputList) {
3404+
simplecpp::Output err{
3405+
Output::DUI_ERROR,
3406+
{},
3407+
e.what
3408+
};
3409+
outputList->emplace_back(std::move(err));
3410+
}
3411+
output.clear();
3412+
return;
33823413
}
33833414
}
33843415

@@ -3507,14 +3538,14 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35073538
else
35083539
it->second = macro;
35093540
}
3510-
} catch (const std::runtime_error &) {
3541+
} catch (const std::runtime_error &err) {
35113542
if (outputList) {
3512-
simplecpp::Output err{
3543+
simplecpp::Output out{
35133544
Output::SYNTAX_ERROR,
35143545
rawtok->location,
3515-
"Failed to parse #define"
3546+
std::string("Failed to parse #define, ") + err.what()
35163547
};
3517-
outputList->emplace_back(std::move(err));
3548+
outputList->emplace_back(std::move(out));
35183549
}
35193550
output.clear();
35203551
return;
@@ -3671,7 +3702,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36713702
bool closingAngularBracket = false;
36723703
if (tok) {
36733704
const std::string &sourcefile = rawtokens.file(rawtok->location);
3674-
const bool systemheader = (tok && tok->op == '<');
3705+
const bool systemheader = tok->op == '<';
36753706
std::string header;
36763707

36773708
if (systemheader) {

externals/simplecpp/simplecpp.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ namespace simplecpp {
174174
bool isOneOf(const char ops[]) const;
175175
bool startsWithOneOf(const char c[]) const;
176176
bool endsWithOneOf(const char c[]) const;
177-
static bool isNumberLike(const std::string& str) {
178-
return std::isdigit(static_cast<unsigned char>(str[0])) ||
179-
(str.size() > 1U && (str[0] == '-' || str[0] == '+') && std::isdigit(static_cast<unsigned char>(str[1])));
177+
static bool isNumberLike(const std::string& s) {
178+
return std::isdigit(static_cast<unsigned char>(s[0])) ||
179+
(s.size() > 1U && (s[0] == '-' || s[0] == '+') && std::isdigit(static_cast<unsigned char>(s[1])));
180180
}
181181

182182
TokenString macro;
@@ -213,6 +213,9 @@ namespace simplecpp {
213213
bool isExpandedFrom(const Macro* m) const {
214214
return mExpandedFrom.find(m) != mExpandedFrom.end();
215215
}
216+
void markExpandedFrom(const Macro* m) {
217+
mExpandedFrom.insert(m);
218+
}
216219

217220
void printAll() const;
218221
void printOut() const;
@@ -376,7 +379,7 @@ namespace simplecpp {
376379
const std::string& file(const Location& loc) const;
377380

378381
private:
379-
TokenList(const unsigned char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList, int unused);
382+
TokenList(const unsigned char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList, int /*unused*/);
380383

381384
void combineOperators();
382385

@@ -396,7 +399,7 @@ namespace simplecpp {
396399
void constFoldQuestionOp(Token *&tok1);
397400

398401
std::string readUntil(Stream &stream, const Location &location, char start, char end, OutputList *outputList);
399-
void lineDirective(unsigned int fileIndex, unsigned int line, Location &location);
402+
void lineDirective(unsigned int fileIndex_, unsigned int line, Location &location);
400403

401404
const Token* lastLineTok(int maxsize=1000) const;
402405
const Token* isLastLinePreprocessor(int maxsize=1000) const;

0 commit comments

Comments
 (0)