Skip to content

Commit 0f57c75

Browse files
committed
kconfig: introduce menu type enum
Currently, menu->prompt->type is checked to distinguish "comment" (P_COMMENT) and "menu" (P_MENU) entries from regular "config" entries. This is odd because P_COMMENT and P_MENU are not properties. This commit introduces menu type enum to distinguish menu types more naturally. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 94145ff commit 0f57c75

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

scripts/kconfig/expr.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,26 @@ struct property {
205205
for (st = sym->prop; st; st = st->next) \
206206
if (st->text)
207207

208+
enum menu_type {
209+
M_CHOICE, // "choice"
210+
M_COMMENT, // "comment"
211+
M_IF, // "if"
212+
M_MENU, // "mainmenu", "menu", "menuconfig"
213+
M_NORMAL, // others, i.e., "config"
214+
};
215+
208216
/*
209217
* Represents a node in the menu tree, as seen in e.g. menuconfig (though used
210218
* for all front ends). Each symbol, menu, etc. defined in the Kconfig files
211219
* gets a node. A symbol defined in multiple locations gets one node at each
212220
* location.
213221
*
222+
* @type: type of the menu entry
214223
* @choice_members: list of choice members with priority.
215224
*/
216225
struct menu {
226+
enum menu_type type;
227+
217228
/* The next menu node at the same level */
218229
struct menu *next;
219230

scripts/kconfig/lkc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void _menu_init(void);
8181
void menu_warn(const struct menu *menu, const char *fmt, ...);
8282
struct menu *menu_add_menu(void);
8383
void menu_end_menu(void);
84-
void menu_add_entry(struct symbol *sym);
84+
void menu_add_entry(struct symbol *sym, enum menu_type type);
8585
void menu_add_dep(struct expr *dep);
8686
void menu_add_visibility(struct expr *dep);
8787
struct property *menu_add_prompt(enum prop_type type, const char *prompt,

scripts/kconfig/menu.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
static const char nohelp_text[] = "There is no help available for this option.";
1717

18-
struct menu rootmenu;
18+
struct menu rootmenu = { .type = M_MENU };
1919
static struct menu **last_entry_ptr;
2020

2121
/**
@@ -65,12 +65,13 @@ void _menu_init(void)
6565
last_entry_ptr = &rootmenu.list;
6666
}
6767

68-
void menu_add_entry(struct symbol *sym)
68+
void menu_add_entry(struct symbol *sym, enum menu_type type)
6969
{
7070
struct menu *menu;
7171

7272
menu = xmalloc(sizeof(*menu));
7373
memset(menu, 0, sizeof(*menu));
74+
menu->type = type;
7475
menu->sym = sym;
7576
menu->parent = current_menu;
7677
menu->filename = cur_filename;

scripts/kconfig/parser.y

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ stmt_list_in_choice:
139139

140140
config_entry_start: T_CONFIG nonconst_symbol T_EOL
141141
{
142-
menu_add_entry($2);
142+
menu_add_entry($2, M_NORMAL);
143143
printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name);
144144
};
145145

@@ -173,7 +173,7 @@ config_stmt: config_entry_start config_option_list
173173

174174
menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
175175
{
176-
menu_add_entry($2);
176+
menu_add_entry($2, M_MENU);
177177
printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name);
178178
};
179179

@@ -246,7 +246,7 @@ choice: T_CHOICE T_EOL
246246
{
247247
struct symbol *sym = sym_lookup(NULL, 0);
248248

249-
menu_add_entry(sym);
249+
menu_add_entry(sym, M_CHOICE);
250250
menu_set_type(S_BOOLEAN);
251251
INIT_LIST_HEAD(&current_entry->choice_members);
252252

@@ -315,7 +315,7 @@ default:
315315
if_entry: T_IF expr T_EOL
316316
{
317317
printd(DEBUG_PARSE, "%s:%d:if\n", cur_filename, cur_lineno);
318-
menu_add_entry(NULL);
318+
menu_add_entry(NULL, M_IF);
319319
menu_add_dep($2);
320320
$$ = menu_add_menu();
321321
};
@@ -338,7 +338,7 @@ if_stmt_in_choice: if_entry stmt_list_in_choice if_end
338338

339339
menu: T_MENU T_WORD_QUOTE T_EOL
340340
{
341-
menu_add_entry(NULL);
341+
menu_add_entry(NULL, M_MENU);
342342
menu_add_prompt(P_MENU, $2, NULL);
343343
printd(DEBUG_PARSE, "%s:%d:menu\n", cur_filename, cur_lineno);
344344
};
@@ -376,7 +376,7 @@ source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
376376

377377
comment: T_COMMENT T_WORD_QUOTE T_EOL
378378
{
379-
menu_add_entry(NULL);
379+
menu_add_entry(NULL, M_COMMENT);
380380
menu_add_prompt(P_COMMENT, $2, NULL);
381381
printd(DEBUG_PARSE, "%s:%d:comment\n", cur_filename, cur_lineno);
382382
};

0 commit comments

Comments
 (0)