parser.y (a23e1966932464e1c5226cb9ac4ce1d5fc10ba22) | parser.y (fde192511bdbff554320b31574bb8a9cb3275522) |
---|---|
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 4 */ 5%{ 6 7#include <ctype.h> 8#include <stdarg.h> --- 16 unchanged lines hidden (view full) --- 25static void yyerror(const char *err); 26static void zconfprint(const char *err, ...); 27static void zconf_error(const char *err, ...); 28static bool zconf_endtoken(const char *tokenname, 29 const char *expected_tokenname); 30 31struct menu *current_menu, *current_entry; 32 | 1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 4 */ 5%{ 6 7#include <ctype.h> 8#include <stdarg.h> --- 16 unchanged lines hidden (view full) --- 25static void yyerror(const char *err); 26static void zconfprint(const char *err, ...); 27static void zconf_error(const char *err, ...); 28static bool zconf_endtoken(const char *tokenname, 29 const char *expected_tokenname); 30 31struct menu *current_menu, *current_entry; 32 |
33static bool inside_choice = false; 34 |
|
33%} 34 35%union 36{ 37 char *string; 38 struct symbol *symbol; 39 struct expr *expr; 40 struct menu *menu; --- 23 unchanged lines hidden (view full) --- 64%token T_IMPLY 65%token T_INT 66%token T_MAINMENU 67%token T_MENU 68%token T_MENUCONFIG 69%token T_MODULES 70%token T_ON 71%token T_OPEN_PAREN | 35%} 36 37%union 38{ 39 char *string; 40 struct symbol *symbol; 41 struct expr *expr; 42 struct menu *menu; --- 23 unchanged lines hidden (view full) --- 66%token T_IMPLY 67%token T_INT 68%token T_MAINMENU 69%token T_MENU 70%token T_MENUCONFIG 71%token T_MODULES 72%token T_ON 73%token T_OPEN_PAREN |
72%token T_OPTIONAL | |
73%token T_PLUS_EQUAL 74%token T_PROMPT 75%token T_RANGE 76%token T_SELECT 77%token T_SOURCE 78%token T_STRING 79%token T_TRISTATE 80%token T_VISIBLE 81%token T_EOL 82%token <string> T_ASSIGN_VAL 83 84%left T_OR 85%left T_AND 86%left T_EQUAL T_UNEQUAL 87%left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL 88%nonassoc T_NOT 89 90%type <symbol> nonconst_symbol 91%type <symbol> symbol | 74%token T_PLUS_EQUAL 75%token T_PROMPT 76%token T_RANGE 77%token T_SELECT 78%token T_SOURCE 79%token T_STRING 80%token T_TRISTATE 81%token T_VISIBLE 82%token T_EOL 83%token <string> T_ASSIGN_VAL 84 85%left T_OR 86%left T_AND 87%left T_EQUAL T_UNEQUAL 88%left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL 89%nonassoc T_NOT 90 91%type <symbol> nonconst_symbol 92%type <symbol> symbol |
92%type <type> type logic_type default | 93%type <type> type default |
93%type <expr> expr 94%type <expr> if_expr 95%type <string> end 96%type <menu> if_entry menu_entry choice_entry 97%type <string> assign_val 98%type <flavor> assign_op 99 100%destructor { --- 34 unchanged lines hidden (view full) --- 135 | stmt_list_in_choice if_stmt_in_choice 136 | stmt_list_in_choice error T_EOL { zconf_error("invalid statement"); } 137; 138 139/* config/menuconfig entry */ 140 141config_entry_start: T_CONFIG nonconst_symbol T_EOL 142{ | 94%type <expr> expr 95%type <expr> if_expr 96%type <string> end 97%type <menu> if_entry menu_entry choice_entry 98%type <string> assign_val 99%type <flavor> assign_op 100 101%destructor { --- 34 unchanged lines hidden (view full) --- 136 | stmt_list_in_choice if_stmt_in_choice 137 | stmt_list_in_choice error T_EOL { zconf_error("invalid statement"); } 138; 139 140/* config/menuconfig entry */ 141 142config_entry_start: T_CONFIG nonconst_symbol T_EOL 143{ |
143 $2->flags |= SYMBOL_OPTIONAL; | |
144 menu_add_entry($2); 145 printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name); 146}; 147 148config_stmt: config_entry_start config_option_list 149{ | 144 menu_add_entry($2); 145 printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name); 146}; 147 148config_stmt: config_entry_start config_option_list 149{ |
150 if (inside_choice) { 151 if (!current_entry->prompt) { 152 fprintf(stderr, "%s:%d: error: choice member must have a prompt\n", 153 current_entry->filename, current_entry->lineno); 154 yynerrs++; 155 } 156 157 if (current_entry->sym->type != S_BOOLEAN) { 158 fprintf(stderr, "%s:%d: error: choice member must be bool\n", 159 current_entry->filename, current_entry->lineno); 160 yynerrs++; 161 } 162 } 163 |
|
150 printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno); 151}; 152 153menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL 154{ | 164 printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno); 165}; 166 167menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL 168{ |
155 $2->flags |= SYMBOL_OPTIONAL; | |
156 menu_add_entry($2); 157 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name); 158}; 159 160menuconfig_stmt: menuconfig_entry_start config_option_list 161{ 162 if (current_entry->prompt) 163 current_entry->prompt->type = P_MENU; --- 55 unchanged lines hidden (view full) --- 219 current_entry->sym->name, modules_sym->name); 220 modules_sym = current_entry->sym; 221}; 222 223/* choice entry */ 224 225choice: T_CHOICE T_EOL 226{ | 169 menu_add_entry($2); 170 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name); 171}; 172 173menuconfig_stmt: menuconfig_entry_start config_option_list 174{ 175 if (current_entry->prompt) 176 current_entry->prompt->type = P_MENU; --- 55 unchanged lines hidden (view full) --- 232 current_entry->sym->name, modules_sym->name); 233 modules_sym = current_entry->sym; 234}; 235 236/* choice entry */ 237 238choice: T_CHOICE T_EOL 239{ |
227 struct symbol *sym = sym_lookup(NULL, SYMBOL_CHOICE); 228 sym->flags |= SYMBOL_NO_WRITE; | 240 struct symbol *sym = sym_lookup(NULL, 0); 241 |
229 menu_add_entry(sym); 230 menu_add_expr(P_CHOICE, NULL, NULL); | 242 menu_add_entry(sym); 243 menu_add_expr(P_CHOICE, NULL, NULL); |
244 menu_set_type(S_BOOLEAN); 245 |
|
231 printd(DEBUG_PARSE, "%s:%d:choice\n", cur_filename, cur_lineno); 232}; 233 234choice_entry: choice choice_option_list 235{ 236 if (!current_entry->prompt) { 237 fprintf(stderr, "%s:%d: error: choice must have a prompt\n", 238 current_entry->filename, current_entry->lineno); 239 yynerrs++; 240 } 241 242 $$ = menu_add_menu(); | 246 printd(DEBUG_PARSE, "%s:%d:choice\n", cur_filename, cur_lineno); 247}; 248 249choice_entry: choice choice_option_list 250{ 251 if (!current_entry->prompt) { 252 fprintf(stderr, "%s:%d: error: choice must have a prompt\n", 253 current_entry->filename, current_entry->lineno); 254 yynerrs++; 255 } 256 257 $$ = menu_add_menu(); |
258 259 inside_choice = true; |
|
243}; 244 245choice_end: end 246{ | 260}; 261 262choice_end: end 263{ |
264 inside_choice = false; 265 |
|
247 if (zconf_endtoken($1, "choice")) { 248 menu_end_menu(); 249 printd(DEBUG_PARSE, "%s:%d:endchoice\n", cur_filename, cur_lineno); 250 } 251}; 252 253choice_stmt: choice_entry stmt_list_in_choice choice_end 254; --- 6 unchanged lines hidden (view full) --- 261; 262 263choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL 264{ 265 menu_add_prompt(P_PROMPT, $2, $3); 266 printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno); 267}; 268 | 266 if (zconf_endtoken($1, "choice")) { 267 menu_end_menu(); 268 printd(DEBUG_PARSE, "%s:%d:endchoice\n", cur_filename, cur_lineno); 269 } 270}; 271 272choice_stmt: choice_entry stmt_list_in_choice choice_end 273; --- 6 unchanged lines hidden (view full) --- 280; 281 282choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL 283{ 284 menu_add_prompt(P_PROMPT, $2, $3); 285 printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno); 286}; 287 |
269choice_option: logic_type prompt_stmt_opt T_EOL | 288choice_option: T_BOOL T_WORD_QUOTE if_expr T_EOL |
270{ | 289{ |
271 menu_set_type($1); 272 printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1); | 290 menu_add_prompt(P_PROMPT, $2, $3); 291 printd(DEBUG_PARSE, "%s:%d:bool\n", cur_filename, cur_lineno); |
273}; 274 | 292}; 293 |
275choice_option: T_OPTIONAL T_EOL 276{ 277 current_entry->sym->flags |= SYMBOL_OPTIONAL; 278 printd(DEBUG_PARSE, "%s:%d:optional\n", cur_filename, cur_lineno); 279}; 280 | |
281choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL 282{ 283 menu_add_symbol(P_DEFAULT, $2, $3); 284 printd(DEBUG_PARSE, "%s:%d:default\n", cur_filename, cur_lineno); 285}; 286 287type: | 294choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL 295{ 296 menu_add_symbol(P_DEFAULT, $2, $3); 297 printd(DEBUG_PARSE, "%s:%d:default\n", cur_filename, cur_lineno); 298}; 299 300type: |
288 logic_type | 301 T_BOOL { $$ = S_BOOLEAN; } 302 | T_TRISTATE { $$ = S_TRISTATE; } |
289 | T_INT { $$ = S_INT; } 290 | T_HEX { $$ = S_HEX; } 291 | T_STRING { $$ = S_STRING; } 292 | 303 | T_INT { $$ = S_INT; } 304 | T_HEX { $$ = S_HEX; } 305 | T_STRING { $$ = S_STRING; } 306 |
293logic_type: 294 T_BOOL { $$ = S_BOOLEAN; } 295 | T_TRISTATE { $$ = S_TRISTATE; } 296 | |
297default: 298 T_DEFAULT { $$ = S_UNKNOWN; } 299 | T_DEF_BOOL { $$ = S_BOOLEAN; } 300 | T_DEF_TRISTATE { $$ = S_TRISTATE; } 301 302/* if entry */ 303 304if_entry: T_IF expr T_EOL --- 161 unchanged lines hidden (view full) --- 466 467assign_val: 468 /* empty */ { $$ = xstrdup(""); }; 469 | T_ASSIGN_VAL 470; 471 472%% 473 | 307default: 308 T_DEFAULT { $$ = S_UNKNOWN; } 309 | T_DEF_BOOL { $$ = S_BOOLEAN; } 310 | T_DEF_TRISTATE { $$ = S_TRISTATE; } 311 312/* if entry */ 313 314if_entry: T_IF expr T_EOL --- 161 unchanged lines hidden (view full) --- 476 477assign_val: 478 /* empty */ { $$ = xstrdup(""); }; 479 | T_ASSIGN_VAL 480; 481 482%% 483 |
484/** 485 * choice_check_sanity - check sanity of a choice member 486 * 487 * @menu: menu of the choice member 488 * 489 * Return: -1 if an error is found, 0 otherwise. 490 */ 491static int choice_check_sanity(struct menu *menu) 492{ 493 struct property *prop; 494 int ret = 0; 495 496 for (prop = menu->sym->prop; prop; prop = prop->next) { 497 if (prop->type == P_DEFAULT) { 498 fprintf(stderr, "%s:%d: error: %s", 499 prop->filename, prop->lineno, 500 "defaults for choice values not supported\n"); 501 ret = -1; 502 } 503 504 if (prop->menu != menu && prop->type == P_PROMPT && 505 prop->menu->parent != menu->parent) { 506 fprintf(stderr, "%s:%d: error: %s", 507 prop->filename, prop->lineno, 508 "choice value has a prompt outside its choice group\n"); 509 ret = -1; 510 } 511 } 512 513 return ret; 514} 515 |
|
474void conf_parse(const char *name) 475{ 476 struct menu *menu; 477 478 autoconf_cmd = str_new(); 479 480 str_printf(&autoconf_cmd, "\ndeps_config := \\\n"); 481 --- 30 unchanged lines hidden (view full) --- 512 513 if (!menu_has_prompt(&rootmenu)) { 514 current_entry = &rootmenu; 515 menu_add_prompt(P_MENU, "Main menu", NULL); 516 } 517 518 menu_finalize(); 519 | 516void conf_parse(const char *name) 517{ 518 struct menu *menu; 519 520 autoconf_cmd = str_new(); 521 522 str_printf(&autoconf_cmd, "\ndeps_config := \\\n"); 523 --- 30 unchanged lines hidden (view full) --- 554 555 if (!menu_has_prompt(&rootmenu)) { 556 current_entry = &rootmenu; 557 menu_add_prompt(P_MENU, "Main menu", NULL); 558 } 559 560 menu_finalize(); 561 |
520 menu = &rootmenu; 521 while (menu) { | 562 menu_for_each_entry(menu) { 563 struct menu *child; 564 |
522 if (menu->sym && sym_check_deps(menu->sym)) 523 yynerrs++; 524 | 565 if (menu->sym && sym_check_deps(menu->sym)) 566 yynerrs++; 567 |
525 if (menu->list) { 526 menu = menu->list; 527 continue; | 568 if (menu->sym && sym_is_choice(menu->sym)) { 569 menu_for_each_sub_entry(child, menu) 570 if (child->sym && choice_check_sanity(child)) 571 yynerrs++; |
528 } | 572 } |
529 530 while (!menu->next && menu->parent) 531 menu = menu->parent; 532 533 menu = menu->next; | |
534 } 535 536 if (yynerrs) 537 exit(1); 538 conf_set_changed(true); 539} 540 541static bool zconf_endtoken(const char *tokenname, --- 202 unchanged lines hidden --- | 573 } 574 575 if (yynerrs) 576 exit(1); 577 conf_set_changed(true); 578} 579 580static bool zconf_endtoken(const char *tokenname, --- 202 unchanged lines hidden --- |