// 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)
}
}
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)
}
}
case TINTER:
for _, f := range t.FieldSlice() {
- if exportname(f.Sym.Name) {
+ if types.IsExported(f.Sym.Name) {
p.markType(f.Type)
}
}
// 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
}
}
p.string(name)
- if name != "" && !exportname(name) {
+ if name != "" && !types.IsExported(name) {
p.pkg(t.Sym.Pkg)
}
}
// 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)
}
}
// 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)
}
}
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)
}
alias = true
fallthrough
default:
- if !exportname(name) {
+ if !types.IsExported(name) {
pkg = p.pkg()
}
}
return builtinpkg.Lookup(name)
}
pkg := localpkg
- if !exportname(name) {
+ if !types.IsExported(name) {
pkg = p.pkg()
}
return pkg.Lookup(name)
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)
// 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)
}
"cmd/internal/bio"
"cmd/internal/src"
"fmt"
- "unicode"
- "unicode/utf8"
)
var (
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"
}
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() {
// 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)...)
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 {
if n.Op != ONAME {
continue
}
- if !exportname(s.Name) {
+ if !types.IsExported(s.Name) {
continue
}
if s.Pkg.Name != "main" {
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")
}
var sig = Sig{
name: method.Name,
}
- if !exportname(method.Name) {
+ if !types.IsExported(method.Name) {
if method.Pkg == nil {
Fatalf("imethods: missing package")
}
// 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)
}
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
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)
}
}
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
// 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
}
}
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)
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)
}
// 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
}
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.
// 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
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)")
}
import (
"cmd/internal/obj"
"cmd/internal/src"
+ "unicode"
+ "unicode/utf8"
)
// Sym represents an object name. Most commonly, this is a Go identifier naming
}
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)
+}