[PATCH] ARM SMP: Use exclusive load/store for __xchg
[wandboard.git] / scripts / kconfig / zconf.y
blob54460f8d3696b2bd9ee1895ff35d3e5a845a32de
1 %{
2 /*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Released under the terms of the GNU GPL v2.0.
5 */
7 #include <ctype.h>
8 #include <stdarg.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdbool.h>
14 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
16 #define PRINTD 0x0001
17 #define DEBUG_PARSE 0x0002
19 int cdebug = PRINTD;
21 extern int zconflex(void);
22 static void zconfprint(const char *err, ...);
23 static void zconferror(const char *err);
24 static bool zconf_endtoken(int token, int starttoken, int endtoken);
26 struct symbol *symbol_hash[257];
28 static struct menu *current_menu, *current_entry;
30 #define YYERROR_VERBOSE
32 %expect 40
34 %union
36 int token;
37 char *string;
38 struct symbol *symbol;
39 struct expr *expr;
40 struct menu *menu;
43 %token T_MAINMENU
44 %token T_MENU
45 %token T_ENDMENU
46 %token T_SOURCE
47 %token T_CHOICE
48 %token T_ENDCHOICE
49 %token T_COMMENT
50 %token T_CONFIG
51 %token T_MENUCONFIG
52 %token T_HELP
53 %token <string> T_HELPTEXT
54 %token T_IF
55 %token T_ENDIF
56 %token T_DEPENDS
57 %token T_REQUIRES
58 %token T_OPTIONAL
59 %token T_PROMPT
60 %token T_DEFAULT
61 %token T_TRISTATE
62 %token T_DEF_TRISTATE
63 %token T_BOOLEAN
64 %token T_DEF_BOOLEAN
65 %token T_STRING
66 %token T_INT
67 %token T_HEX
68 %token <string> T_WORD
69 %token <string> T_WORD_QUOTE
70 %token T_UNEQUAL
71 %token T_EOF
72 %token T_EOL
73 %token T_CLOSE_PAREN
74 %token T_OPEN_PAREN
75 %token T_ON
76 %token T_SELECT
77 %token T_RANGE
79 %left T_OR
80 %left T_AND
81 %left T_EQUAL T_UNEQUAL
82 %nonassoc T_NOT
84 %type <string> prompt
85 %type <string> source
86 %type <symbol> symbol
87 %type <expr> expr
88 %type <expr> if_expr
89 %type <token> end
92 #define LKC_DIRECT_LINK
93 #include "lkc.h"
96 input: /* empty */
97 | input block
100 block: common_block
101 | choice_stmt
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; }
110 common_block:
111 if_stmt
112 | comment_stmt
113 | config_stmt
114 | menuconfig_stmt
115 | source_stmt
116 | nl_or_eof
120 /* config/menuconfig entry */
122 config_entry_start: T_CONFIG T_WORD T_EOL
124 struct symbol *sym = sym_lookup($2, 0);
125 sym->flags |= SYMBOL_OPTIONAL;
126 menu_add_entry(sym);
127 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
130 config_stmt: config_entry_start config_option_list
132 menu_end_entry();
133 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
136 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
138 struct symbol *sym = sym_lookup($2, 0);
139 sym->flags |= SYMBOL_OPTIONAL;
140 menu_add_entry(sym);
141 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
144 menuconfig_stmt: menuconfig_entry_start config_option_list
146 if (current_entry->prompt)
147 current_entry->prompt->type = P_MENU;
148 else
149 zconfprint("warning: menuconfig statement without prompt");
150 menu_end_entry();
151 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
154 config_option_list:
155 /* empty */
156 | config_option_list config_option
157 | config_option_list depends
158 | config_option_list help
159 | config_option_list T_EOL
162 config_option: T_TRISTATE prompt_stmt_opt T_EOL
164 menu_set_type(S_TRISTATE);
165 printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno());
168 config_option: T_DEF_TRISTATE expr if_expr T_EOL
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());
175 config_option: T_BOOLEAN prompt_stmt_opt T_EOL
177 menu_set_type(S_BOOLEAN);
178 printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno());
181 config_option: T_DEF_BOOLEAN expr if_expr T_EOL
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());
188 config_option: T_INT prompt_stmt_opt T_EOL
190 menu_set_type(S_INT);
191 printd(DEBUG_PARSE, "%s:%d:int\n", zconf_curname(), zconf_lineno());
194 config_option: T_HEX prompt_stmt_opt T_EOL
196 menu_set_type(S_HEX);
197 printd(DEBUG_PARSE, "%s:%d:hex\n", zconf_curname(), zconf_lineno());
200 config_option: T_STRING prompt_stmt_opt T_EOL
202 menu_set_type(S_STRING);
203 printd(DEBUG_PARSE, "%s:%d:string\n", zconf_curname(), zconf_lineno());
206 config_option: T_PROMPT prompt if_expr T_EOL
208 menu_add_prompt(P_PROMPT, $2, $3);
209 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
212 config_option: T_DEFAULT expr if_expr T_EOL
214 menu_add_expr(P_DEFAULT, $2, $3);
215 printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno());
218 config_option: T_SELECT T_WORD if_expr T_EOL
220 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
221 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
224 config_option: T_RANGE symbol symbol if_expr T_EOL
226 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
227 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
230 /* choice entry */
232 choice: T_CHOICE T_EOL
234 struct symbol *sym = sym_lookup(NULL, 0);
235 sym->flags |= SYMBOL_CHOICE;
236 menu_add_entry(sym);
237 menu_add_expr(P_CHOICE, NULL, NULL);
238 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
241 choice_entry: choice choice_option_list
243 menu_end_entry();
244 menu_add_menu();
247 choice_end: end
249 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
250 menu_end_menu();
251 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
255 choice_stmt:
256 choice_entry choice_block choice_end
257 | choice_entry choice_block
259 printf("%s:%d: missing 'endchoice' for this 'choice' statement\n", current_menu->file->name, current_menu->lineno);
260 zconfnerrs++;
263 choice_option_list:
264 /* empty */
265 | choice_option_list choice_option
266 | choice_option_list depends
267 | choice_option_list help
268 | choice_option_list T_EOL
271 choice_option: T_PROMPT prompt if_expr T_EOL
273 menu_add_prompt(P_PROMPT, $2, $3);
274 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
277 choice_option: T_TRISTATE prompt_stmt_opt T_EOL
279 menu_set_type(S_TRISTATE);
280 printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno());
283 choice_option: T_BOOLEAN prompt_stmt_opt T_EOL
285 menu_set_type(S_BOOLEAN);
286 printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno());
289 choice_option: T_OPTIONAL T_EOL
291 current_entry->sym->flags |= SYMBOL_OPTIONAL;
292 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
295 choice_option: T_DEFAULT T_WORD if_expr T_EOL
297 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
298 printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno());
301 choice_block:
302 /* empty */
303 | choice_block common_block
306 /* if entry */
308 if: T_IF expr T_EOL
310 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
311 menu_add_entry(NULL);
312 menu_add_dep($2);
313 menu_end_entry();
314 menu_add_menu();
317 if_end: end
319 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
320 menu_end_menu();
321 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
325 if_stmt:
326 if if_block if_end
327 | if if_block
329 printf("%s:%d: missing 'endif' for this 'if' statement\n", current_menu->file->name, current_menu->lineno);
330 zconfnerrs++;
333 if_block:
334 /* empty */
335 | if_block common_block
336 | if_block menu_stmt
337 | if_block choice_stmt
340 /* menu entry */
342 menu: T_MENU prompt T_EOL
344 menu_add_entry(NULL);
345 menu_add_prop(P_MENU, $2, NULL, NULL);
346 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
349 menu_entry: menu depends_list
351 menu_end_entry();
352 menu_add_menu();
355 menu_end: end
357 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
358 menu_end_menu();
359 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
363 menu_stmt:
364 menu_entry menu_block menu_end
365 | menu_entry menu_block
367 printf("%s:%d: missing 'endmenu' for this 'menu' statement\n", current_menu->file->name, current_menu->lineno);
368 zconfnerrs++;
371 menu_block:
372 /* empty */
373 | menu_block common_block
374 | menu_block menu_stmt
375 | menu_block choice_stmt
376 | menu_block error T_EOL { zconfprint("invalid menu option"); yyerrok; }
379 source: T_SOURCE prompt T_EOL
381 $$ = $2;
382 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
385 source_stmt: source
387 zconf_nextfile($1);
390 /* comment entry */
392 comment: T_COMMENT prompt T_EOL
394 menu_add_entry(NULL);
395 menu_add_prop(P_COMMENT, $2, NULL, NULL);
396 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
399 comment_stmt: comment depends_list
401 menu_end_entry();
404 /* help option */
406 help_start: T_HELP T_EOL
408 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
409 zconf_starthelp();
412 help: help_start T_HELPTEXT
414 current_entry->sym->help = $2;
417 /* depends option */
419 depends_list: /* empty */
420 | depends_list depends
421 | depends_list T_EOL
424 depends: T_DEPENDS T_ON expr T_EOL
426 menu_add_dep($3);
427 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
429 | T_DEPENDS expr T_EOL
431 menu_add_dep($2);
432 printd(DEBUG_PARSE, "%s:%d:depends\n", zconf_curname(), zconf_lineno());
434 | T_REQUIRES expr T_EOL
436 menu_add_dep($2);
437 printd(DEBUG_PARSE, "%s:%d:requires\n", zconf_curname(), zconf_lineno());
440 /* prompt statement */
442 prompt_stmt_opt:
443 /* empty */
444 | prompt if_expr
446 menu_add_prop(P_PROMPT, $1, NULL, $2);
449 prompt: T_WORD
450 | T_WORD_QUOTE
453 end: T_ENDMENU nl_or_eof { $$ = T_ENDMENU; }
454 | T_ENDCHOICE nl_or_eof { $$ = T_ENDCHOICE; }
455 | T_ENDIF nl_or_eof { $$ = T_ENDIF; }
458 nl_or_eof:
459 T_EOL | T_EOF;
461 if_expr: /* empty */ { $$ = NULL; }
462 | T_IF expr { $$ = $2; }
465 expr: symbol { $$ = expr_alloc_symbol($1); }
466 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
467 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
468 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
469 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
470 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
471 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
474 symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
475 | T_WORD_QUOTE { $$ = sym_lookup($1, 1); free($1); }
480 void conf_parse(const char *name)
482 struct symbol *sym;
483 int i;
485 zconf_initscan(name);
487 sym_init();
488 menu_init();
489 modules_sym = sym_lookup("MODULES", 0);
490 rootmenu.prompt = menu_add_prop(P_MENU, "Linux Kernel Configuration", NULL, NULL);
492 //zconfdebug = 1;
493 zconfparse();
494 if (zconfnerrs)
495 exit(1);
496 menu_finalize(&rootmenu);
497 for_all_symbols(i, sym) {
498 if (!(sym->flags & SYMBOL_CHECKED) && sym_check_deps(sym))
499 printf("\n");
500 else
501 sym->flags |= SYMBOL_CHECK_DONE;
504 sym_change_count = 1;
507 const char *zconf_tokenname(int token)
509 switch (token) {
510 case T_MENU: return "menu";
511 case T_ENDMENU: return "endmenu";
512 case T_CHOICE: return "choice";
513 case T_ENDCHOICE: return "endchoice";
514 case T_IF: return "if";
515 case T_ENDIF: return "endif";
517 return "<token>";
520 static bool zconf_endtoken(int token, int starttoken, int endtoken)
522 if (token != endtoken) {
523 zconfprint("unexpected '%s' within %s block", zconf_tokenname(token), zconf_tokenname(starttoken));
524 zconfnerrs++;
525 return false;
527 if (current_menu->file != current_file) {
528 zconfprint("'%s' in different file than '%s'", zconf_tokenname(token), zconf_tokenname(starttoken));
529 zconfprint("location of the '%s'", zconf_tokenname(starttoken));
530 zconfnerrs++;
531 return false;
533 return true;
536 static void zconfprint(const char *err, ...)
538 va_list ap;
540 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno() + 1);
541 va_start(ap, err);
542 vfprintf(stderr, err, ap);
543 va_end(ap);
544 fprintf(stderr, "\n");
547 static void zconferror(const char *err)
549 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
552 void print_quoted_string(FILE *out, const char *str)
554 const char *p;
555 int len;
557 putc('"', out);
558 while ((p = strchr(str, '"'))) {
559 len = p - str;
560 if (len)
561 fprintf(out, "%.*s", len, str);
562 fputs("\\\"", out);
563 str = p + 1;
565 fputs(str, out);
566 putc('"', out);
569 void print_symbol(FILE *out, struct menu *menu)
571 struct symbol *sym = menu->sym;
572 struct property *prop;
574 if (sym_is_choice(sym))
575 fprintf(out, "choice\n");
576 else
577 fprintf(out, "config %s\n", sym->name);
578 switch (sym->type) {
579 case S_BOOLEAN:
580 fputs(" boolean\n", out);
581 break;
582 case S_TRISTATE:
583 fputs(" tristate\n", out);
584 break;
585 case S_STRING:
586 fputs(" string\n", out);
587 break;
588 case S_INT:
589 fputs(" integer\n", out);
590 break;
591 case S_HEX:
592 fputs(" hex\n", out);
593 break;
594 default:
595 fputs(" ???\n", out);
596 break;
598 for (prop = sym->prop; prop; prop = prop->next) {
599 if (prop->menu != menu)
600 continue;
601 switch (prop->type) {
602 case P_PROMPT:
603 fputs(" prompt ", out);
604 print_quoted_string(out, prop->text);
605 if (!expr_is_yes(prop->visible.expr)) {
606 fputs(" if ", out);
607 expr_fprint(prop->visible.expr, out);
609 fputc('\n', out);
610 break;
611 case P_DEFAULT:
612 fputs( " default ", out);
613 expr_fprint(prop->expr, out);
614 if (!expr_is_yes(prop->visible.expr)) {
615 fputs(" if ", out);
616 expr_fprint(prop->visible.expr, out);
618 fputc('\n', out);
619 break;
620 case P_CHOICE:
621 fputs(" #choice value\n", out);
622 break;
623 default:
624 fprintf(out, " unknown prop %d!\n", prop->type);
625 break;
628 if (sym->help) {
629 int len = strlen(sym->help);
630 while (sym->help[--len] == '\n')
631 sym->help[len] = 0;
632 fprintf(out, " help\n%s\n", sym->help);
634 fputc('\n', out);
637 void zconfdump(FILE *out)
639 struct property *prop;
640 struct symbol *sym;
641 struct menu *menu;
643 menu = rootmenu.list;
644 while (menu) {
645 if ((sym = menu->sym))
646 print_symbol(out, menu);
647 else if ((prop = menu->prompt)) {
648 switch (prop->type) {
649 case P_COMMENT:
650 fputs("\ncomment ", out);
651 print_quoted_string(out, prop->text);
652 fputs("\n", out);
653 break;
654 case P_MENU:
655 fputs("\nmenu ", out);
656 print_quoted_string(out, prop->text);
657 fputs("\n", out);
658 break;
659 default:
662 if (!expr_is_yes(prop->visible.expr)) {
663 fputs(" depends ", out);
664 expr_fprint(prop->visible.expr, out);
665 fputc('\n', out);
667 fputs("\n", out);
670 if (menu->list)
671 menu = menu->list;
672 else if (menu->next)
673 menu = menu->next;
674 else while ((menu = menu->parent)) {
675 if (menu->prompt && menu->prompt->type == P_MENU)
676 fputs("\nendmenu\n", out);
677 if (menu->next) {
678 menu = menu->next;
679 break;
685 #include "lex.zconf.c"
686 #include "util.c"
687 #include "confdata.c"
688 #include "expr.c"
689 #include "symbol.c"
690 #include "menu.c"