Commit fffac807 authored by Andrei Vieru's avatar Andrei Vieru Committed by Robert Griesemer

"godoc -src pkg_name" excludes duplicates entries

$ godoc xml | grep Copy\(\)
func (c CharData) Copy() CharData
func (c Comment) Copy() Comment
func (d Directive) Copy() Directive
func (p ProcInst) Copy() ProcInst
func (e StartElement) Copy() StartElement
--------------------------------------------
$ godoc -src xml | grep Copy\(\)
func (c CharData) Copy() CharData
--------------------------------------------
$ godoc -src xml Copy
func (c CharData) Copy() CharData { return CharData(makeCopy(c)) }
--------------------------------------------
The command "godoc -src pkg_name" should output the interface of the named package, but it excludes all duplicate entries. Also the command "godoc -src pkg_name method_name" will output the source code only for one method even if there are more of them with the same name in the same package. This patch set fixes this issue.

R=gri
CC=golang-dev
https://golang.org/cl/883051
parent df3a5440
...@@ -1273,7 +1273,7 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf ...@@ -1273,7 +1273,7 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf
if mode&genDoc != 0 { if mode&genDoc != 0 {
pdoc = doc.NewPackageDoc(pkg, pathutil.Clean(relpath)) // no trailing '/' in importpath pdoc = doc.NewPackageDoc(pkg, pathutil.Clean(relpath)) // no trailing '/' in importpath
} else { } else {
past = ast.MergePackageFiles(pkg, false) past = ast.MergePackageFiles(pkg, ast.FilterUnassociatedComments)
} }
} }
......
...@@ -290,6 +290,17 @@ func FilterPackage(pkg *Package, f Filter) bool { ...@@ -290,6 +290,17 @@ func FilterPackage(pkg *Package, f Filter) bool {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Merging of package files // Merging of package files
// The MergeMode flags control the behavior of MergePackageFiles.
type MergeMode uint
const (
// If set, duplicate function declarations are excluded.
FilterFuncDuplicates MergeMode = 1 << iota
// If set, comments that are not associated with a specific
// AST node (as Doc or Comment) are excluded.
FilterUnassociatedComments
)
// separator is an empty //-style comment that is interspersed between // separator is an empty //-style comment that is interspersed between
// different comment groups when they are concatenated into a single group // different comment groups when they are concatenated into a single group
// //
...@@ -318,14 +329,9 @@ func lineAfterComment(c *Comment) token.Position { ...@@ -318,14 +329,9 @@ func lineAfterComment(c *Comment) token.Position {
// MergePackageFiles creates a file AST by merging the ASTs of the // MergePackageFiles creates a file AST by merging the ASTs of the
// files belonging to a package. If complete is set, the package // files belonging to a package. The mode flags control merging behavior.
// files are assumed to contain the complete, unfiltered package
// information. In this case, MergePackageFiles collects all entities
// and all comments. Otherwise (complete == false), MergePackageFiles
// excludes duplicate entries and does not collect comments that are
// not attached to AST nodes.
// //
func MergePackageFiles(pkg *Package, complete bool) *File { func MergePackageFiles(pkg *Package, mode MergeMode) *File {
// Count the number of package docs, comments and declarations across // Count the number of package docs, comments and declarations across
// all package files. // all package files.
ndocs := 0 ndocs := 0
...@@ -380,7 +386,7 @@ func MergePackageFiles(pkg *Package, complete bool) *File { ...@@ -380,7 +386,7 @@ func MergePackageFiles(pkg *Package, complete bool) *File {
n := 0 // number of filtered entries n := 0 // number of filtered entries
for _, f := range pkg.Files { for _, f := range pkg.Files {
for _, d := range f.Decls { for _, d := range f.Decls {
if !complete { if mode&FilterFuncDuplicates != 0 {
// A language entity may be declared multiple // A language entity may be declared multiple
// times in different package files; only at // times in different package files; only at
// build time declarations must be unique. // build time declarations must be unique.
...@@ -432,7 +438,7 @@ func MergePackageFiles(pkg *Package, complete bool) *File { ...@@ -432,7 +438,7 @@ func MergePackageFiles(pkg *Package, complete bool) *File {
// Collect comments from all package files. // Collect comments from all package files.
var comments []*CommentGroup var comments []*CommentGroup
if complete { if mode&FilterUnassociatedComments == 0 {
comments = make([]*CommentGroup, ncomments) comments = make([]*CommentGroup, ncomments)
i := 0 i := 0
for _, f := range pkg.Files { for _, f := range pkg.Files {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment