]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: rename gc.exportname to types.IsExported
authorMatthew Dempsky <mdempsky@google.com>
Mon, 9 Apr 2018 22:22:01 +0000 (15:22 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 9 Apr 2018 22:58:00 +0000 (22:58 +0000)
gofmt -r 'exportname(s) -> types.IsExported(s)'

Passes toolstash-check.

Change-Id: I6b428bd039c135be66d8b81c325d4e08bae69f24
Reviewed-on: https://go-review.googlesource.com/105938
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/obj.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go
src/cmd/compile/internal/types/sym.go

index 060e7b7a677634f31b39daaf4d8ff3b6fb31e046..f37ab3e819145577e8cdad8a4d70d49f73004783 100644 (file)
@@ -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)
        }
 }
index 4f1d8747b5e6bf4c7c2504fd64d2ad0e6dda056e..0e00fa070a1ddd5780771a42852ccb37483a7d8e 100644 (file)
@@ -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)
index 9a906f19a31a045d6ce65ec342068a6a0efe7a60..e2e21faf80264e9130a7c376ee3addb2f20cc877 100644 (file)
@@ -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)
        }
index 9990b590a47b885f46f3e4682da15f2268974a94..a5837286085f993d46f0388b8cd28d4fa547d8eb 100644 (file)
@@ -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() {
index 5e8c2a85c73f0a5945d43122dd1931c2f9b41adf..4c0a4ace1d1438992b4725624c3b8b5b1e49f896 100644 (file)
@@ -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 {
index 6b33f2467bd8f7568cb7029c4c946788449defb1..b33a057cee15b169151b2480da729490395060e7 100644 (file)
@@ -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" {
index f350d514e5f508eecb906b96b4b4e3cad53148fd..27fbd7b8d8edc2e6ac42b011c3ab082fedc34120 100644 (file)
@@ -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
                        }
index 4cc2c8ad396fb1e6958f8ae5ee9652bff6c0d79e..7b3d4cea1a8d6fd8fef8840bda15bbfc33c2cf2b 100644 (file)
@@ -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
        }
index a30c9ca4ff9d4847649b0850c07094fd2592f2db..9c9046bb3a06e01398a51690abbcb36d7b67aed6 100644 (file)
@@ -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
index 69cc56da59547c3ce98404be8b7967d875aff331..330d921ee776cf4f2304279405e48747d1a76063 100644 (file)
@@ -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)")
        }
 
index 00328fa44f4159d7a6fc7b1c017acc6c121804ac..e9b454d83afaa0181774dc4c16f119d391927e72 100644 (file)
@@ -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)
+}