Last active
March 23, 2016 17:05
-
-
Save bprosnitz/45c2ec35e214522d5685 to your computer and use it in GitHub Desktop.
A vdl target that pretty prints calls to the interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package vom | |
import ( | |
"fmt" | |
"os" | |
"strings" | |
"v.io/v23/vdl" | |
) | |
func targetDebugMsg(method string, depth int, args ...interface{}) { | |
argStrs := make([]string, len(args)) | |
for i := range args { | |
argStrs[i] = fmt.Sprintf("%v", args[i]) | |
} | |
fmt.Fprintf(os.Stderr, "%s %s(%s)\n", strings.Repeat("\t", depth), method, strings.Join(argStrs, ", ")) | |
} | |
type DebuggingTarget struct { | |
depth int | |
} | |
func (t *DebuggingTarget) msg(method string, args ...interface{}) { | |
targetDebugMsg(method, t.depth, args...) | |
} | |
func (t *DebuggingTarget) FromBool(src bool, tt *vdl.Type) error { | |
t.msg("FromBool", src, tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromUint(src uint64, tt *vdl.Type) error { | |
t.msg("FromUint", src, tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromInt(src int64, tt *vdl.Type) error { | |
t.msg("FromInt", src, tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromFloat(src float64, tt *vdl.Type) error { | |
t.msg("FromFloat", src, tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromComplex(src complex128, tt *vdl.Type) error { | |
t.msg("FromComplex", src, tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromBytes(src []byte, tt *vdl.Type) error { | |
t.msg("FromBytes", src, tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromString(src string, tt *vdl.Type) error { | |
t.msg("FromString", src, tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromEnumLabel(src string, tt *vdl.Type) error { | |
t.msg("FromEnumLabel", src, tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromTypeObject(tt *vdl.Type) error { | |
t.msg("FromTypeObject", tt) | |
return nil | |
} | |
func (t *DebuggingTarget) FromZero(tt *vdl.Type) error { | |
t.msg("FromZero", tt) | |
return nil | |
} | |
func (t *DebuggingTarget) StartList(tt *vdl.Type, len int) (vdl.ListTarget, error) { | |
t.msg("StartList", tt, len) | |
return &DebuggingListTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingTarget) FinishList(lt vdl.ListTarget) error { | |
t.msg("FinishList") | |
return nil | |
} | |
func (t *DebuggingTarget) StartSet(tt *vdl.Type, len int) (vdl.SetTarget, error) { | |
t.msg("StartSet", tt, len) | |
return &DebuggingSetTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingTarget) FinishSet(lt vdl.SetTarget) error { | |
t.msg("FinishSet") | |
return nil | |
} | |
func (t *DebuggingTarget) StartMap(tt *vdl.Type, len int) (vdl.MapTarget, error) { | |
t.msg("StartMap", tt, len) | |
return &DebuggingMapTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingTarget) FinishMap(lt vdl.MapTarget) error { | |
t.msg("FinishMap") | |
return nil | |
} | |
func (t *DebuggingTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) { | |
t.msg("StartFields", tt) | |
return &DebuggingFieldsTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingTarget) FinishFields(lt vdl.FieldsTarget) error { | |
t.msg("FinishFields") | |
return nil | |
} | |
type DebuggingListTarget struct { | |
depth int | |
} | |
func (t *DebuggingListTarget) msg(method string, args ...interface{}) { | |
targetDebugMsg(method, t.depth, args...) | |
} | |
func (t *DebuggingListTarget) StartElem(index int) (elem vdl.Target, _ error) { | |
t.msg("StartElem", index) | |
return &DebuggingTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingListTarget) FinishElem(elem vdl.Target) error { | |
t.msg("FinishElem") | |
return nil | |
} | |
type DebuggingSetTarget struct { | |
depth int | |
} | |
func (t *DebuggingSetTarget) msg(method string, args ...interface{}) { | |
targetDebugMsg(method, t.depth, args...) | |
} | |
func (t *DebuggingSetTarget) StartKey() (key vdl.Target, _ error) { | |
t.msg("StartKey") | |
return &DebuggingTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingSetTarget) FinishKey(key vdl.Target) error { | |
t.msg("FinishKey") | |
return nil | |
} | |
type DebuggingMapTarget struct { | |
depth int | |
} | |
func (t *DebuggingMapTarget) msg(method string, args ...interface{}) { | |
targetDebugMsg(method, t.depth, args...) | |
} | |
func (t *DebuggingMapTarget) StartKey() (key vdl.Target, _ error) { | |
t.msg("StartKey") | |
return &DebuggingTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingMapTarget) FinishKeyStartField(key vdl.Target) (field vdl.Target, _ error) { | |
t.msg("FinishKeyStartField") | |
return &DebuggingTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingMapTarget) FinishField(key, field vdl.Target) error { | |
t.msg("FinishField") | |
return nil | |
} | |
type DebuggingFieldsTarget struct { | |
depth int | |
} | |
func (t *DebuggingFieldsTarget) msg(method string, args ...interface{}) { | |
targetDebugMsg(method, t.depth, args...) | |
} | |
func (t *DebuggingFieldsTarget) StartField(name string) (key, field vdl.Target, _ error) { | |
t.msg("StartField", name) | |
return nil, &DebuggingTarget{depth: t.depth + 1}, nil | |
} | |
func (t *DebuggingFieldsTarget) FinishField(key, field vdl.Target) error { | |
t.msg("FinishField") | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment