Skip to content

Commit

Permalink
kconfig: move prompt handling to menu_add_prompt() from menu_add_prop()
Browse files Browse the repository at this point in the history
menu_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().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
Masahiro Yamada committed Jan 6, 2020
1 parent 1be6e79 commit 024352f
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions scripts/kconfig/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 024352f

Please sign in to comment.