aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-05-20 00:18:15 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-05-20 00:18:15 +0000
commit9ff56c9570642711d5b7ab29920ecf5dbff14a27 (patch)
treec891bdec1e6f073f73fedeef23718bc3ac30d499 /gcc
parent37cb25ed7acdb844b218231130e54b8b7a0ff6e6 (diff)
downloadgcc-9ff56c9570642711d5b7ab29920ecf5dbff14a27.zip
gcc-9ff56c9570642711d5b7ab29920ecf5dbff14a27.tar.gz
gcc-9ff56c9570642711d5b7ab29920ecf5dbff14a27.tar.bz2
Update to current version of Go library.
From-SVN: r173931
Diffstat (limited to 'gcc')
-rw-r--r--gcc/go/gofrontend/types.cc61
-rw-r--r--gcc/go/gofrontend/types.h2
-rw-r--r--gcc/testsuite/go.test/test/convert.go2
-rw-r--r--gcc/testsuite/go.test/test/fixedbugs/bug177.go25
-rw-r--r--gcc/testsuite/go.test/test/fixedbugs/bug248.dir/bug2.go4
-rw-r--r--gcc/testsuite/go.test/test/interface/fake.go26
-rw-r--r--gcc/testsuite/go.test/test/ken/cplx3.go6
7 files changed, 79 insertions, 47 deletions
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index e33b349..bf19216 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -1432,7 +1432,7 @@ Type::methods_constructor(Gogo* gogo, Type* methods_type,
p != smethods.end();
++p)
vals->push_back(this->method_constructor(gogo, method_type, p->first,
- p->second));
+ p->second, only_value_methods));
return Expression::make_slice_composite_literal(methods_type, vals, bloc);
}
@@ -1444,7 +1444,8 @@ Type::methods_constructor(Gogo* gogo, Type* methods_type,
Expression*
Type::method_constructor(Gogo*, Type* method_type,
const std::string& method_name,
- const Method* m) const
+ const Method* m,
+ bool only_value_methods) const
{
source_location bloc = BUILTINS_LOCATION;
@@ -1487,6 +1488,25 @@ Type::method_constructor(Gogo*, Type* method_type,
++p;
go_assert(p->field_name() == "typ");
+ if (!only_value_methods && m->is_value_method())
+ {
+ // This is a value method on a pointer type. Change the type of
+ // the method to use a pointer receiver. The implementation
+ // always uses a pointer receiver anyhow.
+ Type* rtype = mtype->receiver()->type();
+ Type* prtype = Type::make_pointer_type(rtype);
+ Typed_identifier* receiver =
+ new Typed_identifier(mtype->receiver()->name(), prtype,
+ mtype->receiver()->location());
+ mtype = Type::make_function_type(receiver,
+ (mtype->parameters() == NULL
+ ? NULL
+ : mtype->parameters()->copy()),
+ (mtype->results() == NULL
+ ? NULL
+ : mtype->results()->copy()),
+ mtype->location());
+ }
vals->push_back(Expression::make_type_descriptor(mtype, bloc));
++p;
@@ -2779,14 +2799,7 @@ Function_type::type_descriptor_params(Type* params_type,
+ (receiver != NULL ? 1 : 0));
if (receiver != NULL)
- {
- Type* rtype = receiver->type();
- // The receiver is always passed as a pointer. FIXME: Is this
- // right? Should that fact affect the type descriptor?
- if (rtype->points_to() == NULL)
- rtype = Type::make_pointer_type(rtype);
- vals->push_back(Expression::make_type_descriptor(rtype, bloc));
- }
+ vals->push_back(Expression::make_type_descriptor(receiver->type(), bloc));
if (params != NULL)
{
@@ -4822,9 +4835,10 @@ Array_type::make_array_type_descriptor_type()
Type* uintptr_type = Type::lookup_integer_type("uintptr");
Struct_type* sf =
- Type::make_builtin_struct_type(3,
+ Type::make_builtin_struct_type(4,
"", tdt,
"elem", ptdt,
+ "slice", ptdt,
"len", uintptr_type);
ret = Type::make_builtin_named_type("ArrayType", sf);
@@ -4891,6 +4905,11 @@ Array_type::array_type_descriptor(Gogo* gogo, Named_type* name)
vals->push_back(Expression::make_type_descriptor(this->element_type_, bloc));
++p;
+ go_assert(p->field_name() == "slice");
+ Type* slice_type = Type::make_array_type(this->element_type_, NULL);
+ vals->push_back(Expression::make_type_descriptor(slice_type, bloc));
+
+ ++p;
go_assert(p->field_name() == "len");
vals->push_back(Expression::make_cast(p->type(), this->length_, bloc));
@@ -5375,8 +5394,9 @@ Channel_type::do_make_expression_tree(Translate_context* context,
Gogo* gogo = context->gogo();
tree channel_type = type_to_tree(this->get_backend(gogo));
- tree element_tree = type_to_tree(this->element_type_->get_backend(gogo));
- tree element_size_tree = size_in_bytes(element_tree);
+ Type* ptdt = Type::make_type_descriptor_ptr_type();
+ tree element_type_descriptor =
+ this->element_type_->type_descriptor_pointer(gogo);
tree bad_index = NULL_TREE;
@@ -5402,8 +5422,8 @@ Channel_type::do_make_expression_tree(Translate_context* context,
"__go_new_channel",
2,
channel_type,
- sizetype,
- element_size_tree,
+ type_to_tree(ptdt->get_backend(gogo)),
+ element_type_descriptor,
sizetype,
expr_tree);
if (ret == error_mark_node)
@@ -6242,7 +6262,16 @@ Interface_type::do_reflection(Gogo* gogo, std::string* ret) const
if (p != this->methods_->begin())
ret->append(";");
ret->push_back(' ');
- ret->append(Gogo::unpack_hidden_name(p->name()));
+ if (!Gogo::is_hidden_name(p->name()))
+ ret->append(p->name());
+ else
+ {
+ // This matches what the gc compiler does.
+ std::string prefix = Gogo::hidden_name_prefix(p->name());
+ ret->append(prefix.substr(prefix.find('.') + 1));
+ ret->push_back('.');
+ ret->append(Gogo::unpack_hidden_name(p->name()));
+ }
std::string sub = p->type()->reflection(gogo);
go_assert(sub.compare(0, 4, "func") == 0);
sub = sub.substr(4);
diff --git a/gcc/go/gofrontend/types.h b/gcc/go/gofrontend/types.h
index 913266b..3ada1b1 100644
--- a/gcc/go/gofrontend/types.h
+++ b/gcc/go/gofrontend/types.h
@@ -1044,7 +1044,7 @@ class Type
// Build a composite literal for one method.
Expression*
method_constructor(Gogo*, Type* method_type, const std::string& name,
- const Method*) const;
+ const Method*, bool only_value_methods) const;
static tree
build_receive_return_type(tree type);
diff --git a/gcc/testsuite/go.test/test/convert.go b/gcc/testsuite/go.test/test/convert.go
index e7361aa..0a75663 100644
--- a/gcc/testsuite/go.test/test/convert.go
+++ b/gcc/testsuite/go.test/test/convert.go
@@ -8,7 +8,7 @@ package main
import "reflect"
-func typeof(x interface{}) string { return reflect.Typeof(x).String() }
+func typeof(x interface{}) string { return reflect.TypeOf(x).String() }
func f() int { return 0 }
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug177.go b/gcc/testsuite/go.test/test/fixedbugs/bug177.go
index 84ff59d..a120ad0 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/bug177.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/bug177.go
@@ -5,23 +5,26 @@
// license that can be found in the LICENSE file.
package main
+
import "reflect"
-type S1 struct { i int }
-type S2 struct { S1 }
+
+type S1 struct{ i int }
+type S2 struct{ S1 }
+
func main() {
- typ := reflect.Typeof(S2{}).(*reflect.StructType);
- f := typ.Field(0);
+ typ := reflect.TypeOf(S2{})
+ f := typ.Field(0)
if f.Name != "S1" || f.Anonymous != true {
- println("BUG: ", f.Name, f.Anonymous);
- return;
+ println("BUG: ", f.Name, f.Anonymous)
+ return
}
- f, ok := typ.FieldByName("S1");
+ f, ok := typ.FieldByName("S1")
if !ok {
- println("BUG: missing S1");
- return;
+ println("BUG: missing S1")
+ return
}
if !f.Anonymous {
- println("BUG: S1 is not anonymous");
- return;
+ println("BUG: S1 is not anonymous")
+ return
}
}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug248.dir/bug2.go b/gcc/testsuite/go.test/test/fixedbugs/bug248.dir/bug2.go
index 4ea187a..b6c816a 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/bug248.dir/bug2.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/bug248.dir/bug2.go
@@ -38,11 +38,11 @@ func main() {
// meaning that reflect data for v0, v1 didn't get confused.
// path is full (rooted) path name. check suffix for gc, prefix for gccgo
- if s := reflect.Typeof(v0).PkgPath(); !strings.HasSuffix(s, "/bug0") && !strings.HasPrefix(s, "bug0") {
+ if s := reflect.TypeOf(v0).PkgPath(); !strings.HasSuffix(s, "/bug0") && !strings.HasPrefix(s, "bug0") {
println("bad v0 path", len(s), s)
panic("fail")
}
- if s := reflect.Typeof(v1).PkgPath(); !strings.HasSuffix(s, "/bug1") && !strings.HasPrefix(s, "bug1") {
+ if s := reflect.TypeOf(v1).PkgPath(); !strings.HasSuffix(s, "/bug1") && !strings.HasPrefix(s, "bug1") {
println("bad v1 path", s)
panic("fail")
}
diff --git a/gcc/testsuite/go.test/test/interface/fake.go b/gcc/testsuite/go.test/test/interface/fake.go
index 5cf3be0..bdc5b90 100644
--- a/gcc/testsuite/go.test/test/interface/fake.go
+++ b/gcc/testsuite/go.test/test/interface/fake.go
@@ -46,34 +46,34 @@ func main() {
x.t = add("abc", "def")
x.u = 1
x.v = 2
- x.w = 1<<28
- x.x = 2<<28
+ x.w = 1 << 28
+ x.x = 2 << 28
x.y = 0x12345678
x.z = x.y
// check mem and string
- v := reflect.NewValue(x)
- i := v.(*reflect.StructValue).Field(0)
- j := v.(*reflect.StructValue).Field(1)
+ v := reflect.ValueOf(x)
+ i := v.Field(0)
+ j := v.Field(1)
assert(i.Interface() == j.Interface())
- s := v.(*reflect.StructValue).Field(2)
- t := v.(*reflect.StructValue).Field(3)
+ s := v.Field(2)
+ t := v.Field(3)
assert(s.Interface() == t.Interface())
// make sure different values are different.
// make sure whole word is being compared,
// not just a single byte.
- i = v.(*reflect.StructValue).Field(4)
- j = v.(*reflect.StructValue).Field(5)
+ i = v.Field(4)
+ j = v.Field(5)
assert(i.Interface() != j.Interface())
- i = v.(*reflect.StructValue).Field(6)
- j = v.(*reflect.StructValue).Field(7)
+ i = v.Field(6)
+ j = v.Field(7)
assert(i.Interface() != j.Interface())
- i = v.(*reflect.StructValue).Field(8)
- j = v.(*reflect.StructValue).Field(9)
+ i = v.Field(8)
+ j = v.Field(9)
assert(i.Interface() == j.Interface())
}
diff --git a/gcc/testsuite/go.test/test/ken/cplx3.go b/gcc/testsuite/go.test/test/ken/cplx3.go
index 83acc15..fa6ff1d 100644
--- a/gcc/testsuite/go.test/test/ken/cplx3.go
+++ b/gcc/testsuite/go.test/test/ken/cplx3.go
@@ -25,9 +25,9 @@ func main() {
println(c)
var a interface{}
- switch c := reflect.NewValue(a).(type) {
- case *reflect.ComplexValue:
- v := c.Get()
+ switch c := reflect.ValueOf(a); c.Kind() {
+ case reflect.Complex64, reflect.Complex128:
+ v := c.Complex()
_, _ = complex128(v), true
}
}