Skip to content

Commit a02f057

Browse files
Roman ZippelLinus Torvalds
authored andcommitted
[PATCH] kconfig: improve error handling in the parser
Add a few error tokens to the parser to catch common errors and print more descriptive error messages. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Cc: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 3370f9f commit a02f057

6 files changed

Lines changed: 515 additions & 421 deletions

File tree

‎scripts/kconfig/lex.zconf.c_shipped‎

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void zconffree (void * );
323323

324324
/* Begin user sect3 */
325325

326-
#define zconfwrap(n) 1
326+
#define zconfwrap() 1
327327
#define YY_SKIP_YYWRAP
328328

329329
typedef unsigned char YY_CHAR;
@@ -686,10 +686,10 @@ struct yy_trans_info
686686
static yyconst flex_int16_t yy_accept[61] =
687687
{ 0,
688688
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
689-
34, 5, 4, 3, 2, 7, 8, 6, 32, 29,
689+
34, 5, 4, 2, 3, 7, 8, 6, 32, 29,
690690
31, 24, 28, 27, 26, 22, 17, 13, 16, 20,
691-
22, 11, 12, 19, 19, 14, 22, 22, 4, 3,
692-
2, 2, 1, 6, 32, 29, 31, 30, 24, 23,
691+
22, 11, 12, 19, 19, 14, 22, 22, 4, 2,
692+
3, 3, 1, 6, 32, 29, 31, 30, 24, 23,
693693
26, 25, 15, 20, 9, 19, 19, 21, 10, 18
694694
} ;
695695

@@ -753,6 +753,11 @@ char *zconftext;
753753

754754
#define START_STRSIZE 16
755755

756+
static struct {
757+
struct file *file;
758+
int lineno;
759+
} current_pos;
760+
756761
static char *text;
757762
static int text_size, text_asize;
758763

@@ -766,7 +771,7 @@ struct buffer *current_buf;
766771
static int last_ts, first_ts;
767772

768773
static void zconf_endhelp(void);
769-
static struct buffer *zconf_endfile(void);
774+
static void zconf_endfile(void);
770775

771776
void new_string(void)
772777
{
@@ -993,17 +998,17 @@ do_action: /* This label is used only to access EOF actions. */
993998
{ /* beginning of action switch */
994999
case 1:
9951000
/* rule 1 can match eol */
996-
YY_RULE_SETUP
997-
current_file->lineno++;
998-
YY_BREAK
9991001
case 2:
1002+
/* rule 2 can match eol */
10001003
YY_RULE_SETUP
1001-
1004+
{
1005+
current_file->lineno++;
1006+
return T_EOL;
1007+
}
10021008
YY_BREAK
10031009
case 3:
1004-
/* rule 3 can match eol */
10051010
YY_RULE_SETUP
1006-
current_file->lineno++; return T_EOL;
1011+
10071012
YY_BREAK
10081013
case 4:
10091014
YY_RULE_SETUP
@@ -1023,8 +1028,10 @@ case 6:
10231028
YY_RULE_SETUP
10241029
{
10251030
struct kconf_id *id = kconf_id_lookup(zconftext, zconfleng);
1031+
BEGIN(PARAM);
1032+
current_pos.file = current_file;
1033+
current_pos.lineno = current_file->lineno;
10261034
if (id && id->flags & TF_COMMAND) {
1027-
BEGIN(PARAM);
10281035
zconflval.id = id;
10291036
return id->token;
10301037
}
@@ -1040,7 +1047,11 @@ YY_RULE_SETUP
10401047
case 8:
10411048
/* rule 8 can match eol */
10421049
YY_RULE_SETUP
1043-
current_file->lineno++; BEGIN(INITIAL);
1050+
{
1051+
BEGIN(INITIAL);
1052+
current_file->lineno++;
1053+
return T_EOL;
1054+
}
10441055
YY_BREAK
10451056

10461057
case 9:
@@ -1246,9 +1257,9 @@ case YY_STATE_EOF(HELP):
12461257
case YY_STATE_EOF(INITIAL):
12471258
case YY_STATE_EOF(COMMAND):
12481259
{
1249-
if (current_buf) {
1260+
if (current_file) {
12501261
zconf_endfile();
1251-
return T_EOF;
1262+
return T_EOL;
12521263
}
12531264
fclose(zconfin);
12541265
yyterminate();
@@ -1958,7 +1969,7 @@ YY_BUFFER_STATE zconf_scan_buffer (char * base, yy_size_t size )
19581969

19591970
/** Setup the input buffer state to scan a string. The next call to zconflex() will
19601971
* scan from a @e copy of @a str.
1961-
* @param str a NUL-terminated string to scan
1972+
* @param yy_str a NUL-terminated string to scan
19621973
*
19631974
* @return the newly allocated buffer state object.
19641975
* @note If you want to scan bytes that may contain NUL values, then use
@@ -2276,7 +2287,7 @@ void zconf_nextfile(const char *name)
22762287
current_file = file;
22772288
}
22782289

2279-
static struct buffer *zconf_endfile(void)
2290+
static void zconf_endfile(void)
22802291
{
22812292
struct buffer *parent;
22822293

@@ -2292,23 +2303,15 @@ static struct buffer *zconf_endfile(void)
22922303
}
22932304
free(current_buf);
22942305
current_buf = parent;
2295-
2296-
return parent;
22972306
}
22982307

22992308
int zconf_lineno(void)
23002309
{
2301-
if (current_buf)
2302-
return current_file->lineno - 1;
2303-
else
2304-
return 0;
2310+
return current_pos.lineno;
23052311
}
23062312

23072313
char *zconf_curname(void)
23082314
{
2309-
if (current_buf)
2310-
return current_file->name;
2311-
else
2312-
return "<none>";
2315+
return current_pos.file ? current_pos.file->name : "<none>";
23132316
}
23142317

‎scripts/kconfig/lkc.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void kconfig_load(void);
7070

7171
/* menu.c */
7272
void menu_init(void);
73-
void menu_add_menu(void);
73+
struct menu *menu_add_menu(void);
7474
void menu_end_menu(void);
7575
void menu_add_entry(struct symbol *sym);
7676
void menu_end_entry(void);

‎scripts/kconfig/menu.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ void menu_end_entry(void)
6161
{
6262
}
6363

64-
void menu_add_menu(void)
64+
struct menu *menu_add_menu(void)
6565
{
66-
current_menu = current_entry;
66+
menu_end_entry();
6767
last_entry_ptr = &current_entry->list;
68+
return current_menu = current_entry;
6869
}
6970

7071
void menu_end_menu(void)

‎scripts/kconfig/zconf.l‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
#define START_STRSIZE 16
2020

21+
static struct {
22+
struct file *file;
23+
int lineno;
24+
} current_pos;
25+
2126
static char *text;
2227
static int text_size, text_asize;
2328

@@ -31,7 +36,7 @@ struct buffer *current_buf;
3136
static int last_ts, first_ts;
3237

3338
static void zconf_endhelp(void);
34-
static struct buffer *zconf_endfile(void);
39+
static void zconf_endfile(void);
3540

3641
void new_string(void)
3742
{
@@ -70,10 +75,13 @@ n [A-Za-z0-9_]
7075
int str = 0;
7176
int ts, i;
7277

73-
[ \t]*#.*\n current_file->lineno++;
78+
[ \t]*#.*\n |
79+
[ \t]*\n {
80+
current_file->lineno++;
81+
return T_EOL;
82+
}
7483
[ \t]*#.*
7584

76-
[ \t]*\n current_file->lineno++; return T_EOL;
7785

7886
[ \t]+ {
7987
BEGIN(COMMAND);
@@ -88,8 +96,10 @@ n [A-Za-z0-9_]
8896
<COMMAND>{
8997
{n}+ {
9098
struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
99+
BEGIN(PARAM);
100+
current_pos.file = current_file;
101+
current_pos.lineno = current_file->lineno;
91102
if (id && id->flags & TF_COMMAND) {
92-
BEGIN(PARAM);
93103
zconflval.id = id;
94104
return id->token;
95105
}
@@ -98,7 +108,11 @@ n [A-Za-z0-9_]
98108
return T_WORD;
99109
}
100110
.
101-
\n current_file->lineno++; BEGIN(INITIAL);
111+
\n {
112+
BEGIN(INITIAL);
113+
current_file->lineno++;
114+
return T_EOL;
115+
}
102116
}
103117

104118
<PARAM>{
@@ -214,9 +228,9 @@ n [A-Za-z0-9_]
214228
}
215229

216230
<<EOF>> {
217-
if (current_buf) {
231+
if (current_file) {
218232
zconf_endfile();
219-
return T_EOF;
233+
return T_EOL;
220234
}
221235
fclose(yyin);
222236
yyterminate();
@@ -307,7 +321,7 @@ void zconf_nextfile(const char *name)
307321
current_file = file;
308322
}
309323

310-
static struct buffer *zconf_endfile(void)
324+
static void zconf_endfile(void)
311325
{
312326
struct buffer *parent;
313327

@@ -323,22 +337,14 @@ static struct buffer *zconf_endfile(void)
323337
}
324338
free(current_buf);
325339
current_buf = parent;
326-
327-
return parent;
328340
}
329341

330342
int zconf_lineno(void)
331343
{
332-
if (current_buf)
333-
return current_file->lineno - 1;
334-
else
335-
return 0;
344+
return current_pos.lineno;
336345
}
337346

338347
char *zconf_curname(void)
339348
{
340-
if (current_buf)
341-
return current_file->name;
342-
else
343-
return "<none>";
349+
return current_pos.file ? current_pos.file->name : "<none>";
344350
}

0 commit comments

Comments
 (0)