diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-11-09 00:04:44 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-11-09 00:04:44 +0200 |
commit | 4d75955e833201c4f1d0219d48676521aeee1afa (patch) | |
tree | 56f03526c28bb6ee56d73a57915dc25592c7e47b /src | |
parent | b097ff86951b52a4e34bd0d7e40921e5469c4f5f (diff) | |
download | cflow-4d75955e833201c4f1d0219d48676521aeee1afa.tar.gz cflow-4d75955e833201c4f1d0219d48676521aeee1afa.tar.bz2 |
Fix parsing of typedefs after `struct'.
* src/c.l: Include cflow.h (and, consequently, config.h) at the top
of the generated source.
(prev_token): New static.
(get_token): Set prev_token.
(ident): Treat any valid identifier after struct/union/enum
as identifier (do not attempt any symbol lookup).
Diffstat (limited to 'src')
-rw-r--r-- | src/c.l | 38 |
1 files changed, 28 insertions, 10 deletions
@@ -16,14 +16,17 @@ | |||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | MA 02110-1301 USA */ | 17 | MA 02110-1301 USA */ |
18 | 18 | ||
19 | %top { | ||
20 | #include <cflow.h> | ||
21 | #include <ctype.h> | ||
22 | #include <parser.h> | ||
23 | } | ||
24 | |||
19 | %x comment | 25 | %x comment |
20 | %x string | 26 | %x string |
21 | %x stringwait | 27 | %x stringwait |
22 | %x longline | 28 | %x longline |
23 | %{ | 29 | %{ |
24 | #include <cflow.h> | ||
25 | #include <ctype.h> | ||
26 | #include <parser.h> | ||
27 | 30 | ||
28 | struct obstack string_stk; | 31 | struct obstack string_stk; |
29 | 32 | ||
@@ -37,6 +40,11 @@ int ident(); | |||
37 | void update_loc(); | 40 | void update_loc(); |
38 | #define lex_error(msg) error_at_line(0, 0, filename, line_num, "%s", msg) | 41 | #define lex_error(msg) error_at_line(0, 0, filename, line_num, "%s", msg) |
39 | 42 | ||
43 | /* Keep the token returned at the previous call to yylex. This is used | ||
44 | as a lexical tie-in to ensure that the next token after STRUCT is | ||
45 | IDENTIFIER. See get_token and ident below. */ | ||
46 | static int prev_token; | ||
47 | |||
40 | %} | 48 | %} |
41 | FILENAME [^\n*?]* | 49 | FILENAME [^\n*?]* |
42 | ONUMBER (0[0-7]*) | 50 | ONUMBER (0[0-7]*) |
@@ -221,12 +229,20 @@ init_lex(int debug_level) | |||
221 | int | 229 | int |
222 | ident() | 230 | ident() |
223 | { | 231 | { |
224 | Symbol *sp; | 232 | /* Do not attempt any symbol table lookup if the previous token was |
233 | STRUCT. This helps properly parse constructs like: | ||
225 | 234 | ||
226 | sp = lookup(yytext); | 235 | typedef struct foo foo; |
227 | if (sp && sp->type == SymToken) { | 236 | struct foo { |
228 | yylval.str = sp->name; | 237 | int dummy; |
229 | return sp->token_type; | 238 | }; |
239 | */ | ||
240 | if (prev_token != STRUCT) { | ||
241 | Symbol *sp = lookup(yytext); | ||
242 | if (sp && sp->type == SymToken) { | ||
243 | yylval.str = sp->name; | ||
244 | return sp->token_type; | ||
245 | } | ||
230 | } | 246 | } |
231 | obstack_grow(&string_stk, yytext, yyleng); | 247 | obstack_grow(&string_stk, yytext, yyleng); |
232 | obstack_1grow(&string_stk, 0); | 248 | obstack_1grow(&string_stk, 0); |
@@ -320,7 +336,7 @@ yywrap() | |||
320 | fclose(yyin); | 336 | fclose(yyin); |
321 | yyin = NULL; | 337 | yyin = NULL; |
322 | #ifdef FLEX_SCANNER | 338 | #ifdef FLEX_SCANNER |
323 | yy_delete_buffer(yy_current_buffer); | 339 | yy_delete_buffer(YY_CURRENT_BUFFER); |
324 | #endif | 340 | #endif |
325 | delete_statics(); | 341 | delete_statics(); |
326 | return 1; | 342 | return 1; |
@@ -329,7 +345,9 @@ yywrap() | |||
329 | int | 345 | int |
330 | get_token() | 346 | get_token() |
331 | { | 347 | { |
332 | return yyin ? yylex() : 0; | 348 | int tok = yylex(); |
349 | prev_token = tok; | ||
350 | return tok; | ||
333 | } | 351 | } |
334 | 352 | ||
335 | int | 353 | int |