w.current = pkg
scope := pkg.Scope()
for _, name := range scope.Names() {
- if ast.IsExported(name) {
+ if token.IsExported(name) {
w.emitObj(scope.Lookup(name))
}
}
"os"
"reflect"
"regexp"
- "unicode"
- "unicode/utf8"
)
// dump is like fdump but prints to stderr.
for i, n := 0, typ.NumField(); i < n; i++ {
// Exclude non-exported fields because their
// values cannot be accessed via reflection.
- if name := typ.Field(i).Name; isExported(name) {
+ if name := typ.Field(i).Name; types.IsExported(name) {
if !p.fieldrx.MatchString(name) {
omitted = true
continue // field name not selected by filter
return false
}
-func isExported(name string) bool {
- ch, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(ch)
-}
-
func commonPrefixLen(a, b string) (i int) {
for i < len(a) && i < len(b) && a[i] == b[i] {
i++
"cmd/internal/src"
"encoding/binary"
"fmt"
- "go/ast"
"io"
"math/big"
"strings"
name = fmt.Sprintf("%s·%d", name, v)
}
- if !ast.IsExported(name) && s.Pkg != w.currPkg {
+ if !types.IsExported(name) && s.Pkg != w.currPkg {
Fatalf("weird package in name: %v => %v, not %q", s, name, w.currPkg.Path)
}
"path"
"path/filepath"
"strings"
- "unicode"
- "unicode/utf8"
)
var (
// case letter, it can only be a symbol in the current directory.
// Kills the problem caused by case-insensitive file systems
// matching an upper case name as a package name.
- if isUpper(arg) {
+ if token.IsExported(arg) {
pkg, err := build.ImportDir(".", build.ImportComment)
if err == nil {
return pkg, "", arg, false
// If the unexported flag (-u) is true, isExported returns true because
// it means that we treat the name as if it is exported.
func isExported(name string) bool {
- return unexported || isUpper(name)
-}
-
-// isUpper reports whether the name starts with an upper case letter.
-func isUpper(name string) bool {
- ch, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(ch)
+ return unexported || token.IsExported(name)
}
// findNextPackage returns the next full file name path that matches the
// (perhaps partial) package path pkg. The boolean reports if any match was found.
func findNextPackage(pkg string) (string, bool) {
- if pkg == "" || isUpper(pkg) { // Upper case symbol cannot be a package name.
+ if pkg == "" || token.IsExported(pkg) { // Upper case symbol cannot be a package name.
return "", false
}
if filepath.IsAbs(pkg) {
},
"net/http/httputil": {"L4", "NET", "OS", "context", "net/http", "net/http/internal", "golang.org/x/net/http/httpguts"},
"net/http/pprof": {"L4", "OS", "html/template", "net/http", "runtime/pprof", "runtime/trace"},
- "net/rpc": {"L4", "NET", "encoding/gob", "html/template", "net/http"},
+ "net/rpc": {"L4", "NET", "encoding/gob", "html/template", "net/http", "go/token"},
"net/rpc/jsonrpc": {"L4", "NET", "encoding/json", "net/rpc"},
}
func filterIdentList(list []*ast.Ident) []*ast.Ident {
j := 0
for _, x := range list {
- if ast.IsExported(x.Name) {
+ if token.IsExported(x.Name) {
list[j] = x
j++
}
// and reports whether at least one exported name exists.
func updateIdentList(list []*ast.Ident) (hasExported bool) {
for i, x := range list {
- if ast.IsExported(x.Name) {
+ if token.IsExported(x.Name) {
hasExported = true
} else {
list[i] = underscore
if n := len(field.Names); n == 0 {
// anonymous field
fname := r.recordAnonymousField(parent, field.Type)
- if ast.IsExported(fname) {
+ if token.IsExported(fname) {
keepField = true
} else if ityp != nil && fname == "error" {
// possibly the predeclared error interface; keep
// always keep imports so we can collect them
return true
case *ast.ValueSpec:
- s.Values = filterExprList(s.Values, ast.IsExported, true)
+ s.Values = filterExprList(s.Values, token.IsExported, true)
if len(s.Values) > 0 || s.Type == nil && len(s.Values) == 0 {
// If there are values declared on RHS, just replace the unexported
// identifiers on the LHS with underscore, so that it matches
}
}
case *ast.TypeSpec:
- if name := s.Name.Name; ast.IsExported(name) {
+ if name := s.Name.Name; token.IsExported(name) {
r.filterType(r.lookupType(s.Name.Name), s.Type)
return true
} else if name == "error" {
// conflicting method will be filtered here, too -
// thus, removing these methods early will not lead
// to the false removal of possible conflicts
- return ast.IsExported(d.Name.Name)
+ return token.IsExported(d.Name.Name)
}
return false
}
}
func (r *reader) isVisible(name string) bool {
- return r.mode&AllDecls != 0 || ast.IsExported(name)
+ return r.mode&AllDecls != 0 || token.IsExported(name)
}
// lookupType returns the base type with the given name.
switch {
case m.Decl == nil:
// exclude conflict entry
- case allMethods, m.Level == 0, !ast.IsExported(removeStar(m.Orig)):
+ case allMethods, m.Level == 0, !token.IsExported(removeStar(m.Orig)):
// forced inclusion, method not embedded, or method
// embedded but original receiver type not exported
list[i] = m
"strconv"
"strings"
"sync"
- "unicode"
- "unicode/utf8"
)
type importer struct {
// TODO(gri) replace this with something closer to fieldName
pos := p.pos()
name := p.string()
- if !exported(name) {
+ if !token.IsExported(name) {
p.pkg()
}
alias = true
fallthrough
default:
- if !exported(name) {
+ if !token.IsExported(name) {
pkg = p.pkg()
}
}
return types.NewVar(token.NoPos, pkg, name, t), isddd
}
-func exported(name string) bool {
- ch, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(ch)
-}
-
func (p *importer) value() constant.Value {
switch tag := p.tagOrIndex(); tag {
case falseTag:
import (
"bytes"
"fmt"
- "go/ast"
"go/constant"
"go/token"
)
// Id returns name if it is exported, otherwise it
// returns the name qualified with the package path.
func Id(pkg *Package, name string) string {
- if ast.IsExported(name) {
+ if token.IsExported(name) {
return name
}
// unexported names need the package path for differentiation
// Exported reports whether the object is exported (starts with a capital letter).
// It doesn't take into account whether the object is in a local (function) scope
// or not.
-func (obj *object) Exported() bool { return ast.IsExported(obj.name) }
+func (obj *object) Exported() bool { return token.IsExported(obj.name) }
// Id is a wrapper for Id(obj.Pkg(), obj.Name()).
func (obj *object) Id() string { return Id(obj.pkg, obj.name) }
"compress/gzip"
"crypto/rand"
"fmt"
- "go/ast"
+ "go/token"
"io"
"io/ioutil"
"net/http/internal"
}
for i := 0; i < hv.NumField(); i++ {
name := hv.Type().Field(i).Name
- if !ast.IsExported(name) {
+ if !token.IsExported(name) {
continue
}
hf := hv.Field(i).Interface()
"bufio"
"encoding/gob"
"errors"
+ "go/token"
"io"
"log"
"net"
"reflect"
"strings"
"sync"
- "unicode"
- "unicode/utf8"
)
const (
// DefaultServer is the default instance of *Server.
var DefaultServer = NewServer()
-// Is this an exported - upper case - name?
-func isExported(name string) bool {
- rune, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(rune)
-}
-
// Is this type exported or a builtin?
func isExportedOrBuiltinType(t reflect.Type) bool {
for t.Kind() == reflect.Ptr {
}
// PkgPath will be non-empty even for an exported type,
// so we need to check the type name as well.
- return isExported(t.Name()) || t.PkgPath() == ""
+ return token.IsExported(t.Name()) || t.PkgPath() == ""
}
// Register publishes in the server the set of methods of the
log.Print(s)
return errors.New(s)
}
- if !isExported(sname) && !useName {
+ if !token.IsExported(sname) && !useName {
s := "rpc.Register: type " + sname + " is not exported"
log.Print(s)
return errors.New(s)
"encoding/base64"
"flag"
"fmt"
+ "go/token"
"io"
"math"
"math/rand"
"sync/atomic"
"testing"
"time"
- "unicode"
- "unicode/utf8"
"unsafe"
)
if n == "" {
panic("field.Name must not be empty")
}
- exported := isExported(n)
+ exported := token.IsExported(n)
if exported != test.exported {
t.Errorf("test-%d: got exported=%v want exported=%v", i, exported, test.exported)
}
}
}
-// isExported reports whether name is an exported Go symbol
-// (that is, whether it begins with an upper-case letter).
-//
-func isExported(name string) bool {
- ch, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(ch)
-}
-
func TestStructOfGC(t *testing.T) {
type T *uintptr
tt := TypeOf(T(nil))