kconfig: replace current_pos with separate cur_{filename,lineno}
authorMasahiro Yamada <masahiroy@kernel.org>
Fri, 2 Feb 2024 15:58:07 +0000 (00:58 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 19 Feb 2024 09:20:40 +0000 (18:20 +0900)
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

index 1bb372868ecf1d65f42f4bd68b7eeaa43ebf1053..540098435a3b1f9e8fed733c70e932ffa3943dad 100644 (file)
 
 #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;
 }