Commit 8facc5f3 authored by Masahiro Yamada's avatar Masahiro Yamada

kconfig: move the file and lineno in struct file to struct buffer

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: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 4ff7ceae
...@@ -19,9 +19,7 @@ extern "C" { ...@@ -19,9 +19,7 @@ extern "C" {
struct file { struct file {
struct file *next; struct file *next;
struct file *parent;
const char *name; const char *name;
int lineno;
}; };
typedef enum tristate { typedef enum tristate {
...@@ -278,7 +276,6 @@ struct jump_key { ...@@ -278,7 +276,6 @@ struct jump_key {
}; };
extern struct file *file_list; extern struct file *file_list;
extern struct file *current_file;
extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol symbol_yes, symbol_no, symbol_mod;
extern struct symbol *modules_sym; extern struct symbol *modules_sym;
......
...@@ -40,6 +40,8 @@ struct buffer { ...@@ -40,6 +40,8 @@ struct buffer {
struct buffer *parent; struct buffer *parent;
YY_BUFFER_STATE state; YY_BUFFER_STATE state;
int yylineno; int yylineno;
const char *filename;
int source_lineno;
}; };
static struct buffer *current_buf; static struct buffer *current_buf;
...@@ -255,7 +257,7 @@ n [A-Za-z0-9_-] ...@@ -255,7 +257,7 @@ n [A-Za-z0-9_-]
fprintf(stderr, "%s:%d:warning: no new line at end of file\n", fprintf(stderr, "%s:%d:warning: no new line at end of file\n",
cur_filename, yylineno); cur_filename, yylineno);
if (current_file) { if (current_buf) {
zconf_endfile(); zconf_endfile();
return T_EOL; return T_EOL;
} }
...@@ -399,19 +401,20 @@ void zconf_initscan(const char *name) ...@@ -399,19 +401,20 @@ void zconf_initscan(const char *name)
exit(1); exit(1);
} }
current_file = file_lookup(name); cur_filename = file_lookup(name)->name;
cur_filename = current_file->name;
yylineno = 1; yylineno = 1;
} }
void zconf_nextfile(const char *name) void zconf_nextfile(const char *name)
{ {
struct file *iter;
struct file *file = file_lookup(name); struct file *file = file_lookup(name);
struct buffer *buf = xmalloc(sizeof(*buf)); struct buffer *buf = xmalloc(sizeof(*buf));
bool recur_include = false;
buf->state = YY_CURRENT_BUFFER; buf->state = YY_CURRENT_BUFFER;
buf->yylineno = yylineno; buf->yylineno = yylineno;
buf->filename = cur_filename;
buf->source_lineno = cur_lineno;
buf->parent = current_buf; buf->parent = current_buf;
current_buf = buf; current_buf = buf;
yyin = zconf_fopen(name); yyin = zconf_fopen(name);
...@@ -422,45 +425,36 @@ void zconf_nextfile(const char *name) ...@@ -422,45 +425,36 @@ void zconf_nextfile(const char *name)
} }
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
current_file->lineno = cur_lineno; for (buf = current_buf; buf; buf = buf->parent) {
file->parent = current_file; if (!strcmp(buf->filename, name))
recur_include = true;
for (iter = current_file; iter; iter = iter->parent) { }
if (!strcmp(iter->name, name)) {
fprintf(stderr, if (recur_include) {
"Recursive inclusion detected.\n" fprintf(stderr,
"Inclusion path:\n" "Recursive inclusion detected.\n"
" current file : %s\n", name); "Inclusion path:\n"
iter = file; " current file : %s\n", name);
do {
iter = iter->parent; for (buf = current_buf; buf; buf = buf->parent)
fprintf(stderr, " included from: %s:%d\n", fprintf(stderr, " included from: %s:%d\n",
iter->name, iter->lineno); buf->filename, buf->source_lineno);
} while (strcmp(iter->name, name)); exit(1);
exit(1);
}
} }
yylineno = 1; yylineno = 1;
cur_filename = file->name; cur_filename = file->name;
current_file = file;
} }
static void zconf_endfile(void) static void zconf_endfile(void)
{ {
struct buffer *tmp; struct buffer *tmp;
current_file = current_file->parent;
if (current_file)
cur_filename = current_file->name;
if (!current_buf)
return;
fclose(yyin); fclose(yyin);
yy_delete_buffer(YY_CURRENT_BUFFER); yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(current_buf->state); yy_switch_to_buffer(current_buf->state);
yylineno = current_buf->yylineno; yylineno = current_buf->yylineno;
cur_filename = current_buf->filename;
tmp = current_buf; tmp = current_buf;
current_buf = current_buf->parent; current_buf = current_buf->parent;
free(tmp); free(tmp);
......
...@@ -17,7 +17,6 @@ struct menu rootmenu; ...@@ -17,7 +17,6 @@ struct menu rootmenu;
static struct menu **last_entry_ptr; static struct menu **last_entry_ptr;
struct file *file_list; struct file *file_list;
struct file *current_file;
void menu_warn(struct menu *menu, const char *fmt, ...) void menu_warn(struct menu *menu, const char *fmt, ...)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment