提交 979f2b2f 编写于 作者: M Masahiro Yamada

kconfig: remove keyword lookup table entirely

Commit 7a88488b ("[PATCH] kconfig: use gperf for kconfig keywords")
introduced gperf for the keyword lookup.

Then, commit bb3290d9 ("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.
Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
上级 4b31a32c
static struct kconf_id kconf_id_array[] = {
{ "mainmenu", T_MAINMENU, TF_COMMAND },
{ "menu", T_MENU, TF_COMMAND },
{ "endmenu", T_ENDMENU, TF_COMMAND },
{ "source", T_SOURCE, TF_COMMAND },
{ "choice", T_CHOICE, TF_COMMAND },
{ "endchoice", T_ENDCHOICE, TF_COMMAND },
{ "comment", T_COMMENT, TF_COMMAND },
{ "config", T_CONFIG, TF_COMMAND },
{ "menuconfig", T_MENUCONFIG, TF_COMMAND },
{ "help", T_HELP, TF_COMMAND },
{ "---help---", T_HELP, TF_COMMAND },
{ "if", T_IF, TF_COMMAND|TF_PARAM },
{ "endif", T_ENDIF, TF_COMMAND },
{ "depends", T_DEPENDS, TF_COMMAND },
{ "optional", T_OPTIONAL, TF_COMMAND },
{ "default", T_DEFAULT, TF_COMMAND },
{ "def_bool", T_DEF_BOOL, TF_COMMAND },
{ "def_tristate", T_DEF_TRISTATE, TF_COMMAND },
{ "prompt", T_PROMPT, TF_COMMAND },
{ "bool", T_BOOL, TF_COMMAND },
{ "tristate", T_TRISTATE, TF_COMMAND },
{ "int", T_INT, TF_COMMAND },
{ "hex", T_HEX, TF_COMMAND },
{ "string", T_STRING, TF_COMMAND },
{ "select", T_SELECT, TF_COMMAND },
{ "imply", T_IMPLY, TF_COMMAND },
{ "range", T_RANGE, TF_COMMAND },
{ "visible", T_VISIBLE, TF_COMMAND },
{ "option", T_OPTION, TF_COMMAND },
{ "on", T_ON, TF_PARAM },
};
#define KCONF_ID_ARRAY_SIZE (sizeof(kconf_id_array)/sizeof(struct kconf_id))
static const struct kconf_id *kconf_id_lookup(register const char *str, register unsigned int len)
{
int i;
for (i = 0; i < KCONF_ID_ARRAY_SIZE; i++) {
struct kconf_id *id = kconf_id_array+i;
int l = strlen(id->name);
if (len == l && !memcmp(str, id->name, len))
return id;
}
return NULL;
}
...@@ -30,9 +30,6 @@ static inline const char *CONFIG_prefix(void) ...@@ -30,9 +30,6 @@ static inline const char *CONFIG_prefix(void)
#undef CONFIG_ #undef CONFIG_
#define CONFIG_ CONFIG_prefix() #define CONFIG_ CONFIG_prefix()
#define TF_COMMAND 0x0001
#define TF_PARAM 0x0002
enum conf_def_mode { enum conf_def_mode {
def_default, def_default,
def_yes, def_yes,
...@@ -41,12 +38,6 @@ enum conf_def_mode { ...@@ -41,12 +38,6 @@ enum conf_def_mode {
def_random def_random
}; };
struct kconf_id {
const char *name;
int token;
unsigned int flags;
};
extern int yylineno; extern int yylineno;
void zconfdump(FILE *out); void zconfdump(FILE *out);
void zconf_starthelp(void); void zconf_starthelp(void);
......
%option nostdinit noyywrap never-interactive full ecs %option nostdinit noyywrap never-interactive full ecs
%option 8bit nodefault yylineno %option 8bit nodefault yylineno
%x COMMAND HELP STRING PARAM ASSIGN_VAL %x ASSIGN_VAL HELP STRING
%{ %{
/* /*
* Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
...@@ -87,45 +87,73 @@ n [A-Za-z0-9_-] ...@@ -87,45 +87,73 @@ n [A-Za-z0-9_-]
int str = 0; int str = 0;
int ts, i; int ts, i;
[ \t]*#.*\n | #.* /* ignore comment */
[ \t]*\n { [ \t]* /* whitespaces */
return T_EOL; \\\n /* escaped new line */
} \n return T_EOL;
[ \t]*#.* "allnoconfig_y" return T_ALLNOCONFIG_Y;
. { "bool" return T_BOOL;
unput(yytext[0]); "choice" return T_CHOICE;
BEGIN(COMMAND); "comment" return T_COMMENT;
} "config" return T_CONFIG;
"def_bool" return T_DEF_BOOL;
"def_tristate" return T_DEF_TRISTATE;
<COMMAND>{ "default" return T_DEFAULT;
{n}+ { "defconfig_list" return T_DEFCONFIG_LIST;
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); "depends" return T_DEPENDS;
if (id && id->flags & TF_COMMAND) { "endchoice" return T_ENDCHOICE;
BEGIN(PARAM); "endif" return T_ENDIF;
return id->token; "endmenu" return T_ENDMENU;
} "help"|"---help---" return T_HELP;
alloc_string(yytext, yyleng); "hex" return T_HEX;
yylval.string = text; "if" return T_IF;
return T_WORD; "imply" return T_IMPLY;
} "int" return T_INT;
({n}|$)+ { "mainmenu" return T_MAINMENU;
/* this token includes at least one '$' */ "menu" return T_MENU;
yylval.string = expand_token(yytext, yyleng); "menuconfig" return T_MENUCONFIG;
if (strlen(yylval.string)) "modules" return T_MODULES;
return T_WORD; "on" return T_ON;
free(yylval.string); "option" return T_OPTION;
} "optional" return T_OPTIONAL;
"=" return T_EQUAL; "prompt" return T_PROMPT;
":=" return T_COLON_EQUAL; "range" return T_RANGE;
"+=" return T_PLUS_EQUAL; "select" return T_SELECT;
[[:blank:]]+ "source" return T_SOURCE;
. warn_ignored_character(*yytext); "string" return T_STRING;
\n { "tristate" return T_TRISTATE;
BEGIN(INITIAL); "visible" return T_VISIBLE;
return T_EOL; "||" return T_OR;
} "&&" return T_AND;
} "=" return T_EQUAL;
"!=" return T_UNEQUAL;
"<" return T_LESS;
"<=" return T_LESS_EQUAL;
">" return T_GREATER;
">=" return T_GREATER_EQUAL;
"!" return T_NOT;
"(" return T_OPEN_PAREN;
")" return T_CLOSE_PAREN;
":=" return T_COLON_EQUAL;
"+=" return T_PLUS_EQUAL;
\"|\' {
str = yytext[0];
new_string();
BEGIN(STRING);
}
{n}+ {
alloc_string(yytext, yyleng);
yylval.string = text;
return T_WORD;
}
({n}|$)+ {
/* this token includes at least one '$' */
yylval.string = expand_token(yytext, yyleng);
if (strlen(yylval.string))
return T_WORD;
free(yylval.string);
}
. warn_ignored_character(*yytext);
<ASSIGN_VAL>{ <ASSIGN_VAL>{
[^[:blank:]\n]+.* { [^[:blank:]\n]+.* {
...@@ -137,49 +165,6 @@ n [A-Za-z0-9_-] ...@@ -137,49 +165,6 @@ n [A-Za-z0-9_-]
. .
} }
<PARAM>{
"modules" return T_MODULES;
"defconfig_list" return T_DEFCONFIG_LIST;
"allnoconfig_y" return T_ALLNOCONFIG_Y;
"&&" return T_AND;
"||" return T_OR;
"(" return T_OPEN_PAREN;
")" return T_CLOSE_PAREN;
"!" return T_NOT;
"=" return T_EQUAL;
"!=" return T_UNEQUAL;
"<=" return T_LESS_EQUAL;
">=" return T_GREATER_EQUAL;
"<" return T_LESS;
">" return T_GREATER;
\"|\' {
str = yytext[0];
new_string();
BEGIN(STRING);
}
\n BEGIN(INITIAL); return T_EOL;
{n}+ {
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
if (id && id->flags & TF_PARAM) {
return id->token;
}
alloc_string(yytext, yyleng);
yylval.string = text;
return T_WORD;
}
({n}|$)+ {
/* this token includes at least one '$' */
yylval.string = expand_token(yytext, yyleng);
if (strlen(yylval.string))
return T_WORD;
free(yylval.string);
}
#.* /* comment */
\\\n ;
[[:blank:]]+
. warn_ignored_character(*yytext);
}
<STRING>{ <STRING>{
"$".* append_expanded_string(yytext); "$".* append_expanded_string(yytext);
[^$'"\\\n]+ { [^$'"\\\n]+ {
...@@ -190,7 +175,7 @@ n [A-Za-z0-9_-] ...@@ -190,7 +175,7 @@ n [A-Za-z0-9_-]
} }
\'|\" { \'|\" {
if (str == yytext[0]) { if (str == yytext[0]) {
BEGIN(PARAM); BEGIN(INITIAL);
yylval.string = text; yylval.string = text;
return T_WORD_QUOTE; return T_WORD_QUOTE;
} else } else
......
...@@ -110,11 +110,6 @@ static struct menu *current_menu, *current_entry; ...@@ -110,11 +110,6 @@ static struct menu *current_menu, *current_entry;
menu_end_menu(); menu_end_menu();
} if_entry menu_entry choice_entry } if_entry menu_entry choice_entry
%{
/* Include kconf_id.c here so it can see the token constants. */
#include "kconf_id.c"
%}
%% %%
input: mainmenu_stmt stmt_list | stmt_list; input: mainmenu_stmt stmt_list | stmt_list;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册