kconfig: misc cleanups
cover kconfig: misc cleanups
Masahiro Yamada (8):
kconfig: remove the rootmenu check in menu_add_prop()
kconfig: use parent->dep as the parentdep of 'menu'
kconfig: drop T_WORD from the RHS of 'prompt' symbol
kconfig: remove 'prompt' symbol
kconfig: move prompt handling to menu_add_prompt() from
menu_add_prop()
kconfig: remove 'prompt' argument from menu_add_prop()
kconfig: remove sym from struct property
kconfig: squash prop_alloc() into menu_add_prop()
scripts/kconfig/expr.h | 1 - scripts/kconfig/lkc.h | 1 - scripts/kconfig/menu.c | 103 ++++++++++++++++++++++----------------- scripts/kconfig/parser.y | 21 +++----- scripts/kconfig/symbol.c | 22 --------- 5 files changed, 66 insertions(+), 82 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/8 kconfig: remove the rootmenu check in menu_add_prop()
This reverts commit ba6ff60d5eb4 ("kconfig: don't emit warning upon rootmenu's prompt redefinition").
At that time, rootmenu.prompt was always set first, then it was set again if a "mainmenu" statement was specified in the Kconfig file.
This is no longer the case since commit 0724a7c32a54 ("kconfig: Don't leak main menus during parsing"). Remove the unneeded check.
---
scripts/kconfig/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/menu.c +1 -1
@@ -138,7 +138,7 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, structwhile (isspace (*prompt)) prompt++; } -if (current_entry->prompt && current_entry != &rootmenu) +if (current_entry->prompt)prop_warn (prop,"prompt redefined" );/* Apply all upper menus' visibilities to actual prompts. */
Signature · 1 line
2.17.1
PATCH 2/8 kconfig: use parent->dep as the parentdep of 'menu'
In reply to Masahiro YamadaIn menu_finalize(), the dependency of a menu entry is propagated downwards.
For the 'menu', ->dep and ->prompt->visible.expr are the same. Both accumulate the 'depends on' of itself and upper menu entries.
---
scripts/kconfig/menu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/kconfig/menu.c +3 -5
@@ -326,12 +326,10 @@ void menu_finalize(struct menu *parent)* choice value symbols. */ parentdep =expr_alloc_symbol (sym); - }else if (parent->prompt) -/* Menu node for 'menu' */ - parentdep = parent->prompt->visible.expr; -else -/* Menu node for 'if' */ + }else { +/* Menu node for 'menu', 'if' */ parentdep = parent->dep; + }/* For each child menu node... */ for (menu = parent->list; menu; menu = menu->next) {
Signature · 1 line
2.17.1
Re: [PATCH 2/8] kconfig: use parent->dep as the parentdep of 'menu'
Quoted 5 lines · Masahiro Yamada
In
menu_finalize(), the dependency of a menu entry is propagated downwards.For the 'menu', ->dep and ->prompt->visible.expr are the same.
Just for clarification, this meansparent->dep and parent->prompt->visible.expr
have the same expression.
expr_eq(parent->dep, parent->prompt->visible.expr) should return 1.
Quoted 31 lines
Both accumulate the 'depends on' of itself and upper menu entries.
Signed-off-by Masahiro Yamada <[email protected]>---
scripts/kconfig/menu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)scripts/kconfig/menu.c +3
-6@@ -326,12 +326,10 @@ void menu_finalize(struct menu *parent)* choice value symbols. */ parentdep =expr_alloc_symbol (sym); - }else if (parent->prompt) -/* Menu node for 'menu' */ - parentdep = parent->prompt->visible.expr; -else -/* Menu node for 'if' */ + }else { +/* Menu node for 'menu', 'if' */ parentdep = parent->dep; + }/* For each child menu node... */ for (menu = parent->list; menu; menu = menu->next) { --2.17.1
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH 3/8 kconfig: drop T_WORD from the RHS of 'prompt' symbol
In reply to Masahiro YamadaCommit 8636a1f9677d ("treewide: surround Kconfig file paths with double quotes") killed use-cases to reduce an unquoted string into the 'prompt' symbol.
Kconfig still allows to use an unquoted string in the context of menu, source, or prompt.
So, you can omit quoting if the prompt is a single word:
bool foo
..., but I do not think this is so useful.
Let's require quoting:
bool "foo"
All the Kconfig files in the kernel are written in this way.
---
scripts/kconfig/parser.y | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
scripts/kconfig/parser.y +1 -3
@@ -445,9 +445,7 @@ prompt_stmt_opt: menu_add_prompt(P_PROMPT, $1, $2); }; -prompt: T_WORD - | T_WORD_QUOTE -; +prompt: T_WORD_QUOTE end: T_ENDMENU T_EOL { $$ = "menu"; } | T_ENDCHOICE T_EOL { $$ = "choice"; current_choice_menu = NULL; }
Signature · 1 line
2.17.1
PATCH 4/8 kconfig: remove 'prompt' symbol
In reply to Masahiro YamadaNow that 'prompt' is only reduced from T_WORD_QUOTE without any action, use T_WORD_QUOTE directly.
---
scripts/kconfig/parser.y | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
scripts/kconfig/parser.y +7 -10
@@ -93,7 +93,6 @@ static struct menu *current_choice_menu; %left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL %nonassoc T_NOT -%type <string> prompt %type <symbol> nonconst_symbol %type <symbol> symbol %type <type> type logic_type default
@@ -116,7 +115,7 @@ input: mainmenu_stmt stmt_list | stmt_list; /* mainmenu entry */ -mainmenu_stmt: T_MAINMENU prompt T_EOL +mainmenu_stmt: T_MAINMENU T_WORD_QUOTE T_EOL { menu_add_prompt(P_MENU, $2, NULL); };
@@ -184,7 +183,7 @@ config_option: type prompt_stmt_opt T_EOL $1); }; -config_option: T_PROMPT prompt if_expr T_EOL +config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL { menu_add_prompt(P_PROMPT, $2, $3); printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
@@ -276,7 +275,7 @@ choice_option_list: | choice_option_list help ; -choice_option: T_PROMPT prompt if_expr T_EOL +choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL { menu_add_prompt(P_PROMPT, $2, $3); printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
@@ -345,7 +344,7 @@ if_stmt: if_entry stmt_list if_end /* menu entry */ -menu: T_MENU prompt T_EOL +menu: T_MENU T_WORD_QUOTE T_EOL { menu_add_entry(NULL); menu_add_prompt(P_MENU, $2, NULL);
@@ -374,7 +373,7 @@ menu_option_list: | menu_option_list depends ; -source_stmt: T_SOURCE prompt T_EOL +source_stmt: T_SOURCE T_WORD_QUOTE T_EOL { printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); zconf_nextfile($2);
@@ -383,7 +382,7 @@ source_stmt: T_SOURCE prompt T_EOL /* comment entry */ -comment: T_COMMENT prompt T_EOL +comment: T_COMMENT T_WORD_QUOTE T_EOL { menu_add_entry(NULL); menu_add_prompt(P_COMMENT, $2, NULL);
@@ -440,13 +439,11 @@ visible: T_VISIBLE if_expr T_EOL prompt_stmt_opt: /* empty */ - | prompt if_expr + | T_WORD_QUOTE if_expr { menu_add_prompt(P_PROMPT, $1, $2); }; -prompt: T_WORD_QUOTE - end: T_ENDMENU T_EOL { $$ = "menu"; } | T_ENDCHOICE T_EOL { $$ = "choice"; current_choice_menu = NULL; } | T_ENDIF T_EOL { $$ = "if"; }
Signature · 1 line
2.17.1
PATCH 5/8 kconfig: move prompt handling to menu_add_prompt() from menu_add_prop()
In reply to Masahiro Yamadamenu_add_prompt() is the only function that calls menu_add_prop() with non-NULL prompt.
So, the code inside the if-conditional block of menu_add_prop() can be moved to menu_add_prompt().
---
scripts/kconfig/menu.c | 70 ++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 36 deletions(-)
scripts/kconfig/menu.c +34 -36
@@ -132,53 +132,51 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, struct prop->expr = expr; prop->visible.expr = dep; -if (prompt) { -if (isspace (*prompt)) { -prop_warn (prop,"leading whitespace ignored" ); -while (isspace (*prompt)) - prompt++; - } -if (current_entry->prompt) -prop_warn (prop,"prompt redefined" ); +return prop; +} -/* Apply all upper menus' visibilities to actual prompts. */ -if (type ==P_PROMPT ) { -struct menu *menu = current_entry; +struct property *menu_add_prompt (enum prop_type type,char *prompt, +struct expr *dep) +{ +struct property *prop =menu_add_prop (type, prompt,NULL , dep); -while ((menu = menu->parent) !=NULL ) { -struct expr *dup_expr; +if (isspace (*prompt)) { +prop_warn (prop,"leading whitespace ignored" ); +while (isspace (*prompt)) + prompt++; + } +if (current_entry->prompt) +prop_warn (prop,"prompt redefined" ); -if (!menu->visibility) -continue ; -/* -* Do not add a reference to the -* menu's visibility expression but -* use a copy of it. Otherwise the -* expression reduction functions -* will modify expressions that have -* multiple references which can -* cause unwanted side effects. -*/ - dup_expr =expr_copy (menu->visibility); +/* Apply all upper menus' visibilities to actual prompts. */ +if (type ==P_PROMPT ) { +struct menu *menu = current_entry; - prop->visible.expr - =expr_alloc_and (prop->visible.expr, - dup_expr); - } - } +while ((menu = menu->parent) !=NULL ) { +struct expr *dup_expr; - current_entry->prompt = prop; +if (!menu->visibility) +continue ; +/* +* Do not add a reference to the menu's visibility +* expression but use a copy of it. Otherwise the +* expression reduction functions will modify +* expressions that have multiple references which +* can cause unwanted side effects. +*/ + dup_expr =expr_copy (menu->visibility); + + prop->visible.expr =expr_alloc_and (prop->visible.expr, + dup_expr); + } } + + current_entry->prompt = prop; prop->text = prompt;return prop; } -struct property *menu_add_prompt (enum prop_type type,char *prompt,struct expr *dep) -{ -return menu_add_prop (type, prompt,NULL , dep); -} -void menu_add_visibility (struct expr *expr) { current_entry->visibility = expr_alloc_and(current_entry->visibility,
Signature · 1 line
2.17.1
PATCH 6/8 kconfig: remove 'prompt' argument from menu_add_prop()
In reply to Masahiro YamadaThis function does not use the 'prompt' argument.
---
scripts/kconfig/menu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
scripts/kconfig/menu.c +5 -4
@@ -124,7 +124,8 @@ void menu_set_type(int type) sym_type_name(sym->type), sym_type_name(type)); } -static struct property *menu_add_prop (enum prop_type type,char *prompt,struct expr *expr,struct expr *dep) +static struct property *menu_add_prop (enum prop_type type,struct expr *expr, +struct expr *dep) {struct property *prop =prop_alloc (type, current_entry->sym);
@@ -138,7 +139,7 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, structstruct property *menu_add_prompt (enum prop_type type,char *prompt,struct expr *dep) { -struct property *prop =menu_add_prop (type, prompt,NULL , dep); +struct property *prop =menu_add_prop (type,NULL , dep);if (isspace (*prompt)) {prop_warn (prop,"leading whitespace ignored" );
@@ -185,12 +186,12 @@ void menu_add_visibility(struct expr *expr)void menu_add_expr (enum prop_type type,struct expr *expr,struct expr *dep) { -menu_add_prop (type,NULL , expr, dep); +menu_add_prop (type, expr, dep); }void menu_add_symbol (enum prop_type type,struct symbol *sym,struct expr *dep) { -menu_add_prop (type,NULL ,expr_alloc_symbol (sym), dep); +menu_add_prop (type,expr_alloc_symbol (sym), dep); }void menu_add_option_modules (void )
Signature · 1 line
2.17.1
PATCH 7/8 kconfig: remove sym from struct property
In reply to Masahiro Yamadastruct property can reference to the symbol that it is associated with by prop->menu->sym.
Fix up the one usage of prop->sym, and remove sym from struct property.
---
scripts/kconfig/expr.h | 1 - scripts/kconfig/parser.y | 2 +- scripts/kconfig/symbol.c | 1 - 3 files changed, 1 insertion(+), 3 deletions(-)
scripts/kconfig/expr.h +0 -1
@@ -191,7 +191,6 @@ enum prop_type {struct property {struct property *next;/* next property - null if last */ -struct symbol *sym;/* the symbol for which the property is associated */ enum prop_type type;/* type of property */ const char *text;/* the prompt value - P_PROMPT, P_MENU, P_COMMENT */ struct expr_value visible;
scripts/kconfig/parser.y +1 -1
@@ -671,7 +671,7 @@ static void print_symbol(FILE *out, struct menu *menu) break; case P_SYMBOL: fputs( " symbol ", out); - fprintf(out, "%s\n", prop->sym->name); + fprintf(out, "%s\n", prop->menu->sym->name); break; default: fprintf(out, " unknown prop %d!\n", prop->type);
scripts/kconfig/symbol.c +0 -1
@@ -1281,7 +1281,6 @@ struct property *prop_alloc(enum prop_type type, struct symbol *sym) prop =xmalloc (sizeof (*prop));memset (prop,0 ,sizeof (*prop)); prop->type = type; - prop->sym = sym; prop->file = current_file; prop->lineno =zconf_lineno ();
Signature · 1 line
2.17.1
PATCH 8/8 kconfig: squash prop_alloc() into menu_add_prop()
In reply to Masahiro Yamadaprop_alloc() is only called from menu_add_prop(). Squash it.
---
scripts/kconfig/lkc.h | 1 - scripts/kconfig/menu.c | 18 +++++++++++++++++- scripts/kconfig/symbol.c | 21 --------------------- 3 files changed, 17 insertions(+), 23 deletions(-)
scripts/kconfig/lkc.h +0 -1
@@ -112,7 +112,6 @@ struct symbol *sym_choice_default(struct symbol *sym);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 property *prop_alloc (enum prop_type type,struct symbol *sym);struct symbol *prop_get_symbol (struct property *prop);static inline tristate sym_get_tristate_value (struct symbol *sym)
scripts/kconfig/menu.c +17 -1
@@ -127,12 +127,28 @@ void menu_set_type(int type)static struct property *menu_add_prop (enum prop_type type,struct expr *expr,struct expr *dep) { -struct property *prop =prop_alloc (type, current_entry->sym); +struct property *prop; + prop =xmalloc (sizeof (*prop)); +memset (prop,0 ,sizeof (*prop)); + prop->type = type; + prop->file = current_file; + prop->lineno =zconf_lineno (); prop->menu = current_entry; prop->expr = expr; prop->visible.expr = dep; +/* append property to the prop list of symbol */ +if (current_entry->sym) { +struct property **propp; + +for (propp = ¤t_entry->sym->prop; + *propp; + propp = &(*propp)->next) + ; + *propp = prop; + } +return prop; }
scripts/kconfig/symbol.c +0 -21
@@ -1273,27 +1273,6 @@ struct symbol *sym_check_deps(struct symbol *sym)return sym2; } -struct property *prop_alloc (enum prop_type type,struct symbol *sym) -{ -struct property *prop; -struct property **propp; - - prop =xmalloc (sizeof (*prop)); -memset (prop,0 ,sizeof (*prop)); - prop->type = type; - prop->file = current_file; - prop->lineno =zconf_lineno (); - -/* append property to the prop list of symbol */ -if (sym) { -for (propp = &sym->prop; *propp; propp = &(*propp)->next) - ; - *propp = prop; - } - -return prop; -} -struct symbol *prop_get_symbol (struct property *prop) { if (prop->expr && (prop->expr->type == E_SYMBOL ||
Signature · 1 line
2.17.1