]> Cypherpunks.ru repositories - gostls13.git/commitdiff
Change type of Printf's args to ... interface{}
authorRob Pike <r@golang.org>
Mon, 1 Feb 2010 23:53:37 +0000 (10:53 +1100)
committerRob Pike <r@golang.org>
Mon, 1 Feb 2010 23:53:37 +0000 (10:53 +1100)
R=rsc
CC=golang-dev
https://golang.org/cl/197043

15 files changed:
src/cmd/cgo/util.go
src/cmd/goyacc/goyacc.go
src/pkg/debug/proc/proc_linux.go
src/pkg/exp/eval/compiler.go
src/pkg/exp/eval/expr.go
src/pkg/exp/eval/stmt.go
src/pkg/exp/parser/parser.go
src/pkg/fmt/print.go
src/pkg/go/parser/parser.go
src/pkg/go/printer/printer.go
src/pkg/log/log.go
src/pkg/template/template.go
src/pkg/testing/testing.go
test/bench/pidigits.go
test/defer.go

index 782efddf4e24ca35c37bae8e6b0ed8ab68863148..95067039ca74114c94ca282cbbc6daa316ca0258 100644 (file)
@@ -76,7 +76,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
 }
 
 // Die with an error message.
-func fatal(msg string, args ...) {
+func fatal(msg string, args ...interface{}) {
        fmt.Fprintf(os.Stderr, msg+"\n", args)
        os.Exit(2)
 }
@@ -84,7 +84,7 @@ func fatal(msg string, args ...) {
 var nerrors int
 var noPos token.Position
 
-func error(pos token.Position, msg string, args ...) {
+func error(pos token.Position, msg string, args ...interface{}) {
        nerrors++
        if pos.IsValid() {
                fmt.Fprintf(os.Stderr, "%s: ", pos)
index 59c9752326c66f44a0a38be6b79bd8bc29776aa3..4e4819b40b92a6df40d18a56bcbcb1d0f0c072f8 100644 (file)
@@ -3097,7 +3097,7 @@ func create(s string, m int) *bufio.Writer {
 //
 // write out error comment
 //
-func error(s string, v ...) {
+func error(s string, v ...interface{}) {
        nerrors++
        fmt.Fprintf(stderr, s, v)
        fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno)
index 7273e97d8498feef3b954473c3e519df690dd61b..cdeba7c0e4dde3f316e8918e0df0c534b7756ce3 100644 (file)
@@ -282,7 +282,7 @@ func (t *thread) ptraceDetach() os.Error {
 
 var logLock sync.Mutex
 
-func (t *thread) logTrace(format string, args ...) {
+func (t *thread) logTrace(format string, args ...interface{}) {
        if !trace {
                return
        }
@@ -301,7 +301,7 @@ func (t *thread) logTrace(format string, args ...) {
        fmt.Fprint(os.Stderr, "\n")
 }
 
-func (t *thread) warn(format string, args ...) {
+func (t *thread) warn(format string, args ...interface{}) {
        logLock.Lock()
        defer logLock.Unlock()
        fmt.Fprintf(os.Stderr, "Thread %d: WARNING ", t.tid)
@@ -309,7 +309,7 @@ func (t *thread) warn(format string, args ...) {
        fmt.Fprint(os.Stderr, "\n")
 }
 
-func (p *process) logTrace(format string, args ...) {
+func (p *process) logTrace(format string, args ...interface{}) {
        if !trace {
                return
        }
index 6bde3b5672dd92f44181c66c2a0cacd0fbf624eb..bf5a842e6e1cad315d7f10631c541630aecd2a43 100644 (file)
@@ -27,7 +27,7 @@ type compiler struct {
        silentErrors int
 }
 
-func (a *compiler) diagAt(pos positioned, format string, args ...) {
+func (a *compiler) diagAt(pos positioned, format string, args ...interface{}) {
        a.errors.Error(pos.Pos(), fmt.Sprintf(format, args))
        a.numErrors++
 }
index 27aea0877815440902c4d92d4ff988205245259c..ed32c0a3c6d65bf58373b43ed197dba211d9344d 100644 (file)
@@ -58,7 +58,7 @@ func (a *exprInfo) newExpr(t Type, desc string) *expr {
        return &expr{exprInfo: a, t: t, desc: desc}
 }
 
-func (a *exprInfo) diag(format string, args ...) {
+func (a *exprInfo) diag(format string, args ...interface{}) {
        a.diagAt(&a.pos, format, args)
 }
 
index d89fde1f93db77d3adaa4181de83c897d8e58bb7..758e479f89d1a0a8e2917ac8a189e59b5784bb0a 100644 (file)
@@ -27,7 +27,7 @@ type stmtCompiler struct {
        stmtLabel *label
 }
 
-func (a *stmtCompiler) diag(format string, args ...) {
+func (a *stmtCompiler) diag(format string, args ...interface{}) {
        a.diagAt(&a.pos, format, args)
 }
 
index 8336bdb08fa87165b5e9900de8d5cc384cd6ba28..6114c88953c482176d1d8d3601bc2266c0ecc2a6 100644 (file)
@@ -91,7 +91,7 @@ func (p *parser) init(filename string, src []byte, mode uint) {
 // ----------------------------------------------------------------------------
 // Parsing support
 
-func (p *parser) printTrace(a ...) {
+func (p *parser) printTrace(a ...interface{}) {
        const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " +
                ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
        const n = uint(len(dots))
index cc2c82cb7e3d8015b973001f4ce0c47b908619aa..de64179cc876f69e104f799287b80ee20a2291e6 100644 (file)
@@ -212,26 +212,24 @@ func (p *pp) Write(b []byte) (ret int, err os.Error) {
 // These routines end in 'f' and take a format string.
 
 // Fprintf formats according to a format specifier and writes to w.
-func Fprintf(w io.Writer, format string, a ...) (n int, error os.Error) {
-       v := reflect.NewValue(a).(*reflect.StructValue)
+func Fprintf(w io.Writer, format string, a ...interface{}) (n int, error os.Error) {
        p := newPrinter()
-       p.doprintf(format, v)
+       p.doprintf(format, a)
        n64, error := p.buf.WriteTo(w)
        p.free()
        return int(n64), error
 }
 
 // Printf formats according to a format specifier and writes to standard output.
-func Printf(format string, v ...) (n int, errno os.Error) {
-       n, errno = Fprintf(os.Stdout, format, v)
+func Printf(format string, a ...interface{}) (n int, errno os.Error) {
+       n, errno = Fprintf(os.Stdout, format, a)
        return n, errno
 }
 
 // Sprintf formats according to a format specifier and returns the resulting string.
-func Sprintf(format string, a ...) string {
-       v := reflect.NewValue(a).(*reflect.StructValue)
+func Sprintf(format string, a ...interface{}) string {
        p := newPrinter()
-       p.doprintf(format, v)
+       p.doprintf(format, a)
        s := p.buf.String()
        p.free()
        return s
@@ -241,10 +239,9 @@ func Sprintf(format string, a ...) string {
 
 // Fprint formats using the default formats for its operands and writes to w.
 // Spaces are added between operands when neither is a string.
-func Fprint(w io.Writer, a ...) (n int, error os.Error) {
-       v := reflect.NewValue(a).(*reflect.StructValue)
+func Fprint(w io.Writer, a ...interface{}) (n int, error os.Error) {
        p := newPrinter()
-       p.doprint(v, false, false)
+       p.doprint(a, false, false)
        n64, error := p.buf.WriteTo(w)
        p.free()
        return int(n64), error
@@ -252,17 +249,16 @@ func Fprint(w io.Writer, a ...) (n int, error os.Error) {
 
 // Print formats using the default formats for its operands and writes to standard output.
 // Spaces are added between operands when neither is a string.
-func Print(v ...) (n int, errno os.Error) {
-       n, errno = Fprint(os.Stdout, v)
+func Print(a ...interface{}) (n int, errno os.Error) {
+       n, errno = Fprint(os.Stdout, a)
        return n, errno
 }
 
 // Sprint formats using the default formats for its operands and returns the resulting string.
 // Spaces are added between operands when neither is a string.
-func Sprint(a ...) string {
-       v := reflect.NewValue(a).(*reflect.StructValue)
+func Sprint(a ...interface{}) string {
        p := newPrinter()
-       p.doprint(v, false, false)
+       p.doprint(a, false, false)
        s := p.buf.String()
        p.free()
        return s
@@ -274,10 +270,9 @@ func Sprint(a ...) string {
 
 // Fprintln formats using the default formats for its operands and writes to w.
 // Spaces are always added between operands and a newline is appended.
-func Fprintln(w io.Writer, a ...) (n int, error os.Error) {
-       v := reflect.NewValue(a).(*reflect.StructValue)
+func Fprintln(w io.Writer, a ...interface{}) (n int, error os.Error) {
        p := newPrinter()
-       p.doprint(v, true, true)
+       p.doprint(a, true, true)
        n64, error := p.buf.WriteTo(w)
        p.free()
        return int(n64), error
@@ -285,17 +280,16 @@ func Fprintln(w io.Writer, a ...) (n int, error os.Error) {
 
 // Println formats using the default formats for its operands and writes to standard output.
 // Spaces are always added between operands and a newline is appended.
-func Println(v ...) (n int, errno os.Error) {
-       n, errno = Fprintln(os.Stdout, v)
+func Println(a ...interface{}) (n int, errno os.Error) {
+       n, errno = Fprintln(os.Stdout, a)
        return n, errno
 }
 
 // Sprintln formats using the default formats for its operands and returns the resulting string.
 // Spaces are always added between operands and a newline is appended.
-func Sprintln(a ...) string {
-       v := reflect.NewValue(a).(*reflect.StructValue)
+func Sprintln(a ...interface{}) string {
        p := newPrinter()
-       p.doprint(v, true, true)
+       p.doprint(a, true, true)
        s := p.buf.String()
        p.free()
        return s
@@ -317,44 +311,84 @@ func getField(v *reflect.StructValue, i int) reflect.Value {
 
 // Getters for the fields of the argument structure.
 
-func getBool(v reflect.Value) (val bool, ok bool) {
-       if b, ok := v.(*reflect.BoolValue); ok {
+func getBool(a interface{}) (val bool, ok bool) {
+       // Is it a regular bool type?
+       if b, ok := a.(bool); ok {
+               return b, true
+       }
+       // Must be a renamed bool type.
+       if b, ok := reflect.NewValue(a).(*reflect.BoolValue); ok {
                return b.Get(), true
        }
        return
 }
 
-func getInt(v reflect.Value) (val int64, signed, ok bool) {
-       switch v := v.(type) {
+func getInt(a interface{}) (val int64, signed, ok bool) {
+       // Is it a predeclared integer type?
+       switch i := a.(type) {
+       case int:
+               return int64(i), true, true
+       case int8:
+               return int64(i), true, true
+       case int16:
+               return int64(i), true, true
+       case int32:
+               return int64(i), true, true
+       case int64:
+               return i, true, true
+       case uint:
+               return int64(i), false, true
+       case uint8:
+               return int64(i), false, true
+       case uint16:
+               return int64(i), false, true
+       case uint32:
+               return int64(i), false, true
+       case uint64:
+               return int64(i), false, true
+       case uintptr:
+               return int64(i), false, true
+       }
+       // Must be a renamed integer type.
+       switch i := reflect.NewValue(a).(type) {
        case *reflect.IntValue:
-               return int64(v.Get()), true, true
+               return int64(i.Get()), true, true
        case *reflect.Int8Value:
-               return int64(v.Get()), true, true
+               return int64(i.Get()), true, true
        case *reflect.Int16Value:
-               return int64(v.Get()), true, true
+               return int64(i.Get()), true, true
        case *reflect.Int32Value:
-               return int64(v.Get()), true, true
+               return int64(i.Get()), true, true
        case *reflect.Int64Value:
-               return int64(v.Get()), true, true
+               return i.Get(), true, true
        case *reflect.UintValue:
-               return int64(v.Get()), false, true
+               return int64(i.Get()), false, true
        case *reflect.Uint8Value:
-               return int64(v.Get()), false, true
+               return int64(i.Get()), false, true
        case *reflect.Uint16Value:
-               return int64(v.Get()), false, true
+               return int64(i.Get()), false, true
        case *reflect.Uint32Value:
-               return int64(v.Get()), false, true
+               return int64(i.Get()), false, true
        case *reflect.Uint64Value:
-               return int64(v.Get()), false, true
+               return int64(i.Get()), false, true
        case *reflect.UintptrValue:
-               return int64(v.Get()), false, true
+               return int64(i.Get()), false, true
        }
        return
 }
 
-func getString(v reflect.Value) (val string, ok bool) {
-       if v, ok := v.(*reflect.StringValue); ok {
-               return v.Get(), true
+func getString(a interface{}) (val string, ok bool) {
+       // Is it a regular string or []byte type?
+       switch s := a.(type) {
+       case string:
+               return s, true
+       case []byte:
+               return string(s), true
+       }
+       // Must be a renamed string or []byte type.
+       v := reflect.NewValue(a)
+       if s, ok := v.(*reflect.StringValue); ok {
+               return s.Get(), true
        }
        if bytes, ok := v.Interface().([]byte); ok {
                return string(bytes), true
@@ -362,26 +396,48 @@ func getString(v reflect.Value) (val string, ok bool) {
        return
 }
 
-func getFloat32(v reflect.Value) (val float32, ok bool) {
-       switch v := v.(type) {
+var floatBits = reflect.Typeof(float(0)).Size() * 8
+
+func getFloat32(a interface{}) (val float32, ok bool) {
+       // Is it a regular floating-point type?
+       switch f := a.(type) {
+       case float32:
+               return f, true
+       case float:
+               if floatBits == 32 {
+                       return float32(f), true
+               }
+       }
+       // Must be a renamed floating-point type.
+       switch f := a.(type) {
        case *reflect.Float32Value:
-               return float32(v.Get()), true
+               return float32(f.Get()), true
        case *reflect.FloatValue:
-               if v.Type().Size()*8 == 32 {
-                       return float32(v.Get()), true
+               if floatBits == 32 {
+                       return float32(f.Get()), true
                }
        }
        return
 }
 
-func getFloat64(v reflect.Value) (val float64, ok bool) {
-       switch v := v.(type) {
-       case *reflect.FloatValue:
-               if v.Type().Size()*8 == 64 {
-                       return float64(v.Get()), true
+func getFloat64(a interface{}) (val float64, ok bool) {
+       // Is it a regular floating-point type?
+       switch f := a.(type) {
+       case float64:
+               return f, true
+       case float:
+               if floatBits == 64 {
+                       return float64(f), true
                }
+       }
+       // Must be a renamed floating-point type.
+       switch f := a.(type) {
        case *reflect.Float64Value:
-               return float64(v.Get()), true
+               return float64(f.Get()), true
+       case *reflect.FloatValue:
+               if floatBits == 64 {
+                       return float64(f.Get()), true
+               }
        }
        return
 }
@@ -406,24 +462,80 @@ type uintptrGetter interface {
        Get() uintptr
 }
 
-func (p *pp) printField(field reflect.Value, plus, sharp bool, depth int) (was_string bool) {
-       inter := field.Interface()
-       if inter != nil {
+func (p *pp) unknownType(v interface{}) {
+       if v == nil {
+               p.buf.Write(nilAngleBytes)
+               return
+       }
+       p.buf.WriteByte('?')
+       p.buf.WriteString(reflect.Typeof(v).String())
+       p.buf.WriteByte('?')
+}
+
+func (p *pp) printField(field interface{}, plus, sharp bool, depth int) (was_string bool) {
+       if field != nil {
                switch {
                default:
-                       if stringer, ok := inter.(Stringer); ok {
+                       if stringer, ok := field.(Stringer); ok {
                                p.buf.WriteString(stringer.String())
                                return false // this value is not a string
                        }
                case sharp:
-                       if stringer, ok := inter.(GoStringer); ok {
+                       if stringer, ok := field.(GoStringer); ok {
                                p.buf.WriteString(stringer.GoString())
                                return false // this value is not a string
                        }
                }
        }
-BigSwitch:
+
+       // Some types can be done without reflection.
        switch f := field.(type) {
+       case bool:
+               p.fmt.fmt_boolean(f)
+               return false
+       case float32:
+               p.fmt.fmt_g32(f)
+               return false
+       case float64:
+               p.fmt.fmt_g64(f)
+               return false
+       case float:
+               if floatBits == 32 {
+                       p.fmt.fmt_g32(float32(f))
+               } else {
+                       p.fmt.fmt_g64(float64(f))
+               }
+               return false
+       case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr:
+               v, signed, ok := getInt(field)
+               if !ok {
+                       // cannot happen, but print something to be sure
+                       p.unknownType(f)
+               } else {
+                       if signed {
+                               p.fmt.fmt_d64(v)
+                       } else {
+                               if sharp {
+                                       p.fmt.sharp = true // turn on 0x
+                                       p.fmt.fmt_ux64(uint64(v))
+                               } else {
+                                       p.fmt.fmt_ud64(uint64(v))
+                               }
+                       }
+               }
+               return false
+       case string:
+               if sharp {
+                       p.fmt.fmt_q(f)
+               } else {
+                       p.fmt.fmt_s(f)
+               }
+               return true
+       }
+
+       // Need to use reflection
+BigSwitch:
+       switch f := reflect.NewValue(field).(type) {
        case *reflect.BoolValue:
                p.fmt.fmt_boolean(f.Get())
        case *reflect.Float32Value:
@@ -431,7 +543,7 @@ BigSwitch:
        case *reflect.Float64Value:
                p.fmt.fmt_g64(f.Get())
        case *reflect.FloatValue:
-               if field.Type().Size()*8 == 32 {
+               if floatBits == 32 {
                        p.fmt.fmt_g32(float32(f.Get()))
                } else {
                        p.fmt.fmt_g64(float64(f.Get()))
@@ -445,7 +557,7 @@ BigSwitch:
                }
        case *reflect.MapValue:
                if sharp {
-                       p.buf.WriteString(field.Type().String())
+                       p.buf.WriteString(f.Type().String())
                        p.buf.WriteByte('{')
                } else {
                        p.buf.Write(mapBytes)
@@ -459,9 +571,9 @@ BigSwitch:
                                        p.buf.WriteByte(' ')
                                }
                        }
-                       p.printField(key, plus, sharp, depth+1)
+                       p.printField(key.Interface(), plus, sharp, depth+1)
                        p.buf.WriteByte(':')
-                       p.printField(f.Elem(key), plus, sharp, depth+1)
+                       p.printField(f.Elem(key).Interface(), plus, sharp, depth+1)
                }
                if sharp {
                        p.buf.WriteByte('}')
@@ -470,7 +582,7 @@ BigSwitch:
                }
        case *reflect.StructValue:
                if sharp {
-                       p.buf.WriteString(field.Type().String())
+                       p.buf.WriteString(reflect.Typeof(field).String())
                }
                p.add('{')
                v := f
@@ -490,24 +602,24 @@ BigSwitch:
                                        p.buf.WriteByte(':')
                                }
                        }
-                       p.printField(getField(v, i), plus, sharp, depth+1)
+                       p.printField(getField(v, i).Interface(), plus, sharp, depth+1)
                }
                p.buf.WriteByte('}')
        case *reflect.InterfaceValue:
                value := f.Elem()
                if value == nil {
                        if sharp {
-                               p.buf.WriteString(field.Type().String())
+                               p.buf.WriteString(reflect.Typeof(field).String())
                                p.buf.Write(nilParenBytes)
                        } else {
                                p.buf.Write(nilAngleBytes)
                        }
                } else {
-                       return p.printField(value, plus, sharp, depth+1)
+                       return p.printField(value.Interface(), plus, sharp, depth+1)
                }
        case reflect.ArrayOrSliceValue:
                if sharp {
-                       p.buf.WriteString(field.Type().String())
+                       p.buf.WriteString(reflect.Typeof(field).String())
                        p.buf.WriteByte('{')
                } else {
                        p.buf.WriteByte('[')
@@ -520,7 +632,7 @@ BigSwitch:
                                        p.buf.WriteByte(' ')
                                }
                        }
-                       p.printField(f.Elem(i), plus, sharp, depth+1)
+                       p.printField(f.Elem(i).Interface(), plus, sharp, depth+1)
                }
                if sharp {
                        p.buf.WriteByte('}')
@@ -535,17 +647,17 @@ BigSwitch:
                        switch a := f.Elem().(type) {
                        case reflect.ArrayOrSliceValue:
                                p.buf.WriteByte('&')
-                               p.printField(a, plus, sharp, depth+1)
+                               p.printField(a.Interface(), plus, sharp, depth+1)
                                break BigSwitch
                        case *reflect.StructValue:
                                p.buf.WriteByte('&')
-                               p.printField(a, plus, sharp, depth+1)
+                               p.printField(a.Interface(), plus, sharp, depth+1)
                                break BigSwitch
                        }
                }
                if sharp {
                        p.buf.WriteByte('(')
-                       p.buf.WriteString(field.Type().String())
+                       p.buf.WriteString(reflect.Typeof(field).String())
                        p.buf.WriteByte(')')
                        p.buf.WriteByte('(')
                        if v == 0 {
@@ -567,7 +679,7 @@ BigSwitch:
                v := f.Get()
                if sharp {
                        p.buf.WriteByte('(')
-                       p.buf.WriteString(field.Type().String())
+                       p.buf.WriteString(reflect.Typeof(field).String())
                        p.buf.WriteByte(')')
                        p.buf.WriteByte('(')
                        if v == 0 {
@@ -596,14 +708,12 @@ BigSwitch:
                        }
                        break
                }
-               p.buf.WriteByte('?')
-               p.buf.WriteString(field.Type().String())
-               p.buf.WriteByte('?')
+               p.unknownType(f)
        }
-       return was_string
+       return false
 }
 
-func (p *pp) doprintf(format string, v *reflect.StructValue) {
+func (p *pp) doprintf(format string, a []interface{}) {
        end := len(format) - 1
        fieldnum := 0 // we process one field per non-trivial format
        for i := 0; i <= end; {
@@ -649,20 +759,19 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
                        p.buf.WriteByte('%') // TODO: should we bother with width & prec?
                        continue
                }
-               if fieldnum >= v.NumField() { // out of operands
+               if fieldnum >= len(a) { // out of operands
                        p.buf.WriteByte('%')
                        p.add(c)
                        p.buf.Write(missingBytes)
                        continue
                }
-               field := getField(v, fieldnum)
+               field := a[fieldnum]
                fieldnum++
 
                // Try formatter except for %T,
                // which is special and handled internally.
-               inter := field.Interface()
-               if inter != nil && c != 'T' {
-                       if formatter, ok := inter.(Formatter); ok {
+               if field != nil && c != 'T' {
+                       if formatter, ok := field.(Formatter); ok {
                                formatter.Format(p, c)
                                continue
                        }
@@ -787,9 +896,9 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
 
                // string
                case 's':
-                       if inter != nil {
+                       if field != nil {
                                // if object implements String, use the result.
-                               if stringer, ok := inter.(Stringer); ok {
+                               if stringer, ok := field.(Stringer); ok {
                                        p.fmt.fmt_s(stringer.String())
                                        break
                                }
@@ -808,7 +917,7 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
 
                // pointer, including addresses of reference types.
                case 'p':
-                       switch v := field.(type) {
+                       switch v := reflect.NewValue(field).(type) {
                        case getter:
                                p.fmt.fmt_s("0x")
                                p.fmt.fmt_uX64(uint64(v.Get()))
@@ -825,27 +934,27 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
 
                // the value's type
                case 'T':
-                       p.buf.WriteString(field.Type().String())
+                       p.buf.WriteString(reflect.Typeof(field).String())
 
                default:
                badtype:
                        p.buf.WriteByte('%')
                        p.add(c)
                        p.buf.WriteByte('(')
-                       p.buf.WriteString(field.Type().String())
+                       p.buf.WriteString(reflect.Typeof(field).String())
                        p.buf.WriteByte('=')
                        p.printField(field, false, false, 0)
                        p.buf.WriteByte(')')
                }
        }
-       if fieldnum < v.NumField() {
+       if fieldnum < len(a) {
                p.buf.Write(extraBytes)
-               for ; fieldnum < v.NumField(); fieldnum++ {
-                       field := getField(v, fieldnum)
-                       p.buf.WriteString(field.Type().String())
+               for ; fieldnum < len(a); fieldnum++ {
+                       field := a[fieldnum]
+                       p.buf.WriteString(reflect.Typeof(field).String())
                        p.buf.WriteByte('=')
                        p.printField(field, false, false, 0)
-                       if fieldnum+1 < v.NumField() {
+                       if fieldnum+1 < len(a) {
                                p.buf.Write(commaSpaceBytes)
                        }
                }
@@ -853,11 +962,11 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
        }
 }
 
-func (p *pp) doprint(v *reflect.StructValue, addspace, addnewline bool) {
+func (p *pp) doprint(a []interface{}, addspace, addnewline bool) {
        prev_string := false
-       for fieldnum := 0; fieldnum < v.NumField(); fieldnum++ {
+       for fieldnum := 0; fieldnum < len(a); fieldnum++ {
                // always add spaces if we're doing println
-               field := getField(v, fieldnum)
+               field := a[fieldnum]
                if fieldnum > 0 {
                        _, is_string := field.(*reflect.StringValue)
                        if addspace || !is_string && !prev_string {
index 140b954f9bc827562bac77440501fa9fbe2b39c9..d848d2392b7473329d5b80ff3e6a22e3459baec2 100644 (file)
@@ -93,7 +93,7 @@ func (p *parser) init(filename string, src []byte, scope *ast.Scope, mode uint)
 // ----------------------------------------------------------------------------
 // Parsing support
 
-func (p *parser) printTrace(a ...) {
+func (p *parser) printTrace(a ...interface{}) {
        const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " +
                ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
        const n = uint(len(dots))
index 4fe7bfbc37ab910234d223e8ee5e1c46fd079fa6..304ba0b0ac284991799105739e501391089d288d 100644 (file)
@@ -101,7 +101,7 @@ func (p *printer) init(output io.Writer, cfg *Config) {
 }
 
 
-func (p *printer) internalError(msg ...) {
+func (p *printer) internalError(msg ...interface{}) {
        if debug {
                fmt.Print(p.pos.String() + ": ")
                fmt.Println(msg)
index ac996a38daee33d8336380674cedc72274fd52a4..83769be03974295a4358397dfe34b14189ffb2d7 100644 (file)
@@ -149,31 +149,33 @@ func (l *Logger) Output(calldepth int, s string) os.Error {
 }
 
 // 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 ...interface{}) {
+       l.Output(2, fmt.Sprintf(format, v))
+}
 
 // Log is analogous to Print() for a Logger.
-func (l *Logger) Log(v ...) { l.Output(2, fmt.Sprintln(v)) }
+func (l *Logger) Log(v ...interface{}) { 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 ...interface{}) { 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 ...interface{}) { 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 ...interface{}) { 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 ...interface{}) { 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 ...interface{}) { 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 ...interface{}) { 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 ...interface{}) { 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 ...interface{}) { crash.Output(2, fmt.Sprintf(format, v)) }
index b507c3c9ecca6468e3d68fd40fe3ec267b47509c..c32a742b871e1eb5272d24f198048f69056c23ea 100644 (file)
@@ -187,14 +187,14 @@ func New(fmap FormatterMap) *Template {
 }
 
 // Report error and stop executing.  The line number must be provided explicitly.
-func (t *Template) execError(st *state, line int, err string, args ...) {
+func (t *Template) execError(st *state, line int, err string, args ...interface{}) {
        st.errors <- &Error{line, fmt.Sprintf(err, args)}
        runtime.Goexit()
 }
 
 // Report error, save in Template to terminate parsing.
 // The line number comes from the template state.
-func (t *Template) parseError(err string, args ...) {
+func (t *Template) parseError(err string, args ...interface{}) {
        t.error = &Error{t.linenum, fmt.Sprintf(err, args)}
 }
 
index 77f9942d8bda21c5c2f155f16fc3a0e847ec2fc9..f917004e87c0e0985a1d494dcf7cd743132bdb32 100644 (file)
@@ -89,34 +89,34 @@ 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 ...interface{}) { 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.
-func (t *T) Logf(format string, args ...) {
+func (t *T) Logf(format string, args ...interface{}) {
        t.errors += "\t" + tabify(fmt.Sprintf(format, args))
 }
 
 // Error is equivalent to Log() followed by Fail().
-func (t *T) Error(args ...) {
+func (t *T) Error(args ...interface{}) {
        t.Log(args)
        t.Fail()
 }
 
 // Errorf is equivalent to Logf() followed by Fail().
-func (t *T) Errorf(format string, args ...) {
+func (t *T) Errorf(format string, args ...interface{}) {
        t.Logf(format, args)
        t.Fail()
 }
 
 // Fatal is equivalent to Log() followed by FailNow().
-func (t *T) Fatal(args ...) {
+func (t *T) Fatal(args ...interface{}) {
        t.Log(args)
        t.FailNow()
 }
 
 // Fatalf is equivalent to Logf() followed by FailNow().
-func (t *T) Fatalf(format string, args ...) {
+func (t *T) Fatalf(format string, args ...interface{}) {
        t.Logf(format, args)
        t.FailNow()
 }
index 430c1182872383f01e3f31a853e1c797e0370649..aaa9f53a5cb75e53fbd8da299fff8758c6c951ad 100644 (file)
@@ -92,7 +92,7 @@ func eliminate_digit(d int64) {
        bignum.Iscale(numer, 10)
 }
 
-func printf(s string, arg ...) {
+func printf(s string, arg ...interface{}) {
        if !*silent {
                fmt.Printf(s, arg)
        }
index 19730a5eade7174f44cf06b08210b2f092ec5a5b..8b8312235d1c2f7d99d27bb49637ef1b1376cb19 100644 (file)
@@ -10,9 +10,7 @@ import "fmt"
 
 var result string
 
-func addInt(i int) {
-       result += fmt.Sprint(i)
-}
+func addInt(i int) { result += fmt.Sprint(i) }
 
 func test1helper() {
        for i := 0; i < 10; i++ {
@@ -21,16 +19,14 @@ func test1helper() {
 }
 
 func test1() {
-       result = "";
-       test1helper();
+       result = ""
+       test1helper()
        if result != "9876543210" {
-               fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result);
+               fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result)
        }
 }
 
-func addDotDotDot(v ...) {
-       result += fmt.Sprint(v)
-}
+func addDotDotDot(v ...interface{}) { result += fmt.Sprint(v) }
 
 func test2helper() {
        for i := 0; i < 10; i++ {
@@ -39,14 +35,14 @@ func test2helper() {
 }
 
 func test2() {
-       result = "";
-       test2helper();
+       result = ""
+       test2helper()
        if result != "9876543210" {
-               fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result);
+               fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result)
        }
 }
 
 func main() {
-       test1();
-       test2();
+       test1()
+       test2()
 }