Skip to content

Commit 342a9d7

Browse files
committed
Update simplecpp
1 parent 6ac1ec9 commit 342a9d7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

externals/simplecpp/simplecpp.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3299,6 +3299,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
32993299
// AlwaysFalse => drop all code in #if and #else
33003300
enum IfState { True, ElseIsTrue, AlwaysFalse };
33013301
std::stack<int> ifstates;
3302+
std::stack<Token *> iftokens;
33023303
ifstates.push(True);
33033304

33043305
std::stack<const Token *> includetokenstack;
@@ -3607,15 +3608,24 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36073608
ifstates.push(AlwaysFalse);
36083609
else
36093610
ifstates.push(conditionIsTrue ? True : ElseIsTrue);
3611+
iftokens.push(rawtok->previous);
36103612
} else if (ifstates.top() == True) {
36113613
ifstates.top() = AlwaysFalse;
3614+
iftokens.top()->skip = rawtok->previous;
3615+
iftokens.top() = rawtok->previous;
36123616
} else if (ifstates.top() == ElseIsTrue && conditionIsTrue) {
36133617
ifstates.top() = True;
3618+
iftokens.top()->skip = rawtok->previous;
3619+
iftokens.top() = rawtok->previous;
36143620
}
36153621
} else if (rawtok->str() == ELSE) {
36163622
ifstates.top() = (ifstates.top() == ElseIsTrue) ? True : AlwaysFalse;
3623+
iftokens.top()->skip = rawtok->previous;
3624+
iftokens.top() = rawtok->previous;
36173625
} else if (rawtok->str() == ENDIF) {
36183626
ifstates.pop();
3627+
iftokens.top()->skip = rawtok->previous;
3628+
iftokens.pop();
36193629
} else if (rawtok->str() == UNDEF) {
36203630
if (ifstates.top() == True) {
36213631
const Token *tok = rawtok->next;
@@ -3627,7 +3637,10 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36273637
} else if (ifstates.top() == True && rawtok->str() == PRAGMA && rawtok->next && rawtok->next->str() == ONCE && sameline(rawtok,rawtok->next)) {
36283638
pragmaOnce.insert(rawtok->location.file());
36293639
}
3630-
rawtok = gotoNextLine(rawtok);
3640+
if (ifstates.top() != True && rawtok->previous && rawtok->previous->skip)
3641+
rawtok = rawtok->previous->skip;
3642+
else
3643+
rawtok = gotoNextLine(rawtok);
36313644
continue;
36323645
}
36333646

externals/simplecpp/simplecpp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ namespace simplecpp {
109109
class SIMPLECPP_LIB Token {
110110
public:
111111
Token(const TokenString &s, const Location &loc, bool wsahead = false) :
112-
whitespaceahead(wsahead), location(loc), previous(nullptr), next(nullptr), string(s) {
112+
whitespaceahead(wsahead), location(loc), previous(nullptr), next(nullptr), skip(nullptr), string(s) {
113113
flags();
114114
}
115115

116116
Token(const Token &tok) :
117-
macro(tok.macro), op(tok.op), comment(tok.comment), name(tok.name), number(tok.number), whitespaceahead(tok.whitespaceahead), location(tok.location), previous(nullptr), next(nullptr), string(tok.string), mExpandedFrom(tok.mExpandedFrom) {
117+
macro(tok.macro), op(tok.op), comment(tok.comment), name(tok.name), number(tok.number), whitespaceahead(tok.whitespaceahead), location(tok.location), previous(nullptr), next(nullptr), skip(nullptr), string(tok.string), mExpandedFrom(tok.mExpandedFrom) {
118118
}
119119

120120
void flags() {
@@ -150,6 +150,7 @@ namespace simplecpp {
150150
Location location;
151151
Token *previous;
152152
Token *next;
153+
Token *skip;
153154

154155
const Token *previousSkipComments() const {
155156
const Token *tok = this->previous;

0 commit comments

Comments
 (0)