diff options
213 files changed, 1297 insertions, 3670 deletions
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index d2c74e119..9087c9197 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -580,9 +580,7 @@ func (c *typeConv) FuncType(dtype *dwarf.FuncType) *FuncType { } // Identifier -func (c *typeConv) Ident(s string) *ast.Ident { - return &ast.Ident{Value: s}; -} +func (c *typeConv) Ident(s string) *ast.Ident { return &ast.Ident{Value: s} } // Opaque type of n bytes. func (c *typeConv) Opaque(n int64) ast.Expr { diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 0b67e2453..c80170478 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -16,9 +16,7 @@ import ( "os"; ) -func usage() { - fmt.Fprint(os.Stderr, "usage: cgo [compiler options] file.go\n"); -} +func usage() { fmt.Fprint(os.Stderr, "usage: cgo [compiler options] file.go\n") } var ptrSizeMap = map[string]int64{ "386": 4, diff --git a/src/cmd/godoc/index.go b/src/cmd/godoc/index.go index 9db87a7d4..47da83396 100644 --- a/src/cmd/godoc/index.go +++ b/src/cmd/godoc/index.go @@ -50,9 +50,7 @@ type RunList struct { less func(x, y interface{}) bool; } -func (h *RunList) Less(i, j int) bool { - return h.less(h.At(i), h.At(j)); -} +func (h *RunList) Less(i, j int) bool { return h.less(h.At(i), h.At(j)) } func (h *RunList) sort(less func(x, y interface{}) bool) { @@ -142,24 +140,16 @@ func makeSpotInfo(kind SpotKind, lori int, isIndex bool) SpotInfo { } -func (x SpotInfo) less(y SpotInfo) bool { - return x.Lori() < y.Lori(); -} +func (x SpotInfo) less(y SpotInfo) bool { return x.Lori() < y.Lori() } -func (x SpotInfo) Kind() SpotKind { - return SpotKind(x>>1&7); -} +func (x SpotInfo) Kind() SpotKind { return SpotKind(x>>1&7) } -func (x SpotInfo) Lori() int { - return int(x>>4); -} +func (x SpotInfo) Lori() int { return int(x>>4) } -func (x SpotInfo) IsIndex() bool { - return x&1 != 0; -} +func (x SpotInfo) IsIndex() bool { return x&1 != 0 } // A Pak describes a Go package. @@ -182,9 +172,7 @@ type File struct { } -func (f *File) less(g *File) bool { - return f.Path < g.Path; -} +func (f *File) less(g *File) bool { return f.Path < g.Path } // A Spot describes a single occurence of a word. @@ -195,9 +183,7 @@ type Spot struct { // Spots are sorted by filename. -func lessSpot(x, y interface{}) bool { - return x.(Spot).File.less(y.(Spot).File); -} +func lessSpot(x, y interface{}) bool { return x.(Spot).File.less(y.(Spot).File) } // A FileRun describes a run of Spots of a word in a single file. @@ -207,15 +193,9 @@ type FileRun struct { } -func (f *FileRun) Len() int { - return len(f.Infos); -} -func (f *FileRun) Less(i, j int) bool { - return f.Infos[i].less(f.Infos[j]); -} -func (f *FileRun) Swap(i, j int) { - f.Infos[i], f.Infos[j] = f.Infos[j], f.Infos[i]; -} +func (f *FileRun) Len() int { return len(f.Infos) } +func (f *FileRun) Less(i, j int) bool { return f.Infos[i].less(f.Infos[j]) } +func (f *FileRun) Swap(i, j int) { f.Infos[i], f.Infos[j] = f.Infos[j], f.Infos[i] } // newFileRun allocates a new *FileRun from the Spot run [i, j) in h. @@ -263,15 +243,9 @@ type PakRun struct { } // Sorting support for files within a PakRun. -func (p *PakRun) Len() int { - return len(p.Files); -} -func (p *PakRun) Less(i, j int) bool { - return p.Files[i].File.less(p.Files[j].File); -} -func (p *PakRun) Swap(i, j int) { - p.Files[i], p.Files[j] = p.Files[j], p.Files[i]; -} +func (p *PakRun) Len() int { return len(p.Files) } +func (p *PakRun) Less(i, j int) bool { return p.Files[i].File.less(p.Files[j].File) } +func (p *PakRun) Swap(i, j int) { p.Files[i], p.Files[j] = p.Files[j], p.Files[i] } // newPakRun allocates a new *PakRun from the *FileRun run [i, j) in h. @@ -290,9 +264,7 @@ func newPakRun(h *RunList, i, j int) interface{} { // PakRuns are sorted by package. -func lessPakRun(x, y interface{}) bool { - return x.(*PakRun).Pak.less(&y.(*PakRun).Pak); -} +func lessPakRun(x, y interface{}) bool { return x.(*PakRun).Pak.less(&y.(*PakRun).Pak) } // A HitList describes a list of PakRuns. @@ -350,9 +322,7 @@ type AltWords struct { } -func lessWordPair(x, y interface{}) bool { - return x.(*wordPair).canon < y.(*wordPair).canon; -} +func lessWordPair(x, y interface{}) bool { return x.(*wordPair).canon < y.(*wordPair).canon } // newAltWords allocates a new *AltWords from the *wordPair run [i, j) in h. @@ -591,9 +561,7 @@ type Index struct { } -func canonical(w string) string { - return strings.ToLower(w); -} +func canonical(w string) string { return strings.ToLower(w) } // NewIndex creates a new index for the file tree rooted at root. diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go index de051da2b..6c68fcd64 100644 --- a/src/cmd/godoc/main.go +++ b/src/cmd/godoc/main.go @@ -183,9 +183,7 @@ func main() { // 1) set timestamp right away so that the indexer is kicked on fsTree.set(nil); // 2) compute initial directory tree in a goroutine so that launch is quick - go func() { - fsTree.set(newDirectory(".", maxDirDepth)); - }(); + go func() { fsTree.set(newDirectory(".", maxDirDepth)) }(); // Start sync goroutine, if enabled. if *syncCmd != "" && *syncMin > 0 { diff --git a/src/cmd/goyacc/goyacc.go b/src/cmd/goyacc/goyacc.go index 7717cc839..ea4c544f8 100644 --- a/src/cmd/goyacc/goyacc.go +++ b/src/cmd/goyacc/goyacc.go @@ -131,30 +131,18 @@ const OK = 1 const NOMORE = -1000 // macros for getting associativity and precedence levels -func ASSOC(i int) int { - return i&3; -} +func ASSOC(i int) int { return i&3 } -func PLEVEL(i int) int { - return (i>>4)&077; -} +func PLEVEL(i int) int { return (i>>4)&077 } -func TYPE(i int) int { - return (i>>10)&077; -} +func TYPE(i int) int { return (i>>10)&077 } // macros for setting associativity and precedence levels -func SETASC(i, j int) int { - return i|j; -} +func SETASC(i, j int) int { return i|j } -func SETPLEV(i, j int) int { - return i|(j<<4); -} +func SETPLEV(i, j int) int { return i|(j<<4) } -func SETTYPE(i, j int) int { - return i|(j<<10); -} +func SETTYPE(i, j int) int { return i|(j<<10) } // I/O descriptors var finput *bufio.Reader // input file @@ -3000,17 +2988,11 @@ func usage() { exit(1); } -func bitset(set Lkset, bit int) int { - return set[bit>>5]&(1<<uint(bit&31)); -} +func bitset(set Lkset, bit int) int { return set[bit>>5]&(1<<uint(bit&31)) } -func setbit(set Lkset, bit int) { - set[bit>>5] |= (1<<uint(bit&31)); -} +func setbit(set Lkset, bit int) { set[bit>>5] |= (1<<uint(bit&31)) } -func mkset() Lkset { - return make([]int, tbitset); -} +func mkset() Lkset { return make([]int, tbitset) } // // set a to the union of a and b @@ -3048,17 +3030,13 @@ func prlook(p Lkset) { // var peekrune int -func isdigit(c int) bool { - return c >= '0' && c <= '9'; -} +func isdigit(c int) bool { return c >= '0' && c <= '9' } func isword(c int) bool { return c >= 0xa0 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } -func mktemp(t string) string { - return t; -} +func mktemp(t string) string { return t } // // return 1 if 2 arrays are equal diff --git a/src/cmd/hgpatch/main.go b/src/cmd/hgpatch/main.go index f1f27c506..a46f9ab75 100644 --- a/src/cmd/hgpatch/main.go +++ b/src/cmd/hgpatch/main.go @@ -246,13 +246,9 @@ type undo func() os.Error var undoLog vector.Vector // vector of undo -func undoRevert(name string) { - undoLog.Push(undo(func() os.Error { return hgRevert(name) })); -} +func undoRevert(name string) { undoLog.Push(undo(func() os.Error { return hgRevert(name) })) } -func undoRm(name string) { - undoLog.Push(undo(func() os.Error { return os.Remove(name) })); -} +func undoRm(name string) { undoLog.Push(undo(func() os.Error { return os.Remove(name) })) } func runUndo() { for i := undoLog.Len() - 1; i >= 0; i-- { @@ -392,6 +388,4 @@ type runError struct { err os.Error; } -func (e *runError) String() string { - return strings.Join(e.cmd, " ") + ": " + e.err.String(); -} +func (e *runError) String() string { return strings.Join(e.cmd, " ") + ": " + e.err.String() } diff --git a/src/pkg/archive/tar/reader.go b/src/pkg/archive/tar/reader.go index d5e45288c..8cb40304d 100644 --- a/src/pkg/archive/tar/reader.go +++ b/src/pkg/archive/tar/reader.go @@ -44,9 +44,7 @@ type Reader struct { } // NewReader creates a new Reader reading from r. -func NewReader(r io.Reader) *Reader { - return &Reader{r: r}; -} +func NewReader(r io.Reader) *Reader { return &Reader{r: r} } // Next advances to the next entry in the tar archive. func (tr *Reader) Next() (*Header, os.Error) { diff --git a/src/pkg/archive/tar/writer.go b/src/pkg/archive/tar/writer.go index 68ec2afe9..a3c03cef1 100644 --- a/src/pkg/archive/tar/writer.go +++ b/src/pkg/archive/tar/writer.go @@ -45,9 +45,7 @@ type Writer struct { } // NewWriter creates a new Writer writing to w. -func NewWriter(w io.Writer) *Writer { - return &Writer{w: w}; -} +func NewWriter(w io.Writer) *Writer { return &Writer{w: w} } // Flush finishes writing the current file (optional). func (tw *Writer) Flush() os.Error { diff --git a/src/pkg/asn1/asn1.go b/src/pkg/asn1/asn1.go index e89adb272..642a6ad2b 100644 --- a/src/pkg/asn1/asn1.go +++ b/src/pkg/asn1/asn1.go @@ -34,18 +34,14 @@ type StructuralError struct { Msg string; } -func (e StructuralError) String() string { - return "ASN.1 structure error: " + e.Msg; -} +func (e StructuralError) String() string { return "ASN.1 structure error: " + e.Msg } // A SyntaxError suggests that the ASN.1 data is invalid. type SyntaxError struct { Msg string; } -func (e SyntaxError) String() string { - return "ASN.1 syntax error: " + e.Msg; -} +func (e SyntaxError) String() string { return "ASN.1 syntax error: " + e.Msg } // We start by dealing with each of the primitive types in turn. @@ -190,9 +186,7 @@ func parseBase128Int(bytes []byte, initOffset int) (ret, offset int, err os.Erro // UTCTime -func isDigit(b byte) bool { - return '0' <= b && b <= '9'; -} +func isDigit(b byte) bool { return '0' <= b && b <= '9' } // twoDigits returns the value of two, base 10 digits. func twoDigits(bytes []byte, max int) (int, bool) { diff --git a/src/pkg/asn1/asn1_test.go b/src/pkg/asn1/asn1_test.go index ca2729225..f9a7106d9 100644 --- a/src/pkg/asn1/asn1_test.go +++ b/src/pkg/asn1/asn1_test.go @@ -190,21 +190,13 @@ type parseFieldParametersTest struct { out fieldParameters; } -func newInt(n int) *int { - return &n; -} +func newInt(n int) *int { return &n } -func newInt64(n int64) *int64 { - return &n; -} +func newInt64(n int64) *int64 { return &n } -func newString(s string) *string { - return &s; -} +func newString(s string) *string { return &s } -func newBool(b bool) *bool { - return &b; -} +func newBool(b bool) *bool { return &b } var parseFieldParametersTestData []parseFieldParametersTest = []parseFieldParametersTest{ parseFieldParametersTest{"", fieldParameters{false, false, nil, nil}}, diff --git a/src/pkg/big/int.go b/src/pkg/big/int.go index 5db4f0901..235becfeb 100644 --- a/src/pkg/big/int.go +++ b/src/pkg/big/int.go @@ -27,9 +27,7 @@ func (z *Int) New(x int64) *Int { // NewInt allocates and returns a new Int set to x. -func NewInt(x int64) *Int { - return new(Int).New(x); -} +func NewInt(x int64) *Int { return new(Int).New(x) } // Set sets z to x. diff --git a/src/pkg/big/int_test.go b/src/pkg/big/int_test.go index 442b76fcc..a89b7aa9e 100644 --- a/src/pkg/big/int_test.go +++ b/src/pkg/big/int_test.go @@ -264,8 +264,8 @@ func checkDiv(x, y []byte) bool { type divTest struct { - x, y string; - q, r string; + x, y string; + q, r string; } diff --git a/src/pkg/big/nat.go b/src/pkg/big/nat.go index 9a59f049c..99ddefb62 100644 --- a/src/pkg/big/nat.go +++ b/src/pkg/big/nat.go @@ -482,6 +482,4 @@ func shiftRight(dst, src []Word, n int) { // greaterThan returns true iff (x1<<_W + x2) > (y1<<_W + y2) -func greaterThan(x1, x2, y1, y2 Word) bool { - return x1 > y1 || x1 == y1 && x2 > y2; -} +func greaterThan(x1, x2, y1, y2 Word) bool { return x1 > y1 || x1 == y1 && x2 > y2 } diff --git a/src/pkg/bignum/bignum.go b/src/pkg/bignum/bignum.go index 961d19c42..ed61dad6b 100755 --- a/src/pkg/bignum/bignum.go +++ b/src/pkg/bignum/bignum.go @@ -88,9 +88,7 @@ func assert(p bool) { } -func isSmall(x digit) bool { - return x < 1<<logH; -} +func isSmall(x digit) bool { return x < 1<<logH } // For debugging. Keep around. @@ -176,23 +174,17 @@ func (x Natural) Value() uint64 { // IsEven returns true iff x is divisible by 2. // -func (x Natural) IsEven() bool { - return len(x) == 0 || x[0]&1 == 0; -} +func (x Natural) IsEven() bool { return len(x) == 0 || x[0]&1 == 0 } // IsOdd returns true iff x is not divisible by 2. // -func (x Natural) IsOdd() bool { - return len(x) > 0 && x[0]&1 != 0; -} +func (x Natural) IsOdd() bool { return len(x) > 0 && x[0]&1 != 0 } // IsZero returns true iff x == 0. // -func (x Natural) IsZero() bool { - return len(x) == 0; -} +func (x Natural) IsZero() bool { return len(x) == 0 } // Operations @@ -867,9 +859,7 @@ func (x Natural) ToString(base uint) string { // String converts x to its decimal string representation. // x.String() is the same as x.ToString(10). // -func (x Natural) String() string { - return x.ToString(10); -} +func (x Natural) String() string { return x.ToString(10) } func fmtbase(c int) uint { @@ -888,9 +878,7 @@ func fmtbase(c int) uint { // Format is a support routine for fmt.Formatter. It accepts // the formats 'b' (binary), 'o' (octal), and 'x' (hexadecimal). // -func (x Natural) Format(h fmt.State, c int) { - fmt.Fprintf(h, "%s", x.ToString(fmtbase(c))); -} +func (x Natural) Format(h fmt.State, c int) { fmt.Fprintf(h, "%s", x.ToString(fmtbase(c))) } func hexvalue(ch byte) uint { @@ -1015,9 +1003,7 @@ func Fact(n uint) Natural { // Binomial computes the binomial coefficient of (n, k). // -func Binomial(n, k uint) Natural { - return MulRange(n-k+1, n).Div(MulRange(1, k)); -} +func Binomial(n, k uint) Natural { return MulRange(n-k+1, n).Div(MulRange(1, k)) } // Gcd computes the gcd of x and y. diff --git a/src/pkg/bignum/integer.go b/src/pkg/bignum/integer.go index 0d0d0ed8e..d305625b5 100644 --- a/src/pkg/bignum/integer.go +++ b/src/pkg/bignum/integer.go @@ -64,55 +64,41 @@ func (x *Integer) Value() int64 { // Abs returns the absolute value of x. // -func (x *Integer) Abs() Natural { - return x.mant; -} +func (x *Integer) Abs() Natural { return x.mant } // Predicates // IsEven returns true iff x is divisible by 2. // -func (x *Integer) IsEven() bool { - return x.mant.IsEven(); -} +func (x *Integer) IsEven() bool { return x.mant.IsEven() } // IsOdd returns true iff x is not divisible by 2. // -func (x *Integer) IsOdd() bool { - return x.mant.IsOdd(); -} +func (x *Integer) IsOdd() bool { return x.mant.IsOdd() } // IsZero returns true iff x == 0. // -func (x *Integer) IsZero() bool { - return x.mant.IsZero(); -} +func (x *Integer) IsZero() bool { return x.mant.IsZero() } // IsNeg returns true iff x < 0. // -func (x *Integer) IsNeg() bool { - return x.sign && !x.mant.IsZero(); -} +func (x *Integer) IsNeg() bool { return x.sign && !x.mant.IsZero() } // IsPos returns true iff x >= 0. // -func (x *Integer) IsPos() bool { - return !x.sign && !x.mant.IsZero(); -} +func (x *Integer) IsPos() bool { return !x.sign && !x.mant.IsZero() } // Operations // Neg returns the negated value of x. // -func (x *Integer) Neg() *Integer { - return MakeInt(!x.sign, x.mant); -} +func (x *Integer) Neg() *Integer { return MakeInt(!x.sign, x.mant) } // Iadd sets z to the sum x + y. @@ -323,9 +309,7 @@ func (x *Integer) DivMod(y *Integer) (*Integer, *Integer) { // Shl implements ``shift left'' x << s. It returns x * 2^s. // -func (x *Integer) Shl(s uint) *Integer { - return MakeInt(x.sign, x.mant.Shl(s)); -} +func (x *Integer) Shl(s uint) *Integer { return MakeInt(x.sign, x.mant.Shl(s)) } // The bitwise operations on integers are defined on the 2's-complement @@ -504,17 +488,13 @@ func (x *Integer) ToString(base uint) string { // String converts x to its decimal string representation. // x.String() is the same as x.ToString(10). // -func (x *Integer) String() string { - return x.ToString(10); -} +func (x *Integer) String() string { return x.ToString(10) } // Format is a support routine for fmt.Formatter. It accepts // the formats 'b' (binary), 'o' (octal), and 'x' (hexadecimal). // -func (x *Integer) Format(h fmt.State, c int) { - fmt.Fprintf(h, "%s", x.ToString(fmtbase(c))); -} +func (x *Integer) Format(h fmt.State, c int) { fmt.Fprintf(h, "%s", x.ToString(fmtbase(c))) } // IntFromString returns the integer corresponding to the diff --git a/src/pkg/bignum/nrdiv_test.go b/src/pkg/bignum/nrdiv_test.go index 5fdc31a77..a695e73c5 100644 --- a/src/pkg/bignum/nrdiv_test.go +++ b/src/pkg/bignum/nrdiv_test.go @@ -39,15 +39,11 @@ func (x fpNat) sub(y fpNat) fpNat { // mul2 computes x*2. -func (x fpNat) mul2() fpNat { - return fpNat{x.m, x.e + 1}; -} +func (x fpNat) mul2() fpNat { return fpNat{x.m, x.e + 1} } // mul computes x*y. -func (x fpNat) mul(y fpNat) fpNat { - return fpNat{x.m.Mul(y.m), x.e + y.e}; -} +func (x fpNat) mul(y fpNat) fpNat { return fpNat{x.m.Mul(y.m), x.e + y.e} } // mant computes the (possibly truncated) Natural representation @@ -169,9 +165,7 @@ func div(t *testing.T, x, y Natural) { } -func idiv(t *testing.T, x0, y0 uint64) { - div(t, Nat(x0), Nat(y0)); -} +func idiv(t *testing.T, x0, y0 uint64) { div(t, Nat(x0), Nat(y0)) } func TestNRDiv(t *testing.T) { diff --git a/src/pkg/bignum/rational.go b/src/pkg/bignum/rational.go index 5f7423bac..6cdc1f344 100644 --- a/src/pkg/bignum/rational.go +++ b/src/pkg/bignum/rational.go @@ -51,40 +51,30 @@ func (x *Rational) Value() (numerator *Integer, denominator Natural) { // IsZero returns true iff x == 0. // -func (x *Rational) IsZero() bool { - return x.a.IsZero(); -} +func (x *Rational) IsZero() bool { return x.a.IsZero() } // IsNeg returns true iff x < 0. // -func (x *Rational) IsNeg() bool { - return x.a.IsNeg(); -} +func (x *Rational) IsNeg() bool { return x.a.IsNeg() } // IsPos returns true iff x > 0. // -func (x *Rational) IsPos() bool { - return x.a.IsPos(); -} +func (x *Rational) IsPos() bool { return x.a.IsPos() } // IsInt returns true iff x can be written with a denominator 1 // in the form x == x'/1; i.e., if x is an integer value. // -func (x *Rational) IsInt() bool { - return x.b.Cmp(Nat(1)) == 0; -} +func (x *Rational) IsInt() bool { return x.b.Cmp(Nat(1)) == 0 } // Operations // Neg returns the negated value of x. // -func (x *Rational) Neg() *Rational { - return MakeRat(x.a.Neg(), x.b); -} +func (x *Rational) Neg() *Rational { return MakeRat(x.a.Neg(), x.b) } // Add returns the sum x + y. @@ -103,9 +93,7 @@ func (x *Rational) Sub(y *Rational) *Rational { // Mul returns the product x * y. // -func (x *Rational) Mul(y *Rational) *Rational { - return MakeRat(x.a.Mul(y.a), x.b.Mul(y.b)); -} +func (x *Rational) Mul(y *Rational) *Rational { return MakeRat(x.a.Mul(y.a), x.b.Mul(y.b)) } // Quo returns the quotient x / y for y != 0. @@ -127,9 +115,7 @@ func (x *Rational) Quo(y *Rational) *Rational { // == 0 if x == y // > 0 if x > y // -func (x *Rational) Cmp(y *Rational) int { - return (x.a.MulNat(y.b)).Cmp(y.a.MulNat(x.b)); -} +func (x *Rational) Cmp(y *Rational) int { return (x.a.MulNat(y.b)).Cmp(y.a.MulNat(x.b)) } // ToString converts x to a string for a given base, with 2 <= base <= 16. @@ -148,17 +134,13 @@ func (x *Rational) ToString(base uint) string { // String converts x to its decimal string representation. // x.String() is the same as x.ToString(10). // -func (x *Rational) String() string { - return x.ToString(10); -} +func (x *Rational) String() string { return x.ToString(10) } // Format is a support routine for fmt.Formatter. It accepts // the formats 'b' (binary), 'o' (octal), and 'x' (hexadecimal). // -func (x *Rational) Format(h fmt.State, c int) { - fmt.Fprintf(h, "%s", x.ToString(fmtbase(c))); -} +func (x *Rational) Format(h fmt.State, c int) { fmt.Fprintf(h, "%s", x.ToString(fmtbase(c))) } // RatFromString returns the rational number corresponding to the diff --git a/src/pkg/bufio/bufio.go b/src/pkg/bufio/bufio.go index 5b71182c4..e66d72a35 100644 --- a/src/pkg/bufio/bufio.go +++ b/src/pkg/bufio/bufio.go @@ -211,9 +211,7 @@ func findByte(p []byte, c byte) int { } // Buffered returns the number of bytes that can be read from the current buffer. -func (b *Reader) Buffered() int { - return b.w - b.r; -} +func (b *Reader) Buffered() int { return b.w - b.r } // ReadSlice reads until the first occurrence of delim in the input, // returning a slice pointing at the bytes in the buffer. @@ -404,14 +402,10 @@ func (b *Writer) Flush() os.Error { } // Available returns how many bytes are unused in the buffer. -func (b *Writer) Available() int { - return len(b.buf) - b.n; -} +func (b *Writer) Available() int { return len(b.buf) - b.n } // Buffered returns the number of bytes that have been written into the current buffer. -func (b *Writer) Buffered() int { - return b.n; -} +func (b *Writer) Buffered() int { return b.n } // Write writes the contents of p into the buffer. // It returns the number of bytes written. diff --git a/src/pkg/bytes/buffer.go b/src/pkg/bytes/buffer.go index 875086525..a448dff84 100644 --- a/src/pkg/bytes/buffer.go +++ b/src/pkg/bytes/buffer.go @@ -37,9 +37,7 @@ type Buffer struct { // Bytes returns the contents of the unread portion of the buffer; // len(b.Bytes()) == b.Len(). -func (b *Buffer) Bytes() []byte { - return b.buf[b.off : len(b.buf)]; -} +func (b *Buffer) Bytes() []byte { return b.buf[b.off : len(b.buf)] } // String returns the contents of the unread portion of the buffer // as a string. If the Buffer is a nil pointer, it returns "<nil>". @@ -53,9 +51,7 @@ func (b *Buffer) String() string { // Len returns the number of bytes of the unread portion of the buffer; // b.Len() == len(b.Bytes()). -func (b *Buffer) Len() int { - return len(b.buf) - b.off; -} +func (b *Buffer) Len() int { return len(b.buf) - b.off } // Truncate discards all but the first n unread bytes from the buffer. // It is an error to call b.Truncate(n) with n > b.Len(). @@ -69,9 +65,7 @@ func (b *Buffer) Truncate(n int) { // Reset resets the buffer so it has no content. // b.Reset() is the same as b.Truncate(0). -func (b *Buffer) Reset() { - b.Truncate(0); -} +func (b *Buffer) Reset() { b.Truncate(0) } // Write appends the contents of p to the buffer. The return // value n is the length of p; err is always nil. @@ -166,9 +160,7 @@ func (b *Buffer) ReadByte() (c byte, err os.Error) { // NewBuffer creates and initializes a new Buffer // using buf as its initial contents. -func NewBuffer(buf []byte) *Buffer { - return &Buffer{buf: buf}; -} +func NewBuffer(buf []byte) *Buffer { return &Buffer{buf: buf} } // NewBufferString creates and initializes a new Buffer // using string s as its initial contents. diff --git a/src/pkg/bytes/bytes.go b/src/pkg/bytes/bytes.go index 05d87fcb6..3ebc8373a 100644 --- a/src/pkg/bytes/bytes.go +++ b/src/pkg/bytes/bytes.go @@ -155,9 +155,7 @@ func genSplit(s, sep []byte, sepSave, n int) [][]byte { // Split splits the array s around each instance of sep, returning an array of subarrays of s. // If sep is empty, Split splits s after each UTF-8 sequence. // If n > 0, Split splits s into at most n subarrays; the last subarray will contain an unsplit remainder. -func Split(s, sep []byte, n int) [][]byte { - return genSplit(s, sep, 0, n); -} +func Split(s, sep []byte, n int) [][]byte { return genSplit(s, sep, 0, n) } // SplitAfter splits the array s after each instance of sep, returning an array of subarrays of s. // If sep is empty, SplitAfter splits s after each UTF-8 sequence. @@ -244,19 +242,13 @@ func Map(mapping func(rune int) int, s []byte) []byte { } // ToUpper returns a copy of the byte array s with all Unicode letters mapped to their upper case. -func ToUpper(s []byte) []byte { - return Map(unicode.ToUpper, s); -} +func ToUpper(s []byte) []byte { return Map(unicode.ToUpper, s) } // ToUpper returns a copy of the byte array s with all Unicode letters mapped to their lower case. -func ToLower(s []byte) []byte { - return Map(unicode.ToLower, s); -} +func ToLower(s []byte) []byte { return Map(unicode.ToLower, s) } // ToTitle returns a copy of the byte array s with all Unicode letters mapped to their title case. -func ToTitle(s []byte) []byte { - return Map(unicode.ToTitle, s); -} +func ToTitle(s []byte) []byte { return Map(unicode.ToTitle, s) } // Trim returns a slice of the string s, with all leading and trailing white space // removed, as defined by Unicode. diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index ee727f0cd..b00de1b0c 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -287,17 +287,11 @@ func TestMap(t *testing.T) { } } -func TestToUpper(t *testing.T) { - runStringTests(t, ToUpper, "ToUpper", upperTests); -} +func TestToUpper(t *testing.T) { runStringTests(t, ToUpper, "ToUpper", upperTests) } -func TestToLower(t *testing.T) { - runStringTests(t, ToLower, "ToLower", lowerTests); -} +func TestToLower(t *testing.T) { runStringTests(t, ToLower, "ToLower", lowerTests) } -func TestTrimSpace(t *testing.T) { - runStringTests(t, TrimSpace, "TrimSpace", trimSpaceTests); -} +func TestTrimSpace(t *testing.T) { runStringTests(t, TrimSpace, "TrimSpace", trimSpaceTests) } type AddTest struct { s, t string; diff --git a/src/pkg/compress/flate/huffman_code.go b/src/pkg/compress/flate/huffman_code.go index 8929697bc..eecfceb9c 100644 --- a/src/pkg/compress/flate/huffman_code.go +++ b/src/pkg/compress/flate/huffman_code.go @@ -55,9 +55,7 @@ type levelInfo struct { down *levelInfo; } -func maxNode() literalNode { - return literalNode{math.MaxUint16, math.MaxInt32}; -} +func maxNode() literalNode { return literalNode{math.MaxUint16, math.MaxInt32} } func newHuffmanEncoder(size int) *huffmanEncoder { return &huffmanEncoder{make([]uint8, size), make([]uint16, size)}; @@ -357,17 +355,13 @@ type literalNodeSorter struct { less func(i, j int) bool; } -func (s literalNodeSorter) Len() int { - return len(s.a); -} +func (s literalNodeSorter) Len() int { return len(s.a) } func (s literalNodeSorter) Less(i, j int) bool { return s.less(i, j); } -func (s literalNodeSorter) Swap(i, j int) { - s.a[i], s.a[j] = s.a[j], s.a[i]; -} +func (s literalNodeSorter) Swap(i, j int) { s.a[i], s.a[j] = s.a[j], s.a[i] } func sortByFreq(a []literalNode) { s := &literalNodeSorter{a, func(i, j int) bool { return a[i].freq < a[j].freq }}; diff --git a/src/pkg/compress/flate/inflate.go b/src/pkg/compress/flate/inflate.go index 149cb08c7..96bbcb653 100644 --- a/src/pkg/compress/flate/inflate.go +++ b/src/pkg/compress/flate/inflate.go @@ -32,9 +32,7 @@ func (e CorruptInputError) String() string { // An InternalError reports an error in the flate code itself. type InternalError string -func (e InternalError) String() string { - return "flate: internal error: " + string(e); -} +func (e InternalError) String() string { return "flate: internal error: " + string(e) } // A ReadError reports an error encountered while reading input. type ReadError struct { diff --git a/src/pkg/compress/flate/token.go b/src/pkg/compress/flate/token.go index 476eae783..d37730ca5 100644 --- a/src/pkg/compress/flate/token.go +++ b/src/pkg/compress/flate/token.go @@ -68,9 +68,7 @@ var offsetCodes = [...]uint32{ type token uint32 // Convert a literal into a literal token. -func literalToken(literal uint32) token { - return token(literalType + literal); -} +func literalToken(literal uint32) token { return token(literalType + literal) } // Convert a < xlength, xoffset > pair into a match token. func matchToken(xlength uint32, xoffset uint32) token { @@ -78,27 +76,17 @@ func matchToken(xlength uint32, xoffset uint32) token { } // Returns the type of a token -func (t token) typ() uint32 { - return uint32(t)&typeMask; -} +func (t token) typ() uint32 { return uint32(t)&typeMask } // Returns the literal of a literal token -func (t token) literal() uint32 { - return uint32(t - literalType); -} +func (t token) literal() uint32 { return uint32(t - literalType) } // Returns the extra offset of a match token -func (t token) offset() uint32 { - return uint32(t) & offsetMask; -} +func (t token) offset() uint32 { return uint32(t) & offsetMask } -func (t token) length() uint32 { - return uint32((t - matchType) >> lengthShift); -} +func (t token) length() uint32 { return uint32((t - matchType) >> lengthShift) } -func lengthCode(len uint32) uint32 { - return lengthCodes[len]; -} +func lengthCode(len uint32) uint32 { return lengthCodes[len] } // Returns the offset code corresponding to a specific offset func offsetCode(off uint32) uint32 { diff --git a/src/pkg/compress/gzip/gunzip.go b/src/pkg/compress/gzip/gunzip.go index 07906cd38..3dbfeca65 100644 --- a/src/pkg/compress/gzip/gunzip.go +++ b/src/pkg/compress/gzip/gunzip.go @@ -220,6 +220,4 @@ func (z *Inflater) Read(p []byte) (n int, err os.Error) { } // Calling Close does not close the wrapped io.Reader originally passed to NewInflater. -func (z *Inflater) Close() os.Error { - return z.inflater.Close(); -} +func (z *Inflater) Close() os.Error { return z.inflater.Close() } diff --git a/src/pkg/container/heap/heap.go b/src/pkg/container/heap/heap.go index f78e3b3a5..100dcad05 100644 --- a/src/pkg/container/heap/heap.go +++ b/src/pkg/container/heap/heap.go @@ -27,9 +27,7 @@ type Interface interface { // and may be called whenever the heap invariants may have been invalidated. // Its complexity is O(n*log(n)) where n = h.Len(). // -func Init(h Interface) { - sort.Sort(h); -} +func Init(h Interface) { sort.Sort(h) } // Push pushes the element x onto the heap. The complexity is diff --git a/src/pkg/container/heap/heap_test.go b/src/pkg/container/heap/heap_test.go index 99722f2e9..2375906b9 100644 --- a/src/pkg/container/heap/heap_test.go +++ b/src/pkg/container/heap/heap_test.go @@ -43,14 +43,10 @@ func (h *myHeap) verify(t *testing.T, i int) { } -func (h *myHeap) Push(x interface{}) { - h.IntVector.Push(x.(int)); -} +func (h *myHeap) Push(x interface{}) { h.IntVector.Push(x.(int)) } -func (h *myHeap) Pop() interface{} { - return h.IntVector.Pop(); -} +func (h *myHeap) Pop() interface{} { return h.IntVector.Pop() } func TestInit(t *testing.T) { diff --git a/src/pkg/container/list/list.go b/src/pkg/container/list/list.go index acd34c417..b1f12080f 100755 --- a/src/pkg/container/list/list.go +++ b/src/pkg/container/list/list.go @@ -19,14 +19,10 @@ type Element struct { } // Next returns the next list element or nil. -func (e *Element) Next() *Element { - return e.next; -} +func (e *Element) Next() *Element { return e.next } // Prev returns the previous list element or nil. -func (e *Element) Prev() *Element { - return e.prev; -} +func (e *Element) Prev() *Element { return e.prev } // List represents a doubly linked list. type List struct { @@ -45,19 +41,13 @@ func (l *List) Init() *List { } // New returns an initialized list. -func New() *List { - return new(List).Init(); -} +func New() *List { return new(List).Init() } // Front returns the first element in the list. -func (l *List) Front() *Element { - return l.front; -} +func (l *List) Front() *Element { return l.front } // Back returns the last element in the list. -func (l *List) Back() *Element { - return l.back; -} +func (l *List) Back() *Element { return l.back } // Remove removes the element from the list. func (l *List) Remove(e *Element) { @@ -187,9 +177,7 @@ func (l *List) MoveToBack(e *Element) { } // Len returns the number of elements in the list. -func (l *List) Len() int { - return l.len; -} +func (l *List) Len() int { return l.len } func (l *List) iterate(c chan<- interface{}) { for e := l.front; e != nil; e = e.next { diff --git a/src/pkg/container/ring/ring_test.go b/src/pkg/container/ring/ring_test.go index 0dc3a71d1..7032cdfcf 100644 --- a/src/pkg/container/ring/ring_test.go +++ b/src/pkg/container/ring/ring_test.go @@ -138,9 +138,7 @@ func sum(r *Ring) int { } -func sumN(n int) int { - return (n*n + n)/2; -} +func sumN(n int) int { return (n*n + n)/2 } func TestNew(t *testing.T) { diff --git a/src/pkg/container/vector/intvector.go b/src/pkg/container/vector/intvector.go index 9db252958..e17d619ad 100644 --- a/src/pkg/container/vector/intvector.go +++ b/src/pkg/container/vector/intvector.go @@ -21,27 +21,19 @@ func (p *IntVector) Init(len int) *IntVector { // NewIntVector returns an initialized new IntVector with length at least len. -func NewIntVector(len int) *IntVector { - return new(IntVector).Init(len); -} +func NewIntVector(len int) *IntVector { return new(IntVector).Init(len) } // At returns the i'th element of the vector. -func (p *IntVector) At(i int) int { - return p.Vector.At(i).(int); -} +func (p *IntVector) At(i int) int { return p.Vector.At(i).(int) } // Set sets the i'th element of the vector to value x. -func (p *IntVector) Set(i int, x int) { - p.a[i] = x; -} +func (p *IntVector) Set(i int, x int) { p.a[i] = x } // Last returns the element in the vector of highest index. -func (p *IntVector) Last() int { - return p.Vector.Last().(int); -} +func (p *IntVector) Last() int { return p.Vector.Last().(int) } // Data returns all the elements as a slice. @@ -56,9 +48,7 @@ func (p *IntVector) Data() []int { // Insert inserts into the vector an element of value x before // the current element at index i. -func (p *IntVector) Insert(i int, x int) { - p.Vector.Insert(i, x); -} +func (p *IntVector) Insert(i int, x int) { p.Vector.Insert(i, x) } // InsertVector inserts into the vector the contents of the Vector @@ -76,15 +66,11 @@ func (p *IntVector) Slice(i, j int) *IntVector { // Push appends x to the end of the vector. -func (p *IntVector) Push(x int) { - p.Vector.Push(x); -} +func (p *IntVector) Push(x int) { p.Vector.Push(x) } // Pop deletes and returns the last element of the vector. -func (p *IntVector) Pop() int { - return p.Vector.Pop().(int); -} +func (p *IntVector) Pop() int { return p.Vector.Pop().(int) } // AppendVector appends the entire IntVector x to the end of this vector. @@ -95,9 +81,7 @@ func (p *IntVector) AppendVector(x *IntVector) { // sort.Interface support // Less returns a boolean denoting whether the i'th element is less than the j'th element. -func (p *IntVector) Less(i, j int) bool { - return p.At(i) < p.At(j); -} +func (p *IntVector) Less(i, j int) bool { return p.At(i) < p.At(j) } // Iterate over all elements; driver for range diff --git a/src/pkg/container/vector/stringvector.go b/src/pkg/container/vector/stringvector.go index 4e54ea85c..c3f31f046 100644 --- a/src/pkg/container/vector/stringvector.go +++ b/src/pkg/container/vector/stringvector.go @@ -20,27 +20,19 @@ func (p *StringVector) Init(len int) *StringVector { // NewStringVector returns an initialized new StringVector with length at least len. -func NewStringVector(len int) *StringVector { - return new(StringVector).Init(len); -} +func NewStringVector(len int) *StringVector { return new(StringVector).Init(len) } // At returns the i'th element of the vector. -func (p *StringVector) At(i int) string { - return p.Vector.At(i).(string); -} +func (p *StringVector) At(i int) string { return p.Vector.At(i).(string) } // Set sets the i'th element of the vector to value x. -func (p *StringVector) Set(i int, x string) { - p.a[i] = x; -} +func (p *StringVector) Set(i int, x string) { p.a[i] = x } // Last returns the element in the vector of highest index. -func (p *StringVector) Last() string { - return p.Vector.Last().(string); -} +func (p *StringVector) Last() string { return p.Vector.Last().(string) } // Data returns all the elements as a slice. @@ -75,15 +67,11 @@ func (p *StringVector) Slice(i, j int) *StringVector { // Push appends x to the end of the vector. -func (p *StringVector) Push(x string) { - p.Vector.Push(x); -} +func (p *StringVector) Push(x string) { p.Vector.Push(x) } // Pop deletes and returns the last element of the vector. -func (p *StringVector) Pop() string { - return p.Vector.Pop().(string); -} +func (p *StringVector) Pop() string { return p.Vector.Pop().(string) } // AppendVector appends the entire StringVector x to the end of this vector. @@ -94,9 +82,7 @@ func (p *StringVector) AppendVector(x *StringVector) { // sort.Interface support // Less returns a boolean denoting whether the i'th element is less than the j'th element. -func (p *StringVector) Less(i, j int) bool { - return p.At(i) < p.At(j); -} +func (p *StringVector) Less(i, j int) bool { return p.At(i) < p.At(j) } // Iterate over all elements; driver for range diff --git a/src/pkg/container/vector/vector.go b/src/pkg/container/vector/vector.go index 3746b422a..ee19997fb 100644 --- a/src/pkg/container/vector/vector.go +++ b/src/pkg/container/vector/vector.go @@ -79,9 +79,7 @@ func (p *Vector) Init(initial_len int) *Vector { // New returns an initialized new Vector with length at least len. -func New(len int) *Vector { - return new(Vector).Init(len); -} +func New(len int) *Vector { return new(Vector).Init(len) } // Len returns the number of elements in the vector. @@ -95,21 +93,15 @@ func (p *Vector) Len() int { // At returns the i'th element of the vector. -func (p *Vector) At(i int) Element { - return p.a[i]; -} +func (p *Vector) At(i int) Element { return p.a[i] } // Set sets the i'th element of the vector to value x. -func (p *Vector) Set(i int, x Element) { - p.a[i] = x; -} +func (p *Vector) Set(i int, x Element) { p.a[i] = x } // Last returns the element in the vector of highest index. -func (p *Vector) Last() Element { - return p.a[len(p.a)-1]; -} +func (p *Vector) Last() Element { return p.a[len(p.a)-1] } // Data returns all the elements as a slice. @@ -186,9 +178,7 @@ func (p *Vector) Do(f func(elem Element)) { // Convenience wrappers // Push appends x to the end of the vector. -func (p *Vector) Push(x Element) { - p.Insert(len(p.a), x); -} +func (p *Vector) Push(x Element) { p.Insert(len(p.a), x) } // Pop deletes the last element of the vector. @@ -202,9 +192,7 @@ func (p *Vector) Pop() Element { // AppendVector appends the entire Vector x to the end of this vector. -func (p *Vector) AppendVector(x *Vector) { - p.InsertVector(len(p.a), x); -} +func (p *Vector) AppendVector(x *Vector) { p.InsertVector(len(p.a), x) } // Partial sort.Interface support @@ -216,9 +204,7 @@ type LessInterface interface { // Less returns a boolean denoting whether the i'th element is less than the j'th element. -func (p *Vector) Less(i, j int) bool { - return p.a[i].(LessInterface).Less(p.a[j]); -} +func (p *Vector) Less(i, j int) bool { return p.a[i].(LessInterface).Less(p.a[j]) } // Swap exchanges the elements at indexes i and j. diff --git a/src/pkg/container/vector/vector_test.go b/src/pkg/container/vector/vector_test.go index 32a21f3eb..12a8aa077 100644 --- a/src/pkg/container/vector/vector_test.go +++ b/src/pkg/container/vector/vector_test.go @@ -48,9 +48,7 @@ func TestNew(t *testing.T) { } -func val(i int) int { - return i*991 - 1234; -} +func val(i int) int { return i*991 - 1234 } func TestAccess(t *testing.T) { diff --git a/src/pkg/crypto/aes/block.go b/src/pkg/crypto/aes/block.go index 738deba66..969983019 100644 --- a/src/pkg/crypto/aes/block.go +++ b/src/pkg/crypto/aes/block.go @@ -135,9 +135,7 @@ func subw(w uint32) uint32 { } // Rotate -func rotw(w uint32) uint32 { - return w<<8 | w>>24; -} +func rotw(w uint32) uint32 { return w<<8 | w>>24 } // Key expansion algorithm. See FIPS-197, Figure 11. // Their rcon[i] is our powx[i-1] << 24. diff --git a/src/pkg/crypto/aes/cipher.go b/src/pkg/crypto/aes/cipher.go index db9b59cd0..411272549 100644 --- a/src/pkg/crypto/aes/cipher.go +++ b/src/pkg/crypto/aes/cipher.go @@ -46,24 +46,18 @@ func NewCipher(key []byte) (*Cipher, os.Error) { // BlockSize returns the AES block size, 16 bytes. // It is necessary to satisfy the Key interface in the // package "crypto/modes". -func (c *Cipher) BlockSize() int { - return BlockSize; -} +func (c *Cipher) BlockSize() int { return BlockSize } // Encrypt encrypts the 16-byte buffer src using the key k // and stores the result in dst. // Note that for amounts of data larger than a block, // it is not safe to just call Encrypt on successive blocks; // instead, use an encryption mode like AESCBC (see modes.go). -func (c *Cipher) Encrypt(src, dst []byte) { - encryptBlock(c.enc, src, dst); -} +func (c *Cipher) Encrypt(src, dst []byte) { encryptBlock(c.enc, src, dst) } // Decrypt decrypts the 16-byte buffer src using the key k // and stores the result in dst. -func (c *Cipher) Decrypt(src, dst []byte) { - decryptBlock(c.dec, src, dst); -} +func (c *Cipher) Decrypt(src, dst []byte) { decryptBlock(c.dec, src, dst) } // Reset zeros the key data, so that it will no longer // appear in the process's memory. diff --git a/src/pkg/crypto/block/cbc.go b/src/pkg/crypto/block/cbc.go index 7bdf7d304..47aa8f32d 100644 --- a/src/pkg/crypto/block/cbc.go +++ b/src/pkg/crypto/block/cbc.go @@ -32,9 +32,7 @@ func newCBC(c Cipher, iv []byte) *cbcCipher { return x; } -func (x *cbcCipher) BlockSize() int { - return x.blockSize; -} +func (x *cbcCipher) BlockSize() int { return x.blockSize } func (x *cbcCipher) Encrypt(src, dst []byte) { for i := 0; i < x.blockSize; i++ { diff --git a/src/pkg/crypto/block/cfb.go b/src/pkg/crypto/block/cfb.go index 412381605..f515bdcfd 100644 --- a/src/pkg/crypto/block/cfb.go +++ b/src/pkg/crypto/block/cfb.go @@ -38,9 +38,7 @@ func newCFB(c Cipher, s int, iv []byte) *cfbCipher { return x; } -func (x *cfbCipher) BlockSize() int { - return x.blockSize; -} +func (x *cfbCipher) BlockSize() int { return x.blockSize } func (x *cfbCipher) Encrypt(src, dst []byte) { // Encrypt old IV and xor prefix with src to make dst. diff --git a/src/pkg/crypto/block/cmac.go b/src/pkg/crypto/block/cmac.go index 667dc7b3e..f57e64174 100644 --- a/src/pkg/crypto/block/cmac.go +++ b/src/pkg/crypto/block/cmac.go @@ -102,6 +102,4 @@ func (d *cmac) Sum() []byte { return d.digest; } -func (d *cmac) Size() int { - return len(d.digest); -} +func (d *cmac) Size() int { return len(d.digest) } diff --git a/src/pkg/crypto/block/ecb_test.go b/src/pkg/crypto/block/ecb_test.go index 664c4f4e1..c6507220b 100644 --- a/src/pkg/crypto/block/ecb_test.go +++ b/src/pkg/crypto/block/ecb_test.go @@ -20,9 +20,7 @@ type IncCipher struct { encrypting bool; } -func (c *IncCipher) BlockSize() int { - return c.blockSize; -} +func (c *IncCipher) BlockSize() int { return c.blockSize } func (c *IncCipher) Encrypt(src, dst []byte) { if !c.encrypting { diff --git a/src/pkg/crypto/hmac/hmac.go b/src/pkg/crypto/hmac/hmac.go index 4ed5686d7..f1cc6b32a 100644 --- a/src/pkg/crypto/hmac/hmac.go +++ b/src/pkg/crypto/hmac/hmac.go @@ -64,9 +64,7 @@ func (h *hmac) Write(p []byte) (n int, err os.Error) { return h.inner.Write(p); } -func (h *hmac) Size() int { - return h.size; -} +func (h *hmac) Size() int { return h.size } func (h *hmac) Reset() { h.inner.Reset(); @@ -94,11 +92,7 @@ func New(h hash.Hash, key []byte) hash.Hash { } // NewMD5 returns a new HMAC-MD5 hash using the given key. -func NewMD5(key []byte) hash.Hash { - return New(md5.New(), key); -} +func NewMD5(key []byte) hash.Hash { return New(md5.New(), key) } // NewSHA1 returns a new HMAC-SHA1 hash using the given key. -func NewSHA1(key []byte) hash.Hash { - return New(sha1.New(), key); -} +func NewSHA1(key []byte) hash.Hash { return New(sha1.New(), key) } diff --git a/src/pkg/crypto/md5/md5.go b/src/pkg/crypto/md5/md5.go index 77b3319c0..4236ad3fa 100644 --- a/src/pkg/crypto/md5/md5.go +++ b/src/pkg/crypto/md5/md5.go @@ -45,9 +45,7 @@ func New() hash.Hash { return d; } -func (d *digest) Size() int { - return Size; -} +func (d *digest) Size() int { return Size } func (d *digest) Write(p []byte) (nn int, err os.Error) { nn = len(p); diff --git a/src/pkg/crypto/rsa/rsa.go b/src/pkg/crypto/rsa/rsa.go index 685efd18f..beb416297 100644 --- a/src/pkg/crypto/rsa/rsa.go +++ b/src/pkg/crypto/rsa/rsa.go @@ -296,9 +296,7 @@ func EncryptOAEP(hash hash.Hash, rand io.Reader, pub *PublicKey, msg []byte, lab // It is deliberately vague to avoid adaptive attacks. type DecryptionError struct{} -func (DecryptionError) String() string { - return "RSA decryption error"; -} +func (DecryptionError) String() string { return "RSA decryption error" } // modInverse returns ia, the inverse of a in the multiplicative group of prime // order n. It requires that a be a member of the group (i.e. less than n). diff --git a/src/pkg/crypto/sha1/sha1.go b/src/pkg/crypto/sha1/sha1.go index a278f04eb..4e75b7336 100644 --- a/src/pkg/crypto/sha1/sha1.go +++ b/src/pkg/crypto/sha1/sha1.go @@ -47,9 +47,7 @@ func New() hash.Hash { return d; } -func (d *digest) Size() int { - return Size; -} +func (d *digest) Size() int { return Size } func (d *digest) Write(p []byte) (nn int, err os.Error) { nn = len(p); diff --git a/src/pkg/crypto/subtle/constant_time.go b/src/pkg/crypto/subtle/constant_time.go index a1d2eaf99..4dd7aa042 100644 --- a/src/pkg/crypto/subtle/constant_time.go +++ b/src/pkg/crypto/subtle/constant_time.go @@ -21,9 +21,7 @@ func ConstantTimeCompare(x, y []byte) int { // ConstantTimeSelect returns x if v is 1 and y if v is 0. // Its behavior is undefined if v takes any other value. -func ConstantTimeSelect(v, x, y int) int { - return ^(v-1) & x | (v-1)&y; -} +func ConstantTimeSelect(v, x, y int) int { return ^(v-1) & x | (v-1)&y } // ConstantTimeByteEq returns 1 if x == x and 0 otherwise. func ConstantTimeByteEq(x, y uint8) int { diff --git a/src/pkg/crypto/tls/common.go b/src/pkg/crypto/tls/common.go index 2145b7b55..36ad640cd 100644 --- a/src/pkg/crypto/tls/common.go +++ b/src/pkg/crypto/tls/common.go @@ -106,20 +106,12 @@ func mutualVersion(theirMajor, theirMinor uint8) (major, minor uint8, ok bool) { // A nop implements the NULL encryption and MAC algorithms. type nop struct{} -func (nop) XORKeyStream(buf []byte) { -} +func (nop) XORKeyStream(buf []byte) {} -func (nop) Write(buf []byte) (int, os.Error) { - return len(buf), nil; -} +func (nop) Write(buf []byte) (int, os.Error) { return len(buf), nil } -func (nop) Sum() []byte { - return nil; -} +func (nop) Sum() []byte { return nil } -func (nop) Reset() { -} +func (nop) Reset() {} -func (nop) Size() int { - return 0; -} +func (nop) Size() int { return 0 } diff --git a/src/pkg/crypto/tls/tls.go b/src/pkg/crypto/tls/tls.go index 13d8fd70b..c20e24e55 100644 --- a/src/pkg/crypto/tls/tls.go +++ b/src/pkg/crypto/tls/tls.go @@ -155,13 +155,9 @@ func (l Listener) Accept() (c net.Conn, err os.Error) { return; } -func (l Listener) Close() os.Error { - return l.listener.Close(); -} +func (l Listener) Close() os.Error { return l.listener.Close() } -func (l Listener) Addr() net.Addr { - return l.listener.Addr(); -} +func (l Listener) Addr() net.Addr { return l.listener.Addr() } // NewListener creates a Listener which accepts connections from an inner // Listener and wraps each connection with Server. diff --git a/src/pkg/debug/dwarf/buf.go b/src/pkg/debug/dwarf/buf.go index 34880a5d5..87576e65c 100644 --- a/src/pkg/debug/dwarf/buf.go +++ b/src/pkg/debug/dwarf/buf.go @@ -49,9 +49,7 @@ func (b *buf) bytes(n int) []byte { return data; } -func (b *buf) skip(n int) { - b.bytes(n); -} +func (b *buf) skip(n int) { b.bytes(n) } func (b *buf) string() string { for i := 0; i < len(b.data); i++ { diff --git a/src/pkg/debug/dwarf/type.go b/src/pkg/debug/dwarf/type.go index 91334bdf2..77d24f5d2 100644 --- a/src/pkg/debug/dwarf/type.go +++ b/src/pkg/debug/dwarf/type.go @@ -29,13 +29,9 @@ type CommonType struct { Name string; // name that can be used to refer to type } -func (c *CommonType) Common() *CommonType { - return c; -} +func (c *CommonType) Common() *CommonType { return c } -func (c *CommonType) Size() int64 { - return c.ByteSize; -} +func (c *CommonType) Size() int64 { return c.ByteSize } // Basic types @@ -46,9 +42,7 @@ type BasicType struct { BitOffset int64; } -func (b *BasicType) Basic() *BasicType { - return b; -} +func (b *BasicType) Basic() *BasicType { return b } func (t *BasicType) String() string { if t.Name != "" { @@ -106,13 +100,9 @@ type QualType struct { Type Type; } -func (t *QualType) String() string { - return t.Qual + " " + t.Type.String(); -} +func (t *QualType) String() string { return t.Qual + " " + t.Type.String() } -func (t *QualType) Size() int64 { - return t.Type.Size(); -} +func (t *QualType) Size() int64 { return t.Type.Size() } // An ArrayType represents a fixed size array type. type ArrayType struct { @@ -126,18 +116,14 @@ func (t *ArrayType) String() string { return "[" + strconv.Itoa64(t.Count) + "]" + t.Type.String(); } -func (t *ArrayType) Size() int64 { - return t.Count * t.Type.Size(); -} +func (t *ArrayType) Size() int64 { return t.Count * t.Type.Size() } // A VoidType represents the C void type. type VoidType struct { CommonType; } -func (t *VoidType) String() string { - return "void"; -} +func (t *VoidType) String() string { return "void" } // A PtrType represents a pointer type. type PtrType struct { @@ -145,9 +131,7 @@ type PtrType struct { Type Type; } -func (t *PtrType) String() string { - return "*" + t.Type.String(); -} +func (t *PtrType) String() string { return "*" + t.Type.String() } // A StructType represents a struct, union, or C++ class type. type StructType struct { @@ -258,9 +242,7 @@ type DotDotDotType struct { CommonType; } -func (t *DotDotDotType) String() string { - return "..."; -} +func (t *DotDotDotType) String() string { return "..." } // A TypedefType represents a named type. type TypedefType struct { @@ -268,13 +250,9 @@ type TypedefType struct { Type Type; } -func (t *TypedefType) String() string { - return t.Name; -} +func (t *TypedefType) String() string { return t.Name } -func (t *TypedefType) Size() int64 { - return t.Type.Size(); -} +func (t *TypedefType) Size() int64 { return t.Type.Size() } func (d *Data) Type(off Offset) (Type, os.Error) { if t, ok := d.typeCache[off]; ok { diff --git a/src/pkg/debug/dwarf/type_test.go b/src/pkg/debug/dwarf/type_test.go index 98e444eaf..dcecbe2c3 100644 --- a/src/pkg/debug/dwarf/type_test.go +++ b/src/pkg/debug/dwarf/type_test.go @@ -56,9 +56,7 @@ func machoData(t *testing.T, name string) *Data { } -func TestTypedefsELF(t *testing.T) { - testTypedefs(t, elfData(t, "testdata/typedef.elf")); -} +func TestTypedefsELF(t *testing.T) { testTypedefs(t, elfData(t, "testdata/typedef.elf")) } func TestTypedefsMachO(t *testing.T) { testTypedefs(t, machoData(t, "testdata/typedef.macho")); diff --git a/src/pkg/debug/elf/elf.go b/src/pkg/debug/elf/elf.go index 716f10b40..42a240efd 100644 --- a/src/pkg/debug/elf/elf.go +++ b/src/pkg/debug/elf/elf.go @@ -73,12 +73,8 @@ var versionStrings = []intName{ intName{1, "EV_CURRENT"}, } -func (i Version) String() string { - return stringName(uint32(i), versionStrings, false); -} -func (i Version) GoString() string { - return stringName(uint32(i), versionStrings, true); -} +func (i Version) String() string { return stringName(uint32(i), versionStrings, false) } +func (i Version) GoString() string { return stringName(uint32(i), versionStrings, true) } // Class is found in Header.Ident[EI_CLASS] and Header.Class. type Class byte @@ -95,12 +91,8 @@ var classStrings = []intName{ intName{2, "ELFCLASS64"}, } -func (i Class) String() string { - return stringName(uint32(i), classStrings, false); -} -func (i Class) GoString() string { - return stringName(uint32(i), classStrings, true); -} +func (i Class) String() string { return stringName(uint32(i), classStrings, false) } +func (i Class) GoString() string { return stringName(uint32(i), classStrings, true) } // Data is found in Header.Ident[EI_DATA] and Header.Data. type Data byte @@ -117,12 +109,8 @@ var dataStrings = []intName{ intName{2, "ELFDATA2MSB"}, } -func (i Data) String() string { - return stringName(uint32(i), dataStrings, false); -} -func (i Data) GoString() string { - return stringName(uint32(i), dataStrings, true); -} +func (i Data) String() string { return stringName(uint32(i), dataStrings, false) } +func (i Data) GoString() string { return stringName(uint32(i), dataStrings, true) } // OSABI is found in Header.Ident[EI_OSABI] and Header.OSABI. type OSABI byte @@ -167,12 +155,8 @@ var osabiStrings = []intName{ intName{255, "ELFOSABI_STANDALONE"}, } -func (i OSABI) String() string { - return stringName(uint32(i), osabiStrings, false); -} -func (i OSABI) GoString() string { - return stringName(uint32(i), osabiStrings, true); -} +func (i OSABI) String() string { return stringName(uint32(i), osabiStrings, false) } +func (i OSABI) GoString() string { return stringName(uint32(i), osabiStrings, true) } // Type is found in Header.Type. type Type uint16 @@ -201,12 +185,8 @@ var typeStrings = []intName{ intName{0xffff, "ET_HIPROC"}, } -func (i Type) String() string { - return stringName(uint32(i), typeStrings, false); -} -func (i Type) GoString() string { - return stringName(uint32(i), typeStrings, true); -} +func (i Type) String() string { return stringName(uint32(i), typeStrings, false) } +func (i Type) GoString() string { return stringName(uint32(i), typeStrings, true) } // Machine is found in Header.Machine. type Machine uint16 @@ -315,12 +295,8 @@ var machineStrings = []intName{ intName{0x9026, "EM_ALPHA"}, } -func (i Machine) String() string { - return stringName(uint32(i), machineStrings, false); -} -func (i Machine) GoString() string { - return stringName(uint32(i), machineStrings, true); -} +func (i Machine) String() string { return stringName(uint32(i), machineStrings, false) } +func (i Machine) GoString() string { return stringName(uint32(i), machineStrings, true) } // Special section indices. type SectionIndex int @@ -347,12 +323,8 @@ var shnStrings = []intName{ intName{0xffff, "SHN_XINDEX"}, } -func (i SectionIndex) String() string { - return stringName(uint32(i), shnStrings, false); -} -func (i SectionIndex) GoString() string { - return stringName(uint32(i), shnStrings, true); -} +func (i SectionIndex) String() string { return stringName(uint32(i), shnStrings, false) } +func (i SectionIndex) GoString() string { return stringName(uint32(i), shnStrings, true) } // Section type. type SectionType uint32 @@ -409,12 +381,8 @@ var shtStrings = []intName{ intName{0xffffffff, "SHT_HIUSER"}, } -func (i SectionType) String() string { - return stringName(uint32(i), shtStrings, false); -} -func (i SectionType) GoString() string { - return stringName(uint32(i), shtStrings, true); -} +func (i SectionType) String() string { return stringName(uint32(i), shtStrings, false) } +func (i SectionType) GoString() string { return stringName(uint32(i), shtStrings, true) } // Section flags. type SectionFlag uint32 @@ -447,12 +415,8 @@ var shfStrings = []intName{ intName{0x400, "SHF_TLS"}, } -func (i SectionFlag) String() string { - return flagName(uint32(i), shfStrings, false); -} -func (i SectionFlag) GoString() string { - return flagName(uint32(i), shfStrings, true); -} +func (i SectionFlag) String() string { return flagName(uint32(i), shfStrings, false) } +func (i SectionFlag) GoString() string { return flagName(uint32(i), shfStrings, true) } // Prog.Type type ProgType int @@ -487,12 +451,8 @@ var ptStrings = []intName{ intName{0x7fffffff, "PT_HIPROC"}, } -func (i ProgType) String() string { - return stringName(uint32(i), ptStrings, false); -} -func (i ProgType) GoString() string { - return stringName(uint32(i), ptStrings, true); -} +func (i ProgType) String() string { return stringName(uint32(i), ptStrings, false) } +func (i ProgType) GoString() string { return stringName(uint32(i), ptStrings, true) } // Prog.Flag type ProgFlag uint32 @@ -511,12 +471,8 @@ var pfStrings = []intName{ intName{0x4, "PF_R"}, } -func (i ProgFlag) String() string { - return flagName(uint32(i), pfStrings, false); -} -func (i ProgFlag) GoString() string { - return flagName(uint32(i), pfStrings, true); -} +func (i ProgFlag) String() string { return flagName(uint32(i), pfStrings, false) } +func (i ProgFlag) GoString() string { return flagName(uint32(i), pfStrings, true) } // Dyn.Tag type DynTag int @@ -607,12 +563,8 @@ var dtStrings = []intName{ intName{0x7fffffff, "DT_HIPROC"}, } -func (i DynTag) String() string { - return stringName(uint32(i), dtStrings, false); -} -func (i DynTag) GoString() string { - return stringName(uint32(i), dtStrings, true); -} +func (i DynTag) String() string { return stringName(uint32(i), dtStrings, false) } +func (i DynTag) GoString() string { return stringName(uint32(i), dtStrings, true) } // DT_FLAGS values. type DynFlag int @@ -640,12 +592,8 @@ var dflagStrings = []intName{ intName{0x0010, "DF_STATIC_TLS"}, } -func (i DynFlag) String() string { - return flagName(uint32(i), dflagStrings, false); -} -func (i DynFlag) GoString() string { - return flagName(uint32(i), dflagStrings, true); -} +func (i DynFlag) String() string { return flagName(uint32(i), dflagStrings, false) } +func (i DynFlag) GoString() string { return flagName(uint32(i), dflagStrings, true) } // NType values; used in core files. type NType int @@ -662,12 +610,8 @@ var ntypeStrings = []intName{ intName{3, "NT_PRPSINFO"}, } -func (i NType) String() string { - return stringName(uint32(i), ntypeStrings, false); -} -func (i NType) GoString() string { - return stringName(uint32(i), ntypeStrings, true); -} +func (i NType) String() string { return stringName(uint32(i), ntypeStrings, false) } +func (i NType) GoString() string { return stringName(uint32(i), ntypeStrings, true) } /* Symbol Binding - ELFNN_ST_BIND - st_info */ type SymBind int @@ -692,12 +636,8 @@ var stbStrings = []intName{ intName{15, "STB_HIPROC"}, } -func (i SymBind) String() string { - return stringName(uint32(i), stbStrings, false); -} -func (i SymBind) GoString() string { - return stringName(uint32(i), stbStrings, true); -} +func (i SymBind) String() string { return stringName(uint32(i), stbStrings, false) } +func (i SymBind) GoString() string { return stringName(uint32(i), stbStrings, true) } /* Symbol type - ELFNN_ST_TYPE - st_info */ type SymType int @@ -730,12 +670,8 @@ var sttStrings = []intName{ intName{15, "STT_HIPROC"}, } -func (i SymType) String() string { - return stringName(uint32(i), sttStrings, false); -} -func (i SymType) GoString() string { - return stringName(uint32(i), sttStrings, true); -} +func (i SymType) String() string { return stringName(uint32(i), sttStrings, false) } +func (i SymType) GoString() string { return stringName(uint32(i), sttStrings, true) } /* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */ type SymVis int @@ -754,12 +690,8 @@ var stvStrings = []intName{ intName{0x3, "STV_PROTECTED"}, } -func (i SymVis) String() string { - return stringName(uint32(i), stvStrings, false); -} -func (i SymVis) GoString() string { - return stringName(uint32(i), stvStrings, true); -} +func (i SymVis) String() string { return stringName(uint32(i), stvStrings, false) } +func (i SymVis) GoString() string { return stringName(uint32(i), stvStrings, true) } /* * Relocation types. @@ -822,12 +754,8 @@ var rx86_64Strings = []intName{ intName{23, "R_X86_64_TPOFF32"}, } -func (i R_X86_64) String() string { - return stringName(uint32(i), rx86_64Strings, false); -} -func (i R_X86_64) GoString() string { - return stringName(uint32(i), rx86_64Strings, true); -} +func (i R_X86_64) String() string { return stringName(uint32(i), rx86_64Strings, false) } +func (i R_X86_64) GoString() string { return stringName(uint32(i), rx86_64Strings, true) } // Relocation types for Alpha. type R_ALPHA int @@ -894,12 +822,8 @@ var ralphaStrings = []intName{ intName{27, "R_ALPHA_RELATIVE"}, } -func (i R_ALPHA) String() string { - return stringName(uint32(i), ralphaStrings, false); -} -func (i R_ALPHA) GoString() string { - return stringName(uint32(i), ralphaStrings, true); -} +func (i R_ALPHA) String() string { return stringName(uint32(i), ralphaStrings, false) } +func (i R_ALPHA) GoString() string { return stringName(uint32(i), ralphaStrings, true) } // Relocation types for ARM. type R_ARM int @@ -976,12 +900,8 @@ var rarmStrings = []intName{ intName{255, "R_ARM_RBASE"}, } -func (i R_ARM) String() string { - return stringName(uint32(i), rarmStrings, false); -} -func (i R_ARM) GoString() string { - return stringName(uint32(i), rarmStrings, true); -} +func (i R_ARM) String() string { return stringName(uint32(i), rarmStrings, false) } +func (i R_ARM) GoString() string { return stringName(uint32(i), rarmStrings, true) } // Relocation types for 386. type R_386 int @@ -1054,12 +974,8 @@ var r386Strings = []intName{ intName{37, "R_386_TLS_TPOFF32"}, } -func (i R_386) String() string { - return stringName(uint32(i), r386Strings, false); -} -func (i R_386) GoString() string { - return stringName(uint32(i), r386Strings, true); -} +func (i R_386) String() string { return stringName(uint32(i), r386Strings, false) } +func (i R_386) GoString() string { return stringName(uint32(i), r386Strings, true) } // Relocation types for PowerPC. type R_PPC int @@ -1226,12 +1142,8 @@ var rppcStrings = []intName{ intName{116, "R_PPC_EMB_RELSDA"}, } -func (i R_PPC) String() string { - return stringName(uint32(i), rppcStrings, false); -} -func (i R_PPC) GoString() string { - return stringName(uint32(i), rppcStrings, true); -} +func (i R_PPC) String() string { return stringName(uint32(i), rppcStrings, false) } +func (i R_PPC) GoString() string { return stringName(uint32(i), rppcStrings, true) } // Relocation types for SPARC. type R_SPARC int @@ -1354,12 +1266,8 @@ var rsparcStrings = []intName{ intName{55, "R_SPARC_UA16"}, } -func (i R_SPARC) String() string { - return stringName(uint32(i), rsparcStrings, false); -} -func (i R_SPARC) GoString() string { - return stringName(uint32(i), rsparcStrings, true); -} +func (i R_SPARC) String() string { return stringName(uint32(i), rsparcStrings, false) } +func (i R_SPARC) GoString() string { return stringName(uint32(i), rsparcStrings, true) } /* * Magic number for the elf trampoline, chosen wisely to be an immediate @@ -1443,15 +1351,9 @@ type Rela32 struct { Addend int32; /* Addend. */ } -func R_SYM32(info uint32) uint32 { - return uint32(info>>8); -} -func R_TYPE32(info uint32) uint32 { - return uint32(info&0xff); -} -func R_INFO32(sym, typ uint32) uint32 { - return sym<<8 | typ; -} +func R_SYM32(info uint32) uint32 { return uint32(info>>8) } +func R_TYPE32(info uint32) uint32 { return uint32(info&0xff) } +func R_INFO32(sym, typ uint32) uint32 { return sym<<8 | typ } // ELF32 Symbol. type Sym32 struct { @@ -1465,15 +1367,9 @@ type Sym32 struct { const Sym32Size = 16 -func ST_BIND(info uint8) SymBind { - return SymBind(info>>4); -} -func ST_TYPE(bind SymBind, typ SymType) uint8 { - return uint8(bind)<<4 | uint8(typ)&0xf; -} -func ST_VISIBILITY(other uint8) SymVis { - return SymVis(other&3); -} +func ST_BIND(info uint8) SymBind { return SymBind(info>>4) } +func ST_TYPE(bind SymBind, typ SymType) uint8 { return uint8(bind)<<4 | uint8(typ)&0xf } +func ST_VISIBILITY(other uint8) SymVis { return SymVis(other&3) } /* * ELF64 @@ -1558,15 +1454,9 @@ type Rela64 struct { Addend int64; /* Addend. */ } -func R_SYM64(info uint64) uint32 { - return uint32(info>>32); -} -func R_TYPE64(info uint64) uint32 { - return uint32(info); -} -func R_INFO(sym, typ uint32) uint64 { - return uint64(sym)<<32 | uint64(typ); -} +func R_SYM64(info uint64) uint32 { return uint32(info>>32) } +func R_TYPE64(info uint64) uint32 { return uint32(info) } +func R_INFO(sym, typ uint32) uint64 { return uint64(sym)<<32 | uint64(typ) } /* diff --git a/src/pkg/debug/elf/file.go b/src/pkg/debug/elf/file.go index 0945eb506..c51f9bd16 100644 --- a/src/pkg/debug/elf/file.go +++ b/src/pkg/debug/elf/file.go @@ -76,9 +76,7 @@ func (s *Section) Data() ([]byte, os.Error) { } // Open returns a new ReadSeeker reading the ELF section. -func (s *Section) Open() io.ReadSeeker { - return io.NewSectionReader(s.sr, 0, 1<<63 - 1); -} +func (s *Section) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63 - 1) } // A ProgHeader represents a single ELF program header. type ProgHeader struct { @@ -106,9 +104,7 @@ type Prog struct { } // Open returns a new ReadSeeker reading the ELF program body. -func (p *Prog) Open() io.ReadSeeker { - return io.NewSectionReader(p.sr, 0, 1<<63 - 1); -} +func (p *Prog) Open() io.ReadSeeker { return io.NewSectionReader(p.sr, 0, 1<<63 - 1) } // A Symbol represents an entry in an ELF symbol table section. type Symbol struct { diff --git a/src/pkg/debug/gosym/symtab.go b/src/pkg/debug/gosym/symtab.go index 153465ae4..cb9b1f4eb 100644 --- a/src/pkg/debug/gosym/symtab.go +++ b/src/pkg/debug/gosym/symtab.go @@ -35,9 +35,7 @@ type Sym struct { } // Static returns whether this symbol is static (not visible outside its file). -func (s *Sym) Static() bool { - return s.Type >= 'a'; -} +func (s *Sym) Static() bool { return s.Type >= 'a' } // PackageName returns the package part of the symbol name, // or the empty string if there is none. @@ -518,9 +516,7 @@ func (o *Obj) alineFromLine(path string, line int) (int, os.Error) { // the symbol table. type UnknownFileError string -func (e UnknownFileError) String() string { - return "unknown file: " + string(e); -} +func (e UnknownFileError) String() string { return "unknown file: " + string(e) } // UnknownLineError represents a failure to map a line to a program // counter, either because the line is beyond the bounds of the file diff --git a/src/pkg/debug/macho/file.go b/src/pkg/debug/macho/file.go index 3561e03fd..52ba94fd7 100644 --- a/src/pkg/debug/macho/file.go +++ b/src/pkg/debug/macho/file.go @@ -35,9 +35,7 @@ type Load interface { // A LoadBytes is the uninterpreted bytes of a Mach-O load command. type LoadBytes []byte -func (b LoadBytes) Raw() []byte { - return b; -} +func (b LoadBytes) Raw() []byte { return b } // A SegmentHeader is the header for a Mach-O 32-bit or 64-bit load segment command. type SegmentHeader struct { @@ -77,9 +75,7 @@ func (s *Segment) Data() ([]byte, os.Error) { } // Open returns a new ReadSeeker reading the segment. -func (s *Segment) Open() io.ReadSeeker { - return io.NewSectionReader(s.sr, 0, 1<<63 - 1); -} +func (s *Segment) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63 - 1) } type SectionHeader struct { Name string; @@ -114,9 +110,7 @@ func (s *Section) Data() ([]byte, os.Error) { } // Open returns a new ReadSeeker reading the Mach-O section. -func (s *Section) Open() io.ReadSeeker { - return io.NewSectionReader(s.sr, 0, 1<<63 - 1); -} +func (s *Section) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63 - 1) } /* diff --git a/src/pkg/debug/macho/macho.go b/src/pkg/debug/macho/macho.go index 4903f1345..d8fbba376 100644 --- a/src/pkg/debug/macho/macho.go +++ b/src/pkg/debug/macho/macho.go @@ -51,12 +51,8 @@ var cpuStrings = []intName{ intName{uint32(CpuAmd64), "CpuAmd64"}, } -func (i Cpu) String() string { - return stringName(uint32(i), cpuStrings, false); -} -func (i Cpu) GoString() string { - return stringName(uint32(i), cpuStrings, true); -} +func (i Cpu) String() string { return stringName(uint32(i), cpuStrings, false) } +func (i Cpu) GoString() string { return stringName(uint32(i), cpuStrings, true) } // A LoadCmd is a Mach-O load command. type LoadCmd uint32 @@ -75,12 +71,8 @@ var cmdStrings = []intName{ intName{uint32(LoadCmdUnixThread), "LoadCmdUnixThread"}, } -func (i LoadCmd) String() string { - return stringName(uint32(i), cmdStrings, false); -} -func (i LoadCmd) GoString() string { - return stringName(uint32(i), cmdStrings, true); -} +func (i LoadCmd) String() string { return stringName(uint32(i), cmdStrings, false) } +func (i LoadCmd) GoString() string { return stringName(uint32(i), cmdStrings, true) } // A Segment64 is a 64-bit Mach-O segment load command. type Segment64 struct { diff --git a/src/pkg/debug/proc/proc.go b/src/pkg/debug/proc/proc.go index 084228b24..0719ebef3 100644 --- a/src/pkg/debug/proc/proc.go +++ b/src/pkg/debug/proc/proc.go @@ -151,18 +151,14 @@ type Process interface { // stop. type Stopped struct{} -func (c Stopped) String() string { - return "stopped"; -} +func (c Stopped) String() string { return "stopped" } // Breakpoint is a stop cause resulting from a thread reaching a set // breakpoint. type Breakpoint Word // PC returns the program counter that the program is stopped at. -func (c Breakpoint) PC() Word { - return Word(c); -} +func (c Breakpoint) PC() Word { return Word(c) } func (c Breakpoint) String() string { return "breakpoint at 0x" + strconv.Uitob64(uint64(c.PC()), 16); @@ -173,13 +169,9 @@ func (c Breakpoint) String() string { type Signal string // Signal returns the signal being delivered to the thread. -func (c Signal) Name() string { - return string(c); -} +func (c Signal) Name() string { return string(c) } -func (c Signal) String() string { - return c.Name(); -} +func (c Signal) String() string { return c.Name() } // ThreadCreate is a stop cause returned from an existing thread when // it creates a new thread. The new thread exists in a primordial @@ -189,13 +181,9 @@ type ThreadCreate struct { thread Thread; } -func (c *ThreadCreate) NewThread() Thread { - return c.thread; -} +func (c *ThreadCreate) NewThread() Thread { return c.thread } -func (c *ThreadCreate) String() string { - return "thread create"; -} +func (c *ThreadCreate) String() string { return "thread create" } // ThreadExit is a stop cause resulting from a thread exiting. When // this cause first arises, the thread will still be in the list of @@ -207,26 +195,18 @@ type ThreadExit struct { } // Exited returns true if the thread exited normally. -func (c *ThreadExit) Exited() bool { - return c.exitStatus != -1; -} +func (c *ThreadExit) Exited() bool { return c.exitStatus != -1 } // ExitStatus returns the exit status of the thread if it exited // normally or -1 otherwise. -func (c *ThreadExit) ExitStatus() int { - return c.exitStatus; -} +func (c *ThreadExit) ExitStatus() int { return c.exitStatus } // Signaled returns true if the thread was terminated by a signal. -func (c *ThreadExit) Signaled() bool { - return c.exitStatus == -1; -} +func (c *ThreadExit) Signaled() bool { return c.exitStatus == -1 } // StopSignal returns the signal that terminated the thread, or "" if // it was not terminated by a signal. -func (c *ThreadExit) StopSignal() string { - return c.signal; -} +func (c *ThreadExit) StopSignal() string { return c.signal } func (c *ThreadExit) String() string { res := "thread exited "; diff --git a/src/pkg/debug/proc/proc_linux.go b/src/pkg/debug/proc/proc_linux.go index 60a0555e9..ac469ecad 100644 --- a/src/pkg/debug/proc/proc_linux.go +++ b/src/pkg/debug/proc/proc_linux.go @@ -84,17 +84,11 @@ func (ts threadState) isStopped() bool { return ts == stopped || ts == stoppedBreakpoint || ts == stoppedSignal || ts == stoppedThreadCreate || ts == stoppedExiting; } -func (ts threadState) isZombie() bool { - return ts == exiting; -} +func (ts threadState) isZombie() bool { return ts == exiting } -func (ts threadState) isTerminal() bool { - return ts == exited || ts == detached; -} +func (ts threadState) isTerminal() bool { return ts == exited || ts == detached } -func (ts threadState) String() string { - return string(ts); -} +func (ts threadState) String() string { return string(ts) } /* * Basic types @@ -206,9 +200,7 @@ func (e breakpointExistsError) String() string { type noBreakpointError Word -func (e noBreakpointError) String() string { - return fmt.Sprintf("no breakpoint at PC %#x", e); -} +func (e noBreakpointError) String() string { return fmt.Sprintf("no breakpoint at PC %#x", e) } type newThreadError struct { *os.Waitmsg; @@ -222,9 +214,7 @@ func (e *newThreadError) String() string { type ProcessExited struct{} -func (p ProcessExited) String() string { - return "process exited"; -} +func (p ProcessExited) String() string { return "process exited" } /* * Ptrace wrappers diff --git a/src/pkg/debug/proc/regs_linux_386.go b/src/pkg/debug/proc/regs_linux_386.go index 496fbc337..a665cd4d1 100644 --- a/src/pkg/debug/proc/regs_linux_386.go +++ b/src/pkg/debug/proc/regs_linux_386.go @@ -34,9 +34,7 @@ var names = [...]string{ "gs", } -func (r *_386Regs) PC() Word { - return Word(r.Eip); -} +func (r *_386Regs) PC() Word { return Word(r.Eip) } func (r *_386Regs) SetPC(val Word) os.Error { r.Eip = int32(val); @@ -48,22 +46,16 @@ func (r *_386Regs) Link() Word { panic("No link register"); } -func (r *_386Regs) SetLink(val Word) os.Error { - panic("No link register"); -} +func (r *_386Regs) SetLink(val Word) os.Error { panic("No link register") } -func (r *_386Regs) SP() Word { - return Word(r.Esp); -} +func (r *_386Regs) SP() Word { return Word(r.Esp) } func (r *_386Regs) SetSP(val Word) os.Error { r.Esp = int32(val); return r.setter(&r.PtraceRegs); } -func (r *_386Regs) Names() []string { - return &names; -} +func (r *_386Regs) Names() []string { return &names } func (r *_386Regs) Get(i int) Word { switch i { diff --git a/src/pkg/debug/proc/regs_linux_amd64.go b/src/pkg/debug/proc/regs_linux_amd64.go index 068add85d..64559dc9e 100644 --- a/src/pkg/debug/proc/regs_linux_amd64.go +++ b/src/pkg/debug/proc/regs_linux_amd64.go @@ -48,9 +48,7 @@ var names = [...]string{ //"gs_base", } -func (r *amd64Regs) PC() Word { - return Word(r.Rip); -} +func (r *amd64Regs) PC() Word { return Word(r.Rip) } func (r *amd64Regs) SetPC(val Word) os.Error { r.Rip = uint64(val); @@ -66,18 +64,14 @@ func (r *amd64Regs) SetLink(val Word) os.Error { panic("No link register"); } -func (r *amd64Regs) SP() Word { - return Word(r.Rsp); -} +func (r *amd64Regs) SP() Word { return Word(r.Rsp) } func (r *amd64Regs) SetSP(val Word) os.Error { r.Rsp = uint64(val); return r.setter(&r.PtraceRegs); } -func (r *amd64Regs) Names() []string { - return &names; -} +func (r *amd64Regs) Names() []string { return &names } func (r *amd64Regs) Get(i int) Word { switch i { diff --git a/src/pkg/debug/proc/regs_linux_arm.go b/src/pkg/debug/proc/regs_linux_arm.go index ac4bfb4f0..ed2834f69 100644 --- a/src/pkg/debug/proc/regs_linux_arm.go +++ b/src/pkg/debug/proc/regs_linux_arm.go @@ -13,37 +13,21 @@ import ( type armRegs struct{} -func (r *armRegs) PC() Word { - return Word(0); -} +func (r *armRegs) PC() Word { return Word(0) } -func (r *armRegs) SetPC(val Word) os.Error { - return nil; -} +func (r *armRegs) SetPC(val Word) os.Error { return nil } -func (r *armRegs) Link() Word { - return Word(0); -} +func (r *armRegs) Link() Word { return Word(0) } -func (r *armRegs) SetLink(val Word) os.Error { - return nil; -} +func (r *armRegs) SetLink(val Word) os.Error { return nil } -func (r *armRegs) SP() Word { - return Word(0); -} +func (r *armRegs) SP() Word { return Word(0) } -func (r *armRegs) SetSP(val Word) os.Error { - return nil; -} +func (r *armRegs) SetSP(val Word) os.Error { return nil } -func (r *armRegs) Names() []string { - return nil; -} +func (r *armRegs) Names() []string { return nil } -func (r *armRegs) Get(i int) Word { - return Word(0); -} +func (r *armRegs) Get(i int) Word { return Word(0) } func (r *armRegs) Set(i int, val Word) os.Error { return nil; diff --git a/src/pkg/ebnf/ebnf.go b/src/pkg/ebnf/ebnf.go index 1561b7b02..fdbb4b1ea 100644 --- a/src/pkg/ebnf/ebnf.go +++ b/src/pkg/ebnf/ebnf.go @@ -106,14 +106,10 @@ func (x Sequence) Pos() token.Position { } -func (x Range) Pos() token.Position { - return x.Begin.Pos(); -} +func (x Range) Pos() token.Position { return x.Begin.Pos() } -func (p *Production) Pos() token.Position { - return p.Name.Pos(); -} +func (p *Production) Pos() token.Position { return p.Name.Pos() } // ---------------------------------------------------------------------------- diff --git a/src/pkg/encoding/ascii85/ascii85.go b/src/pkg/encoding/ascii85/ascii85.go index adf1fe7dd..a1d9f7a7a 100644 --- a/src/pkg/encoding/ascii85/ascii85.go +++ b/src/pkg/encoding/ascii85/ascii85.go @@ -84,18 +84,14 @@ func Encode(dst, src []byte) int { } // MaxEncodedLen returns the maximum length of an encoding of n source bytes. -func MaxEncodedLen(n int) int { - return (n+3)/4*5; -} +func MaxEncodedLen(n int) int { return (n+3)/4*5 } // NewEncoder returns a new ascii85 stream encoder. Data written to // the returned writer will be encoded and then written to w. // Ascii85 encodings operate in 32-bit blocks; when finished // writing, the caller must Close the returned encoder to flush any // trailing partial block. -func NewEncoder(w io.Writer) io.WriteCloser { - return &encoder{w: w}; -} +func NewEncoder(w io.Writer) io.WriteCloser { return &encoder{w: w} } type encoder struct { err os.Error; @@ -248,9 +244,7 @@ func Decode(dst, src []byte, flush bool) (ndst, nsrc int, err os.Error) { } // NewDecoder constructs a new ascii85 stream decoder. -func NewDecoder(r io.Reader) io.Reader { - return &decoder{r: r}; -} +func NewDecoder(r io.Reader) io.Reader { return &decoder{r: r} } type decoder struct { err os.Error; diff --git a/src/pkg/encoding/base64/base64.go b/src/pkg/encoding/base64/base64.go index 9079f74fe..33010aa1b 100644 --- a/src/pkg/encoding/base64/base64.go +++ b/src/pkg/encoding/base64/base64.go @@ -189,9 +189,7 @@ func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser { // EncodedLen returns the length in bytes of the base64 encoding // of an input buffer of length n. -func (enc *Encoding) EncodedLen(n int) int { - return (n+2)/3*4; -} +func (enc *Encoding) EncodedLen(n int) int { return (n+2)/3*4 } /* * Decoder @@ -329,6 +327,4 @@ func NewDecoder(enc *Encoding, r io.Reader) io.Reader { // DecodeLen returns the maximum length in bytes of the decoded data // corresponding to n bytes of base64-encoded data. -func (enc *Encoding) DecodedLen(n int) int { - return n/4*3; -} +func (enc *Encoding) DecodedLen(n int) int { return n/4*3 } diff --git a/src/pkg/encoding/binary/binary.go b/src/pkg/encoding/binary/binary.go index c49879c66..6907fa02c 100644 --- a/src/pkg/encoding/binary/binary.go +++ b/src/pkg/encoding/binary/binary.go @@ -34,9 +34,7 @@ var BigEndian ByteOrder = bigEndian(0) type littleEndian unused -func (littleEndian) Uint16(b []byte) uint16 { - return uint16(b[0]) | uint16(b[1])<<8; -} +func (littleEndian) Uint16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])<<8 } func (littleEndian) PutUint16(b []byte, v uint16) { b[0] = byte(v); @@ -70,19 +68,13 @@ func (littleEndian) PutUint64(b []byte, v uint64) { b[7] = byte(v>>56); } -func (littleEndian) String() string { - return "LittleEndian"; -} +func (littleEndian) String() string { return "LittleEndian" } -func (littleEndian) GoString() string { - return "binary.LittleEndian"; -} +func (littleEndian) GoString() string { return "binary.LittleEndian" } type bigEndian unused -func (bigEndian) Uint16(b []byte) uint16 { - return uint16(b[1]) | uint16(b[0])<<8; -} +func (bigEndian) Uint16(b []byte) uint16 { return uint16(b[1]) | uint16(b[0])<<8 } func (bigEndian) PutUint16(b []byte, v uint16) { b[0] = byte(v>>8); @@ -116,13 +108,9 @@ func (bigEndian) PutUint64(b []byte, v uint64) { b[7] = byte(v); } -func (bigEndian) String() string { - return "BigEndian"; -} +func (bigEndian) String() string { return "BigEndian" } -func (bigEndian) GoString() string { - return "binary.BigEndian"; -} +func (bigEndian) GoString() string { return "binary.BigEndian" } // Read reads structured binary data from r into data. // Data must be a pointer to a fixed-size value. @@ -218,21 +206,13 @@ func (d *decoder) uint64() uint64 { return x; } -func (d *decoder) int8() int8 { - return int8(d.uint8()); -} +func (d *decoder) int8() int8 { return int8(d.uint8()) } -func (d *decoder) int16() int16 { - return int16(d.uint16()); -} +func (d *decoder) int16() int16 { return int16(d.uint16()) } -func (d *decoder) int32() int32 { - return int32(d.uint32()); -} +func (d *decoder) int32() int32 { return int32(d.uint32()) } -func (d *decoder) int64() int64 { - return int64(d.uint64()); -} +func (d *decoder) int64() int64 { return int64(d.uint64()) } func (d *decoder) value(v reflect.Value) { switch v := v.(type) { diff --git a/src/pkg/encoding/git85/git.go b/src/pkg/encoding/git85/git.go index 51e4654dd..e49251fb3 100644 --- a/src/pkg/encoding/git85/git.go +++ b/src/pkg/encoding/git85/git.go @@ -142,18 +142,14 @@ func Decode(dst, src []byte) (n int, err os.Error) { return ndst, nil; } -func MaxDecodedLen(n int) int { - return n/5*4; -} +func MaxDecodedLen(n int) int { return n/5*4 } // NewEncoder returns a new GIT base85 stream encoder. Data written to // the returned writer will be encoded and then written to w. // The GIT encoding operates on 52-byte blocks; when finished // writing, the caller must Close the returned encoder to flush any // partially written blocks. -func NewEncoder(w io.Writer) io.WriteCloser { - return &encoder{w: w}; -} +func NewEncoder(w io.Writer) io.WriteCloser { return &encoder{w: w} } type encoder struct { w io.Writer; @@ -224,9 +220,7 @@ func (e *encoder) Close() os.Error { } // NewDecoder returns a new GIT base85 stream decoder. -func NewDecoder(r io.Reader) io.Reader { - return &decoder{r: r}; -} +func NewDecoder(r io.Reader) io.Reader { return &decoder{r: r} } type decoder struct { r io.Reader; diff --git a/src/pkg/encoding/hex/hex.go b/src/pkg/encoding/hex/hex.go index 77aa13305..ff55dd489 100644 --- a/src/pkg/encoding/hex/hex.go +++ b/src/pkg/encoding/hex/hex.go @@ -14,9 +14,7 @@ import ( const hextable = "0123456789abcdef" // EncodedLen returns the length of an encoding of n source bytes. -func EncodedLen(n int) int { - return n*2; -} +func EncodedLen(n int) int { return n*2 } // Encode encodes src into EncodedLen(len(src)) // bytes of dst. As a convenience, it returns the number @@ -34,9 +32,7 @@ func Encode(dst, src []byte) int { // OddLengthInputError results from decoding an odd length slice. type OddLengthInputError struct{} -func (OddLengthInputError) String() string { - return "odd length hex string"; -} +func (OddLengthInputError) String() string { return "odd length hex string" } // InvalidHexCharError results from finding an invalid character in a hex string. type InvalidHexCharError byte @@ -46,9 +42,7 @@ func (e InvalidHexCharError) String() string { } -func DecodedLen(x int) int { - return x/2; -} +func DecodedLen(x int) int { return x/2 } // Decode decodes src into DecodedLen(len(src)) bytes, returning the actual // number of bytes written to dst. diff --git a/src/pkg/exp/4s/4s.go b/src/pkg/exp/4s/4s.go index f5eb14b6a..fbe8c5f0a 100644 --- a/src/pkg/exp/4s/4s.go +++ b/src/pkg/exp/4s/4s.go @@ -70,9 +70,7 @@ func audioServer() { } } -func PlaySound(b []uint16) { - sndc <- b; -} +func PlaySound(b []uint16) { sndc <- b } var whoosh = []uint16{ // Insert your favorite sound samples here. diff --git a/src/pkg/exp/datafmt/datafmt.go b/src/pkg/exp/datafmt/datafmt.go index bea3a49e6..28c9e7449 100644 --- a/src/pkg/exp/datafmt/datafmt.go +++ b/src/pkg/exp/datafmt/datafmt.go @@ -332,17 +332,13 @@ func newState(fmt Format, env Environment, errors chan os.Error) *State { // Env returns the environment passed to Format.Apply. -func (s *State) Env() interface{} { - return s.env; -} +func (s *State) Env() interface{} { return s.env } // LinePos returns the position of the current line beginning // in the state's output buffer. Line numbers start at 1. // -func (s *State) LinePos() token.Position { - return s.linePos; -} +func (s *State) LinePos() token.Position { return s.linePos } // Pos returns the position of the next byte to be written to the diff --git a/src/pkg/exp/datafmt/datafmt_test.go b/src/pkg/exp/datafmt/datafmt_test.go index af4adfa9f..c43cca2b7 100644 --- a/src/pkg/exp/datafmt/datafmt_test.go +++ b/src/pkg/exp/datafmt/datafmt_test.go @@ -236,9 +236,7 @@ const F1 = `datafmt "datafmt";` `int = "%d";` `datafmt.T1 = "<" a ">";` -func TestStruct1(t *testing.T) { - check(t, F1, "<42>", T1{42}); -} +func TestStruct1(t *testing.T) { check(t, F1, "<42>", T1{42}) } // ---------------------------------------------------------------------------- @@ -354,9 +352,7 @@ func TestStructPoint(t *testing.T) { const FSlice = `int = "%b";` `array = { * / ", " }` -func TestSlice(t *testing.T) { - check(t, FSlice, "10, 11, 101, 111", []int{2, 3, 5, 7}); -} +func TestSlice(t *testing.T) { check(t, FSlice, "10, 11, 101, 111", []int{2, 3, 5, 7}) } // TODO add more tests diff --git a/src/pkg/exp/draw/arith.go b/src/pkg/exp/draw/arith.go index 43aefbaad..314754ea9 100644 --- a/src/pkg/exp/draw/arith.go +++ b/src/pkg/exp/draw/arith.go @@ -21,44 +21,28 @@ type Rectangle struct { var ZR Rectangle // Pt is shorthand for Point{X, Y}. -func Pt(X, Y int) Point { - return Point{X, Y}; -} +func Pt(X, Y int) Point { return Point{X, Y} } // Rect is shorthand for Rectangle{Pt(x0, y0), Pt(x1, y1)}. -func Rect(x0, y0, x1, y1 int) Rectangle { - return Rectangle{Point{x0, y0}, Point{x1, y1}}; -} +func Rect(x0, y0, x1, y1 int) Rectangle { return Rectangle{Point{x0, y0}, Point{x1, y1}} } // Rpt is shorthand for Rectangle{min, max}. -func Rpt(min, max Point) Rectangle { - return Rectangle{min, max}; -} +func Rpt(min, max Point) Rectangle { return Rectangle{min, max} } // Add returns the sum of p and q: Pt(p.X+q.X, p.Y+q.Y). -func (p Point) Add(q Point) Point { - return Point{p.X + q.X, p.Y + q.Y}; -} +func (p Point) Add(q Point) Point { return Point{p.X + q.X, p.Y + q.Y} } // Sub returns the difference of p and q: Pt(p.X-q.X, p.Y-q.Y). -func (p Point) Sub(q Point) Point { - return Point{p.X - q.X, p.Y - q.Y}; -} +func (p Point) Sub(q Point) Point { return Point{p.X - q.X, p.Y - q.Y} } // Mul returns p scaled by k: Pt(p.X*k p.Y*k). -func (p Point) Mul(k int) Point { - return Point{p.X * k, p.Y * k}; -} +func (p Point) Mul(k int) Point { return Point{p.X * k, p.Y * k} } // Div returns p divided by k: Pt(p.X/k, p.Y/k). -func (p Point) Div(k int) Point { - return Point{p.X / k, p.Y / k}; -} +func (p Point) Div(k int) Point { return Point{p.X / k, p.Y / k} } // Eq returns true if p and q are equal. -func (p Point) Eq(q Point) bool { - return p.X == q.X && p.Y == q.Y; -} +func (p Point) Eq(q Point) bool { return p.X == q.X && p.Y == q.Y } // Inset returns the rectangle r inset by n: Rect(r.Min.X+n, r.Min.Y+n, r.Max.X-n, r.Max.Y-n). func (r Rectangle) Inset(n int) Rectangle { @@ -66,14 +50,10 @@ func (r Rectangle) Inset(n int) Rectangle { } // Add returns the rectangle r translated by p: Rpt(r.Min.Add(p), r.Max.Add(p)). -func (r Rectangle) Add(p Point) Rectangle { - return Rectangle{r.Min.Add(p), r.Max.Add(p)}; -} +func (r Rectangle) Add(p Point) Rectangle { return Rectangle{r.Min.Add(p), r.Max.Add(p)} } // Sub returns the rectangle r translated by -p: Rpt(r.Min.Sub(p), r.Max.Sub(p)). -func (r Rectangle) Sub(p Point) Rectangle { - return Rectangle{r.Min.Sub(p), r.Max.Sub(p)}; -} +func (r Rectangle) Sub(p Point) Rectangle { return Rectangle{r.Min.Sub(p), r.Max.Sub(p)} } // Canon returns a canonical version of r: the returned rectangle // has Min.X <= Max.X and Min.Y <= Max.Y. @@ -94,9 +74,7 @@ func (r Rectangle) Overlaps(r1 Rectangle) bool { } // Empty retruns true if r contains no points. -func (r Rectangle) Empty() bool { - return r.Max.X <= r.Min.X || r.Max.Y <= r.Min.Y; -} +func (r Rectangle) Empty() bool { return r.Max.X <= r.Min.X || r.Max.Y <= r.Min.Y } // InRect returns true if all the points in r are also in r1. func (r Rectangle) In(r1 Rectangle) bool { @@ -157,11 +135,7 @@ func (r Rectangle) Clip(r1 Rectangle) Rectangle { } // Dx returns the width of the rectangle r: r.Max.X - r.Min.X. -func (r Rectangle) Dx() int { - return r.Max.X - r.Min.X; -} +func (r Rectangle) Dx() int { return r.Max.X - r.Min.X } // Dy returns the width of the rectangle r: r.Max.Y - r.Min.Y. -func (r Rectangle) Dy() int { - return r.Max.Y - r.Min.Y; -} +func (r Rectangle) Dy() int { return r.Max.Y - r.Min.Y } diff --git a/src/pkg/exp/draw/color.go b/src/pkg/exp/draw/color.go index db772c7ad..310f70e30 100644 --- a/src/pkg/exp/draw/color.go +++ b/src/pkg/exp/draw/color.go @@ -92,17 +92,11 @@ func (c Color) SetAlpha(a uint8) Color { return r<<24 | g<<16 | b<<8 | Color(a); } -func (c Color) Width() int { - return 1e9; -} +func (c Color) Width() int { return 1e9 } -func (c Color) Height() int { - return 1e9; -} +func (c Color) Height() int { return 1e9 } -func (c Color) At(x, y int) image.Color { - return c; -} +func (c Color) At(x, y int) image.Color { return c } func toColor(color image.Color) image.Color { if c, ok := color.(Color); ok { @@ -112,6 +106,4 @@ func toColor(color image.Color) image.Color { return Color(r>>24<<24 | g>>24<<16 | b>>24<<8 | a>>24); } -func (c Color) ColorModel() image.ColorModel { - return image.ColorModelFunc(toColor); -} +func (c Color) ColorModel() image.ColorModel { return image.ColorModelFunc(toColor) } diff --git a/src/pkg/exp/eval/abort.go b/src/pkg/exp/eval/abort.go index 346722c8c..6cac2175a 100644 --- a/src/pkg/exp/eval/abort.go +++ b/src/pkg/exp/eval/abort.go @@ -37,15 +37,11 @@ func (t *Thread) Try(f func(t *Thread)) os.Error { type DivByZeroError struct{} -func (DivByZeroError) String() string { - return "divide by zero"; -} +func (DivByZeroError) String() string { return "divide by zero" } type NilPointerError struct{} -func (NilPointerError) String() string { - return "nil pointer dereference"; -} +func (NilPointerError) String() string { return "nil pointer dereference" } type IndexError struct { Idx, Len int64; @@ -70,9 +66,7 @@ type KeyError struct { Key interface{}; } -func (e KeyError) String() string { - return fmt.Sprintf("key '%v' not found in map", e.Key); -} +func (e KeyError) String() string { return fmt.Sprintf("key '%v' not found in map", e.Key) } type NegativeLengthError struct { Len int64; diff --git a/src/pkg/exp/eval/bridge.go b/src/pkg/exp/eval/bridge.go index d4bf2b888..d10aade9e 100644 --- a/src/pkg/exp/eval/bridge.go +++ b/src/pkg/exp/eval/bridge.go @@ -130,9 +130,7 @@ func TypeFromNative(t reflect.Type) Type { } // TypeOfNative returns the interpreter Type of a regular Go value. -func TypeOfNative(v interface{}) Type { - return TypeFromNative(reflect.Typeof(v)); -} +func TypeOfNative(v interface{}) Type { return TypeFromNative(reflect.Typeof(v)) } /* * Function bridging diff --git a/src/pkg/exp/eval/compiler.go b/src/pkg/exp/eval/compiler.go index 9d57d7abe..f349b836f 100644 --- a/src/pkg/exp/eval/compiler.go +++ b/src/pkg/exp/eval/compiler.go @@ -32,9 +32,7 @@ func (a *compiler) diagAt(pos positioned, format string, args ...) { a.numErrors++; } -func (a *compiler) numError() int { - return a.numErrors + a.silentErrors; -} +func (a *compiler) numError() int { return a.numErrors + a.silentErrors } // The universal scope func newUniverse() *Scope { diff --git a/src/pkg/exp/eval/eval_test.go b/src/pkg/exp/eval/eval_test.go index 4d711bfc4..307c50486 100644 --- a/src/pkg/exp/eval/eval_test.go +++ b/src/pkg/exp/eval/eval_test.go @@ -17,9 +17,7 @@ import ( // Print each statement or expression before parsing it var noisy = false -func init() { - flag.BoolVar(&noisy, "noisy", false, "chatter during eval tests"); -} +func init() { flag.BoolVar(&noisy, "noisy", false, "chatter during eval tests") } /* * Generic statement/expression test framework @@ -104,14 +102,10 @@ func match(t *testing.T, err os.Error, pat string) bool { */ // Expression compile error -func CErr(expr string, cerr string) test { - return test([]job{job{code: expr, cerr: cerr}}); -} +func CErr(expr string, cerr string) test { return test([]job{job{code: expr, cerr: cerr}}) } // Expression runtime error -func RErr(expr string, rterr string) test { - return test([]job{job{code: expr, rterr: rterr}}); -} +func RErr(expr string, rterr string) test { return test([]job{job{code: expr, rterr: rterr}}) } // Expression value func Val(expr string, val interface{}) test { @@ -119,9 +113,7 @@ func Val(expr string, val interface{}) test { } // Statement runs without error -func Run(stmts string) test { - return test([]job{job{code: stmts, noval: true}}); -} +func Run(stmts string) test { return test([]job{job{code: stmts, noval: true}}) } // Two statements without error. // TODO(rsc): Should be possible with Run but the parser @@ -213,9 +205,7 @@ func toValue(val interface{}) Value { type testFunc struct{} -func (*testFunc) NewFrame() *Frame { - return &Frame{nil, &[2]Value{}}; -} +func (*testFunc) NewFrame() *Frame { return &Frame{nil, &[2]Value{}} } func (*testFunc) Call(t *Thread) { n := t.f.Vars[0].(IntValue).Get(t); @@ -227,9 +217,7 @@ func (*testFunc) Call(t *Thread) { type oneTwoFunc struct{} -func (*oneTwoFunc) NewFrame() *Frame { - return &Frame{nil, &[2]Value{}}; -} +func (*oneTwoFunc) NewFrame() *Frame { return &Frame{nil, &[2]Value{}} } func (*oneTwoFunc) Call(t *Thread) { t.f.Vars[0].(IntValue).Set(t, 1); @@ -238,12 +226,9 @@ func (*oneTwoFunc) Call(t *Thread) { type voidFunc struct{} -func (*voidFunc) NewFrame() *Frame { - return &Frame{nil, []Value{}}; -} +func (*voidFunc) NewFrame() *Frame { return &Frame{nil, []Value{}} } -func (*voidFunc) Call(t *Thread) { -} +func (*voidFunc) Call(t *Thread) {} func newTestWorld() *World { w := NewWorld(); diff --git a/src/pkg/exp/eval/expr.go b/src/pkg/exp/eval/expr.go index c2b0dbf7b..af6259a78 100644 --- a/src/pkg/exp/eval/expr.go +++ b/src/pkg/exp/eval/expr.go @@ -402,9 +402,7 @@ func (a *assignCompiler) compile(b *block, lt Type) (func(Value, *Thread)) { rf := a.rs[i].asPtr(); a.rs[i] = a.rs[i].newExpr(lt, a.rs[i].desc); len := at.Len; - a.rs[i].eval = func(t *Thread) Slice { - return Slice{rf(t).(ArrayValue), len, len}; - }; + a.rs[i].eval = func(t *Thread) Slice { return Slice{rf(t).(ArrayValue), len, len} }; rt = a.rs[i].t; } } @@ -1592,17 +1590,13 @@ func (a *exprInfo) compileBinaryExpr(op token.Token, l, r *expr) *expr { // Useful type predicates // TODO(austin) CL 33668 mandates identical types except for comparisons. compat := func() bool { return l.t.compat(r.t, false) }; - integers := func() bool { - return l.t.isInteger() && r.t.isInteger(); - }; + integers := func() bool { return l.t.isInteger() && r.t.isInteger() }; floats := func() bool { return l.t.isFloat() && r.t.isFloat() }; strings := func() bool { // TODO(austin) Deal with named types return l.t == StringType && r.t == StringType; }; - booleans := func() bool { - return l.t.isBoolean() && r.t.isBoolean(); - }; + booleans := func() bool { return l.t.isBoolean() && r.t.isBoolean() }; // Type check var t Type; diff --git a/src/pkg/exp/eval/expr1.go b/src/pkg/exp/eval/expr1.go index 547ca380a..c77c99934 100644 --- a/src/pkg/exp/eval/expr1.go +++ b/src/pkg/exp/eval/expr1.go @@ -12,15 +12,11 @@ import ( * "As" functions. These retrieve evaluator functions from an * expr, panicking if the requested evaluator has the wrong type. */ -func (a *expr) asBool() (func(*Thread) bool) { - return a.eval.(func(*Thread) bool); -} +func (a *expr) asBool() (func(*Thread) bool) { return a.eval.(func(*Thread) bool) } func (a *expr) asUint() (func(*Thread) uint64) { return a.eval.(func(*Thread) uint64); } -func (a *expr) asInt() (func(*Thread) int64) { - return a.eval.(func(*Thread) int64); -} +func (a *expr) asInt() (func(*Thread) int64) { return a.eval.(func(*Thread) int64) } func (a *expr) asIdealInt() (func() *bignum.Integer) { return a.eval.(func() *bignum.Integer); } @@ -39,18 +35,12 @@ func (a *expr) asArray() (func(*Thread) ArrayValue) { func (a *expr) asStruct() (func(*Thread) StructValue) { return a.eval.(func(*Thread) StructValue); } -func (a *expr) asPtr() (func(*Thread) Value) { - return a.eval.(func(*Thread) Value); -} -func (a *expr) asFunc() (func(*Thread) Func) { - return a.eval.(func(*Thread) Func); -} +func (a *expr) asPtr() (func(*Thread) Value) { return a.eval.(func(*Thread) Value) } +func (a *expr) asFunc() (func(*Thread) Func) { return a.eval.(func(*Thread) Func) } func (a *expr) asSlice() (func(*Thread) Slice) { return a.eval.(func(*Thread) Slice); } -func (a *expr) asMap() (func(*Thread) Map) { - return a.eval.(func(*Thread) Map); -} +func (a *expr) asMap() (func(*Thread) Map) { return a.eval.(func(*Thread) Map) } func (a *expr) asMulti() (func(*Thread) []Value) { return a.eval.(func(*Thread) []Value); } @@ -132,49 +122,27 @@ func (a *expr) genIdentOp(level, index int) { a.evalAddr = func(t *Thread) Value { return t.f.Get(level, index) }; switch a.t.lit().(type) { case *boolType: - a.eval = func(t *Thread) bool { - return t.f.Get(level, index).(BoolValue).Get(t); - }; + a.eval = func(t *Thread) bool { return t.f.Get(level, index).(BoolValue).Get(t) }; case *uintType: - a.eval = func(t *Thread) uint64 { - return t.f.Get(level, index).(UintValue).Get(t); - }; + a.eval = func(t *Thread) uint64 { return t.f.Get(level, index).(UintValue).Get(t) }; case *intType: - a.eval = func(t *Thread) int64 { - return t.f.Get(level, index).(IntValue).Get(t); - }; + a.eval = func(t *Thread) int64 { return t.f.Get(level, index).(IntValue).Get(t) }; case *floatType: - a.eval = func(t *Thread) float64 { - return t.f.Get(level, index).(FloatValue).Get(t); - }; + a.eval = func(t *Thread) float64 { return t.f.Get(level, index).(FloatValue).Get(t) }; case *stringType: - a.eval = func(t *Thread) string { - return t.f.Get(level, index).(StringValue).Get(t); - }; + a.eval = func(t *Thread) string { return t.f.Get(level, index).(StringValue).Get(t) }; case *ArrayType: - a.eval = func(t *Thread) ArrayValue { - return t.f.Get(level, index).(ArrayValue).Get(t); - }; + a.eval = func(t *Thread) ArrayValue { return t.f.Get(level, index).(ArrayValue).Get(t) }; case *StructType: - a.eval = func(t *Thread) StructValue { - return t.f.Get(level, index).(StructValue).Get(t); - }; + a.eval = func(t *Thread) StructValue { return t.f.Get(level, index).(StructValue).Get(t) }; case *PtrType: - a.eval = func(t *Thread) Value { - return t.f.Get(level, index).(PtrValue).Get(t); - }; + a.eval = func(t *Thread) Value { return t.f.Get(level, index).(PtrValue).Get(t) }; case *FuncType: - a.eval = func(t *Thread) Func { - return t.f.Get(level, index).(FuncValue).Get(t); - }; + a.eval = func(t *Thread) Func { return t.f.Get(level, index).(FuncValue).Get(t) }; case *SliceType: - a.eval = func(t *Thread) Slice { - return t.f.Get(level, index).(SliceValue).Get(t); - }; + a.eval = func(t *Thread) Slice { return t.f.Get(level, index).(SliceValue).Get(t) }; case *MapType: - a.eval = func(t *Thread) Map { - return t.f.Get(level, index).(MapValue).Get(t); - }; + a.eval = func(t *Thread) Map { return t.f.Get(level, index).(MapValue).Get(t) }; default: log.Crashf("unexpected identifier type %v at %v", a.t, a.pos); } diff --git a/src/pkg/exp/eval/expr_test.go b/src/pkg/exp/eval/expr_test.go index 11d993af0..31ed530be 100644 --- a/src/pkg/exp/eval/expr_test.go +++ b/src/pkg/exp/eval/expr_test.go @@ -340,6 +340,4 @@ var exprTests = []test{ CErr("fn==oneTwo", opTypes), } -func TestExpr(t *testing.T) { - runTests(t, "exprTests", exprTests); -} +func TestExpr(t *testing.T) { runTests(t, "exprTests", exprTests) } diff --git a/src/pkg/exp/eval/func.go b/src/pkg/exp/eval/func.go index fac7b8629..103d2766d 100644 --- a/src/pkg/exp/eval/func.go +++ b/src/pkg/exp/eval/func.go @@ -40,9 +40,7 @@ type codeBuf struct { instrs code; } -func newCodeBuf() *codeBuf { - return &codeBuf{make(code, 0, 16)}; -} +func newCodeBuf() *codeBuf { return &codeBuf{make(code, 0, 16)} } func (b *codeBuf) push(instr func(*Thread)) { n := len(b.instrs); @@ -57,9 +55,7 @@ func (b *codeBuf) push(instr func(*Thread)) { b.instrs[n] = instr; } -func (b *codeBuf) nextPC() uint { - return uint(len(b.instrs)); -} +func (b *codeBuf) nextPC() uint { return uint(len(b.instrs)) } func (b *codeBuf) get() code { // Freeze this buffer into an array of exactly the right size @@ -80,10 +76,6 @@ type evalFunc struct { code code; } -func (f *evalFunc) NewFrame() *Frame { - return f.outer.child(f.frameSize); -} +func (f *evalFunc) NewFrame() *Frame { return f.outer.child(f.frameSize) } -func (f *evalFunc) Call(t *Thread) { - f.code.exec(t); -} +func (f *evalFunc) Call(t *Thread) { f.code.exec(t) } diff --git a/src/pkg/exp/eval/scope.go b/src/pkg/exp/eval/scope.go index 1c3d1f622..43df7cf63 100644 --- a/src/pkg/exp/eval/scope.go +++ b/src/pkg/exp/eval/scope.go @@ -121,9 +121,7 @@ func (b *block) DefineVar(name string, pos token.Position, t Type) (*Variable, D return v, nil; } -func (b *block) DefineTemp(t Type) *Variable { - return b.defineSlot(t, true); -} +func (b *block) DefineTemp(t Type) *Variable { return b.defineSlot(t, true) } func (b *block) defineSlot(t Type, temp bool) *Variable { if b.inner != nil && b.inner.scope == b.scope { @@ -175,9 +173,7 @@ func (b *block) Lookup(name string) (bl *block, level int, def Def) { return nil, 0, nil; } -func (s *Scope) NewFrame(outer *Frame) *Frame { - return outer.child(s.maxVars); -} +func (s *Scope) NewFrame(outer *Frame) *Frame { return outer.child(s.maxVars) } /* * Frames diff --git a/src/pkg/exp/eval/stmt.go b/src/pkg/exp/eval/stmt.go index 433073a01..b9dcfe550 100644 --- a/src/pkg/exp/eval/stmt.go +++ b/src/pkg/exp/eval/stmt.go @@ -89,9 +89,7 @@ func (f *flowBuf) put(cond bool, term bool, jumps []*uint) { // putTerm creates a flow control point at the next PC that // unconditionally terminates execution. -func (f *flowBuf) putTerm() { - f.put(false, true, nil); -} +func (f *flowBuf) putTerm() { f.put(false, true, nil) } // put1 creates a flow control point at the next PC that jumps to one // PC and, if cond is true, can also continue to the PC following the @@ -1222,9 +1220,7 @@ func (a *blockCompiler) enterChild() *blockCompiler { }; } -func (a *blockCompiler) exit() { - a.block.exit(); -} +func (a *blockCompiler) exit() { a.block.exit() } /* * Function compiler diff --git a/src/pkg/exp/eval/stmt_test.go b/src/pkg/exp/eval/stmt_test.go index 55cea6df3..0adea1e62 100644 --- a/src/pkg/exp/eval/stmt_test.go +++ b/src/pkg/exp/eval/stmt_test.go @@ -344,6 +344,4 @@ var stmtTests = []test{ Run2("func f1(){}", "f1()"), } -func TestStmt(t *testing.T) { - runTests(t, "stmtTests", stmtTests); -} +func TestStmt(t *testing.T) { runTests(t, "stmtTests", stmtTests) } diff --git a/src/pkg/exp/eval/type.go b/src/pkg/exp/eval/type.go index 261dcc3ce..85f96fb19 100644 --- a/src/pkg/exp/eval/type.go +++ b/src/pkg/exp/eval/type.go @@ -92,9 +92,7 @@ func hashTypeArray(key []Type) uintptr { return hash; } -func newTypeArrayMap() typeArrayMap { - return make(map[uintptr]*typeArrayMapEntry); -} +func newTypeArrayMap() typeArrayMap { return make(map[uintptr]*typeArrayMapEntry) } func (m typeArrayMap) Get(key []Type) interface{} { ent, ok := m[hashTypeArray(key)]; @@ -134,25 +132,15 @@ func (m typeArrayMap) Put(key []Type, v interface{}) interface{} { type commonType struct{} -func (commonType) isBoolean() bool { - return false; -} +func (commonType) isBoolean() bool { return false } -func (commonType) isInteger() bool { - return false; -} +func (commonType) isInteger() bool { return false } -func (commonType) isFloat() bool { - return false; -} +func (commonType) isFloat() bool { return false } -func (commonType) isIdeal() bool { - return false; -} +func (commonType) isIdeal() bool { return false } -func (commonType) Pos() token.Position { - return token.Position{}; -} +func (commonType) Pos() token.Position { return token.Position{} } /* * Bool @@ -169,13 +157,9 @@ func (t *boolType) compat(o Type, conv bool) bool { return ok; } -func (t *boolType) lit() Type { - return t; -} +func (t *boolType) lit() Type { return t } -func (t *boolType) isBoolean() bool { - return true; -} +func (t *boolType) isBoolean() bool { return true } func (boolType) String() string { // Use angle brackets as a convention for printing the @@ -219,17 +203,11 @@ func (t *uintType) compat(o Type, conv bool) bool { ; } -func (t *uintType) lit() Type { - return t; -} +func (t *uintType) lit() Type { return t } -func (t *uintType) isInteger() bool { - return true; -} +func (t *uintType) isInteger() bool { return true } -func (t *uintType) String() string { - return "<" + t.name + ">"; -} +func (t *uintType) String() string { return "<" + t.name + ">" } func (t *uintType) Zero() Value { switch t.Bits { @@ -257,9 +235,7 @@ func (t *uintType) Zero() Value { panic("unexpected uint bit count: ", t.Bits); } -func (t *uintType) minVal() *bignum.Rational { - return bignum.Rat(0, 1); -} +func (t *uintType) minVal() *bignum.Rational { return bignum.Rat(0, 1) } func (t *uintType) maxVal() *bignum.Rational { bits := t.Bits; @@ -304,17 +280,11 @@ func (t *intType) compat(o Type, conv bool) bool { return ok && t == t2; } -func (t *intType) lit() Type { - return t; -} +func (t *intType) lit() Type { return t } -func (t *intType) isInteger() bool { - return true; -} +func (t *intType) isInteger() bool { return true } -func (t *intType) String() string { - return "<" + t.name + ">"; -} +func (t *intType) String() string { return "<" + t.name + ">" } func (t *intType) Zero() Value { switch t.Bits { @@ -369,25 +339,15 @@ func (t *idealIntType) compat(o Type, conv bool) bool { return ok; } -func (t *idealIntType) lit() Type { - return t; -} +func (t *idealIntType) lit() Type { return t } -func (t *idealIntType) isInteger() bool { - return true; -} +func (t *idealIntType) isInteger() bool { return true } -func (t *idealIntType) isIdeal() bool { - return true; -} +func (t *idealIntType) isIdeal() bool { return true } -func (t *idealIntType) String() string { - return "ideal integer"; -} +func (t *idealIntType) String() string { return "ideal integer" } -func (t *idealIntType) Zero() Value { - return &idealIntV{bignum.Int(0)}; -} +func (t *idealIntType) Zero() Value { return &idealIntV{bignum.Int(0)} } /* * Float @@ -413,17 +373,11 @@ func (t *floatType) compat(o Type, conv bool) bool { return ok && t == t2; } -func (t *floatType) lit() Type { - return t; -} +func (t *floatType) lit() Type { return t } -func (t *floatType) isFloat() bool { - return true; -} +func (t *floatType) isFloat() bool { return true } -func (t *floatType) String() string { - return "<" + t.name + ">"; -} +func (t *floatType) String() string { return "<" + t.name + ">" } func (t *floatType) Zero() Value { switch t.Bits { @@ -490,25 +444,15 @@ func (t *idealFloatType) compat(o Type, conv bool) bool { return ok; } -func (t *idealFloatType) lit() Type { - return t; -} +func (t *idealFloatType) lit() Type { return t } -func (t *idealFloatType) isFloat() bool { - return true; -} +func (t *idealFloatType) isFloat() bool { return true } -func (t *idealFloatType) isIdeal() bool { - return true; -} +func (t *idealFloatType) isIdeal() bool { return true } -func (t *idealFloatType) String() string { - return "ideal float"; -} +func (t *idealFloatType) String() string { return "ideal float" } -func (t *idealFloatType) Zero() Value { - return &idealFloatV{bignum.Rat(1, 0)}; -} +func (t *idealFloatType) Zero() Value { return &idealFloatV{bignum.Rat(1, 0)} } /* * String @@ -525,13 +469,9 @@ func (t *stringType) compat(o Type, conv bool) bool { return ok; } -func (t *stringType) lit() Type { - return t; -} +func (t *stringType) lit() Type { return t } -func (t *stringType) String() string { - return "<string>"; -} +func (t *stringType) String() string { return "<string>" } func (t *stringType) Zero() Value { res := stringV(""); @@ -575,13 +515,9 @@ func (t *ArrayType) compat(o Type, conv bool) bool { return t.Len == t2.Len && t.Elem.compat(t2.Elem, conv); } -func (t *ArrayType) lit() Type { - return t; -} +func (t *ArrayType) lit() Type { return t } -func (t *ArrayType) String() string { - return "[]" + t.Elem.String(); -} +func (t *ArrayType) String() string { return "[]" + t.Elem.String() } func (t *ArrayType) Zero() Value { res := arrayV(make([]Value, t.Len)); @@ -682,9 +618,7 @@ func (t *StructType) compat(o Type, conv bool) bool { return true; } -func (t *StructType) lit() Type { - return t; -} +func (t *StructType) lit() Type { return t } func (t *StructType) String() string { s := "struct {"; @@ -738,17 +672,11 @@ func (t *PtrType) compat(o Type, conv bool) bool { return t.Elem.compat(t2.Elem, conv); } -func (t *PtrType) lit() Type { - return t; -} +func (t *PtrType) lit() Type { return t } -func (t *PtrType) String() string { - return "*" + t.Elem.String(); -} +func (t *PtrType) String() string { return "*" + t.Elem.String() } -func (t *PtrType) Zero() Value { - return &ptrV{nil}; -} +func (t *PtrType) Zero() Value { return &ptrV{nil} } /* * Function @@ -828,9 +756,7 @@ func (t *FuncType) compat(o Type, conv bool) bool { return true; } -func (t *FuncType) lit() Type { - return t; -} +func (t *FuncType) lit() Type { return t } func typeListString(ts []Type, ns []*ast.Ident) string { s := ""; @@ -869,9 +795,7 @@ func (t *FuncType) String() string { return s; } -func (t *FuncType) Zero() Value { - return &funcV{nil}; -} +func (t *FuncType) Zero() Value { return &funcV{nil} } type FuncDecl struct { Type *FuncType; @@ -978,17 +902,11 @@ func NewInterfaceType(methods []IMethod, embeds []*InterfaceType) *InterfaceType type iMethodSorter []IMethod -func (s iMethodSorter) Less(a, b int) bool { - return s[a].Name < s[b].Name; -} +func (s iMethodSorter) Less(a, b int) bool { return s[a].Name < s[b].Name } -func (s iMethodSorter) Swap(a, b int) { - s[a], s[b] = s[b], s[a]; -} +func (s iMethodSorter) Swap(a, b int) { s[a], s[b] = s[b], s[a] } -func (s iMethodSorter) Len() int { - return len(s); -} +func (s iMethodSorter) Len() int { return len(s) } func (t *InterfaceType) compat(o Type, conv bool) bool { t2, ok := o.lit().(*InterfaceType); @@ -1007,9 +925,7 @@ func (t *InterfaceType) compat(o Type, conv bool) bool { return true; } -func (t *InterfaceType) lit() Type { - return t; -} +func (t *InterfaceType) lit() Type { return t } func (t *InterfaceType) String() string { // TODO(austin) Instead of showing embedded interfaces, this @@ -1078,9 +994,7 @@ func (t *InterfaceType) implementedBy(o Type) (*IMethod, bool) { return &t.methods[0], false; } -func (t *InterfaceType) Zero() Value { - return &interfaceV{}; -} +func (t *InterfaceType) Zero() Value { return &interfaceV{} } /* * Slice @@ -1112,13 +1026,9 @@ func (t *SliceType) compat(o Type, conv bool) bool { return t.Elem.compat(t2.Elem, conv); } -func (t *SliceType) lit() Type { - return t; -} +func (t *SliceType) lit() Type { return t } -func (t *SliceType) String() string { - return "[]" + t.Elem.String(); -} +func (t *SliceType) String() string { return "[]" + t.Elem.String() } func (t *SliceType) Zero() Value { // The value of an uninitialized slice is nil. The length and @@ -1160,13 +1070,9 @@ func (t *MapType) compat(o Type, conv bool) bool { return t.Elem.compat(t2.Elem, conv) && t.Key.compat(t2.Key, conv); } -func (t *MapType) lit() Type { - return t; -} +func (t *MapType) lit() Type { return t } -func (t *MapType) String() string { - return "map[" + t.Key.String() + "] " + t.Elem.String(); -} +func (t *MapType) String() string { return "map[" + t.Key.String() + "] " + t.Elem.String() } func (t *MapType) Zero() Value { // The value of an uninitialized map is nil. @@ -1239,33 +1145,19 @@ func (t *NamedType) compat(o Type, conv bool) bool { return o.compat(t.Def, conv); } -func (t *NamedType) lit() Type { - return t.Def.lit(); -} +func (t *NamedType) lit() Type { return t.Def.lit() } -func (t *NamedType) isBoolean() bool { - return t.Def.isBoolean(); -} +func (t *NamedType) isBoolean() bool { return t.Def.isBoolean() } -func (t *NamedType) isInteger() bool { - return t.Def.isInteger(); -} +func (t *NamedType) isInteger() bool { return t.Def.isInteger() } -func (t *NamedType) isFloat() bool { - return t.Def.isFloat(); -} +func (t *NamedType) isFloat() bool { return t.Def.isFloat() } -func (t *NamedType) isIdeal() bool { - return false; -} +func (t *NamedType) isIdeal() bool { return false } -func (t *NamedType) String() string { - return t.Name; -} +func (t *NamedType) String() string { return t.Name } -func (t *NamedType) Zero() Value { - return t.Def.Zero(); -} +func (t *NamedType) Zero() Value { return t.Def.Zero() } /* * Multi-valued type @@ -1309,9 +1201,7 @@ func (t *MultiType) compat(o Type, conv bool) bool { var EmptyType Type = NewMultiType([]Type{}) -func (t *MultiType) lit() Type { - return t; -} +func (t *MultiType) lit() Type { return t } func (t *MultiType) String() string { if len(t.Elems) == 0 { diff --git a/src/pkg/exp/eval/typec.go b/src/pkg/exp/eval/typec.go index 53722f90b..d771adada 100644 --- a/src/pkg/exp/eval/typec.go +++ b/src/pkg/exp/eval/typec.go @@ -364,9 +364,7 @@ notimpl: * Type compiler interface */ -func noLateCheck() bool { - return true; -} +func noLateCheck() bool { return true } func (a *compiler) compileType(b *block, typ ast.Expr) Type { tc := &typeCompiler{a, b, noLateCheck}; diff --git a/src/pkg/exp/eval/value.go b/src/pkg/exp/eval/value.go index f4f0bba0b..d57920538 100644 --- a/src/pkg/exp/eval/value.go +++ b/src/pkg/exp/eval/value.go @@ -141,21 +141,13 @@ type MapValue interface { type boolV bool -func (v *boolV) String() string { - return fmt.Sprint(*v); -} +func (v *boolV) String() string { return fmt.Sprint(*v) } -func (v *boolV) Assign(t *Thread, o Value) { - *v = boolV(o.(BoolValue).Get(t)); -} +func (v *boolV) Assign(t *Thread, o Value) { *v = boolV(o.(BoolValue).Get(t)) } -func (v *boolV) Get(*Thread) bool { - return bool(*v); -} +func (v *boolV) Get(*Thread) bool { return bool(*v) } -func (v *boolV) Set(t *Thread, x bool) { - *v = boolV(x); -} +func (v *boolV) Set(t *Thread, x bool) { *v = boolV(x) } /* * Uint @@ -163,111 +155,63 @@ func (v *boolV) Set(t *Thread, x bool) { type uint8V uint8 -func (v *uint8V) String() string { - return fmt.Sprint(*v); -} +func (v *uint8V) String() string { return fmt.Sprint(*v) } -func (v *uint8V) Assign(t *Thread, o Value) { - *v = uint8V(o.(UintValue).Get(t)); -} +func (v *uint8V) Assign(t *Thread, o Value) { *v = uint8V(o.(UintValue).Get(t)) } -func (v *uint8V) Get(*Thread) uint64 { - return uint64(*v); -} +func (v *uint8V) Get(*Thread) uint64 { return uint64(*v) } -func (v *uint8V) Set(t *Thread, x uint64) { - *v = uint8V(x); -} +func (v *uint8V) Set(t *Thread, x uint64) { *v = uint8V(x) } type uint16V uint16 -func (v *uint16V) String() string { - return fmt.Sprint(*v); -} +func (v *uint16V) String() string { return fmt.Sprint(*v) } -func (v *uint16V) Assign(t *Thread, o Value) { - *v = uint16V(o.(UintValue).Get(t)); -} +func (v *uint16V) Assign(t *Thread, o Value) { *v = uint16V(o.(UintValue).Get(t)) } -func (v *uint16V) Get(*Thread) uint64 { - return uint64(*v); -} +func (v *uint16V) Get(*Thread) uint64 { return uint64(*v) } -func (v *uint16V) Set(t *Thread, x uint64) { - *v = uint16V(x); -} +func (v *uint16V) Set(t *Thread, x uint64) { *v = uint16V(x) } type uint32V uint32 -func (v *uint32V) String() string { - return fmt.Sprint(*v); -} +func (v *uint32V) String() string { return fmt.Sprint(*v) } -func (v *uint32V) Assign(t *Thread, o Value) { - *v = uint32V(o.(UintValue).Get(t)); -} +func (v *uint32V) Assign(t *Thread, o Value) { *v = uint32V(o.(UintValue).Get(t)) } -func (v *uint32V) Get(*Thread) uint64 { - return uint64(*v); -} +func (v *uint32V) Get(*Thread) uint64 { return uint64(*v) } -func (v *uint32V) Set(t *Thread, x uint64) { - *v = uint32V(x); -} +func (v *uint32V) Set(t *Thread, x uint64) { *v = uint32V(x) } type uint64V uint64 -func (v *uint64V) String() string { - return fmt.Sprint(*v); -} +func (v *uint64V) String() string { return fmt.Sprint(*v) } -func (v *uint64V) Assign(t *Thread, o Value) { - *v = uint64V(o.(UintValue).Get(t)); -} +func (v *uint64V) Assign(t *Thread, o Value) { *v = uint64V(o.(UintValue).Get(t)) } -func (v *uint64V) Get(*Thread) uint64 { - return uint64(*v); -} +func (v *uint64V) Get(*Thread) uint64 { return uint64(*v) } -func (v *uint64V) Set(t *Thread, x uint64) { - *v = uint64V(x); -} +func (v *uint64V) Set(t *Thread, x uint64) { *v = uint64V(x) } type uintV uint -func (v *uintV) String() string { - return fmt.Sprint(*v); -} +func (v *uintV) String() string { return fmt.Sprint(*v) } -func (v *uintV) Assign(t *Thread, o Value) { - *v = uintV(o.(UintValue).Get(t)); -} +func (v *uintV) Assign(t *Thread, o Value) { *v = uintV(o.(UintValue).Get(t)) } -func (v *uintV) Get(*Thread) uint64 { - return uint64(*v); -} +func (v *uintV) Get(*Thread) uint64 { return uint64(*v) } -func (v *uintV) Set(t *Thread, x uint64) { - *v = uintV(x); -} +func (v *uintV) Set(t *Thread, x uint64) { *v = uintV(x) } type uintptrV uintptr -func (v *uintptrV) String() string { - return fmt.Sprint(*v); -} +func (v *uintptrV) String() string { return fmt.Sprint(*v) } -func (v *uintptrV) Assign(t *Thread, o Value) { - *v = uintptrV(o.(UintValue).Get(t)); -} +func (v *uintptrV) Assign(t *Thread, o Value) { *v = uintptrV(o.(UintValue).Get(t)) } -func (v *uintptrV) Get(*Thread) uint64 { - return uint64(*v); -} +func (v *uintptrV) Get(*Thread) uint64 { return uint64(*v) } -func (v *uintptrV) Set(t *Thread, x uint64) { - *v = uintptrV(x); -} +func (v *uintptrV) Set(t *Thread, x uint64) { *v = uintptrV(x) } /* * Int @@ -275,93 +219,53 @@ func (v *uintptrV) Set(t *Thread, x uint64) { type int8V int8 -func (v *int8V) String() string { - return fmt.Sprint(*v); -} +func (v *int8V) String() string { return fmt.Sprint(*v) } -func (v *int8V) Assign(t *Thread, o Value) { - *v = int8V(o.(IntValue).Get(t)); -} +func (v *int8V) Assign(t *Thread, o Value) { *v = int8V(o.(IntValue).Get(t)) } -func (v *int8V) Get(*Thread) int64 { - return int64(*v); -} +func (v *int8V) Get(*Thread) int64 { return int64(*v) } -func (v *int8V) Set(t *Thread, x int64) { - *v = int8V(x); -} +func (v *int8V) Set(t *Thread, x int64) { *v = int8V(x) } type int16V int16 -func (v *int16V) String() string { - return fmt.Sprint(*v); -} +func (v *int16V) String() string { return fmt.Sprint(*v) } -func (v *int16V) Assign(t *Thread, o Value) { - *v = int16V(o.(IntValue).Get(t)); -} +func (v *int16V) Assign(t *Thread, o Value) { *v = int16V(o.(IntValue).Get(t)) } -func (v *int16V) Get(*Thread) int64 { - return int64(*v); -} +func (v *int16V) Get(*Thread) int64 { return int64(*v) } -func (v *int16V) Set(t *Thread, x int64) { - *v = int16V(x); -} +func (v *int16V) Set(t *Thread, x int64) { *v = int16V(x) } type int32V int32 -func (v *int32V) String() string { - return fmt.Sprint(*v); -} +func (v *int32V) String() string { return fmt.Sprint(*v) } -func (v *int32V) Assign(t *Thread, o Value) { - *v = int32V(o.(IntValue).Get(t)); -} +func (v *int32V) Assign(t *Thread, o Value) { *v = int32V(o.(IntValue).Get(t)) } -func (v *int32V) Get(*Thread) int64 { - return int64(*v); -} +func (v *int32V) Get(*Thread) int64 { return int64(*v) } -func (v *int32V) Set(t *Thread, x int64) { - *v = int32V(x); -} +func (v *int32V) Set(t *Thread, x int64) { *v = int32V(x) } type int64V int64 -func (v *int64V) String() string { - return fmt.Sprint(*v); -} +func (v *int64V) String() string { return fmt.Sprint(*v) } -func (v *int64V) Assign(t *Thread, o Value) { - *v = int64V(o.(IntValue).Get(t)); -} +func (v *int64V) Assign(t *Thread, o Value) { *v = int64V(o.(IntValue).Get(t)) } -func (v *int64V) Get(*Thread) int64 { - return int64(*v); -} +func (v *int64V) Get(*Thread) int64 { return int64(*v) } -func (v *int64V) Set(t *Thread, x int64) { - *v = int64V(x); -} +func (v *int64V) Set(t *Thread, x int64) { *v = int64V(x) } type intV int -func (v *intV) String() string { - return fmt.Sprint(*v); -} +func (v *intV) String() string { return fmt.Sprint(*v) } -func (v *intV) Assign(t *Thread, o Value) { - *v = intV(o.(IntValue).Get(t)); -} +func (v *intV) Assign(t *Thread, o Value) { *v = intV(o.(IntValue).Get(t)) } -func (v *intV) Get(*Thread) int64 { - return int64(*v); -} +func (v *intV) Get(*Thread) int64 { return int64(*v) } -func (v *intV) Set(t *Thread, x int64) { - *v = intV(x); -} +func (v *intV) Set(t *Thread, x int64) { *v = intV(x) } /* * Ideal int @@ -371,17 +275,13 @@ type idealIntV struct { V *bignum.Integer; } -func (v *idealIntV) String() string { - return v.V.String(); -} +func (v *idealIntV) String() string { return v.V.String() } func (v *idealIntV) Assign(t *Thread, o Value) { v.V = o.(IdealIntValue).Get(); } -func (v *idealIntV) Get() *bignum.Integer { - return v.V; -} +func (v *idealIntV) Get() *bignum.Integer { return v.V } /* * Float @@ -389,57 +289,33 @@ func (v *idealIntV) Get() *bignum.Integer { type float32V float32 -func (v *float32V) String() string { - return fmt.Sprint(*v); -} +func (v *float32V) String() string { return fmt.Sprint(*v) } -func (v *float32V) Assign(t *Thread, o Value) { - *v = float32V(o.(FloatValue).Get(t)); -} +func (v *float32V) Assign(t *Thread, o Value) { *v = float32V(o.(FloatValue).Get(t)) } -func (v *float32V) Get(*Thread) float64 { - return float64(*v); -} +func (v *float32V) Get(*Thread) float64 { return float64(*v) } -func (v *float32V) Set(t *Thread, x float64) { - *v = float32V(x); -} +func (v *float32V) Set(t *Thread, x float64) { *v = float32V(x) } type float64V float64 -func (v *float64V) String() string { - return fmt.Sprint(*v); -} +func (v *float64V) String() string { return fmt.Sprint(*v) } -func (v *float64V) Assign(t *Thread, o Value) { - *v = float64V(o.(FloatValue).Get(t)); -} +func (v *float64V) Assign(t *Thread, o Value) { *v = float64V(o.(FloatValue).Get(t)) } -func (v *float64V) Get(*Thread) float64 { - return float64(*v); -} +func (v *float64V) Get(*Thread) float64 { return float64(*v) } -func (v *float64V) Set(t *Thread, x float64) { - *v = float64V(x); -} +func (v *float64V) Set(t *Thread, x float64) { *v = float64V(x) } type floatV float -func (v *floatV) String() string { - return fmt.Sprint(*v); -} +func (v *floatV) String() string { return fmt.Sprint(*v) } -func (v *floatV) Assign(t *Thread, o Value) { - *v = floatV(o.(FloatValue).Get(t)); -} +func (v *floatV) Assign(t *Thread, o Value) { *v = floatV(o.(FloatValue).Get(t)) } -func (v *floatV) Get(*Thread) float64 { - return float64(*v); -} +func (v *floatV) Get(*Thread) float64 { return float64(*v) } -func (v *floatV) Set(t *Thread, x float64) { - *v = floatV(x); -} +func (v *floatV) Set(t *Thread, x float64) { *v = floatV(x) } /* * Ideal float @@ -449,17 +325,13 @@ type idealFloatV struct { V *bignum.Rational; } -func (v *idealFloatV) String() string { - return ratToString(v.V); -} +func (v *idealFloatV) String() string { return ratToString(v.V) } func (v *idealFloatV) Assign(t *Thread, o Value) { v.V = o.(IdealFloatValue).Get(); } -func (v *idealFloatV) Get() *bignum.Rational { - return v.V; -} +func (v *idealFloatV) Get() *bignum.Rational { return v.V } /* * String @@ -467,21 +339,13 @@ func (v *idealFloatV) Get() *bignum.Rational { type stringV string -func (v *stringV) String() string { - return fmt.Sprint(*v); -} +func (v *stringV) String() string { return fmt.Sprint(*v) } -func (v *stringV) Assign(t *Thread, o Value) { - *v = stringV(o.(StringValue).Get(t)); -} +func (v *stringV) Assign(t *Thread, o Value) { *v = stringV(o.(StringValue).Get(t)) } -func (v *stringV) Get(*Thread) string { - return string(*v); -} +func (v *stringV) Get(*Thread) string { return string(*v) } -func (v *stringV) Set(t *Thread, x string) { - *v = stringV(x); -} +func (v *stringV) Set(t *Thread, x string) { *v = stringV(x) } /* * Array @@ -508,9 +372,7 @@ func (v *arrayV) Assign(t *Thread, o Value) { } } -func (v *arrayV) Get(*Thread) ArrayValue { - return v; -} +func (v *arrayV) Get(*Thread) ArrayValue { return v } func (v *arrayV) Elem(t *Thread, i int64) Value { return (*v)[i]; @@ -548,9 +410,7 @@ func (v *structV) Assign(t *Thread, o Value) { } } -func (v *structV) Get(*Thread) StructValue { - return v; -} +func (v *structV) Get(*Thread) StructValue { return v } func (v *structV) Field(t *Thread, i int) Value { return (*v)[i]; @@ -572,17 +432,11 @@ func (v *ptrV) String() string { return "&" + v.target.String(); } -func (v *ptrV) Assign(t *Thread, o Value) { - v.target = o.(PtrValue).Get(t); -} +func (v *ptrV) Assign(t *Thread, o Value) { v.target = o.(PtrValue).Get(t) } -func (v *ptrV) Get(*Thread) Value { - return v.target; -} +func (v *ptrV) Get(*Thread) Value { return v.target } -func (v *ptrV) Set(t *Thread, x Value) { - v.target = x; -} +func (v *ptrV) Set(t *Thread, x Value) { v.target = x } /* * Functions @@ -597,17 +451,11 @@ func (v *funcV) String() string { return "func {...}"; } -func (v *funcV) Assign(t *Thread, o Value) { - v.target = o.(FuncValue).Get(t); -} +func (v *funcV) Assign(t *Thread, o Value) { v.target = o.(FuncValue).Get(t) } -func (v *funcV) Get(*Thread) Func { - return v.target; -} +func (v *funcV) Get(*Thread) Func { return v.target } -func (v *funcV) Set(t *Thread, x Func) { - v.target = x; -} +func (v *funcV) Set(t *Thread, x Func) { v.target = x } /* * Interfaces @@ -628,9 +476,7 @@ func (v *interfaceV) Assign(t *Thread, o Value) { v.Interface = o.(InterfaceValue).Get(t); } -func (v *interfaceV) Get(*Thread) Interface { - return v.Interface; -} +func (v *interfaceV) Get(*Thread) Interface { return v.Interface } func (v *interfaceV) Set(t *Thread, x Interface) { v.Interface = x; @@ -651,17 +497,11 @@ func (v *sliceV) String() string { return v.Base.Sub(0, v.Len).String(); } -func (v *sliceV) Assign(t *Thread, o Value) { - v.Slice = o.(SliceValue).Get(t); -} +func (v *sliceV) Assign(t *Thread, o Value) { v.Slice = o.(SliceValue).Get(t) } -func (v *sliceV) Get(*Thread) Slice { - return v.Slice; -} +func (v *sliceV) Get(*Thread) Slice { return v.Slice } -func (v *sliceV) Set(t *Thread, x Slice) { - v.Slice = x; -} +func (v *sliceV) Set(t *Thread, x Slice) { v.Slice = x } /* * Maps @@ -688,23 +528,15 @@ func (v *mapV) String() string { return res+"]"; } -func (v *mapV) Assign(t *Thread, o Value) { - v.target = o.(MapValue).Get(t); -} +func (v *mapV) Assign(t *Thread, o Value) { v.target = o.(MapValue).Get(t) } -func (v *mapV) Get(*Thread) Map { - return v.target; -} +func (v *mapV) Get(*Thread) Map { return v.target } -func (v *mapV) Set(t *Thread, x Map) { - v.target = x; -} +func (v *mapV) Set(t *Thread, x Map) { v.target = x } type evalMap map[interface{}]Value -func (m evalMap) Len(t *Thread) int64 { - return int64(len(m)); -} +func (m evalMap) Len(t *Thread) int64 { return int64(len(m)) } func (m evalMap) Elem(t *Thread, key interface{}) Value { if v, ok := m[key]; ok { diff --git a/src/pkg/exp/eval/world.go b/src/pkg/exp/eval/world.go index bf9af22ab..8218c24f5 100644 --- a/src/pkg/exp/eval/world.go +++ b/src/pkg/exp/eval/world.go @@ -81,9 +81,7 @@ func (w *World) CompileDeclList(decls []ast.Decl) (Code, os.Error) { return w.CompileStmtList(stmts); } -func (s *stmtCode) Type() Type { - return nil; -} +func (s *stmtCode) Type() Type { return nil } func (s *stmtCode) Run() (Value, os.Error) { t := new(Thread); @@ -120,9 +118,7 @@ func (w *World) CompileExpr(e ast.Expr) (Code, os.Error) { return &exprCode{w, ec, eval}, nil; } -func (e *exprCode) Type() Type { - return e.e.t; -} +func (e *exprCode) Type() Type { return e.e.t } func (e *exprCode) Run() (Value, os.Error) { t := new(Thread); diff --git a/src/pkg/exp/iterable/iterable_test.go b/src/pkg/exp/iterable/iterable_test.go index bc66ff5dd..fbb24f7b6 100644 --- a/src/pkg/exp/iterable/iterable_test.go +++ b/src/pkg/exp/iterable/iterable_test.go @@ -23,24 +23,12 @@ func (arr IntArray) Iter() <-chan interface{} { var oneToFive = IntArray{1, 2, 3, 4, 5} -func isNegative(n interface{}) bool { - return n.(int) < 0; -} -func isPositive(n interface{}) bool { - return n.(int) > 0; -} -func isAbove3(n interface{}) bool { - return n.(int) > 3; -} -func isEven(n interface{}) bool { - return n.(int) % 2 == 0; -} -func doubler(n interface{}) interface{} { - return n.(int) * 2; -} -func addOne(n interface{}) interface{} { - return n.(int) + 1; -} +func isNegative(n interface{}) bool { return n.(int) < 0 } +func isPositive(n interface{}) bool { return n.(int) > 0 } +func isAbove3(n interface{}) bool { return n.(int) > 3 } +func isEven(n interface{}) bool { return n.(int) % 2 == 0 } +func doubler(n interface{}) interface{} { return n.(int) * 2 } +func addOne(n interface{}) interface{} { return n.(int) + 1 } func adder(acc interface{}, n interface{}) interface{} { return acc.(int) + n.(int); } diff --git a/src/pkg/exp/nacl/av/av.go b/src/pkg/exp/nacl/av/av.go index 4c6312552..12801c631 100644 --- a/src/pkg/exp/nacl/av/av.go +++ b/src/pkg/exp/nacl/av/av.go @@ -54,25 +54,17 @@ type Window struct { // *Window implements draw.Context var _ draw.Context = (*Window)(nil) -func (w *Window) KeyboardChan() <-chan int { - return w.kbdc; -} +func (w *Window) KeyboardChan() <-chan int { return w.kbdc } func (w *Window) MouseChan() <-chan draw.Mouse { return w.mousec; } -func (w *Window) QuitChan() <-chan bool { - return w.quitc; -} +func (w *Window) QuitChan() <-chan bool { return w.quitc } -func (w *Window) ResizeChan() <-chan bool { - return w.resizec; -} +func (w *Window) ResizeChan() <-chan bool { return w.resizec } -func (w *Window) Screen() draw.Image { - return w.Image; -} +func (w *Window) Screen() draw.Image { return w.Image } // Init initializes the Native Client subsystems specified by subsys. // Init must be called before using any of the other functions @@ -223,9 +215,7 @@ var bridge struct { // so this blocks. Once the bridge is ready, multimediaBridge.Run // will drop a value into the channel. Then any calls // to waitBridge will finish, taking the value out and immediately putting it back. -func waitBridge() { - bridge.c <- <-bridge.c; -} +func waitBridge() { bridge.c <- <-bridge.c } const eqsize = 64 diff --git a/src/pkg/exp/nacl/av/image.go b/src/pkg/exp/nacl/av/image.go index 8bc8fd07b..e92ca8aeb 100644 --- a/src/pkg/exp/nacl/av/image.go +++ b/src/pkg/exp/nacl/av/image.go @@ -22,9 +22,7 @@ type Image struct { var _ image.Image = (*Image)(nil) -func (m *Image) ColorModel() image.ColorModel { - return ColorModel; -} +func (m *Image) ColorModel() image.ColorModel { return ColorModel } func (m *Image) Width() int { if len(m.Pixel) == 0 { @@ -33,13 +31,9 @@ func (m *Image) Width() int { return len(m.Pixel[0]); } -func (m *Image) Height() int { - return len(m.Pixel); -} +func (m *Image) Height() int { return len(m.Pixel) } -func (m *Image) At(x, y int) image.Color { - return m.Pixel[y][x]; -} +func (m *Image) At(x, y int) image.Color { return m.Pixel[y][x] } func (m *Image) Set(x, y int, color image.Color) { if c, ok := color.(Color); ok { diff --git a/src/pkg/exp/nacl/srpc/msg.go b/src/pkg/exp/nacl/srpc/msg.go index b0c8041a5..e6ab4aa8f 100644 --- a/src/pkg/exp/nacl/srpc/msg.go +++ b/src/pkg/exp/nacl/srpc/msg.go @@ -226,9 +226,7 @@ func (m *msg) grow(n int) []byte { return m.wdata[i : i+n]; } -func (m *msg) wuint8(x uint8) { - m.grow(1)[0] = x; -} +func (m *msg) wuint8(x uint8) { m.grow(1)[0] = x } func (m *msg) wuint32(x uint32) { b := m.grow(4); @@ -252,9 +250,7 @@ func (m *msg) wuint64(x uint64) { b[7] = byte(hi>>24); } -func (m *msg) wbytes(p []byte) { - bytes.Copy(m.grow(len(p)), p); -} +func (m *msg) wbytes(p []byte) { bytes.Copy(m.grow(len(p)), p) } func (m *msg) wstring(s string) { b := m.grow(len(s)); diff --git a/src/pkg/exp/nacl/srpc/server.go b/src/pkg/exp/nacl/srpc/server.go index 984aebeea..87b51a6f4 100644 --- a/src/pkg/exp/nacl/srpc/server.go +++ b/src/pkg/exp/nacl/srpc/server.go @@ -198,6 +198,4 @@ func (serviceDiscovery) Run(arg, ret []interface{}, size []int) Errno { return OK; } -func init() { - Add("service_discovery", ":C", serviceDiscovery{}); -} +func init() { Add("service_discovery", ":C", serviceDiscovery{}) } diff --git a/src/pkg/exp/ogle/arch.go b/src/pkg/exp/ogle/arch.go index 16ed4728c..20ce9f666 100644 --- a/src/pkg/exp/ogle/arch.go +++ b/src/pkg/exp/ogle/arch.go @@ -74,17 +74,11 @@ func (ArchLSB) ToFloat32(bits uint32) float32 { return math.Float32frombits(bits); } -func (ArchLSB) FromFloat32(f float32) uint32 { - return math.Float32bits(f); -} +func (ArchLSB) FromFloat32(f float32) uint32 { return math.Float32bits(f) } -func (ArchLSB) ToFloat64(bits uint64) float64 { - return math.Float64frombits(bits); -} +func (ArchLSB) ToFloat64(bits uint64) float64 { return math.Float64frombits(bits) } -func (ArchLSB) FromFloat64(f float64) uint64 { - return math.Float64bits(f); -} +func (ArchLSB) FromFloat64(f float64) uint64 { return math.Float64bits(f) } type ArchAlignedMultiple struct{} @@ -98,17 +92,11 @@ type amd64 struct { gReg int; } -func (a *amd64) IntSize() int { - return 4; -} +func (a *amd64) IntSize() int { return 4 } -func (a *amd64) PtrSize() int { - return 8; -} +func (a *amd64) PtrSize() int { return 8 } -func (a *amd64) FloatSize() int { - return 4; -} +func (a *amd64) FloatSize() int { return 4 } func (a *amd64) G(regs proc.Regs) proc.Word { // See src/pkg/runtime/mkasmh @@ -125,9 +113,7 @@ func (a *amd64) G(regs proc.Regs) proc.Word { return regs.Get(a.gReg); } -func (a *amd64) ClosureSize() int { - return 8; -} +func (a *amd64) ClosureSize() int { return 8 } func (a *amd64) ParseClosure(data []byte) (int, bool) { if data[0] == 0x48 && data[1] == 0x81 && data[2] == 0xc4 && data[7] == 0xc3 { diff --git a/src/pkg/exp/ogle/cmd.go b/src/pkg/exp/ogle/cmd.go index 4805c9243..4df546a27 100644 --- a/src/pkg/exp/ogle/cmd.go +++ b/src/pkg/exp/ogle/cmd.go @@ -76,9 +76,7 @@ func newScanner(input []byte) (*scanner.Scanner, *scanner.ErrorVector) { // A UsageError occurs when a command is called with illegal arguments. type UsageError string -func (e UsageError) String() string { - return string(e); -} +func (e UsageError) String() string { return string(e) } // A cmd represents a single command with a handler. type cmd struct { @@ -325,8 +323,7 @@ func printCurFrame() { } // fnOut moves the current frame to the caller of the current frame. -func fnOutSig() { -} +func fnOutSig() {} func fnOut(t *eval.Thread, args []eval.Value, res []eval.Value) { if curProc == nil { t.Abort(NoCurrentGoroutine{}); @@ -340,8 +337,7 @@ func fnOut(t *eval.Thread, args []eval.Value, res []eval.Value) { } // fnContWait continues the current process and waits for a stopping event. -func fnContWaitSig() { -} +func fnContWaitSig() {} func fnContWait(t *eval.Thread, args []eval.Value, res []eval.Value) { if curProc == nil { t.Abort(NoCurrentGoroutine{}); @@ -359,8 +355,7 @@ func fnContWait(t *eval.Thread, args []eval.Value, res []eval.Value) { } // fnBpSet sets a breakpoint at the entry to the named function. -func fnBpSetSig(string) { -} +func fnBpSetSig(string) {} func fnBpSet(t *eval.Thread, args []eval.Value, res []eval.Value) { // TODO(austin) This probably shouldn't take a symbol name. // Perhaps it should take an interface that provides PC's. diff --git a/src/pkg/exp/ogle/event.go b/src/pkg/exp/ogle/event.go index c66c791e2..898ab2762 100644 --- a/src/pkg/exp/ogle/event.go +++ b/src/pkg/exp/ogle/event.go @@ -114,9 +114,7 @@ func (h *commonHook) RemoveHandler(eh EventHandler) { } } -func (h *commonHook) NumHandler() int { - return h.len; -} +func (h *commonHook) NumHandler() int { return h.len } func (h *commonHook) handle(e Event) (EventAction, os.Error) { action := EADefault; @@ -151,13 +149,9 @@ type commonEvent struct { t *Goroutine; } -func (e *commonEvent) Process() *Process { - return e.p; -} +func (e *commonEvent) Process() *Process { return e.p } -func (e *commonEvent) Goroutine() *Goroutine { - return e.t; -} +func (e *commonEvent) Goroutine() *Goroutine { return e.t } /* * Standard event handlers @@ -229,9 +223,7 @@ func (h *breakpointHook) String() string { return fmt.Sprintf("breakpoint at %#x", h.pc); } -func (b *Breakpoint) PC() proc.Word { - return b.pc; -} +func (b *Breakpoint) PC() proc.Word { return b.pc } func (b *Breakpoint) String() string { // TODO(austin) Include process name and goroutine @@ -247,9 +239,7 @@ type goroutineCreateHook struct { commonHook; } -func (h *goroutineCreateHook) String() string { - return "goroutine create"; -} +func (h *goroutineCreateHook) String() string { return "goroutine create" } // A GoroutineCreate event occurs when a process creates a new // goroutine. When this event is handled, the current goroutine will @@ -261,9 +251,7 @@ type GoroutineCreate struct { // Parent returns the goroutine that created this goroutine. May be // nil if this event is the creation of the first goroutine. -func (e *GoroutineCreate) Parent() *Goroutine { - return e.parent; -} +func (e *GoroutineCreate) Parent() *Goroutine { return e.parent } func (e *GoroutineCreate) String() string { // TODO(austin) Include process name @@ -277,9 +265,7 @@ type goroutineExitHook struct { commonHook; } -func (h *goroutineExitHook) String() string { - return "goroutine exit"; -} +func (h *goroutineExitHook) String() string { return "goroutine exit" } // A GoroutineExit event occurs when a Go goroutine exits. type GoroutineExit struct { diff --git a/src/pkg/exp/ogle/frame.go b/src/pkg/exp/ogle/frame.go index d7fae6856..a0ba71e74 100644 --- a/src/pkg/exp/ogle/frame.go +++ b/src/pkg/exp/ogle/frame.go @@ -201,9 +201,7 @@ func (f *Frame) aOuter(a aborter) *Frame { // Inner returns the Frame called by this Frame, or nil if this is the // innermost frame. -func (f *Frame) Inner() *Frame { - return f.inner; -} +func (f *Frame) Inner() *Frame { return f.inner } func (f *Frame) String() string { res := f.fn.Name; diff --git a/src/pkg/exp/ogle/goroutine.go b/src/pkg/exp/ogle/goroutine.go index ad1b89334..683b70d19 100644 --- a/src/pkg/exp/ogle/goroutine.go +++ b/src/pkg/exp/ogle/goroutine.go @@ -28,9 +28,7 @@ func (t *Goroutine) String() string { } // isG0 returns true if this thread if the internal idle thread -func (t *Goroutine) isG0() bool { - return t.g.addr().base == t.g.r.p.sys.g0.addr().base; -} +func (t *Goroutine) isG0() bool { return t.g.addr().base == t.g.r.p.sys.g0.addr().base } func (t *Goroutine) resetFrame() (err os.Error) { // TODO(austin) Reuse any live part of the current frame stack diff --git a/src/pkg/exp/ogle/main.go b/src/pkg/exp/ogle/main.go index 88265624a..39e002978 100644 --- a/src/pkg/exp/ogle/main.go +++ b/src/pkg/exp/ogle/main.go @@ -6,6 +6,4 @@ package main import "exp/ogle" -func main() { - ogle.Main(); -} +func main() { ogle.Main() } diff --git a/src/pkg/exp/ogle/process.go b/src/pkg/exp/ogle/process.go index 07074992b..b2efbcd46 100644 --- a/src/pkg/exp/ogle/process.go +++ b/src/pkg/exp/ogle/process.go @@ -20,9 +20,7 @@ import ( // in the object file or runtime structures. type FormatError string -func (e FormatError) String() string { - return string(e); -} +func (e FormatError) String() string { return string(e) } // An UnknownArchitecture occurs when trying to load an object file // that indicates an architecture not supported by the debugger. @@ -36,9 +34,7 @@ func (e UnknownArchitecture) String() string { // memory or registers of a process that is not stopped. type ProcessNotStopped struct{} -func (e ProcessNotStopped) String() string { - return "process not stopped"; -} +func (e ProcessNotStopped) String() string { return "process not stopped" } // An UnknownGoroutine error is an internal error representing an // unrecognized G structure pointer. @@ -56,9 +52,7 @@ func (e UnknownGoroutine) String() string { // process). type NoCurrentGoroutine struct{} -func (e NoCurrentGoroutine) String() string { - return "no current goroutine"; -} +func (e NoCurrentGoroutine) String() string { return "no current goroutine" } // A Process represents a remote attached process. type Process struct { @@ -338,9 +332,7 @@ func (p *Process) OnGoroutineCreate() EventHook { } // OnGoroutineExit returns the hook that is run when a goroutine exits. -func (p *Process) OnGoroutineExit() EventHook { - return p.goroutineExitHook; -} +func (p *Process) OnGoroutineExit() EventHook { return p.goroutineExitHook } // osThreadToGoroutine looks up the goroutine running on an OS thread. func (p *Process) osThreadToGoroutine(t proc.Thread) (*Goroutine, os.Error) { @@ -475,9 +467,7 @@ func (p *Process) processEvent(ev Event) (EventAction, os.Error) { // may return nil if the process has never been stopped by an event. // // TODO(austin) Return nil if the user calls p.Stop()? -func (p *Process) Event() Event { - return p.event; -} +func (p *Process) Event() Event { return p.event } /* * Process control diff --git a/src/pkg/exp/ogle/rtype.go b/src/pkg/exp/ogle/rtype.go index 6d890fc92..0b05b1120 100644 --- a/src/pkg/exp/ogle/rtype.go +++ b/src/pkg/exp/ogle/rtype.go @@ -144,9 +144,7 @@ func parseRemoteType(a aborter, rs remoteStruct) *remoteType { } log.Stderrf("%sParsing type at %#x (%s)", prtIndent, addr, name); prtIndent += " "; - defer func() { - prtIndent = prtIndent[0 : len(prtIndent)-1]; - }(); + defer func() { prtIndent = prtIndent[0 : len(prtIndent)-1] }(); } // Get Type header diff --git a/src/pkg/exp/ogle/rvalue.go b/src/pkg/exp/ogle/rvalue.go index 1cfd8f78f..a01512ace 100644 --- a/src/pkg/exp/ogle/rvalue.go +++ b/src/pkg/exp/ogle/rvalue.go @@ -16,17 +16,13 @@ import ( // point to something in another process. type RemoteMismatchError string -func (e RemoteMismatchError) String() string { - return string(e); -} +func (e RemoteMismatchError) String() string { return string(e) } // A ReadOnlyError occurs when attempting to set or assign to a // read-only value. type ReadOnlyError string -func (e ReadOnlyError) String() string { - return string(e); -} +func (e ReadOnlyError) String() string { return string(e) } // A maker is a function that converts a remote address into an // interpreter Value. @@ -78,9 +74,7 @@ func (v remote) Set(a aborter, size int, x uint64) { } } -func (v remote) plus(x proc.Word) remote { - return remote{v.base + x, v.p}; -} +func (v remote) plus(x proc.Word) remote { return remote{v.base + x, v.p} } func tryRVString(f func(a aborter) string) string { var s string; @@ -107,13 +101,9 @@ func (v remoteBool) Assign(t *eval.Thread, o eval.Value) { v.Set(t, o.(eval.BoolValue).Get(t)); } -func (v remoteBool) Get(t *eval.Thread) bool { - return v.aGet(t); -} +func (v remoteBool) Get(t *eval.Thread) bool { return v.aGet(t) } -func (v remoteBool) aGet(a aborter) bool { - return v.r.Get(a, 1) != 0; -} +func (v remoteBool) aGet(a aborter) bool { return v.r.Get(a, 1) != 0 } func (v remoteBool) Set(t *eval.Thread, x bool) { v.aSet(t, x); @@ -127,13 +117,9 @@ func (v remoteBool) aSet(a aborter, x bool) { } } -func (v remoteBool) addr() remote { - return v.r; -} +func (v remoteBool) addr() remote { return v.r } -func mkBool(r remote) eval.Value { - return remoteBool{r}; -} +func mkBool(r remote) eval.Value { return remoteBool{r} } /* * Uint @@ -156,45 +142,27 @@ func (v remoteUint) Get(t *eval.Thread) uint64 { return v.aGet(t); } -func (v remoteUint) aGet(a aborter) uint64 { - return v.r.Get(a, v.size); -} +func (v remoteUint) aGet(a aborter) uint64 { return v.r.Get(a, v.size) } func (v remoteUint) Set(t *eval.Thread, x uint64) { v.aSet(t, x); } -func (v remoteUint) aSet(a aborter, x uint64) { - v.r.Set(a, v.size, x); -} +func (v remoteUint) aSet(a aborter, x uint64) { v.r.Set(a, v.size, x) } -func (v remoteUint) addr() remote { - return v.r; -} +func (v remoteUint) addr() remote { return v.r } -func mkUint8(r remote) eval.Value { - return remoteUint{r, 1}; -} +func mkUint8(r remote) eval.Value { return remoteUint{r, 1} } -func mkUint16(r remote) eval.Value { - return remoteUint{r, 2}; -} +func mkUint16(r remote) eval.Value { return remoteUint{r, 2} } -func mkUint32(r remote) eval.Value { - return remoteUint{r, 4}; -} +func mkUint32(r remote) eval.Value { return remoteUint{r, 4} } -func mkUint64(r remote) eval.Value { - return remoteUint{r, 8}; -} +func mkUint64(r remote) eval.Value { return remoteUint{r, 8} } -func mkUint(r remote) eval.Value { - return remoteUint{r, r.p.IntSize()}; -} +func mkUint(r remote) eval.Value { return remoteUint{r, r.p.IntSize()} } -func mkUintptr(r remote) eval.Value { - return remoteUint{r, r.p.PtrSize()}; -} +func mkUintptr(r remote) eval.Value { return remoteUint{r, r.p.PtrSize()} } /* * Int @@ -213,45 +181,27 @@ func (v remoteInt) Assign(t *eval.Thread, o eval.Value) { v.Set(t, o.(eval.IntValue).Get(t)); } -func (v remoteInt) Get(t *eval.Thread) int64 { - return v.aGet(t); -} +func (v remoteInt) Get(t *eval.Thread) int64 { return v.aGet(t) } -func (v remoteInt) aGet(a aborter) int64 { - return int64(v.r.Get(a, v.size)); -} +func (v remoteInt) aGet(a aborter) int64 { return int64(v.r.Get(a, v.size)) } func (v remoteInt) Set(t *eval.Thread, x int64) { v.aSet(t, x); } -func (v remoteInt) aSet(a aborter, x int64) { - v.r.Set(a, v.size, uint64(x)); -} +func (v remoteInt) aSet(a aborter, x int64) { v.r.Set(a, v.size, uint64(x)) } -func (v remoteInt) addr() remote { - return v.r; -} +func (v remoteInt) addr() remote { return v.r } -func mkInt8(r remote) eval.Value { - return remoteInt{r, 1}; -} +func mkInt8(r remote) eval.Value { return remoteInt{r, 1} } -func mkInt16(r remote) eval.Value { - return remoteInt{r, 2}; -} +func mkInt16(r remote) eval.Value { return remoteInt{r, 2} } -func mkInt32(r remote) eval.Value { - return remoteInt{r, 4}; -} +func mkInt32(r remote) eval.Value { return remoteInt{r, 4} } -func mkInt64(r remote) eval.Value { - return remoteInt{r, 8}; -} +func mkInt64(r remote) eval.Value { return remoteInt{r, 8} } -func mkInt(r remote) eval.Value { - return remoteInt{r, r.p.IntSize()}; -} +func mkInt(r remote) eval.Value { return remoteInt{r, r.p.IntSize()} } /* * Float @@ -302,21 +252,13 @@ func (v remoteFloat) aSet(a aborter, x float64) { v.r.Set(a, v.size, bits); } -func (v remoteFloat) addr() remote { - return v.r; -} +func (v remoteFloat) addr() remote { return v.r } -func mkFloat32(r remote) eval.Value { - return remoteFloat{r, 4}; -} +func mkFloat32(r remote) eval.Value { return remoteFloat{r, 4} } -func mkFloat64(r remote) eval.Value { - return remoteFloat{r, 8}; -} +func mkFloat64(r remote) eval.Value { return remoteFloat{r, 8} } -func mkFloat(r remote) eval.Value { - return remoteFloat{r, r.p.FloatSize()}; -} +func mkFloat(r remote) eval.Value { return remoteFloat{r, r.p.FloatSize()} } /* * String @@ -361,9 +303,7 @@ func (v remoteString) aSet(a aborter, x string) { a.Abort(ReadOnlyError("remote strings cannot be assigned to")); } -func mkString(r remote) eval.Value { - return remoteString{r}; -} +func mkString(r remote) eval.Value { return remoteString{r} } /* * Array @@ -458,9 +398,7 @@ func (v remoteStruct) field(i int) eval.Value { return f.fieldType.mk(v.r.plus(proc.Word(f.offset))); } -func (v remoteStruct) addr() remote { - return v.r; -} +func (v remoteStruct) addr() remote { return v.r } /* * Pointer @@ -517,9 +455,7 @@ func (v remotePtr) aSet(a aborter, x eval.Value) { v.r.Set(a, v.r.p.PtrSize(), uint64(xr.addr().base)); } -func (v remotePtr) addr() remote { - return v.r; -} +func (v remotePtr) addr() remote { return v.r } /* * Slice diff --git a/src/pkg/exp/ogle/vars.go b/src/pkg/exp/ogle/vars.go index 58ddbff16..74d540ce9 100644 --- a/src/pkg/exp/ogle/vars.go +++ b/src/pkg/exp/ogle/vars.go @@ -90,9 +90,7 @@ type remotePackage struct { defs []eval.Value; } -func (v remotePackage) String() string { - return "<remote package>"; -} +func (v remotePackage) String() string { return "<remote package>" } func (v remotePackage) Assign(t *eval.Thread, o eval.Value) { t.Abort(ReadOnlyError("remote packages cannot be assigned to")); @@ -208,9 +206,7 @@ func (p *Process) typeOfSym(s *gosym.Sym) (*remoteType, os.Error) { } addr := proc.Word(s.GoType); var rt *remoteType; - err := try(func(a aborter) { - rt = parseRemoteType(a, p.runtime.Type.mk(remote{addr, p}).(remoteStruct)); - }); + err := try(func(a aborter) { rt = parseRemoteType(a, p.runtime.Type.mk(remote{addr, p}).(remoteStruct)) }); if err != nil { return nil, err; } diff --git a/src/pkg/exp/spacewar/pdp1.go b/src/pkg/exp/spacewar/pdp1.go index ddffe7f40..02c3717e9 100644 --- a/src/pkg/exp/spacewar/pdp1.go +++ b/src/pkg/exp/spacewar/pdp1.go @@ -158,9 +158,7 @@ func (e HaltError) String() string { type LoopError Word -func (e LoopError) String() string { - return fmt.Sprintf("indirect load looping at %06o", e); -} +func (e LoopError) String() string { return fmt.Sprintf("indirect load looping at %06o", e) } func (m *M) run(inst Word, t Trapper) os.Error { ib, y := (inst>>12)&1, inst&07777; diff --git a/src/pkg/expvar/expvar.go b/src/pkg/expvar/expvar.go index 9a975fc1f..0c85df844 100644 --- a/src/pkg/expvar/expvar.go +++ b/src/pkg/expvar/expvar.go @@ -27,9 +27,7 @@ type Int struct { mu sync.Mutex; } -func (v *Int) String() string { - return strconv.Itoa64(v.i); -} +func (v *Int) String() string { return strconv.Itoa64(v.i) } func (v *Int) Add(delta int64) { v.mu.Lock(); @@ -120,21 +118,15 @@ type String struct { s string; } -func (v *String) String() string { - return strconv.Quote(v.s); -} +func (v *String) String() string { return strconv.Quote(v.s) } -func (v *String) Set(value string) { - v.s = value; -} +func (v *String) Set(value string) { v.s = value } // IntFunc wraps a func() int64 to create a value that satisfies the Var interface. // The function will be called each time the Var is evaluated. type IntFunc func() int64 -func (v IntFunc) String() string { - return strconv.Itoa64(v()); -} +func (v IntFunc) String() string { return strconv.Itoa64(v()) } // All published variables. @@ -217,6 +209,4 @@ func expvarHandler(c *http.Conn, req *http.Request) { fmt.Fprintf(c, "\n}\n"); } -func init() { - http.Handle("/debug/vars", http.HandlerFunc(expvarHandler)); -} +func init() { http.Handle("/debug/vars", http.HandlerFunc(expvarHandler)) } diff --git a/src/pkg/flag/flag.go b/src/pkg/flag/flag.go index 5dc698ce2..1f5f6434a 100644 --- a/src/pkg/flag/flag.go +++ b/src/pkg/flag/flag.go @@ -75,9 +75,7 @@ func (b *boolValue) set(s string) bool { return ok; } -func (b *boolValue) String() string { - return fmt.Sprintf("%v", *b.p); -} +func (b *boolValue) String() string { return fmt.Sprintf("%v", *b.p) } // -- Int Value type intValue struct { @@ -95,9 +93,7 @@ func (i *intValue) set(s string) bool { return err == nil; } -func (i *intValue) String() string { - return fmt.Sprintf("%v", *i.p); -} +func (i *intValue) String() string { return fmt.Sprintf("%v", *i.p) } // -- Int64 Value type int64Value struct { @@ -115,9 +111,7 @@ func (i *int64Value) set(s string) bool { return err == nil; } -func (i *int64Value) String() string { - return fmt.Sprintf("%v", *i.p); -} +func (i *int64Value) String() string { return fmt.Sprintf("%v", *i.p) } // -- Uint Value type uintValue struct { @@ -135,9 +129,7 @@ func (i *uintValue) set(s string) bool { return err == nil; } -func (i *uintValue) String() string { - return fmt.Sprintf("%v", *i.p); -} +func (i *uintValue) String() string { return fmt.Sprintf("%v", *i.p) } // -- uint64 Value type uint64Value struct { @@ -155,9 +147,7 @@ func (i *uint64Value) set(s string) bool { return err == nil; } -func (i *uint64Value) String() string { - return fmt.Sprintf("%v", *i.p); -} +func (i *uint64Value) String() string { return fmt.Sprintf("%v", *i.p) } // -- string Value type stringValue struct { @@ -174,9 +164,7 @@ func (s *stringValue) set(val string) bool { return true; } -func (s *stringValue) String() string { - return fmt.Sprintf("%s", *s.p); -} +func (s *stringValue) String() string { return fmt.Sprintf("%s", *s.p) } // FlagValue is the interface to the dynamic value stored in a flag. // (The default value is represented as a string.) @@ -258,9 +246,7 @@ var Usage = func() { PrintDefaults(); } -func NFlag() int { - return len(flags.actual); -} +func NFlag() int { return len(flags.actual) } // Arg returns the i'th command-line argument. Arg(0) is the first remaining argument // after flags have been processed. @@ -273,14 +259,10 @@ func Arg(i int) string { } // NArg is the number of arguments remaining after flags have been processed. -func NArg() int { - return len(os.Args) - flags.first_arg; -} +func NArg() int { return len(os.Args) - flags.first_arg } // Args returns the non-flag command-line arguments. -func Args() []string { - return os.Args[flags.first_arg : len(os.Args)]; -} +func Args() []string { return os.Args[flags.first_arg : len(os.Args)] } func add(name string, value FlagValue, usage string) { // Remember the default value as a string; it won't change. diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go index c929ea879..bd0901771 100644 --- a/src/pkg/fmt/format.go +++ b/src/pkg/fmt/format.go @@ -54,9 +54,7 @@ func (f *Fmt) clearflags() { f.zero = false; } -func (f *Fmt) clearbuf() { - f.buf = ""; -} +func (f *Fmt) clearbuf() { f.buf = "" } func (f *Fmt) init() { f.clearbuf(); @@ -239,14 +237,10 @@ func (f *Fmt) Fmt_d64(v int64) *Fmt { } // Fmt_d32 formats an int32 in decimal. -func (f *Fmt) Fmt_d32(v int32) *Fmt { - return f.Fmt_d64(int64(v)); -} +func (f *Fmt) Fmt_d32(v int32) *Fmt { return f.Fmt_d64(int64(v)) } // Fmt_d formats an int in decimal. -func (f *Fmt) Fmt_d(v int) *Fmt { - return f.Fmt_d64(int64(v)); -} +func (f *Fmt) Fmt_d(v int) *Fmt { return f.Fmt_d64(int64(v)) } // Fmt_ud64 formats a uint64 in decimal. func (f *Fmt) Fmt_ud64(v uint64) *Fmt { @@ -256,14 +250,10 @@ func (f *Fmt) Fmt_ud64(v uint64) *Fmt { } // Fmt_ud32 formats a uint32 in decimal. -func (f *Fmt) Fmt_ud32(v uint32) *Fmt { - return f.Fmt_ud64(uint64(v)); -} +func (f *Fmt) Fmt_ud32(v uint32) *Fmt { return f.Fmt_ud64(uint64(v)) } // Fmt_ud formats a uint in decimal. -func (f *Fmt) Fmt_ud(v uint) *Fmt { - return f.Fmt_ud64(uint64(v)); -} +func (f *Fmt) Fmt_ud(v uint) *Fmt { return f.Fmt_ud64(uint64(v)) } // Fmt_x64 formats an int64 in hexadecimal. func (f *Fmt) Fmt_x64(v int64) *Fmt { @@ -273,14 +263,10 @@ func (f *Fmt) Fmt_x64(v int64) *Fmt { } // Fmt_x32 formats an int32 in hexadecimal. -func (f *Fmt) Fmt_x32(v int32) *Fmt { - return f.Fmt_x64(int64(v)); -} +func (f *Fmt) Fmt_x32(v int32) *Fmt { return f.Fmt_x64(int64(v)) } // Fmt_x formats an int in hexadecimal. -func (f *Fmt) Fmt_x(v int) *Fmt { - return f.Fmt_x64(int64(v)); -} +func (f *Fmt) Fmt_x(v int) *Fmt { return f.Fmt_x64(int64(v)) } // Fmt_ux64 formats a uint64 in hexadecimal. func (f *Fmt) Fmt_ux64(v uint64) *Fmt { @@ -290,14 +276,10 @@ func (f *Fmt) Fmt_ux64(v uint64) *Fmt { } // Fmt_ux32 formats a uint32 in hexadecimal. -func (f *Fmt) Fmt_ux32(v uint32) *Fmt { - return f.Fmt_ux64(uint64(v)); -} +func (f *Fmt) Fmt_ux32(v uint32) *Fmt { return f.Fmt_ux64(uint64(v)) } // Fmt_ux formats a uint in hexadecimal. -func (f *Fmt) Fmt_ux(v uint) *Fmt { - return f.Fmt_ux64(uint64(v)); -} +func (f *Fmt) Fmt_ux(v uint) *Fmt { return f.Fmt_ux64(uint64(v)) } // Fmt_X64 formats an int64 in upper case hexadecimal. func (f *Fmt) Fmt_X64(v int64) *Fmt { @@ -307,14 +289,10 @@ func (f *Fmt) Fmt_X64(v int64) *Fmt { } // Fmt_X32 formats an int32 in upper case hexadecimal. -func (f *Fmt) Fmt_X32(v int32) *Fmt { - return f.Fmt_X64(int64(v)); -} +func (f *Fmt) Fmt_X32(v int32) *Fmt { return f.Fmt_X64(int64(v)) } // Fmt_X formats an int in upper case hexadecimal. -func (f *Fmt) Fmt_X(v int) *Fmt { - return f.Fmt_X64(int64(v)); -} +func (f *Fmt) Fmt_X(v int) *Fmt { return f.Fmt_X64(int64(v)) } // Fmt_uX64 formats a uint64 in upper case hexadecimal. func (f *Fmt) Fmt_uX64(v uint64) *Fmt { @@ -324,14 +302,10 @@ func (f *Fmt) Fmt_uX64(v uint64) *Fmt { } // Fmt_uX32 formats a uint32 in upper case hexadecimal. -func (f *Fmt) Fmt_uX32(v uint32) *Fmt { - return f.Fmt_uX64(uint64(v)); -} +func (f *Fmt) Fmt_uX32(v uint32) *Fmt { return f.Fmt_uX64(uint64(v)) } // Fmt_uX formats a uint in upper case hexadecimal. -func (f *Fmt) Fmt_uX(v uint) *Fmt { - return f.Fmt_uX64(uint64(v)); -} +func (f *Fmt) Fmt_uX(v uint) *Fmt { return f.Fmt_uX64(uint64(v)) } // Fmt_o64 formats an int64 in octal. func (f *Fmt) Fmt_o64(v int64) *Fmt { @@ -341,14 +315,10 @@ func (f *Fmt) Fmt_o64(v int64) *Fmt { } // Fmt_o32 formats an int32 in octal. -func (f *Fmt) Fmt_o32(v int32) *Fmt { - return f.Fmt_o64(int64(v)); -} +func (f *Fmt) Fmt_o32(v int32) *Fmt { return f.Fmt_o64(int64(v)) } // Fmt_o formats an int in octal. -func (f *Fmt) Fmt_o(v int) *Fmt { - return f.Fmt_o64(int64(v)); -} +func (f *Fmt) Fmt_o(v int) *Fmt { return f.Fmt_o64(int64(v)) } // Fmt_uo64 formats a uint64 in octal. func (f *Fmt) Fmt_uo64(v uint64) *Fmt { @@ -358,14 +328,10 @@ func (f *Fmt) Fmt_uo64(v uint64) *Fmt { } // Fmt_uo32 formats a uint32 in octal. -func (f *Fmt) Fmt_uo32(v uint32) *Fmt { - return f.Fmt_uo64(uint64(v)); -} +func (f *Fmt) Fmt_uo32(v uint32) *Fmt { return f.Fmt_uo64(uint64(v)) } // Fmt_uo formats a uint in octal. -func (f *Fmt) Fmt_uo(v uint) *Fmt { - return f.Fmt_uo64(uint64(v)); -} +func (f *Fmt) Fmt_uo(v uint) *Fmt { return f.Fmt_uo64(uint64(v)) } // Fmt_b64 formats a uint64 in binary. func (f *Fmt) Fmt_b64(v uint64) *Fmt { @@ -375,14 +341,10 @@ func (f *Fmt) Fmt_b64(v uint64) *Fmt { } // Fmt_b32 formats a uint32 in binary. -func (f *Fmt) Fmt_b32(v uint32) *Fmt { - return f.Fmt_b64(uint64(v)); -} +func (f *Fmt) Fmt_b32(v uint32) *Fmt { return f.Fmt_b64(uint64(v)) } // Fmt_b formats a uint in binary. -func (f *Fmt) Fmt_b(v uint) *Fmt { - return f.Fmt_b64(uint64(v)); -} +func (f *Fmt) Fmt_b(v uint) *Fmt { return f.Fmt_b64(uint64(v)) } // Fmt_c formats a Unicode character. func (f *Fmt) Fmt_c(v int) *Fmt { @@ -486,9 +448,7 @@ func (f *Fmt) Fmt_G64(v float64) *Fmt { } // Fmt_fb64 formats a float64 in the form -123p3 (exponent is power of 2). -func (f *Fmt) Fmt_fb64(v float64) *Fmt { - return fmtString(f, strconv.Ftoa64(v, 'b', 0)); -} +func (f *Fmt) Fmt_fb64(v float64) *Fmt { return fmtString(f, strconv.Ftoa64(v, 'b', 0)) } // float32 // cannot defer to float64 versions @@ -520,9 +480,7 @@ func (f *Fmt) Fmt_G32(v float32) *Fmt { } // Fmt_fb32 formats a float32 in the form -123p3 (exponent is power of 2). -func (f *Fmt) Fmt_fb32(v float32) *Fmt { - return fmtString(f, strconv.Ftoa32(v, 'b', 0)); -} +func (f *Fmt) Fmt_fb32(v float32) *Fmt { return fmtString(f, strconv.Ftoa32(v, 'b', 0)) } // float func (x *Fmt) f(a float) *Fmt { diff --git a/src/pkg/fmt/print.go b/src/pkg/fmt/print.go index 58163124c..a27c65cf7 100644 --- a/src/pkg/fmt/print.go +++ b/src/pkg/fmt/print.go @@ -136,13 +136,9 @@ func newPrinter() *pp { return p; } -func (p *pp) Width() (wid int, ok bool) { - return p.fmt.wid, p.fmt.wid_present; -} +func (p *pp) Width() (wid int, ok bool) { return p.fmt.wid, p.fmt.wid_present } -func (p *pp) Precision() (prec int, ok bool) { - return p.fmt.prec, p.fmt.prec_present; -} +func (p *pp) Precision() (prec int, ok bool) { return p.fmt.prec, p.fmt.prec_present } func (p *pp) Flag(b int) bool { switch b { diff --git a/src/pkg/go/ast/ast.go b/src/pkg/go/ast/ast.go index 92f24d6ef..ec299c5f7 100644 --- a/src/pkg/go/ast/ast.go +++ b/src/pkg/go/ast/ast.go @@ -300,82 +300,42 @@ type ( // Pos() implementations for expression/type where the position // corresponds to the position of a sub-node. // -func (x *StringList) Pos() token.Position { - return x.Strings[0].Pos(); -} -func (x *FuncLit) Pos() token.Position { - return x.Type.Pos(); -} -func (x *CompositeLit) Pos() token.Position { - return x.Type.Pos(); -} -func (x *SelectorExpr) Pos() token.Position { - return x.X.Pos(); -} -func (x *IndexExpr) Pos() token.Position { - return x.X.Pos(); -} -func (x *TypeAssertExpr) Pos() token.Position { - return x.X.Pos(); -} -func (x *CallExpr) Pos() token.Position { - return x.Fun.Pos(); -} -func (x *BinaryExpr) Pos() token.Position { - return x.X.Pos(); -} -func (x *KeyValueExpr) Pos() token.Position { - return x.Key.Pos(); -} +func (x *StringList) Pos() token.Position { return x.Strings[0].Pos() } +func (x *FuncLit) Pos() token.Position { return x.Type.Pos() } +func (x *CompositeLit) Pos() token.Position { return x.Type.Pos() } +func (x *SelectorExpr) Pos() token.Position { return x.X.Pos() } +func (x *IndexExpr) Pos() token.Position { return x.X.Pos() } +func (x *TypeAssertExpr) Pos() token.Position { return x.X.Pos() } +func (x *CallExpr) Pos() token.Position { return x.Fun.Pos() } +func (x *BinaryExpr) Pos() token.Position { return x.X.Pos() } +func (x *KeyValueExpr) Pos() token.Position { return x.Key.Pos() } // exprNode() ensures that only expression/type nodes can be // assigned to an ExprNode. -func (x *BadExpr) exprNode() { -} -func (x *Ident) exprNode() { -} -func (x *Ellipsis) exprNode() { -} -func (x *BasicLit) exprNode() { -} -func (x *StringList) exprNode() { -} -func (x *FuncLit) exprNode() { -} -func (x *CompositeLit) exprNode() { -} -func (x *ParenExpr) exprNode() { -} -func (x *SelectorExpr) exprNode() { -} -func (x *IndexExpr) exprNode() { -} -func (x *TypeAssertExpr) exprNode() { -} -func (x *CallExpr) exprNode() { -} -func (x *StarExpr) exprNode() { -} -func (x *UnaryExpr) exprNode() { -} -func (x *BinaryExpr) exprNode() { -} -func (x *KeyValueExpr) exprNode() { -} - -func (x *ArrayType) exprNode() { -} -func (x *StructType) exprNode() { -} -func (x *FuncType) exprNode() { -} -func (x *InterfaceType) exprNode() { -} -func (x *MapType) exprNode() { -} -func (x *ChanType) exprNode() { -} +func (x *BadExpr) exprNode() {} +func (x *Ident) exprNode() {} +func (x *Ellipsis) exprNode() {} +func (x *BasicLit) exprNode() {} +func (x *StringList) exprNode() {} +func (x *FuncLit) exprNode() {} +func (x *CompositeLit) exprNode() {} +func (x *ParenExpr) exprNode() {} +func (x *SelectorExpr) exprNode() {} +func (x *IndexExpr) exprNode() {} +func (x *TypeAssertExpr) exprNode() {} +func (x *CallExpr) exprNode() {} +func (x *StarExpr) exprNode() {} +func (x *UnaryExpr) exprNode() {} +func (x *BinaryExpr) exprNode() {} +func (x *KeyValueExpr) exprNode() {} + +func (x *ArrayType) exprNode() {} +func (x *StructType) exprNode() {} +func (x *FuncType) exprNode() {} +func (x *InterfaceType) exprNode() {} +func (x *MapType) exprNode() {} +func (x *ChanType) exprNode() {} // IsExported returns whether name is an exported Go symbol @@ -387,13 +347,9 @@ func IsExported(name string) bool { // IsExported returns whether name is an exported Go symbol // (i.e., whether it begins with an uppercase letter). -func (name *Ident) IsExported() bool { - return IsExported(name.Value); -} +func (name *Ident) IsExported() bool { return IsExported(name.Value) } -func (name *Ident) String() string { - return name.Value; -} +func (name *Ident) String() string { return name.Value } // ---------------------------------------------------------------------------- @@ -566,68 +522,37 @@ type ( // Pos() implementations for statement nodes where the position // corresponds to the position of a sub-node. // -func (s *DeclStmt) Pos() token.Position { - return s.Decl.Pos(); -} -func (s *LabeledStmt) Pos() token.Position { - return s.Label.Pos(); -} -func (s *ExprStmt) Pos() token.Position { - return s.X.Pos(); -} -func (s *IncDecStmt) Pos() token.Position { - return s.X.Pos(); -} -func (s *AssignStmt) Pos() token.Position { - return s.Lhs[0].Pos(); -} +func (s *DeclStmt) Pos() token.Position { return s.Decl.Pos() } +func (s *LabeledStmt) Pos() token.Position { return s.Label.Pos() } +func (s *ExprStmt) Pos() token.Position { return s.X.Pos() } +func (s *IncDecStmt) Pos() token.Position { return s.X.Pos() } +func (s *AssignStmt) Pos() token.Position { return s.Lhs[0].Pos() } // stmtNode() ensures that only statement nodes can be // assigned to a StmtNode. // -func (s *BadStmt) stmtNode() { -} -func (s *DeclStmt) stmtNode() { -} -func (s *EmptyStmt) stmtNode() { -} -func (s *LabeledStmt) stmtNode() { -} -func (s *ExprStmt) stmtNode() { -} -func (s *IncDecStmt) stmtNode() { -} -func (s *AssignStmt) stmtNode() { -} -func (s *GoStmt) stmtNode() { -} -func (s *DeferStmt) stmtNode() { -} -func (s *ReturnStmt) stmtNode() { -} -func (s *BranchStmt) stmtNode() { -} -func (s *BlockStmt) stmtNode() { -} -func (s *IfStmt) stmtNode() { -} -func (s *CaseClause) stmtNode() { -} -func (s *SwitchStmt) stmtNode() { -} -func (s *TypeCaseClause) stmtNode() { -} -func (s *TypeSwitchStmt) stmtNode() { -} -func (s *CommClause) stmtNode() { -} -func (s *SelectStmt) stmtNode() { -} -func (s *ForStmt) stmtNode() { -} -func (s *RangeStmt) stmtNode() { -} +func (s *BadStmt) stmtNode() {} +func (s *DeclStmt) stmtNode() {} +func (s *EmptyStmt) stmtNode() {} +func (s *LabeledStmt) stmtNode() {} +func (s *ExprStmt) stmtNode() {} +func (s *IncDecStmt) stmtNode() {} +func (s *AssignStmt) stmtNode() {} +func (s *GoStmt) stmtNode() {} +func (s *DeferStmt) stmtNode() {} +func (s *ReturnStmt) stmtNode() {} +func (s *BranchStmt) stmtNode() {} +func (s *BlockStmt) stmtNode() {} +func (s *IfStmt) stmtNode() {} +func (s *CaseClause) stmtNode() {} +func (s *SwitchStmt) stmtNode() {} +func (s *TypeCaseClause) stmtNode() {} +func (s *TypeSwitchStmt) stmtNode() {} +func (s *CommClause) stmtNode() {} +func (s *SelectStmt) stmtNode() {} +func (s *ForStmt) stmtNode() {} +func (s *RangeStmt) stmtNode() {} // ---------------------------------------------------------------------------- @@ -680,23 +605,16 @@ func (s *ImportSpec) Pos() token.Position { return s.Path[0].Pos(); } -func (s *ValueSpec) Pos() token.Position { - return s.Names[0].Pos(); -} -func (s *TypeSpec) Pos() token.Position { - return s.Name.Pos(); -} +func (s *ValueSpec) Pos() token.Position { return s.Names[0].Pos() } +func (s *TypeSpec) Pos() token.Position { return s.Name.Pos() } // specNode() ensures that only spec nodes can be // assigned to a Spec. // -func (s *ImportSpec) specNode() { -} -func (s *ValueSpec) specNode() { -} -func (s *TypeSpec) specNode() { -} +func (s *ImportSpec) specNode() {} +func (s *ValueSpec) specNode() {} +func (s *TypeSpec) specNode() {} // A declaration is represented by one of the following declaration nodes. @@ -742,20 +660,15 @@ type ( // The position of a FuncDecl node is the position of its function type. -func (d *FuncDecl) Pos() token.Position { - return d.Type.Pos(); -} +func (d *FuncDecl) Pos() token.Position { return d.Type.Pos() } // declNode() ensures that only declaration nodes can be // assigned to a DeclNode. // -func (d *BadDecl) declNode() { -} -func (d *GenDecl) declNode() { -} -func (d *FuncDecl) declNode() { -} +func (d *BadDecl) declNode() {} +func (d *GenDecl) declNode() {} +func (d *FuncDecl) declNode() {} // ---------------------------------------------------------------------------- diff --git a/src/pkg/go/ast/scope.go b/src/pkg/go/ast/scope.go index 988b11e95..301630de6 100644 --- a/src/pkg/go/ast/scope.go +++ b/src/pkg/go/ast/scope.go @@ -17,9 +17,7 @@ type Scope struct { // NewScope creates a new scope nested in the outer scope. -func NewScope(outer *Scope) *Scope { - return &Scope{outer, make(map[string]*Ident)}; -} +func NewScope(outer *Scope) *Scope { return &Scope{outer, make(map[string]*Ident)} } // Declare inserts an identifier into the scope s. If the diff --git a/src/pkg/go/doc/comment.go b/src/pkg/go/doc/comment.go index 18fce5c4e..75eb7064b 100644 --- a/src/pkg/go/doc/comment.go +++ b/src/pkg/go/doc/comment.go @@ -165,9 +165,7 @@ func indentLen(s []byte) int { } -func isBlank(s []byte) bool { - return len(s) == 0 || (len(s) == 1 && s[0] == '\n'); -} +func isBlank(s []byte) bool { return len(s) == 0 || (len(s) == 1 && s[0] == '\n') } func commonPrefix(a, b []byte) []byte { diff --git a/src/pkg/go/doc/doc.go b/src/pkg/go/doc/doc.go index 7f8c558e7..d9d436ccb 100644 --- a/src/pkg/go/doc/doc.go +++ b/src/pkg/go/doc/doc.go @@ -324,12 +324,8 @@ type ValueDoc struct { type sortValueDoc []*ValueDoc -func (p sortValueDoc) Len() int { - return len(p); -} -func (p sortValueDoc) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p sortValueDoc) Len() int { return len(p) } +func (p sortValueDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func declName(d *ast.GenDecl) string { @@ -388,15 +384,9 @@ type FuncDoc struct { type sortFuncDoc []*FuncDoc -func (p sortFuncDoc) Len() int { - return len(p); -} -func (p sortFuncDoc) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} -func (p sortFuncDoc) Less(i, j int) bool { - return p[i].Name < p[j].Name; -} +func (p sortFuncDoc) Len() int { return len(p) } +func (p sortFuncDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p sortFuncDoc) Less(i, j int) bool { return p[i].Name < p[j].Name } func makeFuncDocs(m map[string]*ast.FuncDecl) []*FuncDoc { @@ -436,12 +426,8 @@ type TypeDoc struct { type sortTypeDoc []*TypeDoc -func (p sortTypeDoc) Len() int { - return len(p); -} -func (p sortTypeDoc) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p sortTypeDoc) Len() int { return len(p) } +func (p sortTypeDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p sortTypeDoc) Less(i, j int) bool { // sort by name // pull blocks (name = "") up to top diff --git a/src/pkg/go/parser/parser.go b/src/pkg/go/parser/parser.go index 9fd8de8f4..53fff192d 100644 --- a/src/pkg/go/parser/parser.go +++ b/src/pkg/go/parser/parser.go @@ -273,9 +273,7 @@ func openScope(p *parser) *parser { // Usage pattern: defer close(openScope(p)); -func close(p *parser) { - p.topScope = p.topScope.Outer; -} +func close(p *parser) { p.topScope = p.topScope.Outer } func (p *parser) declare(ident *ast.Ident) { @@ -787,9 +785,7 @@ func (p *parser) tryRawType(ellipsisOk bool) ast.Expr { } -func (p *parser) tryType() ast.Expr { - return p.tryRawType(false); -} +func (p *parser) tryType() ast.Expr { return p.tryRawType(false) } // ---------------------------------------------------------------------------- diff --git a/src/pkg/go/parser/parser_test.go b/src/pkg/go/parser/parser_test.go index fc366bcc3..257ef9a7f 100644 --- a/src/pkg/go/parser/parser_test.go +++ b/src/pkg/go/parser/parser_test.go @@ -72,9 +72,7 @@ func nameFilter(filename string) bool { } -func dirFilter(d *os.Dir) bool { - return nameFilter(d.Name); -} +func dirFilter(d *os.Dir) bool { return nameFilter(d.Name) } func TestParse4(t *testing.T) { diff --git a/src/pkg/go/printer/nodes.go b/src/pkg/go/printer/nodes.go index 7e27b3b6e..4c2f0c57f 100644 --- a/src/pkg/go/printer/nodes.go +++ b/src/pkg/go/printer/nodes.go @@ -18,19 +18,21 @@ import ( // Disabled formatting - enable eventually and remove the flag. const ( - oneLineFuncDecls = false; compositeLitBlank = false; stringListMode = exprListMode(0); // previously: noIndent ) -// Other outstanding formatting issues: +// Other formatting issues: // - replacement of expression spacing algorithm with rsc's algorithm // - support for one-line composite types (e.g. structs) as composite literals types // - better comment formatting for /*-style comments at the end of a line (e.g. a declaration) -// when the comment spans multiple lines +// when the comment spans multiple lines; if such a comment is just two lines, formatting is +// not idempotent // - formatting of expression lists; especially for string lists (stringListMode) // - blank after { and before } in one-line composite literals probably looks better +// - should use blank instead of tab to separate one-line function bodies from +// the function header unless there is a group of consecutive one-liners // ---------------------------------------------------------------------------- @@ -497,7 +499,7 @@ func (p *printer) expr1(expr ast.Expr, prec1 int, multiLine *bool) (optSemi bool case *ast.FuncLit: p.expr(x.Type, multiLine); - p.funcBody(x.Body, true, multiLine); + p.funcBody(x.Body, distance(x.Type.Pos(), p.pos), true, multiLine); case *ast.ParenExpr: p.print(token.LPAREN); @@ -994,42 +996,50 @@ func (p *printer) genDecl(d *ast.GenDecl, context declContext, multiLine *bool) } -func (p *printer) isOneLiner(b *ast.BlockStmt) bool { - switch { - case len(b.List) > 1 || p.commentBefore(b.Rbrace): - return false; // too many statements or there is a comment - all bets are off - case len(b.List) == 0: - return true; // empty block and no comments - } - - // test-print the statement and see if it would fit +// nodeSize determines the size of n in chars after formatting. +// The result is <= maxSize if the node fits on one line with at +// most maxSize chars and the formatted output doesn't contain +// any control chars. Otherwise, the result is > maxSize. +// +func (p *printer) nodeSize(n ast.Node, maxSize int) (size int) { + size = maxSize+1; // assume n doesn't fit var buf bytes.Buffer; - _, err := p.Config.Fprint(&buf, b.List[0]); - if err != nil { - return false; // don't try - } - - if buf.Len() > 40 { - return false; // too long + if _, err := p.Config.Fprint(&buf, n); err != nil { + return; } - - for _, ch := range buf.Bytes() { - if ch < ' ' { - return false; // contains control chars (tabs, newlines) + if buf.Len() <= maxSize { + for _, ch := range buf.Bytes() { + if ch < ' ' { + return; + } } + size = buf.Len(); // n fits } + return; +} - return true; + +func (p *printer) isOneLineFunc(b *ast.BlockStmt, headerSize int) bool { + const maxSize = 90; // adjust as appropriate, this is an approximate value + bodySize := 0; + switch { + case len(b.List) > 1 || p.commentBefore(b.Rbrace): + return false; // too many statements or there is a comment - all bets are off + case len(b.List) == 1: + bodySize = p.nodeSize(b.List[0], maxSize); + } + // require both headers and overall size to be not "too large" + return headerSize <= maxSize/2 && headerSize + bodySize <= maxSize; } // Sets multiLine to true if the function body spans multiple lines. -func (p *printer) funcBody(b *ast.BlockStmt, isLit bool, multiLine *bool) { +func (p *printer) funcBody(b *ast.BlockStmt, headerSize int, isLit bool, multiLine *bool) { if b == nil { return; } - if (oneLineFuncDecls || isLit) && p.isOneLiner(b) { + if p.isOneLineFunc(b, headerSize) { sep := vtab; if isLit { sep = blank; @@ -1050,6 +1060,17 @@ func (p *printer) funcBody(b *ast.BlockStmt, isLit bool, multiLine *bool) { } +// distance returns the column difference between from and to if both +// are on the same line; if they are on different lines (or unknown) +// the result is infinity (1<<30). +func distance(from, to token.Position) int { + if from.IsValid() && to.IsValid() && from.Line == to.Line { + return to.Column - from.Column; + } + return 1<<30; +} + + // Sets multiLine to true if the declaration spans multiple lines. func (p *printer) funcDecl(d *ast.FuncDecl, multiLine *bool) { p.leadComment(d.Doc); @@ -1066,7 +1087,7 @@ func (p *printer) funcDecl(d *ast.FuncDecl, multiLine *bool) { } p.expr(d.Name, multiLine); p.signature(d.Type.Params, d.Type.Results, multiLine); - p.funcBody(d.Body, false, multiLine); + p.funcBody(d.Body, distance(d.Pos(), p.pos), false, multiLine); } diff --git a/src/pkg/go/printer/testdata/comments.golden b/src/pkg/go/printer/testdata/comments.golden index 94a4d8da6..cb2827476 100644 --- a/src/pkg/go/printer/testdata/comments.golden +++ b/src/pkg/go/printer/testdata/comments.golden @@ -278,8 +278,7 @@ func _() { // Some interesting interspersed comments -func _( /* this */ x /* is */ /* an */ int) { -} +func _( /* this */ x /* is */ /* an */ int) {} // Line comments with tabs diff --git a/src/pkg/go/printer/testdata/declarations.golden b/src/pkg/go/printer/testdata/declarations.golden index 2f5cf6059..43ba1fd53 100644 --- a/src/pkg/go/printer/testdata/declarations.golden +++ b/src/pkg/go/printer/testdata/declarations.golden @@ -445,26 +445,14 @@ func _() { // formatting of consecutive single-line functions -func _() { -} -func _() { -} -func _() { -} +func _() {} +func _() {} +func _() {} -func _() { -} // an empty line before this function -func _() { -} -func _() { -} +func _() {} // an empty line before this function +func _() {} +func _() {} -func _() { - f(1, 2, 3); -} -func _(x int) int { - return x+1; -} -func _() int { - type T struct{} -} +func _() { f(1, 2, 3) } +func _(x int) int { return x+1 } +func _() int { type T struct{} } diff --git a/src/pkg/go/printer/testdata/statements.golden b/src/pkg/go/printer/testdata/statements.golden index a1839aa18..875bac40b 100644 --- a/src/pkg/go/printer/testdata/statements.golden +++ b/src/pkg/go/printer/testdata/statements.golden @@ -6,8 +6,7 @@ package statements var expr bool -func use(x interface{}) { -} +func use(x interface{}) {} // Formatting of if-statement headers. func _() { diff --git a/src/pkg/go/scanner/errors.go b/src/pkg/go/scanner/errors.go index 090066701..a8219b190 100644 --- a/src/pkg/go/scanner/errors.go +++ b/src/pkg/go/scanner/errors.go @@ -39,9 +39,7 @@ type ErrorVector struct { // Init initializes an ErrorVector. -func (h *ErrorVector) Init() { - h.errors.Init(0); -} +func (h *ErrorVector) Init() { h.errors.Init(0) } // NewErrorVector creates a new ErrorVector. @@ -53,9 +51,7 @@ func NewErrorVector() *ErrorVector { // ErrorCount returns the number of errors collected. -func (h *ErrorVector) ErrorCount() int { - return h.errors.Len(); -} +func (h *ErrorVector) ErrorCount() int { return h.errors.Len() } // Within ErrorVector, an error is represented by an Error node. The @@ -83,12 +79,8 @@ type ErrorList []*Error // ErrorList implements the sort Interface. -func (p ErrorList) Len() int { - return len(p); -} -func (p ErrorList) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p ErrorList) Len() int { return len(p) } +func (p ErrorList) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p ErrorList) Less(i, j int) bool { diff --git a/src/pkg/go/scanner/scanner_test.go b/src/pkg/go/scanner/scanner_test.go index 052f3a8a8..0b036e8b4 100644 --- a/src/pkg/go/scanner/scanner_test.go +++ b/src/pkg/go/scanner/scanner_test.go @@ -357,7 +357,9 @@ func TestStdErrorHander(t *testing.T) { v := NewErrorVector(); nerrors := Tokenize("File1", strings.Bytes(src), v, 0, - func(pos token.Position, tok token.Token, litb []byte) bool { return tok != token.EOF }); + func(pos token.Position, tok token.Token, litb []byte) bool { + return tok != token.EOF; + }); list := v.GetErrorList(Raw); if len(list) != 9 { diff --git a/src/pkg/go/token/token.go b/src/pkg/go/token/token.go index b3191c22c..28c335461 100644 --- a/src/pkg/go/token/token.go +++ b/src/pkg/go/token/token.go @@ -308,23 +308,17 @@ func Lookup(ident []byte) Token { // IsLiteral returns true for tokens corresponding to identifiers // and basic type literals; returns false otherwise. // -func (tok Token) IsLiteral() bool { - return literal_beg < tok && tok < literal_end; -} +func (tok Token) IsLiteral() bool { return literal_beg < tok && tok < literal_end } // IsOperator returns true for tokens corresponding to operators and // delimiters; returns false otherwise. // -func (tok Token) IsOperator() bool { - return operator_beg < tok && tok < operator_end; -} +func (tok Token) IsOperator() bool { return operator_beg < tok && tok < operator_end } // IsKeyword returns true for tokens corresponding to keywords; // returns false otherwise. // -func (tok Token) IsKeyword() bool { - return keyword_beg < tok && tok < keyword_end; -} +func (tok Token) IsKeyword() bool { return keyword_beg < tok && tok < keyword_end } // Token source positions are represented by a Position value. @@ -341,15 +335,11 @@ type Position struct { // Pos is an accessor method for anonymous Position fields. // It returns its receiver. // -func (pos *Position) Pos() Position { - return *pos; -} +func (pos *Position) Pos() Position { return *pos } // IsValid returns true if the position is valid. -func (pos *Position) IsValid() bool { - return pos.Line > 0; -} +func (pos *Position) IsValid() bool { return pos.Line > 0 } func (pos Position) String() string { diff --git a/src/pkg/gob/decode.go b/src/pkg/gob/decode.go index 48221f117..e9e093eef 100644 --- a/src/pkg/gob/decode.go +++ b/src/pkg/gob/decode.go @@ -579,7 +579,9 @@ func decIgnoreOpFor(wireId typeId) (decOp, os.Error) { if err != nil { return nil, err; } - op = func(i *decInstr, state *decodeState, p unsafe.Pointer) { state.err = ignoreSlice(state, elemOp) }; + op = func(i *decInstr, state *decodeState, p unsafe.Pointer) { + state.err = ignoreSlice(state, elemOp); + }; case *arrayType: elemId := wireId.gobType().(*arrayType).Elem; diff --git a/src/pkg/gob/type.go b/src/pkg/gob/type.go index c8110216e..ec8a347e4 100644 --- a/src/pkg/gob/type.go +++ b/src/pkg/gob/type.go @@ -25,15 +25,11 @@ type kind reflect.Type // int8, int16, int, uint, float, func, chan, struct, and so on. // That is, all struct types have the same kind, all func types have the same // kind, all int8 types have the same kind, and so on. -func typeKind(typ reflect.Type) kind { - return kind(reflect.Typeof(typ)); -} +func typeKind(typ reflect.Type) kind { return kind(reflect.Typeof(typ)) } // valueKind returns the kind of the value type // stored inside the interface v. -func valueKind(v interface{}) reflect.Type { - return typeKind(reflect.Typeof(v)); -} +func valueKind(v interface{}) reflect.Type { return typeKind(reflect.Typeof(v)) } // A typeId represents a gob Type as an integer that can be passed on the wire. // Internally, typeIds are used as keys to a map to recover the underlying type info. @@ -67,14 +63,10 @@ func (t typeId) gobType() gobType { } // String returns the string representation of the type associated with the typeId. -func (t typeId) String() string { - return t.gobType().String(); -} +func (t typeId) String() string { return t.gobType().String() } // Name returns the name of the type associated with the typeId. -func (t typeId) Name() string { - return t.gobType().Name(); -} +func (t typeId) Name() string { return t.gobType().Name() } // Common elements of all types. type commonType struct { @@ -82,25 +74,17 @@ type commonType struct { _id typeId; } -func (t *commonType) id() typeId { - return t._id; -} +func (t *commonType) id() typeId { return t._id } -func (t *commonType) setId(id typeId) { - t._id = id; -} +func (t *commonType) setId(id typeId) { t._id = id } -func (t *commonType) String() string { - return t.name; -} +func (t *commonType) String() string { return t.name } func (t *commonType) safeString(seen map[typeId]bool) string { return t.name; } -func (t *commonType) Name() string { - return t.name; -} +func (t *commonType) Name() string { return t.name } // Create and check predefined types // The string for tBytes is "bytes" not "[]byte" to signify its specialness. @@ -143,9 +127,7 @@ func (a *arrayType) safeString(seen map[typeId]bool) string { return fmt.Sprintf("[%d]%s", a.Len, a.Elem.gobType().safeString(seen)); } -func (a *arrayType) String() string { - return a.safeString(make(map[typeId]bool)); -} +func (a *arrayType) String() string { return a.safeString(make(map[typeId]bool)) } // Slice type type sliceType struct { @@ -167,9 +149,7 @@ func (s *sliceType) safeString(seen map[typeId]bool) string { return fmt.Sprintf("[]%s", s.Elem.gobType().safeString(seen)); } -func (s *sliceType) String() string { - return s.safeString(make(map[typeId]bool)); -} +func (s *sliceType) String() string { return s.safeString(make(map[typeId]bool)) } // Struct type type fieldType struct { @@ -198,9 +178,7 @@ func (s *structType) safeString(seen map[typeId]bool) string { return str; } -func (s *structType) String() string { - return s.safeString(make(map[typeId]bool)); -} +func (s *structType) String() string { return s.safeString(make(map[typeId]bool)) } func newStructType(name string) *structType { s := &structType{commonType{name: name}, nil}; diff --git a/src/pkg/hash/adler32/adler32.go b/src/pkg/hash/adler32/adler32.go index 2cd7a198a..3ac6364f9 100644 --- a/src/pkg/hash/adler32/adler32.go +++ b/src/pkg/hash/adler32/adler32.go @@ -30,9 +30,7 @@ type digest struct { a, b uint32; } -func (d *digest) Reset() { - d.a, d.b = 1, 0; -} +func (d *digest) Reset() { d.a, d.b = 1, 0 } // New returns a new Hash32 computing the Adler-32 checksum. func New() hash.Hash32 { @@ -41,9 +39,7 @@ func New() hash.Hash32 { return d; } -func (d *digest) Size() int { - return Size; -} +func (d *digest) Size() int { return Size } // Add p to the running checksum a, b. func update(a, b uint32, p []byte) (aa, bb uint32) { @@ -76,9 +72,7 @@ func (d *digest) Write(p []byte) (nn int, err os.Error) { return len(p), nil; } -func (d *digest) Sum32() uint32 { - return finish(d.a, d.b); -} +func (d *digest) Sum32() uint32 { return finish(d.a, d.b) } func (d *digest) Sum() []byte { p := make([]byte, 4); @@ -91,6 +85,4 @@ func (d *digest) Sum() []byte { } // Checksum returns the Adler-32 checksum of data. -func Checksum(data []byte) uint32 { - return finish(update(1, 0, data)); -} +func Checksum(data []byte) uint32 { return finish(update(1, 0, data)) } diff --git a/src/pkg/hash/crc32/crc32.go b/src/pkg/hash/crc32/crc32.go index 2f5fb8f89..e450f5fb7 100644 --- a/src/pkg/hash/crc32/crc32.go +++ b/src/pkg/hash/crc32/crc32.go @@ -62,23 +62,15 @@ type digest struct { // New creates a new Hash computing the CRC-32 checksum // using the polynomial represented by the Table. -func New(tab *Table) hash.Hash32 { - return &digest{0, tab}; -} +func New(tab *Table) hash.Hash32 { return &digest{0, tab} } // NewIEEE creates a new Hash computing the CRC-32 checksum // using the IEEE polynomial. -func NewIEEE() hash.Hash32 { - return New(IEEETable); -} +func NewIEEE() hash.Hash32 { return New(IEEETable) } -func (d *digest) Size() int { - return Size; -} +func (d *digest) Size() int { return Size } -func (d *digest) Reset() { - d.crc = 0; -} +func (d *digest) Reset() { d.crc = 0 } func update(crc uint32, tab *Table, p []byte) uint32 { crc = ^crc; @@ -93,9 +85,7 @@ func (d *digest) Write(p []byte) (n int, err os.Error) { return len(p), nil; } -func (d *digest) Sum32() uint32 { - return d.crc; -} +func (d *digest) Sum32() uint32 { return d.crc } func (d *digest) Sum() []byte { p := make([]byte, 4); @@ -109,12 +99,8 @@ func (d *digest) Sum() []byte { // Checksum returns the CRC-32 checksum of data // using the polynomial represented by the Table. -func Checksum(data []byte, tab *Table) uint32 { - return update(0, tab, data); -} +func Checksum(data []byte, tab *Table) uint32 { return update(0, tab, data) } // ChecksumIEEE returns the CRC-32 checksum of data // using the IEEE polynomial. -func ChecksumIEEE(data []byte) uint32 { - return update(0, IEEETable, data); -} +func ChecksumIEEE(data []byte) uint32 { return update(0, IEEETable, data) } diff --git a/src/pkg/http/client.go b/src/pkg/http/client.go index 0b045136b..6066becde 100644 --- a/src/pkg/http/client.go +++ b/src/pkg/http/client.go @@ -57,9 +57,7 @@ func (r *Response) AddHeader(key, value string) { // Given a string of the form "host", "host:port", or "[ipv6::address]:port", // return true if the string includes a port. -func hasPort(s string) bool { - return strings.LastIndex(s, ":") > strings.LastIndex(s, "]"); -} +func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") } // Used in Send to implement io.ReadCloser by bundling together the // io.BufReader through which we read the response, and the underlying diff --git a/src/pkg/http/fs.go b/src/pkg/http/fs.go index edeec693e..c0fa69216 100644 --- a/src/pkg/http/fs.go +++ b/src/pkg/http/fs.go @@ -168,9 +168,7 @@ type fileHandler struct { // with the contents of the file system rooted at root. // It strips prefix from the incoming requests before // looking up the file name in the file system. -func FileServer(root, prefix string) Handler { - return &fileHandler{root, prefix}; -} +func FileServer(root, prefix string) Handler { return &fileHandler{root, prefix} } func (f *fileHandler) ServeHTTP(c *Conn, r *Request) { path := r.Url.Path; diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go index 71c93bb1c..521b36098 100644 --- a/src/pkg/http/request.go +++ b/src/pkg/http/request.go @@ -43,9 +43,7 @@ type badStringError struct { str string; } -func (e *badStringError) String() string { - return fmt.Sprintf("%s %q", e.what, e.str); -} +func (e *badStringError) String() string { return fmt.Sprintf("%s %q", e.what, e.str) } // A Request represents a parsed HTTP request header. type Request struct { diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index 3aa5c072f..4b4c5837a 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -115,9 +115,7 @@ func (c *Conn) readRequest() (req *Request, err os.Error) { // Content-Type in this library, so users need not make that // particular call. Calls to SetHeader after WriteHeader (or Write) // are ignored. -func (c *Conn) SetHeader(hdr, val string) { - c.header[CanonicalHeaderKey(hdr)] = val; -} +func (c *Conn) SetHeader(hdr, val string) { c.header[CanonicalHeaderKey(hdr)] = val } // WriteHeader sends an HTTP response header with status code. // If WriteHeader is not called explicitly, the first call to Write @@ -326,9 +324,7 @@ func NotFound(c *Conn, req *Request) { // NotFoundHandler returns a simple request handler // that replies to each request with a ``404 page not found'' reply. -func NotFoundHandler() Handler { - return HandlerFunc(NotFound); -} +func NotFoundHandler() Handler { return HandlerFunc(NotFound) } // Redirect replies to the request with a redirect to url, // which may be a path relative to the request path. @@ -433,9 +429,7 @@ type ServeMux struct { } // NewServeMux allocates and returns a new ServeMux. -func NewServeMux() *ServeMux { - return &ServeMux{make(map[string]Handler)}; -} +func NewServeMux() *ServeMux { return &ServeMux{make(map[string]Handler)} } // DefaultServeMux is the default ServeMux used by Serve. var DefaultServeMux = NewServeMux() @@ -516,9 +510,7 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) { // Handle registers the handler for the given pattern // in the DefaultServeMux. -func Handle(pattern string, handler Handler) { - DefaultServeMux.Handle(pattern, handler); -} +func Handle(pattern string, handler Handler) { DefaultServeMux.Handle(pattern, handler) } // Serve accepts incoming HTTP connections on the listener l, // creating a new service thread for each. The service threads diff --git a/src/pkg/http/triv.go b/src/pkg/http/triv.go index 172806ee5..f9c6b64ab 100644 --- a/src/pkg/http/triv.go +++ b/src/pkg/http/triv.go @@ -33,9 +33,7 @@ type Counter struct { // This makes Counter satisfy the expvar.Var interface, so we can export // it directly. -func (ctr *Counter) String() string { - return fmt.Sprintf("%d", ctr.n); -} +func (ctr *Counter) String() string { return fmt.Sprintf("%d", ctr.n) } func (ctr *Counter) ServeHTTP(c *http.Conn, req *http.Request) { switch req.Method { diff --git a/src/pkg/http/url.go b/src/pkg/http/url.go index 65ad186e6..526c96aa2 100644 --- a/src/pkg/http/url.go +++ b/src/pkg/http/url.go @@ -20,9 +20,7 @@ type URLError struct { Error os.Error; } -func (e *URLError) String() string { - return e.Op + " " + e.URL + ": " + e.Error.String(); -} +func (e *URLError) String() string { return e.Op + " " + e.URL + ": " + e.Error.String() } func ishex(c byte) bool { switch { diff --git a/src/pkg/image/image.go b/src/pkg/image/image.go index 2b5d09642..80dbb8636 100644 --- a/src/pkg/image/image.go +++ b/src/pkg/image/image.go @@ -21,9 +21,7 @@ type RGBA struct { Pixel [][]RGBAColor; } -func (p *RGBA) ColorModel() ColorModel { - return RGBAColorModel; -} +func (p *RGBA) ColorModel() ColorModel { return RGBAColorModel } func (p *RGBA) Width() int { if len(p.Pixel) == 0 { @@ -32,17 +30,11 @@ func (p *RGBA) Width() int { return len(p.Pixel[0]); } -func (p *RGBA) Height() int { - return len(p.Pixel); -} +func (p *RGBA) Height() int { return len(p.Pixel) } -func (p *RGBA) At(x, y int) Color { - return p.Pixel[y][x]; -} +func (p *RGBA) At(x, y int) Color { return p.Pixel[y][x] } -func (p *RGBA) Set(x, y int, c Color) { - p.Pixel[y][x] = toRGBAColor(c).(RGBAColor); -} +func (p *RGBA) Set(x, y int, c Color) { p.Pixel[y][x] = toRGBAColor(c).(RGBAColor) } // NewRGBA returns a new RGBA with the given width and height. func NewRGBA(w, h int) *RGBA { @@ -59,9 +51,7 @@ type RGBA64 struct { Pixel [][]RGBA64Color; } -func (p *RGBA64) ColorModel() ColorModel { - return RGBA64ColorModel; -} +func (p *RGBA64) ColorModel() ColorModel { return RGBA64ColorModel } func (p *RGBA64) Width() int { if len(p.Pixel) == 0 { @@ -70,17 +60,11 @@ func (p *RGBA64) Width() int { return len(p.Pixel[0]); } -func (p *RGBA64) Height() int { - return len(p.Pixel); -} +func (p *RGBA64) Height() int { return len(p.Pixel) } -func (p *RGBA64) At(x, y int) Color { - return p.Pixel[y][x]; -} +func (p *RGBA64) At(x, y int) Color { return p.Pixel[y][x] } -func (p *RGBA64) Set(x, y int, c Color) { - p.Pixel[y][x] = toRGBA64Color(c).(RGBA64Color); -} +func (p *RGBA64) Set(x, y int, c Color) { p.Pixel[y][x] = toRGBA64Color(c).(RGBA64Color) } // NewRGBA64 returns a new RGBA64 with the given width and height. func NewRGBA64(w, h int) *RGBA64 { @@ -97,9 +81,7 @@ type NRGBA struct { Pixel [][]NRGBAColor; } -func (p *NRGBA) ColorModel() ColorModel { - return NRGBAColorModel; -} +func (p *NRGBA) ColorModel() ColorModel { return NRGBAColorModel } func (p *NRGBA) Width() int { if len(p.Pixel) == 0 { @@ -108,17 +90,11 @@ func (p *NRGBA) Width() int { return len(p.Pixel[0]); } -func (p *NRGBA) Height() int { - return len(p.Pixel); -} +func (p *NRGBA) Height() int { return len(p.Pixel) } -func (p *NRGBA) At(x, y int) Color { - return p.Pixel[y][x]; -} +func (p *NRGBA) At(x, y int) Color { return p.Pixel[y][x] } -func (p *NRGBA) Set(x, y int, c Color) { - p.Pixel[y][x] = toNRGBAColor(c).(NRGBAColor); -} +func (p *NRGBA) Set(x, y int, c Color) { p.Pixel[y][x] = toNRGBAColor(c).(NRGBAColor) } // NewNRGBA returns a new NRGBA with the given width and height. func NewNRGBA(w, h int) *NRGBA { @@ -135,9 +111,7 @@ type NRGBA64 struct { Pixel [][]NRGBA64Color; } -func (p *NRGBA64) ColorModel() ColorModel { - return NRGBA64ColorModel; -} +func (p *NRGBA64) ColorModel() ColorModel { return NRGBA64ColorModel } func (p *NRGBA64) Width() int { if len(p.Pixel) == 0 { @@ -146,17 +120,11 @@ func (p *NRGBA64) Width() int { return len(p.Pixel[0]); } -func (p *NRGBA64) Height() int { - return len(p.Pixel); -} +func (p *NRGBA64) Height() int { return len(p.Pixel) } -func (p *NRGBA64) At(x, y int) Color { - return p.Pixel[y][x]; -} +func (p *NRGBA64) At(x, y int) Color { return p.Pixel[y][x] } -func (p *NRGBA64) Set(x, y int, c Color) { - p.Pixel[y][x] = toNRGBA64Color(c).(NRGBA64Color); -} +func (p *NRGBA64) Set(x, y int, c Color) { p.Pixel[y][x] = toNRGBA64Color(c).(NRGBA64Color) } // NewNRGBA64 returns a new NRGBA64 with the given width and height. func NewNRGBA64(w, h int) *NRGBA64 { @@ -214,9 +182,7 @@ type Paletted struct { Palette PalettedColorModel; } -func (p *Paletted) ColorModel() ColorModel { - return p.Palette; -} +func (p *Paletted) ColorModel() ColorModel { return p.Palette } func (p *Paletted) Width() int { if len(p.Pixel) == 0 { @@ -225,13 +191,9 @@ func (p *Paletted) Width() int { return len(p.Pixel[0]); } -func (p *Paletted) Height() int { - return len(p.Pixel); -} +func (p *Paletted) Height() int { return len(p.Pixel) } -func (p *Paletted) At(x, y int) Color { - return p.Palette[p.Pixel[y][x]]; -} +func (p *Paletted) At(x, y int) Color { return p.Palette[p.Pixel[y][x]] } func (p *Paletted) ColorIndexAt(x, y int) uint8 { return p.Pixel[y][x]; diff --git a/src/pkg/image/png/reader.go b/src/pkg/image/png/reader.go index c8a2b076b..9ea338d07 100644 --- a/src/pkg/image/png/reader.go +++ b/src/pkg/image/png/reader.go @@ -63,9 +63,7 @@ type decoder struct { // A FormatError reports that the input is not a valid PNG. type FormatError string -func (e FormatError) String() string { - return "invalid PNG format: " + string(e); -} +func (e FormatError) String() string { return "invalid PNG format: " + string(e) } var chunkOrderError = FormatError("chunk out of order") @@ -74,16 +72,12 @@ type IDATDecodingError struct { Err os.Error; } -func (e IDATDecodingError) String() string { - return "IDAT decoding error: " + e.Err.String(); -} +func (e IDATDecodingError) String() string { return "IDAT decoding error: " + e.Err.String() } // An UnsupportedError reports that the input uses a valid but unimplemented PNG feature. type UnsupportedError string -func (e UnsupportedError) String() string { - return "unsupported PNG feature: " + string(e); -} +func (e UnsupportedError) String() string { return "unsupported PNG feature: " + string(e) } // Big-endian. func parseUint32(b []uint8) uint32 { diff --git a/src/pkg/image/png/writer.go b/src/pkg/image/png/writer.go index 9ff4e1e72..ceb72598e 100644 --- a/src/pkg/image/png/writer.go +++ b/src/pkg/image/png/writer.go @@ -312,9 +312,7 @@ func (e *encoder) writeIDATs() { e.err = bw.Flush(); } -func (e *encoder) writeIEND() { - e.writeChunk(e.tmp[0:0], "IEND"); -} +func (e *encoder) writeIEND() { e.writeChunk(e.tmp[0:0], "IEND") } // Encode writes the Image m to w in PNG format. Any Image may be encoded, but // images that are not image.NRGBA might be encoded lossily. diff --git a/src/pkg/io/io.go b/src/pkg/io/io.go index 50b0873fa..01157c157 100644 --- a/src/pkg/io/io.go +++ b/src/pkg/io/io.go @@ -243,9 +243,7 @@ func Copy(dst Writer, src Reader) (written int64, err os.Error) { // LimitReader returns a Reader that reads from r // but stops with os.EOF after n bytes. -func LimitReader(r Reader, n int64) Reader { - return &limitedReader{r, n}; -} +func LimitReader(r Reader, n int64) Reader { return &limitedReader{r, n} } type limitedReader struct { r Reader; @@ -321,6 +319,4 @@ func (s *SectionReader) ReadAt(p []byte, off int64) (n int, err os.Error) { } // Size returns the size of the section in bytes. -func (s *SectionReader) Size() int64 { - return s.limit - s.base; -} +func (s *SectionReader) Size() int64 { return s.limit - s.base } diff --git a/src/pkg/io/pipe.go b/src/pkg/io/pipe.go index ff52988b2..743e4c468 100644 --- a/src/pkg/io/pipe.go +++ b/src/pkg/io/pipe.go @@ -166,9 +166,7 @@ func (r *PipeReader) CloseWithError(rerr os.Error) os.Error { return r.p.CloseReader(rerr); } -func (r *PipeReader) finish() { - r.Close(); -} +func (r *PipeReader) finish() { r.Close() } // Write half of pipe. type PipeWriter struct { @@ -206,9 +204,7 @@ func (w *PipeWriter) CloseWithError(werr os.Error) os.Error { return w.p.CloseWriter(werr); } -func (w *PipeWriter) finish() { - w.Close(); -} +func (w *PipeWriter) finish() { w.Close() } // Pipe creates a synchronous in-memory pipe. // It can be used to connect code expecting an io.Reader diff --git a/src/pkg/io/utils.go b/src/pkg/io/utils.go index 4e3c0c42b..8c5c710b7 100644 --- a/src/pkg/io/utils.go +++ b/src/pkg/io/utils.go @@ -48,15 +48,9 @@ func WriteFile(filename string, data []byte, perm int) os.Error { // A dirList implements sort.Interface. type dirList []*os.Dir -func (d dirList) Len() int { - return len(d); -} -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]; -} +func (d dirList) Len() int { return len(d) } +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 // a list of sorted directory entries. diff --git a/src/pkg/json/generic.go b/src/pkg/json/generic.go index d53c4f6b0..a8ee83664 100644 --- a/src/pkg/json/generic.go +++ b/src/pkg/json/generic.go @@ -56,51 +56,29 @@ type _Null struct{} // Null is the JSON object representing the null data object. var Null Json = &_Null{} -func (*_Null) Kind() int { - return NullKind; -} -func (*_Null) String() string { - return "null"; -} -func (*_Null) Number() float64 { - return 0; -} -func (*_Null) Bool() bool { - return false; -} -func (*_Null) Get(s string) Json { - return Null; -} -func (*_Null) Elem(int) Json { - return Null; -} -func (*_Null) Len() int { - return 0; -} +func (*_Null) Kind() int { return NullKind } +func (*_Null) String() string { return "null" } +func (*_Null) Number() float64 { return 0 } +func (*_Null) Bool() bool { return false } +func (*_Null) Get(s string) Json { return Null } +func (*_Null) Elem(int) Json { return Null } +func (*_Null) Len() int { return 0 } type _String struct { s string; _Null; } -func (j *_String) Kind() int { - return StringKind; -} -func (j *_String) String() string { - return j.s; -} +func (j *_String) Kind() int { return StringKind } +func (j *_String) String() string { return j.s } type _Number struct { f float64; _Null; } -func (j *_Number) Kind() int { - return NumberKind; -} -func (j *_Number) Number() float64 { - return j.f; -} +func (j *_Number) Kind() int { return NumberKind } +func (j *_Number) Number() float64 { return j.f } func (j *_Number) String() string { if math.Floor(j.f) == j.f { return fmt.Sprintf("%.0f", j.f); @@ -113,12 +91,8 @@ type _Array struct { _Null; } -func (j *_Array) Kind() int { - return ArrayKind; -} -func (j *_Array) Len() int { - return j.a.Len(); -} +func (j *_Array) Kind() int { return ArrayKind } +func (j *_Array) Len() int { return j.a.Len() } func (j *_Array) Elem(i int) Json { if i < 0 || i >= j.a.Len() { return Null; @@ -142,12 +116,8 @@ type _Bool struct { _Null; } -func (j *_Bool) Kind() int { - return BoolKind; -} -func (j *_Bool) Bool() bool { - return j.b; -} +func (j *_Bool) Kind() int { return BoolKind } +func (j *_Bool) Bool() bool { return j.b } func (j *_Bool) String() string { if j.b { return "true"; @@ -160,12 +130,8 @@ type _Map struct { _Null; } -func (j *_Map) Kind() int { - return MapKind; -} -func (j *_Map) Len() int { - return len(j.m); -} +func (j *_Map) Kind() int { return MapKind } +func (j *_Map) Len() int { return len(j.m) } func (j *_Map) Get(s string) Json { if j.m == nil { return Null; @@ -313,38 +279,22 @@ func (b *_JsonBuilder) Get() Json { return nil; } -func (b *_JsonBuilder) Float64(f float64) { - b.Put(&_Number{f, _Null{}}); -} +func (b *_JsonBuilder) Float64(f float64) { b.Put(&_Number{f, _Null{}}) } -func (b *_JsonBuilder) Int64(i int64) { - b.Float64(float64(i)); -} +func (b *_JsonBuilder) Int64(i int64) { b.Float64(float64(i)) } -func (b *_JsonBuilder) Uint64(i uint64) { - b.Float64(float64(i)); -} +func (b *_JsonBuilder) Uint64(i uint64) { b.Float64(float64(i)) } -func (b *_JsonBuilder) Bool(tf bool) { - b.Put(&_Bool{tf, _Null{}}); -} +func (b *_JsonBuilder) Bool(tf bool) { b.Put(&_Bool{tf, _Null{}}) } -func (b *_JsonBuilder) Null() { - b.Put(Null); -} +func (b *_JsonBuilder) Null() { b.Put(Null) } -func (b *_JsonBuilder) String(s string) { - b.Put(&_String{s, _Null{}}); -} +func (b *_JsonBuilder) String(s string) { b.Put(&_String{s, _Null{}}) } -func (b *_JsonBuilder) Array() { - b.Put(&_Array{vector.New(0), _Null{}}); -} +func (b *_JsonBuilder) Array() { b.Put(&_Array{vector.New(0), _Null{}}) } -func (b *_JsonBuilder) Map() { - b.Put(&_Map{make(map[string]Json), _Null{}}); -} +func (b *_JsonBuilder) Map() { b.Put(&_Map{make(map[string]Json), _Null{}}) } func (b *_JsonBuilder) Elem(i int) Builder { bb := new(_JsonBuilder); @@ -364,8 +314,7 @@ func (b *_JsonBuilder) Key(k string) Builder { return bb; } -func (b *_JsonBuilder) Flush() { -} +func (b *_JsonBuilder) Flush() {} // StringToJson parses the string s as a JSON-syntax string // and returns the generic JSON object representation. diff --git a/src/pkg/json/parse.go b/src/pkg/json/parse.go index ba291e940..26c01fe85 100644 --- a/src/pkg/json/parse.go +++ b/src/pkg/json/parse.go @@ -183,9 +183,7 @@ func punct(c byte) bool { return c == '"' || c == '[' || c == ']' || c == ':' || c == '{' || c == '}' || c == ','; } -func white(c byte) bool { - return c == ' ' || c == '\t' || c == '\n' || c == '\v'; -} +func white(c byte) bool { return c == ' ' || c == '\t' || c == '\n' || c == '\v' } func skipwhite(p string, i int) int { for i < len(p) && white(p[i]) { diff --git a/src/pkg/json/struct.go b/src/pkg/json/struct.go index 11cccdce9..37728d38b 100644 --- a/src/pkg/json/struct.go +++ b/src/pkg/json/struct.go @@ -113,8 +113,7 @@ func (b *structBuilder) Float64(f float64) { } } -func (b *structBuilder) Null() { -} +func (b *structBuilder) Null() {} func (b *structBuilder) String(s string) { if b == nil { diff --git a/src/pkg/log/log.go b/src/pkg/log/log.go index 221016674..e5a28031b 100644 --- a/src/pkg/log/log.go +++ b/src/pkg/log/log.go @@ -145,51 +145,31 @@ func (l *Logger) Output(calldepth int, s string) { } // Logf is analogous to Printf() for a Logger. -func (l *Logger) Logf(format string, v ...) { - l.Output(2, fmt.Sprintf(format, v)); -} +func (l *Logger) Logf(format string, v ...) { l.Output(2, fmt.Sprintf(format, v)) } // Log is analogouts to Print() for a Logger. -func (l *Logger) Log(v ...) { - l.Output(2, fmt.Sprintln(v)); -} +func (l *Logger) Log(v ...) { l.Output(2, fmt.Sprintln(v)) } // Stdout is a helper function for easy logging to stdout. It is analogous to Print(). -func Stdout(v ...) { - stdout.Output(2, fmt.Sprint(v)); -} +func Stdout(v ...) { stdout.Output(2, fmt.Sprint(v)) } // Stderr is a helper function for easy logging to stderr. It is analogous to Fprint(os.Stderr). -func Stderr(v ...) { - stderr.Output(2, fmt.Sprintln(v)); -} +func Stderr(v ...) { stderr.Output(2, fmt.Sprintln(v)) } // Stdoutf is a helper functions for easy formatted logging to stdout. It is analogous to Printf(). -func Stdoutf(format string, v ...) { - stdout.Output(2, fmt.Sprintf(format, v)); -} +func Stdoutf(format string, v ...) { stdout.Output(2, fmt.Sprintf(format, v)) } // Stderrf is a helper function for easy formatted logging to stderr. It is analogous to Fprintf(os.Stderr). -func Stderrf(format string, v ...) { - stderr.Output(2, fmt.Sprintf(format, v)); -} +func Stderrf(format string, v ...) { stderr.Output(2, fmt.Sprintf(format, v)) } // Exit is equivalent to Stderr() followed by a call to os.Exit(1). -func Exit(v ...) { - exit.Output(2, fmt.Sprintln(v)); -} +func Exit(v ...) { exit.Output(2, fmt.Sprintln(v)) } // Exitf is equivalent to Stderrf() followed by a call to os.Exit(1). -func Exitf(format string, v ...) { - exit.Output(2, fmt.Sprintf(format, v)); -} +func Exitf(format string, v ...) { exit.Output(2, fmt.Sprintf(format, v)) } // Crash is equivalent to Stderr() followed by a call to panic(). -func Crash(v ...) { - crash.Output(2, fmt.Sprintln(v)); -} +func Crash(v ...) { crash.Output(2, fmt.Sprintln(v)) } // Crashf is equivalent to Stderrf() followed by a call to panic(). -func Crashf(format string, v ...) { - crash.Output(2, fmt.Sprintf(format, v)); -} +func Crashf(format string, v ...) { crash.Output(2, fmt.Sprintf(format, v)) } diff --git a/src/pkg/math/all_test.go b/src/pkg/math/all_test.go index 066f89da8..06c5be200 100644 --- a/src/pkg/math/all_test.go +++ b/src/pkg/math/all_test.go @@ -168,12 +168,8 @@ func tolerance(a, b, e float64) bool { } return d < e; } -func close(a, b float64) bool { - return tolerance(a, b, 1e-14); -} -func veryclose(a, b float64) bool { - return tolerance(a, b, 4e-16); -} +func close(a, b float64) bool { return tolerance(a, b, 1e-14) } +func veryclose(a, b float64) bool { return tolerance(a, b, 4e-16) } func TestAsin(t *testing.T) { for i := 0; i < len(vf); i++ { diff --git a/src/pkg/math/bits.go b/src/pkg/math/bits.go index 100d00623..3084ed508 100644 --- a/src/pkg/math/bits.go +++ b/src/pkg/math/bits.go @@ -25,9 +25,7 @@ func Inf(sign int) float64 { } // NaN returns an IEEE 754 ``not-a-number'' value. -func NaN() float64 { - return Float64frombits(uvnan); -} +func NaN() float64 { return Float64frombits(uvnan) } // IsNaN returns whether f is an IEEE 754 ``not-a-number'' value. func IsNaN(f float64) (is bool) { diff --git a/src/pkg/math/floor.go b/src/pkg/math/floor.go index 7f2c9111d..cb3110fb2 100644 --- a/src/pkg/math/floor.go +++ b/src/pkg/math/floor.go @@ -19,6 +19,4 @@ func Floor(x float64) float64 { } // Ceil returns the least integer value greater than or equal to x. -func Ceil(x float64) float64 { - return -Floor(-x); -} +func Ceil(x float64) float64 { return -Floor(-x) } diff --git a/src/pkg/math/sin.go b/src/pkg/math/sin.go index 973aef554..740d6778b 100644 --- a/src/pkg/math/sin.go +++ b/src/pkg/math/sin.go @@ -58,6 +58,4 @@ func Cos(x float64) float64 { } // Sin returns the sine of x. -func Sin(x float64) float64 { - return sinus(x, 0); -} +func Sin(x float64) float64 { return sinus(x, 0) } diff --git a/src/pkg/math/unsafe.go b/src/pkg/math/unsafe.go index 187dcc225..182b2e13b 100644 --- a/src/pkg/math/unsafe.go +++ b/src/pkg/math/unsafe.go @@ -7,23 +7,15 @@ package math import "unsafe" // Float32bits returns the IEEE 754 binary representation of f. -func Float32bits(f float32) uint32 { - return *(*uint32)(unsafe.Pointer(&f)); -} +func Float32bits(f float32) uint32 { return *(*uint32)(unsafe.Pointer(&f)) } // Float32frombits returns the floating point number corresponding // to the IEEE 754 binary representation b. -func Float32frombits(b uint32) float32 { - return *(*float32)(unsafe.Pointer(&b)); -} +func Float32frombits(b uint32) float32 { return *(*float32)(unsafe.Pointer(&b)) } // Float64bits returns the IEEE 754 binary representation of f. -func Float64bits(f float64) uint64 { - return *(*uint64)(unsafe.Pointer(&f)); -} +func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) } // Float64frombits returns the floating point number corresponding // the IEEE 754 binary representation b. -func Float64frombits(b uint64) float64 { - return *(*float64)(unsafe.Pointer(&b)); -} +func Float64frombits(b uint64) float64 { return *(*float64)(unsafe.Pointer(&b)) } diff --git a/src/pkg/net/dnsclient.go b/src/pkg/net/dnsclient.go index 3c283001b..4a3b7dcc1 100644 --- a/src/pkg/net/dnsclient.go +++ b/src/pkg/net/dnsclient.go @@ -178,9 +178,7 @@ func tryOneName(cfg *_DNS_Config, name string) (addrs []string, err os.Error) { var cfg *_DNS_Config var dnserr os.Error -func loadConfig() { - cfg, dnserr = _DNS_ReadConfig(); -} +func loadConfig() { cfg, dnserr = _DNS_ReadConfig() } func isDomainName(s string) bool { // Requirements on DNS name: diff --git a/src/pkg/net/dnsmsg.go b/src/pkg/net/dnsmsg.go index 93ab3aac0..c7c27e344 100644 --- a/src/pkg/net/dnsmsg.go +++ b/src/pkg/net/dnsmsg.go @@ -231,9 +231,7 @@ type _DNS_RR_A struct { A uint32 "ipv4"; } -func (rr *_DNS_RR_A) Header() *_DNS_RR_Header { - return &rr.Hdr; -} +func (rr *_DNS_RR_A) Header() *_DNS_RR_Header { return &rr.Hdr } // Packing and unpacking. @@ -521,9 +519,7 @@ func printStructValue(val *reflect.StructValue) string { return s; } -func printStruct(any interface{}) string { - return printStructValue(structValue(any)); -} +func printStruct(any interface{}) string { return printStructValue(structValue(any)) } // Resource record packer. func packRR(rr _DNS_RR, msg []byte, off int) (off2 int, ok bool) { diff --git a/src/pkg/net/fd.go b/src/pkg/net/fd.go index 3c326461a..bcb737212 100644 --- a/src/pkg/net/fd.go +++ b/src/pkg/net/fd.go @@ -270,9 +270,7 @@ func (s *pollServer) Run() { var wakeupbuf [1]byte -func (s *pollServer) Wakeup() { - s.pw.Write(&wakeupbuf); -} +func (s *pollServer) Wakeup() { s.pw.Write(&wakeupbuf) } func (s *pollServer) WaitRead(fd *netFD) { s.cr <- fd; diff --git a/src/pkg/net/fd_darwin.go b/src/pkg/net/fd_darwin.go index 8ae9f687c..45acad699 100644 --- a/src/pkg/net/fd_darwin.go +++ b/src/pkg/net/fd_darwin.go @@ -107,6 +107,4 @@ func (p *pollster) WaitFD(nsec int64) (fd int, mode int, err os.Error) { return fd, mode, nil; } -func (p *pollster) Close() os.Error { - return os.NewSyscallError("close", syscall.Close(p.kq)); -} +func (p *pollster) Close() os.Error { return os.NewSyscallError("close", syscall.Close(p.kq)) } diff --git a/src/pkg/net/fd_nacl.go b/src/pkg/net/fd_nacl.go index 36a012b2a..316796486 100644 --- a/src/pkg/net/fd_nacl.go +++ b/src/pkg/net/fd_nacl.go @@ -23,14 +23,11 @@ func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error { func (p *pollster) StopWaiting(fd int, bits uint) { } -func (p *pollster) DelFD(fd int, mode int) { -} +func (p *pollster) DelFD(fd int, mode int) {} func (p *pollster) WaitFD(nsec int64) (fd int, mode int, err os.Error) { _, err = newpollster(); return; } -func (p *pollster) Close() os.Error { - return nil; -} +func (p *pollster) Close() os.Error { return nil } diff --git a/src/pkg/net/ipsock.go b/src/pkg/net/ipsock.go index 76a64e76e..fd37155a2 100644 --- a/src/pkg/net/ipsock.go +++ b/src/pkg/net/ipsock.go @@ -30,9 +30,7 @@ var preferIPv4 = !kernelSupportsIPv6() // TODO(rsc): if syscall.OS == "linux", we're supposd to read // /proc/sys/net/core/somaxconn, // to take advantage of kernels that have raised the limit. -func listenBacklog() int { - return syscall.SOMAXCONN; -} +func listenBacklog() int { return syscall.SOMAXCONN } // Internet sockets (TCP, UDP) diff --git a/src/pkg/net/net.go b/src/pkg/net/net.go index 9c3762ae4..d649756ed 100644 --- a/src/pkg/net/net.go +++ b/src/pkg/net/net.go @@ -266,6 +266,4 @@ func (e *AddrError) String() string { type UnknownNetworkError string -func (e UnknownNetworkError) String() string { - return "unknown network " + string(e); -} +func (e UnknownNetworkError) String() string { return "unknown network " + string(e) } diff --git a/src/pkg/net/parse.go b/src/pkg/net/parse.go index a9ba2d22e..9ed3f2dbd 100644 --- a/src/pkg/net/parse.go +++ b/src/pkg/net/parse.go @@ -17,9 +17,7 @@ type file struct { data []byte; } -func (f *file) close() { - f.file.Close(); -} +func (f *file) close() { f.file.Close() } func (f *file) getLineFromData() (s string, ok bool) { data := f.data; @@ -104,9 +102,7 @@ func splitAtBytes(s string, t string) []string { return a[0:n]; } -func getFields(s string) []string { - return splitAtBytes(s, " \r\t\n"); -} +func getFields(s string) []string { return splitAtBytes(s, " \r\t\n") } // Bigger than we need, not too big to worry about overflow const big = 0xFFFFFF diff --git a/src/pkg/net/tcpsock.go b/src/pkg/net/tcpsock.go index 2c84be03c..a49a73d1b 100644 --- a/src/pkg/net/tcpsock.go +++ b/src/pkg/net/tcpsock.go @@ -28,13 +28,9 @@ type TCPAddr struct { } // Network returns the address's network name, "tcp". -func (a *TCPAddr) Network() string { - return "tcp"; -} +func (a *TCPAddr) Network() string { return "tcp" } -func (a *TCPAddr) String() string { - return joinHostPort(a.IP.String(), itoa(a.Port)); -} +func (a *TCPAddr) String() string { return joinHostPort(a.IP.String(), itoa(a.Port)) } func (a *TCPAddr) family() int { if a == nil || len(a.IP) <= 4 { @@ -81,9 +77,7 @@ func newTCPConn(fd *netFD) *TCPConn { return c; } -func (c *TCPConn) ok() bool { - return c != nil && c.fd != nil; -} +func (c *TCPConn) ok() bool { return c != nil && c.fd != nil } // Implementation of the Conn interface - see Conn for documentation. @@ -283,6 +277,4 @@ func (l *TCPListener) Close() os.Error { } // Addr returns the listener's network address, a *TCPAddr. -func (l *TCPListener) Addr() Addr { - return l.fd.laddr; -} +func (l *TCPListener) Addr() Addr { return l.fd.laddr } diff --git a/src/pkg/net/timeout_test.go b/src/pkg/net/timeout_test.go index 0e03b63f9..acac3c75d 100644 --- a/src/pkg/net/timeout_test.go +++ b/src/pkg/net/timeout_test.go @@ -28,9 +28,7 @@ func testTimeout(t *testing.T, network, addr string) { } } -func TestTimeoutUDP(t *testing.T) { - testTimeout(t, "udp", "127.0.0.1:53"); -} +func TestTimeoutUDP(t *testing.T) { testTimeout(t, "udp", "127.0.0.1:53") } func TestTimeoutTCP(t *testing.T) { // 74.125.19.99 is www.google.com. diff --git a/src/pkg/net/udpsock.go b/src/pkg/net/udpsock.go index f3b6bf6a4..4449e8379 100644 --- a/src/pkg/net/udpsock.go +++ b/src/pkg/net/udpsock.go @@ -28,14 +28,9 @@ type UDPAddr struct { } // Network returns the address's network name, "udp". -func (a *UDPAddr) Network() string { - return "udp"; -} - -func (a *UDPAddr) String() string { - return joinHostPort(a.IP.String(), itoa(a.Port)); +func (a *UDPAddr) Network() string { return "udp" } -} +func (a *UDPAddr) String() string { return joinHostPort(a.IP.String(), itoa(a.Port)) } func (a *UDPAddr) family() int { if a == nil || len(a.IP) <= 4 { @@ -76,13 +71,9 @@ type UDPConn struct { fd *netFD; } -func newUDPConn(fd *netFD) *UDPConn { - return &UDPConn{fd}; -} +func newUDPConn(fd *netFD) *UDPConn { return &UDPConn{fd} } -func (c *UDPConn) ok() bool { - return c != nil && c.fd != nil; -} +func (c *UDPConn) ok() bool { return c != nil && c.fd != nil } // Implementation of the Conn interface - see Conn for documentation. diff --git a/src/pkg/net/unixsock.go b/src/pkg/net/unixsock.go index b30d7f2d4..033f650c3 100644 --- a/src/pkg/net/unixsock.go +++ b/src/pkg/net/unixsock.go @@ -127,13 +127,9 @@ type UnixConn struct { fd *netFD; } -func newUnixConn(fd *netFD) *UnixConn { - return &UnixConn{fd}; -} +func newUnixConn(fd *netFD) *UnixConn { return &UnixConn{fd} } -func (c *UnixConn) ok() bool { - return c != nil && c.fd != nil; -} +func (c *UnixConn) ok() bool { return c != nil && c.fd != nil } // Implementation of the Conn interface - see Conn for documentation. @@ -400,9 +396,7 @@ func (l *UnixListener) Close() os.Error { } // Addr returns the listener's network address. -func (l *UnixListener) Addr() Addr { - return l.fd.laddr; -} +func (l *UnixListener) Addr() Addr { return l.fd.laddr } // ListenUnixgram listens for incoming Unix datagram packets addressed to the // local address laddr. The returned connection c's ReadFrom diff --git a/src/pkg/once/once_test.go b/src/pkg/once/once_test.go index e2e6c2c09..e89e05e81 100644 --- a/src/pkg/once/once_test.go +++ b/src/pkg/once/once_test.go @@ -11,9 +11,7 @@ import ( var ncall int -func call() { - ncall++; -} +func call() { ncall++ } func TestDo(t *testing.T) { ncall = 0; diff --git a/src/pkg/os/error.go b/src/pkg/os/error.go index 809116cff..6bbf5371e 100644 --- a/src/pkg/os/error.go +++ b/src/pkg/os/error.go @@ -15,26 +15,20 @@ type Error interface { // Error. type ErrorString string -func (e ErrorString) String() string { - return string(e); -} +func (e ErrorString) String() string { return string(e) } // Note: If the name of the function NewError changes, // pkg/go/doc/doc.go should be adjusted since it hardwires // this name in a heuristic. // NewError converts s to an ErrorString, which satisfies the Error interface. -func NewError(s string) Error { - return ErrorString(s); -} +func NewError(s string) Error { return ErrorString(s) } // Errno is the Unix error number. Names such as EINVAL are simple // wrappers to convert the error number into an Error. type Errno int64 -func (e Errno) String() string { - return syscall.Errstr(int(e)); -} +func (e Errno) String() string { return syscall.Errstr(int(e)) } // Commonly known Unix errors. var ( @@ -84,9 +78,7 @@ type PathError struct { Error Error; } -func (e *PathError) String() string { - return e.Op + " " + e.Path + ": " + e.Error.String(); -} +func (e *PathError) String() string { return e.Op + " " + e.Path + ": " + e.Error.String() } // SyscallError records an error from a specific system call. type SyscallError struct { @@ -94,9 +86,7 @@ type SyscallError struct { Errno Errno; } -func (e *SyscallError) String() string { - return e.Syscall + ": " + e.Errno.String(); -} +func (e *SyscallError) String() string { return e.Syscall + ": " + e.Errno.String() } // Note: If the name of the function NewSyscallError changes, // pkg/go/doc/doc.go should be adjusted since it hardwires diff --git a/src/pkg/os/exec.go b/src/pkg/os/exec.go index 79d25b2dc..a279bf428 100644 --- a/src/pkg/os/exec.go +++ b/src/pkg/os/exec.go @@ -145,11 +145,7 @@ func (w Waitmsg) String() string { } // Getpid returns the process id of the caller. -func Getpid() int { - return syscall.Getpid(); -} +func Getpid() int { return syscall.Getpid() } // Getppid returns the process id of the caller's parent. -func Getppid() int { - return syscall.Getppid(); -} +func Getppid() int { return syscall.Getppid() } diff --git a/src/pkg/os/file.go b/src/pkg/os/file.go index 578bc2e9e..0afdca39c 100644 --- a/src/pkg/os/file.go +++ b/src/pkg/os/file.go @@ -26,14 +26,10 @@ type File struct { } // Fd returns the integer Unix file descriptor referencing the open file. -func (file *File) Fd() int { - return file.fd; -} +func (file *File) Fd() int { return file.fd } // Name returns the name of the file as presented to Open. -func (file *File) Name() string { - return file.name; -} +func (file *File) Name() string { return file.name } // NewFile returns a new File with the given file descriptor and name. func NewFile(fd int, name string) *File { @@ -102,9 +98,7 @@ func (file *File) Close() Error { type eofError int -func (eofError) String() string { - return "EOF"; -} +func (eofError) String() string { return "EOF" } // EOF is the Error returned by Read when no more input is available. // Functions should return EOF only to signal a graceful end of input. diff --git a/src/pkg/os/proc.go b/src/pkg/os/proc.go index 0dd295edf..e780cfc9a 100644 --- a/src/pkg/os/proc.go +++ b/src/pkg/os/proc.go @@ -13,24 +13,16 @@ var Envs []string // provided by runtime // Getuid returns the numeric user id of the caller. -func Getuid() int { - return syscall.Getuid(); -} +func Getuid() int { return syscall.Getuid() } // Geteuid returns the numeric effective user id of the caller. -func Geteuid() int { - return syscall.Geteuid(); -} +func Geteuid() int { return syscall.Geteuid() } // Getgid returns the numeric group id of the caller. -func Getgid() int { - return syscall.Getgid(); -} +func Getgid() int { return syscall.Getgid() } // Getegid returns the numeric effective group id of the caller. -func Getegid() int { - return syscall.Getegid(); -} +func Getegid() int { return syscall.Getegid() } // Getgroups returns a list of the numeric ids of groups that the caller belongs to. func Getgroups() ([]int, Error) { @@ -40,6 +32,4 @@ func Getgroups() ([]int, Error) { // Exit causes the current program to exit with the given status code. // Conventionally, code zero indicates success, non-zero an error. -func Exit(code int) { - syscall.Exit(code); -} +func Exit(code int) { syscall.Exit(code) } diff --git a/src/pkg/os/sys_nacl.go b/src/pkg/os/sys_nacl.go index 0bea28095..51694a046 100644 --- a/src/pkg/os/sys_nacl.go +++ b/src/pkg/os/sys_nacl.go @@ -4,6 +4,4 @@ package os -func Hostname() (name string, err Error) { - return "nacl", nil; -} +func Hostname() (name string, err Error) { return "nacl", nil } diff --git a/src/pkg/os/types.go b/src/pkg/os/types.go index 7ed547c9b..ec3b4e11b 100644 --- a/src/pkg/os/types.go +++ b/src/pkg/os/types.go @@ -10,9 +10,7 @@ import "syscall" // OS-specific routines in this directory convert the OS-local versions to these. // Getpagesize returns the underlying system's memory page size. -func Getpagesize() int { - return syscall.Getpagesize(); -} +func Getpagesize() int { return syscall.Getpagesize() } // A Dir describes a file and is returned by Stat, Fstat, and Lstat type Dir struct { @@ -34,41 +32,25 @@ type Dir struct { } // IsFifo reports whether the Dir describes a FIFO file. -func (dir *Dir) IsFifo() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFIFO; -} +func (dir *Dir) IsFifo() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFIFO } // IsChar reports whether the Dir describes a character special file. -func (dir *Dir) IsChar() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFCHR; -} +func (dir *Dir) IsChar() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFCHR } // IsDirectory reports whether the Dir describes a directory. -func (dir *Dir) IsDirectory() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFDIR; -} +func (dir *Dir) IsDirectory() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFDIR } // IsBlock reports whether the Dir describes a block special file. -func (dir *Dir) IsBlock() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFBLK; -} +func (dir *Dir) IsBlock() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFBLK } // IsRegular reports whether the Dir describes a regular file. -func (dir *Dir) IsRegular() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFREG; -} +func (dir *Dir) IsRegular() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFREG } // IsSymlink reports whether the Dir describes a symbolic link. -func (dir *Dir) IsSymlink() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFLNK; -} +func (dir *Dir) IsSymlink() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFLNK } // IsSocket reports whether the Dir describes a socket. -func (dir *Dir) IsSocket() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFSOCK; -} +func (dir *Dir) IsSocket() bool { return (dir.Mode & syscall.S_IFMT) == syscall.S_IFSOCK } // Permission returns the file permission bits. -func (dir *Dir) Permission() int { - return int(dir.Mode & 0777); -} +func (dir *Dir) Permission() int { return int(dir.Mode & 0777) } diff --git a/src/pkg/patch/patch.go b/src/pkg/patch/patch.go index c0fdadb84..e8ed627f7 100644 --- a/src/pkg/patch/patch.go +++ b/src/pkg/patch/patch.go @@ -63,9 +63,7 @@ func (noDiffType) Apply(old []byte) ([]byte, os.Error) { // A SyntaxError represents a syntax error encountered while parsing a patch. type SyntaxError string -func (e SyntaxError) String() string { - return string(e); -} +func (e SyntaxError) String() string { return string(e) } var newline = []byte{'\n'} @@ -318,6 +316,4 @@ func hasPrefix(s []byte, t string) bool { // splitLines returns the result of splitting s into lines. // The \n on each line is preserved. -func splitLines(s []byte) [][]byte { - return bytes.SplitAfter(s, newline, 0); -} +func splitLines(s []byte) [][]byte { return bytes.SplitAfter(s, newline, 0) } diff --git a/src/pkg/path/path_test.go b/src/pkg/path/path_test.go index 9036cc185..396d6db7d 100644 --- a/src/pkg/path/path_test.go +++ b/src/pkg/path/path_test.go @@ -186,9 +186,7 @@ func makeTree(t *testing.T) { }); } -func markTree(n *Node) { - walkTree(n, "", func(path string, n *Node) { n.mark++ }); -} +func markTree(n *Node) { walkTree(n, "", func(path string, n *Node) { n.mark++ }) } func checkMarks(t *testing.T) { walkTree(tree, tree.name, func(path string, n *Node) { diff --git a/src/pkg/rand/rand.go b/src/pkg/rand/rand.go index 2e6aab88c..65b14cd18 100644 --- a/src/pkg/rand/rand.go +++ b/src/pkg/rand/rand.go @@ -26,29 +26,19 @@ type Rand struct { // New returns a new Rand that uses random values from src // to generate other random values. -func New(src Source) *Rand { - return &Rand{src}; -} +func New(src Source) *Rand { return &Rand{src} } // Seed uses the provided seed value to initialize the generator to a deterministic state. -func (r *Rand) Seed(seed int64) { - r.src.Seed(seed); -} +func (r *Rand) Seed(seed int64) { r.src.Seed(seed) } // Int63 returns a non-negative pseudo-random 63-bit integer as an int64. -func (r *Rand) Int63() int64 { - return r.src.Int63(); -} +func (r *Rand) Int63() int64 { return r.src.Int63() } // Uint32 returns a pseudo-random 32-bit value as a uint32. -func (r *Rand) Uint32() uint32 { - return uint32(r.Int63() >> 31); -} +func (r *Rand) Uint32() uint32 { return uint32(r.Int63() >> 31) } // Int31 returns a non-negative pseudo-random 31-bit integer as an int32. -func (r *Rand) Int31() int32 { - return int32(r.Int63() >> 32); -} +func (r *Rand) Int31() int32 { return int32(r.Int63() >> 32) } // Int returns a non-negative pseudo-random int. func (r *Rand) Int() int { @@ -70,29 +60,19 @@ func (r *Rand) Int63n(n int64) int64 { } // Int31n returns, as an int32, a non-negative pseudo-random number in [0,n). -func (r *Rand) Int31n(n int32) int32 { - return int32(r.Int63n(int64(n))); -} +func (r *Rand) Int31n(n int32) int32 { return int32(r.Int63n(int64(n))) } // Intn returns, as an int, a non-negative pseudo-random number in [0,n). -func (r *Rand) Intn(n int) int { - return int(r.Int63n(int64(n))); -} +func (r *Rand) Intn(n int) int { return int(r.Int63n(int64(n))) } // Float64 returns, as a float64, a pseudo-random number in [0.0,1.0). -func (r *Rand) Float64() float64 { - return float64(r.Int63())/(1<<63); -} +func (r *Rand) Float64() float64 { return float64(r.Int63())/(1<<63) } // Float32 returns, as a float32, a pseudo-random number in [0.0,1.0). -func (r *Rand) Float32() float32 { - return float32(r.Float64()); -} +func (r *Rand) Float32() float32 { return float32(r.Float64()) } // Float returns, as a float, a pseudo-random number in [0.0,1.0). -func (r *Rand) Float() float { - return float(r.Float64()); -} +func (r *Rand) Float() float { return float(r.Float64()) } // Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n). func (r *Rand) Perm(n int) []int { @@ -114,64 +94,40 @@ func (r *Rand) Perm(n int) []int { var globalRand = New(NewSource(1)) // Seed uses the provided seed value to initialize the generator to a deterministic state. -func Seed(seed int64) { - globalRand.Seed(seed); -} +func Seed(seed int64) { globalRand.Seed(seed) } // Int63 returns a non-negative pseudo-random 63-bit integer as an int64. -func Int63() int64 { - return globalRand.Int63(); -} +func Int63() int64 { return globalRand.Int63() } // Uint32 returns a pseudo-random 32-bit value as a uint32. -func Uint32() uint32 { - return globalRand.Uint32(); -} +func Uint32() uint32 { return globalRand.Uint32() } // Int31 returns a non-negative pseudo-random 31-bit integer as an int32. -func Int31() int32 { - return globalRand.Int31(); -} +func Int31() int32 { return globalRand.Int31() } // Int returns a non-negative pseudo-random int. -func Int() int { - return globalRand.Int(); -} +func Int() int { return globalRand.Int() } // Int63n returns, as an int64, a non-negative pseudo-random number in [0,n). -func Int63n(n int64) int64 { - return globalRand.Int63n(n); -} +func Int63n(n int64) int64 { return globalRand.Int63n(n) } // Int31n returns, as an int32, a non-negative pseudo-random number in [0,n). -func Int31n(n int32) int32 { - return globalRand.Int31n(n); -} +func Int31n(n int32) int32 { return globalRand.Int31n(n) } // Intn returns, as an int, a non-negative pseudo-random number in [0,n). -func Intn(n int) int { - return globalRand.Intn(n); -} +func Intn(n int) int { return globalRand.Intn(n) } // Float64 returns, as a float64, a pseudo-random number in [0.0,1.0). -func Float64() float64 { - return globalRand.Float64(); -} +func Float64() float64 { return globalRand.Float64() } // Float32 returns, as a float32, a pseudo-random number in [0.0,1.0). -func Float32() float32 { - return globalRand.Float32(); -} +func Float32() float32 { return globalRand.Float32() } // Float returns, as a float, a pseudo-random number in [0.0,1.0). -func Float() float { - return globalRand.Float(); -} +func Float() float { return globalRand.Float() } // Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n). -func Perm(n int) []int { - return globalRand.Perm(n); -} +func Perm(n int) []int { return globalRand.Perm(n) } // NormFloat64 returns a normally distributed float64 in the range // [-math.MaxFloat64, +math.MaxFloat64] with @@ -181,9 +137,7 @@ func Perm(n int) []int { // // sample = NormFloat64() * desiredStdDev + desiredMean // -func NormFloat64() float64 { - return globalRand.NormFloat64(); -} +func NormFloat64() float64 { return globalRand.NormFloat64() } // ExpFloat64 returns an exponentially distributed float64 in the range // (0, +math.MaxFloat64] with an exponential distribution whose rate parameter @@ -193,6 +147,4 @@ func NormFloat64() float64 { // // sample = ExpFloat64() / desiredRateParameter // -func ExpFloat64() float64 { - return globalRand.ExpFloat64(); -} +func ExpFloat64() float64 { return globalRand.ExpFloat64() } diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index 5ced27554..abdf57209 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -25,9 +25,7 @@ type pair struct { s string; } -func isDigit(c uint8) bool { - return '0' <= c && c <= '9'; -} +func isDigit(c uint8) bool { return '0' <= c && c <= '9' } func assert(t *testing.T, s, want string) { if s != want { @@ -35,9 +33,7 @@ func assert(t *testing.T, s, want string) { } } -func typestring(i interface{}) string { - return Typeof(i).String(); -} +func typestring(i interface{}) string { return Typeof(i).String() } var typeTests = []pair{ pair{struct { @@ -1070,9 +1066,7 @@ type Point struct { x, y int; } -func (p Point) Dist(scale int) int { - return p.x * p.x * scale + p.y * p.y * scale; -} +func (p Point) Dist(scale int) int { return p.x * p.x * scale + p.y * p.y * scale } func TestMethod(t *testing.T) { // Non-curried method of type. diff --git a/src/pkg/reflect/type.go b/src/pkg/reflect/type.go index b6a526eca..02eb549e8 100644 --- a/src/pkg/reflect/type.go +++ b/src/pkg/reflect/type.go @@ -291,21 +291,13 @@ func (t *uncommonType) Name() string { return *t.name; } -func (t *commonType) String() string { - return *t.string; -} +func (t *commonType) String() string { return *t.string } -func (t *commonType) Size() uintptr { - return t.size; -} +func (t *commonType) Size() uintptr { return t.size } -func (t *commonType) Align() int { - return int(t.align); -} +func (t *commonType) Align() int { return int(t.align) } -func (t *commonType) FieldAlign() int { - return int(t.fieldAlign); -} +func (t *commonType) FieldAlign() int { return int(t.fieldAlign) } func (t *uncommonType) Method(i int) (m Method) { if t == nil || i < 0 || i >= len(t.methods) { @@ -334,41 +326,25 @@ func (t *uncommonType) NumMethod() int { // TODO(rsc): 6g supplies these, but they are not // as efficient as they could be: they have commonType // as the receiver instead of *commonType. -func (t *commonType) NumMethod() int { - return t.uncommonType.NumMethod(); -} +func (t *commonType) NumMethod() int { return t.uncommonType.NumMethod() } -func (t *commonType) Method(i int) (m Method) { - return t.uncommonType.Method(i); -} +func (t *commonType) Method(i int) (m Method) { return t.uncommonType.Method(i) } -func (t *commonType) PkgPath() string { - return t.uncommonType.PkgPath(); -} +func (t *commonType) PkgPath() string { return t.uncommonType.PkgPath() } -func (t *commonType) Name() string { - return t.uncommonType.Name(); -} +func (t *commonType) Name() string { return t.uncommonType.Name() } // Len returns the number of elements in the array. -func (t *ArrayType) Len() int { - return int(t.len); -} +func (t *ArrayType) Len() int { return int(t.len) } // Elem returns the type of the array's elements. -func (t *ArrayType) Elem() Type { - return toType(*t.elem); -} +func (t *ArrayType) Elem() Type { return toType(*t.elem) } // Dir returns the channel direction. -func (t *ChanType) Dir() ChanDir { - return ChanDir(t.dir); -} +func (t *ChanType) Dir() ChanDir { return ChanDir(t.dir) } // Elem returns the channel's element type. -func (t *ChanType) Elem() Type { - return toType(*t.elem); -} +func (t *ChanType) Elem() Type { return toType(*t.elem) } func (d ChanDir) String() string { switch d { @@ -391,9 +367,7 @@ func (t *FuncType) In(i int) Type { } // NumIn returns the number of input parameters. -func (t *FuncType) NumIn() int { - return len(t.in); -} +func (t *FuncType) NumIn() int { return len(t.in) } // Out returns the type of the i'th function output parameter. func (t *FuncType) Out(i int) Type { @@ -404,9 +378,7 @@ func (t *FuncType) Out(i int) Type { } // NumOut returns the number of function output parameters. -func (t *FuncType) NumOut() int { - return len(t.out); -} +func (t *FuncType) NumOut() int { return len(t.out) } // Method returns the i'th interface method. func (t *InterfaceType) Method(i int) (m Method) { @@ -423,29 +395,19 @@ func (t *InterfaceType) Method(i int) (m Method) { } // NumMethod returns the number of interface methods. -func (t *InterfaceType) NumMethod() int { - return len(t.methods); -} +func (t *InterfaceType) NumMethod() int { return len(t.methods) } // Key returns the map key type. -func (t *MapType) Key() Type { - return toType(*t.key); -} +func (t *MapType) Key() Type { return toType(*t.key) } // Elem returns the map element type. -func (t *MapType) Elem() Type { - return toType(*t.elem); -} +func (t *MapType) Elem() Type { return toType(*t.elem) } // Elem returns the pointer element type. -func (t *PtrType) Elem() Type { - return toType(*t.elem); -} +func (t *PtrType) Elem() Type { return toType(*t.elem) } // Elem returns the type of the slice's elements. -func (t *SliceType) Elem() Type { - return toType(*t.elem); -} +func (t *SliceType) Elem() Type { return toType(*t.elem) } type StructField struct { PkgPath string; // empty for uppercase Name @@ -588,9 +550,7 @@ func (t *StructType) FieldByName(name string) (f StructField, present bool) { } // NumField returns the number of struct fields. -func (t *StructType) NumField() int { - return len(t.fields); -} +func (t *StructType) NumField() int { return len(t.fields) } // Convert runtime type to reflect type. // Same memory layouts, different method sets. @@ -660,6 +620,4 @@ type ArrayOrSliceType interface { } // Typeof returns the reflection Type of the value in the interface{}. -func Typeof(i interface{}) Type { - return toType(unsafe.Typeof(i)); -} +func Typeof(i interface{}) Type { return toType(unsafe.Typeof(i)) } diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go index f58f64277..453fe8a8f 100644 --- a/src/pkg/reflect/value.go +++ b/src/pkg/reflect/value.go @@ -80,17 +80,11 @@ type value struct { canSet bool; } -func (v *value) Type() Type { - return v.typ; -} +func (v *value) Type() Type { return v.typ } -func (v *value) Addr() uintptr { - return uintptr(v.addr); -} +func (v *value) Addr() uintptr { return uintptr(v.addr) } -func (v *value) getAddr() addr { - return v.addr; -} +func (v *value) getAddr() addr { return v.addr } func (v *value) Interface() interface{} { if typ, ok := v.typ.(*InterfaceType); ok { @@ -110,9 +104,7 @@ func (v *value) Interface() interface{} { return unsafe.Unreflect(v.typ, unsafe.Pointer(v.addr)); } -func (v *value) CanSet() bool { - return v.canSet; -} +func (v *value) CanSet() bool { return v.canSet } /* * basic types @@ -124,9 +116,7 @@ type BoolValue struct { } // Get returns the underlying bool value. -func (v *BoolValue) Get() bool { - return *(*bool)(v.addr); -} +func (v *BoolValue) Get() bool { return *(*bool)(v.addr) } // Set sets v to the value x. func (v *BoolValue) Set(x bool) { @@ -137,9 +127,7 @@ func (v *BoolValue) Set(x bool) { } // Set sets v to the value x. -func (v *BoolValue) SetValue(x Value) { - v.Set(x.(*BoolValue).Get()); -} +func (v *BoolValue) SetValue(x Value) { v.Set(x.(*BoolValue).Get()) } // FloatValue represents a float value. type FloatValue struct { @@ -147,9 +135,7 @@ type FloatValue struct { } // Get returns the underlying float value. -func (v *FloatValue) Get() float { - return *(*float)(v.addr); -} +func (v *FloatValue) Get() float { return *(*float)(v.addr) } // Set sets v to the value x. func (v *FloatValue) Set(x float) { @@ -160,9 +146,7 @@ func (v *FloatValue) Set(x float) { } // Set sets v to the value x. -func (v *FloatValue) SetValue(x Value) { - v.Set(x.(*FloatValue).Get()); -} +func (v *FloatValue) SetValue(x Value) { v.Set(x.(*FloatValue).Get()) } // Float32Value represents a float32 value. type Float32Value struct { @@ -170,9 +154,7 @@ type Float32Value struct { } // Get returns the underlying float32 value. -func (v *Float32Value) Get() float32 { - return *(*float32)(v.addr); -} +func (v *Float32Value) Get() float32 { return *(*float32)(v.addr) } // Set sets v to the value x. func (v *Float32Value) Set(x float32) { @@ -183,9 +165,7 @@ func (v *Float32Value) Set(x float32) { } // Set sets v to the value x. -func (v *Float32Value) SetValue(x Value) { - v.Set(x.(*Float32Value).Get()); -} +func (v *Float32Value) SetValue(x Value) { v.Set(x.(*Float32Value).Get()) } // Float64Value represents a float64 value. type Float64Value struct { @@ -193,9 +173,7 @@ type Float64Value struct { } // Get returns the underlying float64 value. -func (v *Float64Value) Get() float64 { - return *(*float64)(v.addr); -} +func (v *Float64Value) Get() float64 { return *(*float64)(v.addr) } // Set sets v to the value x. func (v *Float64Value) Set(x float64) { @@ -206,9 +184,7 @@ func (v *Float64Value) Set(x float64) { } // Set sets v to the value x. -func (v *Float64Value) SetValue(x Value) { - v.Set(x.(*Float64Value).Get()); -} +func (v *Float64Value) SetValue(x Value) { v.Set(x.(*Float64Value).Get()) } // IntValue represents an int value. type IntValue struct { @@ -216,9 +192,7 @@ type IntValue struct { } // Get returns the underlying int value. -func (v *IntValue) Get() int { - return *(*int)(v.addr); -} +func (v *IntValue) Get() int { return *(*int)(v.addr) } // Set sets v to the value x. func (v *IntValue) Set(x int) { @@ -229,9 +203,7 @@ func (v *IntValue) Set(x int) { } // Set sets v to the value x. -func (v *IntValue) SetValue(x Value) { - v.Set(x.(*IntValue).Get()); -} +func (v *IntValue) SetValue(x Value) { v.Set(x.(*IntValue).Get()) } // Int8Value represents an int8 value. type Int8Value struct { @@ -239,9 +211,7 @@ type Int8Value struct { } // Get returns the underlying int8 value. -func (v *Int8Value) Get() int8 { - return *(*int8)(v.addr); -} +func (v *Int8Value) Get() int8 { return *(*int8)(v.addr) } // Set sets v to the value x. func (v *Int8Value) Set(x int8) { @@ -252,9 +222,7 @@ func (v *Int8Value) Set(x int8) { } // Set sets v to the value x. -func (v *Int8Value) SetValue(x Value) { - v.Set(x.(*Int8Value).Get()); -} +func (v *Int8Value) SetValue(x Value) { v.Set(x.(*Int8Value).Get()) } // Int16Value represents an int16 value. type Int16Value struct { @@ -262,9 +230,7 @@ type Int16Value struct { } // Get returns the underlying int16 value. -func (v *Int16Value) Get() int16 { - return *(*int16)(v.addr); -} +func (v *Int16Value) Get() int16 { return *(*int16)(v.addr) } // Set sets v to the value x. func (v *Int16Value) Set(x int16) { @@ -275,9 +241,7 @@ func (v *Int16Value) Set(x int16) { } // Set sets v to the value x. -func (v *Int16Value) SetValue(x Value) { - v.Set(x.(*Int16Value).Get()); -} +func (v *Int16Value) SetValue(x Value) { v.Set(x.(*Int16Value).Get()) } // Int32Value represents an int32 value. type Int32Value struct { @@ -285,9 +249,7 @@ type Int32Value struct { } // Get returns the underlying int32 value. -func (v *Int32Value) Get() int32 { - return *(*int32)(v.addr); -} +func (v *Int32Value) Get() int32 { return *(*int32)(v.addr) } // Set sets v to the value x. func (v *Int32Value) Set(x int32) { @@ -298,9 +260,7 @@ func (v *Int32Value) Set(x int32) { } // Set sets v to the value x. -func (v *Int32Value) SetValue(x Value) { - v.Set(x.(*Int32Value).Get()); -} +func (v *Int32Value) SetValue(x Value) { v.Set(x.(*Int32Value).Get()) } // Int64Value represents an int64 value. type Int64Value struct { @@ -308,9 +268,7 @@ type Int64Value struct { } // Get returns the underlying int64 value. -func (v *Int64Value) Get() int64 { - return *(*int64)(v.addr); -} +func (v *Int64Value) Get() int64 { return *(*int64)(v.addr) } // Set sets v to the value x. func (v *Int64Value) Set(x int64) { @@ -321,9 +279,7 @@ func (v *Int64Value) Set(x int64) { } // Set sets v to the value x. -func (v *Int64Value) SetValue(x Value) { - v.Set(x.(*Int64Value).Get()); -} +func (v *Int64Value) SetValue(x Value) { v.Set(x.(*Int64Value).Get()) } // StringValue represents a string value. type StringValue struct { @@ -331,9 +287,7 @@ type StringValue struct { } // Get returns the underlying string value. -func (v *StringValue) Get() string { - return *(*string)(v.addr); -} +func (v *StringValue) Get() string { return *(*string)(v.addr) } // Set sets v to the value x. func (v *StringValue) Set(x string) { @@ -344,9 +298,7 @@ func (v *StringValue) Set(x string) { } // Set sets v to the value x. -func (v *StringValue) SetValue(x Value) { - v.Set(x.(*StringValue).Get()); -} +func (v *StringValue) SetValue(x Value) { v.Set(x.(*StringValue).Get()) } // UintValue represents a uint value. type UintValue struct { @@ -354,9 +306,7 @@ type UintValue struct { } // Get returns the underlying uint value. -func (v *UintValue) Get() uint { - return *(*uint)(v.addr); -} +func (v *UintValue) Get() uint { return *(*uint)(v.addr) } // Set sets v to the value x. func (v *UintValue) Set(x uint) { @@ -367,9 +317,7 @@ func (v *UintValue) Set(x uint) { } // Set sets v to the value x. -func (v *UintValue) SetValue(x Value) { - v.Set(x.(*UintValue).Get()); -} +func (v *UintValue) SetValue(x Value) { v.Set(x.(*UintValue).Get()) } // Uint8Value represents a uint8 value. type Uint8Value struct { @@ -377,9 +325,7 @@ type Uint8Value struct { } // Get returns the underlying uint8 value. -func (v *Uint8Value) Get() uint8 { - return *(*uint8)(v.addr); -} +func (v *Uint8Value) Get() uint8 { return *(*uint8)(v.addr) } // Set sets v to the value x. func (v *Uint8Value) Set(x uint8) { @@ -390,9 +336,7 @@ func (v *Uint8Value) Set(x uint8) { } // Set sets v to the value x. -func (v *Uint8Value) SetValue(x Value) { - v.Set(x.(*Uint8Value).Get()); -} +func (v *Uint8Value) SetValue(x Value) { v.Set(x.(*Uint8Value).Get()) } // Uint16Value represents a uint16 value. type Uint16Value struct { @@ -400,9 +344,7 @@ type Uint16Value struct { } // Get returns the underlying uint16 value. -func (v *Uint16Value) Get() uint16 { - return *(*uint16)(v.addr); -} +func (v *Uint16Value) Get() uint16 { return *(*uint16)(v.addr) } // Set sets v to the value x. func (v *Uint16Value) Set(x uint16) { @@ -413,9 +355,7 @@ func (v *Uint16Value) Set(x uint16) { } // Set sets v to the value x. -func (v *Uint16Value) SetValue(x Value) { - v.Set(x.(*Uint16Value).Get()); -} +func (v *Uint16Value) SetValue(x Value) { v.Set(x.(*Uint16Value).Get()) } // Uint32Value represents a uint32 value. type Uint32Value struct { @@ -423,9 +363,7 @@ type Uint32Value struct { } // Get returns the underlying uint32 value. -func (v *Uint32Value) Get() uint32 { - return *(*uint32)(v.addr); -} +func (v *Uint32Value) Get() uint32 { return *(*uint32)(v.addr) } // Set sets v to the value x. func (v *Uint32Value) Set(x uint32) { @@ -436,9 +374,7 @@ func (v *Uint32Value) Set(x uint32) { } // Set sets v to the value x. -func (v *Uint32Value) SetValue(x Value) { - v.Set(x.(*Uint32Value).Get()); -} +func (v *Uint32Value) SetValue(x Value) { v.Set(x.(*Uint32Value).Get()) } // Uint64Value represents a uint64 value. type Uint64Value struct { @@ -446,9 +382,7 @@ type Uint64Value struct { } // Get returns the underlying uint64 value. -func (v *Uint64Value) Get() uint64 { - return *(*uint64)(v.addr); -} +func (v *Uint64Value) Get() uint64 { return *(*uint64)(v.addr) } // Set sets v to the value x. func (v *Uint64Value) Set(x uint64) { @@ -459,9 +393,7 @@ func (v *Uint64Value) Set(x uint64) { } // Set sets v to the value x. -func (v *Uint64Value) SetValue(x Value) { - v.Set(x.(*Uint64Value).Get()); -} +func (v *Uint64Value) SetValue(x Value) { v.Set(x.(*Uint64Value).Get()) } // UintptrValue represents a uintptr value. type UintptrValue struct { @@ -469,9 +401,7 @@ type UintptrValue struct { } // Get returns the underlying uintptr value. -func (v *UintptrValue) Get() uintptr { - return *(*uintptr)(v.addr); -} +func (v *UintptrValue) Get() uintptr { return *(*uintptr)(v.addr) } // Set sets v to the value x. func (v *UintptrValue) Set(x uintptr) { @@ -482,9 +412,7 @@ func (v *UintptrValue) Set(x uintptr) { } // Set sets v to the value x. -func (v *UintptrValue) SetValue(x Value) { - v.Set(x.(*UintptrValue).Get()); -} +func (v *UintptrValue) SetValue(x Value) { v.Set(x.(*UintptrValue).Get()) } // UnsafePointerValue represents an unsafe.Pointer value. type UnsafePointerValue struct { @@ -495,9 +423,7 @@ type UnsafePointerValue struct { // Get returns uintptr, not unsafe.Pointer, so that // programs that do not import "unsafe" cannot // obtain a value of unsafe.Pointer type from "reflect". -func (v *UnsafePointerValue) Get() uintptr { - return uintptr(*(*unsafe.Pointer)(v.addr)); -} +func (v *UnsafePointerValue) Get() uintptr { return uintptr(*(*unsafe.Pointer)(v.addr)) } // Set sets v to the value x. func (v *UnsafePointerValue) Set(x unsafe.Pointer) { @@ -556,19 +482,13 @@ type ArrayValue struct { } // Len returns the length of the array. -func (v *ArrayValue) Len() int { - return v.typ.(*ArrayType).Len(); -} +func (v *ArrayValue) Len() int { return v.typ.(*ArrayType).Len() } // Cap returns the capacity of the array (equal to Len()). -func (v *ArrayValue) Cap() int { - return v.typ.(*ArrayType).Len(); -} +func (v *ArrayValue) Cap() int { return v.typ.(*ArrayType).Len() } // addr returns the base address of the data in the array. -func (v *ArrayValue) addr() addr { - return v.value.addr; -} +func (v *ArrayValue) addr() addr { return v.value.addr } // Set assigns x to v. // The new value x must have the same type as v. @@ -581,9 +501,7 @@ func (v *ArrayValue) Set(x *ArrayValue) { } // Set sets v to the value x. -func (v *ArrayValue) SetValue(x Value) { - v.Set(x.(*ArrayValue)); -} +func (v *ArrayValue) SetValue(x Value) { v.Set(x.(*ArrayValue)) } // Elem returns the i'th element of v. func (v *ArrayValue) Elem(i int) Value { @@ -612,29 +530,19 @@ type SliceValue struct { value; } -func (v *SliceValue) slice() *SliceHeader { - return (*SliceHeader)(v.value.addr); -} +func (v *SliceValue) slice() *SliceHeader { return (*SliceHeader)(v.value.addr) } // IsNil returns whether v is a nil slice. -func (v *SliceValue) IsNil() bool { - return v.slice().Data == 0; -} +func (v *SliceValue) IsNil() bool { return v.slice().Data == 0 } // Len returns the length of the slice. -func (v *SliceValue) Len() int { - return int(v.slice().Len); -} +func (v *SliceValue) Len() int { return int(v.slice().Len) } // Cap returns the capacity of the slice. -func (v *SliceValue) Cap() int { - return int(v.slice().Cap); -} +func (v *SliceValue) Cap() int { return int(v.slice().Cap) } // addr returns the base address of the data in the slice. -func (v *SliceValue) addr() addr { - return addr(v.slice().Data); -} +func (v *SliceValue) addr() addr { return addr(v.slice().Data) } // SetLen changes the length of v. // The new length n must be between 0 and the capacity, inclusive. @@ -657,9 +565,7 @@ func (v *SliceValue) Set(x *SliceValue) { } // Set sets v to the value x. -func (v *SliceValue) SetValue(x Value) { - v.Set(x.(*SliceValue)); -} +func (v *SliceValue) SetValue(x Value) { v.Set(x.(*SliceValue)) } // Slice returns a sub-slice of the slice v. func (v *SliceValue) Slice(beg, end int) *SliceValue { @@ -711,9 +617,7 @@ type ChanValue struct { } // IsNil returns whether v is a nil channel. -func (v *ChanValue) IsNil() bool { - return *(*uintptr)(v.addr) == 0; -} +func (v *ChanValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 } // Set assigns x to v. // The new value x must have the same type as v. @@ -726,15 +630,11 @@ func (v *ChanValue) Set(x *ChanValue) { } // Set sets v to the value x. -func (v *ChanValue) SetValue(x Value) { - v.Set(x.(*ChanValue)); -} +func (v *ChanValue) SetValue(x Value) { v.Set(x.(*ChanValue)) } // Get returns the uintptr value of v. // It is mainly useful for printing. -func (v *ChanValue) Get() uintptr { - return *(*uintptr)(v.addr); -} +func (v *ChanValue) Get() uintptr { return *(*uintptr)(v.addr) } // implemented in ../pkg/runtime/reflect.cgo func makechan(typ *runtime.ChanType, size uint32) (ch *byte) @@ -791,14 +691,10 @@ func (v *ChanValue) recv(b *bool) Value { } // Send sends x on the channel v. -func (v *ChanValue) Send(x Value) { - v.send(x, nil); -} +func (v *ChanValue) Send(x Value) { v.send(x, nil) } // Recv receives and returns a value from the channel v. -func (v *ChanValue) Recv() Value { - return v.recv(nil); -} +func (v *ChanValue) Recv() Value { return v.recv(nil) } // TrySend attempts to sends x on the channel v but will not block. // It returns true if the value was sent, false otherwise. @@ -844,15 +740,11 @@ type FuncValue struct { } // IsNil returns whether v is a nil function. -func (v *FuncValue) IsNil() bool { - return *(*uintptr)(v.addr) == 0; -} +func (v *FuncValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 } // Get returns the uintptr value of v. // It is mainly useful for printing. -func (v *FuncValue) Get() uintptr { - return *(*uintptr)(v.addr); -} +func (v *FuncValue) Get() uintptr { return *(*uintptr)(v.addr) } // Set assigns x to v. // The new value x must have the same type as v. @@ -865,9 +757,7 @@ func (v *FuncValue) Set(x *FuncValue) { } // Set sets v to the value x. -func (v *FuncValue) SetValue(x Value) { - v.Set(x.(*FuncValue)); -} +func (v *FuncValue) SetValue(x Value) { v.Set(x.(*FuncValue)) } // Method returns a FuncValue corresponding to v's i'th method. // The arguments to a Call on the returned FuncValue @@ -1006,14 +896,10 @@ type InterfaceValue struct { // No Get because v.Interface() is available. // IsNil returns whether v is a nil interface value. -func (v *InterfaceValue) IsNil() bool { - return v.Interface() == nil; -} +func (v *InterfaceValue) IsNil() bool { return v.Interface() == nil } // Elem returns the concrete value stored in the interface value v. -func (v *InterfaceValue) Elem() Value { - return NewValue(v.Interface()); -} +func (v *InterfaceValue) Elem() Value { return NewValue(v.Interface()) } // ../runtime/reflect.cgo func setiface(typ *InterfaceType, x *interface{}, addr addr) @@ -1037,9 +923,7 @@ func (v *InterfaceValue) Set(x Value) { } // Set sets v to the value x. -func (v *InterfaceValue) SetValue(x Value) { - v.Set(x); -} +func (v *InterfaceValue) SetValue(x Value) { v.Set(x) } // Method returns a FuncValue corresponding to v's i'th method. // The arguments to a Call on the returned FuncValue @@ -1072,9 +956,7 @@ type MapValue struct { } // IsNil returns whether v is a nil map value. -func (v *MapValue) IsNil() bool { - return *(*uintptr)(v.addr) == 0; -} +func (v *MapValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 } // Set assigns x to v. // The new value x must have the same type as v. @@ -1087,9 +969,7 @@ func (v *MapValue) Set(x *MapValue) { } // Set sets v to the value x. -func (v *MapValue) SetValue(x Value) { - v.Set(x.(*MapValue)); -} +func (v *MapValue) SetValue(x Value) { v.Set(x.(*MapValue)) } // implemented in ../pkg/runtime/reflect.cgo func mapaccess(m, key, val *byte) bool @@ -1179,15 +1059,11 @@ type PtrValue struct { } // IsNil returns whether v is a nil pointer. -func (v *PtrValue) IsNil() bool { - return *(*uintptr)(v.addr) == 0; -} +func (v *PtrValue) IsNil() bool { return *(*uintptr)(v.addr) == 0 } // Get returns the uintptr value of v. // It is mainly useful for printing. -func (v *PtrValue) Get() uintptr { - return *(*uintptr)(v.addr); -} +func (v *PtrValue) Get() uintptr { return *(*uintptr)(v.addr) } // Set assigns x to v. // The new value x must have the same type as v. @@ -1202,9 +1078,7 @@ func (v *PtrValue) Set(x *PtrValue) { } // Set sets v to the value x. -func (v *PtrValue) SetValue(x Value) { - v.Set(x.(*PtrValue)); -} +func (v *PtrValue) SetValue(x Value) { v.Set(x.(*PtrValue)) } // PointTo changes v to point to x. func (v *PtrValue) PointTo(x Value) { @@ -1258,9 +1132,7 @@ func (v *StructValue) Set(x *StructValue) { } // Set sets v to the value x. -func (v *StructValue) SetValue(x Value) { - v.Set(x.(*StructValue)); -} +func (v *StructValue) SetValue(x Value) { v.Set(x.(*StructValue)) } // Field returns the i'th field of the struct. func (v *StructValue) Field(i int) Value { @@ -1302,9 +1174,7 @@ func (t *StructValue) FieldByName(name string) Value { } // NumField returns the number of fields in the struct. -func (v *StructValue) NumField() int { - return v.typ.(*StructType).NumField(); -} +func (v *StructValue) NumField() int { return v.typ.(*StructType).NumField() } /* * constructors diff --git a/src/pkg/regexp/regexp.go b/src/pkg/regexp/regexp.go index 27fb8ef5d..24fd597f7 100644 --- a/src/pkg/regexp/regexp.go +++ b/src/pkg/regexp/regexp.go @@ -62,18 +62,10 @@ type common struct { _index int; } -func (c *common) next() instr { - return c._next; -} -func (c *common) setNext(i instr) { - c._next = i; -} -func (c *common) index() int { - return c._index; -} -func (c *common) setIndex(i int) { - c._index = i; -} +func (c *common) next() instr { return c._next } +func (c *common) setNext(i instr) { c._next = i } +func (c *common) index() int { return c._index } +func (c *common) setIndex(i int) { c._index = i } // Regexp is the representation of a compiled regular expression. // The public interface is entirely through methods. @@ -104,48 +96,32 @@ type _Start struct { common; } -func (start *_Start) kind() int { - return _START; -} -func (start *_Start) print() { - print("start"); -} +func (start *_Start) kind() int { return _START } +func (start *_Start) print() { print("start") } // --- END end of program type _End struct { common; } -func (end *_End) kind() int { - return _END; -} -func (end *_End) print() { - print("end"); -} +func (end *_End) kind() int { return _END } +func (end *_End) print() { print("end") } // --- BOT beginning of text type _Bot struct { common; } -func (bot *_Bot) kind() int { - return _BOT; -} -func (bot *_Bot) print() { - print("bot"); -} +func (bot *_Bot) kind() int { return _BOT } +func (bot *_Bot) print() { print("bot") } // --- EOT end of text type _Eot struct { common; } -func (eot *_Eot) kind() int { - return _EOT; -} -func (eot *_Eot) print() { - print("eot"); -} +func (eot *_Eot) kind() int { return _EOT } +func (eot *_Eot) print() { print("eot") } // --- CHAR a regular character type _Char struct { @@ -153,12 +129,8 @@ type _Char struct { char int; } -func (char *_Char) kind() int { - return _CHAR; -} -func (char *_Char) print() { - print("char ", string(char.char)); -} +func (char *_Char) kind() int { return _CHAR } +func (char *_Char) print() { print("char ", string(char.char)) } func newChar(char int) *_Char { c := new(_Char); @@ -176,9 +148,7 @@ type _CharClass struct { ranges *vector.IntVector; } -func (cclass *_CharClass) kind() int { - return _CHARCLASS; -} +func (cclass *_CharClass) kind() int { return _CHARCLASS } func (cclass *_CharClass) print() { print("charclass"); @@ -224,24 +194,16 @@ type _Any struct { common; } -func (any *_Any) kind() int { - return _ANY; -} -func (any *_Any) print() { - print("any"); -} +func (any *_Any) kind() int { return _ANY } +func (any *_Any) print() { print("any") } // --- NOTNL any character but newline type _NotNl struct { common; } -func (notnl *_NotNl) kind() int { - return _NOTNL; -} -func (notnl *_NotNl) print() { - print("notnl"); -} +func (notnl *_NotNl) kind() int { return _NOTNL } +func (notnl *_NotNl) print() { print("notnl") } // --- BRA parenthesized expression type _Bra struct { @@ -249,12 +211,8 @@ type _Bra struct { n int; // subexpression number } -func (bra *_Bra) kind() int { - return _BRA; -} -func (bra *_Bra) print() { - print("bra", bra.n); -} +func (bra *_Bra) kind() int { return _BRA } +func (bra *_Bra) print() { print("bra", bra.n) } // --- EBRA end of parenthesized expression type _Ebra struct { @@ -262,12 +220,8 @@ type _Ebra struct { n int; // subexpression number } -func (ebra *_Ebra) kind() int { - return _EBRA; -} -func (ebra *_Ebra) print() { - print("ebra ", ebra.n); -} +func (ebra *_Ebra) kind() int { return _EBRA } +func (ebra *_Ebra) print() { print("ebra ", ebra.n) } // --- ALT alternation type _Alt struct { @@ -275,24 +229,16 @@ type _Alt struct { left instr; // other branch } -func (alt *_Alt) kind() int { - return _ALT; -} -func (alt *_Alt) print() { - print("alt(", alt.left.index(), ")"); -} +func (alt *_Alt) kind() int { return _ALT } +func (alt *_Alt) print() { print("alt(", alt.left.index(), ")") } // --- NOP no operation type _Nop struct { common; } -func (nop *_Nop) kind() int { - return _NOP; -} -func (nop *_Nop) print() { - print("nop"); -} +func (nop *_Nop) kind() int { return _NOP } +func (nop *_Nop) print() { print("nop") } func (re *Regexp) add(i instr) instr { i.setIndex(re.inst.Len()); @@ -310,9 +256,7 @@ type parser struct { const endOfFile = -1 -func (p *parser) c() int { - return p.ch; -} +func (p *parser) c() int { return p.ch } func (p *parser) nextc() int { if p.pos >= len(p.re.expr) { @@ -840,23 +784,17 @@ func (re *Regexp) ExecuteString(s string) (a []int) { // b[a[2*i]:a[2*i+1]] for i > 0 is the subslice matched by the ith parenthesized subexpression. // A negative value means the subexpression did not match any element of the slice. // An empty array means "no match". -func (re *Regexp) Execute(b []byte) (a []int) { - return re.doExecute("", b, 0); -} +func (re *Regexp) Execute(b []byte) (a []int) { return re.doExecute("", b, 0) } // MatchString returns whether the Regexp matches the string s. // The return value is a boolean: true for match, false for no match. -func (re *Regexp) MatchString(s string) bool { - return len(re.doExecute(s, nil, 0)) > 0; -} +func (re *Regexp) MatchString(s string) bool { return len(re.doExecute(s, nil, 0)) > 0 } // Match returns whether the Regexp matches the byte slice b. // The return value is a boolean: true for match, false for no match. -func (re *Regexp) Match(b []byte) bool { - return len(re.doExecute("", b, 0)) > 0; -} +func (re *Regexp) Match(b []byte) bool { return len(re.doExecute("", b, 0)) > 0 } // MatchStrings matches the Regexp against the string s. diff --git a/src/pkg/rpc/debug.go b/src/pkg/rpc/debug.go index fd6acf584..425b7e6e4 100644 --- a/src/pkg/rpc/debug.go +++ b/src/pkg/rpc/debug.go @@ -53,25 +53,13 @@ type debugService struct { type serviceArray []debugService -func (s serviceArray) Len() int { - return len(s); -} -func (s serviceArray) Less(i, j int) bool { - return s[i].name < s[j].name; -} -func (s serviceArray) Swap(i, j int) { - s[i], s[j] = s[j], s[i]; -} +func (s serviceArray) Len() int { return len(s) } +func (s serviceArray) Less(i, j int) bool { return s[i].name < s[j].name } +func (s serviceArray) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (m methodArray) Len() int { - return len(m); -} -func (m methodArray) Less(i, j int) bool { - return m[i].name < m[j].name; -} -func (m methodArray) Swap(i, j int) { - m[i], m[j] = m[j], m[i]; -} +func (m methodArray) Len() int { return len(m) } +func (m methodArray) Less(i, j int) bool { return m[i].name < m[j].name } +func (m methodArray) Swap(i, j int) { m[i], m[j] = m[j], m[i] } // Runs at /debug/rpc func debugHTTP(c *http.Conn, req *http.Request) { diff --git a/src/pkg/rpc/server.go b/src/pkg/rpc/server.go index c0fd9373b..3403c74bc 100644 --- a/src/pkg/rpc/server.go +++ b/src/pkg/rpc/server.go @@ -370,23 +370,17 @@ func (server *serverType) accept(lis net.Listener) { // - one return value of type os.Error // It returns an error if the receiver is not public or has no // suitable methods. -func Register(rcvr interface{}) os.Error { - return server.register(rcvr); -} +func Register(rcvr interface{}) os.Error { return server.register(rcvr) } // ServeConn runs the server on a single connection. When the connection // completes, service terminates. ServeConn blocks; the caller typically // invokes it in a go statement. -func ServeConn(conn io.ReadWriteCloser) { - go server.input(conn); -} +func ServeConn(conn io.ReadWriteCloser) { go server.input(conn) } // Accept accepts connections on the listener and serves requests // for each incoming connection. Accept blocks; the caller typically // invokes it in a go statement. -func Accept(lis net.Listener) { - server.accept(lis); -} +func Accept(lis net.Listener) { server.accept(lis) } // Can connect to RPC service using HTTP CONNECT to rpcPath. var rpcPath string = "/_goRPC_" diff --git a/src/pkg/sort/sort.go b/src/pkg/sort/sort.go index ce7408b90..34a2c4346 100644 --- a/src/pkg/sort/sort.go +++ b/src/pkg/sort/sort.go @@ -131,9 +131,7 @@ func quickSort(data Interface, a, b int) { } } -func Sort(data Interface) { - quickSort(data, 0, data.Len()); -} +func Sort(data Interface) { quickSort(data, 0, data.Len()) } func IsSorted(data Interface) bool { @@ -152,85 +150,49 @@ func IsSorted(data Interface) bool { // IntArray attaches the methods of Interface to []int, sorting in increasing order. type IntArray []int -func (p IntArray) Len() int { - return len(p); -} -func (p IntArray) Less(i, j int) bool { - return p[i] < p[j]; -} -func (p IntArray) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p IntArray) Len() int { return len(p) } +func (p IntArray) Less(i, j int) bool { return p[i] < p[j] } +func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Sort is a convenience method. -func (p IntArray) Sort() { - Sort(p); -} +func (p IntArray) Sort() { Sort(p) } // FloatArray attaches the methods of Interface to []float, sorting in increasing order. type FloatArray []float -func (p FloatArray) Len() int { - return len(p); -} -func (p FloatArray) Less(i, j int) bool { - return p[i] < p[j]; -} -func (p FloatArray) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p FloatArray) Len() int { return len(p) } +func (p FloatArray) Less(i, j int) bool { return p[i] < p[j] } +func (p FloatArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Sort is a convenience method. -func (p FloatArray) Sort() { - Sort(p); -} +func (p FloatArray) Sort() { Sort(p) } // StringArray attaches the methods of Interface to []string, sorting in increasing order. type StringArray []string -func (p StringArray) Len() int { - return len(p); -} -func (p StringArray) Less(i, j int) bool { - return p[i] < p[j]; -} -func (p StringArray) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p StringArray) Len() int { return len(p) } +func (p StringArray) Less(i, j int) bool { return p[i] < p[j] } +func (p StringArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Sort is a convenience method. -func (p StringArray) Sort() { - Sort(p); -} +func (p StringArray) Sort() { Sort(p) } // Convenience wrappers for common cases // SortInts sorts an array of ints in increasing order. -func SortInts(a []int) { - Sort(IntArray(a)); -} +func SortInts(a []int) { Sort(IntArray(a)) } // SortFloats sorts an array of floats in increasing order. -func SortFloats(a []float) { - Sort(FloatArray(a)); -} +func SortFloats(a []float) { Sort(FloatArray(a)) } // SortStrings sorts an array of strings in increasing order. -func SortStrings(a []string) { - Sort(StringArray(a)); -} +func SortStrings(a []string) { Sort(StringArray(a)) } // IntsAreSorted tests whether an array of ints is sorted in increasing order. -func IntsAreSorted(a []int) bool { - return IsSorted(IntArray(a)); -} +func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)) } // FloatsAreSorted tests whether an array of floats is sorted in increasing order. -func FloatsAreSorted(a []float) bool { - return IsSorted(FloatArray(a)); -} +func FloatsAreSorted(a []float) bool { return IsSorted(FloatArray(a)) } // StringsAreSorted tests whether an array of strings is sorted in increasing order. -func StringsAreSorted(a []string) bool { - return IsSorted(StringArray(a)); -} +func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)) } diff --git a/src/pkg/sort/sort_test.go b/src/pkg/sort/sort_test.go index 5c52c0f2b..623100006 100644 --- a/src/pkg/sort/sort_test.go +++ b/src/pkg/sort/sort_test.go @@ -113,12 +113,8 @@ type testingData struct { nswap int; } -func (d *testingData) Len() int { - return len(d.data); -} -func (d *testingData) Less(i, j int) bool { - return d.data[i] < d.data[j]; -} +func (d *testingData) Len() int { return len(d.data) } +func (d *testingData) Less(i, j int) bool { return d.data[i] < d.data[j] } func (d *testingData) Swap(i, j int) { if d.nswap >= d.maxswap { d.t.Errorf("%s: used %d swaps sorting array of %d", d.desc, d.nswap, len(d.data)); diff --git a/src/pkg/strconv/atof_test.go b/src/pkg/strconv/atof_test.go index f918650f3..a59fb78b4 100644 --- a/src/pkg/strconv/atof_test.go +++ b/src/pkg/strconv/atof_test.go @@ -135,10 +135,6 @@ func testAtof(t *testing.T, opt bool) { SetOptimize(oldopt); } -func TestAtof(t *testing.T) { - testAtof(t, true); -} +func TestAtof(t *testing.T) { testAtof(t, true) } -func TestAtofSlow(t *testing.T) { - testAtof(t, false); -} +func TestAtofSlow(t *testing.T) { testAtof(t, false) } diff --git a/src/pkg/strconv/atoi.go b/src/pkg/strconv/atoi.go index 2f1d5dec6..eddda20a5 100644 --- a/src/pkg/strconv/atoi.go +++ b/src/pkg/strconv/atoi.go @@ -11,9 +11,7 @@ type NumError struct { Error os.Error; } -func (e *NumError) String() string { - return "parsing " + e.Num + ": " + e.Error.String(); -} +func (e *NumError) String() string { return "parsing " + e.Num + ": " + e.Error.String() } func computeIntsize() uint { @@ -170,9 +168,7 @@ func Btoi64(s string, base int) (i int64, err os.Error) { // Atoi64 is like Atoui64 but allows signed numbers and // returns its result in an int64. -func Atoi64(s string) (i int64, err os.Error) { - return Btoi64(s, 10); -} +func Atoi64(s string) (i int64, err os.Error) { return Btoi64(s, 10) } // Atoui is like Atoui64 but returns its result as a uint. diff --git a/src/pkg/strconv/ftoa_test.go b/src/pkg/strconv/ftoa_test.go index 7262b25a6..7475ac6b3 100644 --- a/src/pkg/strconv/ftoa_test.go +++ b/src/pkg/strconv/ftoa_test.go @@ -17,9 +17,7 @@ type ftoaTest struct { s string; } -func fdiv(a, b float64) float64 { - return a/b; -} // keep compiler in the dark +func fdiv(a, b float64) float64 { return a/b } // keep compiler in the dark const ( below1e23 = 99999999999999974834176; diff --git a/src/pkg/strconv/internal_test.go b/src/pkg/strconv/internal_test.go index 428c94e00..1a3bab2a0 100644 --- a/src/pkg/strconv/internal_test.go +++ b/src/pkg/strconv/internal_test.go @@ -6,9 +6,7 @@ package strconv -func NewDecimal(i uint64) *decimal { - return newDecimal(i); -} +func NewDecimal(i uint64) *decimal { return newDecimal(i) } func SetOptimize(b bool) bool { old := optimize; diff --git a/src/pkg/strconv/itoa.go b/src/pkg/strconv/itoa.go index 15fa30627..b1025d4a2 100644 --- a/src/pkg/strconv/itoa.go +++ b/src/pkg/strconv/itoa.go @@ -36,31 +36,19 @@ func Itob64(i int64, base uint) string { } // Itoa64 returns the decimal string representation of i. -func Itoa64(i int64) string { - return Itob64(i, 10); -} +func Itoa64(i int64) string { return Itob64(i, 10) } // Uitoa64 returns the decimal string representation of i. -func Uitoa64(i uint64) string { - return Uitob64(i, 10); -} +func Uitoa64(i uint64) string { return Uitob64(i, 10) } // Uitob returns the string representation of i in the given base. -func Uitob(i uint, base uint) string { - return Uitob64(uint64(i), base); -} +func Uitob(i uint, base uint) string { return Uitob64(uint64(i), base) } // Itob returns the string representation of i in the given base. -func Itob(i int, base uint) string { - return Itob64(int64(i), base); -} +func Itob(i int, base uint) string { return Itob64(int64(i), base) } // Itoa returns the decimal string representation of i. -func Itoa(i int) string { - return Itob64(int64(i), 10); -} +func Itoa(i int) string { return Itob64(int64(i), 10) } // Uitoa returns the decimal string representation of i. -func Uitoa(i uint) string { - return Uitob64(uint64(i), 10); -} +func Uitoa(i uint) string { return Uitob64(uint64(i), 10) } diff --git a/src/pkg/strings/reader.go b/src/pkg/strings/reader.go index d742c4964..55e4d963f 100644 --- a/src/pkg/strings/reader.go +++ b/src/pkg/strings/reader.go @@ -35,6 +35,4 @@ func (r *Reader) ReadByte() (b byte, err os.Error) { // NewReader returns a new Reader reading from s. // It is similar to bytes.NewBufferString but more efficient and read-only. -func NewReader(s string) *Reader { - return (*Reader)(&s); -} +func NewReader(s string) *Reader { return (*Reader)(&s) } diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go index 5f3dcfcdc..4169f6211 100644 --- a/src/pkg/strings/strings.go +++ b/src/pkg/strings/strings.go @@ -107,9 +107,7 @@ func genSplit(s, sep string, sepSave, n int) []string { // Split splits the string s around each instance of sep, returning an array of substrings of s. // If sep is empty, Split splits s after each UTF-8 sequence. // If n > 0, split Splits s into at most n substrings; the last substring will be the unsplit remainder. -func Split(s, sep string, n int) []string { - return genSplit(s, sep, 0, n); -} +func Split(s, sep string, n int) []string { return genSplit(s, sep, 0, n) } // SplitAfter splits the string s after each instance of sep, returning an array of substrings of s. // If sep is empty, SplitAfter splits s after each UTF-8 sequence. @@ -191,19 +189,13 @@ func Map(mapping func(rune int) int, s string) string { } // ToUpper returns a copy of the string s with all Unicode letters mapped to their upper case. -func ToUpper(s string) string { - return Map(unicode.ToUpper, s); -} +func ToUpper(s string) string { return Map(unicode.ToUpper, s) } // ToUpper returns a copy of the string s with all Unicode letters mapped to their lower case. -func ToLower(s string) string { - return Map(unicode.ToLower, s); -} +func ToLower(s string) string { return Map(unicode.ToLower, s) } // ToTitle returns a copy of the string s with all Unicode letters mapped to their title case. -func ToTitle(s string) string { - return Map(unicode.ToTitle, s); -} +func ToTitle(s string) string { return Map(unicode.ToTitle, s) } // Trim returns a slice of the string s, with all leading and trailing white space // removed, as defined by Unicode. diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go index cdf3437c3..f7aa4dbae 100644 --- a/src/pkg/strings/strings_test.go +++ b/src/pkg/strings/strings_test.go @@ -74,13 +74,9 @@ func runIndexTests(t *testing.T, f func(s, sep string) int, funcName string, tes } } -func TestIndex(t *testing.T) { - runIndexTests(t, Index, "Index", indexTests); -} +func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) } -func TestLastIndex(t *testing.T) { - runIndexTests(t, LastIndex, "LastIndex", lastIndexTests); -} +func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", lastIndexTests) } type ExplodeTest struct { @@ -249,17 +245,11 @@ func TestMap(t *testing.T) { } } -func TestToUpper(t *testing.T) { - runStringTests(t, ToUpper, "ToUpper", upperTests); -} +func TestToUpper(t *testing.T) { runStringTests(t, ToUpper, "ToUpper", upperTests) } -func TestToLower(t *testing.T) { - runStringTests(t, ToLower, "ToLower", lowerTests); -} +func TestToLower(t *testing.T) { runStringTests(t, ToLower, "ToLower", lowerTests) } -func TestTrimSpace(t *testing.T) { - runStringTests(t, TrimSpace, "TrimSpace", trimSpaceTests); -} +func TestTrimSpace(t *testing.T) { runStringTests(t, TrimSpace, "TrimSpace", trimSpaceTests) } func equal(m string, s1, s2 string, t *testing.T) bool { if s1 == s2 { diff --git a/src/pkg/sync/mutex.go b/src/pkg/sync/mutex.go index 309970f1e..ac59db12d 100644 --- a/src/pkg/sync/mutex.go +++ b/src/pkg/sync/mutex.go @@ -79,17 +79,13 @@ type RWMutex struct { // RLock locks rw for reading. // If the lock is already locked for writing or there is a writer already waiting // to acquire the lock, RLock blocks until the writer has released the lock. -func (rw *RWMutex) RLock() { - rw.m.Lock(); -} +func (rw *RWMutex) RLock() { rw.m.Lock() } // RUnlock undoes a single RLock call; // it does not affect other simultaneous readers. // It is a run-time error if rw is not locked for reading // on entry to RUnlock. -func (rw *RWMutex) RUnlock() { - rw.m.Unlock(); -} +func (rw *RWMutex) RUnlock() { rw.m.Unlock() } // Lock locks rw for writing. // If the lock is already locked for reading or writing, @@ -97,9 +93,7 @@ func (rw *RWMutex) RUnlock() { // To ensure that the lock eventually becomes available, // a blocked Lock call excludes new readers from acquiring // the lock. -func (rw *RWMutex) Lock() { - rw.m.Lock(); -} +func (rw *RWMutex) Lock() { rw.m.Lock() } // Unlock unlocks rw for writing. // It is a run-time error if rw is not locked for writing @@ -109,6 +103,4 @@ func (rw *RWMutex) Lock() { // a locked RWMutex is not associated with a particular goroutine. // It is allowed for one goroutine to RLock (Lock) an RWMutex and then // arrange for another goroutine to RUnlock (Unlock) it. -func (rw *RWMutex) Unlock() { - rw.m.Unlock(); -} +func (rw *RWMutex) Unlock() { rw.m.Unlock() } diff --git a/src/pkg/syscall/exec.go b/src/pkg/syscall/exec.go index eb577f326..4310b9e1a 100644 --- a/src/pkg/syscall/exec.go +++ b/src/pkg/syscall/exec.go @@ -71,9 +71,7 @@ func StringArrayPtr(ss []string) []*byte { return bb; } -func CloseOnExec(fd int) { - fcntl(fd, F_SETFD, FD_CLOEXEC); -} +func CloseOnExec(fd int) { fcntl(fd, F_SETFD, FD_CLOEXEC) } func SetNonblock(fd int, nonblocking bool) (errno int) { flag, err := fcntl(fd, F_GETFL, 0); diff --git a/src/pkg/syscall/syscall.go b/src/pkg/syscall/syscall.go index c19135255..89252d1f8 100644 --- a/src/pkg/syscall/syscall.go +++ b/src/pkg/syscall/syscall.go @@ -27,6 +27,4 @@ func StringByteSlice(s string) []byte { // StringBytePtr returns a pointer to a NUL-terminated array of bytes // containing the text of s. -func StringBytePtr(s string) *byte { - return &StringByteSlice(s)[0]; -} +func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] } diff --git a/src/pkg/syscall/syscall_darwin.go b/src/pkg/syscall/syscall_darwin.go index 21900554b..792dc0bbc 100644 --- a/src/pkg/syscall/syscall_darwin.go +++ b/src/pkg/syscall/syscall_darwin.go @@ -23,9 +23,7 @@ const OS = "darwin" // even linking this function into the binary. See ../os/getwd.go. const ImplementsGetwd = false -func Getwd() (string, int) { - return "", ENOTSUP; -} +func Getwd() (string, int) { return "", ENOTSUP } /* @@ -90,9 +88,7 @@ const ( stopped = 0x7F; ) -func (w WaitStatus) Exited() bool { - return w&mask == exited; -} +func (w WaitStatus) Exited() bool { return w&mask == exited } func (w WaitStatus) ExitStatus() int { if w&mask != exited { @@ -101,9 +97,7 @@ func (w WaitStatus) ExitStatus() int { return int(w>>shift); } -func (w WaitStatus) Signaled() bool { - return w&mask != stopped && w&mask != 0; -} +func (w WaitStatus) Signaled() bool { return w&mask != stopped && w&mask != 0 } func (w WaitStatus) Signal() int { sig := int(w&mask); @@ -113,17 +107,11 @@ func (w WaitStatus) Signal() int { return sig; } -func (w WaitStatus) CoreDump() bool { - return w.Signaled() && w&core != 0; -} +func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 } -func (w WaitStatus) Stopped() bool { - return w&mask == stopped && w>>shift != SIGSTOP; -} +func (w WaitStatus) Stopped() bool { return w&mask == stopped && w>>shift != SIGSTOP } -func (w WaitStatus) Continued() bool { - return w&mask == stopped && w>>shift == SIGSTOP; -} +func (w WaitStatus) Continued() bool { return w&mask == stopped && w>>shift == SIGSTOP } func (w WaitStatus) StopSignal() int { if !w.Stopped() { diff --git a/src/pkg/syscall/syscall_darwin_386.go b/src/pkg/syscall/syscall_darwin_386.go index 5654e09da..41b7578e3 100644 --- a/src/pkg/syscall/syscall_darwin_386.go +++ b/src/pkg/syscall/syscall_darwin_386.go @@ -4,13 +4,9 @@ package syscall -func Getpagesize() int { - return 4096; -} +func Getpagesize() int { return 4096 } -func TimespecToNsec(ts Timespec) int64 { - return int64(ts.Sec)*1e9 + int64(ts.Nsec); -} +func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec/1e9); @@ -18,9 +14,7 @@ func NsecToTimespec(nsec int64) (ts Timespec) { return; } -func TimevalToNsec(tv Timeval) int64 { - return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3; -} +func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } func NsecToTimeval(nsec int64) (tv Timeval) { nsec += 999; // round up to microsecond diff --git a/src/pkg/syscall/syscall_darwin_amd64.go b/src/pkg/syscall/syscall_darwin_amd64.go index 7522069b1..7662b200d 100644 --- a/src/pkg/syscall/syscall_darwin_amd64.go +++ b/src/pkg/syscall/syscall_darwin_amd64.go @@ -4,13 +4,9 @@ package syscall -func Getpagesize() int { - return 4096; -} +func Getpagesize() int { return 4096 } -func TimespecToNsec(ts Timespec) int64 { - return int64(ts.Sec)*1e9 + int64(ts.Nsec); -} +func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec/1e9; @@ -18,9 +14,7 @@ func NsecToTimespec(nsec int64) (ts Timespec) { return; } -func TimevalToNsec(tv Timeval) int64 { - return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3; -} +func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } func NsecToTimeval(nsec int64) (tv Timeval) { nsec += 999; // round up to microsecond diff --git a/src/pkg/syscall/syscall_linux.go b/src/pkg/syscall/syscall_linux.go index 900889df6..e4b82569e 100644 --- a/src/pkg/syscall/syscall_linux.go +++ b/src/pkg/syscall/syscall_linux.go @@ -120,25 +120,15 @@ const ( shift = 8; ) -func (w WaitStatus) Exited() bool { - return w&mask == exited; -} +func (w WaitStatus) Exited() bool { return w&mask == exited } -func (w WaitStatus) Signaled() bool { - return w&mask != stopped && w&mask != exited; -} +func (w WaitStatus) Signaled() bool { return w&mask != stopped && w&mask != exited } -func (w WaitStatus) Stopped() bool { - return w&0xFF == stopped; -} +func (w WaitStatus) Stopped() bool { return w&0xFF == stopped } -func (w WaitStatus) Continued() bool { - return w == 0xFFFF; -} +func (w WaitStatus) Continued() bool { return w == 0xFFFF } -func (w WaitStatus) CoreDump() bool { - return w.Signaled() && w&core != 0; -} +func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 } func (w WaitStatus) ExitStatus() int { if !w.Exited() { @@ -536,17 +526,11 @@ func PtraceCont(pid int, signal int) (errno int) { return ptrace(PTRACE_CONT, pid, 0, uintptr(signal)); } -func PtraceSingleStep(pid int) (errno int) { - return ptrace(PTRACE_SINGLESTEP, pid, 0, 0); -} +func PtraceSingleStep(pid int) (errno int) { return ptrace(PTRACE_SINGLESTEP, pid, 0, 0) } -func PtraceAttach(pid int) (errno int) { - return ptrace(PTRACE_ATTACH, pid, 0, 0); -} +func PtraceAttach(pid int) (errno int) { return ptrace(PTRACE_ATTACH, pid, 0, 0) } -func PtraceDetach(pid int) (errno int) { - return ptrace(PTRACE_DETACH, pid, 0, 0); -} +func PtraceDetach(pid int) (errno int) { return ptrace(PTRACE_DETACH, pid, 0, 0) } // Sendto // Recvfrom diff --git a/src/pkg/syscall/syscall_linux_386.go b/src/pkg/syscall/syscall_linux_386.go index 796859c0a..9632a889e 100644 --- a/src/pkg/syscall/syscall_linux_386.go +++ b/src/pkg/syscall/syscall_linux_386.go @@ -6,13 +6,9 @@ package syscall import "unsafe" -func Getpagesize() int { - return 4096; -} +func Getpagesize() int { return 4096 } -func TimespecToNsec(ts Timespec) int64 { - return int64(ts.Sec)*1e9 + int64(ts.Nsec); -} +func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec/1e9); @@ -20,9 +16,7 @@ func NsecToTimespec(nsec int64) (ts Timespec) { return; } -func TimevalToNsec(tv Timeval) int64 { - return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3; -} +func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } func NsecToTimeval(nsec int64) (tv Timeval) { nsec += 999; // round up to microsecond @@ -151,10 +145,6 @@ func Listen(s int, n int) (errno int) { return; } -func (r *PtraceRegs) PC() uint64 { - return uint64(uint32(r.Eip)); -} +func (r *PtraceRegs) PC() uint64 { return uint64(uint32(r.Eip)) } -func (r *PtraceRegs) SetPC(pc uint64) { - r.Eip = int32(pc); -} +func (r *PtraceRegs) SetPC(pc uint64) { r.Eip = int32(pc) } diff --git a/src/pkg/syscall/syscall_linux_amd64.go b/src/pkg/syscall/syscall_linux_amd64.go index 685fc1b48..3ad3f3a2b 100644 --- a/src/pkg/syscall/syscall_linux_amd64.go +++ b/src/pkg/syscall/syscall_linux_amd64.go @@ -42,13 +42,9 @@ package syscall //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, errno int) //sys sendto(s int, buf []byte, flags int, to uintptr, addrlen _Socklen) (errno int) -func Getpagesize() int { - return 4096; -} +func Getpagesize() int { return 4096 } -func TimespecToNsec(ts Timespec) int64 { - return int64(ts.Sec)*1e9 + int64(ts.Nsec); -} +func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec/1e9; @@ -56,9 +52,7 @@ func NsecToTimespec(nsec int64) (ts Timespec) { return; } -func TimevalToNsec(tv Timeval) int64 { - return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3; -} +func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } func NsecToTimeval(nsec int64) (tv Timeval) { nsec += 999; // round up to microsecond @@ -67,10 +61,6 @@ func NsecToTimeval(nsec int64) (tv Timeval) { return; } -func (r *PtraceRegs) PC() uint64 { - return r.Rip; -} +func (r *PtraceRegs) PC() uint64 { return r.Rip } -func (r *PtraceRegs) SetPC(pc uint64) { - r.Rip = pc; -} +func (r *PtraceRegs) SetPC(pc uint64) { r.Rip = pc } diff --git a/src/pkg/syscall/syscall_linux_arm.go b/src/pkg/syscall/syscall_linux_arm.go index d71b2e154..36f19906a 100644 --- a/src/pkg/syscall/syscall_linux_arm.go +++ b/src/pkg/syscall/syscall_linux_arm.go @@ -4,13 +4,9 @@ package syscall -func Getpagesize() int { - return 4096; -} +func Getpagesize() int { return 4096 } -func TimespecToNsec(ts Timespec) int64 { - return int64(ts.Sec)*1e9 + int64(ts.Nsec); -} +func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec/1e9); @@ -62,9 +58,6 @@ func NsecToTimeval(nsec int64) (tv Timeval) { //sys Statfs(path string, buf *Statfs_t) (errno int) // TODO(kaib): add support for tracing -func (r *PtraceRegs) PC() uint64 { - return 0; -} +func (r *PtraceRegs) PC() uint64 { return 0 } -func (r *PtraceRegs) SetPC(pc uint64) { -} +func (r *PtraceRegs) SetPC(pc uint64) {} diff --git a/src/pkg/syscall/syscall_nacl.go b/src/pkg/syscall/syscall_nacl.go index 3efea2e96..9b3266809 100644 --- a/src/pkg/syscall/syscall_nacl.go +++ b/src/pkg/syscall/syscall_nacl.go @@ -114,9 +114,7 @@ const ( SIGTRAP = 5; ) -func Pipe(p []int) (errno int) { - return ENACL; -} +func Pipe(p []int) (errno int) { return ENACL } func fcntl(fd, cmd, arg int) (val int, errno int) { return 0, ENACL; @@ -130,45 +128,31 @@ func Pwrite(fd int, p []byte, offset int64) (n int, errno int) { return 0, ENACL; } -func Mkdir(path string, mode int) (errno int) { - return ENACL; -} +func Mkdir(path string, mode int) (errno int) { return ENACL } func Lstat(path string, stat *Stat_t) (errno int) { return ENACL; } -func Chdir(path string) (errno int) { - return ENACL; -} +func Chdir(path string) (errno int) { return ENACL } -func Fchdir(fd int) (errno int) { - return ENACL; -} +func Fchdir(fd int) (errno int) { return ENACL } -func Unlink(path string) (errno int) { - return ENACL; -} +func Unlink(path string) (errno int) { return ENACL } -func Rmdir(path string) (errno int) { - return ENACL; -} +func Rmdir(path string) (errno int) { return ENACL } func Link(oldpath, newpath string) (errno int) { return ENACL; } -func Symlink(path, link string) (errno int) { - return ENACL; -} +func Symlink(path, link string) (errno int) { return ENACL } func Readlink(path string, buf []byte) (n int, errno int) { return 0, ENACL; } -func Fchmod(fd int, mode int) (errno int) { - return ENACL; -} +func Fchmod(fd int, mode int) (errno int) { return ENACL } func Chown(path string, uid int, gid int) (errno int) { return ENACL; @@ -196,33 +180,19 @@ func Ftruncate(fd int, length int64) (errno int) { const ImplementsGetwd = true -func Getwd() (wd string, errno int) { - return "", ENACL; -} +func Getwd() (wd string, errno int) { return "", ENACL } -func Getuid() (uid int) { - return -1; -} +func Getuid() (uid int) { return -1 } -func Geteuid() (euid int) { - return -1; -} +func Geteuid() (euid int) { return -1 } -func Getgid() (gid int) { - return -1; -} +func Getgid() (gid int) { return -1 } -func Getegid() (egid int) { - return -1; -} +func Getegid() (egid int) { return -1 } -func Getppid() (ppid int) { - return -1; -} +func Getppid() (ppid int) { return -1 } -func Getgroups() (gids []int, errno int) { - return nil, ENACL; -} +func Getgroups() (gids []int, errno int) { return nil, ENACL } type Sockaddr interface { sockaddr(); @@ -233,23 +203,20 @@ type SockaddrInet4 struct { Addr [4]byte; } -func (*SockaddrInet4) sockaddr() { -} +func (*SockaddrInet4) sockaddr() {} type SockaddrInet6 struct { Port int; Addr [16]byte; } -func (*SockaddrInet6) sockaddr() { -} +func (*SockaddrInet6) sockaddr() {} type SockaddrUnix struct { Name string; } -func (*SockaddrUnix) sockaddr() { -} +func (*SockaddrUnix) sockaddr() {} const ( AF_INET = 1+iota; @@ -284,13 +251,9 @@ func Getpeername(fd int) (sa Sockaddr, errno int) { return nil, ENACL; } -func Bind(fd int, sa Sockaddr) (errno int) { - return ENACL; -} +func Bind(fd int, sa Sockaddr) (errno int) { return ENACL } -func Connect(fd int, sa Sockaddr) (errno int) { - return ENACL; -} +func Connect(fd int, sa Sockaddr) (errno int) { return ENACL } func Socket(domain, typ, proto int) (fd, errno int) { return 0, ENACL; @@ -313,9 +276,7 @@ func SetsockoptLinger(fd, level, opt int, l *Linger) (errno int) { return ENACL; } -func Listen(s int, n int) (errno int) { - return ENACL; -} +func Listen(s int, n int) (errno int) { return ENACL } type Rusage struct { Utime Timeval; @@ -342,38 +303,20 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, type WaitStatus uint32 -func (WaitStatus) Exited() bool { - return false; -} +func (WaitStatus) Exited() bool { return false } -func (WaitStatus) ExitStatus() int { - return -1; -} +func (WaitStatus) ExitStatus() int { return -1 } -func (WaitStatus) Signal() int { - return -1; -} +func (WaitStatus) Signal() int { return -1 } -func (WaitStatus) CoreDump() bool { - return false; -} +func (WaitStatus) CoreDump() bool { return false } -func (WaitStatus) Stopped() bool { - return false; -} +func (WaitStatus) Stopped() bool { return false } -func (WaitStatus) Continued() bool { - return false; -} +func (WaitStatus) Continued() bool { return false } -func (WaitStatus) StopSignal() int { - return -1; -} +func (WaitStatus) StopSignal() int { return -1 } -func (WaitStatus) Signaled() bool { - return false; -} +func (WaitStatus) Signaled() bool { return false } -func (WaitStatus) TrapCause() int { - return -1; -} +func (WaitStatus) TrapCause() int { return -1 } diff --git a/src/pkg/syscall/syscall_nacl_386.go b/src/pkg/syscall/syscall_nacl_386.go index e87c1ffbf..badc4b25b 100644 --- a/src/pkg/syscall/syscall_nacl_386.go +++ b/src/pkg/syscall/syscall_nacl_386.go @@ -4,9 +4,7 @@ package syscall -func Getpagesize() int { - return 4096; -} +func Getpagesize() int { return 4096 } func NsecToTimeval(nsec int64) (tv Timeval) { tv.Sec = int32(nsec/1e9); diff --git a/src/pkg/syscall/zsysnum_linux_386.go b/src/pkg/syscall/zsysnum_linux_386.go index 02691b856..d0d743f3e 100644 --- a/src/pkg/syscall/zsysnum_linux_386.go +++ b/src/pkg/syscall/zsysnum_linux_386.go @@ -315,5 +315,4 @@ const ( SYS_FALLOCATE = 324; ) -func _darwin_system_call_conflict() { -} +func _darwin_system_call_conflict() {} diff --git a/src/pkg/syscall/zsysnum_linux_amd64.go b/src/pkg/syscall/zsysnum_linux_amd64.go index 74faa9578..055e65b5d 100644 --- a/src/pkg/syscall/zsysnum_linux_amd64.go +++ b/src/pkg/syscall/zsysnum_linux_amd64.go @@ -292,5 +292,4 @@ const ( SYS_FALLOCATE = 285; ) -func _darwin_system_call_conflict() { -} +func _darwin_system_call_conflict() {} diff --git a/src/pkg/syscall/zsysnum_linux_arm.go b/src/pkg/syscall/zsysnum_linux_arm.go index a493bfe9c..d1936c049 100644 --- a/src/pkg/syscall/zsysnum_linux_arm.go +++ b/src/pkg/syscall/zsysnum_linux_arm.go @@ -333,5 +333,4 @@ const ( SYS_INOTIFY_INIT1 = (SYS_SYSCALL_BASE + 360); ) -func _darwin_system_call_conflict() { -} +func _darwin_system_call_conflict() {} diff --git a/src/pkg/tabwriter/tabwriter.go b/src/pkg/tabwriter/tabwriter.go index d7d030893..9370bb4a0 100644 --- a/src/pkg/tabwriter/tabwriter.go +++ b/src/pkg/tabwriter/tabwriter.go @@ -92,14 +92,10 @@ type Writer struct { } -func (b *Writer) addLine() { - b.lines.Push(vector.New(0)); -} +func (b *Writer) addLine() { b.lines.Push(vector.New(0)) } -func (b *Writer) line(i int) *vector.Vector { - return b.lines.At(i).(*vector.Vector); -} +func (b *Writer) line(i int) *vector.Vector { return b.lines.At(i).(*vector.Vector) } // Reset the current state. diff --git a/src/pkg/tabwriter/tabwriter_test.go b/src/pkg/tabwriter/tabwriter_test.go index 0a290601f..6016e36cf 100644 --- a/src/pkg/tabwriter/tabwriter_test.go +++ b/src/pkg/tabwriter/tabwriter_test.go @@ -16,14 +16,10 @@ type buffer struct { } -func (b *buffer) init(n int) { - b.a = make([]byte, n)[0:0]; -} +func (b *buffer) init(n int) { b.a = make([]byte, n)[0:0] } -func (b *buffer) clear() { - b.a = b.a[0:0]; -} +func (b *buffer) clear() { b.a = b.a[0:0] } func (b *buffer) Write(buf []byte) (written int, err os.Error) { @@ -41,9 +37,7 @@ func (b *buffer) Write(buf []byte) (written int, err os.Error) { } -func (b *buffer) String() string { - return string(b.a); -} +func (b *buffer) String() string { return string(b.a) } func write(t *testing.T, testname string, w *Writer, src string) { diff --git a/src/pkg/template/template.go b/src/pkg/template/template.go index c647a2d37..728b7a529 100644 --- a/src/pkg/template/template.go +++ b/src/pkg/template/template.go @@ -72,9 +72,7 @@ type Error struct { Msg string; } -func (e *Error) String() string { - return fmt.Sprintf("line %d: %s", e.Line, e.Msg); -} +func (e *Error) String() string { return fmt.Sprintf("line %d: %s", e.Line, e.Msg) } // Most of the literals are aces. var lbrace = []byte{'{'} @@ -196,9 +194,7 @@ func (t *Template) parseError(err string, args ...) { // -- Lexical analysis // Is c a white space character? -func white(c uint8) bool { - return c == ' ' || c == '\t' || c == '\r' || c == '\n'; -} +func white(c uint8) bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n' } // Safely, does s[n:n+len(t)] == t? func equal(s []byte, n int, t []byte) bool { diff --git a/src/pkg/template/template_test.go b/src/pkg/template/template_test.go index becfa0f0b..6fbc14726 100644 --- a/src/pkg/template/template_test.go +++ b/src/pkg/template/template_test.go @@ -59,7 +59,9 @@ func plus1(v interface{}) string { } func writer(f func(interface{}) string) (func(io.Writer, interface{}, string)) { - return func(w io.Writer, v interface{}, format string) { io.WriteString(w, f(v)) }; + return func(w io.Writer, v interface{}, format string) { + io.WriteString(w, f(v)); + }; } diff --git a/src/pkg/testing/iotest/reader.go b/src/pkg/testing/iotest/reader.go index 823124aa3..ae427e6fa 100644 --- a/src/pkg/testing/iotest/reader.go +++ b/src/pkg/testing/iotest/reader.go @@ -14,9 +14,7 @@ import ( // OneByteReader returns a Reader that implements // each non-empty Read by reading one byte from r. -func OneByteReader(r io.Reader) io.Reader { - return &oneByteReader{r}; -} +func OneByteReader(r io.Reader) io.Reader { return &oneByteReader{r} } type oneByteReader struct { r io.Reader; @@ -31,9 +29,7 @@ func (r *oneByteReader) Read(p []byte) (int, os.Error) { // HalfReader returns a Reader that implements Read // by reading half as many requested bytes from r. -func HalfReader(r io.Reader) io.Reader { - return &halfReader{r}; -} +func HalfReader(r io.Reader) io.Reader { return &halfReader{r} } type halfReader struct { r io.Reader; @@ -47,9 +43,7 @@ func (r *halfReader) Read(p []byte) (int, os.Error) { // DataErrReader returns a Reader that returns the final // error with the last data read, instead of by itself with // zero bytes of data. -func DataErrReader(r io.Reader) io.Reader { - return &dataErrReader{r, nil, make([]byte, 1024)}; -} +func DataErrReader(r io.Reader) io.Reader { return &dataErrReader{r, nil, make([]byte, 1024)} } type dataErrReader struct { r io.Reader; diff --git a/src/pkg/testing/quick/quick.go b/src/pkg/testing/quick/quick.go index 5a7e8d37a..3d47240bd 100644 --- a/src/pkg/testing/quick/quick.go +++ b/src/pkg/testing/quick/quick.go @@ -43,9 +43,7 @@ func randFloat64(rand *rand.Rand) float64 { } // randInt64 returns a random integer taking half the range of an int64. -func randInt64(rand *rand.Rand) int64 { - return rand.Int63() - 1<<62; -} +func randInt64(rand *rand.Rand) int64 { return rand.Int63() - 1<<62 } // complexSize is the maximum length of arbitrary values that contain other // values. @@ -195,9 +193,7 @@ func (c *Config) getMaxCount() (maxCount int) { // used, independent of the functions being tested. type SetupError string -func (s SetupError) String() string { - return string(s); -} +func (s SetupError) String() string { return string(s) } // A CheckError is the result of Check finding an error. type CheckError struct { diff --git a/src/pkg/testing/quick/quick_test.go b/src/pkg/testing/quick/quick_test.go index 290f171ea..951582e35 100644 --- a/src/pkg/testing/quick/quick_test.go +++ b/src/pkg/testing/quick/quick_test.go @@ -11,90 +11,50 @@ import ( "os"; ) -func fBool(a bool) bool { - return a; -} +func fBool(a bool) bool { return a } -func fFloat32(a float32) float32 { - return a; -} +func fFloat32(a float32) float32 { return a } -func fFloat64(a float64) float64 { - return a; -} +func fFloat64(a float64) float64 { return a } -func fFloat(a float) float { - return a; -} +func fFloat(a float) float { return a } -func fInt16(a int16) int16 { - return a; -} +func fInt16(a int16) int16 { return a } -func fInt32(a int32) int32 { - return a; -} +func fInt32(a int32) int32 { return a } -func fInt64(a int64) int64 { - return a; -} +func fInt64(a int64) int64 { return a } -func fInt8(a int8) int8 { - return a; -} +func fInt8(a int8) int8 { return a } -func fInt(a int) int { - return a; -} +func fInt(a int) int { return a } -func fUInt8(a uint8) uint8 { - return a; -} +func fUInt8(a uint8) uint8 { return a } -func fMap(a map[int]int) map[int]int { - return a; -} +func fMap(a map[int]int) map[int]int { return a } -func fSlice(a []byte) []byte { - return a; -} +func fSlice(a []byte) []byte { return a } -func fString(a string) string { - return a; -} +func fString(a string) string { return a } type TestStruct struct { A int; B string; } -func fStruct(a TestStruct) TestStruct { - return a; -} +func fStruct(a TestStruct) TestStruct { return a } -func fUint16(a uint16) uint16 { - return a; -} +func fUint16(a uint16) uint16 { return a } -func fUint32(a uint32) uint32 { - return a; -} +func fUint32(a uint32) uint32 { return a } -func fUint64(a uint64) uint64 { - return a; -} +func fUint64(a uint64) uint64 { return a } -func fUint8(a uint8) uint8 { - return a; -} +func fUint8(a uint8) uint8 { return a } -func fUint(a uint) uint { - return a; -} +func fUint(a uint) uint { return a } -func fUintptr(a uintptr) uintptr { - return a; -} +func fUintptr(a uintptr) uintptr { return a } func fIntptr(a *int) *int { b := *a; @@ -142,9 +102,7 @@ func (m myStruct) Generate(r *rand.Rand, _ int) reflect.Value { return reflect.NewValue(myStruct{x: 42}); } -func myStructProperty(in myStruct) bool { - return in.x == 42; -} +func myStructProperty(in myStruct) bool { return in.x == 42 } func TestCheckProperty(t *testing.T) { reportError("myStructProperty", Check(myStructProperty, nil), t); diff --git a/src/pkg/testing/regexp.go b/src/pkg/testing/regexp.go index a91ae4dbb..f4cfe5e6e 100644 --- a/src/pkg/testing/regexp.go +++ b/src/pkg/testing/regexp.go @@ -60,18 +60,10 @@ type common struct { _index int; } -func (c *common) next() instr { - return c._next; -} -func (c *common) setNext(i instr) { - c._next = i; -} -func (c *common) index() int { - return c._index; -} -func (c *common) setIndex(i int) { - c._index = i; -} +func (c *common) next() instr { return c._next } +func (c *common) setNext(i instr) { c._next = i } +func (c *common) index() int { return c._index } +func (c *common) setIndex(i int) { c._index = i } // The representation of a compiled regular expression. // The public interface is entirely through methods. @@ -103,48 +95,32 @@ type _Start struct { common; } -func (start *_Start) kind() int { - return _START; -} -func (start *_Start) print() { - print("start"); -} +func (start *_Start) kind() int { return _START } +func (start *_Start) print() { print("start") } // --- END end of program type _End struct { common; } -func (end *_End) kind() int { - return _END; -} -func (end *_End) print() { - print("end"); -} +func (end *_End) kind() int { return _END } +func (end *_End) print() { print("end") } // --- BOT beginning of text type _Bot struct { common; } -func (bot *_Bot) kind() int { - return _BOT; -} -func (bot *_Bot) print() { - print("bot"); -} +func (bot *_Bot) kind() int { return _BOT } +func (bot *_Bot) print() { print("bot") } // --- EOT end of text type _Eot struct { common; } -func (eot *_Eot) kind() int { - return _EOT; -} -func (eot *_Eot) print() { - print("eot"); -} +func (eot *_Eot) kind() int { return _EOT } +func (eot *_Eot) print() { print("eot") } // --- CHAR a regular character type _Char struct { @@ -152,12 +128,8 @@ type _Char struct { char int; } -func (char *_Char) kind() int { - return _CHAR; -} -func (char *_Char) print() { - print("char ", string(char.char)); -} +func (char *_Char) kind() int { return _CHAR } +func (char *_Char) print() { print("char ", string(char.char)) } func newChar(char int) *_Char { c := new(_Char); @@ -175,9 +147,7 @@ type _CharClass struct { ranges []int; } -func (cclass *_CharClass) kind() int { - return _CHARCLASS; -} +func (cclass *_CharClass) kind() int { return _CHARCLASS } func (cclass *_CharClass) print() { print("charclass"); @@ -234,24 +204,16 @@ type _Any struct { common; } -func (any *_Any) kind() int { - return _ANY; -} -func (any *_Any) print() { - print("any"); -} +func (any *_Any) kind() int { return _ANY } +func (any *_Any) print() { print("any") } // --- NOTNL any character but newline type _NotNl struct { common; } -func (notnl *_NotNl) kind() int { - return _NOTNL; -} -func (notnl *_NotNl) print() { - print("notnl"); -} +func (notnl *_NotNl) kind() int { return _NOTNL } +func (notnl *_NotNl) print() { print("notnl") } // --- BRA parenthesized expression type _Bra struct { @@ -259,12 +221,8 @@ type _Bra struct { n int; // subexpression number } -func (bra *_Bra) kind() int { - return _BRA; -} -func (bra *_Bra) print() { - print("bra", bra.n); -} +func (bra *_Bra) kind() int { return _BRA } +func (bra *_Bra) print() { print("bra", bra.n) } // --- EBRA end of parenthesized expression type _Ebra struct { @@ -272,12 +230,8 @@ type _Ebra struct { n int; // subexpression number } -func (ebra *_Ebra) kind() int { - return _EBRA; -} -func (ebra *_Ebra) print() { - print("ebra ", ebra.n); -} +func (ebra *_Ebra) kind() int { return _EBRA } +func (ebra *_Ebra) print() { print("ebra ", ebra.n) } // --- ALT alternation type _Alt struct { @@ -285,24 +239,16 @@ type _Alt struct { left instr; // other branch } -func (alt *_Alt) kind() int { - return _ALT; -} -func (alt *_Alt) print() { - print("alt(", alt.left.index(), ")"); -} +func (alt *_Alt) kind() int { return _ALT } +func (alt *_Alt) print() { print("alt(", alt.left.index(), ")") } // --- NOP no operation type _Nop struct { common; } -func (nop *_Nop) kind() int { - return _NOP; -} -func (nop *_Nop) print() { - print("nop"); -} +func (nop *_Nop) kind() int { return _NOP } +func (nop *_Nop) print() { print("nop") } func (re *Regexp) add(i instr) instr { n := len(re.inst); @@ -329,9 +275,7 @@ type parser struct { const endOfFile = -1 -func (p *parser) c() int { - return p.ch; -} +func (p *parser) c() int { return p.ch } func (p *parser) nextc() int { if p.pos >= len(p.re.expr) { @@ -837,23 +781,17 @@ func (re *Regexp) ExecuteString(s string) (a []int) { // b[a[2*i]:a[2*i+1]] for i > 0 is the subslice matched by the ith parenthesized subexpression. // A negative value means the subexpression did not match any element of the slice. // An empty array means "no match". -func (re *Regexp) Execute(b []byte) (a []int) { - return re.doExecute("", b, 0); -} +func (re *Regexp) Execute(b []byte) (a []int) { return re.doExecute("", b, 0) } // MatchString returns whether the Regexp matches the string s. // The return value is a boolean: true for match, false for no match. -func (re *Regexp) MatchString(s string) bool { - return len(re.doExecute(s, nil, 0)) > 0; -} +func (re *Regexp) MatchString(s string) bool { return len(re.doExecute(s, nil, 0)) > 0 } // Match returns whether the Regexp matches the byte slice b. // The return value is a boolean: true for match, false for no match. -func (re *Regexp) Match(b []byte) bool { - return len(re.doExecute("", b, 0)) > 0; -} +func (re *Regexp) Match(b []byte) bool { return len(re.doExecute("", b, 0)) > 0 } // MatchStrings matches the Regexp against the string s. diff --git a/src/pkg/testing/script/script.go b/src/pkg/testing/script/script.go index 65ccb09dd..6bf6ca26f 100644 --- a/src/pkg/testing/script/script.go +++ b/src/pkg/testing/script/script.go @@ -57,17 +57,11 @@ type Recv struct { Expected interface{}; } -func (r Recv) getRecv() recvAction { - return r; -} +func (r Recv) getRecv() recvAction { return r } -func (Recv) getSend() sendAction { - return nil; -} +func (Recv) getSend() sendAction { return nil } -func (r Recv) getChannel() interface{} { - return r.Channel; -} +func (r Recv) getChannel() interface{} { return r.Channel } func (r Recv) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelRecv); @@ -85,17 +79,11 @@ type RecvMatch struct { Match func(interface{}) bool; } -func (r RecvMatch) getRecv() recvAction { - return r; -} +func (r RecvMatch) getRecv() recvAction { return r } -func (RecvMatch) getSend() sendAction { - return nil; -} +func (RecvMatch) getSend() sendAction { return nil } -func (r RecvMatch) getChannel() interface{} { - return r.Channel; -} +func (r RecvMatch) getChannel() interface{} { return r.Channel } func (r RecvMatch) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelRecv); @@ -113,17 +101,11 @@ type Closed struct { Channel interface{}; } -func (r Closed) getRecv() recvAction { - return r; -} +func (r Closed) getRecv() recvAction { return r } -func (Closed) getSend() sendAction { - return nil; -} +func (Closed) getSend() sendAction { return nil } -func (r Closed) getChannel() interface{} { - return r.Channel; -} +func (r Closed) getChannel() interface{} { return r.Channel } func (r Closed) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelClosed); @@ -141,17 +123,11 @@ type Send struct { Value interface{}; } -func (Send) getRecv() recvAction { - return nil; -} +func (Send) getRecv() recvAction { return nil } -func (s Send) getSend() sendAction { - return s; -} +func (s Send) getSend() sendAction { return s } -func (s Send) getChannel() interface{} { - return s.Channel; -} +func (s Send) getChannel() interface{} { return s.Channel } func newEmptyInterface(args ...) reflect.Value { return reflect.NewValue(args).(*reflect.StructValue).Field(0); @@ -176,21 +152,13 @@ type Close struct { Channel interface{}; } -func (Close) getRecv() recvAction { - return nil; -} +func (Close) getRecv() recvAction { return nil } -func (s Close) getSend() sendAction { - return s; -} +func (s Close) getSend() sendAction { return s } -func (s Close) getChannel() interface{} { - return s.Channel; -} +func (s Close) getChannel() interface{} { return s.Channel } -func (s Close) send() { - reflect.NewValue(s.Channel).(*reflect.ChanValue).Close(); -} +func (s Close) send() { reflect.NewValue(s.Channel).(*reflect.ChanValue).Close() } // A ReceivedUnexpected error results if no active Events match a value // received from a channel. @@ -211,9 +179,7 @@ func (r ReceivedUnexpected) String() string { // Events. type SetupError string -func (s SetupError) String() string { - return string(s); -} +func (s SetupError) String() string { return string(s) } func NewEvent(name string, predecessors []*Event, action action) *Event { e := &Event{name, false, predecessors, action}; diff --git a/src/pkg/testing/testing.go b/src/pkg/testing/testing.go index e8dfee2bd..b04e8d40c 100644 --- a/src/pkg/testing/testing.go +++ b/src/pkg/testing/testing.go @@ -47,14 +47,10 @@ type T struct { } // Fail marks the Test function as having failed but continues execution. -func (t *T) Fail() { - t.failed = true; -} +func (t *T) Fail() { t.failed = true } // Failed returns whether the Test function has failed. -func (t *T) Failed() bool { - return t.failed; -} +func (t *T) Failed() bool { return t.failed } // FailNow marks the Test function as having failed and stops its execution. // Execution will continue at the next Test. @@ -66,9 +62,7 @@ func (t *T) FailNow() { // Log formats its arguments using default formatting, analogous to Print(), // and records the text in the error log. -func (t *T) Log(args ...) { - t.errors += "\t"+tabify(fmt.Sprintln(args)); -} +func (t *T) Log(args ...) { t.errors += "\t"+tabify(fmt.Sprintln(args)) } // Log formats its arguments according to the format, analogous to Printf(), // and records the text in the error log. diff --git a/src/pkg/time/sleep.go b/src/pkg/time/sleep.go index ee57edd45..e94057a16 100644 --- a/src/pkg/time/sleep.go +++ b/src/pkg/time/sleep.go @@ -11,6 +11,4 @@ import ( // Sleep pauses the current goroutine for ns nanoseconds. // It returns os.EINTR if interrupted. -func Sleep(ns int64) os.Error { - return os.NewSyscallError("sleep", syscall.Sleep(ns)); -} +func Sleep(ns int64) os.Error { return os.NewSyscallError("sleep", syscall.Sleep(ns)) } diff --git a/src/pkg/time/tick.go b/src/pkg/time/tick.go index 01ffef4a1..771fc9f7e 100644 --- a/src/pkg/time/tick.go +++ b/src/pkg/time/tick.go @@ -29,9 +29,7 @@ type Ticker struct { } // Stop turns off a ticker. After Stop, no more ticks will be delivered. -func (t *Ticker) Stop() { - t.shutdown = true; -} +func (t *Ticker) Stop() { t.shutdown = true } func (t *Ticker) ticker(c chan<- int64) { now := Nanoseconds(); diff --git a/src/pkg/time/time.go b/src/pkg/time/time.go index 3b626bbab..72cd34822 100644 --- a/src/pkg/time/time.go +++ b/src/pkg/time/time.go @@ -145,9 +145,7 @@ func SecondsToUTC(sec int64) *Time { } // UTC returns the current time as a parsed Time value in the UTC time zone. -func UTC() *Time { - return SecondsToUTC(Seconds()); -} +func UTC() *Time { return SecondsToUTC(Seconds()) } // SecondsToLocalTime converts sec, in number of seconds since the Unix epoch, // into a parsed Time value in the local time zone. @@ -160,9 +158,7 @@ func SecondsToLocalTime(sec int64) *Time { } // LocalTime returns the current time as a parsed Time value in the local time zone. -func LocalTime() *Time { - return SecondsToLocalTime(Seconds()); -} +func LocalTime() *Time { return SecondsToLocalTime(Seconds()) } // Seconds returns the number of seconds since January 1, 1970 represented by the // parsed Time value. @@ -340,24 +336,16 @@ func format(t *Time, fmt string) string { // Asctime formats the parsed time value in the style of // ANSI C asctime: Sun Nov 6 08:49:37 1994 -func (t *Time) Asctime() string { - return format(t, "%a %b %e %H:%M:%S %Y"); -} +func (t *Time) Asctime() string { return format(t, "%a %b %e %H:%M:%S %Y") } // RFC850 formats the parsed time value in the style of // RFC 850: Sunday, 06-Nov-94 08:49:37 UTC -func (t *Time) RFC850() string { - return format(t, "%A, %d-%b-%y %H:%M:%S %Z"); -} +func (t *Time) RFC850() string { return format(t, "%A, %d-%b-%y %H:%M:%S %Z") } // RFC1123 formats the parsed time value in the style of // RFC 1123: Sun, 06 Nov 1994 08:49:37 UTC -func (t *Time) RFC1123() string { - return format(t, "%a, %d %b %Y %H:%M:%S %Z"); -} +func (t *Time) RFC1123() string { return format(t, "%a, %d %b %Y %H:%M:%S %Z") } // String formats the parsed time value in the style of // date(1) - Sun Nov 6 08:49:37 UTC 1994 -func (t *Time) String() string { - return format(t, "%a %b %e %H:%M:%S %Z %Y"); -} +func (t *Time) String() string { return format(t, "%a %b %e %H:%M:%S %Z %Y") } diff --git a/src/pkg/utf8/utf8.go b/src/pkg/utf8/utf8.go index 18ae7cf58..89cdc9956 100644 --- a/src/pkg/utf8/utf8.go +++ b/src/pkg/utf8/utf8.go @@ -291,6 +291,4 @@ func RuneCountInString(s string) int { // RuneStart reports whether the byte could be the first byte of // an encoded rune. Second and subsequent bytes always have the top // two bits set to 10. -func RuneStart(b byte) bool { - return b&0xC0 != 0x80; -} +func RuneStart(b byte) bool { return b&0xC0 != 0x80 } diff --git a/src/pkg/xml/read.go b/src/pkg/xml/read.go index 152a80dc0..a33188e26 100644 --- a/src/pkg/xml/read.go +++ b/src/pkg/xml/read.go @@ -128,9 +128,7 @@ func Unmarshal(r io.Reader, val interface{}) os.Error { // An UnmarshalError represents an error in the unmarshalling process. type UnmarshalError string -func (e UnmarshalError) String() string { - return string(e); -} +func (e UnmarshalError) String() string { return string(e) } // The Parser's Unmarshal method is like xml.Unmarshal // except that it can be passed a pointer to the initial start element, diff --git a/src/pkg/xml/xml.go b/src/pkg/xml/xml.go index 2f33f2d85..52ef78f2f 100644 --- a/src/pkg/xml/xml.go +++ b/src/pkg/xml/xml.go @@ -28,9 +28,7 @@ import ( // A SyntaxError represents a syntax error in the XML input stream. type SyntaxError string -func (e SyntaxError) String() string { - return "XML syntax error: " + string(e); -} +func (e SyntaxError) String() string { return "XML syntax error: " + string(e) } // A Name represents an XML name (Local) annotated // with a name space identifier (Space). @@ -73,17 +71,13 @@ func copy(b []byte) []byte { return b1; } -func (c CharData) Copy() CharData { - return CharData(copy(c)); -} +func (c CharData) Copy() CharData { return CharData(copy(c)) } // A Comment represents an XML comment of the form <!--comment-->. // The bytes do not include the <!-- and --> comment markers. type Comment []byte -func (c Comment) Copy() Comment { - return Comment(copy(c)); -} +func (c Comment) Copy() Comment { return Comment(copy(c)) } // A ProcInst represents an XML processing instruction of the form <?target inst?> type ProcInst struct { @@ -100,9 +94,7 @@ func (p ProcInst) Copy() ProcInst { // The bytes do not include the <! and > markers. type Directive []byte -func (d Directive) Copy() Directive { - return Directive(copy(d)); -} +func (d Directive) Copy() Directive { return Directive(copy(d)) } type readByter interface { ReadByte() (b byte, err os.Error); diff --git a/src/pkg/xml/xml_test.go b/src/pkg/xml/xml_test.go index e8a2a8769..8b0fda60a 100644 --- a/src/pkg/xml/xml_test.go +++ b/src/pkg/xml/xml_test.go @@ -116,9 +116,7 @@ func (r *stringReader) ReadByte() (b byte, err os.Error) { return; } -func StringReader(s string) io.Reader { - return &stringReader{s, 0}; -} +func StringReader(s string) io.Reader { return &stringReader{s, 0} } func TestRawToken(t *testing.T) { p := NewParser(StringReader(testInput)); |