Commit 71bac7ef authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: rename gc.exportname to types.IsExported

gofmt -r 'exportname(s) -> types.IsExported(s)'

Passes toolstash-check.

Change-Id: I6b428bd039c135be66d8b81c325d4e08bae69f24
Reviewed-on: https://go-review.googlesource.com/105938Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c5dd2543
...@@ -454,7 +454,7 @@ func (p *exporter) markType(t *types.Type) { ...@@ -454,7 +454,7 @@ func (p *exporter) markType(t *types.Type) {
// handles their full method set. // handles their full method set.
if t.Sym != nil && t.Etype != TINTER { if t.Sym != nil && t.Etype != TINTER {
for _, m := range t.Methods().Slice() { for _, m := range t.Methods().Slice() {
if exportname(m.Sym.Name) { if types.IsExported(m.Sym.Name) {
p.markType(m.Type) p.markType(m.Type)
} }
} }
...@@ -481,7 +481,7 @@ func (p *exporter) markType(t *types.Type) { ...@@ -481,7 +481,7 @@ func (p *exporter) markType(t *types.Type) {
case TSTRUCT: case TSTRUCT:
for _, f := range t.FieldSlice() { for _, f := range t.FieldSlice() {
if exportname(f.Sym.Name) || f.Embedded != 0 { if types.IsExported(f.Sym.Name) || f.Embedded != 0 {
p.markType(f.Type) p.markType(f.Type)
} }
} }
...@@ -498,7 +498,7 @@ func (p *exporter) markType(t *types.Type) { ...@@ -498,7 +498,7 @@ func (p *exporter) markType(t *types.Type) {
case TINTER: case TINTER:
for _, f := range t.FieldSlice() { for _, f := range t.FieldSlice() {
if exportname(f.Sym.Name) { if types.IsExported(f.Sym.Name) {
p.markType(f.Type) p.markType(f.Type)
} }
} }
...@@ -893,7 +893,7 @@ func (p *exporter) fieldName(t *types.Field) { ...@@ -893,7 +893,7 @@ func (p *exporter) fieldName(t *types.Field) {
// 3) field name doesn't match base type name (alias name) // 3) field name doesn't match base type name (alias name)
bname := basetypeName(t.Type) bname := basetypeName(t.Type)
if name == bname { if name == bname {
if exportname(name) { if types.IsExported(name) {
name = "" // 1) we don't need to know the field name or package name = "" // 1) we don't need to know the field name or package
} else { } else {
name = "?" // 2) use unexported name "?" to force package export name = "?" // 2) use unexported name "?" to force package export
...@@ -905,7 +905,7 @@ func (p *exporter) fieldName(t *types.Field) { ...@@ -905,7 +905,7 @@ func (p *exporter) fieldName(t *types.Field) {
} }
} }
p.string(name) p.string(name)
if name != "" && !exportname(name) { if name != "" && !types.IsExported(name) {
p.pkg(t.Sym.Pkg) p.pkg(t.Sym.Pkg)
} }
} }
...@@ -913,7 +913,7 @@ func (p *exporter) fieldName(t *types.Field) { ...@@ -913,7 +913,7 @@ func (p *exporter) fieldName(t *types.Field) {
// methodName is like qualifiedName but it doesn't record the package for exported names. // methodName is like qualifiedName but it doesn't record the package for exported names.
func (p *exporter) methodName(sym *types.Sym) { func (p *exporter) methodName(sym *types.Sym) {
p.string(sym.Name) p.string(sym.Name)
if !exportname(sym.Name) { if !types.IsExported(sym.Name) {
p.pkg(sym.Pkg) p.pkg(sym.Pkg)
} }
} }
...@@ -1587,7 +1587,7 @@ func (p *exporter) fieldSym(s *types.Sym, short bool) { ...@@ -1587,7 +1587,7 @@ func (p *exporter) fieldSym(s *types.Sym, short bool) {
// we should never see a _ (blank) here - these are accessible ("read") fields // we should never see a _ (blank) here - these are accessible ("read") fields
// TODO(gri) can we assert this with an explicit check? // TODO(gri) can we assert this with an explicit check?
p.string(name) p.string(name)
if !exportname(name) { if !types.IsExported(name) {
p.pkg(s.Pkg) p.pkg(s.Pkg)
} }
} }
......
...@@ -509,7 +509,7 @@ func (p *importer) typ() *types.Type { ...@@ -509,7 +509,7 @@ func (p *importer) typ() *types.Type {
sym := p.fieldSym() sym := p.fieldSym()
// during import unexported method names should be in the type's package // during import unexported method names should be in the type's package
if !exportname(sym.Name) && sym.Pkg != tsym.Pkg { if !types.IsExported(sym.Name) && sym.Pkg != tsym.Pkg {
Fatalf("imported method name %+v in wrong package %s\n", sym, tsym.Pkg.Name) Fatalf("imported method name %+v in wrong package %s\n", sym, tsym.Pkg.Name)
} }
...@@ -706,7 +706,7 @@ func (p *importer) fieldName() (*types.Sym, bool) { ...@@ -706,7 +706,7 @@ func (p *importer) fieldName() (*types.Sym, bool) {
alias = true alias = true
fallthrough fallthrough
default: default:
if !exportname(name) { if !types.IsExported(name) {
pkg = p.pkg() pkg = p.pkg()
} }
} }
...@@ -721,7 +721,7 @@ func (p *importer) methodName() *types.Sym { ...@@ -721,7 +721,7 @@ func (p *importer) methodName() *types.Sym {
return builtinpkg.Lookup(name) return builtinpkg.Lookup(name)
} }
pkg := localpkg pkg := localpkg
if !exportname(name) { if !types.IsExported(name) {
pkg = p.pkg() pkg = p.pkg()
} }
return pkg.Lookup(name) return pkg.Lookup(name)
...@@ -1230,7 +1230,7 @@ func (p *importer) exprsOrNil() (a, b *Node) { ...@@ -1230,7 +1230,7 @@ func (p *importer) exprsOrNil() (a, b *Node) {
func (p *importer) fieldSym() *types.Sym { func (p *importer) fieldSym() *types.Sym {
name := p.string() name := p.string()
pkg := localpkg pkg := localpkg
if !exportname(name) { if !types.IsExported(name) {
pkg = p.pkg() pkg = p.pkg()
} }
return pkg.Lookup(name) return pkg.Lookup(name)
......
...@@ -874,7 +874,7 @@ func methodSymSuffix(recv *types.Type, msym *types.Sym, suffix string) *types.Sy ...@@ -874,7 +874,7 @@ func methodSymSuffix(recv *types.Type, msym *types.Sym, suffix string) *types.Sy
// methods with the same name. To disambiguate them, include a // methods with the same name. To disambiguate them, include a
// package qualifier for names that came from a different // package qualifier for names that came from a different
// package than the receiver type. // package than the receiver type.
if !exportname(msym.Name) && msym.Pkg != rpkg { if !types.IsExported(msym.Name) && msym.Pkg != rpkg {
b.WriteString(".") b.WriteString(".")
b.WriteString(msym.Pkg.Prefix) b.WriteString(msym.Pkg.Prefix)
} }
......
...@@ -11,8 +11,6 @@ import ( ...@@ -11,8 +11,6 @@ import (
"cmd/internal/bio" "cmd/internal/bio"
"cmd/internal/src" "cmd/internal/src"
"fmt" "fmt"
"unicode"
"unicode/utf8"
) )
var ( var (
...@@ -42,14 +40,6 @@ func exportsym(n *Node) { ...@@ -42,14 +40,6 @@ func exportsym(n *Node) {
exportlist = append(exportlist, n) exportlist = append(exportlist, n)
} }
func exportname(s string) bool {
if r := s[0]; r < utf8.RuneSelf {
return 'A' <= r && r <= 'Z'
}
r, _ := utf8.DecodeRuneInString(s)
return unicode.IsUpper(r)
}
func initname(s string) bool { func initname(s string) bool {
return s == "init" return s == "init"
} }
...@@ -65,7 +55,7 @@ func autoexport(n *Node, ctxt Class) { ...@@ -65,7 +55,7 @@ func autoexport(n *Node, ctxt Class) {
return return
} }
if exportname(n.Sym.Name) || initname(n.Sym.Name) { if types.IsExported(n.Sym.Name) || initname(n.Sym.Name) {
exportsym(n) exportsym(n)
} }
if asmhdr != "" && !n.Sym.Asm() { if asmhdr != "" && !n.Sym.Asm() {
......
...@@ -757,7 +757,7 @@ func typefmt(t *types.Type, flag FmtFlag, mode fmtMode, depth int) string { ...@@ -757,7 +757,7 @@ func typefmt(t *types.Type, flag FmtFlag, mode fmtMode, depth int) string {
// Check first that a symbol is defined for this type. // Check first that a symbol is defined for this type.
// Wrong interface definitions may have types lacking a symbol. // Wrong interface definitions may have types lacking a symbol.
break break
case exportname(f.Sym.Name): case types.IsExported(f.Sym.Name):
buf = append(buf, sconv(f.Sym, FmtShort, mode)...) buf = append(buf, sconv(f.Sym, FmtShort, mode)...)
default: default:
buf = append(buf, sconv(f.Sym, FmtUnsigned, mode)...) buf = append(buf, sconv(f.Sym, FmtUnsigned, mode)...)
...@@ -1705,7 +1705,7 @@ func fldconv(f *types.Field, flag FmtFlag, mode fmtMode, depth int) string { ...@@ -1705,7 +1705,7 @@ func fldconv(f *types.Field, flag FmtFlag, mode fmtMode, depth int) string {
name = asNode(f.Nname).modeString(mode) name = asNode(f.Nname).modeString(mode)
} else if flag&FmtLong != 0 { } else if flag&FmtLong != 0 {
name = mode.Sprintf("%0S", s) name = mode.Sprintf("%0S", s)
if !exportname(name) && flag&FmtUnsigned == 0 { if !types.IsExported(name) && flag&FmtUnsigned == 0 {
name = smodeString(s, mode) // qualify non-exported names (used on structs, not on funarg) name = smodeString(s, mode) // qualify non-exported names (used on structs, not on funarg)
} }
} else { } else {
......
...@@ -183,7 +183,7 @@ func addptabs() { ...@@ -183,7 +183,7 @@ func addptabs() {
if n.Op != ONAME { if n.Op != ONAME {
continue continue
} }
if !exportname(s.Name) { if !types.IsExported(s.Name) {
continue continue
} }
if s.Pkg.Name != "main" { if s.Pkg.Name != "main" {
......
...@@ -414,7 +414,7 @@ func methods(t *types.Type) []*Sig { ...@@ -414,7 +414,7 @@ func methods(t *types.Type) []*Sig {
ms = append(ms, &sig) ms = append(ms, &sig)
sig.name = method.Name sig.name = method.Name
if !exportname(method.Name) { if !types.IsExported(method.Name) {
if method.Pkg == nil { if method.Pkg == nil {
Fatalf("methods: missing package") Fatalf("methods: missing package")
} }
...@@ -461,7 +461,7 @@ func imethods(t *types.Type) []*Sig { ...@@ -461,7 +461,7 @@ func imethods(t *types.Type) []*Sig {
var sig = Sig{ var sig = Sig{
name: method.Name, name: method.Name,
} }
if !exportname(method.Name) { if !types.IsExported(method.Name) {
if method.Pkg == nil { if method.Pkg == nil {
Fatalf("imethods: missing package") Fatalf("imethods: missing package")
} }
...@@ -564,10 +564,10 @@ func dgopkgpathOff(s *obj.LSym, ot int, pkg *types.Pkg) int { ...@@ -564,10 +564,10 @@ func dgopkgpathOff(s *obj.LSym, ot int, pkg *types.Pkg) int {
// dnameField dumps a reflect.name for a struct field. // dnameField dumps a reflect.name for a struct field.
func dnameField(lsym *obj.LSym, ot int, spkg *types.Pkg, ft *types.Field) int { func dnameField(lsym *obj.LSym, ot int, spkg *types.Pkg, ft *types.Field) int {
if !exportname(ft.Sym.Name) && ft.Sym.Pkg != spkg { if !types.IsExported(ft.Sym.Name) && ft.Sym.Pkg != spkg {
Fatalf("package mismatch for %v", ft.Sym) Fatalf("package mismatch for %v", ft.Sym)
} }
nsym := dname(ft.Sym.Name, ft.Note, nil, exportname(ft.Sym.Name)) nsym := dname(ft.Sym.Name, ft.Note, nil, types.IsExported(ft.Sym.Name))
return dsymptr(lsym, ot, nsym, 0) return dsymptr(lsym, ot, nsym, 0)
} }
...@@ -708,7 +708,7 @@ func typePkg(t *types.Type) *types.Pkg { ...@@ -708,7 +708,7 @@ func typePkg(t *types.Type) *types.Pkg {
func dextratypeData(lsym *obj.LSym, ot int, t *types.Type) int { func dextratypeData(lsym *obj.LSym, ot int, t *types.Type) int {
for _, a := range methods(t) { for _, a := range methods(t) {
// ../../../../runtime/type.go:/method // ../../../../runtime/type.go:/method
exported := exportname(a.name) exported := types.IsExported(a.name)
var pkg *types.Pkg var pkg *types.Pkg
if !exported && a.pkg != typePkg(t) { if !exported && a.pkg != typePkg(t) {
pkg = a.pkg pkg = a.pkg
...@@ -896,11 +896,11 @@ func dcommontype(lsym *obj.LSym, t *types.Type) int { ...@@ -896,11 +896,11 @@ func dcommontype(lsym *obj.LSym, t *types.Type) int {
p = "*" + p p = "*" + p
tflag |= tflagExtraStar tflag |= tflagExtraStar
if t.Sym != nil { if t.Sym != nil {
exported = exportname(t.Sym.Name) exported = types.IsExported(t.Sym.Name)
} }
} else { } else {
if t.Elem() != nil && t.Elem().Sym != nil { if t.Elem() != nil && t.Elem().Sym != nil {
exported = exportname(t.Elem().Sym.Name) exported = types.IsExported(t.Elem().Sym.Name)
} }
} }
...@@ -1267,7 +1267,7 @@ func dtypesym(t *types.Type) *obj.LSym { ...@@ -1267,7 +1267,7 @@ func dtypesym(t *types.Type) *obj.LSym {
for _, a := range m { for _, a := range m {
// ../../../../runtime/type.go:/imethod // ../../../../runtime/type.go:/imethod
exported := exportname(a.name) exported := types.IsExported(a.name)
var pkg *types.Pkg var pkg *types.Pkg
if !exported && a.pkg != tpkg { if !exported && a.pkg != tpkg {
pkg = a.pkg pkg = a.pkg
...@@ -1341,7 +1341,7 @@ func dtypesym(t *types.Type) *obj.LSym { ...@@ -1341,7 +1341,7 @@ func dtypesym(t *types.Type) *obj.LSym {
// information from the field descriptors. // information from the field descriptors.
var spkg *types.Pkg var spkg *types.Pkg
for _, f := range fields { for _, f := range fields {
if !exportname(f.Sym.Name) { if !types.IsExported(f.Sym.Name) {
spkg = f.Sym.Pkg spkg = f.Sym.Pkg
break break
} }
......
...@@ -248,7 +248,7 @@ func autolabel(prefix string) *Node { ...@@ -248,7 +248,7 @@ func autolabel(prefix string) *Node {
} }
func restrictlookup(name string, pkg *types.Pkg) *types.Sym { func restrictlookup(name string, pkg *types.Pkg) *types.Sym {
if !exportname(name) && pkg != localpkg { if !types.IsExported(name) && pkg != localpkg {
yyerror("cannot refer to unexported name %s.%s", pkg.Name, name) yyerror("cannot refer to unexported name %s.%s", pkg.Name, name)
} }
return pkg.Lookup(name) return pkg.Lookup(name)
...@@ -262,7 +262,7 @@ func importdot(opkg *types.Pkg, pack *Node) { ...@@ -262,7 +262,7 @@ func importdot(opkg *types.Pkg, pack *Node) {
if s.Def == nil { if s.Def == nil {
continue continue
} }
if !exportname(s.Name) || strings.ContainsRune(s.Name, 0xb7) { // 0xb7 = center dot if !types.IsExported(s.Name) || strings.ContainsRune(s.Name, 0xb7) { // 0xb7 = center dot
continue continue
} }
s1 := lookup(s.Name) s1 := lookup(s.Name)
...@@ -391,8 +391,8 @@ func (x methcmp) Less(i, j int) bool { ...@@ -391,8 +391,8 @@ func (x methcmp) Less(i, j int) bool {
} }
// Exported methods to the front. // Exported methods to the front.
ea := exportname(a.Sym.Name) ea := types.IsExported(a.Sym.Name)
eb := exportname(b.Sym.Name) eb := types.IsExported(b.Sym.Name)
if ea != eb { if ea != eb {
return ea return ea
} }
......
...@@ -3032,7 +3032,7 @@ func typecheckcomplit(n *Node) *Node { ...@@ -3032,7 +3032,7 @@ func typecheckcomplit(n *Node) *Node {
f := t.Field(i) f := t.Field(i)
s := f.Sym s := f.Sym
if s != nil && !exportname(s.Name) && s.Pkg != localpkg { if s != nil && !types.IsExported(s.Name) && s.Pkg != localpkg {
yyerror("implicit assignment of unexported field '%s' in %v literal", s.Name, t) yyerror("implicit assignment of unexported field '%s' in %v literal", s.Name, t)
} }
// No pushtype allowed here. Must name fields for that. // No pushtype allowed here. Must name fields for that.
...@@ -3073,7 +3073,7 @@ func typecheckcomplit(n *Node) *Node { ...@@ -3073,7 +3073,7 @@ func typecheckcomplit(n *Node) *Node {
// package, because of import dot. Redirect to correct sym // package, because of import dot. Redirect to correct sym
// before we do the lookup. // before we do the lookup.
s := key.Sym s := key.Sym
if s.Pkg != localpkg && exportname(s.Name) { if s.Pkg != localpkg && types.IsExported(s.Name) {
s1 := lookup(s.Name) s1 := lookup(s.Name)
if s1.Origpkg == s.Pkg { if s1.Origpkg == s.Pkg {
s = s1 s = s1
......
...@@ -3720,7 +3720,7 @@ func usefield(n *Node) { ...@@ -3720,7 +3720,7 @@ func usefield(n *Node) {
if outer.Sym == nil { if outer.Sym == nil {
yyerror("tracked field must be in named struct type") yyerror("tracked field must be in named struct type")
} }
if !exportname(field.Sym.Name) { if !types.IsExported(field.Sym.Name) {
yyerror("tracked field must be exported (upper case)") yyerror("tracked field must be exported (upper case)")
} }
......
...@@ -7,6 +7,8 @@ package types ...@@ -7,6 +7,8 @@ package types
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/src" "cmd/internal/src"
"unicode"
"unicode/utf8"
) )
// Sym represents an object name. Most commonly, this is a Go identifier naming // Sym represents an object name. Most commonly, this is a Go identifier naming
...@@ -74,3 +76,13 @@ func (sym *Sym) Linksym() *obj.LSym { ...@@ -74,3 +76,13 @@ func (sym *Sym) Linksym() *obj.LSym {
} }
return Ctxt.Lookup(sym.LinksymName()) return Ctxt.Lookup(sym.LinksymName())
} }
// IsExported reports whether name is an exported Go symbol (that is,
// whether it begins with an upper-case letter).
func IsExported(name string) bool {
if r := name[0]; r < utf8.RuneSelf {
return 'A' <= r && r <= 'Z'
}
r, _ := utf8.DecodeRuneInString(name)
return unicode.IsUpper(r)
}
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