Skip to content

Commit 09d5873

Browse files
committed
kconfig: allow only 'config', 'comment', and 'if' inside 'choice'
The code block surrounded by 'if' ... 'endif' is reduced into if_stmt, which is accepted in the 'choice' context. Therefore, you can write any statements within a choice block by wrapping 'if y' ... 'end'. For example, you can create a menu inside a choice, like follows: ---------------->8---------------- choice prompt "choice" config A bool "A" config B bool "B" if y menu "strange menu" config C bool "C" endmenu endif endchoice ---------------->8---------------- I want to change such a weird structure into a syntax error. In fact, the USB gadget Kconfig had used nested 'choice' for no good reason until commit df8df5e ("usb: get rid of 'choice' for legacy gadget drivers") killed it. I think the 'source' inside 'choice' is on the fence. It is at least gramatically sensible as long as the included file contains only bool/tristate configs. However, it makes the code unreadable, and people tend to forget the fact that the file is included from the choice block. Commit 10e5e6c ("usb: gadget: move choice ... endchoice to legacy/Kconfig") got rid of the only usecase. Going forward, you can only use 'config', 'comment', and 'if' inside 'choice'. This also recursively applies to 'if' blocks inside 'choice'. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent b754611 commit 09d5873

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

scripts/kconfig/parser.y

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,24 @@ mainmenu_stmt: T_MAINMENU T_WORD_QUOTE T_EOL
119119

120120
stmt_list:
121121
/* empty */
122-
| stmt_list common_stmt
122+
| stmt_list assignment_stmt
123123
| stmt_list choice_stmt
124+
| stmt_list comment_stmt
125+
| stmt_list config_stmt
126+
| stmt_list if_stmt
124127
| stmt_list menu_stmt
128+
| stmt_list menuconfig_stmt
129+
| stmt_list source_stmt
125130
| stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
126131
| stmt_list error T_EOL { zconf_error("invalid statement"); }
127132
;
128133

129-
common_stmt:
130-
if_stmt
131-
| comment_stmt
132-
| config_stmt
133-
| menuconfig_stmt
134-
| source_stmt
135-
| assignment_stmt
134+
stmt_list_in_choice:
135+
/* empty */
136+
| stmt_list_in_choice comment_stmt
137+
| stmt_list_in_choice config_stmt
138+
| stmt_list_in_choice if_stmt_in_choice
139+
| stmt_list_in_choice error T_EOL { zconf_error("invalid statement"); }
136140
;
137141

138142
/* config/menuconfig entry */
@@ -254,7 +258,7 @@ choice_end: end
254258
}
255259
};
256260

257-
choice_stmt: choice_entry choice_block choice_end
261+
choice_stmt: choice_entry stmt_list_in_choice choice_end
258262
;
259263

260264
choice_option_list:
@@ -305,11 +309,6 @@ default:
305309
| T_DEF_BOOL { $$ = S_BOOLEAN; }
306310
| T_DEF_TRISTATE { $$ = S_TRISTATE; }
307311

308-
choice_block:
309-
/* empty */
310-
| choice_block common_stmt
311-
;
312-
313312
/* if entry */
314313

315314
if_entry: T_IF expr T_EOL
@@ -331,6 +330,9 @@ if_end: end
331330
if_stmt: if_entry stmt_list if_end
332331
;
333332

333+
if_stmt_in_choice: if_entry stmt_list_in_choice if_end
334+
;
335+
334336
/* menu entry */
335337

336338
menu: T_MENU T_WORD_QUOTE T_EOL

0 commit comments

Comments
 (0)