Add support for anonymous structs/unions (#21)

This commit is contained in:
pixel-stuck 2022-02-22 07:08:46 -05:00 committed by GitHub
parent 8c569243c3
commit 0e70194617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 697 additions and 704 deletions

1388
c-parse.c

File diff suppressed because it is too large Load Diff

View File

@ -1278,7 +1278,7 @@ notype_declarator:
structsp: structsp:
STRUCT identifier '{' STRUCT identifier '{'
{ $$ = start_struct (RECORD_TYPE, $2); { $<ttype>$ = start_struct (RECORD_TYPE, $2);
/* Start scope of tag before parsing components. */ /* Start scope of tag before parsing components. */
} }
component_decl_list '}' maybe_attribute component_decl_list '}' maybe_attribute
@ -1290,7 +1290,7 @@ structsp:
| STRUCT identifier | STRUCT identifier
{ $$ = xref_tag (RECORD_TYPE, $2); } { $$ = xref_tag (RECORD_TYPE, $2); }
| UNION identifier '{' | UNION identifier '{'
{ $$ = start_struct (UNION_TYPE, $2); } { $<ttype>$ = start_struct (UNION_TYPE, $2); }
component_decl_list '}' maybe_attribute component_decl_list '}' maybe_attribute
{ $$ = finish_struct ($<ttype>4, $5, $7); } { $$ = finish_struct ($<ttype>4, $5, $7); }
| UNION '{' component_decl_list '}' maybe_attribute | UNION '{' component_decl_list '}' maybe_attribute
@ -1301,13 +1301,13 @@ structsp:
{ $$ = xref_tag (UNION_TYPE, $2); } { $$ = xref_tag (UNION_TYPE, $2); }
| ENUM identifier '{' | ENUM identifier '{'
{ $<itype>3 = suspend_momentary (); { $<itype>3 = suspend_momentary ();
$$ = start_enum ($2); } $<ttype>$ = start_enum ($2); }
enumlist maybecomma_warn '}' maybe_attribute enumlist maybecomma_warn '}' maybe_attribute
{ $$ = finish_enum ($<ttype>4, nreverse ($5), $8); { $$ = finish_enum ($<ttype>4, nreverse ($5), $8);
resume_momentary ($<itype>3); } resume_momentary ($<itype>3); }
| ENUM '{' | ENUM '{'
{ $<itype>2 = suspend_momentary (); { $<itype>2 = suspend_momentary ();
$$ = start_enum (NULL_TREE); } $<ttype>$ = start_enum (NULL_TREE); }
enumlist maybecomma_warn '}' maybe_attribute enumlist maybecomma_warn '}' maybe_attribute
{ $$ = finish_enum ($<ttype>3, nreverse ($4), $7); { $$ = finish_enum ($<ttype>3, nreverse ($4), $7);
resume_momentary ($<itype>2); } resume_momentary ($<itype>2); }
@ -1359,11 +1359,10 @@ component_decl:
prefix_attributes = TREE_PURPOSE (declspec_stack); prefix_attributes = TREE_PURPOSE (declspec_stack);
declspec_stack = TREE_CHAIN (declspec_stack); declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2); } resume_momentary ($2); }
| typed_typespecs | typed_typespecs setspecs save_filename save_lineno
{ if (pedantic) { if (pedantic)
pedwarn ("ANSI C forbids member declarations with no members"); pedwarn ("ANSI C forbids member declarations with no members");
shadow_tag($1); $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE); }
$$ = NULL_TREE; }
| nonempty_type_quals setspecs components | nonempty_type_quals setspecs components
{ $$ = $3; { $$ = $3;
current_declspecs = TREE_VALUE (declspec_stack); current_declspecs = TREE_VALUE (declspec_stack);