Skip to content

Commit

Permalink
kconfig: add an option to determine a menu's visibility
Browse files Browse the repository at this point in the history
This option is aimed to add the possibility to control a menu's visibility
without adding dependency to the expression to all the submenu.

Signed-off-by: Arnaud Lacombe <[email protected]>
Acked-by: Mauro Carvalho Chehab <[email protected]>
Tested-by: Mauro Carvalho Chehab <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
lacombar authored and Mauro Carvalho Chehab committed Nov 22, 2010
1 parent e53beac commit 86e187f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions scripts/kconfig/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct menu {
struct menu *list;
struct symbol *sym;
struct property *prompt;
struct expr *visibility;
struct expr *dep;
unsigned int flags;
char *help;
Expand Down
1 change: 1 addition & 0 deletions scripts/kconfig/lkc.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void menu_end_menu(void);
void menu_add_entry(struct symbol *sym);
void menu_end_entry(void);
void menu_add_dep(struct expr *dep);
void menu_add_visibility(struct expr *dep);
struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep);
struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
Expand Down
11 changes: 11 additions & 0 deletions scripts/kconfig/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr
return menu_add_prop(type, prompt, NULL, dep);
}

void menu_add_visibility(struct expr *expr)
{
current_entry->visibility = expr_alloc_and(current_entry->visibility,
expr);
}

void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
{
menu_add_prop(type, NULL, expr, dep);
Expand Down Expand Up @@ -410,6 +416,11 @@ bool menu_is_visible(struct menu *menu)
if (!menu->prompt)
return false;

if (menu->visibility) {
if (expr_calc_value(menu->visibility) == no)
return no;
}

sym = menu->sym;
if (sym) {
sym_calc_value(sym);
Expand Down
1 change: 1 addition & 0 deletions scripts/kconfig/zconf.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ hex, T_TYPE, TF_COMMAND, S_HEX
string, T_TYPE, TF_COMMAND, S_STRING
select, T_SELECT, TF_COMMAND
range, T_RANGE, TF_COMMAND
visible, T_VISIBLE, TF_COMMAND
option, T_OPTION, TF_COMMAND
on, T_ON, TF_PARAM
modules, T_OPT_MODULES, TF_OPTION
Expand Down
21 changes: 18 additions & 3 deletions scripts/kconfig/zconf.y
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static struct menu *current_menu, *current_entry;
#define YYERROR_VERBOSE
#endif
%}
%expect 28
%expect 30

%union
{
Expand Down Expand Up @@ -68,6 +68,7 @@ static struct menu *current_menu, *current_entry;
%token <id>T_DEFAULT
%token <id>T_SELECT
%token <id>T_RANGE
%token <id>T_VISIBLE
%token <id>T_OPTION
%token <id>T_ON
%token <string> T_WORD
Expand Down Expand Up @@ -123,7 +124,7 @@ stmt_list:
;

option_name:
T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT
T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
;

common_stmt:
Expand Down Expand Up @@ -359,7 +360,7 @@ menu: T_MENU prompt T_EOL
printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
};

menu_entry: menu depends_list
menu_entry: menu visibility_list depends_list
{
$$ = menu_add_menu();
};
Expand Down Expand Up @@ -430,6 +431,19 @@ depends: T_DEPENDS T_ON expr T_EOL
printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
};

/* visibility option */

visibility_list:
/* empty */
| visibility_list visible
| visibility_list T_EOL
;

visible: T_VISIBLE if_expr
{
menu_add_visibility($2);
};

/* prompt statement */

prompt_stmt_opt:
Expand Down Expand Up @@ -526,6 +540,7 @@ static const char *zconf_tokenname(int token)
case T_IF: return "if";
case T_ENDIF: return "endif";
case T_DEPENDS: return "depends";
case T_VISIBLE: return "visible";
}
return "<token>";
}
Expand Down

0 comments on commit 86e187f

Please sign in to comment.