Commit 9690ac05 by Ian Lance Taylor

compiler, reflect: Handle package path like gc compiler.

From-SVN: r188482
parent b29e01b7
...@@ -339,9 +339,14 @@ Gogo::set_package_name(const std::string& package_name, ...@@ -339,9 +339,14 @@ Gogo::set_package_name(const std::string& package_name,
// symbol names. // symbol names.
if (!this->pkgpath_set_) if (!this->pkgpath_set_)
{ {
if (!this->prefix_from_option_) if (!this->prefix_from_option_ && package_name == "main")
this->prefix_ = "go"; this->pkgpath_ = package_name;
this->pkgpath_ = this->prefix_ + '.' + package_name; else
{
if (!this->prefix_from_option_)
this->prefix_ = "go";
this->pkgpath_ = this->prefix_ + '.' + package_name;
}
this->pkgpath_set_ = true; this->pkgpath_set_ = true;
} }
......
...@@ -8337,14 +8337,23 @@ Named_type::do_reflection(Gogo* gogo, std::string* ret) const ...@@ -8337,14 +8337,23 @@ Named_type::do_reflection(Gogo* gogo, std::string* ret) const
{ {
// We handle -fgo-prefix and -fgo-pkgpath differently here for // We handle -fgo-prefix and -fgo-pkgpath differently here for
// compatibility with how the compiler worked before // 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(); const Package* package = this->named_object_->package();
if (gogo->pkgpath_from_option()) if (gogo->pkgpath_from_option())
ret->append(package != NULL ? package->pkgpath() : gogo->pkgpath()); {
else ret->push_back('"');
ret->append(package != NULL ret->append(package != NULL
? package->package_name() ? package->pkgpath_symbol()
: gogo->package_name()); : gogo->pkgpath_symbol());
ret->push_back('"');
}
ret->append(package != NULL
? package->package_name()
: gogo->package_name());
ret->push_back('.'); ret->push_back('.');
} }
if (this->in_function_ != NULL) if (this->in_function_ != NULL)
......
...@@ -726,7 +726,7 @@ var marshalErrorTests = []struct { ...@@ -726,7 +726,7 @@ var marshalErrorTests = []struct {
}, },
{ {
Value: map[*Ship]bool{nil: false}, 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, Kind: reflect.Map,
}, },
{ {
......
...@@ -226,7 +226,7 @@ func TestEscape(t *testing.T) { ...@@ -226,7 +226,7 @@ func TestEscape(t *testing.T) {
{ {
"badMarshaler", "badMarshaler",
`<button onclick='alert(1/{{.B}}in numbers)'>`, `<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", "jsMarshaler",
......
...@@ -83,6 +83,9 @@ type Type interface { ...@@ -83,6 +83,9 @@ type Type interface {
// compare the Types directly. // compare the Types directly.
String() string String() string
// Used internally by gccgo--the string retaining quoting.
rawString() string
// Kind returns the specific kind of this type. // Kind returns the specific kind of this type.
Kind() Kind Kind() Kind
...@@ -432,7 +435,24 @@ func (t *commonType) toType() Type { ...@@ -432,7 +435,24 @@ func (t *commonType) toType() Type {
return canonicalize(t) 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 } func (t *commonType) Size() uintptr { return t.size }
...@@ -942,7 +962,7 @@ func canonicalize(t Type) Type { ...@@ -942,7 +962,7 @@ func canonicalize(t Type) Type {
u := t.uncommon() u := t.uncommon()
var s string var s string
if u == nil || u.PkgPath() == "" { if u == nil || u.PkgPath() == "" {
s = t.String() s = t.rawString()
} else { } else {
s = u.PkgPath() + "." + u.Name() s = u.PkgPath() + "." + u.Name()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment