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>
This commit is contained in:
parent
379a8eb8eb
commit
18492685e4
|
@ -68,6 +68,7 @@ struct kconf_id {
|
||||||
enum symbol_type stype;
|
enum symbol_type stype;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern int yylineno;
|
||||||
void zconfdump(FILE *out);
|
void zconfdump(FILE *out);
|
||||||
void zconf_starthelp(void);
|
void zconf_starthelp(void);
|
||||||
FILE *zconf_fopen(const char *name);
|
FILE *zconf_fopen(const char *name);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
%option nostdinit noyywrap never-interactive full ecs
|
%option nostdinit noyywrap never-interactive full ecs
|
||||||
%option 8bit nodefault perf-report perf-report
|
%option 8bit nodefault yylineno
|
||||||
%option noinput
|
%option noinput
|
||||||
%x COMMAND HELP STRING PARAM
|
%x COMMAND HELP STRING PARAM
|
||||||
%{
|
%{
|
||||||
|
@ -83,7 +83,6 @@ n [A-Za-z0-9_-]
|
||||||
|
|
||||||
[ \t]*#.*\n |
|
[ \t]*#.*\n |
|
||||||
[ \t]*\n {
|
[ \t]*\n {
|
||||||
current_file->lineno++;
|
|
||||||
return T_EOL;
|
return T_EOL;
|
||||||
}
|
}
|
||||||
[ \t]*#.*
|
[ \t]*#.*
|
||||||
|
@ -104,7 +103,7 @@ n [A-Za-z0-9_-]
|
||||||
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
|
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
|
||||||
BEGIN(PARAM);
|
BEGIN(PARAM);
|
||||||
current_pos.file = current_file;
|
current_pos.file = current_file;
|
||||||
current_pos.lineno = current_file->lineno;
|
current_pos.lineno = yylineno;
|
||||||
if (id && id->flags & TF_COMMAND) {
|
if (id && id->flags & TF_COMMAND) {
|
||||||
yylval.id = id;
|
yylval.id = id;
|
||||||
return id->token;
|
return id->token;
|
||||||
|
@ -116,7 +115,6 @@ n [A-Za-z0-9_-]
|
||||||
. warn_ignored_character(*yytext);
|
. warn_ignored_character(*yytext);
|
||||||
\n {
|
\n {
|
||||||
BEGIN(INITIAL);
|
BEGIN(INITIAL);
|
||||||
current_file->lineno++;
|
|
||||||
return T_EOL;
|
return T_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +136,7 @@ n [A-Za-z0-9_-]
|
||||||
new_string();
|
new_string();
|
||||||
BEGIN(STRING);
|
BEGIN(STRING);
|
||||||
}
|
}
|
||||||
\n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
|
\n BEGIN(INITIAL); return T_EOL;
|
||||||
({n}|[/.])+ {
|
({n}|[/.])+ {
|
||||||
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
|
const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
|
||||||
if (id && id->flags & TF_PARAM) {
|
if (id && id->flags & TF_PARAM) {
|
||||||
|
@ -150,7 +148,7 @@ n [A-Za-z0-9_-]
|
||||||
return T_WORD;
|
return T_WORD;
|
||||||
}
|
}
|
||||||
#.* /* comment */
|
#.* /* comment */
|
||||||
\\\n current_file->lineno++;
|
\\\n ;
|
||||||
[[:blank:]]+
|
[[:blank:]]+
|
||||||
. warn_ignored_character(*yytext);
|
. warn_ignored_character(*yytext);
|
||||||
<<EOF>> {
|
<<EOF>> {
|
||||||
|
@ -187,7 +185,6 @@ n [A-Za-z0-9_-]
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s:%d:warning: multi-line strings not supported\n",
|
"%s:%d:warning: multi-line strings not supported\n",
|
||||||
zconf_curname(), zconf_lineno());
|
zconf_curname(), zconf_lineno());
|
||||||
current_file->lineno++;
|
|
||||||
BEGIN(INITIAL);
|
BEGIN(INITIAL);
|
||||||
return T_EOL;
|
return T_EOL;
|
||||||
}
|
}
|
||||||
|
@ -220,12 +217,10 @@ n [A-Za-z0-9_-]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[ \t]*\n/[^ \t\n] {
|
[ \t]*\n/[^ \t\n] {
|
||||||
current_file->lineno++;
|
|
||||||
zconf_endhelp();
|
zconf_endhelp();
|
||||||
return T_HELPTEXT;
|
return T_HELPTEXT;
|
||||||
}
|
}
|
||||||
[ \t]*\n {
|
[ \t]*\n {
|
||||||
current_file->lineno++;
|
|
||||||
append_string("\n", 1);
|
append_string("\n", 1);
|
||||||
}
|
}
|
||||||
[^ \t\n].* {
|
[^ \t\n].* {
|
||||||
|
@ -304,7 +299,7 @@ void zconf_initscan(const char *name)
|
||||||
memset(current_buf, 0, sizeof(*current_buf));
|
memset(current_buf, 0, sizeof(*current_buf));
|
||||||
|
|
||||||
current_file = file_lookup(name);
|
current_file = file_lookup(name);
|
||||||
current_file->lineno = 1;
|
yylineno = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zconf_nextfile(const char *name)
|
void zconf_nextfile(const char *name)
|
||||||
|
@ -325,6 +320,7 @@ void zconf_nextfile(const char *name)
|
||||||
buf->parent = current_buf;
|
buf->parent = current_buf;
|
||||||
current_buf = buf;
|
current_buf = buf;
|
||||||
|
|
||||||
|
current_file->lineno = yylineno;
|
||||||
file->parent = current_file;
|
file->parent = current_file;
|
||||||
|
|
||||||
for (iter = current_file; iter; iter = iter->parent) {
|
for (iter = current_file; iter; iter = iter->parent) {
|
||||||
|
@ -343,7 +339,7 @@ void zconf_nextfile(const char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file->lineno = 1;
|
yylineno = 1;
|
||||||
current_file = file;
|
current_file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,6 +348,8 @@ static void zconf_endfile(void)
|
||||||
struct buffer *parent;
|
struct buffer *parent;
|
||||||
|
|
||||||
current_file = current_file->parent;
|
current_file = current_file->parent;
|
||||||
|
if (current_file)
|
||||||
|
yylineno = current_file->lineno;
|
||||||
|
|
||||||
parent = current_buf->parent;
|
parent = current_buf->parent;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
|
Loading…
Reference in New Issue