Commit 85d33918 authored by Nigel Tao's avatar Nigel Tao

cmd, pkg/go/*: fix "go vet" warnings for go/ast and go/printer

struct literals.

R=gri
CC=golang-dev
https://golang.org/cl/5653073
parent fa8bc8a6
......@@ -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
......@@ -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,
},
}
......
......@@ -104,8 +104,8 @@ const (
)
var printConfig = &printer.Config{
printerMode,
tabWidth,
Mode: printerMode,
Tabwidth: tabWidth,
}
func gofmtFile(f *ast.File) ([]byte, error) {
......
......@@ -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
......
......@@ -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.
......
......@@ -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)
}
......
......@@ -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
......
......@@ -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)
}
......@@ -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)
}
......
......@@ -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
}
......
......@@ -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) {
......
......@@ -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)
}
......@@ -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())
}
}
}
......@@ -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
......
This diff is collapsed.
......@@ -370,7 +370,7 @@ func (p *printer) isOneLineFieldList(list []*ast.Field) bool {
}
func (p *printer) setLineComment(text string) {
p.setComment(&ast.CommentGroup{[]*ast.Comment{{token.NoPos, text}}})
p.setComment(&ast.CommentGroup{List: []*ast.Comment{{Slash: token.NoPos, Text: text}}})
}
func (p *printer) fieldList(fields *ast.FieldList, isStruct, isIncomplete bool) {
......
......@@ -283,10 +283,10 @@ func fibo(n int) {
t.Error("expected offset 1") // error in test
}
testComment(t, f, len(src), &ast.Comment{pos, "//-style comment"})
testComment(t, f, len(src), &ast.Comment{pos, "/*-style comment */"})
testComment(t, f, len(src), &ast.Comment{pos, "/*-style \n comment */"})
testComment(t, f, len(src), &ast.Comment{pos, "/*-style comment \n\n\n */"})
testComment(t, f, len(src), &ast.Comment{Slash: pos, Text: "//-style comment"})
testComment(t, f, len(src), &ast.Comment{Slash: pos, Text: "/*-style comment */"})
testComment(t, f, len(src), &ast.Comment{Slash: pos, Text: "/*-style \n comment */"})
testComment(t, f, len(src), &ast.Comment{Slash: pos, Text: "/*-style comment \n\n\n */"})
}
type visitor chan *ast.Ident
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment