public inbox for linux-kbuild@vger.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 16/27] kconfig: move the file and lineno in struct file to struct buffer
Date: Sat,  3 Feb 2024 00:58:14 +0900	[thread overview]
Message-ID: <20240202155825.314567-17-masahiroy@kernel.org> (raw)
In-Reply-To: <20240202155825.314567-1-masahiroy@kernel.org>

struct file has two link nodes, 'next' and 'parent'.

The former is used to link files in the 'file_list' linked list,
which manages the list of Kconfig files seen so far.

The latter is used to link files in the 'current_file' linked list,
which manages the inclusion ("source") tree.

The latter should be tracked together with the lexer state.

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

 scripts/kconfig/expr.h  |  3 ---
 scripts/kconfig/lexer.l | 50 ++++++++++++++++++-----------------------
 scripts/kconfig/menu.c  |  1 -
 3 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 037db39c5bf0..85e0d1ab3c8a 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -19,9 +19,7 @@ extern "C" {
 
 struct file {
 	struct file *next;
-	struct file *parent;
 	const char *name;
-	int lineno;
 };
 
 typedef enum tristate {
@@ -278,7 +276,6 @@ struct jump_key {
 };
 
 extern struct file *file_list;
-extern struct file *current_file;
 
 extern struct symbol symbol_yes, symbol_no, symbol_mod;
 extern struct symbol *modules_sym;
diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l
index db2397c4e343..71f651bb82ba 100644
--- a/scripts/kconfig/lexer.l
+++ b/scripts/kconfig/lexer.l
@@ -40,6 +40,8 @@ struct buffer {
 	struct buffer *parent;
 	YY_BUFFER_STATE state;
 	int yylineno;
+	const char *filename;
+	int source_lineno;
 };
 
 static struct buffer *current_buf;
@@ -255,7 +257,7 @@ n	[A-Za-z0-9_-]
 		fprintf(stderr, "%s:%d:warning: no new line at end of file\n",
 			cur_filename, yylineno);
 
-	if (current_file) {
+	if (current_buf) {
 		zconf_endfile();
 		return T_EOL;
 	}
@@ -399,19 +401,20 @@ void zconf_initscan(const char *name)
 		exit(1);
 	}
 
-	current_file = file_lookup(name);
-	cur_filename = current_file->name;
+	cur_filename = file_lookup(name)->name;
 	yylineno = 1;
 }
 
 void zconf_nextfile(const char *name)
 {
-	struct file *iter;
 	struct file *file = file_lookup(name);
 	struct buffer *buf = xmalloc(sizeof(*buf));
+	bool recur_include = false;
 
 	buf->state = YY_CURRENT_BUFFER;
 	buf->yylineno = yylineno;
+	buf->filename = cur_filename;
+	buf->source_lineno = cur_lineno;
 	buf->parent = current_buf;
 	current_buf = buf;
 	yyin = zconf_fopen(name);
@@ -422,45 +425,36 @@ void zconf_nextfile(const char *name)
 	}
 	yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
 
-	current_file->lineno = cur_lineno;
-	file->parent = current_file;
+	for (buf = current_buf; buf; buf = buf->parent) {
+		if (!strcmp(buf->filename, name))
+			recur_include = true;
+	}
 
-	for (iter = current_file; iter; iter = iter->parent) {
-		if (!strcmp(iter->name, name)) {
-			fprintf(stderr,
-				"Recursive inclusion detected.\n"
-				"Inclusion path:\n"
-				"  current file : %s\n", name);
-			iter = file;
-			do {
-				iter = iter->parent;
-				fprintf(stderr, "  included from: %s:%d\n",
-					iter->name, iter->lineno);
-			} while (strcmp(iter->name, name));
-			exit(1);
-		}
+	if (recur_include) {
+		fprintf(stderr,
+			"Recursive inclusion detected.\n"
+			"Inclusion path:\n"
+			"  current file : %s\n", name);
+
+		for (buf = current_buf; buf; buf = buf->parent)
+			fprintf(stderr, "  included from: %s:%d\n",
+				buf->filename, buf->source_lineno);
+		exit(1);
 	}
 
 	yylineno = 1;
 	cur_filename = file->name;
-	current_file = file;
 }
 
 static void zconf_endfile(void)
 {
 	struct buffer *tmp;
 
-	current_file = current_file->parent;
-	if (current_file)
-		cur_filename = current_file->name;
-
-	if (!current_buf)
-		return;
-
 	fclose(yyin);
 	yy_delete_buffer(YY_CURRENT_BUFFER);
 	yy_switch_to_buffer(current_buf->state);
 	yylineno = current_buf->yylineno;
+	cur_filename = current_buf->filename;
 	tmp = current_buf;
 	current_buf = current_buf->parent;
 	free(tmp);
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 0ded0b1830d0..b879576d1ab4 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -17,7 +17,6 @@ struct menu rootmenu;
 static struct menu **last_entry_ptr;
 
 struct file *file_list;
-struct file *current_file;
 
 void menu_warn(struct menu *menu, const char *fmt, ...)
 {
-- 
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 ` [PATCH 09/27] kconfig: replace current_pos with separate cur_{filename,lineno} Masahiro Yamada
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 ` Masahiro Yamada [this message]
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-17-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox