kconfig: introduce menu type enum
authorMasahiro Yamada <masahiroy@kernel.org>
Tue, 27 May 2025 17:56:15 +0000 (02:56 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Thu, 5 Jun 2025 20:40:25 +0000 (05:40 +0900)
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 <masahiroy@kernel.org>
scripts/kconfig/expr.h
scripts/kconfig/lkc.h
scripts/kconfig/menu.c
scripts/kconfig/parser.y

index 21578dcd4292407ea7280766151db6297c9f8658..fe2231e0e6a4cdd149582b16a8dc74ee1b8d7deb 100644 (file)
@@ -205,15 +205,26 @@ struct property {
        for (st = sym->prop; st; st = st->next) \
                if (st->text)
 
+enum menu_type {
+       M_CHOICE,  // "choice"
+       M_COMMENT, // "comment"
+       M_IF,      // "if"
+       M_MENU,    // "mainmenu", "menu", "menuconfig"
+       M_NORMAL,  // others, i.e., "config"
+};
+
 /*
  * Represents a node in the menu tree, as seen in e.g. menuconfig (though used
  * for all front ends). Each symbol, menu, etc. defined in the Kconfig files
  * gets a node. A symbol defined in multiple locations gets one node at each
  * location.
  *
+ * @type: type of the menu entry
  * @choice_members: list of choice members with priority.
  */
 struct menu {
+       enum menu_type type;
+
        /* The next menu node at the same level */
        struct menu *next;
 
index b8ebc3094a2347d609bece1caf7278f3d61e1303..fbc907f75eac7e764be777931f6a0b6fdc1a7ccd 100644 (file)
@@ -81,7 +81,7 @@ void _menu_init(void);
 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_entry(struct symbol *sym, enum menu_type type);
 void menu_add_dep(struct expr *dep);
 void menu_add_visibility(struct expr *dep);
 struct property *menu_add_prompt(enum prop_type type, const char *prompt,
index 6587ac86d0d52b53e14d619770a23de924fa62cd..7d48a692bd273ca98187d8a2c7a1d3e820b8efa4 100644 (file)
@@ -15,7 +15,7 @@
 
 static const char nohelp_text[] = "There is no help available for this option.";
 
-struct menu rootmenu;
+struct menu rootmenu = { .type = M_MENU };
 static struct menu **last_entry_ptr;
 
 /**
@@ -65,12 +65,13 @@ void _menu_init(void)
        last_entry_ptr = &rootmenu.list;
 }
 
-void menu_add_entry(struct symbol *sym)
+void menu_add_entry(struct symbol *sym, enum menu_type type)
 {
        struct menu *menu;
 
        menu = xmalloc(sizeof(*menu));
        memset(menu, 0, sizeof(*menu));
+       menu->type = type;
        menu->sym = sym;
        menu->parent = current_menu;
        menu->filename = cur_filename;
index 68372d3ff32539cb5460807ca4369343eff4481d..e9c3c664e9251157a135bc78c0039665dd87b16d 100644 (file)
@@ -139,7 +139,7 @@ stmt_list_in_choice:
 
 config_entry_start: T_CONFIG nonconst_symbol T_EOL
 {
-       menu_add_entry($2);
+       menu_add_entry($2, M_NORMAL);
        printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name);
 };
 
@@ -173,7 +173,7 @@ config_stmt: config_entry_start config_option_list
 
 menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
 {
-       menu_add_entry($2);
+       menu_add_entry($2, M_MENU);
        printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name);
 };
 
@@ -246,7 +246,7 @@ choice: T_CHOICE T_EOL
 {
        struct symbol *sym = sym_lookup(NULL, 0);
 
-       menu_add_entry(sym);
+       menu_add_entry(sym, M_CHOICE);
        menu_set_type(S_BOOLEAN);
        INIT_LIST_HEAD(&current_entry->choice_members);
 
@@ -315,7 +315,7 @@ default:
 if_entry: T_IF expr T_EOL
 {
        printd(DEBUG_PARSE, "%s:%d:if\n", cur_filename, cur_lineno);
-       menu_add_entry(NULL);
+       menu_add_entry(NULL, M_IF);
        menu_add_dep($2);
        $$ = menu_add_menu();
 };
@@ -338,7 +338,7 @@ if_stmt_in_choice: if_entry stmt_list_in_choice if_end
 
 menu: T_MENU T_WORD_QUOTE T_EOL
 {
-       menu_add_entry(NULL);
+       menu_add_entry(NULL, M_MENU);
        menu_add_prompt(P_MENU, $2, NULL);
        printd(DEBUG_PARSE, "%s:%d:menu\n", cur_filename, cur_lineno);
 };
@@ -376,7 +376,7 @@ source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
 
 comment: T_COMMENT T_WORD_QUOTE T_EOL
 {
-       menu_add_entry(NULL);
+       menu_add_entry(NULL, M_COMMENT);
        menu_add_prompt(P_COMMENT, $2, NULL);
        printd(DEBUG_PARSE, "%s:%d:comment\n", cur_filename, cur_lineno);
 };