Commit 92a87cb7 by Ian Lance Taylor

compiler: Use backend interface for struct field offsets.

From-SVN: r210074
parent 0db74577
...@@ -14815,28 +14815,27 @@ class Struct_field_offset_expression : public Expression ...@@ -14815,28 +14815,27 @@ class Struct_field_offset_expression : public Expression
tree tree
Struct_field_offset_expression::do_get_tree(Translate_context* context) Struct_field_offset_expression::do_get_tree(Translate_context* context)
{ {
tree type_tree = type_to_tree(this->type_->get_backend(context->gogo()));
if (type_tree == error_mark_node)
return error_mark_node;
tree val_type_tree = type_to_tree(this->type()->get_backend(context->gogo()));
go_assert(val_type_tree != error_mark_node);
const Struct_field_list* fields = this->type_->fields(); const Struct_field_list* fields = this->type_->fields();
tree struct_field_tree = TYPE_FIELDS(type_tree);
Struct_field_list::const_iterator p; Struct_field_list::const_iterator p;
unsigned i = 0;
for (p = fields->begin(); for (p = fields->begin();
p != fields->end(); p != fields->end();
++p, struct_field_tree = DECL_CHAIN(struct_field_tree)) ++p, ++i)
{
go_assert(struct_field_tree != NULL_TREE);
if (&*p == this->field_) if (&*p == this->field_)
break; break;
}
go_assert(&*p == this->field_); go_assert(&*p == this->field_);
return fold_convert_loc(BUILTINS_LOCATION, val_type_tree, Gogo* gogo = context->gogo();
byte_position(struct_field_tree)); Btype* btype = this->type_->get_backend(gogo);
size_t offset = gogo->backend()->type_field_offset(btype, i);
mpz_t offsetval;
mpz_init_set_ui(offsetval, offset);
Type* uptr_type = Type::lookup_integer_type("uintptr");
Expression* ret = Expression::make_integer(&offsetval, uptr_type,
Linemap::predeclared_location());
mpz_clear(offsetval);
return ret->get_tree(context);
} }
// Dump ast representation for a struct field offset expression. // Dump ast representation for a struct field offset expression.
......
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