Skip to content

Commit bdee2ff

Browse files
authored
bump simplecpp (#4618)
1 parent 6eccb2e commit bdee2ff

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

externals/simplecpp/simplecpp.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424

2525
#include <algorithm>
2626
#include <climits>
27+
#include <cstddef>
28+
#include <cstdlib>
2729
#include <cstring>
2830
#include <ctime>
2931
#include <exception>
30-
#include <fstream>
32+
#include <fstream> // IWYU pragma: keep
3133
#include <iostream>
3234
#include <limits>
33-
#include <sstream>
35+
#include <sstream> // IWYU pragma: keep
3436
#include <stack>
3537
#include <stdexcept>
3638
#if __cplusplus >= 201103L
@@ -136,7 +138,7 @@ static bool startsWith(const std::string &str, const std::string &s)
136138

137139
static bool endsWith(const std::string &s, const std::string &e)
138140
{
139-
return (s.size() >= e.size() && s.compare(s.size() - e.size(), e.size(), e) == 0);
141+
return (s.size() >= e.size()) && std::equal(e.rbegin(), e.rend(), s.rbegin());
140142
}
141143

142144
static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
@@ -566,7 +568,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
566568

567569
TokenString currentToken;
568570

569-
if (cback() && cback()->location.line == location.line && cback()->previous && cback()->previous->op == '#' && (lastLine() == "# error" || lastLine() == "# warning")) {
571+
if (cback() && cback()->location.line == location.line && cback()->previous && cback()->previous->op == '#' && isLastLinePreprocessor() && (lastLine() == "# error" || lastLine() == "# warning")) {
570572
char prev = ' ';
571573
while (istr.good() && (prev == '\\' || (ch != '\r' && ch != '\n'))) {
572574
currentToken += ch;
@@ -627,7 +629,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
627629
currentToken.erase(pos,2);
628630
++multiline;
629631
}
630-
if (multiline || startsWith(lastLine(10),"# ")) {
632+
if (multiline || isLastLinePreprocessor()) {
631633
pos = 0;
632634
while ((pos = currentToken.find('\n',pos)) != std::string::npos) {
633635
currentToken.erase(pos,1);
@@ -708,7 +710,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
708710
else
709711
back()->setstr(prefix + s);
710712

711-
if (newlines > 0 && lastLine().compare(0,9,"# define ") == 0) {
713+
if (newlines > 0 && isLastLinePreprocessor() && lastLine().compare(0,9,"# define ") == 0) {
712714
multiline += newlines;
713715
location.adjust(s);
714716
} else {
@@ -721,7 +723,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
721723
currentToken += ch;
722724
}
723725

724-
if (currentToken == "<" && lastLine() == "# include") {
726+
if (*currentToken.begin() == '<' && isLastLinePreprocessor() && lastLine() == "# include") {
725727
currentToken = readUntil(istr, location, '<', '>', outputList, bom);
726728
if (currentToken.size() < 2U)
727729
return;
@@ -2862,11 +2864,15 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
28622864

28632865
if (systemheader) {
28642866
ret = openHeaderIncludePath(f, dui, header);
2865-
return ret.empty() ? openHeaderRelative(f, sourcefile, header) : ret;
2867+
if (ret.empty())
2868+
return openHeaderRelative(f, sourcefile, header);
2869+
return ret;
28662870
}
28672871

28682872
ret = openHeaderRelative(f, sourcefile, header);
2869-
return ret.empty() ? openHeaderIncludePath(f, dui, header) : ret;
2873+
if (ret.empty())
2874+
return openHeaderIncludePath(f, dui, header);
2875+
return ret;
28702876
}
28712877

28722878
static std::string getFileName(const std::map<std::string, simplecpp::TokenList *> &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader)

externals/simplecpp/simplecpp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#define simplecppH
2121

2222
#include <cctype>
23-
#include <cstddef>
2423
#include <cstring>
2524
#include <istream>
2625
#include <list>

0 commit comments

Comments
 (0)