@@ -3532,6 +3532,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3532
3532
// AlwaysFalse => drop all code in #if and #else
3533
3533
enum IfState { True, ElseIsTrue, AlwaysFalse };
3534
3534
std::stack<int > ifstates;
3535
+ std::stack<const Token *> iftokens;
3535
3536
ifstates.push (True);
3536
3537
3537
3538
std::stack<const Token *> includetokenstack;
@@ -3855,15 +3856,24 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3855
3856
ifstates.push (AlwaysFalse);
3856
3857
else
3857
3858
ifstates.push (conditionIsTrue ? True : ElseIsTrue);
3859
+ iftokens.push (rawtok);
3858
3860
} else if (ifstates.top () == True) {
3859
3861
ifstates.top () = AlwaysFalse;
3862
+ iftokens.top ()->nextcond = rawtok;
3863
+ iftokens.top () = rawtok;
3860
3864
} else if (ifstates.top () == ElseIsTrue && conditionIsTrue) {
3861
3865
ifstates.top () = True;
3866
+ iftokens.top ()->nextcond = rawtok;
3867
+ iftokens.top () = rawtok;
3862
3868
}
3863
3869
} else if (rawtok->str () == ELSE) {
3864
3870
ifstates.top () = (ifstates.top () == ElseIsTrue) ? True : AlwaysFalse;
3871
+ iftokens.top ()->nextcond = rawtok;
3872
+ iftokens.top () = rawtok;
3865
3873
} else if (rawtok->str () == ENDIF) {
3866
3874
ifstates.pop ();
3875
+ iftokens.top ()->nextcond = rawtok;
3876
+ iftokens.pop ();
3867
3877
} else if (rawtok->str () == UNDEF) {
3868
3878
if (ifstates.top () == True) {
3869
3879
const Token *tok = rawtok->next ;
@@ -3875,7 +3885,10 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3875
3885
} else if (ifstates.top () == True && rawtok->str () == PRAGMA && rawtok->next && rawtok->next ->str () == ONCE && sameline (rawtok,rawtok->next )) {
3876
3886
pragmaOnce.insert (rawtok->location .file ());
3877
3887
}
3878
- rawtok = gotoNextLine (rawtok);
3888
+ if (ifstates.top () != True && rawtok->nextcond )
3889
+ rawtok = rawtok->nextcond ->previous ;
3890
+ else
3891
+ rawtok = gotoNextLine (rawtok);
3879
3892
continue ;
3880
3893
}
3881
3894
0 commit comments