* expr_eliminate_eq() 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. Two equal leaves are both replaced with either 'y' * or 'n' as appropriate for 'type', to be eliminated later. */
| 148 | * or 'n' as appropriate for 'type', to be eliminated later. |
| 149 | */ |
| 150 | static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct expr **ep2) |
| 151 | { |
| 152 | /* Recurse down to leaves */ |
| 153 | |
| 154 | if (e1->type == type) { |
| 155 | __expr_eliminate_eq(type, &e1->left.expr, &e2); |
| 156 | __expr_eliminate_eq(type, &e1->right.expr, &e2); |
| 157 | return; |
| 158 | } |
| 159 | if (e2->type == type) { |
| 160 | __expr_eliminate_eq(type, &e1, &e2->left.expr); |
| 161 | __expr_eliminate_eq(type, &e1, &e2->right.expr); |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | /* e1 and e2 are leaves. Compare them. */ |
| 166 | |
| 167 | if (e1->type == E_SYMBOL && e2->type == E_SYMBOL && |
| 168 | e1->left.sym == e2->left.sym && |
| 169 | (e1->left.sym == &symbol_yes || e1->left.sym == &symbol_no)) |
| 170 | return; |
| 171 | if (!expr_eq(e1, e2)) |
| 172 | return; |
| 173 | |
| 174 | /* e1 and e2 are equal leaves. Prepare them for elimination. */ |
| 175 | |
| 176 | trans_count++; |
| 177 | expr_free(e1); expr_free(e2); |
| 178 | switch (type) { |
| 179 | case E_OR: |
| 180 | e1 = expr_alloc_symbol(&symbol_no); |
| 181 | e2 = expr_alloc_symbol(&symbol_no); |
| 182 | break; |
| 183 | case E_AND: |
| 184 | e1 = expr_alloc_symbol(&symbol_yes); |
| 185 | e2 = expr_alloc_symbol(&symbol_yes); |
| 186 | break; |
| 187 | default: |
| 188 | ; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Rewrites the expressions 'ep1' and 'ep2' to remove operands common to both. |
no test coverage detected