diff --git a/run-tests.py b/run-tests.py index 712ba5e6..7ad35dfd 100644 --- a/run-tests.py +++ b/run-tests.py @@ -69,7 +69,6 @@ def cleanup(out): # todo, high priority 'c99-6_10_3_4_p5.c', 'c99-6_10_3_4_p6.c', - 'cxx_compl.cpp', # if A compl B 'cxx_oper_keyword_ms_compat.cpp', 'expr_usual_conversions.c', # condition is true: 4U - 30 >= 0 'stdint.c', diff --git a/simplecpp.cpp b/simplecpp.cpp index e290421a..be3bf59b 100644 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -699,6 +699,7 @@ void simplecpp::TokenList::combineOperators() } } +static const std::string COMPL("compl"); static const std::string NOT("not"); void simplecpp::TokenList::constFoldUnaryNotPosNeg(simplecpp::Token *tok) { @@ -706,10 +707,16 @@ void simplecpp::TokenList::constFoldUnaryNotPosNeg(simplecpp::Token *tok) // "not" might be ! if (isAlternativeUnaryOp(tok, NOT)) tok->op = '!'; + // "compl" might be ~ + else if (isAlternativeUnaryOp(tok, COMPL)) + tok->op = '~'; if (tok->op == '!' && tok->next && tok->next->number) { tok->setstr(tok->next->str == "0" ? "1" : "0"); deleteToken(tok->next); + } else if (tok->op == '~' && tok->next && tok->next->number) { + tok->setstr(toString(~stringToLL(tok->next->str))); + deleteToken(tok->next); } else { if (tok->previous && (tok->previous->number || tok->previous->name)) continue; @@ -1929,15 +1936,15 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map altop(&altopData[0], &altopData[7]); +static const char * const altopData[] = {"and","or","bitand","bitor","compl","not","not_eq","xor"}; +static const std::set altop(&altopData[0], &altopData[8]); static void simplifyName(simplecpp::TokenList &expr) { for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) { if (tok->name) { if (altop.find(tok->str) != altop.end()) { bool alt; - if (tok->str == "not") { + if (tok->str == "not" || tok->str == "compl") { alt = isAlternativeUnaryOp(tok,tok->str); } else { alt = isAlternativeBinaryOp(tok,tok->str);