summaryrefslogtreecommitdiff
path: root/src/go/doc/exports.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/doc/exports.go')
-rw-r--r--src/go/doc/exports.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/go/doc/exports.go b/src/go/doc/exports.go
index ff01285d4..9b421e734 100644
--- a/src/go/doc/exports.go
+++ b/src/go/doc/exports.go
@@ -6,15 +6,18 @@
package doc
-import "go/ast"
+import (
+ "go/ast"
+ "go/token"
+)
// filterIdentList removes unexported names from list in place
// and returns the resulting list.
//
-func filterIdentList(list []*ast.Ident) []*ast.Ident {
+func filterIdentList(list []*ast.Ident, blankOk bool) []*ast.Ident {
j := 0
for _, x := range list {
- if ast.IsExported(x.Name) {
+ if ast.IsExported(x.Name) || (blankOk && x.Name == "_") {
list[j] = x
j++
}
@@ -74,7 +77,7 @@ func (r *reader) filterFieldList(parent *namedType, fields *ast.FieldList, ityp
r.remember(ityp)
}
} else {
- field.Names = filterIdentList(field.Names)
+ field.Names = filterIdentList(field.Names, false)
if len(field.Names) < n {
removedFields = true
}
@@ -136,13 +139,13 @@ func (r *reader) filterType(parent *namedType, typ ast.Expr) {
}
}
-func (r *reader) filterSpec(spec ast.Spec) bool {
+func (r *reader) filterSpec(spec ast.Spec, tok token.Token) bool {
switch s := spec.(type) {
case *ast.ImportSpec:
// always keep imports so we can collect them
return true
case *ast.ValueSpec:
- s.Names = filterIdentList(s.Names)
+ s.Names = filterIdentList(s.Names, tok == token.CONST)
if len(s.Names) > 0 {
r.filterType(nil, s.Type)
return true
@@ -159,10 +162,10 @@ func (r *reader) filterSpec(spec ast.Spec) bool {
return false
}
-func (r *reader) filterSpecList(list []ast.Spec) []ast.Spec {
+func (r *reader) filterSpecList(list []ast.Spec, tok token.Token) []ast.Spec {
j := 0
for _, s := range list {
- if r.filterSpec(s) {
+ if r.filterSpec(s, tok) {
list[j] = s
j++
}
@@ -173,7 +176,7 @@ func (r *reader) filterSpecList(list []ast.Spec) []ast.Spec {
func (r *reader) filterDecl(decl ast.Decl) bool {
switch d := decl.(type) {
case *ast.GenDecl:
- d.Specs = r.filterSpecList(d.Specs)
+ d.Specs = r.filterSpecList(d.Specs, d.Tok)
return len(d.Specs) > 0
case *ast.FuncDecl:
// ok to filter these methods early because any