@@ -3532,6 +3532,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35323532 // AlwaysFalse => drop all code in #if and #else
35333533 enum IfState { True, ElseIsTrue, AlwaysFalse };
35343534 std::stack<int > ifstates;
3535+ std::stack<const Token *> iftokens;
35353536 ifstates.push (True);
35363537
35373538 std::stack<const Token *> includetokenstack;
@@ -3855,15 +3856,24 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
38553856 ifstates.push (AlwaysFalse);
38563857 else
38573858 ifstates.push (conditionIsTrue ? True : ElseIsTrue);
3859+ iftokens.push (rawtok);
38583860 } else if (ifstates.top () == True) {
38593861 ifstates.top () = AlwaysFalse;
3862+ iftokens.top ()->nextcond = rawtok;
3863+ iftokens.top () = rawtok;
38603864 } else if (ifstates.top () == ElseIsTrue && conditionIsTrue) {
38613865 ifstates.top () = True;
3866+ iftokens.top ()->nextcond = rawtok;
3867+ iftokens.top () = rawtok;
38623868 }
38633869 } else if (rawtok->str () == ELSE) {
38643870 ifstates.top () = (ifstates.top () == ElseIsTrue) ? True : AlwaysFalse;
3871+ iftokens.top ()->nextcond = rawtok;
3872+ iftokens.top () = rawtok;
38653873 } else if (rawtok->str () == ENDIF) {
38663874 ifstates.pop ();
3875+ iftokens.top ()->nextcond = rawtok;
3876+ iftokens.pop ();
38673877 } else if (rawtok->str () == UNDEF) {
38683878 if (ifstates.top () == True) {
38693879 const Token *tok = rawtok->next ;
@@ -3875,7 +3885,10 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
38753885 } else if (ifstates.top () == True && rawtok->str () == PRAGMA && rawtok->next && rawtok->next ->str () == ONCE && sameline (rawtok,rawtok->next )) {
38763886 pragmaOnce.insert (rawtok->location .file ());
38773887 }
3878- rawtok = gotoNextLine (rawtok);
3888+ if (ifstates.top () != True && rawtok->nextcond )
3889+ rawtok = rawtok->nextcond ->previous ;
3890+ else
3891+ rawtok = gotoNextLine (rawtok);
38793892 continue ;
38803893 }
38813894
0 commit comments