aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2014-05-05 17:55:03 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2014-05-05 17:55:03 +0000
commit92a87cb7ff2c62403af3fe5d229d51af660c6c73 (patch)
treeb9abd51249fcb5a938371b969f4811570e2ddbb6 /gcc/go/gofrontend
parent0db7457704f3c609c2c01c8f0f4ee3fecac29a74 (diff)
downloadgcc-92a87cb7ff2c62403af3fe5d229d51af660c6c73.zip
gcc-92a87cb7ff2c62403af3fe5d229d51af660c6c73.tar.gz
gcc-92a87cb7ff2c62403af3fe5d229d51af660c6c73.tar.bz2
compiler: Use backend interface for struct field offsets.
From-SVN: r210074
Diffstat (limited to 'gcc/go/gofrontend')
-rw-r--r--gcc/go/gofrontend/expressions.cc31
1 files changed, 15 insertions, 16 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 69af48c..3d44a2b 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -14815,28 +14815,27 @@ class Struct_field_offset_expression : public Expression
tree
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();
- tree struct_field_tree = TYPE_FIELDS(type_tree);
Struct_field_list::const_iterator p;
+ unsigned i = 0;
for (p = fields->begin();
p != fields->end();
- ++p, struct_field_tree = DECL_CHAIN(struct_field_tree))
- {
- go_assert(struct_field_tree != NULL_TREE);
- if (&*p == this->field_)
- break;
- }
+ ++p, ++i)
+ if (&*p == this->field_)
+ break;
go_assert(&*p == this->field_);
- return fold_convert_loc(BUILTINS_LOCATION, val_type_tree,
- byte_position(struct_field_tree));
+ Gogo* gogo = context->gogo();
+ 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.