* [PATCH 1/4] kconfig: call expr_eliminate_yn() at least once in expr_eliminate_dups()
@ 2024-07-07 15:38 Masahiro Yamada
2024-07-07 15:38 ` [PATCH 2/4] kconfig: add const qualifiers to several function arguments Masahiro Yamada
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Masahiro Yamada @ 2024-07-07 15:38 UTC (permalink / raw)
To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada
Kconfig simplifies expressions, but redundant '&&' and '||' operators
involving constant symbols 'y' and 'n' are sometimes trimmed and
sometimes not.
[Test Code]
config DEP
def_bool y
config A
bool "A"
depends on DEP && y
config B
bool "B"
depends on DEP && y && y
[Result]
$ make helpnewconfig
[ snip ]
-----
There is no help available for this option.
Symbol: A [=n]
Type : bool
Defined at Kconfig:4
Prompt: A
Depends on: DEP [=y] && y [=y]
Location:
-> A (A [=n])
-----
-----
There is no help available for this option.
Symbol: B [=n]
Type : bool
Defined at Kconfig:8
Prompt: B
Depends on: DEP [=y]
Location:
-> B (B [=n])
-----
The dependency for A, 'DEP && y', remains as-is, while that for B,
'DEP && y && y', has been reduced to 'DEP'.
Currently, expr_eliminate_dups() calls expr_eliminate_yn() only when
trans_count != 0, in other words, only when expr_eliminate_dups1() has
trimmed at least one leaf. It fails to trim a single '&& y', etc.
To fix this inconsistent behavior, expr_eliminate_yn() should be called
at least once even if no leaf has been trimmed.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/expr.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 6d4b5a5a1e62..b2dfd3123a5d 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -637,7 +637,7 @@ struct expr *expr_eliminate_dups(struct expr *e)
return e;
oldcount = trans_count;
- while (1) {
+ do {
trans_count = 0;
switch (e->type) {
case E_OR: case E_AND:
@@ -645,11 +645,8 @@ struct expr *expr_eliminate_dups(struct expr *e)
default:
;
}
- if (!trans_count)
- /* No simplifications done in this pass. We're done */
- break;
e = expr_eliminate_yn(e);
- }
+ } while (trans_count); /* repeat until we get no more simplifications */
trans_count = oldcount;
return e;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] kconfig: add const qualifiers to several function arguments
2024-07-07 15:38 [PATCH 1/4] kconfig: call expr_eliminate_yn() at least once in expr_eliminate_dups() Masahiro Yamada
@ 2024-07-07 15:38 ` Masahiro Yamada
2024-07-07 15:38 ` [PATCH 3/4] kconfig: remove P_CHOICEVAL property Masahiro Yamada
2024-07-07 15:38 ` [PATCH 4/4] kconfig: remove 'e1' and 'e2' macros from expressoin deduplication Masahiro Yamada
2 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2024-07-07 15:38 UTC (permalink / raw)
To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada
Clarify that the given structures are not modified.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/expr.c | 4 ++--
scripts/kconfig/expr.h | 4 ++--
scripts/kconfig/lkc.h | 21 +++++++++++----------
scripts/kconfig/lkc_proto.h | 12 +++++++-----
| 15 ++++++++-------
scripts/kconfig/parser.y | 4 ++--
scripts/kconfig/symbol.c | 14 +++++++-------
scripts/kconfig/util.c | 2 +-
8 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index b2dfd3123a5d..a85e0d603322 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1096,7 +1096,7 @@ static int expr_compare_type(enum expr_type t1, enum expr_type t2)
return 0;
}
-void expr_print(struct expr *e,
+void expr_print(const struct expr *e,
void (*fn)(void *, struct symbol *, const char *),
void *data, int prevtoken)
{
@@ -1221,7 +1221,7 @@ static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *s
str_printf(gs, " [=%s]", sym_str);
}
-void expr_gstr_print(struct expr *e, struct gstr *gs)
+void expr_gstr_print(const struct expr *e, struct gstr *gs)
{
expr_print(e, expr_print_gstr_helper, gs, E_NONE);
}
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 8849a243b5e7..54b008c0161d 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -291,11 +291,11 @@ struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symb
void expr_fprint(struct expr *e, FILE *out);
struct gstr; /* forward */
-void expr_gstr_print(struct expr *e, struct gstr *gs);
+void expr_gstr_print(const struct expr *e, struct gstr *gs);
void expr_gstr_print_revdep(struct expr *e, struct gstr *gs,
tristate pr_type, const char *title);
-static inline int expr_is_yes(struct expr *e)
+static inline int expr_is_yes(const struct expr *e)
{
return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes);
}
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 586a5e11f51e..3fa46610f25f 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -75,7 +75,7 @@ struct gstr str_new(void);
void str_free(struct gstr *gs);
void str_append(struct gstr *gs, const char *s);
void str_printf(struct gstr *gs, const char *fmt, ...);
-char *str_get(struct gstr *gs);
+char *str_get(const struct gstr *gs);
/* menu.c */
struct menu *menu_next(struct menu *menu, struct menu *root);
@@ -84,13 +84,14 @@ struct menu *menu_next(struct menu *menu, struct menu *root);
#define menu_for_each_entry(menu) \
menu_for_each_sub_entry(menu, &rootmenu)
void _menu_init(void);
-void menu_warn(struct menu *menu, const char *fmt, ...);
+void menu_warn(const struct menu *menu, const char *fmt, ...);
struct menu *menu_add_menu(void);
void menu_end_menu(void);
void menu_add_entry(struct symbol *sym);
void menu_add_dep(struct expr *dep);
void menu_add_visibility(struct expr *dep);
-struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
+struct property *menu_add_prompt(enum prop_type type, const char *prompt,
+ struct expr *dep);
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
void menu_finalize(void);
@@ -100,8 +101,8 @@ extern struct menu rootmenu;
bool menu_is_empty(struct menu *menu);
bool menu_is_visible(struct menu *menu);
-bool menu_has_prompt(struct menu *menu);
-const char *menu_get_prompt(struct menu *menu);
+bool menu_has_prompt(const struct menu *menu);
+const char *menu_get_prompt(const struct menu *menu);
struct menu *menu_get_parent_menu(struct menu *menu);
int get_jump_key_char(void);
struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
@@ -114,25 +115,25 @@ struct symbol *sym_calc_choice(struct menu *choice);
struct property *sym_get_range_prop(struct symbol *sym);
const char *sym_get_string_default(struct symbol *sym);
struct symbol *sym_check_deps(struct symbol *sym);
-struct symbol *prop_get_symbol(struct property *prop);
+struct symbol *prop_get_symbol(const struct property *prop);
-static inline tristate sym_get_tristate_value(struct symbol *sym)
+static inline tristate sym_get_tristate_value(const struct symbol *sym)
{
return sym->curr.tri;
}
-static inline bool sym_is_choice(struct symbol *sym)
+static inline bool sym_is_choice(const struct symbol *sym)
{
/* A choice is a symbol with no name */
return sym->name == NULL;
}
-static inline bool sym_is_choice_value(struct symbol *sym)
+static inline bool sym_is_choice_value(const struct symbol *sym)
{
return sym->flags & SYMBOL_CHOICEVAL ? true : false;
}
-static inline bool sym_has_value(struct symbol *sym)
+static inline bool sym_has_value(const struct symbol *sym)
{
return sym->flags & SYMBOL_DEF_USER ? true : false;
}
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 49cc649d2810..63519cd24bc7 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -25,21 +25,23 @@ struct symbol ** sym_re_search(const char *pattern);
const char * sym_type_name(enum symbol_type type);
void sym_calc_value(struct symbol *sym);
bool sym_dep_errors(void);
-enum symbol_type sym_get_type(struct symbol *sym);
-bool sym_tristate_within_range(struct symbol *sym,tristate tri);
+enum symbol_type sym_get_type(const struct symbol *sym);
+bool sym_tristate_within_range(const struct symbol *sym, tristate tri);
bool sym_set_tristate_value(struct symbol *sym,tristate tri);
void choice_set_value(struct menu *choice, struct symbol *sym);
tristate sym_toggle_tristate_value(struct symbol *sym);
bool sym_string_valid(struct symbol *sym, const char *newval);
bool sym_string_within_range(struct symbol *sym, const char *str);
bool sym_set_string_value(struct symbol *sym, const char *newval);
-bool sym_is_changeable(struct symbol *sym);
-struct menu *sym_get_choice_menu(struct symbol *sym);
+bool sym_is_changeable(const struct symbol *sym);
+struct menu *sym_get_choice_menu(const struct symbol *sym);
const char * sym_get_string_value(struct symbol *sym);
const char * prop_get_type_name(enum prop_type type);
/* expr.c */
-void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken);
+void expr_print(const struct expr *e,
+ void (*fn)(void *, struct symbol *, const char *),
+ void *data, int prevtoken);
#endif /* LKC_PROTO_H */
--git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index b1fbaf2ff792..2a9b4c4f4428 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -38,7 +38,7 @@ struct menu *menu_next(struct menu *menu, struct menu *root)
return menu->next;
}
-void menu_warn(struct menu *menu, const char *fmt, ...)
+void menu_warn(const struct menu *menu, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
@@ -48,7 +48,7 @@ void menu_warn(struct menu *menu, const char *fmt, ...)
va_end(ap);
}
-static void prop_warn(struct property *prop, const char *fmt, ...)
+static void prop_warn(const struct property *prop, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
@@ -175,7 +175,7 @@ static struct property *menu_add_prop(enum prop_type type, struct expr *expr,
return prop;
}
-struct property *menu_add_prompt(enum prop_type type, char *prompt,
+struct property *menu_add_prompt(enum prop_type type, const char *prompt,
struct expr *dep)
{
struct property *prop = menu_add_prop(type, NULL, dep);
@@ -527,7 +527,7 @@ void menu_finalize(void)
_menu_finalize(&rootmenu, false);
}
-bool menu_has_prompt(struct menu *menu)
+bool menu_has_prompt(const struct menu *menu)
{
if (!menu->prompt)
return false;
@@ -573,7 +573,7 @@ bool menu_is_visible(struct menu *menu)
return visible != no;
}
-const char *menu_get_prompt(struct menu *menu)
+const char *menu_get_prompt(const struct menu *menu)
{
if (menu->prompt)
return menu->prompt->text;
@@ -594,13 +594,14 @@ struct menu *menu_get_parent_menu(struct menu *menu)
return menu;
}
-static void get_def_str(struct gstr *r, struct menu *menu)
+static void get_def_str(struct gstr *r, const struct menu *menu)
{
str_printf(r, "Defined at %s:%d\n",
menu->filename, menu->lineno);
}
-static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix)
+static void get_dep_str(struct gstr *r, const struct expr *expr,
+ const char *prefix)
{
if (!expr_is_yes(expr)) {
str_append(r, prefix);
diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y
index 745c82ee15d0..61900feb4254 100644
--- a/scripts/kconfig/parser.y
+++ b/scripts/kconfig/parser.y
@@ -489,7 +489,7 @@ assign_val:
*
* Return: -1 if an error is found, 0 otherwise.
*/
-static int choice_check_sanity(struct menu *menu)
+static int choice_check_sanity(const struct menu *menu)
{
struct property *prop;
int ret = 0;
@@ -644,7 +644,7 @@ static void print_quoted_string(FILE *out, const char *str)
putc('"', out);
}
-static void print_symbol(FILE *out, struct menu *menu)
+static void print_symbol(FILE *out, const struct menu *menu)
{
struct symbol *sym = menu->sym;
struct property *prop;
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index c05d188a1857..3255bf310cb2 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -40,7 +40,7 @@ struct symbol *modules_sym;
static tristate modules_val;
static int sym_warnings;
-enum symbol_type sym_get_type(struct symbol *sym)
+enum symbol_type sym_get_type(const struct symbol *sym)
{
enum symbol_type type = sym->type;
@@ -75,7 +75,7 @@ const char *sym_type_name(enum symbol_type type)
*
* Return: a choice menu if this function is called against a choice member.
*/
-struct menu *sym_get_choice_menu(struct symbol *sym)
+struct menu *sym_get_choice_menu(const struct symbol *sym)
{
struct menu *menu = NULL;
struct menu *m;
@@ -355,7 +355,7 @@ struct symbol *sym_calc_choice(struct menu *choice)
return res;
}
-static void sym_warn_unmet_dep(struct symbol *sym)
+static void sym_warn_unmet_dep(const struct symbol *sym)
{
struct gstr gs = str_new();
@@ -521,7 +521,7 @@ void sym_clear_all_valid(void)
sym_calc_value(modules_sym);
}
-bool sym_tristate_within_range(struct symbol *sym, tristate val)
+bool sym_tristate_within_range(const struct symbol *sym, tristate val)
{
int type = sym_get_type(sym);
@@ -866,7 +866,7 @@ const char *sym_get_string_value(struct symbol *sym)
return (const char *)sym->curr.val;
}
-bool sym_is_changeable(struct symbol *sym)
+bool sym_is_changeable(const struct symbol *sym)
{
return !sym_is_choice(sym) && sym->visible > sym->rev_dep.tri;
}
@@ -1150,7 +1150,7 @@ static void sym_check_print_recursive(struct symbol *last_sym)
dep_stack_remove();
}
-static struct symbol *sym_check_expr_deps(struct expr *e)
+static struct symbol *sym_check_expr_deps(const struct expr *e)
{
struct symbol *sym;
@@ -1309,7 +1309,7 @@ struct symbol *sym_check_deps(struct symbol *sym)
return sym2;
}
-struct symbol *prop_get_symbol(struct property *prop)
+struct symbol *prop_get_symbol(const struct property *prop)
{
if (prop->expr && prop->expr->type == E_SYMBOL)
return prop->expr->left.sym;
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index 439c131b424e..1ea78927121d 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -98,7 +98,7 @@ void str_printf(struct gstr *gs, const char *fmt, ...)
}
/* Retrieve value of growable string */
-char *str_get(struct gstr *gs)
+char *str_get(const struct gstr *gs)
{
return gs->s;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] kconfig: remove P_CHOICEVAL property
2024-07-07 15:38 [PATCH 1/4] kconfig: call expr_eliminate_yn() at least once in expr_eliminate_dups() Masahiro Yamada
2024-07-07 15:38 ` [PATCH 2/4] kconfig: add const qualifiers to several function arguments Masahiro Yamada
@ 2024-07-07 15:38 ` Masahiro Yamada
2024-07-07 15:40 ` Masahiro Yamada
2024-07-07 15:38 ` [PATCH 4/4] kconfig: remove 'e1' and 'e2' macros from expressoin deduplication Masahiro Yamada
2 siblings, 1 reply; 5+ messages in thread
From: Masahiro Yamada @ 2024-07-07 15:38 UTC (permalink / raw)
To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada
This flag is unneeded because a choice member can be detected by
other means.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/expr.h | 1 -
scripts/kconfig/gconf.c | 2 +-
scripts/kconfig/lkc.h | 5 +----
| 5 -----
scripts/kconfig/symbol.c | 6 ++++++
5 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 54b008c0161d..6e47e0ad6e6e 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -131,7 +131,6 @@ struct symbol {
#define SYMBOL_CONST 0x0001 /* symbol is const */
#define SYMBOL_CHECK 0x0008 /* used during dependency checking */
-#define SYMBOL_CHOICEVAL 0x0020 /* used as a value in a choice block */
#define SYMBOL_VALID 0x0080 /* set when symbol.curr is calculated */
#define SYMBOL_WRITE 0x0200 /* write symbol to file (KCONFIG_CONFIG) */
#define SYMBOL_WRITTEN 0x0800 /* track info to avoid double-write to .config */
diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
index 6b50e25133e3..c0f46f189060 100644
--- a/scripts/kconfig/gconf.c
+++ b/scripts/kconfig/gconf.c
@@ -1070,7 +1070,7 @@ static gchar **fill_row(struct menu *menu)
row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
return row;
}
- if (sym->flags & SYMBOL_CHOICEVAL)
+ if (sym_is_choice_value(sym))
row[COL_BTNRAD] = GINT_TO_POINTER(TRUE);
stype = sym_get_type(sym);
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 3fa46610f25f..401bdf36323a 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -128,10 +128,7 @@ static inline bool sym_is_choice(const struct symbol *sym)
return sym->name == NULL;
}
-static inline bool sym_is_choice_value(const struct symbol *sym)
-{
- return sym->flags & SYMBOL_CHOICEVAL ? true : false;
-}
+bool sym_is_choice_value(const struct symbol *sym);
static inline bool sym_has_value(const struct symbol *sym)
{
--git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 2a9b4c4f4428..cd34cc5aefcf 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -467,11 +467,6 @@ static void _menu_finalize(struct menu *parent, bool inside_choice)
sym->dir_dep.expr = expr_alloc_or(sym->dir_dep.expr, parent->dep);
}
for (menu = parent->list; menu; menu = menu->next) {
- if (sym && sym_is_choice(sym) &&
- menu->sym && !sym_is_choice_value(menu->sym)) {
- menu->sym->flags |= SYMBOL_CHOICEVAL;
- }
-
/*
* This code serves two purposes:
*
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 3255bf310cb2..6c6f238c4f7b 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -871,6 +871,11 @@ bool sym_is_changeable(const struct symbol *sym)
return !sym_is_choice(sym) && sym->visible > sym->rev_dep.tri;
}
+bool sym_is_choice_value(const struct symbol *sym)
+{
+ return !list_empty(&sym->choice_link);
+}
+
HASHTABLE_DEFINE(sym_hashtable, SYMBOL_HASHSIZE);
struct symbol *sym_lookup(const char *name, int flags)
@@ -908,6 +913,7 @@ struct symbol *sym_lookup(const char *name, int flags)
symbol->type = S_UNKNOWN;
symbol->flags = flags;
INIT_LIST_HEAD(&symbol->menus);
+ INIT_LIST_HEAD(&symbol->choice_link);
hash_add(sym_hashtable, &symbol->node, hash);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] kconfig: remove 'e1' and 'e2' macros from expressoin deduplication
2024-07-07 15:38 [PATCH 1/4] kconfig: call expr_eliminate_yn() at least once in expr_eliminate_dups() Masahiro Yamada
2024-07-07 15:38 ` [PATCH 2/4] kconfig: add const qualifiers to several function arguments Masahiro Yamada
2024-07-07 15:38 ` [PATCH 3/4] kconfig: remove P_CHOICEVAL property Masahiro Yamada
@ 2024-07-07 15:38 ` Masahiro Yamada
2 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2024-07-07 15:38 UTC (permalink / raw)
To: linux-kbuild; +Cc: linux-kernel, Masahiro Yamada
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 <masahiroy@kernel.org>
---
scripts/kconfig/expr.c | 94 +++++++++++++++++++-----------------------
1 file changed, 42 insertions(+), 52 deletions(-)
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index a85e0d603322..c349da7fe3f8 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -135,9 +135,6 @@ void expr_free(struct expr *e)
static int trans_count;
-#define e1 (*ep1)
-#define e2 (*ep2)
-
/*
* expr_eliminate_eq() helper.
*
@@ -150,38 +147,38 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e
{
/* Recurse down to leaves */
- if (e1->type == type) {
- __expr_eliminate_eq(type, &e1->left.expr, &e2);
- __expr_eliminate_eq(type, &e1->right.expr, &e2);
+ if ((*ep1)->type == type) {
+ __expr_eliminate_eq(type, &(*ep1)->left.expr, ep2);
+ __expr_eliminate_eq(type, &(*ep1)->right.expr, ep2);
return;
}
- if (e2->type == type) {
- __expr_eliminate_eq(type, &e1, &e2->left.expr);
- __expr_eliminate_eq(type, &e1, &e2->right.expr);
+ if ((*ep2)->type == type) {
+ __expr_eliminate_eq(type, ep1, &(*ep2)->left.expr);
+ __expr_eliminate_eq(type, ep1, &(*ep2)->right.expr);
return;
}
- /* e1 and e2 are leaves. Compare them. */
+ /* *ep1 and *ep2 are leaves. Compare them. */
- if (e1->type == E_SYMBOL && e2->type == E_SYMBOL &&
- e1->left.sym == e2->left.sym &&
- (e1->left.sym == &symbol_yes || e1->left.sym == &symbol_no))
+ if ((*ep1)->type == E_SYMBOL && (*ep2)->type == E_SYMBOL &&
+ (*ep1)->left.sym == (*ep2)->left.sym &&
+ ((*ep1)->left.sym == &symbol_yes || (*ep1)->left.sym == &symbol_no))
return;
- if (!expr_eq(e1, e2))
+ if (!expr_eq(*ep1, *ep2))
return;
- /* e1 and e2 are equal leaves. Prepare them for elimination. */
+ /* *ep1 and *ep2 are equal leaves. Prepare them for elimination. */
trans_count++;
- expr_free(e1); expr_free(e2);
+ expr_free(*ep1); expr_free(*ep2);
switch (type) {
case E_OR:
- e1 = expr_alloc_symbol(&symbol_no);
- e2 = expr_alloc_symbol(&symbol_no);
+ *ep1 = expr_alloc_symbol(&symbol_no);
+ *ep2 = expr_alloc_symbol(&symbol_no);
break;
case E_AND:
- e1 = expr_alloc_symbol(&symbol_yes);
- e2 = expr_alloc_symbol(&symbol_yes);
+ *ep1 = expr_alloc_symbol(&symbol_yes);
+ *ep2 = expr_alloc_symbol(&symbol_yes);
break;
default:
;
@@ -219,29 +216,26 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e
*/
void expr_eliminate_eq(struct expr **ep1, struct expr **ep2)
{
- if (!e1 || !e2)
+ if (!*ep1 || !*ep2)
return;
- switch (e1->type) {
+ switch ((*ep1)->type) {
case E_OR:
case E_AND:
- __expr_eliminate_eq(e1->type, ep1, ep2);
+ __expr_eliminate_eq((*ep1)->type, ep1, ep2);
default:
;
}
- if (e1->type != e2->type) switch (e2->type) {
+ if ((*ep1)->type != (*ep2)->type) switch ((*ep2)->type) {
case E_OR:
case E_AND:
- __expr_eliminate_eq(e2->type, ep1, ep2);
+ __expr_eliminate_eq((*ep2)->type, ep1, ep2);
default:
;
}
- e1 = expr_eliminate_yn(e1);
- e2 = expr_eliminate_yn(e2);
+ *ep1 = expr_eliminate_yn(*ep1);
+ *ep2 = expr_eliminate_yn(*ep2);
}
-#undef e1
-#undef e2
-
/*
* Returns true if 'e1' and 'e2' are equal, after minor simplification. Two
* &&/|| 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)
*/
static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct expr **ep2)
{
-#define e1 (*ep1)
-#define e2 (*ep2)
struct expr *tmp;
/* Recurse down to leaves */
- if (e1->type == type) {
- expr_eliminate_dups1(type, &e1->left.expr, &e2);
- expr_eliminate_dups1(type, &e1->right.expr, &e2);
+ if ((*ep1)->type == type) {
+ expr_eliminate_dups1(type, &(*ep1)->left.expr, ep2);
+ expr_eliminate_dups1(type, &(*ep1)->right.expr, ep2);
return;
}
- if (e2->type == type) {
- expr_eliminate_dups1(type, &e1, &e2->left.expr);
- expr_eliminate_dups1(type, &e1, &e2->right.expr);
+ if ((*ep2)->type == type) {
+ expr_eliminate_dups1(type, ep1, &(*ep2)->left.expr);
+ expr_eliminate_dups1(type, ep1, &(*ep2)->right.expr);
return;
}
- /* e1 and e2 are leaves. Compare and process them. */
+ /* *ep1 and *ep2 are leaves. Compare and process them. */
- if (e1 == e2)
+ if (*ep1 == *ep2)
return;
- switch (e1->type) {
+ switch ((*ep1)->type) {
case E_OR: case E_AND:
- expr_eliminate_dups1(e1->type, &e1, &e1);
+ expr_eliminate_dups1((*ep1)->type, ep1, ep1);
default:
;
}
switch (type) {
case E_OR:
- tmp = expr_join_or(e1, e2);
+ tmp = expr_join_or(*ep1, *ep2);
if (tmp) {
- expr_free(e1); expr_free(e2);
- e1 = expr_alloc_symbol(&symbol_no);
- e2 = tmp;
+ expr_free(*ep1); expr_free(*ep2);
+ *ep1 = expr_alloc_symbol(&symbol_no);
+ *ep2 = tmp;
trans_count++;
}
break;
case E_AND:
- tmp = expr_join_and(e1, e2);
+ tmp = expr_join_and(*ep1, *ep2);
if (tmp) {
- expr_free(e1); expr_free(e2);
- e1 = expr_alloc_symbol(&symbol_yes);
- e2 = tmp;
+ expr_free(*ep1); expr_free(*ep2);
+ *ep1 = expr_alloc_symbol(&symbol_yes);
+ *ep2 = tmp;
trans_count++;
}
break;
default:
;
}
-#undef e1
-#undef e2
}
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 3/4] kconfig: remove P_CHOICEVAL property
2024-07-07 15:38 ` [PATCH 3/4] kconfig: remove P_CHOICEVAL property Masahiro Yamada
@ 2024-07-07 15:40 ` Masahiro Yamada
0 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2024-07-07 15:40 UTC (permalink / raw)
To: linux-kbuild; +Cc: linux-kernel
P_CHOICEVAL -> SYMBOL_CHOICEVAL
On Mon, Jul 8, 2024 at 12:39 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> This flag is unneeded because a choice member can be detected by
> other means.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
> scripts/kconfig/expr.h | 1 -
> scripts/kconfig/gconf.c | 2 +-
> scripts/kconfig/lkc.h | 5 +----
> scripts/kconfig/menu.c | 5 -----
> scripts/kconfig/symbol.c | 6 ++++++
> 5 files changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
> index 54b008c0161d..6e47e0ad6e6e 100644
> --- a/scripts/kconfig/expr.h
> +++ b/scripts/kconfig/expr.h
> @@ -131,7 +131,6 @@ struct symbol {
>
> #define SYMBOL_CONST 0x0001 /* symbol is const */
> #define SYMBOL_CHECK 0x0008 /* used during dependency checking */
> -#define SYMBOL_CHOICEVAL 0x0020 /* used as a value in a choice block */
> #define SYMBOL_VALID 0x0080 /* set when symbol.curr is calculated */
> #define SYMBOL_WRITE 0x0200 /* write symbol to file (KCONFIG_CONFIG) */
> #define SYMBOL_WRITTEN 0x0800 /* track info to avoid double-write to .config */
> diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
> index 6b50e25133e3..c0f46f189060 100644
> --- a/scripts/kconfig/gconf.c
> +++ b/scripts/kconfig/gconf.c
> @@ -1070,7 +1070,7 @@ static gchar **fill_row(struct menu *menu)
> row[COL_BTNVIS] = GINT_TO_POINTER(FALSE);
> return row;
> }
> - if (sym->flags & SYMBOL_CHOICEVAL)
> + if (sym_is_choice_value(sym))
> row[COL_BTNRAD] = GINT_TO_POINTER(TRUE);
>
> stype = sym_get_type(sym);
> diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
> index 3fa46610f25f..401bdf36323a 100644
> --- a/scripts/kconfig/lkc.h
> +++ b/scripts/kconfig/lkc.h
> @@ -128,10 +128,7 @@ static inline bool sym_is_choice(const struct symbol *sym)
> return sym->name == NULL;
> }
>
> -static inline bool sym_is_choice_value(const struct symbol *sym)
> -{
> - return sym->flags & SYMBOL_CHOICEVAL ? true : false;
> -}
> +bool sym_is_choice_value(const struct symbol *sym);
>
> static inline bool sym_has_value(const struct symbol *sym)
> {
> diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
> index 2a9b4c4f4428..cd34cc5aefcf 100644
> --- a/scripts/kconfig/menu.c
> +++ b/scripts/kconfig/menu.c
> @@ -467,11 +467,6 @@ static void _menu_finalize(struct menu *parent, bool inside_choice)
> sym->dir_dep.expr = expr_alloc_or(sym->dir_dep.expr, parent->dep);
> }
> for (menu = parent->list; menu; menu = menu->next) {
> - if (sym && sym_is_choice(sym) &&
> - menu->sym && !sym_is_choice_value(menu->sym)) {
> - menu->sym->flags |= SYMBOL_CHOICEVAL;
> - }
> -
> /*
> * This code serves two purposes:
> *
> diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
> index 3255bf310cb2..6c6f238c4f7b 100644
> --- a/scripts/kconfig/symbol.c
> +++ b/scripts/kconfig/symbol.c
> @@ -871,6 +871,11 @@ bool sym_is_changeable(const struct symbol *sym)
> return !sym_is_choice(sym) && sym->visible > sym->rev_dep.tri;
> }
>
> +bool sym_is_choice_value(const struct symbol *sym)
> +{
> + return !list_empty(&sym->choice_link);
> +}
> +
> HASHTABLE_DEFINE(sym_hashtable, SYMBOL_HASHSIZE);
>
> struct symbol *sym_lookup(const char *name, int flags)
> @@ -908,6 +913,7 @@ struct symbol *sym_lookup(const char *name, int flags)
> symbol->type = S_UNKNOWN;
> symbol->flags = flags;
> INIT_LIST_HEAD(&symbol->menus);
> + INIT_LIST_HEAD(&symbol->choice_link);
>
> hash_add(sym_hashtable, &symbol->node, hash);
>
> --
> 2.43.0
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-07-07 15:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-07 15:38 [PATCH 1/4] kconfig: call expr_eliminate_yn() at least once in expr_eliminate_dups() Masahiro Yamada
2024-07-07 15:38 ` [PATCH 2/4] kconfig: add const qualifiers to several function arguments Masahiro Yamada
2024-07-07 15:38 ` [PATCH 3/4] kconfig: remove P_CHOICEVAL property Masahiro Yamada
2024-07-07 15:40 ` Masahiro Yamada
2024-07-07 15:38 ` [PATCH 4/4] kconfig: remove 'e1' and 'e2' macros from expressoin deduplication Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox