gengtype-lex.l: Distinguish unions from structures in the token type.
authorZack Weinberg <zackw@panix.com>
Mon, 26 Mar 2007 21:00:20 +0000 (21:00 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Mon, 26 Mar 2007 21:00:20 +0000 (21:00 +0000)
* 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
gcc/gengtype-lex.l
gcc/gengtype-yacc.y
gcc/gengtype.c
gcc/gengtype.h

index 5bc2cad05d881d2f7d52d1fbc82866ea43d6449a..385247107fbfdebcf33d2679a87b8b3d74a940d3 100644 (file)
@@ -1,5 +1,14 @@
 2007-03-26  Zack Weinberg  <zackw@panix.com>
 
+       * 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.
index 1d136251e1049f01442c67dfb3aaaf37d3645e3c..baf09bcd5fe038d09b0a23c7933928eefcc9d4d3 100644 (file)
@@ -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" {
index 40c22efbd333dd518cf01e757a45771b25b096a4..758bcaae327d029f6a9c262f74d9b59a19835b61 100644 (file)
@@ -35,8 +35,10 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
   const char *s;
 }
 
-%token <t>ENT_TYPEDEF_STRUCT
-%token <t>ENT_STRUCT
+%token <s>ENT_TYPEDEF_STRUCT
+%token <s>ENT_STRUCT
+%token <s>ENT_TYPEDEF_UNION
+%token <s>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
index 6e9383593ecf26f3f6fe2b3808fba66e300819fb..86d72d8f0d7a60bf9b3b539ff8c64cb32ff3934f 100644 (file)
@@ -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'.  */
 
index 1ee9d3acffb93ebc29fae6a42477b91905522321..f803ad3c1ee0d7c4dd1bd1072324526dd04e24ed 100644 (file)
@@ -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);