When I tryed to change something, I was often hit by annoying
shift/reduce conflicts in the parser.
The lexer and parser are too cluttered.
So, I decided to clean-up now.
- Fix all shift/reduce conflicts in the parser
- Rewrite the lexer. The linear keyword search was removed.
The number of states descreased from 6 to 4.
- Fix various subtle issues
Masahiro Yamada (27):
kconfig: fix file name and line number of warn_ignored_character()
kconfig: fix memory leak when EOF is encountered in quotation
kconfig: require T_EOL to reduce visible statement
kconfig: remove unneeded pattern matching to whitespaces
kconfig: refactor pattern matching in STRING state
kconfig: fix ambiguous grammar in terms of new lines
kconfig: clean up EOF handling in the lexer
kconfig: warn no new line at end of file
kconfig: remove grammatically ambiguous "unexpected option" diagnostic
kconfig: remove grammatically ambiguous option_error
kconfig: remove redundant if_block rule
kconfig: remove redundant menu_block rule
kconfig: loosen the order of "visible" and "depends on" in menu entry
kconfig: rename depends_list to comment_option_list
kconfig: remove redundant token defines
kconfig: use distinct tokens for type and default properties
kconfig: refactor scanning and parsing "option" properties
kconfig: use specific tokens instead of T_ASSIGN for assignments
kconfig: use T_WORD instead of T_VARIABLE for variables
microblaze: surround string default in Kconfig with double quotes
treewide: surround file paths in Kconfig files with double quotes
kconfig: ban the use of '.' and '/' in unquoted words
kconfig: refactor end token rules
kconfig: stop associating kconf_id with yylval
kconfig: switch to ASSIGN_VAL state in the second lexer
kconfig: update current_pos in the second lexer
kconfig: remove keyword lookup table entirely
arch/arm/Kconfig | 2 +-
arch/arm/kvm/Kconfig | 2 +-
arch/arm64/Kconfig | 2 +-
arch/arm64/kvm/Kconfig | 2 +-
arch/ia64/Kconfig | 2 +-
arch/m68k/Kconfig | 6 +-
arch/microblaze/Kconfig.platform | 2 +-
arch/mips/kvm/Kconfig | 2 +-
arch/openrisc/Kconfig | 2 +-
arch/powerpc/Kconfig | 4 +-
arch/powerpc/kvm/Kconfig | 2 +-
arch/riscv/Kconfig | 2 +-
arch/s390/Kconfig | 2 +-
arch/s390/kvm/Kconfig | 2 +-
arch/sh/Kconfig | 2 +-
arch/sparc/Kconfig | 2 +-
arch/x86/Kconfig | 2 +-
arch/x86/kvm/Kconfig | 2 +-
block/Kconfig | 2 +-
crypto/Kconfig | 4 +-
drivers/crypto/Kconfig | 2 +-
drivers/gpu/drm/i915/Kconfig | 2 +-
drivers/hwmon/Kconfig | 2 +-
drivers/i2c/Kconfig | 6 +-
drivers/pps/Kconfig | 4 +-
drivers/ras/Kconfig | 2 +-
drivers/thermal/Kconfig | 2 +-
drivers/w1/Kconfig | 4 +-
kernel/Kconfig.preempt | 2 +-
lib/Kconfig.debug | 4 +-
scripts/kconfig/kconf_id.c | 52 --------
scripts/kconfig/lkc.h | 19 +--
scripts/kconfig/menu.c | 43 +++---
scripts/kconfig/preprocess.c | 3 +-
scripts/kconfig/zconf.l | 232 +++++++++++++++++---------------
scripts/kconfig/zconf.y | 280 ++++++++++++++++-----------------------
security/Kconfig | 16 +--
security/integrity/Kconfig | 4 +-
38 files changed, 313 insertions(+), 414 deletions(-)
delete mode 100644 scripts/kconfig/kconf_id.c
--
2.7.4
I guess this is a constant value instead of a symbol.
Signed-off-by: Masahiro Yamada <[email protected]>
---
I will apply this to my Kbuild tree
because it is necessary for Kconfig clean-ups.
arch/microblaze/Kconfig.platform | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/microblaze/Kconfig.platform b/arch/microblaze/Kconfig.platform
index f7f1739..7361974 100644
--- a/arch/microblaze/Kconfig.platform
+++ b/arch/microblaze/Kconfig.platform
@@ -65,6 +65,6 @@ config XILINX_MICROBLAZE0_USE_FPU
config XILINX_MICROBLAZE0_HW_VER
string "Core version number"
- default 7.10.d
+ default "7.10.d"
endmenu
--
2.7.4
T_ENDMENU, T_ENDCHOICE, T_ENDIF are the last users of kconf_id
associated with yylval. Refactor them to not use it.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 43 +++++++++++++++----------------------------
1 file changed, 15 insertions(+), 28 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 3c44d67..36cffc0 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -24,7 +24,8 @@ int yylex(void);
static void yyerror(const char *err);
static void zconfprint(const char *err, ...);
static void zconf_error(const char *err, ...);
-static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken);
+static bool zconf_endtoken(const char *tokenname,
+ const char *expected_tokenname);
struct symbol *symbol_hash[SYMBOL_HASHSIZE];
@@ -98,7 +99,7 @@ static struct menu *current_menu, *current_entry;
%type <type> type bool_or_tri default
%type <expr> expr
%type <expr> if_expr
-%type <id> end
+%type <string> end
%type <menu> if_entry menu_entry choice_entry
%type <string> word_opt assign_val
%type <flavor> assign_op
@@ -256,7 +257,7 @@ choice_entry: choice choice_option_list
choice_end: end
{
- if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
+ if (zconf_endtoken($1, "choice")) {
menu_end_menu();
printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
}
@@ -330,7 +331,7 @@ if_entry: T_IF expr T_EOL
if_end: end
{
- if (zconf_endtoken($1, T_IF, T_ENDIF)) {
+ if (zconf_endtoken($1, "if")) {
menu_end_menu();
printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
}
@@ -355,7 +356,7 @@ menu_entry: menu menu_option_list
menu_end: end
{
- if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
+ if (zconf_endtoken($1, "menu")) {
menu_end_menu();
printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
}
@@ -445,9 +446,9 @@ prompt: T_WORD
| T_WORD_QUOTE
;
-end: T_ENDMENU T_EOL { $$ = $1; }
- | T_ENDCHOICE T_EOL { $$ = $1; }
- | T_ENDIF T_EOL { $$ = $1; }
+end: T_ENDMENU T_EOL { $$ = "menu"; }
+ | T_ENDCHOICE T_EOL { $$ = "choice"; }
+ | T_ENDIF T_EOL { $$ = "if"; }
;
if_expr: /* empty */ { $$ = NULL; }
@@ -530,35 +531,21 @@ void conf_parse(const char *name)
sym_set_change_count(1);
}
-static const char *zconf_tokenname(int token)
-{
- switch (token) {
- case T_MENU: return "menu";
- case T_ENDMENU: return "endmenu";
- case T_CHOICE: return "choice";
- case T_ENDCHOICE: return "endchoice";
- case T_IF: return "if";
- case T_ENDIF: return "endif";
- case T_DEPENDS: return "depends";
- case T_VISIBLE: return "visible";
- }
- return "<token>";
-}
-
-static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
+static bool zconf_endtoken(const char *tokenname,
+ const char *expected_tokenname)
{
- if (id->token != endtoken) {
+ if (strcmp(tokenname, expected_tokenname)) {
zconf_error("unexpected '%s' within %s block",
- id->name, zconf_tokenname(starttoken));
+ tokenname, expected_tokenname);
yynerrs++;
return false;
}
if (current_menu->file != current_file) {
zconf_error("'%s' in different file than '%s'",
- id->name, zconf_tokenname(starttoken));
+ tokenname, expected_tokenname);
fprintf(stderr, "%s:%d: location of the '%s'\n",
current_menu->file->name, current_menu->lineno,
- zconf_tokenname(starttoken));
+ expected_tokenname);
yynerrs++;
return false;
}
--
2.7.4
An unterminated string literal followed by new line is passed to the
parser (with "multi-line strings not supported" warning shown), then
handled properly there.
On the other hand, an unterminated string literal at end of file is
never passed to the parser, then results in memory leak.
[Test Code]
----------(Kconfig begin)----------
source "Kconfig.inc"
config A
bool "a"
-----------(Kconfig end)-----------
--------(Kconfig.inc begin)--------
config B
bool "b\No new line at end of file
---------(Kconfig.inc end)---------
[Summary from Valgrind]
Before the fix:
LEAK SUMMARY:
definitely lost: 16 bytes in 1 blocks
...
After the fix:
LEAK SUMMARY:
definitely lost: 0 bytes in 0 blocks
...
Eliminate the memory leak path by handling this case. Of course, such
a Kconfig file is wrong already, so I will add an error message later.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 2 ++
1 file changed, 2 insertions(+)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index eeac64c..c2f577d 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -221,6 +221,8 @@ n [A-Za-z0-9_-]
}
<<EOF>> {
BEGIN(INITIAL);
+ yylval.string = text;
+ return T_WORD_QUOTE;
}
}
--
2.7.4
To simplify the generated lexer, let the hand-made lexer update the
file name and line number for the parser.
I tested this with DEBUG_PARSE, and confirmed the same file names
and line numbers were dumped.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index d462507..f0734abe 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -108,8 +108,6 @@ n [A-Za-z0-9_-]
<COMMAND>{
{n}+ {
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
- current_pos.file = current_file;
- current_pos.lineno = yylineno;
if (id && id->flags & TF_COMMAND) {
BEGIN(PARAM);
return id->token;
@@ -291,9 +289,21 @@ int yylex(void)
repeat:
token = yylex1();
- /* Do not pass unneeded T_EOL to the parser. */
- if ((prev_token == T_EOL || prev_token == T_HELPTEXT) && token == T_EOL)
- goto repeat;
+ if (prev_token == T_EOL || prev_token == T_HELPTEXT) {
+ if (token == T_EOL) {
+ /* Do not pass unneeded T_EOL to the parser. */
+ goto repeat;
+ } else {
+ /*
+ * For the parser, update file/lineno at the first token
+ * of each statement. Generally, \n is a statement
+ * terminator in Kconfig, but it is not always true
+ * because \n could be escaped by a backslash.
+ */
+ current_pos.file = current_file;
+ current_pos.lineno = yylineno;
+ }
+ }
if (prev_prev_token == T_EOL && prev_token == T_WORD &&
(token == T_EQUAL || token == T_COLON_EQUAL || token == T_PLUS_EQUAL))
--
2.7.4
This commit decreases 6 shift/reduce conflicts, and finally achieves
conflict-free parser.
Since Kconfig has no terminator for a config block, detecting the end
of config_stmt is not easy.
For example, there are two ways for handling the error in the following
code:
1 config FOO
2 =
[A] Print "unknown option" error, assuming the line 2 is a part of
config_option_list
[B] Print "invalid statement", assuming the line 1 is reduced into
a config_stmt by itself
Bison actually chooses [A] because it performs the shift rather than
the reduction where both are possible.
However, there is no reason to choose one over the other since the
code above can be written as follows:
1 config FOO
2
3 =
Remove the option_error, and let it fall back to [B].
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index cef6123..a92f167 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -31,7 +31,6 @@ struct symbol *symbol_hash[SYMBOL_HASHSIZE];
static struct menu *current_menu, *current_entry;
%}
-%expect 6
%union
{
@@ -138,12 +137,6 @@ common_stmt:
| assignment_stmt
;
-option_error:
- T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
- | error T_EOL { zconf_error("invalid option"); }
-;
-
-
/* config/menuconfig entry */
config_entry_start: T_CONFIG nonconst_symbol T_EOL
@@ -180,7 +173,6 @@ config_option_list:
| config_option_list symbol_option
| config_option_list depends
| config_option_list help
- | config_option_list option_error
;
config_option: T_TYPE prompt_stmt_opt T_EOL
@@ -280,7 +272,6 @@ choice_option_list:
| choice_option_list choice_option
| choice_option_list depends
| choice_option_list help
- | choice_option_list option_error
;
choice_option: T_PROMPT prompt if_expr T_EOL
@@ -429,7 +420,6 @@ help: help_start T_HELPTEXT
depends_list:
/* empty */
| depends_list depends
- | depends_list option_error
;
depends: T_DEPENDS T_ON expr T_EOL
--
2.7.4
This commit decreases 15 shift/reduce conflicts.
The location of this error recovery is ambiguous.
For example, there are two ways to interpret the following code:
1 config FOO
2 bool "foo"
[A] Both lines are reduced together into a config_stmt.
[B] The only line 1 is reduced into a config_stmt, and the line 2
matches to "option_name error T_EOL"
Of course, we expect [A], but [B] could be grammatically possible.
Kconfig has no terminator for a config block. So, we cannot detect its
end until we see non-property keywords. People often insert a blank
line between two config blocks, but it is just a coding convention.
Blank lines are actually allowed anywhere in Kconfig files.
The real error is when a property keyword appears right after "endif",
"endchoice", "endmenu", "source", "comment", or variable assignments.
Instead of fixing the grammatical ambiguity, I chose to simply remove
this error recovery.
The difference is
unexpected option "bool"
... is turned into a more generic message:
invalid statement
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 02bfc62..cef6123 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -31,7 +31,7 @@ struct symbol *symbol_hash[SYMBOL_HASHSIZE];
static struct menu *current_menu, *current_entry;
%}
-%expect 21
+%expect 6
%union
{
@@ -94,7 +94,6 @@ static struct menu *current_menu, *current_entry;
%type <expr> expr
%type <expr> if_expr
%type <id> end
-%type <id> option_name
%type <menu> if_entry menu_entry choice_entry
%type <string> symbol_option_arg word_opt assign_val
@@ -127,17 +126,9 @@ stmt_list:
| stmt_list menu_stmt
| stmt_list end { zconf_error("unexpected end statement"); }
| stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
- | stmt_list option_name error T_EOL
-{
- zconf_error("unexpected option \"%s\"", $2->name);
-}
| stmt_list error T_EOL { zconf_error("invalid statement"); }
;
-option_name:
- T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
-;
-
common_stmt:
if_stmt
| comment_stmt
--
2.7.4
For the keywords "modules", "defconfig_list", and "allnoconfig_y",
the lexer should pass specific tokens instead of generic T_WORD.
This simplifies both the lexer and the parser.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/kconf_id.c | 3 ---
scripts/kconfig/lkc.h | 9 +++------
scripts/kconfig/menu.c | 43 ++++++++++++++++++++-----------------------
scripts/kconfig/zconf.l | 3 +++
scripts/kconfig/zconf.y | 35 +++++++++++++++--------------------
5 files changed, 41 insertions(+), 52 deletions(-)
diff --git a/scripts/kconfig/kconf_id.c b/scripts/kconfig/kconf_id.c
index ec2c011..f8b222c 100644
--- a/scripts/kconfig/kconf_id.c
+++ b/scripts/kconfig/kconf_id.c
@@ -30,9 +30,6 @@ static struct kconf_id kconf_id_array[] = {
{ "visible", T_VISIBLE, TF_COMMAND },
{ "option", T_OPTION, TF_COMMAND },
{ "on", T_ON, TF_PARAM },
- { "modules", T_OPT_MODULES, TF_OPTION },
- { "defconfig_list", T_OPT_DEFCONFIG_LIST, TF_OPTION },
- { "allnoconfig_y", T_OPT_ALLNOCONFIG_Y, TF_OPTION },
};
#define KCONF_ID_ARRAY_SIZE (sizeof(kconf_id_array)/sizeof(struct kconf_id))
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index b6bbcd1..5f4880a 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -32,7 +32,6 @@ static inline const char *CONFIG_prefix(void)
#define TF_COMMAND 0x0001
#define TF_PARAM 0x0002
-#define TF_OPTION 0x0004
enum conf_def_mode {
def_default,
@@ -42,10 +41,6 @@ enum conf_def_mode {
def_random
};
-#define T_OPT_MODULES 1
-#define T_OPT_DEFCONFIG_LIST 2
-#define T_OPT_ALLNOCONFIG_Y 4
-
struct kconf_id {
const char *name;
int token;
@@ -90,7 +85,9 @@ void menu_add_visibility(struct expr *dep);
struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
-void menu_add_option(int token, char *arg);
+void menu_add_option_modules(void);
+void menu_add_option_defconfig_list(void);
+void menu_add_option_allnoconfig_y(void);
void menu_finalize(struct menu *parent);
void menu_set_type(int type);
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 4cf15d4..7e2b2c9 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -195,29 +195,26 @@ void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
}
-void menu_add_option(int token, char *arg)
-{
- switch (token) {
- case T_OPT_MODULES:
- if (modules_sym)
- zconf_error("symbol '%s' redefines option 'modules'"
- " already defined by symbol '%s'",
- current_entry->sym->name,
- modules_sym->name
- );
- modules_sym = current_entry->sym;
- break;
- case T_OPT_DEFCONFIG_LIST:
- if (!sym_defconfig_list)
- sym_defconfig_list = current_entry->sym;
- else if (sym_defconfig_list != current_entry->sym)
- zconf_error("trying to redefine defconfig symbol");
- sym_defconfig_list->flags |= SYMBOL_NO_WRITE;
- break;
- case T_OPT_ALLNOCONFIG_Y:
- current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y;
- break;
- }
+void menu_add_option_modules(void)
+{
+ if (modules_sym)
+ zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'",
+ current_entry->sym->name, modules_sym->name);
+ modules_sym = current_entry->sym;
+}
+
+void menu_add_option_defconfig_list(void)
+{
+ if (!sym_defconfig_list)
+ sym_defconfig_list = current_entry->sym;
+ else if (sym_defconfig_list != current_entry->sym)
+ zconf_error("trying to redefine defconfig symbol");
+ sym_defconfig_list->flags |= SYMBOL_NO_WRITE;
+}
+
+void menu_add_option_allnoconfig_y(void)
+{
+ current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y;
}
static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 5046d3c..0265502 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -147,6 +147,9 @@ 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;
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 4345f9f..8db9189 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -64,18 +64,21 @@ static struct menu *current_menu, *current_entry;
%token <id>T_IMPLY
%token <id>T_RANGE
%token <id>T_VISIBLE
-%token <id>T_OPTION
%token <id>T_ON
%token <string> T_WORD
%token <string> T_WORD_QUOTE
+%token T_ALLNOCONFIG_Y
%token T_BOOL
%token T_CLOSE_PAREN
%token T_DEFAULT
+%token T_DEFCONFIG_LIST
%token T_DEF_BOOL
%token T_DEF_TRISTATE
%token T_HEX
%token T_INT
+%token T_MODULES
%token T_OPEN_PAREN
+%token T_OPTION
%token T_STRING
%token T_TRISTATE
%token T_EOL
@@ -97,7 +100,7 @@ static struct menu *current_menu, *current_entry;
%type <expr> if_expr
%type <id> end
%type <menu> if_entry menu_entry choice_entry
-%type <string> symbol_option_arg word_opt assign_val
+%type <string> word_opt assign_val
%destructor {
fprintf(stderr, "%s:%d: missing end statement for this entry\n",
@@ -172,7 +175,6 @@ menuconfig_stmt: menuconfig_entry_start config_option_list
config_option_list:
/* empty */
| config_option_list config_option
- | config_option_list symbol_option
| config_option_list depends
| config_option_list help
;
@@ -219,27 +221,20 @@ config_option: T_RANGE symbol symbol if_expr T_EOL
printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
};
-symbol_option: T_OPTION symbol_option_list T_EOL
-;
+config_option: T_OPTION T_MODULES T_EOL
+{
+ menu_add_option_modules();
+};
-symbol_option_list:
- /* empty */
- | symbol_option_list T_WORD symbol_option_arg
+config_option: T_OPTION T_DEFCONFIG_LIST T_EOL
{
- const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
- if (id && id->flags & TF_OPTION) {
- menu_add_option(id->token, $3);
- free($3);
- }
- else
- zconfprint("warning: ignoring unknown option %s", $2);
- free($2);
+ menu_add_option_defconfig_list();
};
-symbol_option_arg:
- /* empty */ { $$ = NULL; }
- | T_EQUAL prompt { $$ = $2; }
-;
+config_option: T_OPTION T_ALLNOCONFIG_Y T_EOL
+{
+ menu_add_option_allnoconfig_y();
+};
/* choice entry */
--
2.7.4
Here, similar matching patters are duplicated in order to look ahead
the '\n' character. If the next character is '\n', the lexer returns
T_WORD_QUOTE because it must be prepared to return T_EOL at the next
match.
Use unput('\n') trick to reduce the code duplication.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 709b774..b7bc164 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -182,19 +182,9 @@ n [A-Za-z0-9_-]
<STRING>{
"$".* append_expanded_string(yytext);
- [^$'"\\\n]+/\n {
- append_string(yytext, yyleng);
- yylval.string = text;
- return T_WORD_QUOTE;
- }
[^$'"\\\n]+ {
append_string(yytext, yyleng);
}
- \\.?/\n {
- append_string(yytext + 1, yyleng - 1);
- yylval.string = text;
- return T_WORD_QUOTE;
- }
\\.? {
append_string(yytext + 1, yyleng - 1);
}
@@ -210,8 +200,10 @@ n [A-Za-z0-9_-]
fprintf(stderr,
"%s:%d:warning: multi-line strings not supported\n",
zconf_curname(), zconf_lineno());
+ unput('\n');
BEGIN(INITIAL);
- return T_EOL;
+ yylval.string = text;
+ return T_WORD_QUOTE;
}
<<EOF>> {
BEGIN(INITIAL);
--
2.7.4
Currently, "visible" and "depends on", if defined in a menu entry,
must appear in that order.
The real example is in drivers/media/tuners/Kconfig:
menu "Customize TV tuners"
visible if <expr1>
depends on <expr2>
... is fine, but you cannot change the property order like this:
menu "Customize TV tuners"
depends on <expr2>
visible if <expr1>
Kconfig does not require a specific order of properties. In this case,
menu_add_visibility(() and menu_add_dep() are orthogonal.
Loosen this unreasonable restriction.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index eeb449b..7cc8244 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -341,7 +341,7 @@ menu: T_MENU prompt T_EOL
printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
};
-menu_entry: menu visibility_list depends_list
+menu_entry: menu menu_option_list
{
$$ = menu_add_menu();
};
@@ -357,6 +357,12 @@ menu_end: end
menu_stmt: menu_entry stmt_list menu_end
;
+menu_option_list:
+ /* empty */
+ | menu_option_list visible
+ | menu_option_list depends
+;
+
source_stmt: T_SOURCE prompt T_EOL
{
printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
@@ -414,12 +420,6 @@ depends: T_DEPENDS T_ON expr T_EOL
};
/* visibility option */
-
-visibility_list:
- /* empty */
- | visibility_list visible
-;
-
visible: T_VISIBLE if_expr T_EOL
{
menu_add_visibility($2);
--
2.7.4
This commit decreases 8 shift/reduce conflicts.
A certain amount of grammatical ambiguity comes from how to reduce
excessive T_EOL tokens.
Let's take a look at the example code below:
1 config A
2 bool "a"
3
4 depends on B
5
6 config B
7 def_bool y
The line 3 is melt into "config_option_list", but the line 5 can be
either a part of "config_option_list" or "common_stmt" by itself.
Currently, the lexer converts '\n' to T_EOL verbatim. In Kconfig,
a new line is critical as a statement terminator, but new lines
in empty lines are not important since empty lines (or lines that
contain only whitespaces/comments) are just no-op.
If the lexer simply discards no-op lines, the parser will not be
bothered by excessive T_EOL tokens.
Of course, this means we are shifting the complexity from the parser
to the lexer, but it is much easier than tackling on shift/reduce
conflicts.
I introduced the second stage lexer to tweak the lexer.
Discard T_EOL if the previous token is T_EOL or T_HELPTEXT.
Two T_EOL tokens in a row is meaningless. T_HELPTEXT is a special
token that is reduced without T_EOL.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 21 +++++++++++++++++++++
scripts/kconfig/zconf.y | 18 +++---------------
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index b7bc164..847ba42 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -16,6 +16,8 @@
#include "lkc.h"
+#define YY_DECL static int yylex1(void)
+
#define START_STRSIZE 16
static struct {
@@ -23,6 +25,7 @@ static struct {
int lineno;
} current_pos;
+static int prev_token = T_EOL;
static char *text;
static int text_size, text_asize;
@@ -268,6 +271,24 @@ n [A-Za-z0-9_-]
}
%%
+
+/* second stage lexer */
+int yylex(void)
+{
+ int token;
+
+repeat:
+ token = yylex1();
+
+ /* Do not pass unneeded T_EOL to the parser. */
+ if ((prev_token == T_EOL || prev_token == T_HELPTEXT) && token == T_EOL)
+ goto repeat;
+
+ prev_token = token;
+
+ return token;
+}
+
static char *expand_token(const char *in, size_t n)
{
char *out;
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index c28f1a8..02bfc62 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -31,7 +31,7 @@ struct symbol *symbol_hash[SYMBOL_HASHSIZE];
static struct menu *current_menu, *current_entry;
%}
-%expect 29
+%expect 21
%union
{
@@ -111,9 +111,7 @@ static struct menu *current_menu, *current_entry;
%}
%%
-input: nl start | start;
-
-start: mainmenu_stmt stmt_list | stmt_list;
+input: mainmenu_stmt stmt_list | stmt_list;
/* mainmenu entry */
@@ -141,8 +139,7 @@ option_name:
;
common_stmt:
- T_EOL
- | if_stmt
+ if_stmt
| comment_stmt
| config_stmt
| menuconfig_stmt
@@ -193,7 +190,6 @@ config_option_list:
| config_option_list depends
| config_option_list help
| config_option_list option_error
- | config_option_list T_EOL
;
config_option: T_TYPE prompt_stmt_opt T_EOL
@@ -293,7 +289,6 @@ choice_option_list:
| choice_option_list choice_option
| choice_option_list depends
| choice_option_list help
- | choice_option_list T_EOL
| choice_option_list option_error
;
@@ -443,7 +438,6 @@ help: help_start T_HELPTEXT
depends_list:
/* empty */
| depends_list depends
- | depends_list T_EOL
| depends_list option_error
;
@@ -458,7 +452,6 @@ depends: T_DEPENDS T_ON expr T_EOL
visibility_list:
/* empty */
| visibility_list visible
- | visibility_list T_EOL
;
visible: T_VISIBLE if_expr T_EOL
@@ -484,11 +477,6 @@ end: T_ENDMENU T_EOL { $$ = $1; }
| T_ENDIF T_EOL { $$ = $1; }
;
-nl:
- T_EOL
- | nl T_EOL
-;
-
if_expr: /* empty */ { $$ = NULL; }
| T_IF expr { $$ = $2; }
;
--
2.7.4
It would be nice to warn if a new line is missing at end of file.
We could do this by checkpatch.pl for arbitrary files, but new line
is rather essential as a statement terminator in Kconfig.
The warning message looks like this:
kernel/Kconfig.preempt:60:warning: no new line at end of file
Currently, kernel/Kconfig.preempt is the only file with no new line
at end of file. Fix it.
I know there are some false negative cases. For example, no warning
is displayed when the last line contains some whitespaces/comments,
but no new line. Yet, this commit works well for most cases.
Signed-off-by: Masahiro Yamada <[email protected]>
---
kernel/Kconfig.preempt | 2 +-
scripts/kconfig/zconf.l | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt
index cd16551..0fee5fe 100644
--- a/kernel/Kconfig.preempt
+++ b/kernel/Kconfig.preempt
@@ -57,4 +57,4 @@ config PREEMPT
endchoice
config PREEMPT_COUNT
- bool
\ No newline at end of file
+ bool
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 9038e97..5046d3c 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -78,6 +78,13 @@ static void warn_ignored_character(char chr)
"%s:%d:warning: ignoring unsupported character '%c'\n",
current_file->name, yylineno, chr);
}
+
+static void warn_no_newline(void)
+{
+ fprintf(stderr, "%s:%d:warning: no new line at end of file\n",
+ current_file->name, yylineno);
+}
+
%}
n [A-Za-z0-9_-]
@@ -261,6 +268,9 @@ n [A-Za-z0-9_-]
<<EOF>> {
BEGIN(INITIAL);
+ if (prev_token != T_EOL && prev_token != T_HELPTEXT)
+ warn_no_newline();
+
if (current_file) {
zconf_endfile();
return T_EOL;
--
2.7.4
All line-oriented statements should be reduced when seeing a T_EOL
token. I guess missing T_EOL for the "visible" statement is just a
mistake. This commit decreases one shift/reduce conflict.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 22fceb2..c28f1a8 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -31,7 +31,7 @@ struct symbol *symbol_hash[SYMBOL_HASHSIZE];
static struct menu *current_menu, *current_entry;
%}
-%expect 30
+%expect 29
%union
{
@@ -461,7 +461,7 @@ visibility_list:
| visibility_list T_EOL
;
-visible: T_VISIBLE if_expr
+visible: T_VISIBLE if_expr T_EOL
{
menu_add_visibility($2);
};
--
2.7.4
There is no grammatical ambiguity by using T_WORD for variables.
The parser can distinguish variables from symbols from the context.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 4 ++--
scripts/kconfig/zconf.y | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 981b5f8..defb722 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -116,13 +116,13 @@ n [A-Za-z0-9_-]
}
alloc_string(yytext, yyleng);
yylval.string = text;
- return T_VARIABLE;
+ return T_WORD;
}
({n}|$)+ {
/* this token includes at least one '$' */
yylval.string = expand_token(yytext, yyleng);
if (strlen(yylval.string))
- return T_VARIABLE;
+ return T_WORD;
free(yylval.string);
}
"=" { BEGIN(ASSIGN_VAL); return T_EQUAL; }
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 97f86e2..3c44d67 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -84,7 +84,6 @@ static struct menu *current_menu, *current_entry;
%token T_STRING
%token T_TRISTATE
%token T_EOL
-%token <string> T_VARIABLE
%token <string> T_ASSIGN_VAL
%left T_OR
@@ -480,7 +479,7 @@ word_opt: /* empty */ { $$ = NULL; }
/* assignment statement */
-assignment_stmt: T_VARIABLE assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
+assignment_stmt: T_WORD assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
assign_op:
T_EQUAL { $$ = VAR_RECURSIVE; }
--
2.7.4
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.
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: Masahiro Yamada <[email protected]>
---
scripts/kconfig/kconf_id.c | 49 ---------------
scripts/kconfig/lkc.h | 9 ---
scripts/kconfig/zconf.l | 153 ++++++++++++++++++++-------------------------
scripts/kconfig/zconf.y | 5 --
4 files changed, 69 insertions(+), 147 deletions(-)
delete mode 100644 scripts/kconfig/kconf_id.c
diff --git a/scripts/kconfig/kconf_id.c b/scripts/kconfig/kconf_id.c
deleted file mode 100644
index f8b222c..0000000
--- a/scripts/kconfig/kconf_id.c
+++ /dev/null
@@ -1,49 +0,0 @@
-
-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;
-}
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 5f4880a..ff6b3e4 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -30,9 +30,6 @@ static inline const char *CONFIG_prefix(void)
#undef CONFIG_
#define CONFIG_ CONFIG_prefix()
-#define TF_COMMAND 0x0001
-#define TF_PARAM 0x0002
-
enum conf_def_mode {
def_default,
def_yes,
@@ -41,12 +38,6 @@ enum conf_def_mode {
def_random
};
-struct kconf_id {
- const char *name;
- int token;
- unsigned int flags;
-};
-
extern int yylineno;
void zconfdump(FILE *out);
void zconf_starthelp(void);
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index f0734abe..690108f 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -1,6 +1,6 @@
%option nostdinit noyywrap never-interactive full ecs
%option 8bit nodefault yylineno
-%x COMMAND HELP STRING PARAM ASSIGN_VAL
+%x ASSIGN_VAL HELP STRING
%{
/*
* Copyright (C) 2002 Roman Zippel <[email protected]>
@@ -94,45 +94,73 @@ n [A-Za-z0-9_-]
int str = 0;
int ts, i;
-[ \t]*#.*\n |
-[ \t]*\n {
- return T_EOL;
-}
-[ \t]*#.*
-. {
- unput(yytext[0]);
- BEGIN(COMMAND);
-}
-
-
-<COMMAND>{
- {n}+ {
- const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
- if (id && id->flags & TF_COMMAND) {
- BEGIN(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);
- }
- "=" return T_EQUAL;
- ":=" return T_COLON_EQUAL;
- "+=" return T_PLUS_EQUAL;
- [[:blank:]]+
- . warn_ignored_character(*yytext);
- \n {
- BEGIN(INITIAL);
- return T_EOL;
- }
-}
+#.* /* ignore comment */
+[ \t]* /* whitespaces */
+\\\n /* escaped new line */
+\n return T_EOL;
+"allnoconfig_y" return T_ALLNOCONFIG_Y;
+"bool" return T_BOOL;
+"choice" return T_CHOICE;
+"comment" return T_COMMENT;
+"config" return T_CONFIG;
+"default" return T_DEFAULT;
+"def_bool" return T_DEF_BOOL;
+"defconfig_list" return T_DEFCONFIG_LIST;
+"def_tristate" return T_DEF_TRISTATE;
+"depends" return T_DEPENDS;
+"endchoice" return T_ENDCHOICE;
+"endif" return T_ENDIF;
+"endmenu" return T_ENDMENU;
+"help"|"---help---" return T_HELP;
+"hex" return T_HEX;
+"if" return T_IF;
+"imply" return T_IMPLY;
+"int" return T_INT;
+"mainmenu" return T_MAINMENU;
+"menuconfig" return T_MENUCONFIG;
+"menu" return T_MENU;
+"modules" return T_MODULES;
+"on" return T_ON;
+"optional" return T_OPTIONAL;
+"option" return T_OPTION;
+"prompt" return T_PROMPT;
+"range" return T_RANGE;
+"select" return T_SELECT;
+"source" return T_SOURCE;
+"string" return T_STRING;
+"tristate" return T_TRISTATE;
+"visible" return T_VISIBLE;
+"||" 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>{
[^[:blank:]\n]+.* {
@@ -144,49 +172,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>{
"$".* append_expanded_string(yytext);
[^$'"\\\n]+ {
@@ -197,7 +182,7 @@ n [A-Za-z0-9_-]
}
\'|\" {
if (str == yytext[0]) {
- BEGIN(PARAM);
+ BEGIN(INITIAL);
yylval.string = text;
return T_WORD_QUOTE;
} else
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index c611d70..35c373d 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -110,11 +110,6 @@ static struct menu *current_menu, *current_entry;
menu_end_menu();
} 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;
--
2.7.4
In my understanding, special characters such as '.' and '/' are
supported in unquoted words to use bare file paths in the source
statement.
With all included file paths quoted in the previous commit, we can
drop this.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/preprocess.c | 3 +--
scripts/kconfig/zconf.l | 4 ++--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
index 5ca2df7..b028a48 100644
--- a/scripts/kconfig/preprocess.c
+++ b/scripts/kconfig/preprocess.c
@@ -555,8 +555,7 @@ char *expand_string(const char *in)
static bool is_end_of_token(char c)
{
- /* Why are '.' and '/' valid characters for symbols? */
- return !(isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/');
+ return !(isalnum(c) || c == '_' || c == '-');
}
/*
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index defb722..b715af9 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -167,7 +167,7 @@ n [A-Za-z0-9_-]
BEGIN(STRING);
}
\n BEGIN(INITIAL); return T_EOL;
- ({n}|[/.])+ {
+ {n}+ {
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
if (id && id->flags & TF_PARAM) {
yylval.id = id;
@@ -177,7 +177,7 @@ n [A-Za-z0-9_-]
yylval.string = text;
return T_WORD;
}
- ({n}|[/.$])+ {
+ ({n}|$)+ {
/* this token includes at least one '$' */
yylval.string = expand_token(yytext, yyleng);
if (strlen(yylval.string))
--
2.7.4
The lexer has conventionally associated kconf_id data with yylval
to carry additional information to the parser.
No token is relying on this any more.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 2 --
scripts/kconfig/zconf.y | 41 ++++++++++++++++++++---------------------
2 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index b715af9..c8823a4 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -111,7 +111,6 @@ n [A-Za-z0-9_-]
current_pos.lineno = yylineno;
if (id && id->flags & TF_COMMAND) {
BEGIN(PARAM);
- yylval.id = id;
return id->token;
}
alloc_string(yytext, yyleng);
@@ -170,7 +169,6 @@ n [A-Za-z0-9_-]
{n}+ {
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
if (id && id->flags & TF_PARAM) {
- yylval.id = id;
return id->token;
}
alloc_string(yytext, yyleng);
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 36cffc0..c611d70 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -40,50 +40,49 @@ static struct menu *current_menu, *current_entry;
struct symbol *symbol;
struct expr *expr;
struct menu *menu;
- const struct kconf_id *id;
enum symbol_type type;
enum variable_flavor flavor;
}
-%token <id>T_MAINMENU
-%token <id>T_MENU
-%token <id>T_ENDMENU
-%token <id>T_SOURCE
-%token <id>T_CHOICE
-%token <id>T_ENDCHOICE
-%token <id>T_COMMENT
-%token <id>T_CONFIG
-%token <id>T_MENUCONFIG
-%token <id>T_HELP
%token <string> T_HELPTEXT
-%token <id>T_IF
-%token <id>T_ENDIF
-%token <id>T_DEPENDS
-%token <id>T_OPTIONAL
-%token <id>T_PROMPT
-%token <id>T_SELECT
-%token <id>T_IMPLY
-%token <id>T_RANGE
-%token <id>T_VISIBLE
-%token <id>T_ON
%token <string> T_WORD
%token <string> T_WORD_QUOTE
%token T_ALLNOCONFIG_Y
%token T_BOOL
+%token T_CHOICE
%token T_CLOSE_PAREN
%token T_COLON_EQUAL
+%token T_COMMENT
+%token T_CONFIG
%token T_DEFAULT
%token T_DEFCONFIG_LIST
%token T_DEF_BOOL
%token T_DEF_TRISTATE
+%token T_DEPENDS
+%token T_ENDCHOICE
+%token T_ENDIF
+%token T_ENDMENU
+%token T_HELP
%token T_HEX
+%token T_IF
+%token T_IMPLY
%token T_INT
+%token T_MAINMENU
+%token T_MENU
+%token T_MENUCONFIG
%token T_MODULES
+%token T_ON
%token T_OPEN_PAREN
%token T_OPTION
+%token T_OPTIONAL
%token T_PLUS_EQUAL
+%token T_PROMPT
+%token T_RANGE
+%token T_SELECT
+%token T_SOURCE
%token T_STRING
%token T_TRISTATE
+%token T_VISIBLE
%token T_EOL
%token <string> T_ASSIGN_VAL
--
2.7.4
To simplify the generated lexer, switch to the ASSIGN_VAL state in
the hand-made lexer.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index c8823a4..d462507 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -25,6 +25,7 @@ static struct {
int lineno;
} current_pos;
+static int prev_prev_token = T_EOL;
static int prev_token = T_EOL;
static char *text;
static int text_size, text_asize;
@@ -124,9 +125,9 @@ n [A-Za-z0-9_-]
return T_WORD;
free(yylval.string);
}
- "=" { BEGIN(ASSIGN_VAL); return T_EQUAL; }
- ":=" { BEGIN(ASSIGN_VAL); return T_COLON_EQUAL; }
- "+=" { BEGIN(ASSIGN_VAL); return T_PLUS_EQUAL; }
+ "=" return T_EQUAL;
+ ":=" return T_COLON_EQUAL;
+ "+=" return T_PLUS_EQUAL;
[[:blank:]]+
. warn_ignored_character(*yytext);
\n {
@@ -294,6 +295,11 @@ repeat:
if ((prev_token == T_EOL || prev_token == T_HELPTEXT) && token == T_EOL)
goto repeat;
+ if (prev_prev_token == T_EOL && prev_token == T_WORD &&
+ (token == T_EQUAL || token == T_COLON_EQUAL || token == T_PLUS_EQUAL))
+ BEGIN(ASSIGN_VAL);
+
+ prev_prev_token = prev_token;
prev_token = token;
return token;
--
2.7.4
Currently, warn_ignore_character() displays invalid file name and
line number.
The lexer should use current_file->name and yylineno, while the parser
should use zconf_curname() and zconf_lineno().
This difference comes from that the lexer is always going ahead
of the parser. The parser needs to look ahead one token to make a
shift/reduce decision, so the lexer is requested to scan more text
from the input file.
This commit fixes the warning message from warn_ignored_character().
[Test Code]
----(Kconfig begin)----
/
-----(Kconfig end)-----
[Output]
Before the fix:
<none>:0:warning: ignoring unsupported character '/'
After the fix:
Kconfig:1:warning: ignoring unsupported character '/'
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 25bd2b8..eeac64c 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -73,7 +73,7 @@ static void warn_ignored_character(char chr)
{
fprintf(stderr,
"%s:%d:warning: ignoring unsupported character '%c'\n",
- zconf_curname(), zconf_lineno(), chr);
+ current_file->name, yylineno, chr);
}
%}
--
2.7.4
The Kconfig lexer supports special characters such as '.' and '/' in
the parameter context. In my understanding, the reason is just to
support bare file paths in the source statement.
I do not see a good reason to complicate Kconfig for the room of
ambiguity.
The majority of code already surround file paths with double quotes,
and it makes sense since the included file paths are constant string
literals.
Make it treewide consistent now.
Signed-off-by: Masahiro Yamada <[email protected]>
---
I will apply this to my Kbuild tree
because it is necessary for Kconfig clean-ups.
arch/arm/Kconfig | 2 +-
arch/arm/kvm/Kconfig | 2 +-
arch/arm64/Kconfig | 2 +-
arch/arm64/kvm/Kconfig | 2 +-
arch/ia64/Kconfig | 2 +-
arch/m68k/Kconfig | 6 +++---
arch/mips/kvm/Kconfig | 2 +-
arch/openrisc/Kconfig | 2 +-
arch/powerpc/Kconfig | 4 ++--
arch/powerpc/kvm/Kconfig | 2 +-
arch/riscv/Kconfig | 2 +-
arch/s390/Kconfig | 2 +-
arch/s390/kvm/Kconfig | 2 +-
arch/sh/Kconfig | 2 +-
arch/sparc/Kconfig | 2 +-
arch/x86/Kconfig | 2 +-
arch/x86/kvm/Kconfig | 2 +-
block/Kconfig | 2 +-
crypto/Kconfig | 4 ++--
drivers/crypto/Kconfig | 2 +-
drivers/gpu/drm/i915/Kconfig | 2 +-
drivers/hwmon/Kconfig | 2 +-
drivers/i2c/Kconfig | 6 +++---
drivers/pps/Kconfig | 4 ++--
drivers/ras/Kconfig | 2 +-
drivers/thermal/Kconfig | 2 +-
drivers/w1/Kconfig | 4 ++--
lib/Kconfig.debug | 4 ++--
security/Kconfig | 16 ++++++++--------
security/integrity/Kconfig | 4 ++--
30 files changed, 47 insertions(+), 47 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 91be74d..0a7faf8 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -910,7 +910,7 @@ config PLAT_VERSATILE
source "arch/arm/firmware/Kconfig"
-source arch/arm/mm/Kconfig
+source "arch/arm/mm/Kconfig"
config IWMMXT
bool "Enable iWMMXt support"
diff --git a/arch/arm/kvm/Kconfig b/arch/arm/kvm/Kconfig
index e2bd35b..3f5320f 100644
--- a/arch/arm/kvm/Kconfig
+++ b/arch/arm/kvm/Kconfig
@@ -55,6 +55,6 @@ config KVM_ARM_HOST
---help---
Provides host support for ARM processors.
-source drivers/vhost/Kconfig
+source "drivers/vhost/Kconfig"
endif # VIRTUALIZATION
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index ea2ab03..8a84de3 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -807,7 +807,7 @@ config NEED_PER_CPU_EMBED_FIRST_CHUNK
config HOLES_IN_ZONE
def_bool y
-source kernel/Kconfig.hz
+source "kernel/Kconfig.hz"
config ARCH_SUPPORTS_DEBUG_PAGEALLOC
def_bool y
diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig
index 47b23bf..a3f8562 100644
--- a/arch/arm64/kvm/Kconfig
+++ b/arch/arm64/kvm/Kconfig
@@ -61,6 +61,6 @@ config KVM_ARM_PMU
config KVM_INDIRECT_VECTORS
def_bool KVM && (HARDEN_BRANCH_PREDICTOR || HARDEN_EL2_VECTORS)
-source drivers/vhost/Kconfig
+source "drivers/vhost/Kconfig"
endif # VIRTUALIZATION
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index 36773de..0ef105a 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -261,7 +261,7 @@ config HZ
endif
if !IA64_HP_SIM
-source kernel/Kconfig.hz
+source "kernel/Kconfig.hz"
endif
config IA64_BRL_EMU
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 1bc9f1b..6f18c45 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -123,11 +123,11 @@ config BOOTINFO_PROC
menu "Platform setup"
-source arch/m68k/Kconfig.cpu
+source "arch/m68k/Kconfig.cpu"
-source arch/m68k/Kconfig.machine
+source "arch/m68k/Kconfig.machine"
-source arch/m68k/Kconfig.bus
+source "arch/m68k/Kconfig.bus"
endmenu
diff --git a/arch/mips/kvm/Kconfig b/arch/mips/kvm/Kconfig
index 76b93a9..c369302 100644
--- a/arch/mips/kvm/Kconfig
+++ b/arch/mips/kvm/Kconfig
@@ -72,6 +72,6 @@ config KVM_MIPS_DEBUG_COP0_COUNTERS
If unsure, say N.
-source drivers/vhost/Kconfig
+source "drivers/vhost/Kconfig"
endif # VIRTUALIZATION
diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig
index 285f7d0..d765b4a 100644
--- a/arch/openrisc/Kconfig
+++ b/arch/openrisc/Kconfig
@@ -139,7 +139,7 @@ config SMP
If you don't know what to do here, say N.
-source kernel/Kconfig.hz
+source "kernel/Kconfig.hz"
config OPENRISC_NO_SPR_SR_DSX
bool "use SPR_SR_DSX software emulation" if OR1K_1200
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 8be3126..e1307d6 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -393,7 +393,7 @@ config HIGHMEM
bool "High memory support"
depends on PPC32
-source kernel/Kconfig.hz
+source "kernel/Kconfig.hz"
config HUGETLB_PAGE_SIZE_VARIABLE
bool
@@ -816,7 +816,7 @@ config ARCH_WANTS_FREEZER_CONTROL
def_bool y
depends on ADB_PMU
-source kernel/power/Kconfig
+source "kernel/power/Kconfig"
config SECCOMP
bool "Enable seccomp to safely compute untrusted bytecode"
diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 68a0e9d..bfdde04 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -204,6 +204,6 @@ config KVM_XIVE
default y
depends on KVM_XICS && PPC_XIVE_NATIVE && KVM_BOOK3S_HV_POSSIBLE
-source drivers/vhost/Kconfig
+source "drivers/vhost/Kconfig"
endif # VIRTUALIZATION
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 55da93f..4f428ab 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -287,6 +287,6 @@ endmenu
menu "Power management options"
-source kernel/power/Kconfig
+source "kernel/power/Kconfig"
endmenu
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 5173366..48de9d3 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -520,7 +520,7 @@ config SCHED_TOPOLOGY
making when dealing with machines that have multi-threading,
multiple cores or multiple books.
-source kernel/Kconfig.hz
+source "kernel/Kconfig.hz"
config KEXEC
def_bool y
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index a3dbd45..767453f 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -57,6 +57,6 @@ config KVM_S390_UCONTROL
# OK, it's a little counter-intuitive to do this, but it puts it neatly under
# the virtualization menu.
-source drivers/vhost/Kconfig
+source "drivers/vhost/Kconfig"
endif # VIRTUALIZATION
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index f82a4da..b2581b1 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -597,7 +597,7 @@ endmenu
menu "Kernel features"
-source kernel/Kconfig.hz
+source "kernel/Kconfig.hz"
config KEXEC
bool "kexec system call (EXPERIMENTAL)"
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 490b2c9..29b97f1 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -187,7 +187,7 @@ config NR_CPUS
default 32 if SPARC32
default 4096 if SPARC64
-source kernel/Kconfig.hz
+source "kernel/Kconfig.hz"
config RWSEM_GENERIC_SPINLOCK
bool
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 8689e79..59433a52 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1965,7 +1965,7 @@ config SECCOMP
If unsure, say Y. Only embedded should say N here.
-source kernel/Kconfig.hz
+source "kernel/Kconfig.hz"
config KEXEC
bool "kexec system call"
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index 1bbec38..72fa955 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -98,6 +98,6 @@ config KVM_MMU_AUDIT
# OK, it's a little counter-intuitive to do this, but it puts it neatly under
# the virtualization menu.
-source drivers/vhost/Kconfig
+source "drivers/vhost/Kconfig"
endif # VIRTUALIZATION
diff --git a/block/Kconfig b/block/Kconfig
index f7045aa..1b91498 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -224,4 +224,4 @@ config BLK_MQ_RDMA
config BLK_PM
def_bool BLOCK && PM
-source block/Kconfig.iosched
+source "block/Kconfig.iosched"
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 05c91eb..d18b1c3 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1826,7 +1826,7 @@ config CRYPTO_HASH_INFO
bool
source "drivers/crypto/Kconfig"
-source crypto/asymmetric_keys/Kconfig
-source certs/Kconfig
+source "crypto/asymmetric_keys/Kconfig"
+source "certs/Kconfig"
endif # if CRYPTO
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index caa98a7f..4db49de 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -258,7 +258,7 @@ config CRYPTO_DEV_HIFN_795X_RNG
Select this option if you want to enable the random number generator
on the HIFN 795x crypto adapters.
-source drivers/crypto/caam/Kconfig
+source "drivers/crypto/caam/Kconfig"
config CRYPTO_DEV_TALITOS
tristate "Talitos Freescale Security Engine (SEC)"
diff --git a/drivers/gpu/drm/i915/Kconfig b/drivers/gpu/drm/i915/Kconfig
index 33a458b..148be8e 100644
--- a/drivers/gpu/drm/i915/Kconfig
+++ b/drivers/gpu/drm/i915/Kconfig
@@ -131,5 +131,5 @@ config DRM_I915_GVT_KVMGT
menu "drm/i915 Debugging"
depends on DRM_I915
depends on EXPERT
-source drivers/gpu/drm/i915/Kconfig.debug
+source "drivers/gpu/drm/i915/Kconfig.debug"
endmenu
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 81da17a..9ccbbd3 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1306,7 +1306,7 @@ config SENSORS_PCF8591
These devices are hard to detect and rarely found on mainstream
hardware. If unsure, say N.
-source drivers/hwmon/pmbus/Kconfig
+source "drivers/hwmon/pmbus/Kconfig"
config SENSORS_PWM_FAN
tristate "PWM fan"
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index efc3354..c6b7fc7 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -68,7 +68,7 @@ config I2C_MUX
This support is also available as a module. If so, the module
will be called i2c-mux.
-source drivers/i2c/muxes/Kconfig
+source "drivers/i2c/muxes/Kconfig"
config I2C_HELPER_AUTO
bool "Autoselect pertinent helper modules"
@@ -94,8 +94,8 @@ config I2C_SMBUS
This support is also available as a module. If so, the module
will be called i2c-smbus.
-source drivers/i2c/algos/Kconfig
-source drivers/i2c/busses/Kconfig
+source "drivers/i2c/algos/Kconfig"
+source "drivers/i2c/busses/Kconfig"
config I2C_STUB
tristate "I2C/SMBus Test Stub"
diff --git a/drivers/pps/Kconfig b/drivers/pps/Kconfig
index c6008f2..965aa08 100644
--- a/drivers/pps/Kconfig
+++ b/drivers/pps/Kconfig
@@ -37,8 +37,8 @@ config NTP_PPS
It doesn't work on tickless systems at the moment.
-source drivers/pps/clients/Kconfig
+source "drivers/pps/clients/Kconfig"
-source drivers/pps/generators/Kconfig
+source "drivers/pps/generators/Kconfig"
endif # PPS
diff --git a/drivers/ras/Kconfig b/drivers/ras/Kconfig
index 4c3c67d..b834ff5 100644
--- a/drivers/ras/Kconfig
+++ b/drivers/ras/Kconfig
@@ -30,6 +30,6 @@ menuconfig RAS
if RAS
-source arch/x86/ras/Kconfig
+source "arch/x86/ras/Kconfig"
endif
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 5422523..5fbfabb 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -383,7 +383,7 @@ config INTEL_QUARK_DTS_THERMAL
underlying BIOS/Firmware.
menu "ACPI INT340X thermal drivers"
-source drivers/thermal/int340x_thermal/Kconfig
+source "drivers/thermal/int340x_thermal/Kconfig"
endmenu
config INTEL_BXT_PMIC_THERMAL
diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig
index 6743bde..dbb41f4 100644
--- a/drivers/w1/Kconfig
+++ b/drivers/w1/Kconfig
@@ -25,7 +25,7 @@ config W1_CON
2. Userspace commands. Includes read/write and search/alarm search commands.
3. Replies to userspace commands.
-source drivers/w1/masters/Kconfig
-source drivers/w1/slaves/Kconfig
+source "drivers/w1/masters/Kconfig"
+source "drivers/w1/slaves/Kconfig"
endif # W1
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 1af29b8..08a95da 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -439,7 +439,7 @@ config DEBUG_KERNEL
menu "Memory Debugging"
-source mm/Kconfig.debug
+source "mm/Kconfig.debug"
config DEBUG_OBJECTS
bool "Debug object operations"
@@ -1609,7 +1609,7 @@ config LATENCYTOP
Enable this option if you want to use the LatencyTOP tool
to find out which userspace is blocking on what kernel operations.
-source kernel/trace/Kconfig
+source "kernel/trace/Kconfig"
config PROVIDE_OHCI1394_DMA_INIT
bool "Remote debugging over FireWire early on boot"
diff --git a/security/Kconfig b/security/Kconfig
index d9aa521..e4fe2f3 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -4,7 +4,7 @@
menu "Security options"
-source security/keys/Kconfig
+source "security/keys/Kconfig"
config SECURITY_DMESG_RESTRICT
bool "Restrict unprivileged access to the kernel syslog"
@@ -230,14 +230,14 @@ config STATIC_USERMODEHELPER_PATH
If you wish for all usermode helper programs to be disabled,
specify an empty string here (i.e. "").
-source security/selinux/Kconfig
-source security/smack/Kconfig
-source security/tomoyo/Kconfig
-source security/apparmor/Kconfig
-source security/loadpin/Kconfig
-source security/yama/Kconfig
+source "security/selinux/Kconfig"
+source "security/smack/Kconfig"
+source "security/tomoyo/Kconfig"
+source "security/apparmor/Kconfig"
+source "security/loadpin/Kconfig"
+source "security/yama/Kconfig"
-source security/integrity/Kconfig
+source "security/integrity/Kconfig"
choice
prompt "Default security module"
diff --git a/security/integrity/Kconfig b/security/integrity/Kconfig
index da95658..877af1f 100644
--- a/security/integrity/Kconfig
+++ b/security/integrity/Kconfig
@@ -66,7 +66,7 @@ config INTEGRITY_AUDIT
be enabled by specifying 'integrity_audit=1' on the kernel
command line.
-source security/integrity/ima/Kconfig
-source security/integrity/evm/Kconfig
+source "security/integrity/ima/Kconfig"
+source "security/integrity/evm/Kconfig"
endif # if INTEGRITY
--
2.7.4
Whitespaces are consumed in the COMMAND state anyway.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 6 ------
1 file changed, 6 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index c2f577d..709b774 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -88,12 +88,6 @@ n [A-Za-z0-9_-]
return T_EOL;
}
[ \t]*#.*
-
-
-[ \t]+ {
- BEGIN(COMMAND);
-}
-
. {
unput(yytext[0]);
BEGIN(COMMAND);
--
2.7.4
Currently, the lexer returns T_ASSIGN for all of =, :=, and +=
associating yylval with the flavor.
I want to make the generated lexer as simple as possible. So, the
lexer should convert keywords to tokens without thinking about the
meaning.
= -> T_EQUAL
:= -> T_COLON_EQUAL
+= -> T_PLUS_EQUAL
Unfortunately, Kconfig uses = instead of == for the equal operator.
So, both assignment and comparison use T_EQUAL. The parser can still
distinguish them from the context.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 6 +++---
scripts/kconfig/zconf.y | 12 ++++++++++--
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 0265502..981b5f8 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -125,9 +125,9 @@ n [A-Za-z0-9_-]
return T_VARIABLE;
free(yylval.string);
}
- "=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; }
- ":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; }
- "+=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; }
+ "=" { BEGIN(ASSIGN_VAL); return T_EQUAL; }
+ ":=" { BEGIN(ASSIGN_VAL); return T_COLON_EQUAL; }
+ "+=" { BEGIN(ASSIGN_VAL); return T_PLUS_EQUAL; }
[[:blank:]]+
. warn_ignored_character(*yytext);
\n {
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 8db9189..97f86e2 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -70,6 +70,7 @@ static struct menu *current_menu, *current_entry;
%token T_ALLNOCONFIG_Y
%token T_BOOL
%token T_CLOSE_PAREN
+%token T_COLON_EQUAL
%token T_DEFAULT
%token T_DEFCONFIG_LIST
%token T_DEF_BOOL
@@ -79,11 +80,11 @@ static struct menu *current_menu, *current_entry;
%token T_MODULES
%token T_OPEN_PAREN
%token T_OPTION
+%token T_PLUS_EQUAL
%token T_STRING
%token T_TRISTATE
%token T_EOL
%token <string> T_VARIABLE
-%token <flavor> T_ASSIGN
%token <string> T_ASSIGN_VAL
%left T_OR
@@ -101,6 +102,7 @@ static struct menu *current_menu, *current_entry;
%type <id> end
%type <menu> if_entry menu_entry choice_entry
%type <string> word_opt assign_val
+%type <flavor> assign_op
%destructor {
fprintf(stderr, "%s:%d: missing end statement for this entry\n",
@@ -478,7 +480,13 @@ word_opt: /* empty */ { $$ = NULL; }
/* assignment statement */
-assignment_stmt: T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
+assignment_stmt: T_VARIABLE assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
+
+assign_op:
+ T_EQUAL { $$ = VAR_RECURSIVE; }
+ | T_COLON_EQUAL { $$ = VAR_SIMPLE; }
+ | T_PLUS_EQUAL { $$ = VAR_APPEND; }
+;
assign_val:
/* empty */ { $$ = xstrdup(""); };
--
2.7.4
A new file should always start in the INITIAL state.
When the lexer bumps into EOF, the lexer must get back to the INITIAL
state anyway. Remove the redundant <<EOF>> pattern in the PARAM state.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.l | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 847ba42..9038e97 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -178,9 +178,6 @@ n [A-Za-z0-9_-]
\\\n ;
[[:blank:]]+
. warn_ignored_character(*yytext);
- <<EOF>> {
- BEGIN(INITIAL);
- }
}
<STRING>{
@@ -262,6 +259,8 @@ n [A-Za-z0-9_-]
}
<<EOF>> {
+ BEGIN(INITIAL);
+
if (current_file) {
zconf_endfile();
return T_EOL;
--
2.7.4
The code block surrounded by "if" ... "endif" is stmt_list.
Remove the redundant if_block symbol entirely.
Remove "stmt_list: stmt_list end" rule as well since it would
obviously cause conflicts.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index a92f167..dcbf643 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -123,7 +123,6 @@ stmt_list:
| stmt_list common_stmt
| stmt_list choice_stmt
| stmt_list menu_stmt
- | stmt_list end { zconf_error("unexpected end statement"); }
| stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
| stmt_list error T_EOL { zconf_error("invalid statement"); }
;
@@ -330,14 +329,7 @@ if_end: end
}
};
-if_stmt: if_entry if_block if_end
-;
-
-if_block:
- /* empty */
- | if_block common_stmt
- | if_block menu_stmt
- | if_block choice_stmt
+if_stmt: if_entry stmt_list if_end
;
/* menu entry */
--
2.7.4
Now the comment_stmt is the only user of depends_list. Rename it to
comment_option_list
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 7cc8244..7a4bc58 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -379,7 +379,12 @@ comment: T_COMMENT prompt T_EOL
printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
};
-comment_stmt: comment depends_list
+comment_stmt: comment comment_option_list
+;
+
+comment_option_list:
+ /* empty */
+ | comment_option_list depends
;
/* help option */
@@ -408,11 +413,6 @@ help: help_start T_HELPTEXT
/* depends option */
-depends_list:
- /* empty */
- | depends_list depends
-;
-
depends: T_DEPENDS T_ON expr T_EOL
{
menu_add_dep($3);
--
2.7.4
These are already defined as %left.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 5 -----
1 file changed, 5 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 7a4bc58..020454b 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -69,11 +69,6 @@ static struct menu *current_menu, *current_entry;
%token <id>T_ON
%token <string> T_WORD
%token <string> T_WORD_QUOTE
-%token T_UNEQUAL
-%token T_LESS
-%token T_LESS_EQUAL
-%token T_GREATER
-%token T_GREATER_EQUAL
%token T_CLOSE_PAREN
%token T_OPEN_PAREN
%token T_EOL
--
2.7.4
The code block surrounded by "menu" ... "endmenu" is stmt_list.
Remove the redundant menu_block symbol entirely.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/zconf.y | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index dcbf643..eeb449b 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -354,14 +354,7 @@ menu_end: end
}
};
-menu_stmt: menu_entry menu_block menu_end
-;
-
-menu_block:
- /* empty */
- | menu_block common_stmt
- | menu_block menu_stmt
- | menu_block choice_stmt
+menu_stmt: menu_entry stmt_list menu_end
;
source_stmt: T_SOURCE prompt T_EOL
--
2.7.4
On Tue, Dec 11, 2018 at 12:03 PM Masahiro Yamada
<[email protected]> wrote:
> The Kconfig lexer supports special characters such as '.' and '/' in
> the parameter context. In my understanding, the reason is just to
> support bare file paths in the source statement.
>
> I do not see a good reason to complicate Kconfig for the room of
> ambiguity.
>
> The majority of code already surround file paths with double quotes,
> and it makes sense since the included file paths are constant string
> literals.
>
> Make it treewide consistent now.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> arch/m68k/Kconfig | 6 +++---
Acked-by: Geert Uytterhoeven <[email protected]>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
This commit removes kconf_id::stype to prepare for the entire
removal of kconf_id.c
To simplify the lexer, I want keywords straight-mapped to tokens.
Signed-off-by: Masahiro Yamada <[email protected]>
---
scripts/kconfig/kconf_id.c | 16 ++++++------
scripts/kconfig/lkc.h | 1 -
scripts/kconfig/zconf.y | 62 +++++++++++++++++++++++++++++-----------------
3 files changed, 47 insertions(+), 32 deletions(-)
diff --git a/scripts/kconfig/kconf_id.c b/scripts/kconfig/kconf_id.c
index b3e0ea0..ec2c011 100644
--- a/scripts/kconfig/kconf_id.c
+++ b/scripts/kconfig/kconf_id.c
@@ -15,15 +15,15 @@ static struct kconf_id kconf_id_array[] = {
{ "endif", T_ENDIF, TF_COMMAND },
{ "depends", T_DEPENDS, TF_COMMAND },
{ "optional", T_OPTIONAL, TF_COMMAND },
- { "default", T_DEFAULT, TF_COMMAND, S_UNKNOWN },
+ { "default", T_DEFAULT, TF_COMMAND },
+ { "def_bool", T_DEF_BOOL, TF_COMMAND },
+ { "def_tristate", T_DEF_TRISTATE, TF_COMMAND },
{ "prompt", T_PROMPT, TF_COMMAND },
- { "tristate", T_TYPE, TF_COMMAND, S_TRISTATE },
- { "def_tristate", T_DEFAULT, TF_COMMAND, S_TRISTATE },
- { "bool", T_TYPE, TF_COMMAND, S_BOOLEAN },
- { "def_bool", T_DEFAULT, TF_COMMAND, S_BOOLEAN },
- { "int", T_TYPE, TF_COMMAND, S_INT },
- { "hex", T_TYPE, TF_COMMAND, S_HEX },
- { "string", T_TYPE, TF_COMMAND, S_STRING },
+ { "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 },
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 9eb7c83..b6bbcd1 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -50,7 +50,6 @@ struct kconf_id {
const char *name;
int token;
unsigned int flags;
- enum symbol_type stype;
};
extern int yylineno;
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 020454b..4345f9f 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -40,6 +40,7 @@ static struct menu *current_menu, *current_entry;
struct expr *expr;
struct menu *menu;
const struct kconf_id *id;
+ enum symbol_type type;
enum variable_flavor flavor;
}
@@ -59,8 +60,6 @@ static struct menu *current_menu, *current_entry;
%token <id>T_DEPENDS
%token <id>T_OPTIONAL
%token <id>T_PROMPT
-%token <id>T_TYPE
-%token <id>T_DEFAULT
%token <id>T_SELECT
%token <id>T_IMPLY
%token <id>T_RANGE
@@ -69,8 +68,16 @@ static struct menu *current_menu, *current_entry;
%token <id>T_ON
%token <string> T_WORD
%token <string> T_WORD_QUOTE
+%token T_BOOL
%token T_CLOSE_PAREN
+%token T_DEFAULT
+%token T_DEF_BOOL
+%token T_DEF_TRISTATE
+%token T_HEX
+%token T_INT
%token T_OPEN_PAREN
+%token T_STRING
+%token T_TRISTATE
%token T_EOL
%token <string> T_VARIABLE
%token <flavor> T_ASSIGN
@@ -85,6 +92,7 @@ static struct menu *current_menu, *current_entry;
%type <string> prompt
%type <symbol> nonconst_symbol
%type <symbol> symbol
+%type <type> type bool_or_tri default
%type <expr> expr
%type <expr> if_expr
%type <id> end
@@ -169,12 +177,12 @@ config_option_list:
| config_option_list help
;
-config_option: T_TYPE prompt_stmt_opt T_EOL
+config_option: type prompt_stmt_opt T_EOL
{
- menu_set_type($1->stype);
+ menu_set_type($1);
printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
zconf_curname(), zconf_lineno(),
- $1->stype);
+ $1);
};
config_option: T_PROMPT prompt if_expr T_EOL
@@ -183,14 +191,14 @@ config_option: T_PROMPT prompt if_expr T_EOL
printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
};
-config_option: T_DEFAULT expr if_expr T_EOL
+config_option: default expr if_expr T_EOL
{
menu_add_expr(P_DEFAULT, $2, $3);
- if ($1->stype != S_UNKNOWN)
- menu_set_type($1->stype);
+ if ($1 != S_UNKNOWN)
+ menu_set_type($1);
printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
zconf_curname(), zconf_lineno(),
- $1->stype);
+ $1);
};
config_option: T_SELECT nonconst_symbol if_expr T_EOL
@@ -274,15 +282,11 @@ choice_option: T_PROMPT prompt if_expr T_EOL
printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
};
-choice_option: T_TYPE prompt_stmt_opt T_EOL
+choice_option: bool_or_tri prompt_stmt_opt T_EOL
{
- if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
- menu_set_type($1->stype);
- printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
- zconf_curname(), zconf_lineno(),
- $1->stype);
- } else
- YYERROR;
+ menu_set_type($1);
+ printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
+ zconf_curname(), zconf_lineno(), $1);
};
choice_option: T_OPTIONAL T_EOL
@@ -293,14 +297,26 @@ choice_option: T_OPTIONAL T_EOL
choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
{
- if ($1->stype == S_UNKNOWN) {
- menu_add_symbol(P_DEFAULT, $2, $3);
- printd(DEBUG_PARSE, "%s:%d:default\n",
- zconf_curname(), zconf_lineno());
- } else
- YYERROR;
+ menu_add_symbol(P_DEFAULT, $2, $3);
+ printd(DEBUG_PARSE, "%s:%d:default\n",
+ zconf_curname(), zconf_lineno());
};
+type:
+ bool_or_tri
+ | T_INT { $$ = S_INT; }
+ | T_HEX { $$ = S_HEX; }
+ | T_STRING { $$ = S_STRING; }
+
+bool_or_tri:
+ T_BOOL { $$ = S_BOOLEAN; }
+ | T_TRISTATE { $$ = S_TRISTATE; }
+
+default:
+ T_DEFAULT { $$ = S_UNKNOWN; }
+ | T_DEF_BOOL { $$ = S_BOOLEAN; }
+ | T_DEF_TRISTATE { $$ = S_TRISTATE; }
+
choice_block:
/* empty */
| choice_block common_stmt
--
2.7.4
On Tue, Dec 11, 2018 at 08:01:04PM +0900, Masahiro Yamada wrote:
> The Kconfig lexer supports special characters such as '.' and '/' in
> the parameter context. In my understanding, the reason is just to
> support bare file paths in the source statement.
>
> I do not see a good reason to complicate Kconfig for the room of
> ambiguity.
>
> The majority of code already surround file paths with double quotes,
> and it makes sense since the included file paths are constant string
> literals.
>
> Make it treewide consistent now.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
Acked-by: Wolfram Sang <[email protected]>
* Masahiro Yamada <[email protected]> wrote:
> The Kconfig lexer supports special characters such as '.' and '/' in
> the parameter context. In my understanding, the reason is just to
> support bare file paths in the source statement.
>
> I do not see a good reason to complicate Kconfig for the room of
> ambiguity.
>
> The majority of code already surround file paths with double quotes,
> and it makes sense since the included file paths are constant string
> literals.
>
> Make it treewide consistent now.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
Acked-by: Ingo Molnar <[email protected]>
Thanks for doing all this Kconfig language work!
Thanks,
Ingo
On 11. 12. 18 12:01, Masahiro Yamada wrote:
> I guess this is a constant value instead of a symbol.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> I will apply this to my Kbuild tree
> because it is necessary for Kconfig clean-ups.
>
>
> arch/microblaze/Kconfig.platform | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/microblaze/Kconfig.platform b/arch/microblaze/Kconfig.platform
> index f7f1739..7361974 100644
> --- a/arch/microblaze/Kconfig.platform
> +++ b/arch/microblaze/Kconfig.platform
> @@ -65,6 +65,6 @@ config XILINX_MICROBLAZE0_USE_FPU
>
> config XILINX_MICROBLAZE0_HW_VER
> string "Core version number"
> - default 7.10.d
> + default "7.10.d"
>
> endmenu
>
Acked-by: Michal Simek <[email protected]>
Thanks,
Michal
--
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: http://www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs
On Tue, Dec 11, 2018 at 8:04 PM Masahiro Yamada
<[email protected]> wrote:
>
>
> When I tryed to change something, I was often hit by annoying
> shift/reduce conflicts in the parser.
>
> The lexer and parser are too cluttered.
>
> So, I decided to clean-up now.
>
> - Fix all shift/reduce conflicts in the parser
>
> - Rewrite the lexer. The linear keyword search was removed.
> The number of states descreased from 6 to 4.
>
> - Fix various subtle issues
>
>
>
> Masahiro Yamada (27):
> kconfig: fix file name and line number of warn_ignored_character()
> kconfig: fix memory leak when EOF is encountered in quotation
> kconfig: require T_EOL to reduce visible statement
> kconfig: remove unneeded pattern matching to whitespaces
> kconfig: refactor pattern matching in STRING state
> kconfig: fix ambiguous grammar in terms of new lines
> kconfig: clean up EOF handling in the lexer
> kconfig: warn no new line at end of file
> kconfig: remove grammatically ambiguous "unexpected option" diagnostic
> kconfig: remove grammatically ambiguous option_error
> kconfig: remove redundant if_block rule
> kconfig: remove redundant menu_block rule
> kconfig: loosen the order of "visible" and "depends on" in menu entry
> kconfig: rename depends_list to comment_option_list
> kconfig: remove redundant token defines
> kconfig: use distinct tokens for type and default properties
> kconfig: refactor scanning and parsing "option" properties
> kconfig: use specific tokens instead of T_ASSIGN for assignments
> kconfig: use T_WORD instead of T_VARIABLE for variables
> microblaze: surround string default in Kconfig with double quotes
> treewide: surround file paths in Kconfig files with double quotes
> kconfig: ban the use of '.' and '/' in unquoted words
> kconfig: refactor end token rules
> kconfig: stop associating kconf_id with yylval
> kconfig: switch to ASSIGN_VAL state in the second lexer
> kconfig: update current_pos in the second lexer
> kconfig: remove keyword lookup table entirely
Series, applied to kbuild/kconfig.
--
Best Regards
Masahiro Yamada