Commit d3d3accd authored by Robert Griesemer's avatar Robert Griesemer

gofmt-ify io, json, runtime, encoding

R=rsc
http://go/go-review/1017056
parent 441e775d
...@@ -21,14 +21,14 @@ var pairs = []testpair{ ...@@ -21,14 +21,14 @@ var pairs = []testpair{
// Wikipedia example // Wikipedia example
testpair{ testpair{
"Man is distinguished, not only by his reason, but by this singular passion from " "Man is distinguished, not only by his reason, but by this singular passion from "
"other animals, which is a lust of the mind, that by a perseverance of delight in " "other animals, which is a lust of the mind, that by a perseverance of delight in "
"the continued and indefatigable generation of knowledge, exceeds the short " "the continued and indefatigable generation of knowledge, exceeds the short "
"vehemence of any carnal pleasure.", "vehemence of any carnal pleasure.",
"9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,\n" "9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,\n"
"O<DJ+*.@<*K0@<6L(Df-\\0Ec5e;DffZ(EZee.Bl.9pF\"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKY\n" "O<DJ+*.@<*K0@<6L(Df-\\0Ec5e;DffZ(EZee.Bl.9pF\"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKY\n"
"i(DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIa\n" "i(DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIa\n"
"l(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G\n" "l(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G\n"
">uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c\n", ">uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c\n",
}, },
} }
......
...@@ -47,16 +47,16 @@ var gitPairs = []testpair{ ...@@ -47,16 +47,16 @@ var gitPairs = []testpair{
// Wikipedia example, adapted. // Wikipedia example, adapted.
testpair{ testpair{
"Man is distinguished, not only by his reason, but by this singular passion from " "Man is distinguished, not only by his reason, but by this singular passion from "
"other animals, which is a lust of the mind, that by a perseverance of delight in " "other animals, which is a lust of the mind, that by a perseverance of delight in "
"the continued and indefatigable generation of knowledge, exceeds the short " "the continued and indefatigable generation of knowledge, exceeds the short "
"vehemence of any carnal pleasure.", "vehemence of any carnal pleasure.",
"zO<`^zX>%ZCX>)XGZfA9Ab7*B`EFf-gbRchTY<VDJc_3(Mb0BhMVRLV8EFfZabRc4R\n" "zO<`^zX>%ZCX>)XGZfA9Ab7*B`EFf-gbRchTY<VDJc_3(Mb0BhMVRLV8EFfZabRc4R\n"
"zAarPHb0BkRZfA9DVR9gFVRLh7Z*CxFa&K)QZ**v7av))DX>DO_b1WctXlY|;AZc?T\n" "zAarPHb0BkRZfA9DVR9gFVRLh7Z*CxFa&K)QZ**v7av))DX>DO_b1WctXlY|;AZc?T\n"
"zVIXXEb95kYW*~HEWgu;7Ze%PVbZB98AYyqSVIXj2a&u*NWpZI|V`U(3W*}r`Y-wj`\n" "zVIXXEb95kYW*~HEWgu;7Ze%PVbZB98AYyqSVIXj2a&u*NWpZI|V`U(3W*}r`Y-wj`\n"
"zbRcPNAarPDAY*TCbZKsNWn>^>Ze$>7Ze(R<VRUI{VPb4$AZKN6WpZJ3X>V>IZ)PBC\n" "zbRcPNAarPDAY*TCbZKsNWn>^>Ze$>7Ze(R<VRUI{VPb4$AZKN6WpZJ3X>V>IZ)PBC\n"
"zZf|#NWn^b%EFfigV`XJzb0BnRWgv5CZ*p`Xc4cT~ZDnp_Wgu^6AYpEKAY);2ZeeU7\n" "zZf|#NWn^b%EFfigV`XJzb0BnRWgv5CZ*p`Xc4cT~ZDnp_Wgu^6AYpEKAY);2ZeeU7\n"
"IaBO8^b9HiME&u=k\n", "IaBO8^b9HiME&u=k\n",
}, },
} }
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
package io_test package io_test
import ( import (
"fmt"; "fmt";
. "io"; . "io";
"os"; "os";
"strings"; "strings";
"testing"; "testing";
"time"; "time";
) )
func checkWrite(t *testing.T, w Writer, data []byte, c chan int) { func checkWrite(t *testing.T, w Writer, data []byte, c chan int) {
......
...@@ -48,9 +48,15 @@ func WriteFile(filename string, data []byte, perm int) os.Error { ...@@ -48,9 +48,15 @@ func WriteFile(filename string, data []byte, perm int) os.Error {
// A dirList implements sort.Interface. // A dirList implements sort.Interface.
type dirList []*os.Dir type dirList []*os.Dir
func (d dirList) Len() int { return len(d); } func (d dirList) Len() int {
func (d dirList) Less(i, j int) bool { return d[i].Name < d[j].Name; } return len(d);
func (d dirList) Swap(i, j int) { d[i], d[j] = d[j], d[i]; } }
func (d dirList) Less(i, j int) bool {
return d[i].Name < d[j].Name;
}
func (d dirList) Swap(i, j int) {
d[i], d[j] = d[j], d[i];
}
// ReadDir reads the directory named by dirname and returns // ReadDir reads the directory named by dirname and returns
// a list of sorted directory entries. // a list of sorted directory entries.
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
package io_test package io_test
import ( import (
. "io"; . "io";
"os"; "os";
"strings"; "strings";
"testing"; "testing";
) )
func checkSize(t *testing.T, path string, size uint64) { func checkSize(t *testing.T, path string, size uint64) {
......
...@@ -13,11 +13,11 @@ import ( ...@@ -13,11 +13,11 @@ import (
) )
type structBuilder struct { type structBuilder struct {
val reflect.Value; val reflect.Value;
// if map_ != nil, write val to map_[key] on each change // if map_ != nil, write val to map_[key] on each change
map_ *reflect.MapValue; map_ *reflect.MapValue;
key reflect.Value; key reflect.Value;
} }
var nobuilder *structBuilder var nobuilder *structBuilder
...@@ -113,7 +113,8 @@ func (b *structBuilder) Float64(f float64) { ...@@ -113,7 +113,8 @@ func (b *structBuilder) Float64(f float64) {
} }
} }
func (b *structBuilder) Null() {} func (b *structBuilder) Null() {
}
func (b *structBuilder) String(s string) { func (b *structBuilder) String(s string) {
if b == nil { if b == nil {
......
...@@ -10,27 +10,27 @@ import ( ...@@ -10,27 +10,27 @@ import (
) )
type myStruct struct { type myStruct struct {
T bool; T bool;
F bool; F bool;
S string; S string;
I8 int8; I8 int8;
I16 int16; I16 int16;
I32 int32; I32 int32;
I64 int64; I64 int64;
U8 uint8; U8 uint8;
U16 uint16; U16 uint16;
U32 uint32; U32 uint32;
U64 uint64; U64 uint64;
I int; I int;
U uint; U uint;
Fl float; Fl float;
Fl32 float32; Fl32 float32;
Fl64 float64; Fl64 float64;
A []string; A []string;
My *myStruct; My *myStruct;
Map map[string][]int; Map map[string][]int;
MapStruct map[string]myStruct; MapStruct map[string]myStruct;
MapPtrStruct map[string]*myStruct; MapPtrStruct map[string]*myStruct;
} }
const encoded = `{"t":true,"f":false,"s":"abc","i8":1,"i16":2,"i32":3,"i64":4,` const encoded = `{"t":true,"f":false,"s":"abc","i8":1,"i16":2,"i32":3,"i64":4,`
...@@ -43,9 +43,9 @@ const encoded = `{"t":true,"f":false,"s":"abc","i8":1,"i16":2,"i32":3,"i64":4,` ...@@ -43,9 +43,9 @@ const encoded = `{"t":true,"f":false,"s":"abc","i8":1,"i16":2,"i32":3,"i64":4,`
`"mapptrstruct":{"m1":{"u8":8}}}` `"mapptrstruct":{"m1":{"u8":8}}}`
var decodedMap = map[string][]int{ var decodedMap = map[string][]int{
"k1": []int{1,2,3}, "k1": []int{1, 2, 3},
"k2": []int{}, "k2": []int{},
"k3": []int{3,4}, "k3": []int{3, 4},
} }
var decodedMapStruct = map[string]myStruct{ var decodedMapStruct = map[string]myStruct{
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
/* /*
The runtime package contains operations that interact with Go's runtime system, The runtime package contains operations that interact with Go's runtime system,
such as functions to control goroutines. such as functions to control goroutines.
*/ */
package runtime package runtime
// These functions are implemented in the base runtime library, ../../runtime/. // These functions are implemented in the base runtime library, ../../runtime/.
......
...@@ -21,28 +21,28 @@ import "unsafe" ...@@ -21,28 +21,28 @@ import "unsafe"
// compile time; non-empty interface values get created // compile time; non-empty interface values get created
// during initialization. Type is an empty interface // during initialization. Type is an empty interface
// so that the compiler can lay out references as data. // so that the compiler can lay out references as data.
type Type interface { } type Type interface{}
// All types begin with a few common fields needed for // All types begin with a few common fields needed for
// the interface runtime. // the interface runtime.
type commonType struct { type commonType struct {
size uintptr; // size in bytes size uintptr; // size in bytes
hash uint32; // hash of type; avoids computation in hash tables hash uint32; // hash of type; avoids computation in hash tables
alg uint8; // algorithm for copy+hash+cmp (../runtime/runtime.h:/AMEM) alg uint8; // algorithm for copy+hash+cmp (../runtime/runtime.h:/AMEM)
align uint8; // alignment of variable with this type align uint8; // alignment of variable with this type
fieldAlign uint8; // alignment of struct field with this type fieldAlign uint8; // alignment of struct field with this type
string *string; // string form; unnecessary but undeniably useful string *string; // string form; unnecessary but undeniably useful
*uncommonType; // (relatively) uncommon fields *uncommonType; // (relatively) uncommon fields
} }
// Method on non-interface type // Method on non-interface type
type method struct { type method struct {
hash uint32; // hash of name + pkg + typ hash uint32; // hash of name + pkg + typ
name *string; // name of method name *string; // name of method
pkgPath *string; // nil for exported Names; otherwise import path pkgPath *string; // nil for exported Names; otherwise import path
typ *Type; // .(*FuncType) underneath typ *Type; // .(*FuncType) underneath
ifn unsafe.Pointer; // fn used in interface call (one-word receiver) ifn unsafe.Pointer; // fn used in interface call (one-word receiver)
tfn unsafe.Pointer; // fn used for normal method call tfn unsafe.Pointer; // fn used for normal method call
} }
// uncommonType is present only for types with names or methods // uncommonType is present only for types with names or methods
...@@ -50,9 +50,9 @@ type method struct { ...@@ -50,9 +50,9 @@ type method struct {
// Using a pointer to this struct reduces the overall size required // Using a pointer to this struct reduces the overall size required
// to describe an unnamed type with no methods. // to describe an unnamed type with no methods.
type uncommonType struct { type uncommonType struct {
name *string; // name of type name *string; // name of type
pkgPath *string; // import path; nil for built-in types like int, string pkgPath *string; // import path; nil for built-in types like int, string
methods []method; // methods associated with type methods []method; // methods associated with type
} }
// BoolType represents a boolean type. // BoolType represents a boolean type.
...@@ -113,89 +113,90 @@ type UnsafePointerType commonType ...@@ -113,89 +113,90 @@ type UnsafePointerType commonType
// ArrayType represents a fixed array type. // ArrayType represents a fixed array type.
type ArrayType struct { type ArrayType struct {
commonType; commonType;
elem *Type; // array element type elem *Type; // array element type
len uintptr; len uintptr;
} }
// SliceType represents a slice type. // SliceType represents a slice type.
type SliceType struct { type SliceType struct {
commonType; commonType;
elem *Type; // slice element type elem *Type; // slice element type
} }
// ChanDir represents a channel type's direction. // ChanDir represents a channel type's direction.
type ChanDir int type ChanDir int
const ( const (
RecvDir ChanDir = 1<<iota; // <-chan RecvDir ChanDir = 1<<iota; // <-chan
SendDir; // chan<- SendDir; // chan<-
BothDir = RecvDir | SendDir; // chan BothDir = RecvDir|SendDir; // chan
) )
// ChanType represents a channel type. // ChanType represents a channel type.
type ChanType struct { type ChanType struct {
commonType; commonType;
elem *Type; // channel element type elem *Type; // channel element type
dir uintptr; // channel direction (ChanDir) dir uintptr; // channel direction (ChanDir)
} }
// FuncType represents a function type. // FuncType represents a function type.
type FuncType struct { type FuncType struct {
commonType; commonType;
in []*Type; // input parameter types in []*Type; // input parameter types
out []*Type; // output parameter types out []*Type; // output parameter types
} }
// Method on interface type // Method on interface type
type imethod struct { type imethod struct {
hash uint32; // hash of name + pkg + typ; same hash as method hash uint32; // hash of name + pkg + typ; same hash as method
perm uint32; // index of function pointer in interface map perm uint32; // index of function pointer in interface map
name *string; // name of method name *string; // name of method
pkgPath *string; // nil for exported Names; otherwise import path pkgPath *string; // nil for exported Names; otherwise import path
typ *Type; // .(*FuncType) underneath typ *Type; // .(*FuncType) underneath
} }
// InterfaceType represents an interface type. // InterfaceType represents an interface type.
type InterfaceType struct { type InterfaceType struct {
commonType; commonType;
methods []imethod; // sorted by hash methods []imethod; // sorted by hash
} }
// MapType represents a map type. // MapType represents a map type.
type MapType struct { type MapType struct {
commonType; commonType;
key *Type; // map key type key *Type; // map key type
elem *Type; // map element (value) type elem *Type; // map element (value) type
} }
// PtrType represents a pointer type. // PtrType represents a pointer type.
type PtrType struct { type PtrType struct {
commonType; commonType;
elem *Type; // pointer element (pointed at) type elem *Type; // pointer element (pointed at) type
} }
// Struct field // Struct field
type structField struct { type structField struct {
name *string; // nil for embedded fields name *string; // nil for embedded fields
pkgPath *string; // nil for exported Names; otherwise import path pkgPath *string; // nil for exported Names; otherwise import path
typ *Type; // type of field typ *Type; // type of field
tag *string; // nil if no tag tag *string; // nil if no tag
offset uintptr; // byte offset of field within struct offset uintptr; // byte offset of field within struct
} }
// StructType represents a struct type. // StructType represents a struct type.
type StructType struct { type StructType struct {
commonType; commonType;
fields []structField; // sorted by offset fields []structField; // sorted by offset
} }
/* /*
* Must match iface.c:/Itab and compilers. * Must match iface.c:/Itab and compilers.
*/ */
type Itable struct { type Itable struct {
Itype *Type; // (*tab.inter).(*InterfaceType) is the interface type Itype *Type; // (*tab.inter).(*InterfaceType) is the interface type
Type *Type; Type *Type;
link *Itable; link *Itable;
bad int32; bad int32;
unused int32; unused int32;
Fn [100000]uintptr; // bigger than we'll ever see Fn [100000]uintptr; // bigger than we'll ever see
} }
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