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) {
// handles their full method set.
if t.Sym != nil && t.Etype != TINTER {
for _, m := range t.Methods().Slice() {
if exportname(m.Sym.Name) {
if types.IsExported(m.Sym.Name) {
p.markType(m.Type)
}
}
......@@ -481,7 +481,7 @@ func (p *exporter) markType(t *types.Type) {
case TSTRUCT:
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)
}
}
......@@ -498,7 +498,7 @@ func (p *exporter) markType(t *types.Type) {
case TINTER:
for _, f := range t.FieldSlice() {
if exportname(f.Sym.Name) {
if types.IsExported(f.Sym.Name) {
p.markType(f.Type)
}
}
......@@ -893,7 +893,7 @@ func (p *exporter) fieldName(t *types.Field) {
// 3) field name doesn't match base type name (alias name)
bname := basetypeName(t.Type)
if name == bname {
if exportname(name) {
if types.IsExported(name) {
name = "" // 1) we don't need to know the field name or package
} else {
name = "?" // 2) use unexported name "?" to force package export
......@@ -905,7 +905,7 @@ func (p *exporter) fieldName(t *types.Field) {
}
}
p.string(name)
if name != "" && !exportname(name) {
if name != "" && !types.IsExported(name) {
p.pkg(t.Sym.Pkg)
}
}
......@@ -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.
func (p *exporter) methodName(sym *types.Sym) {
p.string(sym.Name)
if !exportname(sym.Name) {
if !types.IsExported(sym.Name) {
p.pkg(sym.Pkg)
}
}
......@@ -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
// TODO(gri) can we assert this with an explicit check?
p.string(name)
if !exportname(name) {
if !types.IsExported(name) {
p.pkg(s.Pkg)
}
}
......
......@@ -509,7 +509,7 @@ func (p *importer) typ() *types.Type {
sym := p.fieldSym()
// 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)
}
......@@ -706,7 +706,7 @@ func (p *importer) fieldName() (*types.Sym, bool) {
alias = true
fallthrough
default:
if !exportname(name) {
if !types.IsExported(name) {
pkg = p.pkg()
}
}
......@@ -721,7 +721,7 @@ func (p *importer) methodName() *types.Sym {
return builtinpkg.Lookup(name)
}
pkg := localpkg
if !exportname(name) {
if !types.IsExported(name) {
pkg = p.pkg()
}
return pkg.Lookup(name)
......@@ -1230,7 +1230,7 @@ func (p *importer) exprsOrNil() (a, b *Node) {
func (p *importer) fieldSym() *types.Sym {
name := p.string()
pkg := localpkg
if !exportname(name) {
if !types.IsExported(name) {
pkg = p.pkg()
}
return pkg.Lookup(name)
......
......@@ -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
// package qualifier for names that came from a different
// package than the receiver type.
if !exportname(msym.Name) && msym.Pkg != rpkg {
if !types.IsExported(msym.Name) && msym.Pkg != rpkg {
b.WriteString(".")
b.WriteString(msym.Pkg.Prefix)
}
......
......@@ -11,8 +11,6 @@ import (
"cmd/internal/bio"
"cmd/internal/src"
"fmt"
"unicode"
"unicode/utf8"
)
var (
......@@ -42,14 +40,6 @@ func exportsym(n *Node) {
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 {
return s == "init"
}
......@@ -65,7 +55,7 @@ func autoexport(n *Node, ctxt Class) {
return
}
if exportname(n.Sym.Name) || initname(n.Sym.Name) {
if types.IsExported(n.Sym.Name) || initname(n.Sym.Name) {
exportsym(n)
}
if asmhdr != "" && !n.Sym.Asm() {
......
......@@ -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.
// Wrong interface definitions may have types lacking a symbol.
break
case exportname(f.Sym.Name):
case types.IsExported(f.Sym.Name):
buf = append(buf, sconv(f.Sym, FmtShort, mode)...)
default:
buf = append(buf, sconv(f.Sym, FmtUnsigned, mode)...)
......@@ -1705,7 +1705,7 @@ func fldconv(f *types.Field, flag FmtFlag, mode fmtMode, depth int) string {
name = asNode(f.Nname).modeString(mode)
} else if flag&FmtLong != 0 {
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)
}
} else {
......
......@@ -183,7 +183,7 @@ func addptabs() {
if n.Op != ONAME {
continue
}
if !exportname(s.Name) {
if !types.IsExported(s.Name) {
continue
}
if s.Pkg.Name != "main" {
......
......@@ -414,7 +414,7 @@ func methods(t *types.Type) []*Sig {
ms = append(ms, &sig)
sig.name = method.Name
if !exportname(method.Name) {
if !types.IsExported(method.Name) {
if method.Pkg == nil {
Fatalf("methods: missing package")
}
......@@ -461,7 +461,7 @@ func imethods(t *types.Type) []*Sig {
var sig = Sig{
name: method.Name,
}
if !exportname(method.Name) {
if !types.IsExported(method.Name) {
if method.Pkg == nil {
Fatalf("imethods: missing package")
}
......@@ -564,10 +564,10 @@ func dgopkgpathOff(s *obj.LSym, ot int, pkg *types.Pkg) int {
// dnameField dumps a reflect.name for a struct field.
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)
}
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)
}
......@@ -708,7 +708,7 @@ func typePkg(t *types.Type) *types.Pkg {
func dextratypeData(lsym *obj.LSym, ot int, t *types.Type) int {
for _, a := range methods(t) {
// ../../../../runtime/type.go:/method
exported := exportname(a.name)
exported := types.IsExported(a.name)
var pkg *types.Pkg
if !exported && a.pkg != typePkg(t) {
pkg = a.pkg
......@@ -896,11 +896,11 @@ func dcommontype(lsym *obj.LSym, t *types.Type) int {
p = "*" + p
tflag |= tflagExtraStar
if t.Sym != nil {
exported = exportname(t.Sym.Name)
exported = types.IsExported(t.Sym.Name)
}
} else {
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 {
for _, a := range m {
// ../../../../runtime/type.go:/imethod
exported := exportname(a.name)
exported := types.IsExported(a.name)
var pkg *types.Pkg
if !exported && a.pkg != tpkg {
pkg = a.pkg
......@@ -1341,7 +1341,7 @@ func dtypesym(t *types.Type) *obj.LSym {
// information from the field descriptors.
var spkg *types.Pkg
for _, f := range fields {
if !exportname(f.Sym.Name) {
if !types.IsExported(f.Sym.Name) {
spkg = f.Sym.Pkg
break
}
......
......@@ -248,7 +248,7 @@ func autolabel(prefix string) *Node {
}
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)
}
return pkg.Lookup(name)
......@@ -262,7 +262,7 @@ func importdot(opkg *types.Pkg, pack *Node) {
if s.Def == nil {
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
}
s1 := lookup(s.Name)
......@@ -391,8 +391,8 @@ func (x methcmp) Less(i, j int) bool {
}
// Exported methods to the front.
ea := exportname(a.Sym.Name)
eb := exportname(b.Sym.Name)
ea := types.IsExported(a.Sym.Name)
eb := types.IsExported(b.Sym.Name)
if ea != eb {
return ea
}
......
......@@ -3032,7 +3032,7 @@ func typecheckcomplit(n *Node) *Node {
f := t.Field(i)
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)
}
// No pushtype allowed here. Must name fields for that.
......@@ -3073,7 +3073,7 @@ func typecheckcomplit(n *Node) *Node {
// package, because of import dot. Redirect to correct sym
// before we do the lookup.
s := key.Sym
if s.Pkg != localpkg && exportname(s.Name) {
if s.Pkg != localpkg && types.IsExported(s.Name) {
s1 := lookup(s.Name)
if s1.Origpkg == s.Pkg {
s = s1
......
......@@ -3720,7 +3720,7 @@ func usefield(n *Node) {
if outer.Sym == nil {
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)")
}
......
......@@ -7,6 +7,8 @@ package types
import (
"cmd/internal/obj"
"cmd/internal/src"
"unicode"
"unicode/utf8"
)
// Sym represents an object name. Most commonly, this is a Go identifier naming
......@@ -74,3 +76,13 @@ func (sym *Sym) Linksym() *obj.LSym {
}
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