diff options
author | Robert Griesemer <gri@golang.org> | 2009-07-06 10:37:33 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-07-06 10:37:33 -0700 |
commit | 5b64dd9f54b3784d0c61add4adcee0af68aa1b48 (patch) | |
tree | 48a258fee1d014e8a586ca205459a12a9505d1fa /src/pkg/go/doc/doc.go | |
parent | 5a0ac3685c82d356483f9085e1f8ecccdeaf74a5 (diff) | |
download | golang-5b64dd9f54b3784d0c61add4adcee0af68aa1b48.tar.gz |
- ast.FilterExports: strips all non-exported nodes from an AST
- use FilterExports instead of the various predicates in printer.go and doc.go
which simplifies a lot of code and makes it easier to deal with complex cases
R=rsc
DELTA=445 (197 added, 190 deleted, 58 changed)
OCL=31110
CL=31196
Diffstat (limited to 'src/pkg/go/doc/doc.go')
-rw-r--r-- | src/pkg/go/doc/doc.go | 50 |
1 files changed, 10 insertions, 40 deletions
diff --git a/src/pkg/go/doc/doc.go b/src/pkg/go/doc/doc.go index 03872fd14..bbae654a5 100644 --- a/src/pkg/go/doc/doc.go +++ b/src/pkg/go/doc/doc.go @@ -18,28 +18,6 @@ import ( // ---------------------------------------------------------------------------- -// Elementary support - -func hasExportedNames(names []*ast.Ident) bool { - for i, name := range names { - if name.IsExported() { - return true; - } - } - return false; -} - - -func hasExportedSpecs(specs []ast.Spec) bool { - for i, s := range specs { - // only called for []astSpec lists of *ast.ValueSpec - return hasExportedNames(s.(*ast.ValueSpec).Names); - } - return false; -} - - -// ---------------------------------------------------------------------------- type typeDoc struct { decl *ast.GenDecl; // len(decl.Specs) == 1, and the element type is *ast.TypeSpec @@ -149,33 +127,25 @@ func (doc *DocReader) addDecl(decl ast.Decl) { // ignore case token.CONST: // constants are always handled as a group - if hasExportedSpecs(d.Specs) { - doc.consts.Push(d); - } + doc.consts.Push(d); case token.TYPE: // types are handled individually + var noPos token.Position; for i, spec := range d.Specs { + // make a (fake) GenDecl node for this TypeSpec + // (we need to do this here - as opposed to just + // for printing - so we don't lose the GenDecl + // documentation) s := spec.(*ast.TypeSpec); - if s.Name.IsExported() { - // make a (fake) GenDecl node for this TypeSpec - // (we need to do this here - as opposed to just - // for printing - so we don't loose the GenDecl - // documentation) - var noPos token.Position; - doc.addType(&ast.GenDecl{d.Doc, d.Pos(), token.TYPE, noPos, []ast.Spec{s}, noPos}); - } + doc.addType(&ast.GenDecl{d.Doc, d.Pos(), token.TYPE, noPos, []ast.Spec{s}, noPos}); } case token.VAR: // variables are always handled as a group - if hasExportedSpecs(d.Specs) { - doc.vars.Push(d); - } + doc.vars.Push(d); } } case *ast.FuncDecl: - if d.Name.IsExported() { - doc.addFunc(d); - } + doc.addFunc(d); } } @@ -194,7 +164,7 @@ func (doc *DocReader) AddProgram(prog *ast.Program) { doc.doc = prog.Doc } - // add all exported declarations + // add all declarations for i, decl := range prog.Decls { doc.addDecl(decl); } |