]> gcc.gnu.org Git - gcc.git/commitdiff
compiler, reflect: Handle package path like gc compiler.
authorIan Lance Taylor <ian@gcc.gnu.org>
Tue, 12 Jun 2012 20:33:22 +0000 (20:33 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 12 Jun 2012 20:33:22 +0000 (20:33 +0000)
From-SVN: r188482

gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/types.cc
libgo/go/encoding/xml/marshal_test.go
libgo/go/html/template/escape_test.go
libgo/go/reflect/type.go

index 80ffe240c7f58125382ccfb8dc04881f7eeb3918..6e9b8c124aa34ce6612e0cab666e84d6febed944 100644 (file)
@@ -339,9 +339,14 @@ Gogo::set_package_name(const std::string& package_name,
   // symbol names.
   if (!this->pkgpath_set_)
     {
-      if (!this->prefix_from_option_)
-       this->prefix_ = "go";
-      this->pkgpath_ = this->prefix_ + '.' + package_name;
+      if (!this->prefix_from_option_ && package_name == "main")
+       this->pkgpath_ = package_name;
+      else
+       {
+         if (!this->prefix_from_option_)
+           this->prefix_ = "go";
+         this->pkgpath_ = this->prefix_ + '.' + package_name;
+       }
       this->pkgpath_set_ = true;
     }
 
index c2e5ed8b9ed5240bde39fd175ada4860400c66a8..ff6b5bddbd2787045976ce905e46cf668716b867 100644 (file)
@@ -8337,14 +8337,23 @@ Named_type::do_reflection(Gogo* gogo, std::string* ret) const
     {
       // We handle -fgo-prefix and -fgo-pkgpath differently here for
       // compatibility with how the compiler worked before
-      // -fgo-pkgpath was introduced.
+      // -fgo-pkgpath was introduced.  When -fgo-pkgpath is specified,
+      // we use it to make a unique reflection string, so that the
+      // type canonicalization in the reflect package will work.  In
+      // order to be compatible with the gc compiler, we quote the
+      // package path, so that the reflect methods can discard it.
       const Package* package = this->named_object_->package();
       if (gogo->pkgpath_from_option())
-       ret->append(package != NULL ? package->pkgpath() : gogo->pkgpath());
-      else
-       ret->append(package != NULL
-                   ? package->package_name()
-                   : gogo->package_name());
+       {
+         ret->push_back('"');
+         ret->append(package != NULL
+                     ? package->pkgpath_symbol()
+                     : gogo->pkgpath_symbol());
+         ret->push_back('"');
+       }
+      ret->append(package != NULL
+                 ? package->package_name()
+                 : gogo->package_name());
       ret->push_back('.');
     }
   if (this->in_function_ != NULL)
index 6f0ecfc233be4778e3fc14ba0fe5479a74225cac..b6978a1e65b5a590c6c722153af5d675224386fe 100644 (file)
@@ -726,7 +726,7 @@ var marshalErrorTests = []struct {
        },
        {
                Value: map[*Ship]bool{nil: false},
-               Err:   "xml: unsupported type: map[*encoding/xml.Ship]bool",
+               Err:   "xml: unsupported type: map[*xml.Ship]bool",
                Kind:  reflect.Map,
        },
        {
index 6670be9a195f7815d46c88e09f3e94f906a8b097..ce12c1795c24ee81926523fab7695be789e5f836 100644 (file)
@@ -226,7 +226,7 @@ func TestEscape(t *testing.T) {
                {
                        "badMarshaler",
                        `<button onclick='alert(1/{{.B}}in numbers)'>`,
-                       `<button onclick='alert(1/ /* json: error calling MarshalJSON for type *html/template.badMarshaler: invalid character &#39;f&#39; looking for beginning of object key string */null in numbers)'>`,
+                       `<button onclick='alert(1/ /* json: error calling MarshalJSON for type *template.badMarshaler: invalid character &#39;f&#39; looking for beginning of object key string */null in numbers)'>`,
                },
                {
                        "jsMarshaler",
index 4999824c91930313d09d12c690eb920d89615e49..a264ef1e08248304d3b129e70f267c673057f9b9 100644 (file)
@@ -83,6 +83,9 @@ type Type interface {
        // compare the Types directly.
        String() string
 
+       // Used internally by gccgo--the string retaining quoting.
+       rawString() string
+
        // Kind returns the specific kind of this type.
        Kind() Kind
 
@@ -432,7 +435,24 @@ func (t *commonType) toType() Type {
        return canonicalize(t)
 }
 
-func (t *commonType) String() string { return *t.string }
+func (t *commonType) rawString() string { return *t.string }
+
+func (t *commonType) String() string {
+       // For gccgo, strip out quoted strings.
+       s := *t.string
+       var q bool
+       r := make([]byte, len(s))
+       j := 0
+       for i := 0; i < len(s); i++ {
+               if s[i] == '"' {
+                       q = !q
+               } else if !q {
+                       r[j] = s[i]
+                       j++
+               }
+       }
+       return string(r[:j])
+}
 
 func (t *commonType) Size() uintptr { return t.size }
 
@@ -942,7 +962,7 @@ func canonicalize(t Type) Type {
        u := t.uncommon()
        var s string
        if u == nil || u.PkgPath() == "" {
-               s = t.String()
+               s = t.rawString()
        } else {
                s = u.PkgPath() + "." + u.Name()
        }
This page took 0.081472 seconds and 5 git commands to generate.