Commit 77334b98 authored by Robert Griesemer's avatar Robert Griesemer

gofmt-ify reflect

- the single line structs can be fixed in another round

R=rsc
http://go/go-review/1016052
parent 666afa1c
This diff is collapsed.
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
const ptrSize = uintptr(unsafe.Sizeof((*byte)(nil))) const ptrSize = uintptr(unsafe.Sizeof((*byte)(nil)))
const cannotSet = "cannot set value obtained via unexported struct field" const cannotSet = "cannot set value obtained via unexported struct field"
type addr unsafe.Pointer type addr unsafe.Pointer
// TODO: This will have to go away when // TODO: This will have to go away when
...@@ -26,7 +27,7 @@ func memmove(adst, asrc addr, n uintptr) { ...@@ -26,7 +27,7 @@ func memmove(adst, asrc addr, n uintptr) {
i--; i--;
*(*byte)(addr(dst+i)) = *(*byte)(addr(src+i)); *(*byte)(addr(dst+i)) = *(*byte)(addr(src+i));
} }
case (n|src|dst) & (ptrSize-1) != 0: case (n|src|dst)&(ptrSize-1) != 0:
// byte copy forward // byte copy forward
for i := uintptr(0); i < n; i++ { for i := uintptr(0); i < n; i++ {
*(*byte)(addr(dst+i)) = *(*byte)(addr(src+i)); *(*byte)(addr(dst+i)) = *(*byte)(addr(src+i));
...@@ -80,7 +81,7 @@ type value struct { ...@@ -80,7 +81,7 @@ type value struct {
} }
func (v *value) Type() Type { func (v *value) Type() Type {
return v.typ return v.typ;
} }
func (v *value) Addr() uintptr { func (v *value) Addr() uintptr {
...@@ -99,10 +100,12 @@ func (v *value) Interface() interface{} { ...@@ -99,10 +100,12 @@ func (v *value) Interface() interface{} {
// to extract correctly. // to extract correctly.
if typ.NumMethod() == 0 { if typ.NumMethod() == 0 {
// Extract as interface value without methods. // Extract as interface value without methods.
return *(*interface{})(v.addr) return *(*interface{})(v.addr);
} }
// Extract from v.addr as interface value with methods. // Extract from v.addr as interface value with methods.
return *(*interface{ m() })(v.addr) return *(*interface {
m();
})(v.addr);
} }
return unsafe.Unreflect(v.typ, unsafe.Pointer(v.addr)); return unsafe.Unreflect(v.typ, unsafe.Pointer(v.addr));
} }
...@@ -549,7 +552,7 @@ func ArrayCopy(dst, src ArrayOrSliceValue) int { ...@@ -549,7 +552,7 @@ func ArrayCopy(dst, src ArrayOrSliceValue) int {
// An ArrayValue represents an array. // An ArrayValue represents an array.
type ArrayValue struct { type ArrayValue struct {
value value;
} }
// Len returns the length of the array. // Len returns the length of the array.
...@@ -589,7 +592,7 @@ func (v *ArrayValue) Elem(i int) Value { ...@@ -589,7 +592,7 @@ func (v *ArrayValue) Elem(i int) Value {
if i < 0 || i >= n { if i < 0 || i >= n {
panic("index", i, "in array len", n); panic("index", i, "in array len", n);
} }
p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size()); p := addr(uintptr(v.addr()) + uintptr(i) * typ.Size());
return newValue(typ, p, v.canSet); return newValue(typ, p, v.canSet);
} }
...@@ -606,7 +609,7 @@ type SliceHeader struct { ...@@ -606,7 +609,7 @@ type SliceHeader struct {
// A SliceValue represents a slice. // A SliceValue represents a slice.
type SliceValue struct { type SliceValue struct {
value value;
} }
func (v *SliceValue) slice() *SliceHeader { func (v *SliceValue) slice() *SliceHeader {
...@@ -667,8 +670,8 @@ func (v *SliceValue) Slice(beg, end int) *SliceValue { ...@@ -667,8 +670,8 @@ func (v *SliceValue) Slice(beg, end int) *SliceValue {
typ := v.typ.(*SliceType); typ := v.typ.(*SliceType);
s := new(SliceHeader); s := new(SliceHeader);
s.Data = uintptr(v.addr()) + uintptr(beg) * typ.Elem().Size(); s.Data = uintptr(v.addr()) + uintptr(beg) * typ.Elem().Size();
s.Len = end - beg; s.Len = end-beg;
s.Cap = cap - beg; s.Cap = cap-beg;
return newValue(typ, addr(s), v.canSet).(*SliceValue); return newValue(typ, addr(s), v.canSet).(*SliceValue);
} }
...@@ -679,7 +682,7 @@ func (v *SliceValue) Elem(i int) Value { ...@@ -679,7 +682,7 @@ func (v *SliceValue) Elem(i int) Value {
if i < 0 || i >= n { if i < 0 || i >= n {
panicln("index", i, "in array of length", n); panicln("index", i, "in array of length", n);
} }
p := addr(uintptr(v.addr()) + uintptr(i)*typ.Size()); p := addr(uintptr(v.addr()) + uintptr(i) * typ.Size());
return newValue(typ, p, v.canSet); return newValue(typ, p, v.canSet);
} }
...@@ -704,7 +707,7 @@ func MakeSlice(typ *SliceType, len, cap int) *SliceValue { ...@@ -704,7 +707,7 @@ func MakeSlice(typ *SliceType, len, cap int) *SliceValue {
// A ChanValue represents a chan. // A ChanValue represents a chan.
type ChanValue struct { type ChanValue struct {
value value;
} }
// IsNil returns whether v is a nil channel. // IsNil returns whether v is a nil channel.
...@@ -767,7 +770,7 @@ func (v *ChanValue) Cap() int { ...@@ -767,7 +770,7 @@ func (v *ChanValue) Cap() int {
// internal send; non-blocking if b != nil // internal send; non-blocking if b != nil
func (v *ChanValue) send(x Value, b *bool) { func (v *ChanValue) send(x Value, b *bool) {
t := v.Type().(*ChanType); t := v.Type().(*ChanType);
if t.Dir() & SendDir == 0{ if t.Dir() & SendDir == 0 {
panic("send on recv-only channel"); panic("send on recv-only channel");
} }
typesMustMatch(t.Elem(), x.Type()); typesMustMatch(t.Elem(), x.Type());
...@@ -884,7 +887,9 @@ func (v *value) Method(i int) *FuncValue { ...@@ -884,7 +887,9 @@ func (v *value) Method(i int) *FuncValue {
// implemented in ../pkg/runtime/*/asm.s // implemented in ../pkg/runtime/*/asm.s
func call(fn, arg *byte, n uint32) func call(fn, arg *byte, n uint32)
type tiny struct { b byte } type tiny struct {
b byte;
}
// Call calls the function v with input parameters in. // Call calls the function v with input parameters in.
// It returns the function's output parameters as Values. // It returns the function's output parameters as Values.
...@@ -913,14 +918,14 @@ func (fv *FuncValue) Call(in []Value) []Value { ...@@ -913,14 +918,14 @@ func (fv *FuncValue) Call(in []Value) []Value {
for i := 0; i < nin; i++ { for i := 0; i < nin; i++ {
tv := t.In(i); tv := t.In(i);
a := uintptr(tv.Align()); a := uintptr(tv.Align());
size = (size + a - 1) &^ (a - 1); size = (size+a-1)&^(a-1);
size += tv.Size(); size += tv.Size();
} }
size = (size + structAlign - 1) &^ (structAlign - 1); size = (size + structAlign - 1)&^(structAlign - 1);
for i := 0; i < nout; i++ { for i := 0; i < nout; i++ {
tv := t.Out(i); tv := t.Out(i);
a := uintptr(tv.Align()); a := uintptr(tv.Align());
size = (size + a - 1) &^ (a - 1); size = (size+a-1)&^(a-1);
size += tv.Size(); size += tv.Size();
} }
...@@ -961,12 +966,12 @@ func (fv *FuncValue) Call(in []Value) []Value { ...@@ -961,12 +966,12 @@ func (fv *FuncValue) Call(in []Value) []Value {
tv := v.Type(); tv := v.Type();
typesMustMatch(t.In(i+delta), tv); typesMustMatch(t.In(i+delta), tv);
a := uintptr(tv.Align()); a := uintptr(tv.Align());
off = (off + a - 1) &^ (a - 1); off = (off+a-1)&^(a-1);
n := tv.Size(); n := tv.Size();
memmove(addr(ptr+off), v.getAddr(), n); memmove(addr(ptr+off), v.getAddr(), n);
off += n; off += n;
} }
off = (off + structAlign - 1) &^ (structAlign - 1); off = (off + structAlign - 1)&^(structAlign - 1);
// Call // Call
call(*(**byte)(fv.addr), (*byte)(addr(ptr)), uint32(size)); call(*(**byte)(fv.addr), (*byte)(addr(ptr)), uint32(size));
...@@ -978,7 +983,7 @@ func (fv *FuncValue) Call(in []Value) []Value { ...@@ -978,7 +983,7 @@ func (fv *FuncValue) Call(in []Value) []Value {
for i := 0; i < nout; i++ { for i := 0; i < nout; i++ {
tv := t.Out(i); tv := t.Out(i);
a := uintptr(tv.Align()); a := uintptr(tv.Align());
off = (off + a - 1) &^ (a - 1); off = (off+a-1)&^(a-1);
v := MakeZero(tv); v := MakeZero(tv);
n := tv.Size(); n := tv.Size();
memmove(v.getAddr(), addr(ptr+off), n); memmove(v.getAddr(), addr(ptr+off), n);
...@@ -995,7 +1000,7 @@ func (fv *FuncValue) Call(in []Value) []Value { ...@@ -995,7 +1000,7 @@ func (fv *FuncValue) Call(in []Value) []Value {
// An InterfaceValue represents an interface value. // An InterfaceValue represents an interface value.
type InterfaceValue struct { type InterfaceValue struct {
value value;
} }
// No Get because v.Interface() is available. // No Get because v.Interface() is available.
...@@ -1063,7 +1068,7 @@ func (v *InterfaceValue) Method(i int) *FuncValue { ...@@ -1063,7 +1068,7 @@ func (v *InterfaceValue) Method(i int) *FuncValue {
// A MapValue represents a map value. // A MapValue represents a map value.
type MapValue struct { type MapValue struct {
value value;
} }
// IsNil returns whether v is a nil map value. // IsNil returns whether v is a nil map value.
...@@ -1141,7 +1146,7 @@ func (v *MapValue) Keys() []Value { ...@@ -1141,7 +1146,7 @@ func (v *MapValue) Keys() []Value {
m := *(**byte)(v.addr); m := *(**byte)(v.addr);
mlen := int32(0); mlen := int32(0);
if m != nil { if m != nil {
mlen = maplen(m) mlen = maplen(m);
} }
it := mapiterinit(m); it := mapiterinit(m);
a := make([]Value, mlen); a := make([]Value, mlen);
...@@ -1170,7 +1175,7 @@ func MakeMap(typ *MapType) *MapValue { ...@@ -1170,7 +1175,7 @@ func MakeMap(typ *MapType) *MapValue {
// A PtrValue represents a pointer. // A PtrValue represents a pointer.
type PtrValue struct { type PtrValue struct {
value value;
} }
// IsNil returns whether v is a nil pointer. // IsNil returns whether v is a nil pointer.
...@@ -1237,7 +1242,7 @@ func Indirect(v Value) Value { ...@@ -1237,7 +1242,7 @@ func Indirect(v Value) Value {
// A StructValue represents a struct value. // A StructValue represents a struct value.
type StructValue struct { type StructValue struct {
value value;
} }
// Set assigns x to v. // Set assigns x to v.
...@@ -1264,7 +1269,7 @@ func (v *StructValue) Field(i int) Value { ...@@ -1264,7 +1269,7 @@ func (v *StructValue) Field(i int) Value {
return nil; return nil;
} }
f := t.Field(i); f := t.Field(i);
return newValue(f.Type, addr(uintptr(v.addr)+f.Offset), v.canSet && f.PkgPath == ""); return newValue(f.Type, addr(uintptr(v.addr) + f.Offset), v.canSet && f.PkgPath == "");
} }
// FieldByIndex returns the nested field corresponding to index. // FieldByIndex returns the nested field corresponding to index.
...@@ -1329,7 +1334,9 @@ func newValue(typ Type, addr addr, canSet bool) Value { ...@@ -1329,7 +1334,9 @@ func newValue(typ Type, addr addr, canSet bool) Value {
// All values have same memory layout; // All values have same memory layout;
// build once and convert. // build once and convert.
v := &struct{value}{value{typ, addr, canSet}}; v := &struct {
value;
}{value{typ, addr, canSet}};
switch typ.(type) { switch typ.(type) {
case *ArrayType: case *ArrayType:
// TODO(rsc): Something must prevent // TODO(rsc): Something must prevent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment