Commit 4c006182 authored by Russ Cox's avatar Russ Cox

pkg: manual cleanup of some gofixed code

R=golang-dev, niemeyer, r
CC=golang-dev
https://golang.org/cl/4372052
parent 017e73c1
......@@ -467,7 +467,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
// Deal with the ANY type.
if ifaceType := fieldType; ifaceType.Kind() == reflect.Interface && ifaceType.NumMethod() == 0 {
ifaceValue := v
var t tagAndLength
t, offset, err = parseTagAndLength(bytes, offset)
if err != nil {
......@@ -506,7 +505,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
return
}
if result != nil {
ifaceValue.Set(reflect.NewValue(result))
v.Set(reflect.NewValue(result))
}
return
}
......@@ -536,9 +535,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
err = StructuralError{"Zero length explicit tag was not an asn1.Flag"}
return
}
flagValue := v
flagValue.SetBool(true)
v.SetBool(true)
return
}
} else {
......@@ -606,23 +603,20 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
switch fieldType {
case objectIdentifierType:
newSlice, err1 := parseObjectIdentifier(innerBytes)
sliceValue := v
sliceValue.Set(reflect.MakeSlice(sliceValue.Type(), len(newSlice), len(newSlice)))
v.Set(reflect.MakeSlice(v.Type(), len(newSlice), len(newSlice)))
if err1 == nil {
reflect.Copy(sliceValue, reflect.NewValue(newSlice))
reflect.Copy(v, reflect.NewValue(newSlice))
}
err = err1
return
case bitStringType:
structValue := v
bs, err1 := parseBitString(innerBytes)
if err1 == nil {
structValue.Set(reflect.NewValue(bs))
v.Set(reflect.NewValue(bs))
}
err = err1
return
case timeType:
ptrValue := v
var time *time.Time
var err1 os.Error
if universalTag == tagUTCTime {
......@@ -631,21 +625,19 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
time, err1 = parseGeneralizedTime(innerBytes)
}
if err1 == nil {
ptrValue.Set(reflect.NewValue(time))
v.Set(reflect.NewValue(time))
}
err = err1
return
case enumeratedType:
parsedInt, err1 := parseInt(innerBytes)
enumValue := v
if err1 == nil {
enumValue.SetInt(int64(parsedInt))
v.SetInt(int64(parsedInt))
}
err = err1
return
case flagType:
flagValue := v
flagValue.SetBool(true)
v.SetBool(true)
return
}
switch val := v; val.Kind() {
......
......@@ -168,18 +168,18 @@ func Write(w io.Writer, order ByteOrder, data interface{}) os.Error {
}
func TotalSize(v reflect.Value) int {
if sv := v; sv.Kind() == reflect.Slice {
if v.Kind() == reflect.Slice {
elem := sizeof(v.Type().Elem())
if elem < 0 {
return -1
}
return sv.Len() * elem
return v.Len() * elem
}
return sizeof(v.Type())
}
func sizeof(v reflect.Type) int {
switch t := v; t.Kind() {
func sizeof(t reflect.Type) int {
switch t.Kind() {
case reflect.Array:
n := sizeof(t.Elem())
if n < 0 {
......@@ -198,12 +198,10 @@ func sizeof(v reflect.Type) int {
}
return sum
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:
switch t := t.Kind(); t {
case reflect.Int, reflect.Uint, reflect.Uintptr:
return -1
}
return int(v.Size())
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:
return int(t.Size())
}
return -1
}
......@@ -297,8 +295,6 @@ func (d *decoder) value(v reflect.Value) {
d.value(v.Index(i))
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
switch v.Type().Kind() {
case reflect.Int8:
v.SetInt(int64(d.int8()))
case reflect.Int16:
......@@ -307,10 +303,7 @@ func (d *decoder) value(v reflect.Value) {
v.SetInt(int64(d.int32()))
case reflect.Int64:
v.SetInt(d.int64())
}
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
switch v.Type().Kind() {
case reflect.Uint8:
v.SetUint(uint64(d.uint8()))
case reflect.Uint16:
......@@ -319,18 +312,12 @@ func (d *decoder) value(v reflect.Value) {
v.SetUint(uint64(d.uint32()))
case reflect.Uint64:
v.SetUint(d.uint64())
}
case reflect.Float32, reflect.Float64:
switch v.Type().Kind() {
case reflect.Float32:
v.SetFloat(float64(math.Float32frombits(d.uint32())))
case reflect.Float64:
v.SetFloat(math.Float64frombits(d.uint64()))
}
case reflect.Complex64, reflect.Complex128:
switch v.Type().Kind() {
case reflect.Complex64:
v.SetComplex(complex(
float64(math.Float32frombits(d.uint32())),
......@@ -342,7 +329,6 @@ func (d *decoder) value(v reflect.Value) {
math.Float64frombits(d.uint64()),
))
}
}
}
func (e *encoder) value(v reflect.Value) {
......
......@@ -37,15 +37,12 @@ func TypeFromNative(t reflect.Type) Type {
switch t.Kind() {
case reflect.Bool:
et = BoolType
case reflect.Float32, reflect.Float64:
switch t.Kind() {
case reflect.Float32:
et = Float32Type
case reflect.Float64:
et = Float64Type
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
switch t.Kind() {
case reflect.Int16:
et = Int16Type
case reflect.Int32:
......@@ -56,9 +53,7 @@ func TypeFromNative(t reflect.Type) Type {
et = Int8Type
case reflect.Int:
et = IntType
}
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
switch t.Kind() {
case reflect.Uint16:
et = Uint16Type
case reflect.Uint32:
......@@ -71,7 +66,7 @@ func TypeFromNative(t reflect.Type) Type {
et = UintType
case reflect.Uintptr:
et = UintptrType
}
case reflect.String:
et = StringType
case reflect.Array:
......
......@@ -400,15 +400,11 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
return len(msg), false
case reflect.Struct:
off, ok = packStructValue(fv, msg, off)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
i := fv.Uint()
switch fv.Type().Kind() {
default:
goto BadType
case reflect.Uint16:
if off+2 > len(msg) {
return len(msg), false
}
i := fv.Uint()
msg[off] = byte(i >> 8)
msg[off+1] = byte(i)
off += 2
......@@ -416,12 +412,12 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
if off+4 > len(msg) {
return len(msg), false
}
i := fv.Uint()
msg[off] = byte(i >> 24)
msg[off+1] = byte(i >> 16)
msg[off+2] = byte(i >> 8)
msg[off+3] = byte(i)
off += 4
}
case reflect.Array:
if fv.Type().Elem().Kind() != reflect.Uint8 {
goto BadType
......@@ -481,10 +477,6 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
return len(msg), false
case reflect.Struct:
off, ok = unpackStructValue(fv, msg, off)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
switch fv.Type().Kind() {
default:
goto BadType
case reflect.Uint16:
if off+2 > len(msg) {
return len(msg), false
......@@ -499,7 +491,6 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
i := uint32(msg[off])<<24 | uint32(msg[off+1])<<16 | uint32(msg[off+2])<<8 | uint32(msg[off+3])
fv.SetUint(uint64(i))
off += 4
}
case reflect.Array:
if fv.Type().Elem().Kind() != reflect.Uint8 {
goto BadType
......
......@@ -60,8 +60,6 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) {
switch concrete := t; concrete.Kind() {
case reflect.Bool:
return reflect.NewValue(rand.Int()&1 == 0), true
case reflect.Float32, reflect.Float64, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Complex64, reflect.Complex128:
switch t.Kind() {
case reflect.Float32:
return reflect.NewValue(randFloat32(rand)), true
case reflect.Float64:
......@@ -92,7 +90,6 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) {
return reflect.NewValue(uint(randInt64(rand))), true
case reflect.Uintptr:
return reflect.NewValue(uintptr(randInt64(rand))), true
}
case reflect.Map:
numElems := rand.Intn(complexSize)
m := reflect.MakeMap(concrete)
......
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