From 17defa6a13ef4f317e22dcb3827b4e8ea1b37541 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Mon, 26 Mar 2007 21:00:20 +0000 Subject: [PATCH] gengtype-lex.l: Distinguish unions from structures in the token type. * gengtype-lex.l: Distinguish unions from structures in the token type. Don't call find_structure; return the tag as a string. * gengtype-yacc.y: Add new token types ENT_TYPEDEF_UNION and ENT_UNION. Type of these, ENT_TYPEDEF_STRUCT, and ENT_STRUCT is string. Reorganize typedef_struct production accordingly. Use create_nested_ptr_option. * gengtype.c (create_nested_ptr_option): New function. * gengtype.h: Declare it. From-SVN: r123232 --- gcc/ChangeLog | 9 +++++++++ gcc/gengtype-lex.l | 8 ++++---- gcc/gengtype-yacc.y | 43 +++++++++++++++++++++++-------------------- gcc/gengtype.c | 12 ++++++++++++ gcc/gengtype.h | 2 ++ 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5bc2cad05d8..385247107fb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,14 @@ 2007-03-26 Zack Weinberg + * gengtype-lex.l: Distinguish unions from structures in the + token type. Don't call find_structure; return the tag as a string. + * gengtype-yacc.y: Add new token types ENT_TYPEDEF_UNION and ENT_UNION. + Type of these, ENT_TYPEDEF_STRUCT, and ENT_STRUCT is string. + Reorganize typedef_struct production accordingly. + Use create_nested_ptr_option. + * gengtype.c (create_nested_ptr_option): New function. + * gengtype.h: Declare it. + * gengtype.h (struct type): Replace 'sc' with boolean, scalar_is_char. (string_type): Don't declare. (do_scalar_typedef): Declare. diff --git a/gcc/gengtype-lex.l b/gcc/gengtype-lex.l index 1d136251e10..baf09bcd5fe 100644 --- a/gcc/gengtype-lex.l +++ b/gcc/gengtype-lex.l @@ -171,12 +171,12 @@ ITYPE {IWORD}({WS}{IWORD})* for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++) ; - yylval.t = find_structure ((const char *) xmemdup (tagstart, taglen, - taglen + 1), - union_p); + yylval.s = (const char *) xmemdup (tagstart, taglen, taglen + 1); + BEGIN(in_struct); update_lineno (yytext, yyleng); - return typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT; + return union_p ? (typedef_p ? ENT_TYPEDEF_UNION : ENT_UNION) + : (typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT); } [^[:alnum:]_](extern|static){WS}/"GTY" { diff --git a/gcc/gengtype-yacc.y b/gcc/gengtype-yacc.y index 40c22efbd33..758bcaae327 100644 --- a/gcc/gengtype-yacc.y +++ b/gcc/gengtype-yacc.y @@ -35,8 +35,10 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA const char *s; } -%token ENT_TYPEDEF_STRUCT -%token ENT_STRUCT +%token ENT_TYPEDEF_STRUCT +%token ENT_STRUCT +%token ENT_TYPEDEF_UNION +%token ENT_UNION %token ENT_EXTERNSTATIC %token GTY_TOKEN %token VEC_TOKEN @@ -68,21 +70,30 @@ start: /* empty */ typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID { - new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line, - $4, $2); - do_typedef ($6, $1, &lexer_line); + type_p t = new_structure ($1, false, &lexer_line, $4, $2); + do_typedef ($6, t, &lexer_line); lexer_toplevel_done = 1; } - ';' - {} + ';' + | ENT_TYPEDEF_UNION options '{' struct_fields '}' ID + { + type_p t = new_structure ($1, true, &lexer_line, $4, $2); + do_typedef ($6, t, &lexer_line); + lexer_toplevel_done = 1; + } + ';' | ENT_STRUCT options '{' struct_fields '}' { - new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line, - $4, $2); + new_structure ($1, false, &lexer_line, $4, $2); lexer_toplevel_done = 1; } - ';' - {} + ';' + | ENT_UNION options '{' struct_fields '}' + { + new_structure ($1, true, &lexer_line, $4, $2); + lexer_toplevel_done = 1; + } + ';' ; externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal @@ -210,15 +221,7 @@ option: ID | type_option '(' type ')' { $$ = create_option (NULL, $1, adjust_field_type ($3, NULL)); } | NESTED_PTR '(' type ',' stringseq ',' stringseq ')' - { - struct nested_ptr_data d; - - d.type = adjust_field_type ($3, NULL); - d.convert_to = $5; - d.convert_from = $7; - $$ = create_option (NULL, "nested_ptr", - xmemdup (&d, sizeof (d), sizeof (d))); - } + { $$ = create_nested_ptr_option ($3, $5, $7); } ; optionseq: option diff --git a/gcc/gengtype.c b/gcc/gengtype.c index 6e9383593ec..86d72d8f0d7 100644 --- a/gcc/gengtype.c +++ b/gcc/gengtype.c @@ -330,6 +330,18 @@ create_option (options_p next, const char *name, const void *info) return o; } +/* Return an options structure for a "nested_ptr" option. */ +options_p +create_nested_ptr_option (type_p t, const char *to, const char *from) +{ + struct nested_ptr_data *d = XNEW (struct nested_ptr_data); + + d->type = adjust_field_type (t, 0); + d->convert_to = to; + d->convert_from = from; + return create_option (NULL, "nested_ptr", d); +} + /* Add a variable named S of type T with options O defined at POS, to `variables'. */ diff --git a/gcc/gengtype.h b/gcc/gengtype.h index 1ee9d3acffb..f803ad3c1ee 100644 --- a/gcc/gengtype.h +++ b/gcc/gengtype.h @@ -139,6 +139,8 @@ extern type_p create_scalar_type (const char *name); extern type_p create_pointer (type_p t); extern type_p create_array (type_p t, const char *len); extern options_p create_option (options_p, const char *name, const void *info); +extern options_p create_nested_ptr_option (type_p t, const char *from, + const char *to); extern type_p adjust_field_type (type_p, options_p); extern void note_variable (const char *s, type_p t, options_p o, struct fileloc *pos);