add support for variable formatters

R=rsc
DELTA=134  (75 added, 41 deleted, 18 changed)
OCL=27245
CL=27247
This commit is contained in:
Rob Pike 2009-04-08 23:33:31 -07:00
parent f95da9a639
commit 3a7df4dde0
3 changed files with 91 additions and 57 deletions

View file

@ -914,3 +914,17 @@ func NewValue(e interface {}) Value {
*ap = value;
return newValueAddr(typ, Addr(ap));
}
// Indirect indirects one level through a value, if it is a pointer.
// If not a pointer, the value is returned unchanged.
// Useful when walking arbitrary data structures.
func Indirect(v Value) Value {
if v.Kind() == PtrKind {
p := v.(PtrValue);
if p.Get() == nil {
return nil
}
v = p.Sub()
}
return v
}