Commit ffe08917 by Ian Lance Taylor

Fix handling of structs with embedded global types.

From-SVN: r178870
parent fe0aee6c
...@@ -12640,6 +12640,16 @@ Composite_literal_expression::lower_struct(Gogo* gogo, Type* type) ...@@ -12640,6 +12640,16 @@ Composite_literal_expression::lower_struct(Gogo* gogo, Type* type)
{ {
const Struct_field* sf = st->field(fre->field_index()); const Struct_field* sf = st->field(fre->field_index());
name = sf->field_name(); name = sf->field_name();
// See below. FIXME.
if (!Gogo::is_hidden_name(name)
&& name[0] >= 'a'
&& name[0] <= 'z')
{
if (gogo->lookup_global(name.c_str()) != NULL)
name = gogo->pack_hidden_name(name, false);
}
char buf[20]; char buf[20];
snprintf(buf, sizeof buf, "%u", fre->field_index()); snprintf(buf, sizeof buf, "%u", fre->field_index());
size_t buflen = strlen(buf); size_t buflen = strlen(buf);
...@@ -12671,7 +12681,7 @@ Composite_literal_expression::lower_struct(Gogo* gogo, Type* type) ...@@ -12671,7 +12681,7 @@ Composite_literal_expression::lower_struct(Gogo* gogo, Type* type)
// A predefined name won't be packed. If it starts with a // A predefined name won't be packed. If it starts with a
// lower case letter we need to check for that case, because // lower case letter we need to check for that case, because
// the field name will be packed. // the field name will be packed. FIXME.
if (!Gogo::is_hidden_name(name) if (!Gogo::is_hidden_name(name)
&& name[0] >= 'a' && name[0] >= 'a'
&& name[0] <= 'z') && name[0] <= 'z')
...@@ -13505,7 +13515,10 @@ Struct_field_offset_expression::do_dump_expression( ...@@ -13505,7 +13515,10 @@ Struct_field_offset_expression::do_dump_expression(
Ast_dump_context* ast_dump_context) const Ast_dump_context* ast_dump_context) const
{ {
ast_dump_context->ostream() << "unsafe.Offsetof("; ast_dump_context->ostream() << "unsafe.Offsetof(";
ast_dump_context->ostream() << this->field_->field_name(); ast_dump_context->dump_type(this->type_);
ast_dump_context->ostream() << '.';
ast_dump_context->ostream() <<
Gogo::message_name(this->field_->field_name());
ast_dump_context->ostream() << ")"; ast_dump_context->ostream() << ")";
} }
......
...@@ -1732,6 +1732,10 @@ class Struct_field ...@@ -1732,6 +1732,10 @@ class Struct_field
const std::string& const std::string&
field_name() const; field_name() const;
// Return whether this struct field is named NAME.
bool
is_field_name(const std::string& name) const;
// The field type. // The field type.
Type* Type*
type() const type() const
......
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