Proper support for empty structs and unions.

They now have a single private, void, unnamed member, resulting in a size of
1 word. This makes empty structs useful for typed opaque handles.
This commit is contained in:
Bill Currie 2010-11-17 14:42:21 +09:00
parent e5e560cbaf
commit a623fb53a7
2 changed files with 12 additions and 5 deletions

View file

@ -230,10 +230,18 @@ def
| storage_class simple_def { current_storage = st_global; }
| storage_class '{' simple_defs '}' ';'
{ current_storage = st_global; }
| STRUCT identifier
{ current_struct = new_struct ($2); } '{' struct_defs '}' ';' { }
| UNION identifier
{ current_struct = new_union ($2); } '{' struct_defs '}' ';' { }
| STRUCT identifier { current_struct = new_struct ($2); }
'{' struct_defs '}' ';'
{
if (!current_struct->struct_head)
new_struct_field (current_struct, &type_void, 0, vis_private);
}
| UNION identifier { current_struct = new_union ($2); }
'{' struct_defs '}' ';'
{
if (!current_struct->struct_head)
new_struct_field (current_struct, &type_void, 0, vis_private);
}
| STRUCT identifier ';' { decl_struct ($2); }
| UNION identifier ';' { decl_union ($2); }
| ENUM '{' enum_list opt_comma '}' ';'

View file

@ -225,7 +225,6 @@ check_struct (const char *name, struct_type stype)
struct_t *
decl_struct (const char *name)
{
return check_struct (name, str_struct);
}