kconfig: move the file and lineno in struct file to struct buffer
authorMasahiro Yamada <masahiroy@kernel.org>
Fri, 2 Feb 2024 15:58:14 +0000 (00:58 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 19 Feb 2024 09:20:40 +0000 (18:20 +0900)
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
scripts/kconfig/lexer.l
scripts/kconfig/menu.c

index 037db39..85e0d1a 100644 (file)
@@ -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;
index db2397c..71f651b 100644 (file)
@@ -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 (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);
-               }
+       for (buf = current_buf; buf; buf = buf->parent) {
+               if (!strcmp(buf->filename, name))
+                       recur_include = true;
+       }
+
+       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);
index 0ded0b1..b879576 100644 (file)
@@ -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, ...)
 {