From 9690ac05c92a154b5d2ca7078d3bf6f4c7eb6c57 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 12 Jun 2012 20:33:22 +0000 Subject: compiler, reflect: Handle package path like gc compiler. From-SVN: r188482 --- gcc/go/gofrontend/gogo.cc | 11 ++++++++--- gcc/go/gofrontend/types.cc | 21 +++++++++++++++------ libgo/go/encoding/xml/marshal_test.go | 2 +- libgo/go/html/template/escape_test.go | 2 +- libgo/go/reflect/type.go | 24 ++++++++++++++++++++++-- 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index 80ffe24..6e9b8c1 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -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; } diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index c2e5ed8..ff6b5bd 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -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) diff --git a/libgo/go/encoding/xml/marshal_test.go b/libgo/go/encoding/xml/marshal_test.go index 6f0ecfc..b6978a1 100644 --- a/libgo/go/encoding/xml/marshal_test.go +++ b/libgo/go/encoding/xml/marshal_test.go @@ -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, }, { diff --git a/libgo/go/html/template/escape_test.go b/libgo/go/html/template/escape_test.go index 6670be9..ce12c17 100644 --- a/libgo/go/html/template/escape_test.go +++ b/libgo/go/html/template/escape_test.go @@ -226,7 +226,7 @@ func TestEscape(t *testing.T) { { "badMarshaler", `