mpfr_clear(imag);
}
- if (type->is_slice_type() && type->named_type() == NULL)
+ if (type->is_slice_type())
{
Type* element_type = type->array_type()->element_type()->forwarded();
bool is_byte = element_type == Type::lookup_integer_type("uint8");
integer_type_node,
fold_convert(integer_type_node, expr_tree));
}
- else if (type->is_string_type()
- && (expr_type->array_type() != NULL
- || (expr_type->points_to() != NULL
- && expr_type->points_to()->array_type() != NULL)))
+ else if (type->is_string_type() && expr_type->is_slice_type())
{
- Type* t = expr_type;
- if (t->points_to() != NULL)
- {
- t = t->points_to();
- expr_tree = build_fold_indirect_ref(expr_tree);
- }
if (!DECL_P(expr_tree))
expr_tree = save_expr(expr_tree);
- Array_type* a = t->array_type();
+ Array_type* a = expr_type->array_type();
Type* e = a->element_type()->forwarded();
go_assert(e->integer_type() != NULL);
tree valptr = fold_convert(const_ptr_type_node,
if (e->integer_type()->is_unsigned()
&& e->integer_type()->bits() == 8)
{
- static tree string_to_byte_array_fndecl;
+ tree string_to_byte_array_fndecl = NULL_TREE;
ret = Gogo::call_builtin(&string_to_byte_array_fndecl,
this->location(),
"__go_string_to_byte_array",
else
{
go_assert(e == Type::lookup_integer_type("int"));
- static tree string_to_int_array_fndecl;
+ tree string_to_int_array_fndecl = NULL_TREE;
ret = Gogo::call_builtin(&string_to_int_array_fndecl,
this->location(),
"__go_string_to_int_array",
}
}
+ Type *pt = type->points_to();
+ bool is_pointer = false;
+ if (pt != NULL)
+ {
+ is_pointer = true;
+ type = pt;
+ }
+
+ Expression* ret;
if (type->is_error())
return Expression::make_error(this->location());
else if (type->struct_type() != NULL)
- return this->lower_struct(gogo, type);
+ ret = this->lower_struct(gogo, type);
else if (type->array_type() != NULL)
- return this->lower_array(type);
+ ret = this->lower_array(type);
else if (type->map_type() != NULL)
- return this->lower_map(gogo, function, inserter, type);
+ ret = this->lower_map(gogo, function, inserter, type);
else
{
error_at(this->location(),
"for composite literal"));
return Expression::make_error(this->location());
}
+
+ if (is_pointer)
+ ret = Expression::make_heap_composite(ret, this->location());
+
+ return ret;
}
// Lower a struct composite literal.
Struct_type* st = type->struct_type();
if (this->vals_ == NULL || !this->has_keys_)
{
- if (this->vals_ != NULL && !this->vals_->empty())
+ if (this->vals_ != NULL
+ && !this->vals_->empty()
+ && type->named_type() != NULL
+ && type->named_type()->named_object()->package() != NULL)
{
- std::string reason;
- if (type->has_hidden_fields(NULL, &reason))
+ for (Struct_field_list::const_iterator pf = st->fields()->begin();
+ pf != st->fields()->end();
+ ++pf)
{
- if (reason.empty())
+ if (Gogo::is_hidden_name(pf->field_name()))
error_at(this->location(),
- "implicit assignment of hidden field");
- else
- error_at(this->location(), "%s", reason.c_str());
+ "assignment of unexported field %qs in %qs literal",
+ Gogo::message_name(pf->field_name()).c_str(),
+ type->named_type()->message_name().c_str());
}
}