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++
}
r.remember(ityp)
}
} else {
- field.Names = filterIdentList(field.Names)
+ field.Names = filterIdentList(field.Names, false)
if len(field.Names) < n {
removedFields = true
}
}
}
-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
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++
}
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
--- /dev/null
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package blank is a go/doc test for the handling of _.
+// See issue 5397.
+package blank
+
+type T int
+
+// T constants.
+const (
+ _ T = iota
+ T1
+ T2
+)
+
+// Package constants.
+const (
+ _ int = iota
+ I1
+ I2
+)
+
+// Blanks not in doc output:
+
+// S has a padding field.
+type S struct {
+ H uint32
+ _ uint8
+ A uint8
+}
+
+func _() {}
+
+type _ T
+
+var _ = T(55)