c-parse.in (component_decl): Support anonymous struct/union.

* c-parse.in (component_decl): Support anonymous struct/union.
        (%expect): Update.
        * c-parse.y: Regenerate.
        * c-parse.c: Likewise.
        * objc/objc-parse.y: Likewise.
        * objc/objc-parse.c: Likewise.
        * c-decl.c (finish_struct): Don't sort the fields.
        (field_decl_cmp): Delete unused function.

Co-Authored-By: Mumit Khan <khan@xraylith.wisc.edu>

From-SVN: r30016
This commit is contained in:
Alastair J. Houghton 1999-10-15 08:42:02 +00:00 committed by Jeff Law
parent e57ad0c815
commit ffc3b0f915
7 changed files with 2202 additions and 2201 deletions

View File

@ -1,3 +1,15 @@
Fri Oct 15 02:37:28 1999 Alastair J. Houghton <ajh8@doc.ic.ac.uk>
Mumit Khan <khan@xraylith.wisc.edu>
* c-parse.in (component_decl): Support anonymous struct/union.
(%expect): Update.
* c-parse.y: Regenerate.
* c-parse.c: Likewise.
* objc/objc-parse.y: Likewise.
* objc/objc-parse.c: Likewise.
* c-decl.c (finish_struct): Don't sort the fields.
(field_decl_cmp): Delete unused function.
Fri Oct 15 01:20:52 1999 Richard Henderson <rth@cygnus.com>
* sparc.md (movsf_const_intreg): Revert last constraint change.

View File

@ -290,7 +290,6 @@ static tree lookup_tag_reverse PROTO((tree));
static tree grokdeclarator PROTO((tree, tree, enum decl_context,
int));
static tree grokparms PROTO((tree, int));
static int field_decl_cmp PROTO((const PTR, const PTR));
static void layout_array_type PROTO((tree));
/* C-specific option variables. */
@ -5287,26 +5286,6 @@ grokfield (filename, line, declarator, declspecs, width)
return value;
}
/* Function to help qsort sort FIELD_DECLs by name order. */
static int
field_decl_cmp (xp, yp)
const PTR xp;
const PTR yp;
{
tree *x = (tree *)xp, *y = (tree *)yp;
if (DECL_NAME (*x) == DECL_NAME (*y))
return 0;
if (DECL_NAME (*x) == NULL)
return -1;
if (DECL_NAME (*y) == NULL)
return 1;
if (DECL_NAME (*x) < DECL_NAME (*y))
return -1;
return 1;
}
/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
FIELDLIST is a chain of FIELD_DECL nodes for the fields.
ATTRIBUTES are attributes to be applied to the structure.
@ -5541,45 +5520,6 @@ finish_struct (t, fieldlist, attributes)
TYPE_FIELDS (t) = fieldlist;
/* If there are lots of fields, sort so we can look through them fast.
We arbitrarily consider 16 or more elts to be "a lot". */
{
int len = 0;
for (x = fieldlist; x; x = TREE_CHAIN (x))
{
if (len > 15)
break;
len += 1;
}
if (len > 15)
{
tree *field_array;
char *space;
len += list_length (x);
/* Use the same allocation policy here that make_node uses, to
ensure that this lives as long as the rest of the struct decl.
All decls in an inline function need to be saved. */
if (ggc_p)
space = ggc_alloc (sizeof (struct lang_type) + len * sizeof (tree));
else if (allocation_temporary_p ())
space = savealloc (sizeof (struct lang_type) + len * sizeof (tree));
else
space = oballoc (sizeof (struct lang_type) + len * sizeof (tree));
TYPE_LANG_SPECIFIC (t) = (struct lang_type *) space;
TYPE_LANG_SPECIFIC (t)->len = len;
field_array = &TYPE_LANG_SPECIFIC (t)->elts[0];
len = 0;
for (x = fieldlist; x; x = TREE_CHAIN (x))
field_array[len++] = x;
qsort (field_array, len, sizeof (tree), field_decl_cmp);
}
}
for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
{
TYPE_FIELDS (x) = TYPE_FIELDS (t);

File diff suppressed because it is too large Load Diff

View File

@ -28,10 +28,10 @@ Boston, MA 02111-1307, USA. */
written by AT&T, but I have never seen it. */
ifobjc
%expect 73
%expect 74
end ifobjc
ifc
%expect 52
%expect 53
end ifc
%{
@ -1598,12 +1598,21 @@ component_decl:
prefix_attributes = TREE_PURPOSE (declspec_stack);
declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2); }
| typed_typespecs
{ if (pedantic)
pedwarn ("ANSI C forbids member declarations with no members");
shadow_tag($1);
$$ = NULL_TREE; }
| nonempty_type_quals setspecs components
| typed_typespecs setspecs save_filename save_lineno maybe_attribute
{
/* Support for unnamed structs or unions as members of
structs or unions (which is [a] useful and [b] supports
MS P-SDK). */
if (pedantic)
pedwarn ("ANSI C doesn't support unnamed structs/unions");
$$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack);
declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2);
}
| nonempty_type_quals setspecs components
{ $$ = $3;
current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack);

View File

@ -28,7 +28,7 @@ Boston, MA 02111-1307, USA. */
/* To whomever it may concern: I have heard that such a thing was once
written by AT&T, but I have never seen it. */
%expect 52
%expect 53
%{
#include "config.h"
@ -1407,12 +1407,21 @@ component_decl:
prefix_attributes = TREE_PURPOSE (declspec_stack);
declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2); }
| typed_typespecs
{ if (pedantic)
pedwarn ("ANSI C forbids member declarations with no members");
shadow_tag($1);
$$ = NULL_TREE; }
| nonempty_type_quals setspecs components
| typed_typespecs setspecs save_filename save_lineno maybe_attribute
{
/* Support for unnamed structs or unions as members of
structs or unions (which is [a] useful and [b] supports
MS P-SDK). */
if (pedantic)
pedwarn ("ANSI C doesn't support unnamed structs/unions");
$$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack);
declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2);
}
| nonempty_type_quals setspecs components
{ $$ = $3;
current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack);

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,7 @@ Boston, MA 02111-1307, USA. */
/* To whomever it may concern: I have heard that such a thing was once
written by AT&T, but I have never seen it. */
%expect 73
%expect 74
%{
#include "config.h"
@ -1537,12 +1537,21 @@ component_decl:
prefix_attributes = TREE_PURPOSE (declspec_stack);
declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2); }
| typed_typespecs
{ if (pedantic)
pedwarn ("ANSI C forbids member declarations with no members");
shadow_tag($1);
$$ = NULL_TREE; }
| nonempty_type_quals setspecs components
| typed_typespecs setspecs save_filename save_lineno maybe_attribute
{
/* Support for unnamed structs or unions as members of
structs or unions (which is [a] useful and [b] supports
MS P-SDK). */
if (pedantic)
pedwarn ("ANSI C doesn't support unnamed structs/unions");
$$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack);
declspec_stack = TREE_CHAIN (declspec_stack);
resume_momentary ($2);
}
| nonempty_type_quals setspecs components
{ $$ = $3;
current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack);