mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
- 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
This commit is contained in:
parent
cd4aab62e3
commit
deb954772d
6 changed files with 246 additions and 238 deletions
|
|
@ -198,9 +198,13 @@ func parse(path string, mode uint) (*ast.Program, *parseErrors) {
|
|||
// Templates
|
||||
|
||||
// Return text for an AST node.
|
||||
func nodeText(node interface{}, mode uint) []byte {
|
||||
func nodeText(node interface{}) []byte {
|
||||
var buf bytes.Buffer;
|
||||
tw := makeTabwriter(&buf);
|
||||
mode := uint(0);
|
||||
if _, isProgram := node.(*ast.Program); isProgram {
|
||||
mode = printer.DocComments;
|
||||
}
|
||||
printer.Fprint(tw, node, mode);
|
||||
tw.Flush();
|
||||
return buf.Data();
|
||||
|
|
@ -219,9 +223,9 @@ func toText(x interface{}) []byte {
|
|||
case String:
|
||||
return strings.Bytes(v.String());
|
||||
case ast.Decl:
|
||||
return nodeText(v, printer.ExportsOnly);
|
||||
return nodeText(v);
|
||||
case ast.Expr:
|
||||
return nodeText(v, printer.ExportsOnly);
|
||||
return nodeText(v);
|
||||
}
|
||||
var buf bytes.Buffer;
|
||||
fmt.Fprint(&buf, x);
|
||||
|
|
@ -331,7 +335,7 @@ func serveGoSource(c *http.Conn, name string) {
|
|||
|
||||
var buf bytes.Buffer;
|
||||
fmt.Fprintln(&buf, "<pre>");
|
||||
template.HtmlEscape(&buf, nodeText(prog, printer.DocComments));
|
||||
template.HtmlEscape(&buf, nodeText(prog));
|
||||
fmt.Fprintln(&buf, "</pre>");
|
||||
|
||||
servePage(c, name + " - Go source", buf.Data());
|
||||
|
|
@ -491,6 +495,7 @@ func (p *pakDesc) Doc() (*doc.PackageDoc, *parseErrors) {
|
|||
r.Init(prog.Name.Value, p.importpath);
|
||||
}
|
||||
i++;
|
||||
ast.FilterExports(prog); // we only care about exports
|
||||
r.AddProgram(prog);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue