Skip to content

Commit a7de16f

Browse files
committed
simplecpp rev 7a81c1ab9
1 parent a1016f8 commit a7de16f

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

externals/simplecpp/simplecpp.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33743374
// AlwaysFalse => drop all code in #if and #else
33753375
enum IfState : std::uint8_t { True, ElseIsTrue, AlwaysFalse };
33763376
std::stack<int> ifstates;
3377+
std::stack<const Token *> iftokens;
33773378
ifstates.push(True);
33783379

33793380
std::stack<const Token *> includetokenstack;
@@ -3699,15 +3700,23 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36993700
ifstates.push(AlwaysFalse);
37003701
else
37013702
ifstates.push(conditionIsTrue ? True : ElseIsTrue);
3702-
} else if (ifstates.top() == True) {
3703-
ifstates.top() = AlwaysFalse;
3704-
} else if (ifstates.top() == ElseIsTrue && conditionIsTrue) {
3705-
ifstates.top() = True;
3703+
iftokens.push(rawtok);
3704+
} else {
3705+
if (ifstates.top() == True)
3706+
ifstates.top() = AlwaysFalse;
3707+
else if (ifstates.top() == ElseIsTrue && conditionIsTrue)
3708+
ifstates.top() = True;
3709+
iftokens.top()->nextcond = rawtok;
3710+
iftokens.top() = rawtok;
37063711
}
37073712
} else if (rawtok->str() == ELSE) {
37083713
ifstates.top() = (ifstates.top() == ElseIsTrue) ? True : AlwaysFalse;
3714+
iftokens.top()->nextcond = rawtok;
3715+
iftokens.top() = rawtok;
37093716
} else if (rawtok->str() == ENDIF) {
37103717
ifstates.pop();
3718+
iftokens.top()->nextcond = rawtok;
3719+
iftokens.pop();
37113720
} else if (rawtok->str() == UNDEF) {
37123721
if (ifstates.top() == True) {
37133722
const Token *tok = rawtok->next;
@@ -3719,7 +3728,10 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37193728
} else if (ifstates.top() == True && rawtok->str() == PRAGMA && rawtok->next && rawtok->next->str() == ONCE && sameline(rawtok,rawtok->next)) {
37203729
pragmaOnce.insert(rawtok->location.file());
37213730
}
3722-
rawtok = gotoNextLine(rawtok);
3731+
if (ifstates.top() != True && rawtok->nextcond)
3732+
rawtok = rawtok->nextcond->previous;
3733+
else
3734+
rawtok = gotoNextLine(rawtok);
37233735
continue;
37243736
}
37253737

externals/simplecpp/simplecpp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ namespace simplecpp {
157157
Location location;
158158
Token *previous{};
159159
Token *next{};
160+
mutable const Token *nextcond{};
160161

161162
const Token *previousSkipComments() const {
162163
const Token *tok = this->previous;

0 commit comments

Comments
 (0)