summaryrefslogtreecommitdiff
path: root/src/pkg/reflect
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/reflect')
-rw-r--r--src/pkg/reflect/all_test.go634
-rw-r--r--src/pkg/reflect/deepequal.go58
-rw-r--r--src/pkg/reflect/tostring_test.go64
-rw-r--r--src/pkg/reflect/type.go322
-rw-r--r--src/pkg/reflect/value.go616
5 files changed, 847 insertions, 847 deletions
diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go
index b94db00d9..974cca8c3 100644
--- a/src/pkg/reflect/all_test.go
+++ b/src/pkg/reflect/all_test.go
@@ -5,27 +5,27 @@
package reflect_test
import (
- "io";
- "os";
- . "reflect";
- "testing";
- "unsafe";
+ "io"
+ "os"
+ . "reflect"
+ "testing"
+ "unsafe"
)
type integer int
type T struct {
- a int;
- b float64;
- c string;
- d *int;
+ a int
+ b float64
+ c string
+ d *int
}
type pair struct {
- i interface{};
- s string;
+ i interface{}
+ s string
}
-func isDigit(c uint8) bool { return '0' <= c && c <= '9' }
+func isDigit(c uint8) bool { return '0' <= c && c <= '9' }
func assert(t *testing.T, s, want string) {
if s != want {
@@ -33,7 +33,7 @@ func assert(t *testing.T, s, want string) {
}
}
-func typestring(i interface{}) string { return Typeof(i).String() }
+func typestring(i interface{}) string { return Typeof(i).String() }
var typeTests = []pair{
pair{struct{ x int }{}, "int"},
@@ -58,96 +58,96 @@ var typeTests = []pair{
pair{struct{ x (chan<- string) }{}, "chan<- string"},
pair{struct {
x struct {
- c chan *int32;
- d float32;
- };
+ c chan *int32
+ d float32
+ }
}{},
"struct { c chan *int32; d float32 }",
},
pair{struct{ x (func(a int8, b int32)) }{}, "func(int8, int32)"},
pair{struct {
x struct {
- c func(chan *integer, *int8);
- };
+ c func(chan *integer, *int8)
+ }
}{},
"struct { c func(chan *reflect_test.integer, *int8) }",
},
pair{struct {
x struct {
- a int8;
- b int32;
- };
+ a int8
+ b int32
+ }
}{},
"struct { a int8; b int32 }",
},
pair{struct {
x struct {
- a int8;
- b int8;
- c int32;
- };
+ a int8
+ b int8
+ c int32
+ }
}{},
"struct { a int8; b int8; c int32 }",
},
pair{struct {
x struct {
- a int8;
- b int8;
- c int8;
- d int32;
- };
+ a int8
+ b int8
+ c int8
+ d int32
+ }
}{},
"struct { a int8; b int8; c int8; d int32 }",
},
pair{struct {
x struct {
- a int8;
- b int8;
- c int8;
- d int8;
- e int32;
- };
+ a int8
+ b int8
+ c int8
+ d int8
+ e int32
+ }
}{},
"struct { a int8; b int8; c int8; d int8; e int32 }",
},
pair{struct {
x struct {
- a int8;
- b int8;
- c int8;
- d int8;
- e int8;
- f int32;
- };
+ a int8
+ b int8
+ c int8
+ d int8
+ e int8
+ f int32
+ }
}{},
"struct { a int8; b int8; c int8; d int8; e int8; f int32 }",
},
pair{struct {
x struct {
- a int8 "hi there";
- };
+ a int8 "hi there"
+ }
}{},
`struct { a int8 "hi there" }`,
},
pair{struct {
x struct {
- a int8 "hi \x00there\t\n\"\\";
- };
+ a int8 "hi \x00there\t\n\"\\"
+ }
}{},
`struct { a int8 "hi \x00there\t\n\"\\" }`,
},
pair{struct {
x struct {
- f func(args ...);
- };
+ f func(args ...)
+ }
}{},
"struct { f func(...) }",
},
pair{struct {
x (interface {
- a(func(func(int) int) (func(func(int)) int));
- b();
- });
+ a(func(func(int) int) (func(func(int)) int))
+ b()
+ })
}{},
"interface { a (func(func(int) (int)) (func(func(int)) (int))); b () }",
},
@@ -173,34 +173,34 @@ var valueTests = []pair{
pair{(map[string]int32)(nil), "map[string] int32{<can't iterate on maps>}"},
pair{(chan<- string)(nil), "chan<- string"},
pair{(struct {
- c chan *int32;
- d float32;
+ c chan *int32
+ d float32
}){},
"struct { c chan *int32; d float32 }{chan *int32, 0}",
},
pair{(func(a int8, b int32))(nil), "func(int8, int32)(0)"},
pair{(struct {
- c func(chan *integer, *int8);
+ c func(chan *integer, *int8)
}){},
"struct { c func(chan *reflect_test.integer, *int8) }{func(chan *reflect_test.integer, *int8)(0)}",
},
pair{(struct {
- a int8;
- b int32;
+ a int8
+ b int32
}){},
"struct { a int8; b int32 }{0, 0}",
},
pair{(struct {
- a int8;
- b int8;
- c int32;
+ a int8
+ b int8
+ c int32
}){},
"struct { a int8; b int8; c int32 }{0, 0, 0}",
},
}
func testType(t *testing.T, i int, typ Type, want string) {
- s := typ.String();
+ s := typ.String()
if s != want {
t.Errorf("#%d: have %#q, want %#q", i, s, want)
}
@@ -214,7 +214,7 @@ func TestTypes(t *testing.T) {
func TestSet(t *testing.T) {
for i, tt := range valueTests {
- v := NewValue(tt.i);
+ v := NewValue(tt.i)
switch v := v.(type) {
case *IntValue:
v.Set(132)
@@ -247,7 +247,7 @@ func TestSet(t *testing.T) {
case *BoolValue:
v.Set(true)
}
- s := valueToString(v);
+ s := valueToString(v)
if s != tt.s {
t.Errorf("#%d: have %#q, want %#q", i, s, tt.s)
}
@@ -256,7 +256,7 @@ func TestSet(t *testing.T) {
func TestSetValue(t *testing.T) {
for i, tt := range valueTests {
- v := NewValue(tt.i);
+ v := NewValue(tt.i)
switch v := v.(type) {
case *IntValue:
v.SetValue(NewValue(int(132)))
@@ -289,7 +289,7 @@ func TestSetValue(t *testing.T) {
case *BoolValue:
v.SetValue(NewValue(true))
}
- s := valueToString(v);
+ s := valueToString(v)
if s != tt.s {
t.Errorf("#%d: have %#q, want %#q", i, s, tt.s)
}
@@ -313,7 +313,7 @@ var valueToStringTests = []pair{
func TestValueToString(t *testing.T) {
for i, test := range valueToStringTests {
- s := valueToString(NewValue(test.i));
+ s := valueToString(NewValue(test.i))
if s != test.s {
t.Errorf("#%d: have %#q, want %#q", i, s, test.s)
}
@@ -321,136 +321,136 @@ func TestValueToString(t *testing.T) {
}
func TestArrayElemSet(t *testing.T) {
- v := NewValue([10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
- v.(*ArrayValue).Elem(4).(*IntValue).Set(123);
- s := valueToString(v);
- const want = "[10]int{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}";
+ v := NewValue([10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
+ v.(*ArrayValue).Elem(4).(*IntValue).Set(123)
+ s := valueToString(v)
+ const want = "[10]int{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}"
if s != want {
t.Errorf("[10]int: have %#q want %#q", s, want)
}
- v = NewValue([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
- v.(*SliceValue).Elem(4).(*IntValue).Set(123);
- s = valueToString(v);
- const want1 = "[]int{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}";
+ v = NewValue([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
+ v.(*SliceValue).Elem(4).(*IntValue).Set(123)
+ s = valueToString(v)
+ const want1 = "[]int{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}"
if s != want1 {
t.Errorf("[]int: have %#q want %#q", s, want1)
}
}
func TestPtrPointTo(t *testing.T) {
- var ip *int32;
- var i int32 = 1234;
- vip := NewValue(&ip);
- vi := NewValue(i);
- vip.(*PtrValue).Elem().(*PtrValue).PointTo(vi);
+ var ip *int32
+ var i int32 = 1234
+ vip := NewValue(&ip)
+ vi := NewValue(i)
+ vip.(*PtrValue).Elem().(*PtrValue).PointTo(vi)
if *ip != 1234 {
t.Errorf("got %d, want 1234", *ip)
}
}
func TestAll(t *testing.T) {
- testType(t, 1, Typeof((int8)(0)), "int8");
- testType(t, 2, Typeof((*int8)(nil)).(*PtrType).Elem(), "int8");
+ testType(t, 1, Typeof((int8)(0)), "int8")
+ testType(t, 2, Typeof((*int8)(nil)).(*PtrType).Elem(), "int8")
typ := Typeof((*struct {
- c chan *int32;
- d float32;
- })(nil));
- testType(t, 3, typ, "*struct { c chan *int32; d float32 }");
- etyp := typ.(*PtrType).Elem();
- testType(t, 4, etyp, "struct { c chan *int32; d float32 }");
- styp := etyp.(*StructType);
- f := styp.Field(0);
- testType(t, 5, f.Type, "chan *int32");
-
- f, present := styp.FieldByName("d");
+ c chan *int32
+ d float32
+ })(nil))
+ testType(t, 3, typ, "*struct { c chan *int32; d float32 }")
+ etyp := typ.(*PtrType).Elem()
+ testType(t, 4, etyp, "struct { c chan *int32; d float32 }")
+ styp := etyp.(*StructType)
+ f := styp.Field(0)
+ testType(t, 5, f.Type, "chan *int32")
+
+ f, present := styp.FieldByName("d")
if !present {
t.Errorf("FieldByName says present field is absent")
}
- testType(t, 6, f.Type, "float32");
+ testType(t, 6, f.Type, "float32")
- f, present = styp.FieldByName("absent");
+ f, present = styp.FieldByName("absent")
if present {
t.Errorf("FieldByName says absent field is present")
}
- typ = Typeof([32]int32{});
- testType(t, 7, typ, "[32]int32");
- testType(t, 8, typ.(*ArrayType).Elem(), "int32");
+ typ = Typeof([32]int32{})
+ testType(t, 7, typ, "[32]int32")
+ testType(t, 8, typ.(*ArrayType).Elem(), "int32")
- typ = Typeof((map[string]*int32)(nil));
- testType(t, 9, typ, "map[string] *int32");
- mtyp := typ.(*MapType);
- testType(t, 10, mtyp.Key(), "string");
- testType(t, 11, mtyp.Elem(), "*int32");
+ typ = Typeof((map[string]*int32)(nil))
+ testType(t, 9, typ, "map[string] *int32")
+ mtyp := typ.(*MapType)
+ testType(t, 10, mtyp.Key(), "string")
+ testType(t, 11, mtyp.Elem(), "*int32")
- typ = Typeof((chan<- string)(nil));
- testType(t, 12, typ, "chan<- string");
- testType(t, 13, typ.(*ChanType).Elem(), "string");
+ typ = Typeof((chan<- string)(nil))
+ testType(t, 12, typ, "chan<- string")
+ testType(t, 13, typ.(*ChanType).Elem(), "string")
// make sure tag strings are not part of element type
typ = Typeof(struct {
- d []uint32 "TAG";
- }{}).(*StructType).Field(0).Type;
- testType(t, 14, typ, "[]uint32");
+ d []uint32 "TAG"
+ }{}).(*StructType).Field(0).Type
+ testType(t, 14, typ, "[]uint32")
}
func TestInterfaceGet(t *testing.T) {
var inter struct {
- e interface{};
- }
- inter.e = 123.456;
- v1 := NewValue(&inter);
- v2 := v1.(*PtrValue).Elem().(*StructValue).Field(0);
- assert(t, v2.Type().String(), "interface { }");
- i2 := v2.(*InterfaceValue).Interface();
- v3 := NewValue(i2);
- assert(t, v3.Type().String(), "float");
+ e interface{}
+ }
+ inter.e = 123.456
+ v1 := NewValue(&inter)
+ v2 := v1.(*PtrValue).Elem().(*StructValue).Field(0)
+ assert(t, v2.Type().String(), "interface { }")
+ i2 := v2.(*InterfaceValue).Interface()
+ v3 := NewValue(i2)
+ assert(t, v3.Type().String(), "float")
}
func TestInterfaceValue(t *testing.T) {
var inter struct {
- e interface{};
+ e interface{}
}
- inter.e = 123.456;
- v1 := NewValue(&inter);
- v2 := v1.(*PtrValue).Elem().(*StructValue).Field(0);
- assert(t, v2.Type().String(), "interface { }");
- v3 := v2.(*InterfaceValue).Elem();
- assert(t, v3.Type().String(), "float");
+ inter.e = 123.456
+ v1 := NewValue(&inter)
+ v2 := v1.(*PtrValue).Elem().(*StructValue).Field(0)
+ assert(t, v2.Type().String(), "interface { }")
+ v3 := v2.(*InterfaceValue).Elem()
+ assert(t, v3.Type().String(), "float")
- i3 := v2.Interface();
+ i3 := v2.Interface()
if _, ok := i3.(float); !ok {
t.Error("v2.Interface() did not return float, got ", Typeof(i3))
}
}
func TestFunctionValue(t *testing.T) {
- v := NewValue(func() {});
+ v := NewValue(func() {})
if v.Interface() != v.Interface() {
t.Fatalf("TestFunction != itself")
}
- assert(t, v.Type().String(), "func()");
+ assert(t, v.Type().String(), "func()")
}
func TestCopyArray(t *testing.T) {
- a := []int{1, 2, 3, 4, 10, 9, 8, 7};
- b := []int{11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44};
- c := []int{11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44};
- va := NewValue(&a);
- vb := NewValue(&b);
+ a := []int{1, 2, 3, 4, 10, 9, 8, 7}
+ b := []int{11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44}
+ c := []int{11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44}
+ va := NewValue(&a)
+ vb := NewValue(&b)
for i := 0; i < len(b); i++ {
if b[i] != c[i] {
t.Fatalf("b != c before test")
}
}
- aa := va.(*PtrValue).Elem().(*SliceValue);
- ab := vb.(*PtrValue).Elem().(*SliceValue);
+ aa := va.(*PtrValue).Elem().(*SliceValue)
+ ab := vb.(*PtrValue).Elem().(*SliceValue)
for tocopy := 1; tocopy <= 7; tocopy++ {
- aa.SetLen(tocopy);
- ArrayCopy(ab, aa);
- aa.SetLen(8);
+ aa.SetLen(tocopy)
+ ArrayCopy(ab, aa)
+ aa.SetLen(8)
for i := 0; i < tocopy; i++ {
if a[i] != b[i] {
t.Errorf("(i) tocopy=%d a[%d]=%d, b[%d]=%d",
@@ -474,39 +474,39 @@ func TestCopyArray(t *testing.T) {
}
func TestBigUnnamedStruct(t *testing.T) {
- b := struct{ a, b, c, d int64 }{1, 2, 3, 4};
- v := NewValue(b);
+ b := struct{ a, b, c, d int64 }{1, 2, 3, 4}
+ v := NewValue(b)
b1 := v.Interface().(struct {
- a, b, c, d int64;
- });
+ a, b, c, d int64
+ })
if b1.a != b.a || b1.b != b.b || b1.c != b.c || b1.d != b.d {
t.Errorf("NewValue(%v).Interface().(*Big) = %v", b, b1)
}
}
type big struct {
- a, b, c, d, e int64;
+ a, b, c, d, e int64
}
func TestBigStruct(t *testing.T) {
- b := big{1, 2, 3, 4, 5};
- v := NewValue(b);
- b1 := v.Interface().(big);
+ b := big{1, 2, 3, 4, 5}
+ v := NewValue(b)
+ b1 := v.Interface().(big)
if b1.a != b.a || b1.b != b.b || b1.c != b.c || b1.d != b.d || b1.e != b.e {
t.Errorf("NewValue(%v).Interface().(big) = %v", b, b1)
}
}
type Basic struct {
- x int;
- y float32;
+ x int
+ y float32
}
type NotBasic Basic
type DeepEqualTest struct {
- a, b interface{};
- eq bool;
+ a, b interface{}
+ eq bool
}
var deepEqualTests = []DeepEqualTest{
@@ -559,11 +559,11 @@ func TestDeepEqual(t *testing.T) {
func TestTypeof(t *testing.T) {
for _, test := range deepEqualTests {
- v := NewValue(test.a);
+ v := NewValue(test.a)
if v == nil {
continue
}
- typ := Typeof(test.a);
+ typ := Typeof(test.a)
if typ != v.Type() {
t.Errorf("Typeof(%v) = %v, but NewValue(%v).Type() = %v", test.a, typ, test.a, v.Type())
}
@@ -571,43 +571,43 @@ func TestTypeof(t *testing.T) {
}
type Recursive struct {
- x int;
- r *Recursive;
+ x int
+ r *Recursive
}
func TestDeepEqualRecursiveStruct(t *testing.T) {
- a, b := new(Recursive), new(Recursive);
- *a = Recursive{12, a};
- *b = Recursive{12, b};
+ a, b := new(Recursive), new(Recursive)
+ *a = Recursive{12, a}
+ *b = Recursive{12, b}
if !DeepEqual(a, b) {
t.Error("DeepEqual(recursive same) = false, want true")
}
}
type Complex struct {
- a int;
- b [3]*Complex;
- c *string;
- d map[float]float;
+ a int
+ b [3]*Complex
+ c *string
+ d map[float]float
}
func TestDeepEqualComplexStruct(t *testing.T) {
- m := make(map[float]float);
- stra, strb := "hello", "hello";
- a, b := new(Complex), new(Complex);
- *a = Complex{5, [3]*Complex{a, b, a}, &stra, m};
- *b = Complex{5, [3]*Complex{b, a, a}, &strb, m};
+ m := make(map[float]float)
+ stra, strb := "hello", "hello"
+ a, b := new(Complex), new(Complex)
+ *a = Complex{5, [3]*Complex{a, b, a}, &stra, m}
+ *b = Complex{5, [3]*Complex{b, a, a}, &strb, m}
if !DeepEqual(a, b) {
t.Error("DeepEqual(complex same) = false, want true")
}
}
func TestDeepEqualComplexStructInequality(t *testing.T) {
- m := make(map[float]float);
- stra, strb := "hello", "helloo"; // Difference is here
- a, b := new(Complex), new(Complex);
- *a = Complex{5, [3]*Complex{a, b, a}, &stra, m};
- *b = Complex{5, [3]*Complex{b, a, a}, &strb, m};
+ m := make(map[float]float)
+ stra, strb := "hello", "helloo" // Difference is here
+ a, b := new(Complex), new(Complex)
+ *a = Complex{5, [3]*Complex{a, b, a}, &stra, m}
+ *b = Complex{5, [3]*Complex{b, a, a}, &strb, m}
if DeepEqual(a, b) {
t.Error("DeepEqual(complex different) = true, want false")
}
@@ -615,8 +615,8 @@ func TestDeepEqualComplexStructInequality(t *testing.T) {
func check2ndField(x interface{}, offs uintptr, t *testing.T) {
- s := NewValue(x).(*StructValue);
- f := s.Type().(*StructType).Field(1);
+ s := NewValue(x).(*StructValue)
+ f := s.Type().(*StructType).Field(1)
if f.Offset != offs {
t.Error("mismatched offsets in structure alignment:", f.Offset, offs)
}
@@ -626,40 +626,40 @@ func check2ndField(x interface{}, offs uintptr, t *testing.T) {
// from the compiler itself.
func TestAlignment(t *testing.T) {
type T1inner struct {
- a int;
+ a int
}
type T1 struct {
- T1inner;
- f int;
+ T1inner
+ f int
}
type T2inner struct {
- a, b int;
+ a, b int
}
type T2 struct {
- T2inner;
- f int;
+ T2inner
+ f int
}
- x := T1{T1inner{2}, 17};
- check2ndField(x, uintptr(unsafe.Pointer(&x.f))-uintptr(unsafe.Pointer(&x)), t);
+ x := T1{T1inner{2}, 17}
+ check2ndField(x, uintptr(unsafe.Pointer(&x.f))-uintptr(unsafe.Pointer(&x)), t)
- x1 := T2{T2inner{2, 3}, 17};
- check2ndField(x1, uintptr(unsafe.Pointer(&x1.f))-uintptr(unsafe.Pointer(&x1)), t);
+ x1 := T2{T2inner{2, 3}, 17}
+ check2ndField(x1, uintptr(unsafe.Pointer(&x1.f))-uintptr(unsafe.Pointer(&x1)), t)
}
type IsNiller interface {
- IsNil() bool;
+ IsNil() bool
}
func Nil(a interface{}, t *testing.T) {
- n := NewValue(a).(*StructValue).Field(0).(IsNiller);
+ n := NewValue(a).(*StructValue).Field(0).(IsNiller)
if !n.IsNil() {
t.Errorf("%v should be nil", a)
}
}
func NotNil(a interface{}, t *testing.T) {
- n := NewValue(a).(*StructValue).Field(0).(IsNiller);
+ n := NewValue(a).(*StructValue).Field(0).(IsNiller)
if n.IsNil() {
t.Errorf("value of type %v should not be nil", NewValue(a).Type().String())
}
@@ -667,10 +667,10 @@ func NotNil(a interface{}, t *testing.T) {
func TestIsNil(t *testing.T) {
// These do not implement IsNil
- doNotNil := []interface{}{int(0), float32(0), struct{ a int }{}};
+ doNotNil := []interface{}{int(0), float32(0), struct{ a int }{}}
for _, ts := range doNotNil {
- ty := Typeof(ts);
- v := MakeZero(ty);
+ ty := Typeof(ts)
+ v := MakeZero(ty)
if _, ok := v.(IsNiller); ok {
t.Errorf("%s is nilable; should not be", ts)
}
@@ -685,10 +685,10 @@ func TestIsNil(t *testing.T) {
struct{ x func() bool }{},
struct{ x chan int }{},
struct{ x []string }{},
- };
+ }
for _, ts := range doNil {
- ty := Typeof(ts).(*StructType).Field(0).Type;
- v := MakeZero(ty);
+ ty := Typeof(ts).(*StructType).Field(0).Type
+ v := MakeZero(ty)
if _, ok := v.(IsNiller); !ok {
t.Errorf("%s %T is not nilable; should be", ts, v)
}
@@ -696,55 +696,55 @@ func TestIsNil(t *testing.T) {
// Check the implementations
var pi struct {
- x *int;
+ x *int
}
- Nil(pi, t);
- pi.x = new(int);
- NotNil(pi, t);
+ Nil(pi, t)
+ pi.x = new(int)
+ NotNil(pi, t)
var si struct {
- x []int;
+ x []int
}
- Nil(si, t);
- si.x = make([]int, 10);
- NotNil(si, t);
+ Nil(si, t)
+ si.x = make([]int, 10)
+ NotNil(si, t)
var ci struct {
- x chan int;
+ x chan int
}
- Nil(ci, t);
- ci.x = make(chan int);
- NotNil(ci, t);
+ Nil(ci, t)
+ ci.x = make(chan int)
+ NotNil(ci, t)
var mi struct {
- x map[int]int;
+ x map[int]int
}
- Nil(mi, t);
- mi.x = make(map[int]int);
- NotNil(mi, t);
+ Nil(mi, t)
+ mi.x = make(map[int]int)
+ NotNil(mi, t)
var ii struct {
- x interface{};
+ x interface{}
}
- Nil(ii, t);
- ii.x = 2;
- NotNil(ii, t);
+ Nil(ii, t)
+ ii.x = 2
+ NotNil(ii, t)
var fi struct {
- x func(t *testing.T);
+ x func(t *testing.T)
}
- Nil(fi, t);
- fi.x = TestIsNil;
- NotNil(fi, t);
+ Nil(fi, t)
+ fi.x = TestIsNil
+ NotNil(fi, t)
}
func TestInterfaceExtraction(t *testing.T) {
var s struct {
- w io.Writer;
+ w io.Writer
}
- s.w = os.Stdout;
- v := Indirect(NewValue(&s)).(*StructValue).Field(0).Interface();
+ s.w = os.Stdout
+ v := Indirect(NewValue(&s)).(*StructValue).Field(0).Interface()
if v != s.w.(interface{}) {
t.Error("Interface() on interface: ", v, s.w)
}
@@ -755,45 +755,45 @@ func TestInterfaceEditing(t *testing.T) {
// so the interface conversion allocates
// memory to hold a string and puts that
// pointer in the interface.
- var i interface{} = "hello";
+ var i interface{} = "hello"
// if i pass the interface value by value
// to NewValue, i should get a fresh copy
// of the value.
- v := NewValue(i);
+ v := NewValue(i)
// and setting that copy to "bye" should
// not change the value stored in i.
- v.(*StringValue).Set("bye");
+ v.(*StringValue).Set("bye")
if i.(string) != "hello" {
t.Errorf(`Set("bye") changed i to %s`, i.(string))
}
// the same should be true of smaller items.
- i = 123;
- v = NewValue(i);
- v.(*IntValue).Set(234);
+ i = 123
+ v = NewValue(i)
+ v.(*IntValue).Set(234)
if i.(int) != 123 {
t.Errorf("Set(234) changed i to %d", i.(int))
}
}
func TestNilPtrValueSub(t *testing.T) {
- var pi *int;
+ var pi *int
if pv := NewValue(pi).(*PtrValue); pv.Elem() != nil {
t.Error("NewValue((*int)(nil)).(*PtrValue).Elem() != nil")
}
}
func TestMap(t *testing.T) {
- m := map[string]int{"a": 1, "b": 2};
- mv := NewValue(m).(*MapValue);
+ m := map[string]int{"a": 1, "b": 2}
+ mv := NewValue(m).(*MapValue)
if n := mv.Len(); n != len(m) {
t.Errorf("Len = %d, want %d", n, len(m))
}
- keys := mv.Keys();
- i := 0;
- newmap := MakeMap(mv.Type().(*MapType));
+ keys := mv.Keys()
+ i := 0
+ newmap := MakeMap(mv.Type().(*MapType))
for k, v := range m {
// Check that returned Keys match keys in range.
// These aren't required to be in the same order,
@@ -804,36 +804,36 @@ func TestMap(t *testing.T) {
} else if kv := keys[i].(*StringValue); kv.Get() != k {
t.Errorf("Keys[%d] = %q, want %q", i, kv.Get(), k)
}
- i++;
+ i++
// Check that value lookup is correct.
- vv := mv.Elem(NewValue(k));
+ vv := mv.Elem(NewValue(k))
if vi := vv.(*IntValue).Get(); vi != v {
t.Errorf("Key %q: have value %d, want %d", vi, v)
}
// Copy into new map.
- newmap.SetElem(NewValue(k), NewValue(v));
+ newmap.SetElem(NewValue(k), NewValue(v))
}
- vv := mv.Elem(NewValue("not-present"));
+ vv := mv.Elem(NewValue("not-present"))
if vv != nil {
t.Errorf("Invalid key: got non-nil value %s", valueToString(vv))
}
- newm := newmap.Interface().(map[string]int);
+ newm := newmap.Interface().(map[string]int)
if len(newm) != len(m) {
t.Errorf("length after copy: newm=%d, m=%d", newm, m)
}
for k, v := range newm {
- mv, ok := m[k];
+ mv, ok := m[k]
if mv != v {
t.Errorf("newm[%q] = %d, but m[%q] = %d, %v", k, v, k, mv, ok)
}
}
- newmap.SetElem(NewValue("a"), nil);
- v, ok := newm["a"];
+ newmap.SetElem(NewValue("a"), nil)
+ v, ok := newm["a"]
if ok {
t.Errorf("newm[\"a\"] = %d after delete", v)
}
@@ -841,40 +841,40 @@ func TestMap(t *testing.T) {
func TestChan(t *testing.T) {
for loop := 0; loop < 2; loop++ {
- var c chan int;
- var cv *ChanValue;
+ var c chan int
+ var cv *ChanValue
// check both ways to allocate channels
switch loop {
case 1:
- c = make(chan int, 1);
- cv = NewValue(c).(*ChanValue);
+ c = make(chan int, 1)
+ cv = NewValue(c).(*ChanValue)
case 0:
- cv = MakeChan(Typeof(c).(*ChanType), 1);
- c = cv.Interface().(chan int);
+ cv = MakeChan(Typeof(c).(*ChanType), 1)
+ c = cv.Interface().(chan int)
}
// Send
- cv.Send(NewValue(2));
+ cv.Send(NewValue(2))
if i := <-c; i != 2 {
t.Errorf("reflect Send 2, native recv %d", i)
}
// Recv
- c <- 3;
+ c <- 3
if i := cv.Recv().(*IntValue).Get(); i != 3 {
t.Errorf("native send 3, reflect Recv %d", i)
}
// TryRecv fail
- val := cv.TryRecv();
+ val := cv.TryRecv()
if val != nil {
t.Errorf("TryRecv on empty chan: %s", valueToString(val))
}
// TryRecv success
- c <- 4;
- val = cv.TryRecv();
+ c <- 4
+ val = cv.TryRecv()
if val == nil {
t.Errorf("TryRecv on ready chan got nil")
} else if i := val.(*IntValue).Get(); i != 4 {
@@ -882,15 +882,15 @@ func TestChan(t *testing.T) {
}
// TrySend fail
- c <- 100;
- ok := cv.TrySend(NewValue(5));
- i := <-c;
+ c <- 100
+ ok := cv.TrySend(NewValue(5))
+ i := <-c
if ok {
t.Errorf("TrySend on full chan succeeded: value %d", i)
}
// TrySend success
- ok = cv.TrySend(NewValue(6));
+ ok = cv.TrySend(NewValue(6))
if !ok {
t.Errorf("TrySend on empty chan failed")
} else {
@@ -900,8 +900,8 @@ func TestChan(t *testing.T) {
}
// Close
- c <- 123;
- cv.Close();
+ c <- 123
+ cv.Close()
if cv.Closed() {
t.Errorf("closed too soon - 1")
}
@@ -920,9 +920,9 @@ func TestChan(t *testing.T) {
}
// check creation of unbuffered channel
- var c chan int;
- cv := MakeChan(Typeof(c).(*ChanType), 0);
- c = cv.Interface().(chan int);
+ var c chan int
+ cv := MakeChan(Typeof(c).(*ChanType), 0)
+ c = cv.Interface().(chan int)
if cv.TrySend(NewValue(7)) {
t.Errorf("TrySend on sync chan succeeded")
}
@@ -931,8 +931,8 @@ func TestChan(t *testing.T) {
}
// len/cap
- cv = MakeChan(Typeof(c).(*ChanType), 10);
- c = cv.Interface().(chan int);
+ cv = MakeChan(Typeof(c).(*ChanType), 10)
+ c = cv.Interface().(chan int)
for i := 0; i < 3; i++ {
c <- i
}
@@ -949,35 +949,35 @@ func dummy(b byte, c int, d byte) (i byte, j int, k byte) {
}
func TestFunc(t *testing.T) {
- ret := NewValue(dummy).(*FuncValue).Call([]Value{NewValue(byte(10)), NewValue(20), NewValue(byte(30))});
+ ret := NewValue(dummy).(*FuncValue).Call([]Value{NewValue(byte(10)), NewValue(20), NewValue(byte(30))})
if len(ret) != 3 {
t.Fatalf("Call returned %d values, want 3", len(ret))
}
- i := ret[0].(*Uint8Value).Get();
- j := ret[1].(*IntValue).Get();
- k := ret[2].(*Uint8Value).Get();
+ i := ret[0].(*Uint8Value).Get()
+ j := ret[1].(*IntValue).Get()
+ k := ret[2].(*Uint8Value).Get()
if i != 10 || j != 20 || k != 30 {
t.Errorf("Call returned %d, %d, %d; want 10, 20, 30", i, j, k)
}
}
type Point struct {
- x, y int;
+ x, y int
}
-func (p Point) Dist(scale int) int { return p.x*p.x*scale + p.y*p.y*scale }
+func (p Point) Dist(scale int) int { return p.x*p.x*scale + p.y*p.y*scale }
func TestMethod(t *testing.T) {
// Non-curried method of type.
- p := Point{3, 4};
- i := Typeof(p).Method(0).Func.Call([]Value{NewValue(p), NewValue(10)})[0].(*IntValue).Get();
+ p := Point{3, 4}
+ i := Typeof(p).Method(0).Func.Call([]Value{NewValue(p), NewValue(10)})[0].(*IntValue).Get()
if i != 250 {
t.Errorf("Type Method returned %d; want 250", i)
}
// Curried method of value.
- i = NewValue(p).Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get();
+ i = NewValue(p).Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get()
if i != 250 {
t.Errorf("Value Method returned %d; want 250", i)
}
@@ -988,53 +988,53 @@ func TestMethod(t *testing.T) {
// access the underlying Point, not the interface.
var s = struct {
x interface {
- Dist(int) int;
- };
- }{p};
- pv := NewValue(s).(*StructValue).Field(0);
- i = pv.Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get();
+ Dist(int) int
+ }
+ }{p}
+ pv := NewValue(s).(*StructValue).Field(0)
+ i = pv.Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get()
if i != 250 {
t.Errorf("Interface Method returned %d; want 250", i)
}
}
func TestInterfaceSet(t *testing.T) {
- p := &Point{3, 4};
+ p := &Point{3, 4}
var s struct {
- I interface{};
- P interface {
- Dist(int) int;
- };
+ I interface{}
+ P interface {
+ Dist(int) int
+ }
}
- sv := NewValue(&s).(*PtrValue).Elem().(*StructValue);
- sv.Field(0).(*InterfaceValue).Set(NewValue(p));
+ sv := NewValue(&s).(*PtrValue).Elem().(*StructValue)
+ sv.Field(0).(*InterfaceValue).Set(NewValue(p))
if q := s.I.(*Point); q != p {
t.Errorf("i: have %p want %p", q, p)
}
- pv := sv.Field(1).(*InterfaceValue);
- pv.Set(NewValue(p));
+ pv := sv.Field(1).(*InterfaceValue)
+ pv.Set(NewValue(p))
if q := s.P.(*Point); q != p {
t.Errorf("i: have %p want %p", q, p)
}
- i := pv.Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get();
+ i := pv.Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get()
if i != 250 {
t.Errorf("Interface Method returned %d; want 250", i)
}
}
type T1 struct {
- a string;
- int;
+ a string
+ int
}
func TestAnonymousFields(t *testing.T) {
- var field StructField;
- var ok bool;
- var t1 T1;
- type1 := Typeof(t1).(*StructType);
+ var field StructField
+ var ok bool
+ var t1 T1
+ type1 := Typeof(t1).(*StructType)
if field, ok = type1.FieldByName("int"); !ok {
t.Error("no field 'int'")
}
@@ -1044,53 +1044,53 @@ func TestAnonymousFields(t *testing.T) {
}
type FTest struct {
- s interface{};
- name string;
- index []int;
- value int;
+ s interface{}
+ name string
+ index []int
+ value int
}
type D1 struct {
- d int;
+ d int
}
type D2 struct {
- d int;
+ d int
}
type S0 struct {
- a, b, c int;
- D1;
- D2;
+ a, b, c int
+ D1
+ D2
}
type S1 struct {
- b int;
- S0;
+ b int
+ S0
}
type S2 struct {
- a int;
- *S1;
+ a int
+ *S1
}
type S1x struct {
- S1;
+ S1
}
type S1y struct {
- S1;
+ S1
}
type S3 struct {
- S1x;
- S2;
- d, e int;
- *S1y;
+ S1x
+ S2
+ d, e int
+ *S1y
}
type S4 struct {
- *S4;
- a int;
+ *S4
+ a int
}
var fieldTests = []FTest{
@@ -1118,8 +1118,8 @@ var fieldTests = []FTest{
func TestFieldByIndex(t *testing.T) {
for _, test := range fieldTests {
- s := Typeof(test.s).(*StructType);
- f := s.FieldByIndex(test.index);
+ s := Typeof(test.s).(*StructType)
+ f := s.FieldByIndex(test.index)
if f.Name != "" {
if test.index != nil {
if f.Name != test.name {
@@ -1133,7 +1133,7 @@ func TestFieldByIndex(t *testing.T) {
}
if test.value != 0 {
- v := NewValue(test.s).(*StructValue).FieldByIndex(test.index);
+ v := NewValue(test.s).(*StructValue).FieldByIndex(test.index)
if v != nil {
if x, ok := v.Interface().(int); ok {
if x != test.value {
@@ -1151,8 +1151,8 @@ func TestFieldByIndex(t *testing.T) {
func TestFieldByName(t *testing.T) {
for _, test := range fieldTests {
- s := Typeof(test.s).(*StructType);
- f, found := s.FieldByName(test.name);
+ s := Typeof(test.s).(*StructType)
+ f, found := s.FieldByName(test.name)
if found {
if test.index != nil {
// Verify field depth and index.
@@ -1173,7 +1173,7 @@ func TestFieldByName(t *testing.T) {
}
if test.value != 0 {
- v := NewValue(test.s).(*StructValue).FieldByName(test.name);
+ v := NewValue(test.s).(*StructValue).FieldByName(test.name)
if v != nil {
if x, ok := v.Interface().(int); ok {
if x != test.value {
diff --git a/src/pkg/reflect/deepequal.go b/src/pkg/reflect/deepequal.go
index f3e13f85c..575946c1e 100644
--- a/src/pkg/reflect/deepequal.go
+++ b/src/pkg/reflect/deepequal.go
@@ -12,10 +12,10 @@ package reflect
// checks in progress are true when it reencounters them.
// Visited are stored in a map indexed by 17 * a1 + a2;
type visit struct {
- a1 uintptr;
- a2 uintptr;
- typ Type;
- next *visit;
+ a1 uintptr
+ a2 uintptr
+ typ Type
+ next *visit
}
// Tests for deep equality using reflected types. The map argument tracks
@@ -31,8 +31,8 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
// if depth > 10 { panic("deepValueEqual") } // for debugging
- addr1 := v1.Addr();
- addr2 := v2.Addr();
+ addr1 := v1.Addr()
+ addr2 := v2.Addr()
if addr1 > addr2 {
// Canonicalize order to reduce number of entries in visited.
addr1, addr2 = addr2, addr1
@@ -44,9 +44,9 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
}
// ... or already seen
- h := 17*addr1 + addr2;
- seen, _ := visited[h];
- typ := v1.Type();
+ h := 17*addr1 + addr2
+ seen, _ := visited[h]
+ typ := v1.Type()
for p := seen; p != nil; p = p.next {
if p.a1 == addr1 && p.a2 == addr2 && p.typ == typ {
return true
@@ -54,12 +54,12 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
}
// Remember for later.
- visited[h] = &visit{addr1, addr2, typ, seen};
+ visited[h] = &visit{addr1, addr2, typ, seen}
switch v := v1.(type) {
case *ArrayValue:
- arr1 := v;
- arr2 := v2.(*ArrayValue);
+ arr1 := v
+ arr2 := v2.(*ArrayValue)
if arr1.Len() != arr2.Len() {
return false
}
@@ -68,10 +68,10 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
return false
}
}
- return true;
+ return true
case *SliceValue:
- arr1 := v;
- arr2 := v2.(*SliceValue);
+ arr1 := v
+ arr2 := v2.(*SliceValue)
if arr1.Len() != arr2.Len() {
return false
}
@@ -80,28 +80,28 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
return false
}
}
- return true;
+ return true
case *InterfaceValue:
- i1 := v.Interface();
- i2 := v2.Interface();
+ i1 := v.Interface()
+ i2 := v2.Interface()
if i1 == nil || i2 == nil {
return i1 == i2
}
- return deepValueEqual(NewValue(i1), NewValue(i2), visited, depth+1);
+ return deepValueEqual(NewValue(i1), NewValue(i2), visited, depth+1)
case *PtrValue:
return deepValueEqual(v.Elem(), v2.(*PtrValue).Elem(), visited, depth+1)
case *StructValue:
- struct1 := v;
- struct2 := v2.(*StructValue);
+ struct1 := v
+ struct2 := v2.(*StructValue)
for i, n := 0, v.NumField(); i < n; i++ {
if !deepValueEqual(struct1.Field(i), struct2.Field(i), visited, depth+1) {
return false
}
}
- return true;
+ return true
case *MapValue:
- map1 := v;
- map2 := v2.(*MapValue);
+ map1 := v
+ map2 := v2.(*MapValue)
if map1.Len() != map2.Len() {
return false
}
@@ -110,13 +110,13 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
return false
}
}
- return true;
+ return true
default:
// Normal equality suffices
return v1.Interface() == v2.Interface()
}
- panic("Not reached");
+ panic("Not reached")
}
// DeepEqual tests for deep equality. It uses normal == equality where possible
@@ -126,10 +126,10 @@ func DeepEqual(a1, a2 interface{}) bool {
if a1 == nil || a2 == nil {
return a1 == a2
}
- v1 := NewValue(a1);
- v2 := NewValue(a2);
+ v1 := NewValue(a1)
+ v2 := NewValue(a2)
if v1.Type() != v2.Type() {
return false
}
- return deepValueEqual(v1, v2, make(map[uintptr]*visit), 0);
+ return deepValueEqual(v1, v2, make(map[uintptr]*visit), 0)
}
diff --git a/src/pkg/reflect/tostring_test.go b/src/pkg/reflect/tostring_test.go
index 4a9e75793..190385afa 100644
--- a/src/pkg/reflect/tostring_test.go
+++ b/src/pkg/reflect/tostring_test.go
@@ -9,18 +9,18 @@
package reflect_test
import (
- . "reflect";
- "strconv";
+ . "reflect"
+ "strconv"
)
// valueToString returns a textual representation of the reflection value val.
// For debugging only.
func valueToString(val Value) string {
- var str string;
+ var str string
if val == nil {
return "<nil>"
}
- typ := val.Type();
+ typ := val.Type()
switch val := val.(type) {
case *IntValue:
return strconv.Uitoa64(uint64(val.Get()))
@@ -61,57 +61,57 @@ func valueToString(val Value) string {
return "false"
}
case *PtrValue:
- v := val;
- str = typ.String() + "(";
+ v := val
+ str = typ.String() + "("
if v.IsNil() {
str += "0"
} else {
str += "&" + valueToString(v.Elem())
}
- str += ")";
- return str;
+ str += ")"
+ return str
case ArrayOrSliceValue:
- v := val;
- str += typ.String();
- str += "{";
+ v := val
+ str += typ.String()
+ str += "{"
for i := 0; i < v.Len(); i++ {
if i > 0 {
str += ", "
}
- str += valueToString(v.Elem(i));
+ str += valueToString(v.Elem(i))
}
- str += "}";
- return str;
+ str += "}"
+ return str
case *MapValue:
- t := typ.(*MapType);
- str = t.String();
- str += "{";
- str += "<can't iterate on maps>";
- str += "}";
- return str;
+ t := typ.(*MapType)
+ str = t.String()
+ str += "{"
+ str += "<can't iterate on maps>"
+ str += "}"
+ return str
case *ChanValue:
- str = typ.String();
- return str;
+ str = typ.String()
+ return str
case *StructValue:
- t := typ.(*StructType);
- v := val;
- str += t.String();
- str += "{";
+ t := typ.(*StructType)
+ v := val
+ str += t.String()
+ str += "{"
for i, n := 0, v.NumField(); i < n; i++ {
if i > 0 {
str += ", "
}
- str += valueToString(v.Field(i));
+ str += valueToString(v.Field(i))
}
- str += "}";
- return str;
+ str += "}"
+ return str
case *InterfaceValue:
return typ.String() + "(" + valueToString(val.Elem()) + ")"
case *FuncValue:
- v := val;
- return typ.String() + "(" + strconv.Itoa64(int64(v.Get())) + ")";
+ v := val
+ return typ.String() + "(" + strconv.Itoa64(int64(v.Get())) + ")"
default:
panicln("valueToString: can't print type ", typ.String())
}
- return "valueToString: can't happen";
+ return "valueToString: can't happen"
}
diff --git a/src/pkg/reflect/type.go b/src/pkg/reflect/type.go
index a6988d312..2c059924b 100644
--- a/src/pkg/reflect/type.go
+++ b/src/pkg/reflect/type.go
@@ -16,9 +16,9 @@
package reflect
import (
- "runtime";
- "strconv";
- "unsafe";
+ "runtime"
+ "strconv"
+ "unsafe"
)
/*
@@ -35,198 +35,198 @@ import (
*/
type commonType struct {
- size uintptr;
- hash uint32;
- alg uint8;
- align uint8;
- fieldAlign uint8;
- string *string;
- *uncommonType;
+ size uintptr
+ hash uint32
+ alg uint8
+ align uint8
+ fieldAlign uint8
+ string *string
+ *uncommonType
}
type method struct {
- hash uint32;
- name *string;
- pkgPath *string;
- typ *runtime.Type;
- ifn unsafe.Pointer;
- tfn unsafe.Pointer;
+ hash uint32
+ name *string
+ pkgPath *string
+ typ *runtime.Type
+ ifn unsafe.Pointer
+ tfn unsafe.Pointer
}
type uncommonType struct {
- name *string;
- pkgPath *string;
- methods []method;
+ name *string
+ pkgPath *string
+ methods []method
}
// BoolType represents a boolean type.
type BoolType struct {
- commonType;
+ commonType
}
// Float32Type represents a float32 type.
type Float32Type struct {
- commonType;
+ commonType
}
// Float64Type represents a float64 type.
type Float64Type struct {
- commonType;
+ commonType
}
// FloatType represents a float type.
type FloatType struct {
- commonType;
+ commonType
}
// Int16Type represents an int16 type.
type Int16Type struct {
- commonType;
+ commonType
}
// Int32Type represents an int32 type.
type Int32Type struct {
- commonType;
+ commonType
}
// Int64Type represents an int64 type.
type Int64Type struct {
- commonType;
+ commonType
}
// Int8Type represents an int8 type.
type Int8Type struct {
- commonType;
+ commonType
}
// IntType represents an int type.
type IntType struct {
- commonType;
+ commonType
}
// Uint16Type represents a uint16 type.
type Uint16Type struct {
- commonType;
+ commonType
}
// Uint32Type represents a uint32 type.
type Uint32Type struct {
- commonType;
+ commonType
}
// Uint64Type represents a uint64 type.
type Uint64Type struct {
- commonType;
+ commonType
}
// Uint8Type represents a uint8 type.
type Uint8Type struct {
- commonType;
+ commonType
}
// UintType represents a uint type.
type UintType struct {
- commonType;
+ commonType
}
// StringType represents a string type.
type StringType struct {
- commonType;
+ commonType
}
// UintptrType represents a uintptr type.
type UintptrType struct {
- commonType;
+ commonType
}
// DotDotDotType represents the ... that can
// be used as the type of the final function parameter.
type DotDotDotType struct {
- commonType;
+ commonType
}
// UnsafePointerType represents an unsafe.Pointer type.
type UnsafePointerType struct {
- commonType;
+ commonType
}
// ArrayType represents a fixed array type.
type ArrayType struct {
- commonType;
- elem *runtime.Type;
- len uintptr;
+ commonType
+ elem *runtime.Type
+ len uintptr
}
// ChanDir represents a channel type's direction.
type ChanDir int
const (
- RecvDir ChanDir = 1 << iota;
- SendDir;
- BothDir = RecvDir | SendDir;
+ RecvDir ChanDir = 1 << iota
+ SendDir
+ BothDir = RecvDir | SendDir
)
// ChanType represents a channel type.
type ChanType struct {
- commonType;
- elem *runtime.Type;
- dir uintptr;
+ commonType
+ elem *runtime.Type
+ dir uintptr
}
// FuncType represents a function type.
type FuncType struct {
- commonType;
- in []*runtime.Type;
- out []*runtime.Type;
+ commonType
+ in []*runtime.Type
+ out []*runtime.Type
}
// Method on interface type
type imethod struct {
- hash uint32;
- perm uint32;
- name *string;
- pkgPath *string;
- typ *runtime.Type;
+ hash uint32
+ perm uint32
+ name *string
+ pkgPath *string
+ typ *runtime.Type
}
// InterfaceType represents an interface type.
type InterfaceType struct {
- commonType;
- methods []imethod;
+ commonType
+ methods []imethod
}
// MapType represents a map type.
type MapType struct {
- commonType;
- key *runtime.Type;
- elem *runtime.Type;
+ commonType
+ key *runtime.Type
+ elem *runtime.Type
}
// PtrType represents a pointer type.
type PtrType struct {
- commonType;
- elem *runtime.Type;
+ commonType
+ elem *runtime.Type
}
// SliceType represents a slice type.
type SliceType struct {
- commonType;
- elem *runtime.Type;
+ commonType
+ elem *runtime.Type
}
// Struct field
type structField struct {
- name *string;
- pkgPath *string;
- typ *runtime.Type;
- tag *string;
- offset uintptr;
+ name *string
+ pkgPath *string
+ typ *runtime.Type
+ tag *string
+ offset uintptr
}
// StructType represents a struct type.
type StructType struct {
- commonType;
- fields []structField;
+ commonType
+ fields []structField
}
@@ -237,10 +237,10 @@ type StructType struct {
// Method represents a single method.
type Method struct {
- PkgPath string; // empty for uppercase Name
- Name string;
- Type *FuncType;
- Func *FuncValue;
+ PkgPath string // empty for uppercase Name
+ Name string
+ Type *FuncType
+ Func *FuncValue
}
// Type is the runtime representation of a Go type.
@@ -253,37 +253,37 @@ type Type interface {
// PkgPath returns the type's package path.
// The package path is a full package import path like "container/vector".
// PkgPath returns an empty string for unnamed types.
- PkgPath() string;
+ PkgPath() string
// Name returns the type's name within its package.
// Name returns an empty string for unnamed types.
- Name() string;
+ Name() string
// String returns a string representation of the type.
// The string representation may use shortened package names
// (e.g., vector instead of "container/vector") and is not
// guaranteed to be unique among types. To test for equality,
// compare the Types directly.
- String() string;
+ String() string
// Size returns the number of bytes needed to store
// a value of the given type; it is analogous to unsafe.Sizeof.
- Size() uintptr;
+ Size() uintptr
// Align returns the alignment of a value of this type
// when allocated in memory.
- Align() int;
+ Align() int
// FieldAlign returns the alignment of a value of this type
// when used as a field in a struct.
- FieldAlign() int;
+ FieldAlign() int
// For non-interface types, Method returns the i'th method with receiver T.
// For interface types, Method returns the i'th method in the interface.
// NumMethod returns the number of such methods.
- Method(int) Method;
- NumMethod() int;
- uncommon() *uncommonType;
+ Method(int) Method
+ NumMethod() int
+ uncommon() *uncommonType
}
func (t *uncommonType) uncommon() *uncommonType {
@@ -294,70 +294,70 @@ func (t *uncommonType) PkgPath() string {
if t == nil || t.pkgPath == nil {
return ""
}
- return *t.pkgPath;
+ return *t.pkgPath
}
func (t *uncommonType) Name() string {
if t == nil || t.name == nil {
return ""
}
- return *t.name;
+ return *t.name
}
-func (t *commonType) String() string { return *t.string }
+func (t *commonType) String() string { return *t.string }
-func (t *commonType) Size() uintptr { return t.size }
+func (t *commonType) Size() uintptr { return t.size }
-func (t *commonType) Align() int { return int(t.align) }
+func (t *commonType) Align() int { return int(t.align) }
-func (t *commonType) FieldAlign() int { return int(t.fieldAlign) }
+func (t *commonType) FieldAlign() int { return int(t.fieldAlign) }
func (t *uncommonType) Method(i int) (m Method) {
if t == nil || i < 0 || i >= len(t.methods) {
return
}
- p := &t.methods[i];
+ p := &t.methods[i]
if p.name != nil {
m.Name = *p.name
}
if p.pkgPath != nil {
m.PkgPath = *p.pkgPath
}
- m.Type = toType(*p.typ).(*FuncType);
- fn := p.tfn;
- m.Func = newFuncValue(m.Type, addr(&fn), true);
- return;
+ m.Type = toType(*p.typ).(*FuncType)
+ fn := p.tfn
+ m.Func = newFuncValue(m.Type, addr(&fn), true)
+ return
}
func (t *uncommonType) NumMethod() int {
if t == nil {
return 0
}
- return len(t.methods);
+ return len(t.methods)
}
// TODO(rsc): 6g supplies these, but they are not
// as efficient as they could be: they have commonType
// as the receiver instead of *commonType.
-func (t *commonType) NumMethod() int { return t.uncommonType.NumMethod() }
+func (t *commonType) NumMethod() int { return t.uncommonType.NumMethod() }
-func (t *commonType) Method(i int) (m Method) { return t.uncommonType.Method(i) }
+func (t *commonType) Method(i int) (m Method) { return t.uncommonType.Method(i) }
-func (t *commonType) PkgPath() string { return t.uncommonType.PkgPath() }
+func (t *commonType) PkgPath() string { return t.uncommonType.PkgPath() }
-func (t *commonType) Name() string { return t.uncommonType.Name() }
+func (t *commonType) Name() string { return t.uncommonType.Name() }
// Len returns the number of elements in the array.
-func (t *ArrayType) Len() int { return int(t.len) }
+func (t *ArrayType) Len() int { return int(t.len) }
// Elem returns the type of the array's elements.
-func (t *ArrayType) Elem() Type { return toType(*t.elem) }
+func (t *ArrayType) Elem() Type { return toType(*t.elem) }
// Dir returns the channel direction.
-func (t *ChanType) Dir() ChanDir { return ChanDir(t.dir) }
+func (t *ChanType) Dir() ChanDir { return ChanDir(t.dir) }
// Elem returns the channel's element type.
-func (t *ChanType) Elem() Type { return toType(*t.elem) }
+func (t *ChanType) Elem() Type { return toType(*t.elem) }
func (d ChanDir) String() string {
switch d {
@@ -368,7 +368,7 @@ func (d ChanDir) String() string {
case BothDir:
return "chan"
}
- return "ChanDir" + strconv.Itoa(int(d));
+ return "ChanDir" + strconv.Itoa(int(d))
}
// In returns the type of the i'th function input parameter.
@@ -376,60 +376,60 @@ func (t *FuncType) In(i int) Type {
if i < 0 || i >= len(t.in) {
return nil
}
- return toType(*t.in[i]);
+ return toType(*t.in[i])
}
// NumIn returns the number of input parameters.
-func (t *FuncType) NumIn() int { return len(t.in) }
+func (t *FuncType) NumIn() int { return len(t.in) }
// Out returns the type of the i'th function output parameter.
func (t *FuncType) Out(i int) Type {
if i < 0 || i >= len(t.out) {
return nil
}
- return toType(*t.out[i]);
+ return toType(*t.out[i])
}
// NumOut returns the number of function output parameters.
-func (t *FuncType) NumOut() int { return len(t.out) }
+func (t *FuncType) NumOut() int { return len(t.out) }
// Method returns the i'th interface method.
func (t *InterfaceType) Method(i int) (m Method) {
if i < 0 || i >= len(t.methods) {
return
}
- p := &t.methods[i];
- m.Name = *p.name;
+ p := &t.methods[i]
+ m.Name = *p.name
if p.pkgPath != nil {
m.PkgPath = *p.pkgPath
}
- m.Type = toType(*p.typ).(*FuncType);
- return;
+ m.Type = toType(*p.typ).(*FuncType)
+ return
}
// NumMethod returns the number of interface methods.
-func (t *InterfaceType) NumMethod() int { return len(t.methods) }
+func (t *InterfaceType) NumMethod() int { return len(t.methods) }
// Key returns the map key type.
-func (t *MapType) Key() Type { return toType(*t.key) }
+func (t *MapType) Key() Type { return toType(*t.key) }
// Elem returns the map element type.
-func (t *MapType) Elem() Type { return toType(*t.elem) }
+func (t *MapType) Elem() Type { return toType(*t.elem) }
// Elem returns the pointer element type.
-func (t *PtrType) Elem() Type { return toType(*t.elem) }
+func (t *PtrType) Elem() Type { return toType(*t.elem) }
// Elem returns the type of the slice's elements.
-func (t *SliceType) Elem() Type { return toType(*t.elem) }
+func (t *SliceType) Elem() Type { return toType(*t.elem) }
type StructField struct {
- PkgPath string; // empty for uppercase Name
- Name string;
- Type Type;
- Tag string;
- Offset uintptr;
- Index []int;
- Anonymous bool;
+ PkgPath string // empty for uppercase Name
+ Name string
+ Type Type
+ Tag string
+ Offset uintptr
+ Index []int
+ Anonymous bool
}
// Field returns the i'th struct field.
@@ -437,17 +437,17 @@ func (t *StructType) Field(i int) (f StructField) {
if i < 0 || i >= len(t.fields) {
return
}
- p := t.fields[i];
- f.Type = toType(*p.typ);
+ p := t.fields[i]
+ f.Type = toType(*p.typ)
if p.name != nil {
f.Name = *p.name
} else {
- t := f.Type;
+ t := f.Type
if pt, ok := t.(*PtrType); ok {
t = pt.Elem()
}
- f.Name = t.Name();
- f.Anonymous = true;
+ f.Name = t.Name()
+ f.Anonymous = true
}
if p.pkgPath != nil {
f.PkgPath = *p.pkgPath
@@ -455,9 +455,9 @@ func (t *StructType) Field(i int) (f StructField) {
if p.tag != nil {
f.Tag = *p.tag
}
- f.Offset = p.offset;
- f.Index = []int{i};
- return;
+ f.Offset = p.offset
+ f.Index = []int{i}
+ return
}
// TODO(gri): Should there be an error/bool indicator if the index
@@ -467,45 +467,45 @@ func (t *StructType) Field(i int) (f StructField) {
func (t *StructType) FieldByIndex(index []int) (f StructField) {
for i, x := range index {
if i > 0 {
- ft := f.Type;
+ ft := f.Type
if pt, ok := ft.(*PtrType); ok {
ft = pt.Elem()
}
if st, ok := ft.(*StructType); ok {
t = st
} else {
- var f0 StructField;
- f = f0;
- return;
+ var f0 StructField
+ f = f0
+ return
}
}
- f = t.Field(x);
+ f = t.Field(x)
}
- return;
+ return
}
-const inf = 1 << 30 // infinity - no struct has that many nesting levels
+const inf = 1 << 30 // infinity - no struct has that many nesting levels
func (t *StructType) fieldByName(name string, mark map[*StructType]bool, depth int) (ff StructField, fd int) {
- fd = inf; // field depth
+ fd = inf // field depth
if _, marked := mark[t]; marked {
// Struct already seen.
return
}
- mark[t] = true;
+ mark[t] = true
- var fi int; // field index
- n := 0; // number of matching fields at depth fd
-L: for i, _ := range t.fields {
- f := t.Field(i);
- d := inf;
+ var fi int // field index
+ n := 0 // number of matching fields at depth fd
+L: for i, _ := range t.fields {
+ f := t.Field(i)
+ d := inf
switch {
case f.Name == name:
// Matching top-level field.
d = depth
case f.Anonymous:
- ft := f.Type;
+ ft := f.Type
if pt, ok := ft.(*PtrType); ok {
ft = pt.Elem()
}
@@ -524,12 +524,12 @@ L: for i, _ := range t.fields {
switch {
case d < fd:
// Found field at shallower depth.
- ff, fi, fd = f, i, d;
- n = 1;
+ ff, fi, fd = f, i, d
+ n = 1
case d == fd:
// More than one matching field at the same depth (or d, fd == inf).
// Same as no field found at this depth.
- n++;
+ n++
if d == depth {
// Impossible to find a field at lower depth.
break L
@@ -542,28 +542,28 @@ L: for i, _ := range t.fields {
if len(ff.Index) <= depth {
ff.Index = make([]int, depth+1)
}
- ff.Index[depth] = fi;
+ ff.Index[depth] = fi
} else {
// None or more than one matching field found.
fd = inf
}
- mark[t] = false, false;
- return;
+ mark[t] = false, false
+ return
}
// FieldByName returns the struct field with the given name
// and a boolean to indicate if the field was found.
func (t *StructType) FieldByName(name string) (f StructField, present bool) {
if ff, fd := t.fieldByName(name, make(map[*StructType]bool), 0); fd < inf {
- ff.Index = ff.Index[0 : fd+1];
- f, present = ff, true;
+ ff.Index = ff.Index[0 : fd+1]
+ f, present = ff, true
}
- return;
+ return
}
// NumField returns the number of struct fields.
-func (t *StructType) NumField() int { return len(t.fields) }
+func (t *StructType) NumField() int { return len(t.fields) }
// Convert runtime type to reflect type.
// Same memory layouts, different method sets.
@@ -624,15 +624,15 @@ func toType(i interface{}) Type {
case *runtime.StructType:
return (*StructType)(unsafe.Pointer(v))
}
- panicln("toType", i);
+ panicln("toType", i)
}
// ArrayOrSliceType is the common interface implemented
// by both ArrayType and SliceType.
type ArrayOrSliceType interface {
- Type;
- Elem() Type;
+ Type
+ Elem() Type
}
// Typeof returns the reflection Type of the value in the interface{}.
-func Typeof(i interface{}) Type { return toType(unsafe.Typeof(i)) }
+func Typeof(i interface{}) Type { return toType(unsafe.Typeof(i)) }
diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go
index 34393f953..bbc66de5e 100644
--- a/src/pkg/reflect/value.go
+++ b/src/pkg/reflect/value.go
@@ -5,8 +5,8 @@
package reflect
import (
- "runtime";
- "unsafe";
+ "runtime"
+ "unsafe"
)
const ptrSize = uintptr(unsafe.Sizeof((*byte)(nil)))
@@ -17,15 +17,15 @@ type addr unsafe.Pointer
// TODO: This will have to go away when
// the new gc goes in.
func memmove(adst, asrc addr, n uintptr) {
- dst := uintptr(adst);
- src := uintptr(asrc);
+ dst := uintptr(adst)
+ src := uintptr(asrc)
switch {
case src < dst && src+n > dst:
// byte copy backward
// careful: i is unsigned
for i := n; i > 0; {
- i--;
- *(*byte)(addr(dst + i)) = *(*byte)(addr(src + i));
+ i--
+ *(*byte)(addr(dst + i)) = *(*byte)(addr(src + i))
}
case (n|src|dst)&(ptrSize-1) != 0:
// byte copy forward
@@ -45,46 +45,46 @@ func memmove(adst, asrc addr, n uintptr) {
// have additional type-specific methods.
type Value interface {
// Type returns the value's type.
- Type() Type;
+ Type() Type
// Interface returns the value as an interface{}.
- Interface() interface{};
+ Interface() interface{}
// CanSet returns whether the value can be changed.
// Values obtained by the use of non-exported struct fields
// can be used in Get but not Set.
// If CanSet() returns false, calling the type-specific Set
// will cause a crash.
- CanSet() bool;
+ CanSet() bool
// SetValue assigns v to the value; v must have the same type as the value.
- SetValue(v Value);
+ SetValue(v Value)
// Addr returns a pointer to the underlying data.
// It is for advanced clients that also
// import the "unsafe" package.
- Addr() uintptr;
+ Addr() uintptr
// Method returns a FuncValue corresponding to the value's i'th method.
// The arguments to a Call on the returned FuncValue
// should not include a receiver; the FuncValue will use
// the value as the receiver.
- Method(i int) *FuncValue;
+ Method(i int) *FuncValue
- getAddr() addr;
+ getAddr() addr
}
type value struct {
- typ Type;
- addr addr;
- canSet bool;
+ typ Type
+ addr addr
+ canSet bool
}
-func (v *value) Type() Type { return v.typ }
+func (v *value) Type() Type { return v.typ }
-func (v *value) Addr() uintptr { return uintptr(v.addr) }
+func (v *value) Addr() uintptr { return uintptr(v.addr) }
-func (v *value) getAddr() addr { return v.addr }
+func (v *value) getAddr() addr { return v.addr }
func (v *value) Interface() interface{} {
if typ, ok := v.typ.(*InterfaceType); ok {
@@ -98,13 +98,13 @@ func (v *value) Interface() interface{} {
}
// Extract from v.addr as interface value with methods.
return *(*interface {
- m();
- })(v.addr);
+ m()
+ })(v.addr)
}
- return unsafe.Unreflect(v.typ, unsafe.Pointer(v.addr));
+ return unsafe.Unreflect(v.typ, unsafe.Pointer(v.addr))
}
-func (v *value) CanSet() bool { return v.canSet }
+func (v *value) CanSet() bool { return v.canSet }
/*
* basic types
@@ -112,325 +112,325 @@ func (v *value) CanSet() bool { return v.canSet }
// BoolValue represents a bool value.
type BoolValue struct {
- value;
+ value
}
// Get returns the underlying bool value.
-func (v *BoolValue) Get() bool { return *(*bool)(v.addr) }
+func (v *BoolValue) Get() bool { return *(*bool)(v.addr) }
// Set sets v to the value x.
func (v *BoolValue) Set(x bool) {
if !v.canSet {
panic(cannotSet)
}
- *(*bool)(v.addr) = x;
+ *(*bool)(v.addr) = x
}
// Set sets v to the value x.
-func (v *BoolValue) SetValue(x Value) { v.Set(x.(*BoolValue).Get()) }
+func (v *BoolValue) SetValue(x Value) { v.Set(x.(*BoolValue).Get()) }
// FloatValue represents a float value.
type FloatValue struct {
- value;
+ value
}
// Get returns the underlying float value.
-func (v *FloatValue) Get() float { return *(*float)(v.addr) }
+func (v *FloatValue) Get() float { return *(*float)(v.addr) }
// Set sets v to the value x.
func (v *FloatValue) Set(x float) {
if !v.canSet {
panic(cannotSet)
}
- *(*float)(v.addr) = x;
+ *(*float)(v.addr) = x
}
// Set sets v to the value x.
-func (v *FloatValue) SetValue(x Value) { v.Set(x.(*FloatValue).Get()) }
+func (v *FloatValue) SetValue(x Value) { v.Set(x.(*FloatValue).Get()) }
// Float32Value represents a float32 value.
type Float32Value struct {
- value;
+ value
}
// Get returns the underlying float32 value.
-func (v *Float32Value) Get() float32 { return *(*float32)(v.addr) }
+func (v *Float32Value) Get() float32 { return *(*float32)(v.addr) }
// Set sets v to the value x.
func (v *Float32Value) Set(x float32) {
if !v.canSet {
panic(cannotSet)
}
- *(*float32)(v.addr) = x;
+ *(*float32)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Float32Value) SetValue(x Value) { v.Set(x.(*Float32Value).Get()) }
+func (v *Float32Value) SetValue(x Value) { v.Set(x.(*Float32Value).Get()) }
// Float64Value represents a float64 value.
type Float64Value struct {
- value;
+ value
}
// Get returns the underlying float64 value.
-func (v *Float64Value) Get() float64 { return *(*float64)(v.addr) }
+func (v *Float64Value) Get() float64 { return *(*float64)(v.addr) }
// Set sets v to the value x.
func (v *Float64Value) Set(x float64) {
if !v.canSet {
panic(cannotSet)
}
- *(*float64)(v.addr) = x;
+ *(*float64)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Float64Value) SetValue(x Value) { v.Set(x.(*Float64Value).Get()) }
+func (v *Float64Value) SetValue(x Value) { v.Set(x.(*Float64Value).Get()) }
// IntValue represents an int value.
type IntValue struct {
- value;
+ value
}
// Get returns the underlying int value.
-func (v *IntValue) Get() int { return *(*int)(v.addr) }
+func (v *IntValue) Get() int { return *(*int)(v.addr) }
// Set sets v to the value x.
func (v *IntValue) Set(x int) {
if !v.canSet {
panic(cannotSet)
}
- *(*int)(v.addr) = x;
+ *(*int)(v.addr) = x
}
// Set sets v to the value x.
-func (v *IntValue) SetValue(x Value) { v.Set(x.(*IntValue).Get()) }
+func (v *IntValue) SetValue(x Value) { v.Set(x.(*IntValue).Get()) }
// Int8Value represents an int8 value.
type Int8Value struct {
- value;
+ value
}
// Get returns the underlying int8 value.
-func (v *Int8Value) Get() int8 { return *(*int8)(v.addr) }
+func (v *Int8Value) Get() int8 { return *(*int8)(v.addr) }
// Set sets v to the value x.
func (v *Int8Value) Set(x int8) {
if !v.canSet {
panic(cannotSet)
}
- *(*int8)(v.addr) = x;
+ *(*int8)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Int8Value) SetValue(x Value) { v.Set(x.(*Int8Value).Get()) }
+func (v *Int8Value) SetValue(x Value) { v.Set(x.(*Int8Value).Get()) }
// Int16Value represents an int16 value.
type Int16Value struct {
- value;
+ value
}
// Get returns the underlying int16 value.
-func (v *Int16Value) Get() int16 { return *(*int16)(v.addr) }
+func (v *Int16Value) Get() int16 { return *(*int16)(v.addr) }
// Set sets v to the value x.
func (v *Int16Value) Set(x int16) {
if !v.canSet {
panic(cannotSet)
}
- *(*int16)(v.addr) = x;
+ *(*int16)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Int16Value) SetValue(x Value) { v.Set(x.(*Int16Value).Get()) }
+func (v *Int16Value) SetValue(x Value) { v.Set(x.(*Int16Value).Get()) }
// Int32Value represents an int32 value.
type Int32Value struct {
- value;
+ value
}
// Get returns the underlying int32 value.
-func (v *Int32Value) Get() int32 { return *(*int32)(v.addr) }
+func (v *Int32Value) Get() int32 { return *(*int32)(v.addr) }
// Set sets v to the value x.
func (v *Int32Value) Set(x int32) {
if !v.canSet {
panic(cannotSet)
}
- *(*int32)(v.addr) = x;
+ *(*int32)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Int32Value) SetValue(x Value) { v.Set(x.(*Int32Value).Get()) }
+func (v *Int32Value) SetValue(x Value) { v.Set(x.(*Int32Value).Get()) }
// Int64Value represents an int64 value.
type Int64Value struct {
- value;
+ value
}
// Get returns the underlying int64 value.
-func (v *Int64Value) Get() int64 { return *(*int64)(v.addr) }
+func (v *Int64Value) Get() int64 { return *(*int64)(v.addr) }
// Set sets v to the value x.
func (v *Int64Value) Set(x int64) {
if !v.canSet {
panic(cannotSet)
}
- *(*int64)(v.addr) = x;
+ *(*int64)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Int64Value) SetValue(x Value) { v.Set(x.(*Int64Value).Get()) }
+func (v *Int64Value) SetValue(x Value) { v.Set(x.(*Int64Value).Get()) }
// StringValue represents a string value.
type StringValue struct {
- value;
+ value
}
// Get returns the underlying string value.
-func (v *StringValue) Get() string { return *(*string)(v.addr) }
+func (v *StringValue) Get() string { return *(*string)(v.addr) }
// Set sets v to the value x.
func (v *StringValue) Set(x string) {
if !v.canSet {
panic(cannotSet)
}
- *(*string)(v.addr) = x;
+ *(*string)(v.addr) = x
}
// Set sets v to the value x.
-func (v *StringValue) SetValue(x Value) { v.Set(x.(*StringValue).Get()) }
+func (v *StringValue) SetValue(x Value) { v.Set(x.(*StringValue).Get()) }
// UintValue represents a uint value.
type UintValue struct {
- value;
+ value
}
// Get returns the underlying uint value.
-func (v *UintValue) Get() uint { return *(*uint)(v.addr) }
+func (v *UintValue) Get() uint { return *(*uint)(v.addr) }
// Set sets v to the value x.
func (v *UintValue) Set(x uint) {
if !v.canSet {
panic(cannotSet)
}
- *(*uint)(v.addr) = x;
+ *(*uint)(v.addr) = x
}
// Set sets v to the value x.
-func (v *UintValue) SetValue(x Value) { v.Set(x.(*UintValue).Get()) }
+func (v *UintValue) SetValue(x Value) { v.Set(x.(*UintValue).Get()) }
// Uint8Value represents a uint8 value.
type Uint8Value struct {
- value;
+ value
}
// Get returns the underlying uint8 value.
-func (v *Uint8Value) Get() uint8 { return *(*uint8)(v.addr) }
+func (v *Uint8Value) Get() uint8 { return *(*uint8)(v.addr) }
// Set sets v to the value x.
func (v *Uint8Value) Set(x uint8) {
if !v.canSet {
panic(cannotSet)
}
- *(*uint8)(v.addr) = x;
+ *(*uint8)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Uint8Value) SetValue(x Value) { v.Set(x.(*Uint8Value).Get()) }
+func (v *Uint8Value) SetValue(x Value) { v.Set(x.(*Uint8Value).Get()) }
// Uint16Value represents a uint16 value.
type Uint16Value struct {
- value;
+ value
}
// Get returns the underlying uint16 value.
-func (v *Uint16Value) Get() uint16 { return *(*uint16)(v.addr) }
+func (v *Uint16Value) Get() uint16 { return *(*uint16)(v.addr) }
// Set sets v to the value x.
func (v *Uint16Value) Set(x uint16) {
if !v.canSet {
panic(cannotSet)
}
- *(*uint16)(v.addr) = x;
+ *(*uint16)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Uint16Value) SetValue(x Value) { v.Set(x.(*Uint16Value).Get()) }
+func (v *Uint16Value) SetValue(x Value) { v.Set(x.(*Uint16Value).Get()) }
// Uint32Value represents a uint32 value.
type Uint32Value struct {
- value;
+ value
}
// Get returns the underlying uint32 value.
-func (v *Uint32Value) Get() uint32 { return *(*uint32)(v.addr) }
+func (v *Uint32Value) Get() uint32 { return *(*uint32)(v.addr) }
// Set sets v to the value x.
func (v *Uint32Value) Set(x uint32) {
if !v.canSet {
panic(cannotSet)
}
- *(*uint32)(v.addr) = x;
+ *(*uint32)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Uint32Value) SetValue(x Value) { v.Set(x.(*Uint32Value).Get()) }
+func (v *Uint32Value) SetValue(x Value) { v.Set(x.(*Uint32Value).Get()) }
// Uint64Value represents a uint64 value.
type Uint64Value struct {
- value;
+ value
}
// Get returns the underlying uint64 value.
-func (v *Uint64Value) Get() uint64 { return *(*uint64)(v.addr) }
+func (v *Uint64Value) Get() uint64 { return *(*uint64)(v.addr) }
// Set sets v to the value x.
func (v *Uint64Value) Set(x uint64) {
if !v.canSet {
panic(cannotSet)
}
- *(*uint64)(v.addr) = x;
+ *(*uint64)(v.addr) = x
}
// Set sets v to the value x.
-func (v *Uint64Value) SetValue(x Value) { v.Set(x.(*Uint64Value).Get()) }
+func (v *Uint64Value) SetValue(x Value) { v.Set(x.(*Uint64Value).Get()) }
// UintptrValue represents a uintptr value.
type UintptrValue struct {
- value;
+ value
}
// Get returns the underlying uintptr value.
-func (v *UintptrValue) Get() uintptr { return *(*uintptr)(v.addr) }
+func (v *UintptrValue) Get() uintptr { return *(*uintptr)(v.addr) }
// Set sets v to the value x.
func (v *UintptrValue) Set(x uintptr) {
if !v.canSet {
panic(cannotSet)
}
- *(*uintptr)(v.addr) = x;
+ *(*uintptr)(v.addr) = x
}
// Set sets v to the value x.
-func (v *UintptrValue) SetValue(x Value) { v.Set(x.(*UintptrValue).Get()) }
+func (v *UintptrValue) SetValue(x Value) { v.Set(x.(*UintptrValue).Get()) }
// UnsafePointerValue represents an unsafe.Pointer value.
type UnsafePointerValue struct {
- value;
+ value
}
// Get returns the underlying uintptr value.
// Get returns uintptr, not unsafe.Pointer, so that
// programs that do not import "unsafe" cannot
// obtain a value of unsafe.Pointer type from "reflect".
-func (v *UnsafePointerValue) Get() uintptr { return uintptr(*(*unsafe.Pointer)(v.addr)) }
+func (v *UnsafePointerValue) Get() uintptr { return uintptr(*(*unsafe.Pointer)(v.addr)) }
// Set sets v to the value x.
func (v *UnsafePointerValue) Set(x unsafe.Pointer) {
if !v.canSet {
panic(cannotSet)
}
- *(*unsafe.Pointer)(v.addr) = x;
+ *(*unsafe.Pointer)(v.addr) = x
}
// Set sets v to the value x.
@@ -451,11 +451,11 @@ func typesMustMatch(t1, t2 Type) {
// ArrayOrSliceValue is the common interface
// implemented by both ArrayValue and SliceValue.
type ArrayOrSliceValue interface {
- Value;
- Len() int;
- Cap() int;
- Elem(i int) Value;
- addr() addr;
+ Value
+ Len() int
+ Cap() int
+ Elem(i int) Value
+ addr() addr
}
// ArrayCopy copies the contents of src into dst until either
@@ -465,30 +465,30 @@ type ArrayOrSliceValue interface {
func ArrayCopy(dst, src ArrayOrSliceValue) int {
// TODO: This will have to move into the runtime
// once the real gc goes in.
- de := dst.Type().(ArrayOrSliceType).Elem();
- se := src.Type().(ArrayOrSliceType).Elem();
- typesMustMatch(de, se);
- n := dst.Len();
+ de := dst.Type().(ArrayOrSliceType).Elem()
+ se := src.Type().(ArrayOrSliceType).Elem()
+ typesMustMatch(de, se)
+ n := dst.Len()
if xn := src.Len(); n > xn {
n = xn
}
- memmove(dst.addr(), src.addr(), uintptr(n)*de.Size());
- return n;
+ memmove(dst.addr(), src.addr(), uintptr(n)*de.Size())
+ return n
}
// An ArrayValue represents an array.
type ArrayValue struct {
- value;
+ value
}
// Len returns the length of the array.
-func (v *ArrayValue) Len() int { return v.typ.(*ArrayType).Len() }
+func (v *ArrayValue) Len() int { return v.typ.(*ArrayType).Len() }
// Cap returns the capacity of the array (equal to Len()).
-func (v *ArrayValue) Cap() int { return v.typ.(*ArrayType).Len() }
+func (v *ArrayValue) Cap() int { return v.typ.(*ArrayType).Len() }
// addr returns the base address of the data in the array.
-func (v *ArrayValue) addr() addr { return v.value.addr }
+func (v *ArrayValue) addr() addr { return v.value.addr }
// Set assigns x to v.
// The new value x must have the same type as v.
@@ -496,22 +496,22 @@ func (v *ArrayValue) Set(x *ArrayValue) {
if !v.canSet {
panic(cannotSet)
}
- typesMustMatch(v.typ, x.typ);
- ArrayCopy(v, x);
+ typesMustMatch(v.typ, x.typ)
+ ArrayCopy(v, x)
}
// Set sets v to the value x.
-func (v *ArrayValue) SetValue(x Value) { v.Set(x.(*ArrayValue)) }
+func (v *ArrayValue) SetValue(x Value) { v.Set(x.(*ArrayValue)) }
// Elem returns the i'th element of v.
func (v *ArrayValue) Elem(i int) Value {
- typ := v.typ.(*ArrayType).Elem();
- n := v.Len();
+ typ := v.typ.(*ArrayType).Elem()
+ n := v.Len()
if i < 0 || i >= n {
panic("index", i, "in array len", n)
}
- p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size());
- return newValue(typ, p, v.canSet);
+ p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size())
+ return newValue(typ, p, v.canSet)
}
/*
@@ -520,38 +520,38 @@ func (v *ArrayValue) Elem(i int) Value {
// runtime representation of slice
type SliceHeader struct {
- Data uintptr;
- Len int;
- Cap int;
+ Data uintptr
+ Len int
+ Cap int
}
// A SliceValue represents a slice.
type SliceValue struct {
- value;
+ value
}
-func (v *SliceValue) slice() *SliceHeader { return (*SliceHeader)(v.value.addr) }
+func (v *SliceValue) slice() *SliceHeader { return (*SliceHeader)(v.value.addr) }
// IsNil returns whether v is a nil slice.
-func (v *SliceValue) IsNil() bool { return v.slice().Data == 0 }
+func (v *SliceValue) IsNil() bool { return v.slice().Data == 0 }
// Len returns the length of the slice.
-func (v *SliceValue) Len() int { return int(v.slice().Len) }
+func (v *SliceValue) Len() int { return int(v.slice().Len) }
// Cap returns the capacity of the slice.
-func (v *SliceValue) Cap() int { return int(v.slice().Cap) }
+func (v *SliceValue) Cap() int { return int(v.slice().Cap) }
// addr returns the base address of the data in the slice.
-func (v *SliceValue) addr() addr { return addr(v.slice().Data) }
+func (v *SliceValue) addr() addr { return addr(v.slice().Data) }
// SetLen changes the length of v.
// The new length n must be between 0 and the capacity, inclusive.
func (v *SliceValue) SetLen(n int) {
- s := v.slice();
+ s := v.slice()
if n < 0 || n > int(s.Cap) {
panicln("SetLen", n, "with capacity", s.Cap)
}
- s.Len = n;
+ s.Len = n
}
// Set assigns x to v.
@@ -560,36 +560,36 @@ func (v *SliceValue) Set(x *SliceValue) {
if !v.canSet {
panic(cannotSet)
}
- typesMustMatch(v.typ, x.typ);
- *v.slice() = *x.slice();
+ typesMustMatch(v.typ, x.typ)
+ *v.slice() = *x.slice()
}
// Set sets v to the value x.
-func (v *SliceValue) SetValue(x Value) { v.Set(x.(*SliceValue)) }
+func (v *SliceValue) SetValue(x Value) { v.Set(x.(*SliceValue)) }
// Slice returns a sub-slice of the slice v.
func (v *SliceValue) Slice(beg, end int) *SliceValue {
- cap := v.Cap();
+ cap := v.Cap()
if beg < 0 || end < beg || end > cap {
panic("slice bounds [", beg, ":", end, "] with capacity ", cap)
}
- typ := v.typ.(*SliceType);
- s := new(SliceHeader);
- s.Data = uintptr(v.addr()) + uintptr(beg)*typ.Elem().Size();
- s.Len = end - beg;
- s.Cap = cap - beg;
- return newValue(typ, addr(s), v.canSet).(*SliceValue);
+ typ := v.typ.(*SliceType)
+ s := new(SliceHeader)
+ s.Data = uintptr(v.addr()) + uintptr(beg)*typ.Elem().Size()
+ s.Len = end - beg
+ s.Cap = cap - beg
+ return newValue(typ, addr(s), v.canSet).(*SliceValue)
}
// Elem returns the i'th element of v.
func (v *SliceValue) Elem(i int) Value {
- typ := v.typ.(*SliceType).Elem();
- n := v.Len();
+ typ := v.typ.(*SliceType).Elem()
+ n := v.Len()
if i < 0 || i >= n {
panicln("index", i, "in array of length", n)
}
- p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size());
- return newValue(typ, p, v.canSet);
+ p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size())
+ return newValue(typ, p, v.canSet)
}
// MakeSlice creates a new zero-initialized slice value
@@ -599,8 +599,8 @@ func MakeSlice(typ *SliceType, len, cap int) *SliceValue {
Data: uintptr(unsafe.NewArray(typ.Elem(), cap)),
Len: len,
Cap: cap,
- };
- return newValue(typ, addr(s), true).(*SliceValue);
+ }
+ return newValue(typ, addr(s), true).(*SliceValue)
}
/*
@@ -609,11 +609,11 @@ func MakeSlice(typ *SliceType, len, cap int) *SliceValue {
// A ChanValue represents a chan.
type ChanValue struct {
- value;
+ value
}
// IsNil returns whether v is a nil channel.
-func (v *ChanValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 }
+func (v *ChanValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 }
// Set assigns x to v.
// The new value x must have the same type as v.
@@ -621,16 +621,16 @@ func (v *ChanValue) Set(x *ChanValue) {
if !v.canSet {
panic(cannotSet)
}
- typesMustMatch(v.typ, x.typ);
- *(*uintptr)(v.addr) = *(*uintptr)(x.addr);
+ typesMustMatch(v.typ, x.typ)
+ *(*uintptr)(v.addr) = *(*uintptr)(x.addr)
}
// Set sets v to the value x.
-func (v *ChanValue) SetValue(x Value) { v.Set(x.(*ChanValue)) }
+func (v *ChanValue) SetValue(x Value) { v.Set(x.(*ChanValue)) }
// Get returns the uintptr value of v.
// It is mainly useful for printing.
-func (v *ChanValue) Get() uintptr { return *(*uintptr)(v.addr) }
+func (v *ChanValue) Get() uintptr { return *(*uintptr)(v.addr) }
// implemented in ../pkg/runtime/reflect.cgo
func makechan(typ *runtime.ChanType, size uint32) (ch *byte)
@@ -643,72 +643,72 @@ func chancap(ch *byte) int32
// Closed returns the result of closed(c) on the underlying channel.
func (v *ChanValue) Closed() bool {
- ch := *(**byte)(v.addr);
- return chanclosed(ch);
+ ch := *(**byte)(v.addr)
+ return chanclosed(ch)
}
// Close closes the channel.
func (v *ChanValue) Close() {
- ch := *(**byte)(v.addr);
- chanclose(ch);
+ ch := *(**byte)(v.addr)
+ chanclose(ch)
}
func (v *ChanValue) Len() int {
- ch := *(**byte)(v.addr);
- return int(chanlen(ch));
+ ch := *(**byte)(v.addr)
+ return int(chanlen(ch))
}
func (v *ChanValue) Cap() int {
- ch := *(**byte)(v.addr);
- return int(chancap(ch));
+ ch := *(**byte)(v.addr)
+ return int(chancap(ch))
}
// internal send; non-blocking if b != nil
func (v *ChanValue) send(x Value, b *bool) {
- t := v.Type().(*ChanType);
+ t := v.Type().(*ChanType)
if t.Dir()&SendDir == 0 {
panic("send on recv-only channel")
}
- typesMustMatch(t.Elem(), x.Type());
- ch := *(**byte)(v.addr);
- chansend(ch, (*byte)(x.getAddr()), b);
+ typesMustMatch(t.Elem(), x.Type())
+ ch := *(**byte)(v.addr)
+ chansend(ch, (*byte)(x.getAddr()), b)
}
// internal recv; non-blocking if b != nil
func (v *ChanValue) recv(b *bool) Value {
- t := v.Type().(*ChanType);
+ t := v.Type().(*ChanType)
if t.Dir()&RecvDir == 0 {
panic("recv on send-only channel")
}
- ch := *(**byte)(v.addr);
- x := MakeZero(t.Elem());
- chanrecv(ch, (*byte)(x.getAddr()), b);
- return x;
+ ch := *(**byte)(v.addr)
+ x := MakeZero(t.Elem())
+ chanrecv(ch, (*byte)(x.getAddr()), b)
+ return x
}
// Send sends x on the channel v.
-func (v *ChanValue) Send(x Value) { v.send(x, nil) }
+func (v *ChanValue) Send(x Value) { v.send(x, nil) }
// Recv receives and returns a value from the channel v.
-func (v *ChanValue) Recv() Value { return v.recv(nil) }
+func (v *ChanValue) Recv() Value { return v.recv(nil) }
// TrySend attempts to sends x on the channel v but will not block.
// It returns true if the value was sent, false otherwise.
func (v *ChanValue) TrySend(x Value) bool {
- var ok bool;
- v.send(x, &ok);
- return ok;
+ var ok bool
+ v.send(x, &ok)
+ return ok
}
// TryRecv attempts to receive a value from the channel v but will not block.
// It returns the value if one is received, nil otherwise.
func (v *ChanValue) TryRecv() Value {
- var ok bool;
- x := v.recv(&ok);
+ var ok bool
+ x := v.recv(&ok)
if !ok {
return nil
}
- return x;
+ return x
}
// MakeChan creates a new channel with the specified type and buffer size.
@@ -719,9 +719,9 @@ func MakeChan(typ *ChanType, buffer int) *ChanValue {
if typ.Dir() != BothDir {
panic("MakeChan: unidirectional channel type")
}
- v := MakeZero(typ).(*ChanValue);
- *(**byte)(v.addr) = makechan((*runtime.ChanType)(unsafe.Pointer(typ)), uint32(buffer));
- return v;
+ v := MakeZero(typ).(*ChanValue)
+ *(**byte)(v.addr) = makechan((*runtime.ChanType)(unsafe.Pointer(typ)), uint32(buffer))
+ return v
}
/*
@@ -730,17 +730,17 @@ func MakeChan(typ *ChanType, buffer int) *ChanValue {
// A FuncValue represents a function value.
type FuncValue struct {
- value;
- first *value;
- isInterface bool;
+ value
+ first *value
+ isInterface bool
}
// IsNil returns whether v is a nil function.
-func (v *FuncValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 }
+func (v *FuncValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 }
// Get returns the uintptr value of v.
// It is mainly useful for printing.
-func (v *FuncValue) Get() uintptr { return *(*uintptr)(v.addr) }
+func (v *FuncValue) Get() uintptr { return *(*uintptr)(v.addr) }
// Set assigns x to v.
// The new value x must have the same type as v.
@@ -748,71 +748,71 @@ func (v *FuncValue) Set(x *FuncValue) {
if !v.canSet {
panic(cannotSet)
}
- typesMustMatch(v.typ, x.typ);
- *(*uintptr)(v.addr) = *(*uintptr)(x.addr);
+ typesMustMatch(v.typ, x.typ)
+ *(*uintptr)(v.addr) = *(*uintptr)(x.addr)
}
// Set sets v to the value x.
-func (v *FuncValue) SetValue(x Value) { v.Set(x.(*FuncValue)) }
+func (v *FuncValue) SetValue(x Value) { v.Set(x.(*FuncValue)) }
// Method returns a FuncValue corresponding to v's i'th method.
// The arguments to a Call on the returned FuncValue
// should not include a receiver; the FuncValue will use v
// as the receiver.
func (v *value) Method(i int) *FuncValue {
- t := v.Type().uncommon();
+ t := v.Type().uncommon()
if t == nil || i < 0 || i >= len(t.methods) {
return nil
}
- p := &t.methods[i];
- fn := p.tfn;
- fv := &FuncValue{value: value{toType(*p.typ), addr(&fn), true}, first: v, isInterface: false};
- return fv;
+ p := &t.methods[i]
+ fn := p.tfn
+ fv := &FuncValue{value: value{toType(*p.typ), addr(&fn), true}, first: v, isInterface: false}
+ return fv
}
// implemented in ../pkg/runtime/*/asm.s
func call(fn, arg *byte, n uint32)
type tiny struct {
- b byte;
+ b byte
}
// Call calls the function v with input parameters in.
// It returns the function's output parameters as Values.
func (fv *FuncValue) Call(in []Value) []Value {
- var structAlign = Typeof((*tiny)(nil)).(*PtrType).Elem().Size();
+ var structAlign = Typeof((*tiny)(nil)).(*PtrType).Elem().Size()
- t := fv.Type().(*FuncType);
- nin := len(in);
+ t := fv.Type().(*FuncType)
+ nin := len(in)
if fv.first != nil && !fv.isInterface {
nin++
}
if nin != t.NumIn() {
panic("FuncValue: wrong argument count")
}
- nout := t.NumOut();
+ nout := t.NumOut()
// Compute arg size & allocate.
// This computation is 6g/8g-dependent
// and probably wrong for gccgo, but so
// is most of this function.
- size := uintptr(0);
+ size := uintptr(0)
if fv.isInterface {
// extra word for interface value
size += ptrSize
}
for i := 0; i < nin; i++ {
- tv := t.In(i);
- a := uintptr(tv.Align());
- size = (size + a - 1) &^ (a - 1);
- size += tv.Size();
+ tv := t.In(i)
+ a := uintptr(tv.Align())
+ size = (size + a - 1) &^ (a - 1)
+ size += tv.Size()
}
- size = (size + structAlign - 1) &^ (structAlign - 1);
+ size = (size + structAlign - 1) &^ (structAlign - 1)
for i := 0; i < nout; i++ {
- tv := t.Out(i);
- a := uintptr(tv.Align());
- size = (size + a - 1) &^ (a - 1);
- size += tv.Size();
+ tv := t.Out(i)
+ a := uintptr(tv.Align())
+ size = (size + a - 1) &^ (a - 1)
+ size += tv.Size()
}
// size must be > 0 in order for &args[0] to be valid.
@@ -821,8 +821,8 @@ func (fv *FuncValue) Call(in []Value) []Value {
if size < 8 {
size = 8
}
- args := make([]byte, size);
- ptr := uintptr(unsafe.Pointer(&args[0]));
+ args := make([]byte, size)
+ ptr := uintptr(unsafe.Pointer(&args[0]))
// Copy into args.
//
@@ -830,54 +830,54 @@ func (fv *FuncValue) Call(in []Value) []Value {
// This one may be fine. The values are holding up the
// references for us, so maybe this can be treated
// like any stack-to-stack copy.
- off := uintptr(0);
- delta := 0;
+ off := uintptr(0)
+ delta := 0
if v := fv.first; v != nil {
// Hard-wired first argument.
if fv.isInterface {
// v is a single uninterpreted word
- memmove(addr(ptr), v.getAddr(), ptrSize);
- off = ptrSize;
+ memmove(addr(ptr), v.getAddr(), ptrSize)
+ off = ptrSize
} else {
// v is a real value
- tv := v.Type();
- typesMustMatch(t.In(0), tv);
- n := tv.Size();
- memmove(addr(ptr), v.getAddr(), n);
- off = n;
- delta = 1;
+ tv := v.Type()
+ typesMustMatch(t.In(0), tv)
+ n := tv.Size()
+ memmove(addr(ptr), v.getAddr(), n)
+ off = n
+ delta = 1
}
}
for i, v := range in {
- tv := v.Type();
- typesMustMatch(t.In(i+delta), tv);
- a := uintptr(tv.Align());
- off = (off + a - 1) &^ (a - 1);
- n := tv.Size();
- memmove(addr(ptr+off), v.getAddr(), n);
- off += n;
+ tv := v.Type()
+ typesMustMatch(t.In(i+delta), tv)
+ a := uintptr(tv.Align())
+ off = (off + a - 1) &^ (a - 1)
+ n := tv.Size()
+ memmove(addr(ptr+off), v.getAddr(), n)
+ off += n
}
- off = (off + structAlign - 1) &^ (structAlign - 1);
+ off = (off + structAlign - 1) &^ (structAlign - 1)
// Call
- call(*(**byte)(fv.addr), (*byte)(addr(ptr)), uint32(size));
+ call(*(**byte)(fv.addr), (*byte)(addr(ptr)), uint32(size))
// Copy return values out of args.
//
// TODO(rsc): revisit like above.
- ret := make([]Value, nout);
+ ret := make([]Value, nout)
for i := 0; i < nout; i++ {
- tv := t.Out(i);
- a := uintptr(tv.Align());
- off = (off + a - 1) &^ (a - 1);
- v := MakeZero(tv);
- n := tv.Size();
- memmove(v.getAddr(), addr(ptr+off), n);
- ret[i] = v;
- off += n;
+ tv := t.Out(i)
+ a := uintptr(tv.Align())
+ off = (off + a - 1) &^ (a - 1)
+ v := MakeZero(tv)
+ n := tv.Size()
+ memmove(v.getAddr(), addr(ptr+off), n)
+ ret[i] = v
+ off += n
}
- return ret;
+ return ret
}
/*
@@ -886,16 +886,16 @@ func (fv *FuncValue) Call(in []Value) []Value {
// An InterfaceValue represents an interface value.
type InterfaceValue struct {
- value;
+ value
}
// No Get because v.Interface() is available.
// IsNil returns whether v is a nil interface value.
-func (v *InterfaceValue) IsNil() bool { return v.Interface() == nil }
+func (v *InterfaceValue) IsNil() bool { return v.Interface() == nil }
// Elem returns the concrete value stored in the interface value v.
-func (v *InterfaceValue) Elem() Value { return NewValue(v.Interface()) }
+func (v *InterfaceValue) Elem() Value { return NewValue(v.Interface()) }
// ../runtime/reflect.cgo
func setiface(typ *InterfaceType, x *interface{}, addr addr)
@@ -911,38 +911,38 @@ func (v *InterfaceValue) Set(x Value) {
}
// Two different representations; see comment in Get.
// Empty interface is easy.
- t := v.typ.(*InterfaceType);
+ t := v.typ.(*InterfaceType)
if t.NumMethod() == 0 {
- *(*interface{})(v.addr) = i;
- return;
+ *(*interface{})(v.addr) = i
+ return
}
// Non-empty interface requires a runtime check.
- setiface(t, &i, v.addr);
+ setiface(t, &i, v.addr)
}
// Set sets v to the value x.
-func (v *InterfaceValue) SetValue(x Value) { v.Set(x) }
+func (v *InterfaceValue) SetValue(x Value) { v.Set(x) }
// Method returns a FuncValue corresponding to v's i'th method.
// The arguments to a Call on the returned FuncValue
// should not include a receiver; the FuncValue will use v
// as the receiver.
func (v *InterfaceValue) Method(i int) *FuncValue {
- t := v.Type().(*InterfaceType);
+ t := v.Type().(*InterfaceType)
if t == nil || i < 0 || i >= len(t.methods) {
return nil
}
- p := &t.methods[i];
+ p := &t.methods[i]
// Interface is two words: itable, data.
- tab := *(**runtime.Itable)(v.addr);
- data := &value{Typeof((*byte)(nil)), addr(uintptr(v.addr) + ptrSize), true};
+ tab := *(**runtime.Itable)(v.addr)
+ data := &value{Typeof((*byte)(nil)), addr(uintptr(v.addr) + ptrSize), true}
// Function pointer is at p.perm in the table.
- fn := tab.Fn[p.perm];
- fv := &FuncValue{value: value{toType(*p.typ), addr(&fn), true}, first: data, isInterface: true};
- return fv;
+ fn := tab.Fn[p.perm]
+ fv := &FuncValue{value: value{toType(*p.typ), addr(&fn), true}, first: data, isInterface: true}
+ return fv
}
/*
@@ -951,11 +951,11 @@ func (v *InterfaceValue) Method(i int) *FuncValue {
// A MapValue represents a map value.
type MapValue struct {
- value;
+ value
}
// IsNil returns whether v is a nil map value.
-func (v *MapValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 }
+func (v *MapValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 }
// Set assigns x to v.
// The new value x must have the same type as v.
@@ -963,12 +963,12 @@ func (v *MapValue) Set(x *MapValue) {
if !v.canSet {
panic(cannotSet)
}
- typesMustMatch(v.typ, x.typ);
- *(*uintptr)(v.addr) = *(*uintptr)(x.addr);
+ typesMustMatch(v.typ, x.typ)
+ *(*uintptr)(v.addr) = *(*uintptr)(x.addr)
}
// Set sets v to the value x.
-func (v *MapValue) SetValue(x Value) { v.Set(x.(*MapValue)) }
+func (v *MapValue) SetValue(x Value) { v.Set(x.(*MapValue)) }
// implemented in ../pkg/runtime/reflect.cgo
func mapaccess(m, key, val *byte) bool
@@ -982,70 +982,70 @@ func makemap(t *runtime.MapType) *byte
// Elem returns the value associated with key in the map v.
// It returns nil if key is not found in the map.
func (v *MapValue) Elem(key Value) Value {
- t := v.Type().(*MapType);
- typesMustMatch(t.Key(), key.Type());
- m := *(**byte)(v.addr);
+ t := v.Type().(*MapType)
+ typesMustMatch(t.Key(), key.Type())
+ m := *(**byte)(v.addr)
if m == nil {
return nil
}
- newval := MakeZero(t.Elem());
+ newval := MakeZero(t.Elem())
if !mapaccess(m, (*byte)(key.getAddr()), (*byte)(newval.getAddr())) {
return nil
}
- return newval;
+ return newval
}
// SetElem sets the value associated with key in the map v to val.
// If val is nil, Put deletes the key from map.
func (v *MapValue) SetElem(key, val Value) {
- t := v.Type().(*MapType);
- typesMustMatch(t.Key(), key.Type());
- var vaddr *byte;
+ t := v.Type().(*MapType)
+ typesMustMatch(t.Key(), key.Type())
+ var vaddr *byte
if val != nil {
- typesMustMatch(t.Elem(), val.Type());
- vaddr = (*byte)(val.getAddr());
+ typesMustMatch(t.Elem(), val.Type())
+ vaddr = (*byte)(val.getAddr())
}
- m := *(**byte)(v.addr);
- mapassign(m, (*byte)(key.getAddr()), vaddr);
+ m := *(**byte)(v.addr)
+ mapassign(m, (*byte)(key.getAddr()), vaddr)
}
// Len returns the number of keys in the map v.
func (v *MapValue) Len() int {
- m := *(**byte)(v.addr);
+ m := *(**byte)(v.addr)
if m == nil {
return 0
}
- return int(maplen(m));
+ return int(maplen(m))
}
// Keys returns a slice containing all the keys present in the map,
// in unspecified order.
func (v *MapValue) Keys() []Value {
- tk := v.Type().(*MapType).Key();
- m := *(**byte)(v.addr);
- mlen := int32(0);
+ tk := v.Type().(*MapType).Key()
+ m := *(**byte)(v.addr)
+ mlen := int32(0)
if m != nil {
mlen = maplen(m)
}
- it := mapiterinit(m);
- a := make([]Value, mlen);
- var i int;
+ it := mapiterinit(m)
+ a := make([]Value, mlen)
+ var i int
for i = 0; i < len(a); i++ {
- k := MakeZero(tk);
+ k := MakeZero(tk)
if !mapiterkey(it, (*byte)(k.getAddr())) {
break
}
- a[i] = k;
- mapiternext(it);
+ a[i] = k
+ mapiternext(it)
}
- return a[0:i];
+ return a[0:i]
}
// MakeMap creates a new map of the specified type.
func MakeMap(typ *MapType) *MapValue {
- v := MakeZero(typ).(*MapValue);
- *(**byte)(v.addr) = makemap((*runtime.MapType)(unsafe.Pointer(typ)));
- return v;
+ v := MakeZero(typ).(*MapValue)
+ *(**byte)(v.addr) = makemap((*runtime.MapType)(unsafe.Pointer(typ)))
+ return v
}
/*
@@ -1054,15 +1054,15 @@ func MakeMap(typ *MapType) *MapValue {
// A PtrValue represents a pointer.
type PtrValue struct {
- value;
+ value
}
// IsNil returns whether v is a nil pointer.
-func (v *PtrValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 }
+func (v *PtrValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 }
// Get returns the uintptr value of v.
// It is mainly useful for printing.
-func (v *PtrValue) Get() uintptr { return *(*uintptr)(v.addr) }
+func (v *PtrValue) Get() uintptr { return *(*uintptr)(v.addr) }
// Set assigns x to v.
// The new value x must have the same type as v.
@@ -1070,24 +1070,24 @@ func (v *PtrValue) Set(x *PtrValue) {
if !v.canSet {
panic(cannotSet)
}
- typesMustMatch(v.typ, x.typ);
+ typesMustMatch(v.typ, x.typ)
// TODO: This will have to move into the runtime
// once the new gc goes in
- *(*uintptr)(v.addr) = *(*uintptr)(x.addr);
+ *(*uintptr)(v.addr) = *(*uintptr)(x.addr)
}
// Set sets v to the value x.
-func (v *PtrValue) SetValue(x Value) { v.Set(x.(*PtrValue)) }
+func (v *PtrValue) SetValue(x Value) { v.Set(x.(*PtrValue)) }
// PointTo changes v to point to x.
func (v *PtrValue) PointTo(x Value) {
if !x.CanSet() {
panic("cannot set x; cannot point to x")
}
- typesMustMatch(v.typ.(*PtrType).Elem(), x.Type());
+ typesMustMatch(v.typ.(*PtrType).Elem(), x.Type())
// TODO: This will have to move into the runtime
// once the new gc goes in.
- *(*uintptr)(v.addr) = x.Addr();
+ *(*uintptr)(v.addr) = x.Addr()
}
// Elem returns the value that v points to.
@@ -1096,7 +1096,7 @@ func (v *PtrValue) Elem() Value {
if v.IsNil() {
return nil
}
- return newValue(v.typ.(*PtrType).Elem(), *(*addr)(v.addr), v.canSet);
+ return newValue(v.typ.(*PtrType).Elem(), *(*addr)(v.addr), v.canSet)
}
// Indirect returns the value that v points to.
@@ -1106,7 +1106,7 @@ func Indirect(v Value) Value {
if pv, ok := v.(*PtrValue); ok {
return pv.Elem()
}
- return v;
+ return v
}
/*
@@ -1115,7 +1115,7 @@ func Indirect(v Value) Value {
// A StructValue represents a struct value.
type StructValue struct {
- value;
+ value
}
// Set assigns x to v.
@@ -1126,26 +1126,26 @@ func (v *StructValue) Set(x *StructValue) {
if !v.canSet {
panic(cannotSet)
}
- typesMustMatch(v.typ, x.typ);
- memmove(v.addr, x.addr, v.typ.Size());
+ typesMustMatch(v.typ, x.typ)
+ memmove(v.addr, x.addr, v.typ.Size())
}
// Set sets v to the value x.
-func (v *StructValue) SetValue(x Value) { v.Set(x.(*StructValue)) }
+func (v *StructValue) SetValue(x Value) { v.Set(x.(*StructValue)) }
// Field returns the i'th field of the struct.
func (v *StructValue) Field(i int) Value {
- t := v.typ.(*StructType);
+ t := v.typ.(*StructType)
if i < 0 || i >= t.NumField() {
return nil
}
- f := t.Field(i);
- return newValue(f.Type, addr(uintptr(v.addr)+f.Offset), v.canSet && f.PkgPath == "");
+ f := t.Field(i)
+ return newValue(f.Type, addr(uintptr(v.addr)+f.Offset), v.canSet && f.PkgPath == "")
}
// FieldByIndex returns the nested field corresponding to index.
func (t *StructValue) FieldByIndex(index []int) (v Value) {
- v = t;
+ v = t
for i, x := range index {
if i > 0 {
if p, ok := v.(*PtrValue); ok {
@@ -1154,13 +1154,13 @@ func (t *StructValue) FieldByIndex(index []int) (v Value) {
if s, ok := v.(*StructValue); ok {
t = s
} else {
- v = nil;
- return;
+ v = nil
+ return
}
}
- v = t.Field(x);
+ v = t.Field(x)
}
- return;
+ return
}
// FieldByName returns the struct field with the given name.
@@ -1169,11 +1169,11 @@ func (t *StructValue) FieldByName(name string) Value {
if f, ok := t.Type().(*StructType).FieldByName(name); ok {
return t.FieldByIndex(f.Index)
}
- return nil;
+ return nil
}
// NumField returns the number of fields in the struct.
-func (v *StructValue) NumField() int { return v.typ.(*StructType).NumField() }
+func (v *StructValue) NumField() int { return v.typ.(*StructType).NumField() }
/*
* constructors
@@ -1185,8 +1185,8 @@ func NewValue(i interface{}) Value {
if i == nil {
return nil
}
- t, a := unsafe.Reflect(i);
- return newValue(toType(t), addr(a), true);
+ t, a := unsafe.Reflect(i)
+ return newValue(toType(t), addr(a), true)
}
@@ -1203,7 +1203,7 @@ func newValue(typ Type, addr addr, canSet bool) Value {
// All values have same memory layout;
// build once and convert.
- v := &struct{ value }{value{typ, addr, canSet}};
+ v := &struct{ value }{value{typ, addr, canSet}}
switch typ.(type) {
case *ArrayType:
// TODO(rsc): Something must prevent
@@ -1261,7 +1261,7 @@ func newValue(typ Type, addr addr, canSet bool) Value {
case *UnsafePointerType:
return (*UnsafePointerValue)(v)
}
- panicln("newValue", typ.String());
+ panicln("newValue", typ.String())
}
// MakeZero returns a zero Value for the specified Type.
@@ -1269,5 +1269,5 @@ func MakeZero(typ Type) Value {
if typ == nil {
return nil
}
- return newValue(typ, addr(unsafe.New(typ)), true);
+ return newValue(typ, addr(unsafe.New(typ)), true)
}