@@ -2482,7 +2482,7 @@ long long simplecpp::characterLiteralToLL(const std::string& str)
24822482 // Assuming this is a UTF-8 encoded code point.
24832483 // This decoder may not completely validate the input.
24842484 // Noncharacters are neither rejected nor replaced.
2485-
2485+
24862486 int additional_bytes;
24872487 if (value >= 0xf5 ) // higher values would result in code points above 0x10ffff
24882488 throw std::runtime_error (" assumed UTF-8 encoded source, but sequence is invalid" );
@@ -2494,26 +2494,26 @@ long long simplecpp::characterLiteralToLL(const std::string& str)
24942494 additional_bytes = 1 ;
24952495 else
24962496 throw std::runtime_error (" assumed UTF-8 encoded source, but sequence is invalid" );
2497-
2497+
24982498 value &= (1 << (6 - additional_bytes)) - 1 ;
24992499
25002500 while (additional_bytes--) {
2501- if (pos + 1 >= str.size ())
2501+ if (pos + 1 >= str.size ())
25022502 throw std::runtime_error (" assumed UTF-8 encoded source, but character literal ends unexpectedly" );
2503-
2503+
25042504 unsigned char c = str[pos++];
2505-
2505+
25062506 if (((c >> 6 ) != 2 ) // ensure c has form 0xb10xxxxxx
25072507 || (!value && additional_bytes == 1 && c < 0xa0 ) // overlong 3-bytes encoding
25082508 || (!value && additional_bytes == 2 && c < 0x90 )) // overlong 4-bytes encoding
25092509 throw std::runtime_error (" assumed UTF-8 encoded source, but sequence is invalid" );
2510-
2510+
25112511 value = (value << 6 ) | (c & ((1 << 7 ) - 1 ));
25122512 }
25132513
25142514 if (value >= 0xd800 && value <= 0xdfff )
25152515 throw std::runtime_error (" assumed UTF-8 encoded source, but sequence is invalid" );
2516-
2516+
25172517 if ((utf8 && value > 0x7f ) || (utf16 && value > 0xffff ) || value > 0x10ffff )
25182518 throw std::runtime_error (" code point too large" );
25192519 }
@@ -2804,7 +2804,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
28042804 return true ;
28052805}
28062806
2807- void simplecpp::preprocess (simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage)
2807+ void simplecpp::preprocess (simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond )
28082808{
28092809 std::map<std::string, std::size_t > sizeOfType (rawtokens.sizeOfType );
28102810 sizeOfType.insert (std::make_pair (" char" , sizeof (char )));
@@ -3119,7 +3119,17 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
31193119 tok = tmp->previous ;
31203120 }
31213121 try {
3122- conditionIsTrue = (evaluate (expr, sizeOfType) != 0 );
3122+ if (ifCond) {
3123+ std::string E;
3124+ for (const simplecpp::Token *tok = expr.cfront (); tok; tok = tok->next )
3125+ E += (E.empty () ? " " : " " ) + tok->str ();
3126+ const long long result = evaluate (expr, sizeOfType);
3127+ conditionIsTrue = (result != 0 );
3128+ ifCond->push_back (IfCond (rawtok->location , E, result));
3129+ } else {
3130+ const long long result = evaluate (expr, sizeOfType);
3131+ conditionIsTrue = (result != 0 );
3132+ }
31233133 } catch (const std::exception &e) {
31243134 if (outputList) {
31253135 Output out (rawtok->location .files );
0 commit comments