@@ -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
0 commit comments