Skip to content
This repository has been archived by the owner on May 2, 2018. It is now read-only.

Commit

Permalink
cmd, pkg/go/*: fix "go vet" warnings for go/ast and go/printer
Browse files Browse the repository at this point in the history
struct literals.

R=gri
CC=golang-dev
https://golang.org/cl/5653073
  • Loading branch information
nigeltao committed Feb 16, 2012
1 parent fa8bc8a commit 85d3391
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 112 deletions.
10 changes: 8 additions & 2 deletions src/cmd/fix/httpfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func httpfs(f *ast.File) bool {
}
dir, prefix := call.Args[0], call.Args[1]
call.Args = []ast.Expr{&ast.CallExpr{
Fun: &ast.SelectorExpr{ast.NewIdent("http"), ast.NewIdent("Dir")},
Fun: &ast.SelectorExpr{
X: ast.NewIdent("http"),
Sel: ast.NewIdent("Dir"),
},
Args: []ast.Expr{dir},
}}
wrapInStripHandler := true
Expand All @@ -53,7 +56,10 @@ func httpfs(f *ast.File) bool {
call.Args = []ast.Expr{
prefix,
&ast.CallExpr{
Fun: &ast.SelectorExpr{ast.NewIdent("http"), ast.NewIdent("FileServer")},
Fun: &ast.SelectorExpr{
X: ast.NewIdent("http"),
Sel: ast.NewIdent("FileServer"),
},
Args: call.Args,
},
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/fix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ const (
)

var printConfig = &printer.Config{
printerMode,
tabWidth,
Mode: printerMode,
Tabwidth: tabWidth,
}

func gofmtFile(f *ast.File) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/fix/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func reflectFn(f *ast.File) bool {
}
*n = v
case *ast.IfStmt:
x := &ast.ExprStmt{n.Cond}
x := &ast.ExprStmt{X: n.Cond}
if reflectFixTypecheck(&n.Init, nil, []ast.Stmt{x, n.Body, n.Else}) {
n.Cond = x.X
fixed = true
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/godoc/codewalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func loadCodewalk(filename string) (*Codewalk, error) {
d.Entity = xml.HTMLEntity
err = d.Decode(cw)
if err != nil {
return nil, &os.PathError{"parsing", filename, err}
return nil, &os.PathError{Op: "parsing", Path: filename, Err: err}
}

// Compute file list, evaluate line numbers for addresses.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/godoc/godoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func writeNode(w io.Writer, fset *token.FileSet, x interface{}) {
// with an another printer mode (which is more efficiently
// implemented in the printer than here with another layer)
mode := printer.TabIndent | printer.UseSpaces
err := (&printer.Config{mode, *tabwidth}).Fprint(&tconv{output: w}, fset, x)
err := (&printer.Config{Mode: mode, Tabwidth: *tabwidth}).Fprint(&tconv{output: w}, fset, x)
if err != nil {
log.Print(err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/godoc/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func parseFiles(fset *token.FileSet, filenames []string) (pkgs map[string]*ast.P
pkg, found := pkgs[name]
if !found {
// TODO(gri) Use NewPackage here; reconsider ParseFiles API.
pkg = &ast.Package{name, nil, nil, make(map[string]*ast.File)}
pkg = &ast.Package{Name: name, Files: make(map[string]*ast.File)}
pkgs[name] = pkg
}
pkg.Files[filename] = file
Expand Down
16 changes: 14 additions & 2 deletions src/cmd/godoc/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ func genSnippet(fset *token.FileSet, d *ast.GenDecl, id *ast.Ident) *Snippet {
}

// only use the spec containing the id for the snippet
dd := &ast.GenDecl{d.Doc, d.Pos(), d.Tok, d.Lparen, []ast.Spec{s}, d.Rparen}
dd := &ast.GenDecl{
Doc: d.Doc,
TokPos: d.Pos(),
Tok: d.Tok,
Lparen: d.Lparen,
Specs: []ast.Spec{s},
Rparen: d.Rparen,
}

return newSnippet(fset, dd, id)
}
Expand All @@ -73,7 +80,12 @@ func funcSnippet(fset *token.FileSet, d *ast.FuncDecl, id *ast.Ident) *Snippet {
}

// only use the function signature for the snippet
dd := &ast.FuncDecl{d.Doc, d.Recv, d.Name, d.Type, nil}
dd := &ast.FuncDecl{
Doc: d.Doc,
Recv: d.Recv,
Name: d.Name,
Type: d.Type,
}

return newSnippet(fset, dd, id)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/gofmt/gofmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error
}

var buf bytes.Buffer
err = (&printer.Config{printerMode, *tabWidth}).Fprint(&buf, fset, file)
err = (&printer.Config{Mode: printerMode, Tabwidth: *tabWidth}).Fprint(&buf, fset, file)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/gofmt/long_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func gofmt(filename string, src *bytes.Buffer) error {
}
ast.SortImports(fset, f)
src.Reset()
return (&printer.Config{printerMode, *tabWidth}).Fprint(src, fset, f)
return (&printer.Config{Mode: printerMode, Tabwidth: *tabWidth}).Fprint(src, fset, f)
}

func testFile(t *testing.T, b1, b2 *bytes.Buffer, filename string) {
Expand Down
10 changes: 6 additions & 4 deletions src/pkg/go/doc/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,10 @@ func (r *reader) readFile(src *ast.File) {
// gets to (re-)use the declaration documentation
// if there's none associated with the spec itself
fake := &ast.GenDecl{
d.Doc, d.Pos(), token.TYPE, token.NoPos,
[]ast.Spec{s}, token.NoPos,
Doc: d.Doc,
TokPos: d.Pos(),
Tok: token.TYPE,
Specs: []ast.Spec{s},
}
r.readType(fake, s)
}
Expand All @@ -460,7 +462,7 @@ func (r *reader) readFile(src *ast.File) {
// non-empty BUG comment; collect comment without BUG prefix
list := append([]*ast.Comment(nil), c.List...) // make a copy
list[0].Text = text[m[1]:]
r.bugs = append(r.bugs, (&ast.CommentGroup{list}).Text())
r.bugs = append(r.bugs, (&ast.CommentGroup{List: list}).Text())
}
}
}
Expand Down Expand Up @@ -530,7 +532,7 @@ func customizeRecv(f *Func, recvTypeName string, embeddedIsPtr bool, level int)
_, origRecvIsPtr := newField.Type.(*ast.StarExpr)
var typ ast.Expr = ast.NewIdent(recvTypeName)
if !embeddedIsPtr && origRecvIsPtr {
typ = &ast.StarExpr{token.NoPos, typ}
typ = &ast.StarExpr{X: typ}
}
newField.Type = typ

Expand Down
Loading

0 comments on commit 85d3391

Please sign in to comment.