1
0
mirror of https://github.com/golang/go synced 2024-11-21 13:24:40 -07:00

gofmt: don't print ()'s around function-typed results (not needed anymore)

- add extra test cases to go/printer tests
- apply gofmt to src and misc

R=rsc
CC=golang-dev
https://golang.org/cl/223041
This commit is contained in:
Robert Griesemer 2010-02-24 13:24:37 -08:00
parent 228903c5da
commit 1be05bbe1e
9 changed files with 41 additions and 37 deletions

View File

@ -303,7 +303,7 @@ func (a *assignCompiler) allowMapForms(nls int) {
// a function that expects an l-value and the frame in which to
// evaluate the RHS expressions. The l-value must have exactly the
// type given by lt. Returns nil if type checking fails.
func (a *assignCompiler) compile(b *block, lt Type) (func(Value, *Thread)) {
func (a *assignCompiler) compile(b *block, lt Type) func(Value, *Thread) {
lmt, isMT := lt.(*MultiType)
rmt, isUnpack := a.rmt, a.isUnpack
@ -446,7 +446,7 @@ func (a *assignCompiler) compile(b *block, lt Type) (func(Value, *Thread)) {
// compileAssign compiles an assignment operation without the full
// generality of an assignCompiler. See assignCompiler for a
// description of the arguments.
func (a *compiler) compileAssign(pos token.Position, b *block, lt Type, rs []*expr, errOp, errPosName string) (func(Value, *Thread)) {
func (a *compiler) compileAssign(pos token.Position, b *block, lt Type, rs []*expr, errOp, errPosName string) func(Value, *Thread) {
ac, ok := a.checkAssign(pos, rs, errOp, errPosName)
if !ok {
return nil
@ -836,8 +836,8 @@ func (a *exprInfo) compileSelectorExpr(v *expr, name string) *expr {
// TODO(austin) Now that the expression compiler works on
// semantic values instead of AST's, there should be a much
// better way of doing this.
var find func(Type, int, string) (func(*expr) *expr)
find = func(t Type, depth int, pathName string) (func(*expr) *expr) {
var find func(Type, int, string) func(*expr) *expr
find = func(t Type, depth int, pathName string) func(*expr) *expr {
// Don't bother looking if we've found something shallower
if bestDepth != -1 && bestDepth < depth {
return nil

View File

@ -12,40 +12,36 @@ 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) 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) asIdealInt() (func() *bignum.Integer) {
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) asIdealInt() func() *bignum.Integer {
return a.eval.(func() *bignum.Integer)
}
func (a *expr) asFloat() (func(*Thread) float64) {
func (a *expr) asFloat() func(*Thread) float64 {
return a.eval.(func(*Thread) float64)
}
func (a *expr) asIdealFloat() (func() *bignum.Rational) {
func (a *expr) asIdealFloat() func() *bignum.Rational {
return a.eval.(func() *bignum.Rational)
}
func (a *expr) asString() (func(*Thread) string) {
func (a *expr) asString() func(*Thread) string {
return a.eval.(func(*Thread) string)
}
func (a *expr) asArray() (func(*Thread) ArrayValue) {
func (a *expr) asArray() func(*Thread) ArrayValue {
return a.eval.(func(*Thread) ArrayValue)
}
func (a *expr) asStruct() (func(*Thread) StructValue) {
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) 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) asMulti() (func(*Thread) []Value) {
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) asMulti() func(*Thread) []Value {
return a.eval.(func(*Thread) []Value)
}
func (a *expr) asInterface() (func(*Thread) interface{}) {
func (a *expr) asInterface() func(*Thread) interface{} {
switch sf := a.eval.(type) {
case func(t *Thread) bool:
return func(t *Thread) interface{} { return sf(t) }
@ -1871,7 +1867,7 @@ func (a *expr) genBinOpNeq(l, r *expr) {
}
}
func genAssign(lt Type, r *expr) (func(lv Value, t *Thread)) {
func genAssign(lt Type, r *expr) func(lv Value, t *Thread) {
switch lt.lit().(type) {
case *boolType:
rf := r.asBool()

View File

@ -1226,7 +1226,7 @@ func (a *blockCompiler) exit() { a.block.exit() }
* Function compiler
*/
func (a *compiler) compileFunc(b *block, decl *FuncDecl, body *ast.BlockStmt) (func(*Thread) Func) {
func (a *compiler) compileFunc(b *block, decl *FuncDecl, body *ast.BlockStmt) func(*Thread) Func {
// Create body scope
//
// The scope of a parameter or result is the body of the

View File

@ -18,7 +18,7 @@ type Iterable interface {
Iter() <-chan interface{}
}
func not(f func(interface{}) bool) (func(interface{}) bool) {
func not(f func(interface{}) bool) func(interface{}) bool {
return func(e interface{}) bool { return !f(e) }
}

View File

@ -241,19 +241,13 @@ func (p *printer) signature(params, result []*ast.Field, multiLine *bool) {
p.parameters(params, multiLine)
if result != nil {
p.print(blank)
if len(result) == 1 && result[0].Names == nil {
// single anonymous result; no ()'s unless it's a function type
f := result[0]
if _, isFtyp := f.Type.(*ast.FuncType); !isFtyp {
p.expr(f.Type, multiLine)
return
}
// single anonymous result; no ()'s
p.expr(result[0].Type, multiLine)
return
}
p.parameters(result, multiLine)
}
return
}

View File

@ -471,6 +471,13 @@ func _() {
}
// formatting of function results
func _() func() {}
func _() func(int) { return nil }
func _() func(int) int { return nil }
func _() func(int) func(int) func() { return nil }
// formatting of consecutive single-line functions
func _() {}
func _() {}

View File

@ -468,6 +468,13 @@ func _() {
}
// formatting of function results
func _() func() {}
func _() func(int) { return nil }
func _() func(int) int { return nil }
func _() func(int) func(int) func() { return nil }
// formatting of consecutive single-line functions
func _() {}
func _() {}

View File

@ -146,7 +146,7 @@ var typeTests = []pair{
},
pair{struct {
x (interface {
a(func(func(int) int) (func(func(int)) int))
a(func(func(int) int) func(func(int)) int)
b()
})
}{},

View File

@ -72,7 +72,7 @@ func plus1(v interface{}) string {
return fmt.Sprint(i + 1)
}
func writer(f func(interface{}) string) (func(io.Writer, 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))
}