@@ -699,17 +699,24 @@ void simplecpp::TokenList::combineOperators()
699699 }
700700}
701701
702+ static const std::string COMPL (" compl" );
702703static const std::string NOT (" not" );
703704void simplecpp::TokenList::constFoldUnaryNotPosNeg (simplecpp::Token *tok)
704705{
705706 for (; tok && tok->op != ' )' ; tok = tok->next ) {
706707 // "not" might be !
707708 if (isAlternativeUnaryOp (tok, NOT))
708709 tok->op = ' !' ;
710+ // "compl" might be ~
711+ else if (isAlternativeUnaryOp (tok, COMPL))
712+ tok->op = ' ~' ;
709713
710714 if (tok->op == ' !' && tok->next && tok->next ->number ) {
711715 tok->setstr (tok->next ->str == " 0" ? " 1" : " 0" );
712716 deleteToken (tok->next );
717+ } else if (tok->op == ' ~' && tok->next && tok->next ->number ) {
718+ tok->setstr (toString (~stringToLL (tok->next->str)));
719+ deleteToken (tok->next );
713720 } else {
714721 if (tok->previous && (tok->previous ->number || tok->previous ->name ))
715722 continue ;
@@ -1929,15 +1936,15 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
19291936 }
19301937}
19311938
1932- static const char * const altopData[] = {" and" ," or" ," bitand" ," bitor" ," not" ," not_eq" ," xor" };
1933- static const std::set<std::string> altop (&altopData[0 ], &altopData[7 ]);
1939+ static const char * const altopData[] = {" and" ," or" ," bitand" ," bitor" ," compl " , " not" ," not_eq" ," xor" };
1940+ static const std::set<std::string> altop (&altopData[0 ], &altopData[8 ]);
19341941static void simplifyName (simplecpp::TokenList &expr)
19351942{
19361943 for (simplecpp::Token *tok = expr.front (); tok; tok = tok->next ) {
19371944 if (tok->name ) {
19381945 if (altop.find (tok->str ) != altop.end ()) {
19391946 bool alt;
1940- if (tok->str == " not" ) {
1947+ if (tok->str == " not" || tok-> str == " compl " ) {
19411948 alt = isAlternativeUnaryOp (tok,tok->str );
19421949 } else {
19431950 alt = isAlternativeBinaryOp (tok,tok->str );
0 commit comments