linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: linux-kbuild@vger.kernel.org
Cc: Ulf Magnusson <ulfalizer@gmail.com>,
	linux-kernel@vger.kernel.org,
	Masahiro Yamada <yamada.masahiro@socionext.com>
Subject: [PATCH 17/27] kconfig: refactor scanning and parsing "option" properties
Date: Tue, 11 Dec 2018 20:01:00 +0900	[thread overview]
Message-ID: <1544526070-16690-18-git-send-email-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <1544526070-16690-1-git-send-email-yamada.masahiro@socionext.com>

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 <yamada.masahiro@socionext.com>
---

 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


  parent reply	other threads:[~2018-12-11 11:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-11 11:00 [PATCH 00/27] kconfig: remove all reduce/shift conflicts, refactor lexer, fix various issues Masahiro Yamada
2018-12-11 11:00 ` [PATCH 01/27] kconfig: fix file name and line number of warn_ignored_character() Masahiro Yamada
2018-12-11 11:00 ` [PATCH 02/27] kconfig: fix memory leak when EOF is encountered in quotation Masahiro Yamada
2018-12-11 11:00 ` [PATCH 03/27] kconfig: require T_EOL to reduce visible statement Masahiro Yamada
2018-12-11 11:00 ` [PATCH 04/27] kconfig: remove unneeded pattern matching to whitespaces Masahiro Yamada
2018-12-11 11:00 ` [PATCH 05/27] kconfig: refactor pattern matching in STRING state Masahiro Yamada
2018-12-11 11:00 ` [PATCH 06/27] kconfig: fix ambiguous grammar in terms of new lines Masahiro Yamada
2018-12-11 11:00 ` [PATCH 07/27] kconfig: clean up EOF handling in the lexer Masahiro Yamada
2018-12-11 11:00 ` [PATCH 08/27] kconfig: warn no new line at end of file Masahiro Yamada
2018-12-11 11:00 ` [PATCH 09/27] kconfig: remove grammatically ambiguous "unexpected option" diagnostic Masahiro Yamada
2018-12-11 11:00 ` [PATCH 10/27] kconfig: remove grammatically ambiguous option_error Masahiro Yamada
2018-12-11 11:00 ` [PATCH 11/27] kconfig: remove redundant if_block rule Masahiro Yamada
2018-12-11 11:00 ` [PATCH 12/27] kconfig: remove redundant menu_block rule Masahiro Yamada
2018-12-11 11:00 ` [PATCH 13/27] kconfig: loosen the order of "visible" and "depends on" in menu entry Masahiro Yamada
2018-12-11 11:00 ` [PATCH 14/27] kconfig: rename depends_list to comment_option_list Masahiro Yamada
2018-12-11 11:00 ` [PATCH 15/27] kconfig: remove redundant token defines Masahiro Yamada
2018-12-11 11:00 ` [PATCH 16/27] kconfig: use distinct tokens for type and default properties Masahiro Yamada
2018-12-11 11:01 ` Masahiro Yamada [this message]
2018-12-11 11:01 ` [PATCH 18/27] kconfig: use specific tokens instead of T_ASSIGN for assignments Masahiro Yamada
2018-12-11 11:01 ` [PATCH 19/27] kconfig: use T_WORD instead of T_VARIABLE for variables Masahiro Yamada
2018-12-11 11:01 ` [PATCH 20/27] microblaze: surround string default in Kconfig with double quotes Masahiro Yamada
2018-12-12  8:28   ` Michal Simek
2018-12-11 11:01 ` [PATCH 21/27] treewide: surround file paths in Kconfig files " Masahiro Yamada
2018-12-11 11:19   ` Wolfram Sang
2018-12-11 11:25   ` Geert Uytterhoeven
2018-12-11 14:43   ` Ingo Molnar
2018-12-11 11:01 ` [PATCH 22/27] kconfig: ban the use of '.' and '/' in unquoted words Masahiro Yamada
2018-12-11 11:01 ` [PATCH 23/27] kconfig: refactor end token rules Masahiro Yamada
2018-12-11 11:01 ` [PATCH 24/27] kconfig: stop associating kconf_id with yylval Masahiro Yamada
2018-12-11 11:01 ` [PATCH 25/27] kconfig: switch to ASSIGN_VAL state in the second lexer Masahiro Yamada
2018-12-11 11:01 ` [PATCH 26/27] kconfig: update current_pos " Masahiro Yamada
2018-12-11 11:01 ` [PATCH 27/27] kconfig: remove keyword lookup table entirely Masahiro Yamada
2018-12-19 14:59 ` [PATCH 00/27] kconfig: remove all reduce/shift conflicts, refactor lexer, fix various issues Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1544526070-16690-18-git-send-email-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ulfalizer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).