mirror of
https://github.com/golang/go
synced 2024-11-21 23:24:41 -07:00
go/ast: remove unnecessary result value from ast.Fprint/Print
These functions are mostly of interest for debugging; the number of bytes written is uninteresting. R=r, bradfitz CC=golang-dev https://golang.org/cl/5540046
This commit is contained in:
parent
c2ffd9d0c2
commit
06479f766c
@ -36,7 +36,7 @@ func NotNilFilter(_ string, v reflect.Value) bool {
|
|||||||
// struct fields for which f(fieldname, fieldvalue) is true are
|
// struct fields for which f(fieldname, fieldvalue) is true are
|
||||||
// are printed; all others are filtered from the output.
|
// are printed; all others are filtered from the output.
|
||||||
//
|
//
|
||||||
func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) (n int, err error) {
|
func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) (err error) {
|
||||||
// setup printer
|
// setup printer
|
||||||
p := printer{
|
p := printer{
|
||||||
output: w,
|
output: w,
|
||||||
@ -48,7 +48,6 @@ func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) (n i
|
|||||||
|
|
||||||
// install error handler
|
// install error handler
|
||||||
defer func() {
|
defer func() {
|
||||||
n = p.written
|
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
err = e.(localError).err // re-panics if it's not a localError
|
err = e.(localError).err // re-panics if it's not a localError
|
||||||
}
|
}
|
||||||
@ -67,19 +66,18 @@ func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) (n i
|
|||||||
|
|
||||||
// Print prints x to standard output, skipping nil fields.
|
// Print prints x to standard output, skipping nil fields.
|
||||||
// Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).
|
// Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).
|
||||||
func Print(fset *token.FileSet, x interface{}) (int, error) {
|
func Print(fset *token.FileSet, x interface{}) error {
|
||||||
return Fprint(os.Stdout, fset, x, NotNilFilter)
|
return Fprint(os.Stdout, fset, x, NotNilFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
type printer struct {
|
type printer struct {
|
||||||
output io.Writer
|
output io.Writer
|
||||||
fset *token.FileSet
|
fset *token.FileSet
|
||||||
filter FieldFilter
|
filter FieldFilter
|
||||||
ptrmap map[interface{}]int // *T -> line number
|
ptrmap map[interface{}]int // *T -> line number
|
||||||
written int // number of bytes written to output
|
indent int // current indentation level
|
||||||
indent int // current indentation level
|
last byte // the last byte processed by Write
|
||||||
last byte // the last byte processed by Write
|
line int // current line number
|
||||||
line int // current line number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var indent = []byte(". ")
|
var indent = []byte(". ")
|
||||||
@ -122,9 +120,7 @@ type localError struct {
|
|||||||
|
|
||||||
// printf is a convenience wrapper that takes care of print errors.
|
// printf is a convenience wrapper that takes care of print errors.
|
||||||
func (p *printer) printf(format string, args ...interface{}) {
|
func (p *printer) printf(format string, args ...interface{}) {
|
||||||
n, err := fmt.Fprintf(p, format, args...)
|
if _, err := fmt.Fprintf(p, format, args...); err != nil {
|
||||||
p.written += n
|
|
||||||
if err != nil {
|
|
||||||
panic(localError{err})
|
panic(localError{err})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func TestPrint(t *testing.T) {
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
if _, err := Fprint(&buf, nil, test.x, nil); err != nil {
|
if err := Fprint(&buf, nil, test.x, nil); err != nil {
|
||||||
t.Errorf("Fprint failed: %s", err)
|
t.Errorf("Fprint failed: %s", err)
|
||||||
}
|
}
|
||||||
if s, ts := trim(buf.String()), trim(test.s); s != ts {
|
if s, ts := trim(buf.String()), trim(test.s); s != ts {
|
||||||
|
Loading…
Reference in New Issue
Block a user