@@ -3740,11 +3740,23 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37403740 conditionIsTrue = false ;
37413741 }
37423742 else if (rawtok->str () == IFDEF ) {
3743- conditionIsTrue = (macros.find (rawtok->next ->str ()) != macros.end () || (hasInclude && rawtok->next ->str () == HAS_INCLUDE ));
3744- maybeUsedMacros[rawtok->next ->str ()].emplace_back (rawtok->next ->location );
3743+ const std::string &name = rawtok->next ->str ();
3744+ conditionIsTrue = (macros.find (name) != macros.end () || (hasInclude && name == HAS_INCLUDE ));
3745+ maybeUsedMacros[name].emplace_back (rawtok->next ->location );
3746+ if (ifCond) {
3747+ std::string E = " defined(" + name + " )" ;
3748+ const long long result = conditionIsTrue ? 1 : 0 ;
3749+ ifCond->emplace_back (rawtok->location , E, result);
3750+ }
37453751 } else if (rawtok->str () == IFNDEF ) {
3746- conditionIsTrue = (macros.find (rawtok->next ->str ()) == macros.end () && !(hasInclude && rawtok->next ->str () == HAS_INCLUDE ));
3747- maybeUsedMacros[rawtok->next ->str ()].emplace_back (rawtok->next ->location );
3752+ const std::string &name = rawtok->next ->str ();
3753+ conditionIsTrue = (macros.find (name) == macros.end () && !(hasInclude && name == HAS_INCLUDE ));
3754+ maybeUsedMacros[name].emplace_back (rawtok->next ->location );
3755+ if (ifCond) {
3756+ std::string E = " !defined(" + name + " )" ;
3757+ const long long result = conditionIsTrue ? 1 : 0 ;
3758+ ifCond->emplace_back (rawtok->location , E, result);
3759+ }
37483760 } else { /* if (rawtok->str() == IF || rawtok->str() == ELIF)*/
37493761 TokenList expr (files);
37503762 for (const Token *tok = rawtok->next ; tok && tok->location .sameline (rawtok->location ); tok = tok->next ) {
0 commit comments