mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile/internal/syntax: clean up node printing API
Preparation for using the syntax printer as expression printer in types2. - Introduced Form to control printing format - Cleaned up/added String and ShortString convenience functions - Implemented ShortForm format which prints … for non-empty function and composite literal bodies - Added test to check write error handling Change-Id: Ie86e46d766fb60fcf07ef643c7788b2ef440ffa8 Reviewed-on: https://go-review.googlesource.com/c/go/+/282552 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
5b9152de57
commit
934f9dc0ef
4 changed files with 94 additions and 27 deletions
|
|
@ -26,7 +26,7 @@ func Fdump(w io.Writer, n Node) (err error) {
|
|||
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
err = e.(localError).err // re-panics if it's not a localError
|
||||
err = e.(writeError).err // re-panics if it's not a writeError
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -82,16 +82,16 @@ func (p *dumper) Write(data []byte) (n int, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// localError wraps locally caught errors so we can distinguish
|
||||
// writeError wraps locally caught write errors so we can distinguish
|
||||
// them from genuine panics which we don't want to return as errors.
|
||||
type localError struct {
|
||||
type writeError struct {
|
||||
err error
|
||||
}
|
||||
|
||||
// printf is a convenience wrapper that takes care of print errors.
|
||||
func (p *dumper) printf(format string, args ...interface{}) {
|
||||
if _, err := fmt.Fprintf(p, format, args...); err != nil {
|
||||
panic(localError{err})
|
||||
panic(writeError{err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue