diff options
| author | Russ Cox <rsc@golang.org> | 2008-12-18 22:37:22 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2008-12-18 22:37:22 -0800 |
| commit | d47d888ba663014e6aa8ca043e694f4b2a5898b8 (patch) | |
| tree | 851fad01a87b8fa071ed46fa0985f1857d9e47ca /src/lib/reflect | |
| parent | 9786f69f74a5fa290476774e07fb10ce8da84123 (diff) | |
| download | go-d47d888ba663014e6aa8ca043e694f4b2a5898b8.tar.xz | |
convert *[] to [].
R=r
OCL=21563
CL=21571
Diffstat (limited to 'src/lib/reflect')
| -rw-r--r-- | src/lib/reflect/all_test.go | 61 | ||||
| -rw-r--r-- | src/lib/reflect/type.go | 13 | ||||
| -rw-r--r-- | src/lib/reflect/value.go | 4 |
3 files changed, 41 insertions, 37 deletions
diff --git a/src/lib/reflect/all_test.go b/src/lib/reflect/all_test.go index fe16a82f5b..df3ca648a2 100644 --- a/src/lib/reflect/all_test.go +++ b/src/lib/reflect/all_test.go @@ -177,23 +177,23 @@ export func TestAll(tt *testing.T) { // TODO(r): wrap up better value := reflect.NewValue(tmp); assert(reflect.ValueToString(value), "*reflect.C·all_test(@)"); } - { - type A [10]int; - var tmp A = A{1,2,3,4,5,6,7,8,9,10}; - value := reflect.NewValue(&tmp); - assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.A·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}"); - value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123); - assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.A·all_test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}"); - } - { - type AA []int; - tmp1 := [10]int{1,2,3,4,5,6,7,8,9,10}; // TODO: should not be necessary to use tmp1 - var tmp *AA = &tmp1; - value := reflect.NewValue(tmp); - assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}"); - value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123); - assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}"); - } +// { +// type A [10]int; +// var tmp A = A{1,2,3,4,5,6,7,8,9,10}; +// value := reflect.NewValue(&tmp); +// assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.A·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}"); +// value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123); +// assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.A·all_test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}"); +// } +// { +// type AA []int; +// tmp1 := [10]int{1,2,3,4,5,6,7,8,9,10}; // TODO: should not be necessary to use tmp1 +// var tmp *AA = &tmp1; +// value := reflect.NewValue(tmp); +// assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}"); +// value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123); +// assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}"); +// } { var ip *int32; @@ -264,18 +264,19 @@ export func TestAll(tt *testing.T) { // TODO(r): wrap up better assert(ct.Elem().String(), "string"); // make sure tag strings are not part of element type - t = reflect.ParseTypeString("", "struct{d *[]uint32 \"TAG\"}"); + t = reflect.ParseTypeString("", "struct{d []uint32 \"TAG\"}"); st = t.(reflect.StructType); name, typ, tag, offset = st.Field(0); - assert(typ.String(), "*[]uint32"); + assert(typ.String(), "[]uint32"); t = reflect.ParseTypeString("", "[]int32"); v := reflect.NewOpenArrayValue(t, 5, 10); t1 := reflect.ParseTypeString("", "*[]int32"); v1 := reflect.NewInitValue(t1); + if v1 == nil { panic("V1 is nil"); } v1.(reflect.PtrValue).SetSub(v); a := v1.Interface().(*[]int32); - println(a, len(a), cap(a)); + println(&a, len(a), cap(a)); for i := 0; i < len(a); i++ { v.Elem(i).(reflect.Int32Value).Set(int32(i)); } @@ -296,33 +297,35 @@ export func TestInterfaceGet(t *testing.T) { } export 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"); } } - for tocopy := 5; tocopy <= 6; tocopy++ { + for tocopy := 1; tocopy <= 7; tocopy++ { CopyArray(vb.(PtrValue).Sub(), va.(PtrValue).Sub(), tocopy); for i := 0; i < tocopy; i++ { if a[i] != b[i] { - t.Errorf("tocopy=%d a[%d]=%d, b[%d]=%d", + t.Errorf("1 tocopy=%d a[%d]=%d, b[%d]=%d", tocopy, i, a[i], i, b[i]); } } for i := tocopy; i < len(b); i++ { if b[i] != c[i] { if i < len(a) { - t.Errorf("tocopy=%d a[%d]=%d, b[%d]=%d, c[%d]=%d", + t.Errorf("2 tocopy=%d a[%d]=%d, b[%d]=%d, c[%d]=%d", tocopy, i, a[i], i, b[i], i, c[i]); } else { - t.Errorf("tocopy=%d b[%d]=%d, c[%d]=%d", + t.Errorf("3 tocopy=%d b[%d]=%d, c[%d]=%d", tocopy, i, b[i], i, c[i]); } + } else { + t.Logf("tocopy=%d elem %d is okay\n", tocopy, i); } } } diff --git a/src/lib/reflect/type.go b/src/lib/reflect/type.go index b6caca1ffc..3fbfe110b9 100644 --- a/src/lib/reflect/type.go +++ b/src/lib/reflect/type.go @@ -124,6 +124,7 @@ type StubType struct { } func NewStubType(name string, typ Type) *StubType { +if typ == nil && len(name) > 0 && name[0] == '*' { panicln("NewStubType", name, typ) } return &StubType{name, typ} } @@ -275,10 +276,10 @@ type Field struct { type StructTypeStruct struct { Common; - field *[]Field; + field []Field; } -func NewStructTypeStruct(name, typestring string, field *[]Field) *StructTypeStruct { +func NewStructTypeStruct(name, typestring string, field []Field) *StructTypeStruct { return &StructTypeStruct{ Common{StructKind, typestring, name, 0}, field} } @@ -327,10 +328,10 @@ export type InterfaceType interface { type InterfaceTypeStruct struct { Common; - field *[]Field; + field []Field; } -func NewInterfaceTypeStruct(name, typestring string, field *[]Field) *InterfaceTypeStruct { +func NewInterfaceTypeStruct(name, typestring string, field []Field) *InterfaceTypeStruct { return &InterfaceTypeStruct{ Common{InterfaceKind, typestring, name, interfacesize}, field } } @@ -683,7 +684,7 @@ func (p *Parser) Chan(name string, tokstart, dir int) *StubType { } // Parse array of fields for struct, interface, and func arguments -func (p *Parser) Fields(sep, term string) *[]Field { +func (p *Parser) Fields(sep, term string) []Field { a := new([]Field, 10); nf := 0; for p.token != "" && p.token != term { @@ -715,7 +716,7 @@ func (p *Parser) Fields(sep, term string) *[]Field { } // A single type packaged as a field for a function return -func (p *Parser) OneField() *[]Field { +func (p *Parser) OneField() []Field { a := new([]Field, 1); a[0].name = ""; a[0].typ = p.Type(""); diff --git a/src/lib/reflect/value.go b/src/lib/reflect/value.go index ea02f066f6..473a308eeb 100644 --- a/src/lib/reflect/value.go +++ b/src/lib/reflect/value.go @@ -693,7 +693,7 @@ export type StructValue interface { type StructValueStruct struct { Common; - field *[]Value; + field []Value; } func (v *StructValueStruct) Len() int { @@ -850,7 +850,7 @@ export func CopyArray(dst ArrayValue, src ArrayValue, n int) { dstp := uintptr(dst.Elem(0).Addr()); srcp := uintptr(src.Elem(0).Addr()); end := uintptr(n)*uintptr(dt.Size()); - if dst.Type().Size() % 8 == 0 { + if end % 8 == 0 { for i := uintptr(0); i < end; i += 8{ di := Addr(dstp + i); si := Addr(srcp + i); |
