aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/zconf.y
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/zconf.y')
-rw-r--r--scripts/kconfig/zconf.y315
1 files changed, 153 insertions, 162 deletions
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index e1a0f455d4a8..1f61fba6aa28 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -11,6 +11,11 @@
11#include <string.h> 11#include <string.h>
12#include <stdbool.h> 12#include <stdbool.h>
13 13
14#define LKC_DIRECT_LINK
15#include "lkc.h"
16
17#include "zconf.hash.c"
18
14#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt) 19#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
15 20
16#define PRINTD 0x0001 21#define PRINTD 0x0001
@@ -20,61 +25,59 @@ int cdebug = PRINTD;
20 25
21extern int zconflex(void); 26extern int zconflex(void);
22static void zconfprint(const char *err, ...); 27static void zconfprint(const char *err, ...);
28static void zconf_error(const char *err, ...);
23static void zconferror(const char *err); 29static void zconferror(const char *err);
24static bool zconf_endtoken(int token, int starttoken, int endtoken); 30static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken);
25 31
26struct symbol *symbol_hash[257]; 32struct symbol *symbol_hash[257];
27 33
28static struct menu *current_menu, *current_entry; 34static struct menu *current_menu, *current_entry;
29 35
36#define YYDEBUG 0
37#if YYDEBUG
30#define YYERROR_VERBOSE 38#define YYERROR_VERBOSE
39#endif
31%} 40%}
32%expect 40 41%expect 26
33 42
34%union 43%union
35{ 44{
36 int token;
37 char *string; 45 char *string;
46 struct file *file;
38 struct symbol *symbol; 47 struct symbol *symbol;
39 struct expr *expr; 48 struct expr *expr;
40 struct menu *menu; 49 struct menu *menu;
50 struct kconf_id *id;
41} 51}
42 52
43%token T_MAINMENU 53%token <id>T_MAINMENU
44%token T_MENU 54%token <id>T_MENU
45%token T_ENDMENU 55%token <id>T_ENDMENU
46%token T_SOURCE 56%token <id>T_SOURCE
47%token T_CHOICE 57%token <id>T_CHOICE
48%token T_ENDCHOICE 58%token <id>T_ENDCHOICE
49%token T_COMMENT 59%token <id>T_COMMENT
50%token T_CONFIG 60%token <id>T_CONFIG
51%token T_MENUCONFIG 61%token <id>T_MENUCONFIG
52%token T_HELP 62%token <id>T_HELP
53%token <string> T_HELPTEXT 63%token <string> T_HELPTEXT
54%token T_IF 64%token <id>T_IF
55%token T_ENDIF 65%token <id>T_ENDIF
56%token T_DEPENDS 66%token <id>T_DEPENDS
57%token T_REQUIRES 67%token <id>T_REQUIRES
58%token T_OPTIONAL 68%token <id>T_OPTIONAL
59%token T_PROMPT 69%token <id>T_PROMPT
60%token T_DEFAULT 70%token <id>T_TYPE
61%token T_TRISTATE 71%token <id>T_DEFAULT
62%token T_DEF_TRISTATE 72%token <id>T_SELECT
63%token T_BOOLEAN 73%token <id>T_RANGE
64%token T_DEF_BOOLEAN 74%token <id>T_ON
65%token T_STRING
66%token T_INT
67%token T_HEX
68%token <string> T_WORD 75%token <string> T_WORD
69%token <string> T_WORD_QUOTE 76%token <string> T_WORD_QUOTE
70%token T_UNEQUAL 77%token T_UNEQUAL
71%token T_EOF
72%token T_EOL
73%token T_CLOSE_PAREN 78%token T_CLOSE_PAREN
74%token T_OPEN_PAREN 79%token T_OPEN_PAREN
75%token T_ON 80%token T_EOL
76%token T_SELECT
77%token T_RANGE
78 81
79%left T_OR 82%left T_OR
80%left T_AND 83%left T_AND
@@ -82,38 +85,54 @@ static struct menu *current_menu, *current_entry;
82%nonassoc T_NOT 85%nonassoc T_NOT
83 86
84%type <string> prompt 87%type <string> prompt
85%type <string> source
86%type <symbol> symbol 88%type <symbol> symbol
87%type <expr> expr 89%type <expr> expr
88%type <expr> if_expr 90%type <expr> if_expr
89%type <token> end 91%type <id> end
92%type <id> option_name
93%type <menu> if_entry menu_entry choice_entry
94
95%destructor {
96 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
97 $$->file->name, $$->lineno);
98 if (current_menu == $$)
99 menu_end_menu();
100} if_entry menu_entry choice_entry
90 101
91%{
92#define LKC_DIRECT_LINK
93#include "lkc.h"
94%}
95%% 102%%
96input: /* empty */ 103input: stmt_list;
97 | input block 104
105stmt_list:
106 /* empty */
107 | stmt_list common_stmt
108 | stmt_list choice_stmt
109 | stmt_list menu_stmt
110 | stmt_list T_MAINMENU prompt nl
111 | stmt_list end { zconf_error("unexpected end statement"); }
112 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
113 | stmt_list option_name error T_EOL
114{
115 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
116}
117 | stmt_list error T_EOL { zconf_error("invalid statement"); }
98; 118;
99 119
100block: common_block 120option_name:
101 | choice_stmt 121 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT
102 | menu_stmt
103 | T_MAINMENU prompt nl_or_eof
104 | T_ENDMENU { zconfprint("unexpected 'endmenu' statement"); }
105 | T_ENDIF { zconfprint("unexpected 'endif' statement"); }
106 | T_ENDCHOICE { zconfprint("unexpected 'endchoice' statement"); }
107 | error nl_or_eof { zconfprint("syntax error"); yyerrok; }
108; 122;
109 123
110common_block: 124common_stmt:
111 if_stmt 125 T_EOL
126 | if_stmt
112 | comment_stmt 127 | comment_stmt
113 | config_stmt 128 | config_stmt
114 | menuconfig_stmt 129 | menuconfig_stmt
115 | source_stmt 130 | source_stmt
116 | nl_or_eof 131;
132
133option_error:
134 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
135 | error T_EOL { zconf_error("invalid option"); }
117; 136;
118 137
119 138
@@ -156,51 +175,16 @@ config_option_list:
156 | config_option_list config_option 175 | config_option_list config_option
157 | config_option_list depends 176 | config_option_list depends
158 | config_option_list help 177 | config_option_list help
178 | config_option_list option_error
159 | config_option_list T_EOL 179 | config_option_list T_EOL
160; 180;
161 181
162config_option: T_TRISTATE prompt_stmt_opt T_EOL 182config_option: T_TYPE prompt_stmt_opt T_EOL
163{ 183{
164 menu_set_type(S_TRISTATE); 184 menu_set_type($1->stype);
165 printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno()); 185 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
166}; 186 zconf_curname(), zconf_lineno(),
167 187 $1->stype);
168config_option: T_DEF_TRISTATE expr if_expr T_EOL
169{
170 menu_add_expr(P_DEFAULT, $2, $3);
171 menu_set_type(S_TRISTATE);
172 printd(DEBUG_PARSE, "%s:%d:def_boolean\n", zconf_curname(), zconf_lineno());
173};
174
175config_option: T_BOOLEAN prompt_stmt_opt T_EOL
176{
177 menu_set_type(S_BOOLEAN);
178 printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno());
179};
180
181config_option: T_DEF_BOOLEAN expr if_expr T_EOL
182{
183 menu_add_expr(P_DEFAULT, $2, $3);
184 menu_set_type(S_BOOLEAN);
185 printd(DEBUG_PARSE, "%s:%d:def_boolean\n", zconf_curname(), zconf_lineno());
186};
187
188config_option: T_INT prompt_stmt_opt T_EOL
189{
190 menu_set_type(S_INT);
191 printd(DEBUG_PARSE, "%s:%d:int\n", zconf_curname(), zconf_lineno());
192};
193
194config_option: T_HEX prompt_stmt_opt T_EOL
195{
196 menu_set_type(S_HEX);
197 printd(DEBUG_PARSE, "%s:%d:hex\n", zconf_curname(), zconf_lineno());
198};
199
200config_option: T_STRING prompt_stmt_opt T_EOL
201{
202 menu_set_type(S_STRING);
203 printd(DEBUG_PARSE, "%s:%d:string\n", zconf_curname(), zconf_lineno());
204}; 188};
205 189
206config_option: T_PROMPT prompt if_expr T_EOL 190config_option: T_PROMPT prompt if_expr T_EOL
@@ -212,7 +196,11 @@ config_option: T_PROMPT prompt if_expr T_EOL
212config_option: T_DEFAULT expr if_expr T_EOL 196config_option: T_DEFAULT expr if_expr T_EOL
213{ 197{
214 menu_add_expr(P_DEFAULT, $2, $3); 198 menu_add_expr(P_DEFAULT, $2, $3);
215 printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno()); 199 if ($1->stype != S_UNKNOWN)
200 menu_set_type($1->stype);
201 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
202 zconf_curname(), zconf_lineno(),
203 $1->stype);
216}; 204};
217 205
218config_option: T_SELECT T_WORD if_expr T_EOL 206config_option: T_SELECT T_WORD if_expr T_EOL
@@ -240,8 +228,7 @@ choice: T_CHOICE T_EOL
240 228
241choice_entry: choice choice_option_list 229choice_entry: choice choice_option_list
242{ 230{
243 menu_end_entry(); 231 $$ = menu_add_menu();
244 menu_add_menu();
245}; 232};
246 233
247choice_end: end 234choice_end: end
@@ -252,13 +239,8 @@ choice_end: end
252 } 239 }
253}; 240};
254 241
255choice_stmt: 242choice_stmt: choice_entry choice_block choice_end
256 choice_entry choice_block choice_end 243;
257 | choice_entry choice_block
258{
259 printf("%s:%d: missing 'endchoice' for this 'choice' statement\n", current_menu->file->name, current_menu->lineno);
260 zconfnerrs++;
261};
262 244
263choice_option_list: 245choice_option_list:
264 /* empty */ 246 /* empty */
@@ -266,6 +248,7 @@ choice_option_list:
266 | choice_option_list depends 248 | choice_option_list depends
267 | choice_option_list help 249 | choice_option_list help
268 | choice_option_list T_EOL 250 | choice_option_list T_EOL
251 | choice_option_list option_error
269; 252;
270 253
271choice_option: T_PROMPT prompt if_expr T_EOL 254choice_option: T_PROMPT prompt if_expr T_EOL
@@ -274,16 +257,15 @@ choice_option: T_PROMPT prompt if_expr T_EOL
274 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); 257 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
275}; 258};
276 259
277choice_option: T_TRISTATE prompt_stmt_opt T_EOL 260choice_option: T_TYPE prompt_stmt_opt T_EOL
278{
279 menu_set_type(S_TRISTATE);
280 printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno());
281};
282
283choice_option: T_BOOLEAN prompt_stmt_opt T_EOL
284{ 261{
285 menu_set_type(S_BOOLEAN); 262 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
286 printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno()); 263 menu_set_type($1->stype);
264 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
265 zconf_curname(), zconf_lineno(),
266 $1->stype);
267 } else
268 YYERROR;
287}; 269};
288 270
289choice_option: T_OPTIONAL T_EOL 271choice_option: T_OPTIONAL T_EOL
@@ -294,24 +276,27 @@ choice_option: T_OPTIONAL T_EOL
294 276
295choice_option: T_DEFAULT T_WORD if_expr T_EOL 277choice_option: T_DEFAULT T_WORD if_expr T_EOL
296{ 278{
297 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3); 279 if ($1->stype == S_UNKNOWN) {
298 printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno()); 280 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
281 printd(DEBUG_PARSE, "%s:%d:default\n",
282 zconf_curname(), zconf_lineno());
283 } else
284 YYERROR;
299}; 285};
300 286
301choice_block: 287choice_block:
302 /* empty */ 288 /* empty */
303 | choice_block common_block 289 | choice_block common_stmt
304; 290;
305 291
306/* if entry */ 292/* if entry */
307 293
308if: T_IF expr T_EOL 294if_entry: T_IF expr nl
309{ 295{
310 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno()); 296 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
311 menu_add_entry(NULL); 297 menu_add_entry(NULL);
312 menu_add_dep($2); 298 menu_add_dep($2);
313 menu_end_entry(); 299 $$ = menu_add_menu();
314 menu_add_menu();
315}; 300};
316 301
317if_end: end 302if_end: end
@@ -322,17 +307,12 @@ if_end: end
322 } 307 }
323}; 308};
324 309
325if_stmt: 310if_stmt: if_entry if_block if_end
326 if if_block if_end 311;
327 | if if_block
328{
329 printf("%s:%d: missing 'endif' for this 'if' statement\n", current_menu->file->name, current_menu->lineno);
330 zconfnerrs++;
331};
332 312
333if_block: 313if_block:
334 /* empty */ 314 /* empty */
335 | if_block common_block 315 | if_block common_stmt
336 | if_block menu_stmt 316 | if_block menu_stmt
337 | if_block choice_stmt 317 | if_block choice_stmt
338; 318;
@@ -348,8 +328,7 @@ menu: T_MENU prompt T_EOL
348 328
349menu_entry: menu depends_list 329menu_entry: menu depends_list
350{ 330{
351 menu_end_entry(); 331 $$ = menu_add_menu();
352 menu_add_menu();
353}; 332};
354 333
355menu_end: end 334menu_end: end
@@ -360,31 +339,20 @@ menu_end: end
360 } 339 }
361}; 340};
362 341
363menu_stmt: 342menu_stmt: menu_entry menu_block menu_end
364 menu_entry menu_block menu_end 343;
365 | menu_entry menu_block
366{
367 printf("%s:%d: missing 'endmenu' for this 'menu' statement\n", current_menu->file->name, current_menu->lineno);
368 zconfnerrs++;
369};
370 344
371menu_block: 345menu_block:
372 /* empty */ 346 /* empty */
373 | menu_block common_block 347 | menu_block common_stmt
374 | menu_block menu_stmt 348 | menu_block menu_stmt
375 | menu_block choice_stmt 349 | menu_block choice_stmt
376 | menu_block error T_EOL { zconfprint("invalid menu option"); yyerrok; }
377; 350;
378 351
379source: T_SOURCE prompt T_EOL 352source_stmt: T_SOURCE prompt T_EOL
380{ 353{
381 $$ = $2;
382 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); 354 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
383}; 355 zconf_nextfile($2);
384
385source_stmt: source
386{
387 zconf_nextfile($1);
388}; 356};
389 357
390/* comment entry */ 358/* comment entry */
@@ -416,9 +384,11 @@ help: help_start T_HELPTEXT
416 384
417/* depends option */ 385/* depends option */
418 386
419depends_list: /* empty */ 387depends_list:
420 | depends_list depends 388 /* empty */
421 | depends_list T_EOL 389 | depends_list depends
390 | depends_list T_EOL
391 | depends_list option_error
422; 392;
423 393
424depends: T_DEPENDS T_ON expr T_EOL 394depends: T_DEPENDS T_ON expr T_EOL
@@ -450,13 +420,15 @@ prompt: T_WORD
450 | T_WORD_QUOTE 420 | T_WORD_QUOTE
451; 421;
452 422
453end: T_ENDMENU nl_or_eof { $$ = T_ENDMENU; } 423end: T_ENDMENU T_EOL { $$ = $1; }
454 | T_ENDCHOICE nl_or_eof { $$ = T_ENDCHOICE; } 424 | T_ENDCHOICE T_EOL { $$ = $1; }
455 | T_ENDIF nl_or_eof { $$ = T_ENDIF; } 425 | T_ENDIF T_EOL { $$ = $1; }
456; 426;
457 427
458nl_or_eof: 428nl:
459 T_EOL | T_EOF; 429 T_EOL
430 | nl T_EOL
431;
460 432
461if_expr: /* empty */ { $$ = NULL; } 433if_expr: /* empty */ { $$ = NULL; }
462 | T_IF expr { $$ = $2; } 434 | T_IF expr { $$ = $2; }
@@ -489,16 +461,16 @@ void conf_parse(const char *name)
489 modules_sym = sym_lookup("MODULES", 0); 461 modules_sym = sym_lookup("MODULES", 0);
490 rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL); 462 rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
491 463
492 //zconfdebug = 1; 464#if YYDEBUG
465 if (getenv("ZCONF_DEBUG"))
466 zconfdebug = 1;
467#endif
493 zconfparse(); 468 zconfparse();
494 if (zconfnerrs) 469 if (zconfnerrs)
495 exit(1); 470 exit(1);
496 menu_finalize(&rootmenu); 471 menu_finalize(&rootmenu);
497 for_all_symbols(i, sym) { 472 for_all_symbols(i, sym) {
498 if (!(sym->flags & SYMBOL_CHECKED) && sym_check_deps(sym)) 473 sym_check_deps(sym);
499 printf("\n");
500 else
501 sym->flags |= SYMBOL_CHECK_DONE;
502 } 474 }
503 475
504 sym_change_count = 1; 476 sym_change_count = 1;
@@ -513,20 +485,25 @@ const char *zconf_tokenname(int token)
513 case T_ENDCHOICE: return "endchoice"; 485 case T_ENDCHOICE: return "endchoice";
514 case T_IF: return "if"; 486 case T_IF: return "if";
515 case T_ENDIF: return "endif"; 487 case T_ENDIF: return "endif";
488 case T_DEPENDS: return "depends";
516 } 489 }
517 return "<token>"; 490 return "<token>";
518} 491}
519 492
520static bool zconf_endtoken(int token, int starttoken, int endtoken) 493static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken)
521{ 494{
522 if (token != endtoken) { 495 if (id->token != endtoken) {
523 zconfprint("unexpected '%s' within %s block", zconf_tokenname(token), zconf_tokenname(starttoken)); 496 zconf_error("unexpected '%s' within %s block",
497 kconf_id_strings + id->name, zconf_tokenname(starttoken));
524 zconfnerrs++; 498 zconfnerrs++;
525 return false; 499 return false;
526 } 500 }
527 if (current_menu->file != current_file) { 501 if (current_menu->file != current_file) {
528 zconfprint("'%s' in different file than '%s'", zconf_tokenname(token), zconf_tokenname(starttoken)); 502 zconf_error("'%s' in different file than '%s'",
529 zconfprint("location of the '%s'", zconf_tokenname(starttoken)); 503 kconf_id_strings + id->name, zconf_tokenname(starttoken));
504 fprintf(stderr, "%s:%d: location of the '%s'\n",
505 current_menu->file->name, current_menu->lineno,
506 zconf_tokenname(starttoken));
530 zconfnerrs++; 507 zconfnerrs++;
531 return false; 508 return false;
532 } 509 }
@@ -537,7 +514,19 @@ static void zconfprint(const char *err, ...)
537{ 514{
538 va_list ap; 515 va_list ap;
539 516
540 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno() + 1); 517 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
518 va_start(ap, err);
519 vfprintf(stderr, err, ap);
520 va_end(ap);
521 fprintf(stderr, "\n");
522}
523
524static void zconf_error(const char *err, ...)
525{
526 va_list ap;
527
528 zconfnerrs++;
529 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
541 va_start(ap, err); 530 va_start(ap, err);
542 vfprintf(stderr, err, ap); 531 vfprintf(stderr, err, ap);
543 va_end(ap); 532 va_end(ap);
@@ -546,7 +535,9 @@ static void zconfprint(const char *err, ...)
546 535
547static void zconferror(const char *err) 536static void zconferror(const char *err)
548{ 537{
538#if YYDEBUG
549 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err); 539 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
540#endif
550} 541}
551 542
552void print_quoted_string(FILE *out, const char *str) 543void print_quoted_string(FILE *out, const char *str)