1
0
mirror of https://github.com/golang/go synced 2024-10-04 14:31:21 -06:00
Commit Graph

9 Commits

Author SHA1 Message Date
Russ Cox
fb175cf77e reflect: new Type and Value definitions
Type is now an interface that implements all the possible type methods.
Instead of a type switch on a reflect.Type t, switch on t.Kind().
If a method is invoked on the wrong kind of type (for example,
calling t.Field(0) when t.Kind() != Struct), the call panics.

There is one method renaming: t.(*ChanType).Dir() is now t.ChanDir().

Value is now a struct value that implements all the possible value methods.
Instead of a type switch on a reflect.Value v, switch on v.Kind().
If a method is invoked on the wrong kind of value (for example,
calling t.Recv() when t.Kind() != Chan), the call panics.

Since Value is now a struct, not an interface, its zero value
cannot be compared to nil.  Instead of v != nil, use v.IsValid().
Instead of other uses of nil as a Value, use Value{}, the zero value.

Many methods have been renamed, most due to signature conflicts:

           OLD                          NEW

    v.(*ArrayValue).Elem             v.Index
    v.(*BoolValue).Get               v.Bool
    v.(*BoolValue).Set               v.SetBool
    v.(*ChanType).Dir                v.ChanDir
    v.(*ChanValue).Get               v.Pointer
    v.(*ComplexValue).Get            v.Complex
    v.(*ComplexValue).Overflow       v.OverflowComplex
    v.(*ComplexValue).Set            v.SetComplex
    v.(*FloatValue).Get              v.Float
    v.(*FloatValue).Overflow         v.OverflowFloat
    v.(*FloatValue).Set              v.SetFloat
    v.(*FuncValue).Get               v.Pointer
    v.(*InterfaceValue).Get          v.InterfaceData
    v.(*IntValue).Get                v.Int
    v.(*IntValue).Overflow           v.OverflowInt
    v.(*IntValue).Set                v.SetInt
    v.(*MapValue).Elem               v.MapIndex
    v.(*MapValue).Get                v.Pointer
    v.(*MapValue).Keys               v.MapKeys
    v.(*MapValue).SetElem            v.SetMapIndex
    v.(*PtrValue).Get                v.Pointer
    v.(*SliceValue).Elem             v.Index
    v.(*SliceValue).Get              v.Pointer
    v.(*StringValue).Get             v.String
    v.(*StringValue).Set             v.SetString
    v.(*UintValue).Get               v.Uint
    v.(*UintValue).Overflow          v.OverflowUint
    v.(*UintValue).Set               v.SetUint
    v.(*UnsafePointerValue).Get      v.Pointer
    v.(*UnsafePointerValue).Set      v.SetPointer

Part of the motivation for this change is to enable a more
efficient implementation of Value, one that does not allocate
memory during most operations.  To reduce the size of the CL,
this CL's implementation is a wrapper around the old API.
Later CLs will make the implementation more efficient without
changing the API.

Other CLs to be submitted at the same time as this one
add support for this change to gofix (4343047) and update
the Go source tree (4353043).

R=gri, iant, niemeyer, r, rog, gustavo, r2
CC=golang-dev
https://golang.org/cl/4281055
2011-04-08 12:26:51 -04:00
Russ Cox
45bdf0367e reflect: add Kind, remove Int8Type, Int8Value, etc.
update other code to match.

R=r
CC=golang-dev
https://golang.org/cl/1680044
2010-06-20 12:16:25 -07:00
Rob Pike
325cf8ef21 delete all uses of panicln by rewriting them using panic or,
in the tests, println+panic.
gofmt some tests too.

R=rsc
CC=golang-dev
https://golang.org/cl/741041
2010-03-24 16:46:53 -07:00
Robert Griesemer
d65a5cce89 1) Change default gofmt default settings for
parsing and printing to new syntax.

   Use -oldparser to parse the old syntax,
   use -oldprinter to print the old syntax.

2) Change default gofmt formatting settings
   to use tabs for indentation only and to use
   spaces for alignment. This will make the code
   alignment insensitive to an editor's tabwidth.

   Use -spaces=false to use tabs for alignment.

3) Manually changed src/exp/parser/parser_test.go
   so that it doesn't try to parse the parser's
   source files using the old syntax (they have
   new syntax now).

4) gofmt -w src misc test/bench

4th set of files.

R=rsc
CC=golang-dev
https://golang.org/cl/180049
2009-12-15 15:40:16 -08:00
Robert Griesemer
40621d5c0d remove semis after statements in one-statement statement lists
R=rsc, r
http://go/go-review/1025029
2009-11-09 12:07:39 -08:00
Robert Griesemer
77334b988c gofmt-ify reflect
- the single line structs can be fixed in another round

R=rsc
http://go/go-review/1016052
2009-11-05 14:23:20 -08:00
Russ Cox
91549438d8 apply gofmt to rand reflect regexp rpc runtime sort strconv strings sync syscall testing time unicode unsafe utf8
R=gri
DELTA=1409  (79 added, 24 deleted, 1306 changed)
OCL=35415
CL=35437
2009-10-07 11:55:06 -07:00
Russ Cox
28eba4877b fix "declared and not used" errors in non-test code.
R=r
DELTA=112  (6 added, 57 deleted, 49 changed)
OCL=34610
CL=34610
2009-09-14 17:20:29 -07:00
Russ Cox
3b864e4195 convert low-level (used by testing) packages to
whole-package compilation.  new Makefiles,
tests now in separate package

	bytes
	flag
	fmt
	io
	math
	once
	os
	reflect
	strconv
	sync
	time
	utf8

delete import "xxx" in package xxx.

inside package xxx, xxx is not declared
anymore so s/xxx.//g

delete file and package level forward declarations.

note the new internal_test.go and sync
and strconv to provide public access to
internals during testing.  the installed version
of the package omits that file and thus does
not open the internals to all clients.

R=r
OCL=33065
CL=33097
2009-08-12 13:18:37 -07:00