diff mbox

Go patch committed: Fix some type reflection strings

Message ID mcrk3v8xwjc.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Oct. 2, 2012, 11:51 p.m. UTC
This patch to the Go frontend fixes the type reflection strings in a
couple of cases to match those generated by the gc compiler.  For an
empty struct, this generates "struct {}" rather than "struct {  }".  For
a type defined within a function, this generates pkg.type rather than
pkg.function_name$type.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline and 4.7 branch.

Ian
diff mbox

Patch

diff -r 83133095b520 go/types.cc
--- a/go/types.cc	Tue Oct 02 15:19:17 2012 -0700
+++ b/go/types.cc	Tue Oct 02 16:27:18 2012 -0700
@@ -4919,14 +4919,15 @@ 
 void
 Struct_type::do_reflection(Gogo* gogo, std::string* ret) const
 {
-  ret->append("struct { ");
+  ret->append("struct {");
 
   for (Struct_field_list::const_iterator p = this->fields_->begin();
        p != this->fields_->end();
        ++p)
     {
       if (p != this->fields_->begin())
-	ret->append("; ");
+	ret->push_back(';');
+      ret->push_back(' ');
       if (p->is_anonymous())
 	ret->push_back('?');
       else
@@ -4959,7 +4960,10 @@ 
 	}
     }
 
-  ret->append(" }");
+  if (!this->fields_->empty())
+    ret->push_back(' ');
+
+  ret->push_back('}');
 }
 
 // Mangled name.
@@ -8390,6 +8394,7 @@ 
     }
   if (this->in_function_ != NULL)
     {
+      ret->push_back('\t');
       ret->append(Gogo::unpack_hidden_name(this->in_function_->name()));
       ret->push_back('$');
       if (this->in_function_index_ > 0)
@@ -8399,6 +8404,7 @@ 
 	  ret->append(buf);
 	  ret->push_back('$');
 	}
+      ret->push_back('\t');
     }
   ret->append(Gogo::unpack_hidden_name(this->named_object_->name()));
 }