I do not think the macros 'e1' and 'e2' are readable. The statement: e1 = expr_alloc_symbol(...); affects the caller's variable, but this is not sufficiently clear from the code. Remove the macros. No functional change intended.
Unified · Split
| @@ -135,9 +135,6 @@ void expr_free(struct expr *e) · 134 unmodified lines | ||
| 135 | 135 | |
| 136 | 136 | static int trans_count; |
| 137 | 137 | |
| 138 | −#define e1 (*ep1) | |
| 139 | −#define e2 (*ep2) | |
| 140 | − | |
| 141 | 138 | /* |
| 142 | 139 | * expr_eliminate_eq() helper. |
| 143 | 140 | * |
| @@ -150,38 +147,38 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e · 6 unmodified lines | ||
| 150 | 147 | { |
| 151 | 148 | /* Recurse down to leaves */ |
| 152 | 149 | |
| 153 | − if (e1->type == type) { | |
| 154 | − __expr_eliminate_eq(type, &e1->left.expr, &e2); | |
| 155 | − __expr_eliminate_eq(type, &e1->right.expr, &e2); | |
| 150 | + if ((*ep1)->type == type) { | |
| 151 | + __expr_eliminate_eq(type, &(*ep1)->left.expr, ep2); | |
| 152 | + __expr_eliminate_eq(type, &(*ep1)->right.expr, ep2); | |
| 156 | 153 | return; |
| 157 | 154 | } |
| 158 | − if (e2->type == type) { | |
| 159 | − __expr_eliminate_eq(type, &e1, &e2->left.expr); | |
| 160 | − __expr_eliminate_eq(type, &e1, &e2->right.expr); | |
| 155 | + if ((*ep2)->type == type) { | |
| 156 | + __expr_eliminate_eq(type, ep1, &(*ep2)->left.expr); | |
| 157 | + __expr_eliminate_eq(type, ep1, &(*ep2)->right.expr); | |
| 161 | 158 | return; |
| 162 | 159 | } |
| 163 | 160 | |
| 164 | − /* e1 and e2 are leaves. Compare them. */ | |
| 161 | + /* *ep1 and *ep2 are leaves. Compare them. */ | |
| 165 | 162 | |
| 166 | − if (e1->type == E_SYMBOL && e2->type == E_SYMBOL && | |
| 167 | − e1->left.sym == e2->left.sym && | |
| 168 | − (e1->left.sym == &symbol_yes || e1->left.sym == &symbol_no)) | |
| 163 | + if ((*ep1)->type == E_SYMBOL && (*ep2)->type == E_SYMBOL && | |
| 164 | + (*ep1)->left.sym == (*ep2)->left.sym && | |
| 165 | + ((*ep1)->left.sym == &symbol_yes || (*ep1)->left.sym == &symbol_no)) | |
| 169 | 166 | return; |
| 170 | − if (!expr_eq(e1, e2)) | |
| 167 | + if (!expr_eq(*ep1, *ep2)) | |
| 171 | 168 | return; |
| 172 | 169 | |
| 173 | − /* e1 and e2 are equal leaves. Prepare them for elimination. */ | |
| 170 | + /* *ep1 and *ep2 are equal leaves. Prepare them for elimination. */ | |
| 174 | 171 | |
| 175 | 172 | trans_count++; |
| 176 | − expr_free(e1); expr_free(e2); | |
| 173 | + expr_free(*ep1); expr_free(*ep2); | |
| 177 | 174 | switch (type) { |
| 178 | 175 | case E_OR: |
| 179 | − e1 = expr_alloc_symbol(&symbol_no); | |
| 180 | − e2 = expr_alloc_symbol(&symbol_no); | |
| 176 | + *ep1 = expr_alloc_symbol(&symbol_no); | |
| 177 | + *ep2 = expr_alloc_symbol(&symbol_no); | |
| 181 | 178 | break; |
| 182 | 179 | case E_AND: |
| 183 | − e1 = expr_alloc_symbol(&symbol_yes); | |
| 184 | − e2 = expr_alloc_symbol(&symbol_yes); | |
| 180 | + *ep1 = expr_alloc_symbol(&symbol_yes); | |
| 181 | + *ep2 = expr_alloc_symbol(&symbol_yes); | |
| 185 | 182 | break; |
| 186 | 183 | default: |
| 187 | 184 | ; |
| @@ -219,29 +216,26 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e · 31 unmodified lines | ||
| 219 | 216 | */ |
| 220 | 217 | void expr_eliminate_eq(struct expr **ep1, struct expr **ep2) |
| 221 | 218 | { |
| 222 | − if (!e1 || !e2) | |
| 219 | + if (!*ep1 || !*ep2) | |
| 223 | 220 | return; |
| 224 | − switch (e1->type) { | |
| 221 | + switch ((*ep1)->type) { | |
| 225 | 222 | case E_OR: |
| 226 | 223 | case E_AND: |
| 227 | − __expr_eliminate_eq(e1->type, ep1, ep2); | |
| 224 | + __expr_eliminate_eq((*ep1)->type, ep1, ep2); | |
| 228 | 225 | default: |
| 229 | 226 | ; |
| 230 | 227 | } |
| 231 | − if (e1->type != e2->type) switch (e2->type) { | |
| 228 | + if ((*ep1)->type != (*ep2)->type) switch ((*ep2)->type) { | |
| 232 | 229 | case E_OR: |
| 233 | 230 | case E_AND: |
| 234 | − __expr_eliminate_eq(e2->type, ep1, ep2); | |
| 231 | + __expr_eliminate_eq((*ep2)->type, ep1, ep2); | |
| 235 | 232 | default: |
| 236 | 233 | ; |
| 237 | 234 | } |
| 238 | − e1 = expr_eliminate_yn(e1); | |
| 239 | − e2 = expr_eliminate_yn(e2); | |
| 235 | + *ep1 = expr_eliminate_yn(*ep1); | |
| 236 | + *ep2 = expr_eliminate_yn(*ep2); | |
| 240 | 237 | } |
| 241 | 238 | |
| 242 | −#undef e1 | |
| 243 | −#undef e2 | |
| 244 | − | |
| 245 | 239 | /* |
| 246 | 240 | * Returns true if 'e1' and 'e2' are equal, after minor simplification. Two |
| 247 | 241 | * &&/|| expressions are considered equal if every operand in one expression |
| @@ -564,59 +558,55 @@ static struct expr *expr_join_and(struct expr *e1, struct expr *e2) · 316 unmodified lines | ||
| 564 | 558 | */ |
| 565 | 559 | static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct expr **ep2) |
| 566 | 560 | { |
| 567 | −#define e1 (*ep1) | |
| 568 | −#define e2 (*ep2) | |
| 569 | 561 | struct expr *tmp; |
| 570 | 562 | |
| 571 | 563 | /* Recurse down to leaves */ |
| 572 | 564 | |
| 573 | − if (e1->type == type) { | |
| 574 | − expr_eliminate_dups1(type, &e1->left.expr, &e2); | |
| 575 | − expr_eliminate_dups1(type, &e1->right.expr, &e2); | |
| 565 | + if ((*ep1)->type == type) { | |
| 566 | + expr_eliminate_dups1(type, &(*ep1)->left.expr, ep2); | |
| 567 | + expr_eliminate_dups1(type, &(*ep1)->right.expr, ep2); | |
| 576 | 568 | return; |
| 577 | 569 | } |
| 578 | − if (e2->type == type) { | |
| 579 | − expr_eliminate_dups1(type, &e1, &e2->left.expr); | |
| 580 | − expr_eliminate_dups1(type, &e1, &e2->right.expr); | |
| 570 | + if ((*ep2)->type == type) { | |
| 571 | + expr_eliminate_dups1(type, ep1, &(*ep2)->left.expr); | |
| 572 | + expr_eliminate_dups1(type, ep1, &(*ep2)->right.expr); | |
| 581 | 573 | return; |
| 582 | 574 | } |
| 583 | 575 | |
| 584 | − /* e1 and e2 are leaves. Compare and process them. */ | |
| 576 | + /* *ep1 and *ep2 are leaves. Compare and process them. */ | |
| 585 | 577 | |
| 586 | − if (e1 == e2) | |
| 578 | + if (*ep1 == *ep2) | |
| 587 | 579 | return; |
| 588 | 580 | |
| 589 | − switch (e1->type) { | |
| 581 | + switch ((*ep1)->type) { | |
| 590 | 582 | case E_OR: case E_AND: |
| 591 | − expr_eliminate_dups1(e1->type, &e1, &e1); | |
| 583 | + expr_eliminate_dups1((*ep1)->type, ep1, ep1); | |
| 592 | 584 | default: |
| 593 | 585 | ; |
| 594 | 586 | } |
| 595 | 587 | |
| 596 | 588 | switch (type) { |
| 597 | 589 | case E_OR: |
| 598 | − tmp = expr_join_or(e1, e2); | |
| 590 | + tmp = expr_join_or(*ep1, *ep2); | |
| 599 | 591 | if (tmp) { |
| 600 | − expr_free(e1); expr_free(e2); | |
| 601 | − e1 = expr_alloc_symbol(&symbol_no); | |
| 602 | − e2 = tmp; | |
| 592 | + expr_free(*ep1); expr_free(*ep2); | |
| 593 | + *ep1 = expr_alloc_symbol(&symbol_no); | |
| 594 | + *ep2 = tmp; | |
| 603 | 595 | trans_count++; |
| 604 | 596 | } |
| 605 | 597 | break; |
| 606 | 598 | case E_AND: |
| 607 | − tmp = expr_join_and(e1, e2); | |
| 599 | + tmp = expr_join_and(*ep1, *ep2); | |
| 608 | 600 | if (tmp) { |
| 609 | − expr_free(e1); expr_free(e2); | |
| 610 | − e1 = expr_alloc_symbol(&symbol_yes); | |
| 611 | − e2 = tmp; | |
| 601 | + expr_free(*ep1); expr_free(*ep2); | |
| 602 | + *ep1 = expr_alloc_symbol(&symbol_yes); | |
| 603 | + *ep2 = tmp; | |
| 612 | 604 | trans_count++; |
| 613 | 605 | } |
| 614 | 606 | break; |
| 615 | 607 | default: |
| 616 | 608 | ; |
| 617 | 609 | } |
| 618 | −#undef e1 | |
| 619 | −#undef e2 | |
| 620 | 610 | } |
| 621 | 611 | |
| 622 | 612 | /* |