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
This commit is contained in:
Zack Weinberg 2007-03-26 21:00:20 +00:00 committed by Zack Weinberg
parent 95161faf6d
commit 17defa6a13
5 changed files with 50 additions and 24 deletions

View 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.

View 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" {

View 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

View 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'. */

View 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);