All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 09/27] kconfig: replace current_pos with separate cur_{filename,lineno}
Date: Sat,  3 Feb 2024 00:58:07 +0900	[thread overview]
Message-ID: <20240202155825.314567-10-masahiroy@kernel.org> (raw)
In-Reply-To: <20240202155825.314567-1-masahiroy@kernel.org>

Replace current_pos with separate variables representing the file name
and the line number, respectively.

No functional change is intended.

By the way, you might wonder why the "<none>" fallback exists in
zconf_curname(). menu_add_symbol() saves the current file and the line
number. It is intended to be called only during the yyparse() time.
However, menu_finalize() calls it, where there is no file being parsed.
This is a long-standing hack that should be fixed later. I left a FIXME
comment.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kconfig/lexer.l | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l
index 1bb372868ecf..540098435a3b 100644
--- a/scripts/kconfig/lexer.l
+++ b/scripts/kconfig/lexer.l
@@ -22,10 +22,14 @@
 
 #define START_STRSIZE	16
 
-static struct {
-	struct file *file;
-	int lineno;
-} current_pos;
+/* The Kconfig file currently being parsed.  */
+static const char *cur_filename;
+
+/*
+ * The line number of the current statement. This does not match yylineno.
+ * yylineno is used by the lexer, while cur_lineno is used by the parser.
+ */
+static int cur_lineno;
 
 static int prev_prev_token = T_EOL;
 static int prev_token = T_EOL;
@@ -279,9 +283,14 @@ repeat:
 			 * 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.
+			 *
+			 * FIXME:
+			 * cur_filename and cur_lineno are used even after
+			 * yyparse(); menu_finalize() calls menu_add_symbol().
+			 * This should be fixed.
 			 */
-			current_pos.file = current_file;
-			current_pos.lineno = yylineno;
+			cur_filename = current_file ? current_file->name : "<none>";
+			cur_lineno = yylineno;
 		}
 	}
 
@@ -462,10 +471,10 @@ static void zconf_endfile(void)
 
 int zconf_lineno(void)
 {
-	return current_pos.lineno;
+	return cur_lineno;
 }
 
 const char *zconf_curname(void)
 {
-	return current_pos.file ? current_pos.file->name : "<none>";
+	return cur_filename;
 }
-- 
2.40.1


  parent reply	other threads:[~2024-02-02 15:58 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 15:57 [PATCH 00/27] kconfig: refactor lexer and parser code Masahiro Yamada
2024-02-02 15:57 ` [PATCH 01/27] kconfig: fix infinite loop when expanding a macro at the end of file Masahiro Yamada
2024-02-02 15:58 ` [PATCH 02/27] kconfig: fix off-by-one in zconf_error() Masahiro Yamada
2024-02-02 15:58 ` [PATCH 03/27] kconfig: remove orphan lookup_file() declaration Masahiro Yamada
2024-02-02 15:58 ` [PATCH 04/27] kconfig: remove compat_getline() Masahiro Yamada
2024-02-02 15:58 ` [PATCH 05/27] kconfig: remove unneeded sym_find() call in conf_parse() Masahiro Yamada
2024-02-02 15:58 ` [PATCH 06/27] kconfig: write Kconfig files to autoconf.cmd in order Masahiro Yamada
2024-02-02 15:58 ` [PATCH 07/27] kconfig: call env_write_dep() right after yyparse() Masahiro Yamada
2024-02-02 15:58 ` [PATCH 08/27] kconfig: split preprocessor prototypes into preprocess.h Masahiro Yamada
2024-02-02 15:58 ` Masahiro Yamada [this message]
2024-02-02 15:58 ` [PATCH 10/27] kconfig: remove zconf_curname() and zconf_lineno() Masahiro Yamada
2024-02-02 15:58 ` [PATCH 11/27] kconfig: associate struct menu with file name directly Masahiro Yamada
2024-02-02 15:58 ` [PATCH 12/27] kconfig: associate struct property " Masahiro Yamada
2024-02-02 15:58 ` [PATCH 13/27] kconfig: replace file->name with name in zconf_nextfile() Masahiro Yamada
2024-02-02 15:58 ` [PATCH 14/27] kconfig: do not delay the cur_filename update Masahiro Yamada
2024-02-02 15:58 ` [PATCH 15/27] kconfig: replace remaining current_file->name with cur_filename Masahiro Yamada
2024-02-02 15:58 ` [PATCH 16/27] kconfig: move the file and lineno in struct file to struct buffer Masahiro Yamada
2024-02-02 15:58 ` [PATCH 17/27] kconfig: make file::name a flexible array member Masahiro Yamada
2024-02-02 15:58 ` [PATCH 18/27] kconfig: change file_lookup() to return the file name Masahiro Yamada
2024-02-02 15:58 ` [PATCH 19/27] kconfig: split list_head into a separate header Masahiro Yamada
2024-02-02 15:58 ` [PATCH 20/27] kconfig: resync list.h Masahiro Yamada
2024-02-02 15:58 ` [PATCH 21/27] kconfig: import more list macros and inline functions Masahiro Yamada
2024-02-02 15:58 ` [PATCH 22/27] kconfig: add macros useful for hashtable Masahiro Yamada
2024-02-02 15:58 ` [PATCH 23/27] kconfig: move ARRAY_SIZE to a header Masahiro Yamada
2024-02-02 15:58 ` [PATCH 24/27] kconfig: move strhash() " Masahiro Yamada
2024-02-02 15:58 ` [PATCH 25/27] kconfig: convert linked list of files to hash table Masahiro Yamada
2024-02-02 15:58 ` [PATCH 26/27] kconfig: use generic macros to implement symbol hashtable Masahiro Yamada
2024-02-02 15:58 ` [PATCH 27/27] kconfig: do not imply the type of choice value Masahiro Yamada
2024-02-10 23:47 ` [PATCH 00/27] kconfig: refactor lexer and parser code 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=20240202155825.314567-10-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.