Skip to content

Commit a152704

Browse files
committed
Support for bitwise not.
1 parent 0c806cf commit a152704

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

run-tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def cleanup(out):
6969
# todo, high priority
7070
'c99-6_10_3_4_p5.c',
7171
'c99-6_10_3_4_p6.c',
72-
'cxx_compl.cpp', # if A compl B
7372
'cxx_oper_keyword_ms_compat.cpp',
7473
'expr_usual_conversions.c', # condition is true: 4U - 30 >= 0
7574
'stdint.c',

simplecpp.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,17 +699,24 @@ void simplecpp::TokenList::combineOperators()
699699
}
700700
}
701701

702+
static const std::string COMPL("compl");
702703
static const std::string NOT("not");
703704
void 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]);
19341941
static 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

Comments
 (0)