1
0
mirror of https://github.com/golang/go synced 2024-11-13 17:20:22 -07:00

weekend snapshot

- fixed a minor bug
- some initial code to extract interface of a package

R=r
OCL=25866
CL=25866
This commit is contained in:
Robert Griesemer 2009-03-06 16:54:26 -08:00
parent 5e400ebf18
commit 6309076158
2 changed files with 24 additions and 3 deletions

View File

@ -1016,7 +1016,7 @@ func (P *Printer) DoVarDecl(d *ast.VarDecl) {
} }
func (P *Printer) DoFuncDecl(d *ast.FuncDecl) { func (P *Printer) funcDecl(d *ast.FuncDecl, with_body bool) {
P.Token(d.Pos_, token.FUNC); P.Token(d.Pos_, token.FUNC);
P.separator = blank; P.separator = blank;
if recv := d.Recv; recv != nil { if recv := d.Recv; recv != nil {
@ -1032,7 +1032,7 @@ func (P *Printer) DoFuncDecl(d *ast.FuncDecl) {
} }
P.Expr(d.Ident); P.Expr(d.Ident);
P.Signature(d.Sig); P.Signature(d.Sig);
if d.Body != nil { if with_body && d.Body != nil {
P.separator = blank; P.separator = blank;
P.Block(d.Body, true); P.Block(d.Body, true);
} }
@ -1040,6 +1040,11 @@ func (P *Printer) DoFuncDecl(d *ast.FuncDecl) {
} }
func (P *Printer) DoFuncDecl(d *ast.FuncDecl) {
P.funcDecl(d, true);
}
func (P *Printer) DoDeclList(d *ast.DeclList) { func (P *Printer) DoDeclList(d *ast.DeclList) {
if !*def || d.Tok == token.IMPORT || d.Tok == token.VAR { if !*def || d.Tok == token.IMPORT || d.Tok == token.VAR {
P.Token(d.Pos, d.Tok); P.Token(d.Pos, d.Tok);
@ -1073,6 +1078,20 @@ func (P *Printer) Decl(d ast.Decl) {
} }
// ----------------------------------------------------------------------------
// Interface
func (P *Printer) Interface(p *ast.Program) {
for i := 0; i < len(p.Decls); i++ {
decl := p.Decls[i];
// TODO use type switch
if fun, is_fun := decl.(*ast.FuncDecl); is_fun {
P.funcDecl(fun, false);
}
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Program // Program
@ -1110,7 +1129,8 @@ func Print(writer io.Write, html bool, prog *ast.Program) {
if P.html { if P.html {
err := templ.Apply(text, "<!--", template.Substitution { err := templ.Apply(text, "<!--", template.Substitution {
"PACKAGE-->" : func() { /* P.Expr(prog.Ident); */ }, "PACKAGE-->" : func() { P.Printf("%s", prog.Ident.Str); },
"INTERFACE-->" : func() { P.Interface(prog); },
"BODY-->" : func() { P.Program(prog); }, "BODY-->" : func() { P.Program(prog); },
}); });
if err != nil { if err != nil {

View File

@ -1,3 +1,4 @@
<h1><!--PACKAGE--></h1> <h1><!--PACKAGE--></h1>
<pre> <pre>