* expr_eliminate_dups() helper. * * Walks the two expression trees given in 'ep1' and 'ep2'. Any node that does * not have type 'type' (E_OR/E_AND) is considered a leaf, and is compared * against all other leaves to look for simplifications. */
| 594 | * against all other leaves to look for simplifications. |
| 595 | */ |
| 596 | static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct expr **ep2) |
| 597 | { |
| 598 | #define e1 (*ep1) |
| 599 | #define e2 (*ep2) |
| 600 | struct expr *tmp; |
| 601 | |
| 602 | /* Recurse down to leaves */ |
| 603 | |
| 604 | if (e1->type == type) { |
| 605 | expr_eliminate_dups1(type, &e1->left.expr, &e2); |
| 606 | expr_eliminate_dups1(type, &e1->right.expr, &e2); |
| 607 | return; |
| 608 | } |
| 609 | if (e2->type == type) { |
| 610 | expr_eliminate_dups1(type, &e1, &e2->left.expr); |
| 611 | expr_eliminate_dups1(type, &e1, &e2->right.expr); |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | /* e1 and e2 are leaves. Compare and process them. */ |
| 616 | |
| 617 | if (e1 == e2) |
| 618 | return; |
| 619 | |
| 620 | switch (e1->type) { |
| 621 | case E_OR: case E_AND: |
| 622 | expr_eliminate_dups1(e1->type, &e1, &e1); |
| 623 | default: |
| 624 | ; |
| 625 | } |
| 626 | |
| 627 | switch (type) { |
| 628 | case E_OR: |
| 629 | tmp = expr_join_or(e1, e2); |
| 630 | if (tmp) { |
| 631 | expr_free(e1); expr_free(e2); |
| 632 | e1 = expr_alloc_symbol(&symbol_no); |
| 633 | e2 = tmp; |
| 634 | trans_count++; |
| 635 | } |
| 636 | break; |
| 637 | case E_AND: |
| 638 | tmp = expr_join_and(e1, e2); |
| 639 | if (tmp) { |
| 640 | expr_free(e1); expr_free(e2); |
| 641 | e1 = expr_alloc_symbol(&symbol_yes); |
| 642 | e2 = tmp; |
| 643 | trans_count++; |
| 644 | } |
| 645 | break; |
| 646 | default: |
| 647 | ; |
| 648 | } |
| 649 | #undef e1 |
| 650 | #undef e2 |
| 651 | } |
| 652 | |
| 653 | /* |
no test coverage detected