History

kconfig: remove keyword lookup table entirely

Commit 7a88488bbc23 ("[PATCH] kconfig: use gperf for kconfig keywords") introduced gperf for the keyword lookup. Then, commit bb3290d91695 ("Remove gperf usage from toolchain") killed the gperf use. As a result, the linear keyword search was left behind. If we do not use gperf, there is no reason to have the separate table of the keywords. Move all keywords back to the lexer. I also refactored the lexer to remove the COMMAND and PARAM states.

Masahiro Yamada committed 7 years ago

Commit 979f2b21 parent 4b31a324 files · +69 −147Browse files

Unified · Split

4 files
  1. scripts/kconfig/kconf_id.c +0 −49
  2. scripts/kconfig/lkc.h +0 −9
  3. scripts/kconfig/zconf.l +69 −84
  4. scripts/kconfig/zconf.y +0 −5
scripts/kconfig/kconf_id.c+0−49
@@ -1,49 +0,0 @@
1−
2−static struct kconf_id kconf_id_array[] = {
3− { "mainmenu", T_MAINMENU, TF_COMMAND },
4− { "menu", T_MENU, TF_COMMAND },
5− { "endmenu", T_ENDMENU, TF_COMMAND },
6− { "source", T_SOURCE, TF_COMMAND },
7− { "choice", T_CHOICE, TF_COMMAND },
8− { "endchoice", T_ENDCHOICE, TF_COMMAND },
9− { "comment", T_COMMENT, TF_COMMAND },
10− { "config", T_CONFIG, TF_COMMAND },
11− { "menuconfig", T_MENUCONFIG, TF_COMMAND },
12− { "help", T_HELP, TF_COMMAND },
13− { "---help---", T_HELP, TF_COMMAND },
14− { "if", T_IF, TF_COMMAND|TF_PARAM },
15− { "endif", T_ENDIF, TF_COMMAND },
16− { "depends", T_DEPENDS, TF_COMMAND },
17− { "optional", T_OPTIONAL, TF_COMMAND },
18− { "default", T_DEFAULT, TF_COMMAND },
19− { "def_bool", T_DEF_BOOL, TF_COMMAND },
20− { "def_tristate", T_DEF_TRISTATE, TF_COMMAND },
21− { "prompt", T_PROMPT, TF_COMMAND },
22− { "bool", T_BOOL, TF_COMMAND },
23− { "tristate", T_TRISTATE, TF_COMMAND },
24− { "int", T_INT, TF_COMMAND },
25− { "hex", T_HEX, TF_COMMAND },
26− { "string", T_STRING, TF_COMMAND },
27− { "select", T_SELECT, TF_COMMAND },
28− { "imply", T_IMPLY, TF_COMMAND },
29− { "range", T_RANGE, TF_COMMAND },
30− { "visible", T_VISIBLE, TF_COMMAND },
31− { "option", T_OPTION, TF_COMMAND },
32− { "on", T_ON, TF_PARAM },
33−};
34−
35−#define KCONF_ID_ARRAY_SIZE (sizeof(kconf_id_array)/sizeof(struct kconf_id))
36−
37−static const struct kconf_id *kconf_id_lookup(register const char *str, register unsigned int len)
38−{
39− int i;
40−
41− for (i = 0; i < KCONF_ID_ARRAY_SIZE; i++) {
42− struct kconf_id *id = kconf_id_array+i;
43− int l = strlen(id->name);
44−
45− if (len == l && !memcmp(str, id->name, len))
46− return id;
47− }
48− return NULL;
49−}
scripts/kconfig/lkc.h+0−9
@@ -30,9 +30,6 @@ static inline const char *CONFIG_prefix(void) · 29 unmodified lines
3030 #undef CONFIG_
3131 #define CONFIG_ CONFIG_prefix()
3232
33−#define TF_COMMAND 0x0001
34−#define TF_PARAM 0x0002
35−
3633 enum conf_def_mode {
3734 def_default,
3835 def_yes,
@@ -41,12 +38,6 @@ enum conf_def_mode { · 2 unmodified lines
4138 def_random
4239 };
4340
44−struct kconf_id {
45− const char *name;
46− int token;
47− unsigned int flags;
48−};
49−
5041 extern int yylineno;
5142 void zconfdump(FILE *out);
5243 void zconf_starthelp(void);
scripts/kconfig/zconf.l+69−84
@@ -1,6 +1,6 @@
11 %option nostdinit noyywrap never-interactive full ecs
22 %option 8bit nodefault yylineno
3−%x COMMAND HELP STRING PARAM ASSIGN_VAL
3+%x ASSIGN_VAL HELP STRING
44 %{
55 /*
66 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
@@ -87,45 +87,73 @@ n [A-Za-z0-9_-] · 80 unmodified lines
8787 int str = 0;
8888 int ts, i;
8989
90−[ \t]*#.*\n |
91−[ \t]*\n {
92− return T_EOL;
93−}
94−[ \t]*#.*
95−. {
96− unput(yytext[0]);
97− BEGIN(COMMAND);
98−}
99−
100−
101−<COMMAND>{
102− {n}+ {
103− const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
104− if (id && id->flags & TF_COMMAND) {
105− BEGIN(PARAM);
106− return id->token;
107− }
108− alloc_string(yytext, yyleng);
109− yylval.string = text;
110− return T_WORD;
111− }
112− ({n}|$)+ {
113− /* this token includes at least one '$' */
114− yylval.string = expand_token(yytext, yyleng);
115− if (strlen(yylval.string))
116− return T_WORD;
117− free(yylval.string);
118− }
119− "=" return T_EQUAL;
120− ":=" return T_COLON_EQUAL;
121− "+=" return T_PLUS_EQUAL;
122− [[:blank:]]+
123− . warn_ignored_character(*yytext);
124− \n {
125− BEGIN(INITIAL);
126− return T_EOL;
127− }
128−}
90+#.* /* ignore comment */
91+[ \t]* /* whitespaces */
92+\\\n /* escaped new line */
93+\n return T_EOL;
94+"allnoconfig_y" return T_ALLNOCONFIG_Y;
95+"bool" return T_BOOL;
96+"choice" return T_CHOICE;
97+"comment" return T_COMMENT;
98+"config" return T_CONFIG;
99+"def_bool" return T_DEF_BOOL;
100+"def_tristate" return T_DEF_TRISTATE;
101+"default" return T_DEFAULT;
102+"defconfig_list" return T_DEFCONFIG_LIST;
103+"depends" return T_DEPENDS;
104+"endchoice" return T_ENDCHOICE;
105+"endif" return T_ENDIF;
106+"endmenu" return T_ENDMENU;
107+"help"|"---help---" return T_HELP;
108+"hex" return T_HEX;
109+"if" return T_IF;
110+"imply" return T_IMPLY;
111+"int" return T_INT;
112+"mainmenu" return T_MAINMENU;
113+"menu" return T_MENU;
114+"menuconfig" return T_MENUCONFIG;
115+"modules" return T_MODULES;
116+"on" return T_ON;
117+"option" return T_OPTION;
118+"optional" return T_OPTIONAL;
119+"prompt" return T_PROMPT;
120+"range" return T_RANGE;
121+"select" return T_SELECT;
122+"source" return T_SOURCE;
123+"string" return T_STRING;
124+"tristate" return T_TRISTATE;
125+"visible" return T_VISIBLE;
126+"||" return T_OR;
127+"&&" return T_AND;
128+"=" return T_EQUAL;
129+"!=" return T_UNEQUAL;
130+"<" return T_LESS;
131+"<=" return T_LESS_EQUAL;
132+">" return T_GREATER;
133+">=" return T_GREATER_EQUAL;
134+"!" return T_NOT;
135+"(" return T_OPEN_PAREN;
136+")" return T_CLOSE_PAREN;
137+":=" return T_COLON_EQUAL;
138+"+=" return T_PLUS_EQUAL;
139+\"|\' {
140+ str = yytext[0];
141+ new_string();
142+ BEGIN(STRING);
143+ }
144+{n}+ {
145+ alloc_string(yytext, yyleng);
146+ yylval.string = text;
147+ return T_WORD;
148+ }
149+({n}|$)+ {
150+ /* this token includes at least one '$' */
151+ yylval.string = expand_token(yytext, yyleng);
152+ if (strlen(yylval.string))
153+ return T_WORD;
154+ free(yylval.string);
155+ }
156+. warn_ignored_character(*yytext);
129157
130158 <ASSIGN_VAL>{
131159 [^[:blank:]\n]+.* {
@@ -137,49 +165,6 @@ n [A-Za-z0-9_-] · 5 unmodified lines
137165 .
138166 }
139167
140−<PARAM>{
141− "modules" return T_MODULES;
142− "defconfig_list" return T_DEFCONFIG_LIST;
143− "allnoconfig_y" return T_ALLNOCONFIG_Y;
144− "&&" return T_AND;
145− "||" return T_OR;
146− "(" return T_OPEN_PAREN;
147− ")" return T_CLOSE_PAREN;
148− "!" return T_NOT;
149− "=" return T_EQUAL;
150− "!=" return T_UNEQUAL;
151− "<=" return T_LESS_EQUAL;
152− ">=" return T_GREATER_EQUAL;
153− "<" return T_LESS;
154− ">" return T_GREATER;
155− \"|\' {
156− str = yytext[0];
157− new_string();
158− BEGIN(STRING);
159− }
160− \n BEGIN(INITIAL); return T_EOL;
161− {n}+ {
162− const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
163− if (id && id->flags & TF_PARAM) {
164− return id->token;
165− }
166− alloc_string(yytext, yyleng);
167− yylval.string = text;
168− return T_WORD;
169− }
170− ({n}|$)+ {
171− /* this token includes at least one '$' */
172− yylval.string = expand_token(yytext, yyleng);
173− if (strlen(yylval.string))
174− return T_WORD;
175− free(yylval.string);
176− }
177− #.* /* comment */
178− \\\n ;
179− [[:blank:]]+
180− . warn_ignored_character(*yytext);
181−}
182−
183168 <STRING>{
184169 "$".* append_expanded_string(yytext);
185170 [^$'"\\\n]+ {
@@ -190,7 +175,7 @@ n [A-Za-z0-9_-] · 4 unmodified lines
190175 }
191176 \'|\" {
192177 if (str == yytext[0]) {
193− BEGIN(PARAM);
178+ BEGIN(INITIAL);
194179 yylval.string = text;
195180 return T_WORD_QUOTE;
196181 } else
scripts/kconfig/zconf.y+0−5
@@ -110,11 +110,6 @@ static struct menu *current_menu, *current_entry; · 109 unmodified lines
110110 menu_end_menu();
111111 } if_entry menu_entry choice_entry
112112
113−%{
114−/* Include kconf_id.c here so it can see the token constants. */
115−#include "kconf_id.c"
116−%}
117−
118113 %%
119114 input: mainmenu_stmt stmt_list | stmt_list;
120115