Commit ffc3b0f9 by Alastair J. Houghton Committed by Jeff Law

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
parent e57ad0c8
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> Fri Oct 15 01:20:52 1999 Richard Henderson <rth@cygnus.com>
* sparc.md (movsf_const_intreg): Revert last constraint change. * sparc.md (movsf_const_intreg): Revert last constraint change.
......
...@@ -290,7 +290,6 @@ static tree lookup_tag_reverse PROTO((tree)); ...@@ -290,7 +290,6 @@ static tree lookup_tag_reverse PROTO((tree));
static tree grokdeclarator PROTO((tree, tree, enum decl_context, static tree grokdeclarator PROTO((tree, tree, enum decl_context,
int)); int));
static tree grokparms PROTO((tree, int)); static tree grokparms PROTO((tree, int));
static int field_decl_cmp PROTO((const PTR, const PTR));
static void layout_array_type PROTO((tree)); static void layout_array_type PROTO((tree));
/* C-specific option variables. */ /* C-specific option variables. */
...@@ -5287,26 +5286,6 @@ grokfield (filename, line, declarator, declspecs, width) ...@@ -5287,26 +5286,6 @@ grokfield (filename, line, declarator, declspecs, width)
return value; 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. /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
FIELDLIST is a chain of FIELD_DECL nodes for the fields. FIELDLIST is a chain of FIELD_DECL nodes for the fields.
ATTRIBUTES are attributes to be applied to the structure. ATTRIBUTES are attributes to be applied to the structure.
...@@ -5541,45 +5520,6 @@ finish_struct (t, fieldlist, attributes) ...@@ -5541,45 +5520,6 @@ finish_struct (t, fieldlist, attributes)
TYPE_FIELDS (t) = fieldlist; 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)) for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
{ {
TYPE_FIELDS (x) = TYPE_FIELDS (t); TYPE_FIELDS (x) = TYPE_FIELDS (t);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -28,10 +28,10 @@ Boston, MA 02111-1307, USA. */ ...@@ -28,10 +28,10 @@ Boston, MA 02111-1307, USA. */
written by AT&T, but I have never seen it. */ written by AT&T, but I have never seen it. */
ifobjc ifobjc
%expect 73 %expect 74
end ifobjc end ifobjc
ifc ifc
%expect 52 %expect 53
end ifc end ifc
%{ %{
...@@ -1598,12 +1598,21 @@ component_decl: ...@@ -1598,12 +1598,21 @@ 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 maybe_attribute
{ if (pedantic) {
pedwarn ("ANSI C forbids member declarations with no members"); /* Support for unnamed structs or unions as members of
shadow_tag($1); structs or unions (which is [a] useful and [b] supports
$$ = NULL_TREE; } MS P-SDK). */
| nonempty_type_quals setspecs components 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; { $$ = $3;
current_declspecs = TREE_VALUE (declspec_stack); current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack); prefix_attributes = TREE_PURPOSE (declspec_stack);
......
...@@ -28,7 +28,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -28,7 +28,7 @@ Boston, MA 02111-1307, USA. */
/* To whomever it may concern: I have heard that such a thing was once /* To whomever it may concern: I have heard that such a thing was once
written by AT&T, but I have never seen it. */ written by AT&T, but I have never seen it. */
%expect 52 %expect 53
%{ %{
#include "config.h" #include "config.h"
...@@ -1407,12 +1407,21 @@ component_decl: ...@@ -1407,12 +1407,21 @@ 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 maybe_attribute
{ if (pedantic) {
pedwarn ("ANSI C forbids member declarations with no members"); /* Support for unnamed structs or unions as members of
shadow_tag($1); structs or unions (which is [a] useful and [b] supports
$$ = NULL_TREE; } MS P-SDK). */
| nonempty_type_quals setspecs components 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; { $$ = $3;
current_declspecs = TREE_VALUE (declspec_stack); current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack); prefix_attributes = TREE_PURPOSE (declspec_stack);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -28,7 +28,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -28,7 +28,7 @@ Boston, MA 02111-1307, USA. */
/* To whomever it may concern: I have heard that such a thing was once /* To whomever it may concern: I have heard that such a thing was once
written by AT&T, but I have never seen it. */ written by AT&T, but I have never seen it. */
%expect 73 %expect 74
%{ %{
#include "config.h" #include "config.h"
...@@ -1537,12 +1537,21 @@ component_decl: ...@@ -1537,12 +1537,21 @@ 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 maybe_attribute
{ if (pedantic) {
pedwarn ("ANSI C forbids member declarations with no members"); /* Support for unnamed structs or unions as members of
shadow_tag($1); structs or unions (which is [a] useful and [b] supports
$$ = NULL_TREE; } MS P-SDK). */
| nonempty_type_quals setspecs components 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; { $$ = $3;
current_declspecs = TREE_VALUE (declspec_stack); current_declspecs = TREE_VALUE (declspec_stack);
prefix_attributes = TREE_PURPOSE (declspec_stack); prefix_attributes = TREE_PURPOSE (declspec_stack);
......
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