summaryrefslogtreecommitdiff
path: root/src/pkg/reflect
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/reflect')
-rw-r--r--src/pkg/reflect/deepequal.go14
-rw-r--r--src/pkg/reflect/tostring_test.go12
-rw-r--r--src/pkg/reflect/type.go164
3 files changed, 94 insertions, 96 deletions
diff --git a/src/pkg/reflect/deepequal.go b/src/pkg/reflect/deepequal.go
index 3c5663aea..9d1d14c89 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
@@ -23,7 +23,7 @@ type visit struct {
// recursive types.
func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
if v1 == nil || v2 == nil {
- return v1 == v2
+ return v1 == v2;
}
if v1.Type() != v2.Type() {
return false;
@@ -44,7 +44,7 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
}
// ... or already seen
- h := 17 * addr1 + addr2;
+ h := 17*addr1 + addr2;
seen, _ := visited[h];
typ := v1.Type();
for p := seen; p != nil; p = p.next {
@@ -93,7 +93,7 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
case *StructValue:
struct1 := v;
struct2 := v2.(*StructValue);
- for i, n:= 0, v.NumField(); i < n; i++ {
+ for i, n := 0, v.NumField(); i < n; i++ {
if !deepValueEqual(struct1.Field(i), struct2.Field(i), visited, depth+1) {
return false;
}
diff --git a/src/pkg/reflect/tostring_test.go b/src/pkg/reflect/tostring_test.go
index eeac5a028..334f8420c 100644
--- a/src/pkg/reflect/tostring_test.go
+++ b/src/pkg/reflect/tostring_test.go
@@ -9,8 +9,8 @@
package reflect_test
import (
- . "reflect";
- "strconv";
+ . "reflect";
+ "strconv";
)
// valueToString returns a textual representation of the reflection value val.
@@ -56,9 +56,9 @@ func valueToString(val Value) string {
return val.Get();
case *BoolValue:
if val.Get() {
- return "true"
+ return "true";
} else {
- return "false"
+ return "false";
}
case *PtrValue:
v := val;
@@ -76,7 +76,7 @@ func valueToString(val Value) string {
str += "{";
for i := 0; i < v.Len(); i++ {
if i > 0 {
- str += ", "
+ str += ", ";
}
str += valueToString(v.Elem(i));
}
@@ -99,7 +99,7 @@ func valueToString(val Value) string {
str += "{";
for i, n := 0, v.NumField(); i < n; i++ {
if i > 0 {
- str += ", "
+ str += ", ";
}
str += valueToString(v.Field(i));
}
diff --git a/src/pkg/reflect/type.go b/src/pkg/reflect/type.go
index 246628752..66e51c2f5 100644
--- a/src/pkg/reflect/type.go
+++ b/src/pkg/reflect/type.go
@@ -24,197 +24,198 @@ import (
*/
type commonType struct {
- size uintptr;
- hash uint32;
- alg uint8;
- align uint8;
- fieldAlign uint8;
- string *string;
+ 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;
+ elem *runtime.Type;
+ len uintptr;
}
// ChanDir represents a channel type's direction.
type ChanDir int
+
const (
- RecvDir ChanDir = 1<<iota;
+ RecvDir ChanDir = 1<<iota;
SendDir;
- BothDir = RecvDir | SendDir;
+ BothDir = RecvDir|SendDir;
)
// ChanType represents a channel type.
type ChanType struct {
commonType;
- elem *runtime.Type;
- dir uintptr;
+ elem *runtime.Type;
+ dir uintptr;
}
// FuncType represents a function type.
type FuncType struct {
commonType;
- in []*runtime.Type;
- out []*runtime.Type;
+ 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;
+ methods []imethod;
}
// MapType represents a map type.
type MapType struct {
commonType;
- key *runtime.Type;
- elem *runtime.Type;
+ key *runtime.Type;
+ elem *runtime.Type;
}
// PtrType represents a pointer type.
type PtrType struct {
commonType;
- elem *runtime.Type;
+ elem *runtime.Type;
}
// SliceType represents a slice type.
type SliceType struct {
commonType;
- elem *runtime.Type;
+ 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;
+ fields []structField;
}
@@ -225,10 +226,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.
@@ -240,36 +241,35 @@ type Method struct {
type Type interface {
// PkgPath returns the type's package path.
// The package path is a full package import path like "container/vector".
- PkgPath() string;
+ PkgPath() string;
// Name returns the type's name within its package.
- 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;
-
+ Method(int) Method;
+ NumMethod() int;
uncommon() *uncommonType;
}
@@ -279,7 +279,7 @@ func (t *uncommonType) uncommon() *uncommonType {
func (t *uncommonType) PkgPath() string {
if t == nil || t.pkgPath == nil {
- return ""
+ return "";
}
return *t.pkgPath;
}
@@ -448,13 +448,13 @@ func (t *SliceType) Elem() Type {
}
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.
@@ -509,7 +509,7 @@ func (t *StructType) FieldByIndex(index []int) (f StructField) {
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
@@ -521,7 +521,7 @@ func (t *StructType) fieldByName(name string, mark map[*StructType]bool, depth i
mark[t] = true;
var fi int; // field index
- n := 0; // number of matching fields at depth fd
+ n := 0; // number of matching fields at depth fd
L: for i, _ := range t.fields {
f := t.Field(i);
d := inf;
@@ -584,7 +584,7 @@ func (t *StructType) FieldByName(name string) (f StructField, present bool) {
ff.Index = ff.Index[0 : fd+1];
f, present = ff, true;
}
- return
+ return;
}
// NumField returns the number of struct fields.
@@ -663,5 +663,3 @@ type ArrayOrSliceType interface {
func Typeof(i interface{}) Type {
return toType(unsafe.Typeof(i));
}
-
-