Commit 53febcba by Ian Lance Taylor Committed by Ian Lance Taylor

godump.c (go_format_type): Output the first field with a usable Go type, if any.

	* godump.c (go_format_type): Output the first field with a usable
	Go type, if any.

From-SVN: r174262
parent 7d7766a0
2011-05-25 Ian Lance Taylor <iant@google.com> 2011-05-25 Ian Lance Taylor <iant@google.com>
* godump.c (go_format_type): Output the first field with a usable
Go type, if any.
2011-05-25 Ian Lance Taylor <iant@google.com>
* godump.c (go_format_type): Check for invalid type names, pointer * godump.c (go_format_type): Check for invalid type names, pointer
target types, and struct field types. target types, and struct field types.
......
...@@ -685,6 +685,17 @@ go_format_type (struct godump_container *container, tree type, ...@@ -685,6 +685,17 @@ go_format_type (struct godump_container *container, tree type,
field != NULL_TREE; field != NULL_TREE;
field = TREE_CHAIN (field)) field = TREE_CHAIN (field))
{ {
struct obstack hold_type_obstack;
bool field_ok;
if (TREE_CODE (type) == UNION_TYPE)
{
hold_type_obstack = container->type_obstack;
obstack_init (&container->type_obstack);
}
field_ok = true;
if (DECL_NAME (field) == NULL) if (DECL_NAME (field) == NULL)
{ {
char buf[100]; char buf[100];
...@@ -711,7 +722,7 @@ go_format_type (struct godump_container *container, tree type, ...@@ -711,7 +722,7 @@ go_format_type (struct godump_container *container, tree type,
if (DECL_BIT_FIELD (field)) if (DECL_BIT_FIELD (field))
{ {
obstack_grow (ob, "INVALID-bit-field", 17); obstack_grow (ob, "INVALID-bit-field", 17);
ret = false; field_ok = false;
} }
else else
{ {
...@@ -734,7 +745,7 @@ go_format_type (struct godump_container *container, tree type, ...@@ -734,7 +745,7 @@ go_format_type (struct godump_container *container, tree type,
IDENTIFIER_POINTER (name), IDENTIFIER_POINTER (name),
NO_INSERT); NO_INSERT);
if (slot != NULL) if (slot != NULL)
ret = false; field_ok = false;
obstack_1grow (ob, '_'); obstack_1grow (ob, '_');
go_append_string (ob, name); go_append_string (ob, name);
...@@ -743,16 +754,40 @@ go_format_type (struct godump_container *container, tree type, ...@@ -743,16 +754,40 @@ go_format_type (struct godump_container *container, tree type,
{ {
if (!go_format_type (container, TREE_TYPE (field), true, if (!go_format_type (container, TREE_TYPE (field), true,
false)) false))
ret = false; field_ok = false;
} }
} }
obstack_grow (ob, "; ", 2); obstack_grow (ob, "; ", 2);
/* Only output the first field of a union, and hope for /* Only output the first successful field of a union, and
the best. */ hope for the best. */
if (TREE_CODE (type) == UNION_TYPE) if (TREE_CODE (type) == UNION_TYPE)
{
if (!field_ok && TREE_CHAIN (field) == NULL_TREE)
{
field_ok = true;
ret = false;
}
if (field_ok)
{
unsigned int sz;
sz = obstack_object_size (&container->type_obstack);
obstack_grow (&hold_type_obstack,
obstack_base (&container->type_obstack),
sz);
}
obstack_free (&container->type_obstack, NULL);
container->type_obstack = hold_type_obstack;
if (field_ok)
break; break;
} }
else
{
if (!field_ok)
ret = false;
}
}
obstack_1grow (ob, '}'); obstack_1grow (ob, '}');
} }
break; 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