Commit 71ccd1fc by Richard Kenner

(encode_aggregate_within): New function.

(encode_aggregate): Generates encodings for unions similar to those for
structs except surrounded by parenthesis instead of braces.

From-SVN: r13583
parent ec0bc8b6
/* Implement classes and message passing for Objective C.
Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
Copyright (C) 1992, 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
Contributed by Steve Naroff.
This file is part of GNU CC.
......@@ -6453,23 +6453,19 @@ encode_array (type, curtype, format)
}
static void
encode_aggregate (type, curtype, format)
encode_aggregate_within (type, curtype, format, left, right)
tree type;
int curtype;
int format;
char left;
char right;
{
enum tree_code code = TREE_CODE (type);
switch (code)
{
case RECORD_TYPE:
{
if (obstack_object_size (&util_obstack) > 0
&& *(obstack_next_free (&util_obstack) - 1) == '^')
{
tree name = TYPE_NAME (type);
/* We have a reference; this is a NeXT extension. */
/* we have a reference; this is a NeXT extension. */
if (obstack_object_size (&util_obstack) - curtype == 1
&& format == OBJC_ENCODE_INLINE_DEFS)
......@@ -6479,34 +6475,40 @@ encode_aggregate (type, curtype, format)
if (name && TREE_CODE (name) == IDENTIFIER_NODE)
{
obstack_1grow (&util_obstack, '{');
obstack_1grow (&util_obstack, left);
obstack_grow (&util_obstack,
IDENTIFIER_POINTER (name),
strlen (IDENTIFIER_POINTER (name)));
obstack_1grow (&util_obstack, '=');
}
else
obstack_grow (&util_obstack, "{?=", 3);
{
obstack_1grow (&util_obstack, left);
obstack_grow (&util_obstack, "?=", 2);
}
for ( ; fields; fields = TREE_CHAIN (fields))
encode_field_decl (fields, curtype, format);
obstack_1grow (&util_obstack, '}');
obstack_1grow (&util_obstack, right);
}
else if (name && TREE_CODE (name) == IDENTIFIER_NODE)
{
obstack_1grow (&util_obstack, '{');
obstack_1grow (&util_obstack, left);
obstack_grow (&util_obstack,
IDENTIFIER_POINTER (name),
strlen (IDENTIFIER_POINTER (name)));
obstack_1grow (&util_obstack, '}');
obstack_1grow (&util_obstack, right);
}
else
{
/* We have an untagged structure or a typedef. */
obstack_grow (&util_obstack, "{?}", 3);
obstack_1grow (&util_obstack, left);
obstack_1grow (&util_obstack, '?');
obstack_1grow (&util_obstack, right);
}
}
else
......@@ -6517,12 +6519,11 @@ encode_aggregate (type, curtype, format)
if (format == OBJC_ENCODE_INLINE_DEFS
|| generating_instance_variables)
{
obstack_1grow (&util_obstack, '{');
obstack_1grow (&util_obstack, left);
if (name && TREE_CODE (name) == IDENTIFIER_NODE)
obstack_grow (&util_obstack,
IDENTIFIER_POINTER (name),
strlen (IDENTIFIER_POINTER (name)));
else
obstack_1grow (&util_obstack, '?');
......@@ -6548,12 +6549,12 @@ encode_aggregate (type, curtype, format)
encode_field_decl (fields, curtype, format);
}
obstack_1grow (&util_obstack, '}');
obstack_1grow (&util_obstack, right);
}
else
{
obstack_1grow (&util_obstack, '{');
obstack_1grow (&util_obstack, left);
if (name && TREE_CODE (name) == IDENTIFIER_NODE)
obstack_grow (&util_obstack,
IDENTIFIER_POINTER (name),
......@@ -6562,42 +6563,29 @@ encode_aggregate (type, curtype, format)
/* We have an untagged structure or a typedef. */
obstack_1grow (&util_obstack, '?');
obstack_1grow (&util_obstack, '}');
obstack_1grow (&util_obstack, right);
}
}
break;
}
}
case UNION_TYPE:
{
if (*obstack_next_free (&util_obstack) == '^'
|| format != OBJC_ENCODE_INLINE_DEFS)
static void
encode_aggregate (type, curtype, format)
tree type;
int curtype;
int format;
{
enum tree_code code = TREE_CODE (type);
switch (code)
{
/* We have a reference (this is a NeXT extension)
or we don't want the details. */
if (TYPE_NAME (type)
&& TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
case RECORD_TYPE:
{
obstack_1grow (&util_obstack, '(');
obstack_grow (&util_obstack,
IDENTIFIER_POINTER (TYPE_NAME (type)),
strlen (IDENTIFIER_POINTER (TYPE_NAME (type))));
obstack_1grow (&util_obstack, ')');
}
else
/* We have an untagged structure or a typedef. */
obstack_grow (&util_obstack, "(?)", 3);
encode_aggregate_within(type, curtype, format, '{', '}');
break;
}
else
case UNION_TYPE:
{
tree fields = TYPE_FIELDS (type);
obstack_1grow (&util_obstack, '(');
for ( ; fields; fields = TREE_CHAIN (fields))
encode_field_decl (fields, curtype, format);
obstack_1grow (&util_obstack, ')');
}
encode_aggregate_within(type, curtype, format, '(', ')');
break;
}
......
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