mirror of
https://github.com/golang/go
synced 2024-11-26 06:07:57 -07:00
- minor formatting and capitalization (export) changes
TBR=rsc OCL=27861 CL=27861
This commit is contained in:
parent
af8036aa6b
commit
9b6009b651
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// TODO: printing is gone; install as "go/doc"
|
|
||||||
|
|
||||||
package doc
|
package doc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -51,6 +49,7 @@ type typeDoc struct {
|
|||||||
|
|
||||||
|
|
||||||
// DocReader accumulates documentation for a single package.
|
// DocReader accumulates documentation for a single package.
|
||||||
|
//
|
||||||
type DocReader struct {
|
type DocReader struct {
|
||||||
name string; // package name
|
name string; // package name
|
||||||
path string; // import path
|
path string; // import path
|
||||||
@ -64,6 +63,7 @@ type DocReader struct {
|
|||||||
|
|
||||||
// Init initializes a DocReader to collect package documentation
|
// Init initializes a DocReader to collect package documentation
|
||||||
// for the package with the given package name and import path.
|
// for the package with the given package name and import path.
|
||||||
|
//
|
||||||
func (doc *DocReader) Init(pkg, imp string) {
|
func (doc *DocReader) Init(pkg, imp string) {
|
||||||
doc.name = pkg;
|
doc.name = pkg;
|
||||||
doc.path = imp;
|
doc.path = imp;
|
||||||
@ -116,8 +116,8 @@ func (doc *DocReader) addFunc(fun *ast.FuncDecl) {
|
|||||||
typ.methods[name] = fun;
|
typ.methods[name] = fun;
|
||||||
}
|
}
|
||||||
// if the type wasn't found, it wasn't exported
|
// if the type wasn't found, it wasn't exported
|
||||||
// TODO: a non-exported type may still have exported functions
|
// TODO(gri): a non-exported type may still have exported functions
|
||||||
// determine what to do in that case
|
// determine what to do in that case
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ func (doc *DocReader) AddProgram(prog *ast.Program) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add package documentation
|
// add package documentation
|
||||||
// TODO what to do if there are multiple files?
|
// TODO(gri) what to do if there are multiple files?
|
||||||
if prog.Doc != nil {
|
if prog.Doc != nil {
|
||||||
doc.doc = prog.Doc
|
doc.doc = prog.Doc
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ func (doc *DocReader) AddProgram(prog *ast.Program) {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Conversion to external representation
|
// Conversion to external representation
|
||||||
|
|
||||||
func Regexp(s string) *regexp.Regexp {
|
func makeRex(s string) *regexp.Regexp {
|
||||||
re, err := regexp.Compile(s);
|
re, err := regexp.Compile(s);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("MakeRegexp ", s, " ", err.String());
|
panic("MakeRegexp ", s, " ", err.String());
|
||||||
@ -220,16 +220,16 @@ var (
|
|||||||
|
|
||||||
// TODO(rsc): Cannot use var initialization for regexps,
|
// TODO(rsc): Cannot use var initialization for regexps,
|
||||||
// because Regexp constructor needs threads.
|
// because Regexp constructor needs threads.
|
||||||
func SetupRegexps() {
|
func setupRegexps() {
|
||||||
comment_markers = Regexp("^[ \t]*(// ?| ?\\* ?)");
|
comment_markers = makeRex("^[ \t]*(// ?| ?\\* ?)");
|
||||||
trailing_whitespace = Regexp("[ \t\r]+$");
|
trailing_whitespace = makeRex("[ \t\r]+$");
|
||||||
comment_junk = Regexp("^[ \t]*(/\\*|\\*/)[ \t]*$");
|
comment_junk = makeRex("^[ \t]*(/\\*|\\*/)[ \t]*$");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Aggregate comment text, without comment markers.
|
// Aggregate comment text, without comment markers.
|
||||||
func comment(comments ast.Comments) string {
|
func comment(comments ast.Comments) string {
|
||||||
once.Do(SetupRegexps);
|
once.Do(setupRegexps);
|
||||||
lines := make([]string, 0, 20);
|
lines := make([]string, 0, 20);
|
||||||
for i, c := range comments {
|
for i, c := range comments {
|
||||||
// split on newlines
|
// split on newlines
|
||||||
@ -295,8 +295,10 @@ func comment(comments ast.Comments) string {
|
|||||||
return strings.Join(lines, "\n");
|
return strings.Join(lines, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ValueDoc is the documentation for a group of declared
|
// ValueDoc is the documentation for a group of declared
|
||||||
// values, either vars or consts.
|
// values, either vars or consts.
|
||||||
|
//
|
||||||
type ValueDoc struct {
|
type ValueDoc struct {
|
||||||
Doc string;
|
Doc string;
|
||||||
Decl *ast.GenDecl;
|
Decl *ast.GenDecl;
|
||||||
@ -307,6 +309,7 @@ type sortValueDoc []*ValueDoc
|
|||||||
func (p sortValueDoc) Len() int { return len(p); }
|
func (p sortValueDoc) Len() int { return len(p); }
|
||||||
func (p sortValueDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i]; }
|
func (p sortValueDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i]; }
|
||||||
|
|
||||||
|
|
||||||
func declName(d *ast.GenDecl) string {
|
func declName(d *ast.GenDecl) string {
|
||||||
if len(d.Specs) != 1 {
|
if len(d.Specs) != 1 {
|
||||||
return ""
|
return ""
|
||||||
@ -322,6 +325,7 @@ func declName(d *ast.GenDecl) string {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (p sortValueDoc) Less(i, j int) bool {
|
func (p sortValueDoc) Less(i, j int) bool {
|
||||||
// sort by name
|
// sort by name
|
||||||
// pull blocks (name = "") up to top
|
// pull blocks (name = "") up to top
|
||||||
@ -332,6 +336,7 @@ func (p sortValueDoc) Less(i, j int) bool {
|
|||||||
return p[i].order < p[j].order;
|
return p[i].order < p[j].order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func makeValueDocs(v *vector.Vector) []*ValueDoc {
|
func makeValueDocs(v *vector.Vector) []*ValueDoc {
|
||||||
d := make([]*ValueDoc, v.Len());
|
d := make([]*ValueDoc, v.Len());
|
||||||
for i := range d {
|
for i := range d {
|
||||||
@ -345,6 +350,7 @@ func makeValueDocs(v *vector.Vector) []*ValueDoc {
|
|||||||
|
|
||||||
// FuncDoc is the documentation for a func declaration,
|
// FuncDoc is the documentation for a func declaration,
|
||||||
// either a top-level function or a method function.
|
// either a top-level function or a method function.
|
||||||
|
//
|
||||||
type FuncDoc struct {
|
type FuncDoc struct {
|
||||||
Doc string;
|
Doc string;
|
||||||
Recv ast.Expr; // TODO(rsc): Would like string here
|
Recv ast.Expr; // TODO(rsc): Would like string here
|
||||||
@ -357,6 +363,7 @@ func (p sortFuncDoc) Len() int { return len(p); }
|
|||||||
func (p sortFuncDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i]; }
|
func (p sortFuncDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i]; }
|
||||||
func (p sortFuncDoc) Less(i, j int) bool { return p[i].Name < p[j].Name; }
|
func (p sortFuncDoc) Less(i, j int) bool { return p[i].Name < p[j].Name; }
|
||||||
|
|
||||||
|
|
||||||
func makeFuncDocs(m map[string] *ast.FuncDecl) []*FuncDoc {
|
func makeFuncDocs(m map[string] *ast.FuncDecl) []*FuncDoc {
|
||||||
d := make([]*FuncDoc, len(m));
|
d := make([]*FuncDoc, len(m));
|
||||||
i := 0;
|
i := 0;
|
||||||
@ -401,6 +408,7 @@ func (p sortTypeDoc) Less(i, j int) bool {
|
|||||||
return p[i].order < p[j].order;
|
return p[i].order < p[j].order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NOTE(rsc): This would appear not to be correct for type ( )
|
// NOTE(rsc): This would appear not to be correct for type ( )
|
||||||
// blocks, but the doc extractor above has split them into
|
// blocks, but the doc extractor above has split them into
|
||||||
// individual statements.
|
// individual statements.
|
||||||
@ -425,6 +433,7 @@ func makeTypeDocs(m map[string] *typeDoc) []*TypeDoc {
|
|||||||
|
|
||||||
|
|
||||||
// PackageDoc is the documentation for an entire package.
|
// PackageDoc is the documentation for an entire package.
|
||||||
|
//
|
||||||
type PackageDoc struct {
|
type PackageDoc struct {
|
||||||
PackageName string;
|
PackageName string;
|
||||||
ImportPath string;
|
ImportPath string;
|
||||||
@ -437,6 +446,7 @@ type PackageDoc struct {
|
|||||||
|
|
||||||
|
|
||||||
// Doc returns the accumulated documentation for the package.
|
// Doc returns the accumulated documentation for the package.
|
||||||
|
//
|
||||||
func (doc *DocReader) Doc() *PackageDoc {
|
func (doc *DocReader) Doc() *PackageDoc {
|
||||||
p := new(PackageDoc);
|
p := new(PackageDoc);
|
||||||
p.PackageName = doc.name;
|
p.PackageName = doc.name;
|
||||||
@ -466,6 +476,7 @@ func isRegexp(s string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func match(s string, a []string) bool {
|
func match(s string, a []string) bool {
|
||||||
for i, t := range a {
|
for i, t := range a {
|
||||||
if isRegexp(t) {
|
if isRegexp(t) {
|
||||||
@ -480,6 +491,7 @@ func match(s string, a []string) bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func matchDecl(d *ast.GenDecl, names []string) bool {
|
func matchDecl(d *ast.GenDecl, names []string) bool {
|
||||||
for i, d := range d.Specs {
|
for i, d := range d.Specs {
|
||||||
switch v := d.(type) {
|
switch v := d.(type) {
|
||||||
@ -498,6 +510,7 @@ func matchDecl(d *ast.GenDecl, names []string) bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func filterValueDocs(a []*ValueDoc, names []string) []*ValueDoc {
|
func filterValueDocs(a []*ValueDoc, names []string) []*ValueDoc {
|
||||||
w := 0;
|
w := 0;
|
||||||
for i, vd := range a {
|
for i, vd := range a {
|
||||||
@ -509,6 +522,7 @@ func filterValueDocs(a []*ValueDoc, names []string) []*ValueDoc {
|
|||||||
return a[0 : w];
|
return a[0 : w];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func filterTypeDocs(a []*TypeDoc, names []string) []*TypeDoc {
|
func filterTypeDocs(a []*TypeDoc, names []string) []*TypeDoc {
|
||||||
w := 0;
|
w := 0;
|
||||||
for i, td := range a {
|
for i, td := range a {
|
||||||
@ -520,6 +534,7 @@ func filterTypeDocs(a []*TypeDoc, names []string) []*TypeDoc {
|
|||||||
return a[0 : w];
|
return a[0 : w];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func filterFuncDocs(a []*FuncDoc, names []string) []*FuncDoc {
|
func filterFuncDocs(a []*FuncDoc, names []string) []*FuncDoc {
|
||||||
w := 0;
|
w := 0;
|
||||||
for i, fd := range a {
|
for i, fd := range a {
|
||||||
@ -531,10 +546,12 @@ func filterFuncDocs(a []*FuncDoc, names []string) []*FuncDoc {
|
|||||||
return a[0 : w];
|
return a[0 : w];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Filter eliminates information from d that is not
|
// Filter eliminates information from d that is not
|
||||||
// about one of the given names.
|
// about one of the given names.
|
||||||
// TODO: Recognize "Type.Method" as a name.
|
// TODO: Recognize "Type.Method" as a name.
|
||||||
// TODO(r): maybe precompile the regexps.
|
// TODO(r): maybe precompile the regexps.
|
||||||
|
//
|
||||||
func (p *PackageDoc) Filter(names []string) {
|
func (p *PackageDoc) Filter(names []string) {
|
||||||
p.Consts = filterValueDocs(p.Consts, names);
|
p.Consts = filterValueDocs(p.Consts, names);
|
||||||
p.Vars = filterValueDocs(p.Vars, names);
|
p.Vars = filterValueDocs(p.Vars, names);
|
||||||
|
Loading…
Reference in New Issue
Block a user