Source File
print.go
Belonging Package
go/ast
package ast
import (
)
type FieldFilter func(name string, value reflect.Value) bool
defer func() {
if := recover(); != nil {
= .(localError).err // re-panics if it's not a localError
}
}()
func ( *token.FileSet, interface{}) error {
return Fprint(os.Stdout, , , NotNilFilter)
}
type printer struct {
output io.Writer
fset *token.FileSet
filter FieldFilter
ptrmap map[interface{}]int // *T -> line number
indent int // current indentation level
last byte // the last byte processed by Write
line int // current line number
}
var indent = []byte(". ")
func ( *printer) ( []byte) ( int, error) {
var int
type localError struct {
err error
}
func ( *printer) ( reflect.Value) {
if !NotNilFilter("", ) {
.printf("nil")
return
}
switch .Kind() {
case reflect.Interface:
.(.Elem())
case reflect.Map:
.printf("%s (len = %d) {", .Type(), .Len())
if .Len() > 0 {
.indent++
.printf("\n")
for , := range .MapKeys() {
.()
.printf(": ")
.(.MapIndex())
.printf("\n")
}
.indent--
}
.printf("}")
case reflect.Ptr:
:= .Interface()
if , := .ptrmap[]; {
.printf("(obj @ %d)", )
} else {
.ptrmap[] = .line
.(.Elem())
}
case reflect.Array:
.printf("%s {", .Type())
if .Len() > 0 {
.indent++
.printf("\n")
for , := 0, .Len(); < ; ++ {
.printf("%d: ", )
.(.Index())
.printf("\n")
}
.indent--
}
.printf("}")
case reflect.Slice:
if , := .Interface().([]byte); {
.printf("%#q", )
return
}
.printf("%s (len = %d) {", .Type(), .Len())
if .Len() > 0 {
.indent++
.printf("\n")
for , := 0, .Len(); < ; ++ {
.printf("%d: ", )
.(.Index())
.printf("\n")
}
.indent--
}
.printf("}")
case reflect.Struct:
:= .Type()
.printf("%s {", )
.indent++
:= true
.printf("%q", )
return
.printf("%v", )
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |