Skip to content

Commit 3c2f84c

Browse files
committed
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. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 94a4b0a commit 3c2f84c

File tree

1 file changed

+42
-52
lines changed

1 file changed

+42
-52
lines changed

scripts/kconfig/expr.c

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ void expr_free(struct expr *e)
135135

136136
static int trans_count;
137137

138-
#define e1 (*ep1)
139-
#define e2 (*ep2)
140-
141138
/*
142139
* expr_eliminate_eq() helper.
143140
*
@@ -150,38 +147,38 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e
150147
{
151148
/* Recurse down to leaves */
152149

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);
156153
return;
157154
}
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);
161158
return;
162159
}
163160

164-
/* e1 and e2 are leaves. Compare them. */
161+
/* *ep1 and *ep2 are leaves. Compare them. */
165162

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))
169166
return;
170-
if (!expr_eq(e1, e2))
167+
if (!expr_eq(*ep1, *ep2))
171168
return;
172169

173-
/* e1 and e2 are equal leaves. Prepare them for elimination. */
170+
/* *ep1 and *ep2 are equal leaves. Prepare them for elimination. */
174171

175172
trans_count++;
176-
expr_free(e1); expr_free(e2);
173+
expr_free(*ep1); expr_free(*ep2);
177174
switch (type) {
178175
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);
181178
break;
182179
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);
185182
break;
186183
default:
187184
;
@@ -219,29 +216,26 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e
219216
*/
220217
void expr_eliminate_eq(struct expr **ep1, struct expr **ep2)
221218
{
222-
if (!e1 || !e2)
219+
if (!*ep1 || !*ep2)
223220
return;
224-
switch (e1->type) {
221+
switch ((*ep1)->type) {
225222
case E_OR:
226223
case E_AND:
227-
__expr_eliminate_eq(e1->type, ep1, ep2);
224+
__expr_eliminate_eq((*ep1)->type, ep1, ep2);
228225
default:
229226
;
230227
}
231-
if (e1->type != e2->type) switch (e2->type) {
228+
if ((*ep1)->type != (*ep2)->type) switch ((*ep2)->type) {
232229
case E_OR:
233230
case E_AND:
234-
__expr_eliminate_eq(e2->type, ep1, ep2);
231+
__expr_eliminate_eq((*ep2)->type, ep1, ep2);
235232
default:
236233
;
237234
}
238-
e1 = expr_eliminate_yn(e1);
239-
e2 = expr_eliminate_yn(e2);
235+
*ep1 = expr_eliminate_yn(*ep1);
236+
*ep2 = expr_eliminate_yn(*ep2);
240237
}
241238

242-
#undef e1
243-
#undef e2
244-
245239
/*
246240
* Returns true if 'e1' and 'e2' are equal, after minor simplification. Two
247241
* &&/|| 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)
564558
*/
565559
static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct expr **ep2)
566560
{
567-
#define e1 (*ep1)
568-
#define e2 (*ep2)
569561
struct expr *tmp;
570562

571563
/* Recurse down to leaves */
572564

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);
576568
return;
577569
}
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);
581573
return;
582574
}
583575

584-
/* e1 and e2 are leaves. Compare and process them. */
576+
/* *ep1 and *ep2 are leaves. Compare and process them. */
585577

586-
if (e1 == e2)
578+
if (*ep1 == *ep2)
587579
return;
588580

589-
switch (e1->type) {
581+
switch ((*ep1)->type) {
590582
case E_OR: case E_AND:
591-
expr_eliminate_dups1(e1->type, &e1, &e1);
583+
expr_eliminate_dups1((*ep1)->type, ep1, ep1);
592584
default:
593585
;
594586
}
595587

596588
switch (type) {
597589
case E_OR:
598-
tmp = expr_join_or(e1, e2);
590+
tmp = expr_join_or(*ep1, *ep2);
599591
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;
603595
trans_count++;
604596
}
605597
break;
606598
case E_AND:
607-
tmp = expr_join_and(e1, e2);
599+
tmp = expr_join_and(*ep1, *ep2);
608600
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;
612604
trans_count++;
613605
}
614606
break;
615607
default:
616608
;
617609
}
618-
#undef e1
619-
#undef e2
620610
}
621611

622612
/*

0 commit comments

Comments
 (0)