summaryrefslogtreecommitdiff
path: root/src/pkg/go/doc/doc.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-03-05 10:13:58 -0800
committerRobert Griesemer <gri@golang.org>2010-03-05 10:13:58 -0800
commitafca5d8cad43101800b2e5bdcdbb4787a0ce8497 (patch)
tree228ca0d13f99202ecbfc51c02fb6f6b1a9be2f5d /src/pkg/go/doc/doc.go
parent7a4de4f0ba2bc1f9acbb5eb0c7a4b2536f447ffd (diff)
downloadgolang-afca5d8cad43101800b2e5bdcdbb4787a0ce8497.tar.gz
godoc: don't throw away function documentation
if there are multiple functions (for a package, type) with the same name Fixes issue 642. R=rsc CC=golang-dev http://codereview.appspot.com/243041
Diffstat (limited to 'src/pkg/go/doc/doc.go')
-rw-r--r--src/pkg/go/doc/doc.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/pkg/go/doc/doc.go b/src/pkg/go/doc/doc.go
index 1bf496933..5479743ba 100644
--- a/src/pkg/go/doc/doc.go
+++ b/src/pkg/go/doc/doc.go
@@ -147,6 +147,24 @@ func (doc *docReader) addValue(decl *ast.GenDecl) {
}
+// Helper function to set the table entry for function f. Makes sure that
+// at least one f with associated documentation is stored in table, if there
+// are multiple f's with the same name.
+func setFunc(table map[string]*ast.FuncDecl, f *ast.FuncDecl) {
+ name := f.Name.Name()
+ if g, exists := table[name]; exists && g.Doc != nil {
+ // a function with the same name has already been registered;
+ // since it has documentation, assume f is simply another
+ // implementation and ignore it
+ // TODO(gri) consider collecting all functions, or at least
+ // all comments
+ return
+ }
+ // function doesn't exist or has no documentation; use f
+ table[name] = f
+}
+
+
func (doc *docReader) addFunc(fun *ast.FuncDecl) {
name := fun.Name.Name()
@@ -156,7 +174,7 @@ func (doc *docReader) addFunc(fun *ast.FuncDecl) {
typ := doc.lookupTypeDoc(baseTypeName(fun.Recv.List[0].Type))
if typ != nil {
// exported receiver type
- typ.methods[name] = fun
+ setFunc(typ.methods, fun)
}
// otherwise don't show the method
// TODO(gri): There may be exported methods of non-exported types
@@ -187,18 +205,18 @@ func (doc *docReader) addFunc(fun *ast.FuncDecl) {
if doc.pkgName == "os" && tname == "Error" &&
name != "NewError" && name != "NewSyscallError" {
// not a factory function for os.Error
- doc.funcs[name] = fun // treat as ordinary function
+ setFunc(doc.funcs, fun) // treat as ordinary function
return
}
- typ.factories[name] = fun
+ setFunc(typ.factories, fun)
return
}
}
}
// ordinary function
- doc.funcs[name] = fun
+ setFunc(doc.funcs, fun)
}