Patchwork [gccgo] Map fixes

login
register
mail settings
Submitter Ian Taylor
Date Sept. 2, 2010, 2:51 p.m.
Message ID <mcreidc6vxi.fsf@google.com>
Download mbox | patch
Permalink /patch/63492/
State New
Headers show

Comments

Ian Taylor - Sept. 2, 2010, 2:51 p.m.
This gccgo patch does two things.  It Permits the use of maps as map
keys, which is appropriate because == and != 0 work on maps.  It also
changes the code to convert map keys to the key type on an index
operation, which is necessary when using a map on interfaces.  Committed
to gccgo branch.

Ian

Patch

diff -r 16300503a180 go/expressions.cc
--- a/go/expressions.cc	Wed Sep 01 17:41:04 2010 -0700
+++ b/go/expressions.cc	Thu Sep 02 07:47:20 2010 -0700
@@ -9250,7 +9250,7 @@ 
 Map_index_expression::do_determine_type(const Type_context*)
 {
   this->map_->determine_type_no_context();
-  Type_context subcontext(this->get_map_type()->key_type(), true);
+  Type_context subcontext(this->get_map_type()->key_type(), false);
   this->index_->determine_type(&subcontext);
 }
 
@@ -9320,6 +9320,10 @@ 
 
   tree map_tree = this->map_->get_tree(context);
   tree index_tree = this->index_->get_tree(context);
+  index_tree = Expression::convert_for_assignment(context, type->key_type(),
+						  this->index_->type(),
+						  index_tree,
+						  this->location());
   if (map_tree == error_mark_node || index_tree == error_mark_node)
     return error_mark_node;
 
diff -r 16300503a180 go/gogo-tree.cc
--- a/go/gogo-tree.cc	Wed Sep 01 17:41:04 2010 -0700
+++ b/go/gogo-tree.cc	Thu Sep 02 07:47:20 2010 -0700
@@ -2435,6 +2435,7 @@ 
     case Type::TYPE_COMPLEX:
     case Type::TYPE_POINTER:
     case Type::TYPE_FUNCTION:
+    case Type::TYPE_MAP:
     case Type::TYPE_CHANNEL:
       hash_fn_name = "__go_type_hash_identity";
       equal_fn_name = "__go_type_equal_identity";
@@ -2447,7 +2448,6 @@ 
 
     case Type::TYPE_STRUCT:
     case Type::TYPE_ARRAY:
-    case Type::TYPE_MAP:
       // These types can not be hashed or compared.
       hash_fn_name = "__go_type_hash_error";
       equal_fn_name = "__go_type_equal_error";
diff -r 16300503a180 go/statements.cc
--- a/go/statements.cc	Wed Sep 01 17:41:04 2010 -0700
+++ b/go/statements.cc	Thu Sep 02 07:47:20 2010 -0700
@@ -3057,7 +3057,7 @@ 
 {
   if (this->cases_ != NULL)
     {
-      Type_context case_context(type, true);
+      Type_context case_context(type, false);
       for (Expression_list::iterator p = this->cases_->begin();
 	   p != this->cases_->end();
 	   ++p)
diff -r 16300503a180 go/types.cc
--- a/go/types.cc	Wed Sep 01 17:41:04 2010 -0700
+++ b/go/types.cc	Thu Sep 02 07:47:20 2010 -0700
@@ -4061,8 +4061,7 @@ 
 Map_type::do_verify()
 {
   if (this->key_type_->struct_type() != NULL
-      || this->key_type_->array_type() != NULL
-      || this->key_type_->map_type() != NULL)
+      || this->key_type_->array_type() != NULL)
     {
       error_at(this->location_, "invalid map key type");
       return false;