diff options
| author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-03-22 13:00:14 -0400 |
|---|---|---|
| committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-03-25 13:04:07 -0400 |
| commit | 18492685e479fd4d8e1dca836f57c11b6800f083 (patch) | |
| tree | aab2d26d2fef07d1b5009645ca16c766e4f7c90d /scripts | |
| parent | 379a8eb8eb1a55344e1cf976fa589a12c68b60a7 (diff) | |
kconfig: use yylineno option instead of manual lineno increments
Tracking the line number by hand is error-prone since you need to
increment it in every \n matching pattern.
If '%option yylineno' is set, flex defines 'yylineno' to contain the
current line number and automatically updates it each time it reads a
\n character. This is much more convenient although the lexer does
not initializes yylineno, so you need to set it to 1 each time you
start reading a new file, and restore it you go back to the previous
file.
I tested this with DEBUG_PARSE, and confirmed the same dump message
was produced.
I removed the perf-report option. Otherwise, I see the following
message:
%option yylineno entails a performance penalty ONLY on rules that
can match newline characters
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/kconfig/lkc.h | 1 | ||||
| -rw-r--r-- | scripts/kconfig/zconf.l | 20 |
2 files changed, 10 insertions, 11 deletions
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 2d5ec2d0e952..f4394af6e4b8 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h | |||
| @@ -68,6 +68,7 @@ struct kconf_id { | |||
| 68 | enum symbol_type stype; | 68 | enum symbol_type stype; |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| 71 | extern int yylineno; | ||
| 71 | void zconfdump(FILE *out); | 72 | void zconfdump(FILE *out); |
| 72 | void zconf_starthelp(void); | 73 | void zconf_starthelp(void); |
| 73 | FILE *zconf_fopen(const char *name); | 74 | FILE *zconf_fopen(const char *name); |
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 29b5d338d6bc..045093d827e1 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | %option nostdinit noyywrap never-interactive full ecs | 1 | %option nostdinit noyywrap never-interactive full ecs |
| 2 | %option 8bit nodefault perf-report perf-report | 2 | %option 8bit nodefault yylineno |
| 3 | %option noinput | 3 | %option noinput |
| 4 | %x COMMAND HELP STRING PARAM | 4 | %x COMMAND HELP STRING PARAM |
| 5 | %{ | 5 | %{ |
| @@ -83,7 +83,6 @@ n [A-Za-z0-9_-] | |||
| 83 | 83 | ||
| 84 | [ \t]*#.*\n | | 84 | [ \t]*#.*\n | |
| 85 | [ \t]*\n { | 85 | [ \t]*\n { |
| 86 | current_file->lineno++; | ||
| 87 | return T_EOL; | 86 | return T_EOL; |
| 88 | } | 87 | } |
| 89 | [ \t]*#.* | 88 | [ \t]*#.* |
| @@ -104,7 +103,7 @@ n [A-Za-z0-9_-] | |||
| 104 | const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); | 103 | const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); |
| 105 | BEGIN(PARAM); | 104 | BEGIN(PARAM); |
| 106 | current_pos.file = current_file; | 105 | current_pos.file = current_file; |
| 107 | current_pos.lineno = current_file->lineno; | 106 | current_pos.lineno = yylineno; |
| 108 | if (id && id->flags & TF_COMMAND) { | 107 | if (id && id->flags & TF_COMMAND) { |
| 109 | yylval.id = id; | 108 | yylval.id = id; |
| 110 | return id->token; | 109 | return id->token; |
| @@ -116,7 +115,6 @@ n [A-Za-z0-9_-] | |||
| 116 | . warn_ignored_character(*yytext); | 115 | . warn_ignored_character(*yytext); |
| 117 | \n { | 116 | \n { |
| 118 | BEGIN(INITIAL); | 117 | BEGIN(INITIAL); |
| 119 | current_file->lineno++; | ||
| 120 | return T_EOL; | 118 | return T_EOL; |
| 121 | } | 119 | } |
| 122 | } | 120 | } |
| @@ -138,7 +136,7 @@ n [A-Za-z0-9_-] | |||
| 138 | new_string(); | 136 | new_string(); |
| 139 | BEGIN(STRING); | 137 | BEGIN(STRING); |
| 140 | } | 138 | } |
| 141 | \n BEGIN(INITIAL); current_file->lineno++; return T_EOL; | 139 | \n BEGIN(INITIAL); return T_EOL; |
| 142 | ({n}|[/.])+ { | 140 | ({n}|[/.])+ { |
| 143 | const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); | 141 | const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); |
| 144 | if (id && id->flags & TF_PARAM) { | 142 | if (id && id->flags & TF_PARAM) { |
| @@ -150,7 +148,7 @@ n [A-Za-z0-9_-] | |||
| 150 | return T_WORD; | 148 | return T_WORD; |
| 151 | } | 149 | } |
| 152 | #.* /* comment */ | 150 | #.* /* comment */ |
| 153 | \\\n current_file->lineno++; | 151 | \\\n ; |
| 154 | [[:blank:]]+ | 152 | [[:blank:]]+ |
| 155 | . warn_ignored_character(*yytext); | 153 | . warn_ignored_character(*yytext); |
| 156 | <<EOF>> { | 154 | <<EOF>> { |
| @@ -187,7 +185,6 @@ n [A-Za-z0-9_-] | |||
| 187 | fprintf(stderr, | 185 | fprintf(stderr, |
| 188 | "%s:%d:warning: multi-line strings not supported\n", | 186 | "%s:%d:warning: multi-line strings not supported\n", |
| 189 | zconf_curname(), zconf_lineno()); | 187 | zconf_curname(), zconf_lineno()); |
| 190 | current_file->lineno++; | ||
| 191 | BEGIN(INITIAL); | 188 | BEGIN(INITIAL); |
| 192 | return T_EOL; | 189 | return T_EOL; |
| 193 | } | 190 | } |
| @@ -220,12 +217,10 @@ n [A-Za-z0-9_-] | |||
| 220 | } | 217 | } |
| 221 | } | 218 | } |
| 222 | [ \t]*\n/[^ \t\n] { | 219 | [ \t]*\n/[^ \t\n] { |
| 223 | current_file->lineno++; | ||
| 224 | zconf_endhelp(); | 220 | zconf_endhelp(); |
| 225 | return T_HELPTEXT; | 221 | return T_HELPTEXT; |
| 226 | } | 222 | } |
| 227 | [ \t]*\n { | 223 | [ \t]*\n { |
| 228 | current_file->lineno++; | ||
| 229 | append_string("\n", 1); | 224 | append_string("\n", 1); |
| 230 | } | 225 | } |
| 231 | [^ \t\n].* { | 226 | [^ \t\n].* { |
| @@ -304,7 +299,7 @@ void zconf_initscan(const char *name) | |||
| 304 | memset(current_buf, 0, sizeof(*current_buf)); | 299 | memset(current_buf, 0, sizeof(*current_buf)); |
| 305 | 300 | ||
| 306 | current_file = file_lookup(name); | 301 | current_file = file_lookup(name); |
| 307 | current_file->lineno = 1; | 302 | yylineno = 1; |
| 308 | } | 303 | } |
| 309 | 304 | ||
| 310 | void zconf_nextfile(const char *name) | 305 | void zconf_nextfile(const char *name) |
| @@ -325,6 +320,7 @@ void zconf_nextfile(const char *name) | |||
| 325 | buf->parent = current_buf; | 320 | buf->parent = current_buf; |
| 326 | current_buf = buf; | 321 | current_buf = buf; |
| 327 | 322 | ||
| 323 | current_file->lineno = yylineno; | ||
| 328 | file->parent = current_file; | 324 | file->parent = current_file; |
| 329 | 325 | ||
| 330 | for (iter = current_file; iter; iter = iter->parent) { | 326 | for (iter = current_file; iter; iter = iter->parent) { |
| @@ -343,7 +339,7 @@ void zconf_nextfile(const char *name) | |||
| 343 | } | 339 | } |
| 344 | } | 340 | } |
| 345 | 341 | ||
| 346 | file->lineno = 1; | 342 | yylineno = 1; |
| 347 | current_file = file; | 343 | current_file = file; |
| 348 | } | 344 | } |
| 349 | 345 | ||
| @@ -352,6 +348,8 @@ static void zconf_endfile(void) | |||
| 352 | struct buffer *parent; | 348 | struct buffer *parent; |
| 353 | 349 | ||
| 354 | current_file = current_file->parent; | 350 | current_file = current_file->parent; |
| 351 | if (current_file) | ||
| 352 | yylineno = current_file->lineno; | ||
| 355 | 353 | ||
| 356 | parent = current_buf->parent; | 354 | parent = current_buf->parent; |
| 357 | if (parent) { | 355 | if (parent) { |
