History

kconfig: remove 'e1' and 'e2' macros from expression deduplication

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.

Masahiro Yamada committed 2 years ago

Commit 3c2f84c1 parent 94a4b0a1 file · +42 −52Browse files

Unified · Split

scripts/kconfig/expr.c+42−52
@@ -135,9 +135,6 @@ void expr_free(struct expr *e) · 134 unmodified lines
135 135
136static int trans_count;136static int trans_count;
137 137
138#define e1 (*ep1)
139#define e2 (*ep2)
140
141/*138/*
142 * expr_eliminate_eq() helper.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 /* Recurse down to leaves */148 /* Recurse down to leaves */
152 149
153 if (e1->type == type) {150 if ((*ep1)->type == type) {
154 __expr_eliminate_eq(type, &e1->left.expr, &e2);151 __expr_eliminate_eq(type, &(*ep1)->left.expr, ep2);
155 __expr_eliminate_eq(type, &e1->right.expr, &e2);152 __expr_eliminate_eq(type, &(*ep1)->right.expr, ep2);
156 return;153 return;
157 }154 }
158 if (e2->type == type) {155 if ((*ep2)->type == type) {
159 __expr_eliminate_eq(type, &e1, &e2->left.expr);156 __expr_eliminate_eq(type, ep1, &(*ep2)->left.expr);
160 __expr_eliminate_eq(type, &e1, &e2->right.expr);157 __expr_eliminate_eq(type, ep1, &(*ep2)->right.expr);
161 return;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 &&163 if ((*ep1)->type == E_SYMBOL && (*ep2)->type == E_SYMBOL &&
167 e1->left.sym == e2->left.sym &&164 (*ep1)->left.sym == (*ep2)->left.sym &&
168 (e1->left.sym == &symbol_yes || e1->left.sym == &symbol_no))165 ((*ep1)->left.sym == &symbol_yes || (*ep1)->left.sym == &symbol_no))
169 return;166 return;
170 if (!expr_eq(e1, e2))167 if (!expr_eq(*ep1, *ep2))
171 return;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 trans_count++;172 trans_count++;
176 expr_free(e1); expr_free(e2);173 expr_free(*ep1); expr_free(*ep2);
177 switch (type) {174 switch (type) {
178 case E_OR:175 case E_OR:
179 e1 = expr_alloc_symbol(&symbol_no);176 *ep1 = expr_alloc_symbol(&symbol_no);
180 e2 = expr_alloc_symbol(&symbol_no);177 *ep2 = expr_alloc_symbol(&symbol_no);
181 break;178 break;
182 case E_AND:179 case E_AND:
183 e1 = expr_alloc_symbol(&symbol_yes);180 *ep1 = expr_alloc_symbol(&symbol_yes);
184 e2 = expr_alloc_symbol(&symbol_yes);181 *ep2 = expr_alloc_symbol(&symbol_yes);
185 break;182 break;
186 default: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 */
220void expr_eliminate_eq(struct expr **ep1, struct expr **ep2)217void expr_eliminate_eq(struct expr **ep1, struct expr **ep2)
221{218{
222 if (!e1 || !e2)219 if (!*ep1 || !*ep2)
223 return;220 return;
224 switch (e1->type) {221 switch ((*ep1)->type) {
225 case E_OR:222 case E_OR:
226 case E_AND:223 case E_AND:
227 __expr_eliminate_eq(e1->type, ep1, ep2);224 __expr_eliminate_eq((*ep1)->type, ep1, ep2);
228 default: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 case E_OR:229 case E_OR:
233 case E_AND:230 case E_AND:
234 __expr_eliminate_eq(e2->type, ep1, ep2);231 __expr_eliminate_eq((*ep2)->type, ep1, ep2);
235 default:232 default:
236 ;233 ;
237 }234 }
238 e1 = expr_eliminate_yn(e1);235 *ep1 = expr_eliminate_yn(*ep1);
239 e2 = expr_eliminate_yn(e2);236 *ep2 = expr_eliminate_yn(*ep2);
240}237}
241 238
242#undef e1
243#undef e2
244
245/*239/*
246 * Returns true if 'e1' and 'e2' are equal, after minor simplification. Two240 * Returns true if 'e1' and 'e2' are equal, after minor simplification. Two
247 * &&/|| expressions are considered equal if every operand in one expression241 * &&/|| 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 */
565static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct expr **ep2)559static 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 struct expr *tmp;561 struct expr *tmp;
570 562
571 /* Recurse down to leaves */563 /* Recurse down to leaves */
572 564
573 if (e1->type == type) {565 if ((*ep1)->type == type) {
574 expr_eliminate_dups1(type, &e1->left.expr, &e2);566 expr_eliminate_dups1(type, &(*ep1)->left.expr, ep2);
575 expr_eliminate_dups1(type, &e1->right.expr, &e2);567 expr_eliminate_dups1(type, &(*ep1)->right.expr, ep2);
576 return;568 return;
577 }569 }
578 if (e2->type == type) {570 if ((*ep2)->type == type) {
579 expr_eliminate_dups1(type, &e1, &e2->left.expr);571 expr_eliminate_dups1(type, ep1, &(*ep2)->left.expr);
580 expr_eliminate_dups1(type, &e1, &e2->right.expr);572 expr_eliminate_dups1(type, ep1, &(*ep2)->right.expr);
581 return;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 return;579 return;
588 580
589 switch (e1->type) {581 switch ((*ep1)->type) {
590 case E_OR: case E_AND:582 case E_OR: case E_AND:
591 expr_eliminate_dups1(e1->type, &e1, &e1);583 expr_eliminate_dups1((*ep1)->type, ep1, ep1);
592 default:584 default:
593 ;585 ;
594 }586 }
595 587
596 switch (type) {588 switch (type) {
597 case E_OR:589 case E_OR:
598 tmp = expr_join_or(e1, e2);590 tmp = expr_join_or(*ep1, *ep2);
599 if (tmp) {591 if (tmp) {
600 expr_free(e1); expr_free(e2);592 expr_free(*ep1); expr_free(*ep2);
601 e1 = expr_alloc_symbol(&symbol_no);593 *ep1 = expr_alloc_symbol(&symbol_no);
602 e2 = tmp;594 *ep2 = tmp;
603 trans_count++;595 trans_count++;
604 }596 }
605 break;597 break;
606 case E_AND:598 case E_AND:
607 tmp = expr_join_and(e1, e2);599 tmp = expr_join_and(*ep1, *ep2);
608 if (tmp) {600 if (tmp) {
609 expr_free(e1); expr_free(e2);601 expr_free(*ep1); expr_free(*ep2);
610 e1 = expr_alloc_symbol(&symbol_yes);602 *ep1 = expr_alloc_symbol(&symbol_yes);
611 e2 = tmp;603 *ep2 = tmp;
612 trans_count++;604 trans_count++;
613 }605 }
614 break;606 break;
615 default:607 default:
616 ;608 ;
617 }609 }
618#undef e1
619#undef e2
620}610}
621 611
622/*612/*