diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-10-29 17:14:51 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-10-29 17:14:51 +0000 |
commit | 730f6d14253f7c8f44eff8c03beb5984e2f4c6cf (patch) | |
tree | 51c7bcf037fe05935e1479b498e56d84212089b1 /gcc | |
parent | 285b1f01acaf962e7a668aed7bab4d609a19fc3b (diff) | |
download | gcc-730f6d14253f7c8f44eff8c03beb5984e2f4c6cf.zip gcc-730f6d14253f7c8f44eff8c03beb5984e2f4c6cf.tar.gz gcc-730f6d14253f7c8f44eff8c03beb5984e2f4c6cf.tar.bz2 |
compiler, runtime: change type hash/equal to Go funcs
Change the type descriptor hash and equal functions from C code pointers
to Go func values. This permits them to be set to a Go function
closure. This is in preparation for the Go 1.5, so that we can use a
closure for the hash/equal functions returned by the new reflect.ArrayOf
function.
Reviewed-on: https://go-review.googlesource.com/16485
From-SVN: r229541
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 26 | ||||
-rw-r--r-- | gcc/go/gofrontend/types.cc | 33 |
3 files changed, 48 insertions, 13 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 6fcd185..8d3547b 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -11e249a59e8c627fe9c2938c38e39cb1efefb1fb +57da43e8159bfe1a31e49683c371cf36e2fb6051 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 0d25dda..c9750bd 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -1197,19 +1197,29 @@ Func_descriptor_expression::do_get_backend(Translate_context* context) Gogo* gogo = context->gogo(); std::string var_name; - if (no->package() == NULL) - var_name = gogo->pkgpath_symbol(); + bool is_descriptor = false; + if (no->is_function_declaration() + && !no->func_declaration_value()->asm_name().empty() + && Linemap::is_predeclared_location(no->location())) + { + var_name = no->func_declaration_value()->asm_name() + "_descriptor"; + is_descriptor = true; + } else - var_name = no->package()->pkgpath_symbol(); - var_name.push_back('.'); - var_name.append(Gogo::unpack_hidden_name(no->name())); - var_name.append("$descriptor"); + { + if (no->package() == NULL) + var_name = gogo->pkgpath_symbol(); + else + var_name = no->package()->pkgpath_symbol(); + var_name.push_back('.'); + var_name.append(Gogo::unpack_hidden_name(no->name())); + var_name.append("$descriptor"); + } Btype* btype = this->type()->get_backend(gogo); Bvariable* bvar; - if (no->package() != NULL - || Linemap::is_predeclared_location(no->location())) + if (no->package() != NULL || is_descriptor) bvar = context->backend()->immutable_struct_reference(var_name, btype, loc); else diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index dcc6bc8..5c8950a 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -1474,6 +1474,27 @@ Type::make_type_descriptor_type() Type* void_type = Type::make_void_type(); Type* unsafe_pointer_type = Type::make_pointer_type(void_type); + Typed_identifier_list *params = new Typed_identifier_list(); + params->push_back(Typed_identifier("key", unsafe_pointer_type, bloc)); + params->push_back(Typed_identifier("key_size", uintptr_type, bloc)); + + Typed_identifier_list* results = new Typed_identifier_list(); + results->push_back(Typed_identifier("", uintptr_type, bloc)); + + Type* hash_fntype = Type::make_function_type(NULL, params, results, + bloc); + + params = new Typed_identifier_list(); + params->push_back(Typed_identifier("key1", unsafe_pointer_type, bloc)); + params->push_back(Typed_identifier("key2", unsafe_pointer_type, bloc)); + params->push_back(Typed_identifier("key_size", uintptr_type, bloc)); + + results = new Typed_identifier_list(); + results->push_back(Typed_identifier("", Type::lookup_bool_type(), bloc)); + + Type* equal_fntype = Type::make_function_type(NULL, params, results, + bloc); + // Forward declaration for the type descriptor type. Named_object* named_type_descriptor_type = Named_object::make_type_declaration("commonType", NULL, bloc); @@ -1514,8 +1535,8 @@ Type::make_type_descriptor_type() "fieldAlign", uint8_type, "size", uintptr_type, "hash", uint32_type, - "hashfn", uintptr_type, - "equalfn", uintptr_type, + "hashfn", hash_fntype, + "equalfn", equal_fntype, "gc", uintptr_type, "string", pointer_string_type, "", pointer_uncommon_type, @@ -1852,6 +1873,10 @@ Type::write_specific_type_functions(Gogo* gogo, Named_type* name, gogo->add_block(b, bloc); gogo->lower_block(equal_fn, b); gogo->finish_function(bloc); + + // Build the function descriptors for the type descriptor to refer to. + hash_fn->func_value()->descriptor(gogo, hash_fn); + equal_fn->func_value()->descriptor(gogo, equal_fn); } // Write a hash function that simply calls the hash function for a @@ -2009,8 +2034,8 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind, Named_object* equal_fn; this->type_functions(gogo, name, hash_fntype, equal_fntype, &hash_fn, &equal_fn); - vals->push_back(Expression::make_func_code_reference(hash_fn, bloc)); - vals->push_back(Expression::make_func_code_reference(equal_fn, bloc)); + vals->push_back(Expression::make_func_reference(hash_fn, NULL, bloc)); + vals->push_back(Expression::make_func_reference(equal_fn, NULL, bloc)); ++p; go_assert(p->is_field_name("gc")); |