Commit 17defa6a by Zack Weinberg Committed by Zack Weinberg

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
parent 95161faf
2007-03-26 Zack Weinberg <zackw@panix.com> 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. * gengtype.h (struct type): Replace 'sc' with boolean, scalar_is_char.
(string_type): Don't declare. (string_type): Don't declare.
(do_scalar_typedef): Declare. (do_scalar_typedef): Declare.
......
...@@ -171,12 +171,12 @@ ITYPE {IWORD}({WS}{IWORD})* ...@@ -171,12 +171,12 @@ ITYPE {IWORD}({WS}{IWORD})*
for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++) for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
; ;
yylval.t = find_structure ((const char *) xmemdup (tagstart, taglen, yylval.s = (const char *) xmemdup (tagstart, taglen, taglen + 1);
taglen + 1),
union_p);
BEGIN(in_struct); BEGIN(in_struct);
update_lineno (yytext, yyleng); 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" { [^[:alnum:]_](extern|static){WS}/"GTY" {
......
...@@ -35,8 +35,10 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA ...@@ -35,8 +35,10 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
const char *s; const char *s;
} }
%token <t>ENT_TYPEDEF_STRUCT %token <s>ENT_TYPEDEF_STRUCT
%token <t>ENT_STRUCT %token <s>ENT_STRUCT
%token <s>ENT_TYPEDEF_UNION
%token <s>ENT_UNION
%token ENT_EXTERNSTATIC %token ENT_EXTERNSTATIC
%token GTY_TOKEN %token GTY_TOKEN
%token VEC_TOKEN %token VEC_TOKEN
...@@ -68,21 +70,30 @@ start: /* empty */ ...@@ -68,21 +70,30 @@ start: /* empty */
typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID typedef_struct: ENT_TYPEDEF_STRUCT options '{' struct_fields '}' ID
{ {
new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line, type_p t = new_structure ($1, false, &lexer_line, $4, $2);
$4, $2); do_typedef ($6, t, &lexer_line);
do_typedef ($6, $1, &lexer_line);
lexer_toplevel_done = 1; 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 '}' | ENT_STRUCT options '{' struct_fields '}'
{ {
new_structure ($1->u.s.tag, UNION_P ($1), &lexer_line, new_structure ($1, false, &lexer_line, $4, $2);
$4, $2);
lexer_toplevel_done = 1; 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 externstatic: ENT_EXTERNSTATIC options lasttype ID semiequal
...@@ -210,15 +221,7 @@ option: ID ...@@ -210,15 +221,7 @@ option: ID
| type_option '(' type ')' | type_option '(' type ')'
{ $$ = create_option (NULL, $1, adjust_field_type ($3, NULL)); } { $$ = create_option (NULL, $1, adjust_field_type ($3, NULL)); }
| NESTED_PTR '(' type ',' stringseq ',' stringseq ')' | NESTED_PTR '(' type ',' stringseq ',' stringseq ')'
{ { $$ = create_nested_ptr_option ($3, $5, $7); }
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)));
}
; ;
optionseq: option optionseq: option
......
...@@ -330,6 +330,18 @@ create_option (options_p next, const char *name, const void *info) ...@@ -330,6 +330,18 @@ create_option (options_p next, const char *name, const void *info)
return o; 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, /* Add a variable named S of type T with options O defined at POS,
to `variables'. */ to `variables'. */
......
...@@ -139,6 +139,8 @@ extern type_p create_scalar_type (const char *name); ...@@ -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_pointer (type_p t);
extern type_p create_array (type_p t, const char *len); 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_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 type_p adjust_field_type (type_p, options_p);
extern void note_variable (const char *s, type_p t, options_p o, extern void note_variable (const char *s, type_p t, options_p o,
struct fileloc *pos); struct fileloc *pos);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment