Commit Graph

22 Commits

Author SHA1 Message Date
Masahiro Yamada 5b058034e3 kconfig: change file_lookup() to return the file name
Currently, file_lookup() returns a pointer to (struct file), but the
callers use only file->name.

Make it return the ->name member directly.

This adjustment encapsulates struct file and file_list as internal
implementation.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:41 +09:00
Masahiro Yamada 8facc5f319 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: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:40 +09:00
Masahiro Yamada 4ff7ceae83 kconfig: replace remaining current_file->name with cur_filename
Replace the remaining current_file->name in the lexer context.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:40 +09:00
Masahiro Yamada d3e4a68fe2 kconfig: do not delay the cur_filename update
Currently, cur_filename is updated at the first token of each statement.
However, this seems unnecessary based on my understanding; the parser
can use the same variable as the lexer tracks.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:40 +09:00
Masahiro Yamada fe273c6fc3 kconfig: replace file->name with name in zconf_nextfile()
The 'file->name' and 'name' are the same in this function.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:40 +09:00
Masahiro Yamada 1d7c4f10ba kconfig: remove zconf_curname() and zconf_lineno()
Now zconf_curname() and zconf_lineno() are so simple that they just
return cur_filename, cur_lineno, respectively.

Remove these functions, and then use cur_filename and cur_lineno
directly.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:40 +09:00
Masahiro Yamada 52907c07c4 kconfig: replace current_pos with separate cur_{filename,lineno}
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>
2024-02-19 18:20:40 +09:00
Masahiro Yamada d3d16228a5 kconfig: split preprocessor prototypes into preprocess.h
These are needed only for the parse stage. Move the prototypes into
a separate header to make sure they are not used after that.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:40 +09:00
Masahiro Yamada af8bbce920 kconfig: fix infinite loop when expanding a macro at the end of file
A macro placed at the end of a file with no newline causes an infinite
loop.

[Test Kconfig]
  $(info,hello)
  \ No newline at end of file

I realized that flex-provided input() returns 0 instead of EOF when it
reaches the end of a file.

Fixes: 104daea149 ("kconfig: reference environment variables directly and remove 'option env='")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:40 +09:00
Masahiro Yamada 93c432e8c9 kconfig: fix line number in recursive inclusion detection
The error message shows a wrong line number if the 'source' directive
is wrapped to the following line.

[Test Code]

  source \
  "Kconfig"

This results in the following error message:

  Recursive inclusion detected.
  Inclusion path:
    current file : Kconfig
    included from: Kconfig:2

The correct message should be as follows:

  Recursive inclusion detected.
  Inclusion path:
    current file : Kconfig
    included from: Kconfig:1

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:39 +09:00
Masahiro Yamada 12e3342fc7 kconfig: remove unneeded buffer allocation in zconf_initscan()
In Kconfig, there is a stack to save the lexer state for each inclusion
level.

Currently, it operates as an empty stack, with the 'current_buf' always
pointing to an empty buffer. There is no need to preallocate the buffer.
Change it to a full stack.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-02-19 18:20:39 +09:00
Masahiro Yamada 6988f70cf1 kconfig: rename a variable in the lexer to a clearer name
In Kconfig, like Python, you can enclose a string by double-quotes or
single-quotes. So, both "foo" and 'foo' are allowed.

The variable, "str", is used to remember whether the string started with
a double-quote or a single-quote because open/closing quotation marks
must match.

The name "str" is too generic to understand the intent. Rename it to
"open_quote", which is easier to understand. The type should be 'char'.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Boris Kolpackov <boris@codesynthesis.com>
2021-09-30 02:08:59 +09:00
Masahiro Yamada 65017d8381 kconfig: narrow the scope of variables in the lexer
The variables, "ts" and "i", are used locally in the action of
the [ \t]+ pattern in the <HELP> start state.

Define them where they are used.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-09-30 02:05:10 +09:00
Masahiro Yamada 6dd85ff178 kconfig: change "modules" from sub-option to first-level attribute
Now "modules" is the only member of the "option" property.

Remove "option", and move "modules" to the top level property.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-04-14 15:22:49 +09:00
Masahiro Yamada ab838577aa kconfig: remove allnoconfig_y option
Now that the only user, CONFIG_EMBEDDED has stopped using this option,
remove it entirely.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-04-14 15:22:49 +09:00
Masahiro Yamada b75b0a819a kconfig: change defconfig_list option to environment variable
"defconfig_list" is a weird option that defines a static symbol that
declares the list of base config files in case the .config does not
exist yet.

This is quite different from other normal symbols; we just abused the
"string" type and the "default" properties to list out the input files.
They must be fixed values since these are searched for and loaded in
the parse stage.

It is an ugly hack, and should not exist in the first place. Providing
this feature as an environment variable is a saner approach.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-04-14 15:22:48 +09:00
Boris Kolpackov 78cb090783 kconfig: clean up header inclusion
- Add missing includes.
- Remove no longer necessary includes.

Signed-off-by: Boris Kolpackov <boris@codesynthesis.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2020-12-08 23:31:29 +09:00
Masahiro Yamada d41809ff7a kconfig: add 'static' to some file-local data
Fix some warnings from sparce like follows:

  warning: symbol '...' was not declared. Should it be static?

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2020-08-14 13:30:04 +09:00
Masahiro Yamada f70f74d15c kconfig: remove '---help---' support
The conversion is done. No more user of '---help---'.

Cc: Ulf Magnusson <ulfalizer@gmail.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2020-08-14 13:30:03 +09:00
Jacob Garber b9d1a8e930 kconfig: use snprintf for formatting pathnames
Valid pathnames will never exceed PATH_MAX, but these file names
are unsanitized and can cause buffer overflow if set incorrectly.
Use snprintf to avoid this. This was flagged during a Coverity scan
of the coreboot project, which also uses kconfig for its build system.

Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2019-05-14 23:23:25 +09:00
Masahiro Yamada 769a1c0226 kconfig: rename zconf.y to parser.y
Use a more logical name.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2019-02-13 23:25:58 +09:00
Masahiro Yamada 981e545a69 kconfig: rename zconf.l to lexer.l
Use a more logical name.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2019-02-13 23:25:49 +09:00