add method Value() Value to InterfaceValue.
use Value() in print to print underlying value
from interface.
before:
package main
import "fmt"
func main() {
x := []interface{} {1, "hello", 2.5};
fmt.Println(x[0], x[1], x[2], x);
}
1 hello 2.5 [<non-nil interface> <non-nil interface> <non-nil interface>]
after:
1 hello 2.5 [1 hello 2.5]
R=r
DELTA=44 (22 added, 16 deleted, 6 changed)
OCL=27139
CL=27141
diff --git a/src/lib/reflect/value.go b/src/lib/reflect/value.go
index 7bd6f3b..ad0cd46 100644
--- a/src/lib/reflect/value.go
+++ b/src/lib/reflect/value.go
@@ -34,6 +34,8 @@
Interface() interface {};
}
+func NewValue(e interface{}) Value;
+
// commonValue fields and functionality for all values
type commonValue struct {
@@ -744,6 +746,7 @@
type InterfaceValue interface {
Value;
Get() interface {}; // Get the underlying interface{} value.
+ Value() Value;
}
type interfaceValueStruct struct {
@@ -754,6 +757,14 @@
return *(*interface{})(v.addr)
}
+func (v *interfaceValueStruct) Value() Value {
+ i := v.Get();
+ if i == nil {
+ return nil;
+ }
+ return NewValue(i);
+}
+
func interfaceCreator(typ Type, addr Addr) Value {
return &interfaceValueStruct{ commonValue{InterfaceKind, typ, addr} }
}