Commit d2fc5d68 authored by Rob Pike's avatar Rob Pike

Change type of Printf's args to ... interface{}

R=rsc
CC=golang-dev
https://golang.org/cl/197043
parent 1f11ece6
...@@ -76,7 +76,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) { ...@@ -76,7 +76,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
} }
// Die with an error message. // Die with an error message.
func fatal(msg string, args ...) { func fatal(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args) fmt.Fprintf(os.Stderr, msg+"\n", args)
os.Exit(2) os.Exit(2)
} }
...@@ -84,7 +84,7 @@ func fatal(msg string, args ...) { ...@@ -84,7 +84,7 @@ func fatal(msg string, args ...) {
var nerrors int var nerrors int
var noPos token.Position var noPos token.Position
func error(pos token.Position, msg string, args ...) { func error(pos token.Position, msg string, args ...interface{}) {
nerrors++ nerrors++
if pos.IsValid() { if pos.IsValid() {
fmt.Fprintf(os.Stderr, "%s: ", pos) fmt.Fprintf(os.Stderr, "%s: ", pos)
......
...@@ -3097,7 +3097,7 @@ func create(s string, m int) *bufio.Writer { ...@@ -3097,7 +3097,7 @@ func create(s string, m int) *bufio.Writer {
// //
// write out error comment // write out error comment
// //
func error(s string, v ...) { func error(s string, v ...interface{}) {
nerrors++ nerrors++
fmt.Fprintf(stderr, s, v) fmt.Fprintf(stderr, s, v)
fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno) fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno)
......
...@@ -282,7 +282,7 @@ func (t *thread) ptraceDetach() os.Error { ...@@ -282,7 +282,7 @@ func (t *thread) ptraceDetach() os.Error {
var logLock sync.Mutex var logLock sync.Mutex
func (t *thread) logTrace(format string, args ...) { func (t *thread) logTrace(format string, args ...interface{}) {
if !trace { if !trace {
return return
} }
...@@ -301,7 +301,7 @@ func (t *thread) logTrace(format string, args ...) { ...@@ -301,7 +301,7 @@ func (t *thread) logTrace(format string, args ...) {
fmt.Fprint(os.Stderr, "\n") fmt.Fprint(os.Stderr, "\n")
} }
func (t *thread) warn(format string, args ...) { func (t *thread) warn(format string, args ...interface{}) {
logLock.Lock() logLock.Lock()
defer logLock.Unlock() defer logLock.Unlock()
fmt.Fprintf(os.Stderr, "Thread %d: WARNING ", t.tid) fmt.Fprintf(os.Stderr, "Thread %d: WARNING ", t.tid)
...@@ -309,7 +309,7 @@ func (t *thread) warn(format string, args ...) { ...@@ -309,7 +309,7 @@ func (t *thread) warn(format string, args ...) {
fmt.Fprint(os.Stderr, "\n") fmt.Fprint(os.Stderr, "\n")
} }
func (p *process) logTrace(format string, args ...) { func (p *process) logTrace(format string, args ...interface{}) {
if !trace { if !trace {
return return
} }
......
...@@ -27,7 +27,7 @@ type compiler struct { ...@@ -27,7 +27,7 @@ type compiler struct {
silentErrors int 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.errors.Error(pos.Pos(), fmt.Sprintf(format, args))
a.numErrors++ a.numErrors++
} }
......
...@@ -58,7 +58,7 @@ func (a *exprInfo) newExpr(t Type, desc string) *expr { ...@@ -58,7 +58,7 @@ func (a *exprInfo) newExpr(t Type, desc string) *expr {
return &expr{exprInfo: a, t: t, desc: desc} 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) a.diagAt(&a.pos, format, args)
} }
......
...@@ -27,7 +27,7 @@ type stmtCompiler struct { ...@@ -27,7 +27,7 @@ type stmtCompiler struct {
stmtLabel *label stmtLabel *label
} }
func (a *stmtCompiler) diag(format string, args ...) { func (a *stmtCompiler) diag(format string, args ...interface{}) {
a.diagAt(&a.pos, format, args) a.diagAt(&a.pos, format, args)
} }
......
...@@ -91,7 +91,7 @@ func (p *parser) init(filename string, src []byte, mode uint) { ...@@ -91,7 +91,7 @@ func (p *parser) init(filename string, src []byte, mode uint) {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Parsing support // Parsing support
func (p *parser) printTrace(a ...) { func (p *parser) printTrace(a ...interface{}) {
const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " + const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " +
". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
const n = uint(len(dots)) const n = uint(len(dots))
......
This diff is collapsed.
...@@ -93,7 +93,7 @@ func (p *parser) init(filename string, src []byte, scope *ast.Scope, mode uint) ...@@ -93,7 +93,7 @@ func (p *parser) init(filename string, src []byte, scope *ast.Scope, mode uint)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Parsing support // Parsing support
func (p *parser) printTrace(a ...) { func (p *parser) printTrace(a ...interface{}) {
const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " + const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " +
". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
const n = uint(len(dots)) const n = uint(len(dots))
......
...@@ -101,7 +101,7 @@ func (p *printer) init(output io.Writer, cfg *Config) { ...@@ -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 { if debug {
fmt.Print(p.pos.String() + ": ") fmt.Print(p.pos.String() + ": ")
fmt.Println(msg) fmt.Println(msg)
......
...@@ -149,31 +149,33 @@ func (l *Logger) Output(calldepth int, s string) os.Error { ...@@ -149,31 +149,33 @@ func (l *Logger) Output(calldepth int, s string) os.Error {
} }
// Logf is analogous to Printf() for a Logger. // 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. // 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(). // 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). // 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(). // 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). // 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). // 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). // 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(). // 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(). // 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)) }
...@@ -187,14 +187,14 @@ func New(fmap FormatterMap) *Template { ...@@ -187,14 +187,14 @@ func New(fmap FormatterMap) *Template {
} }
// Report error and stop executing. The line number must be provided explicitly. // 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)} st.errors <- &Error{line, fmt.Sprintf(err, args)}
runtime.Goexit() runtime.Goexit()
} }
// Report error, save in Template to terminate parsing. // Report error, save in Template to terminate parsing.
// The line number comes from the template state. // 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)} t.error = &Error{t.linenum, fmt.Sprintf(err, args)}
} }
......
...@@ -89,34 +89,34 @@ func (t *T) FailNow() { ...@@ -89,34 +89,34 @@ func (t *T) FailNow() {
// Log formats its arguments using default formatting, analogous to Print(), // Log formats its arguments using default formatting, analogous to Print(),
// and records the text in the error log. // 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(), // Log formats its arguments according to the format, analogous to Printf(),
// and records the text in the error log. // 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)) t.errors += "\t" + tabify(fmt.Sprintf(format, args))
} }
// Error is equivalent to Log() followed by Fail(). // Error is equivalent to Log() followed by Fail().
func (t *T) Error(args ...) { func (t *T) Error(args ...interface{}) {
t.Log(args) t.Log(args)
t.Fail() t.Fail()
} }
// Errorf is equivalent to Logf() followed by 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.Logf(format, args)
t.Fail() t.Fail()
} }
// Fatal is equivalent to Log() followed by FailNow(). // Fatal is equivalent to Log() followed by FailNow().
func (t *T) Fatal(args ...) { func (t *T) Fatal(args ...interface{}) {
t.Log(args) t.Log(args)
t.FailNow() t.FailNow()
} }
// Fatalf is equivalent to Logf() followed by 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.Logf(format, args)
t.FailNow() t.FailNow()
} }
......
...@@ -92,7 +92,7 @@ func eliminate_digit(d int64) { ...@@ -92,7 +92,7 @@ func eliminate_digit(d int64) {
bignum.Iscale(numer, 10) bignum.Iscale(numer, 10)
} }
func printf(s string, arg ...) { func printf(s string, arg ...interface{}) {
if !*silent { if !*silent {
fmt.Printf(s, arg) fmt.Printf(s, arg)
} }
......
...@@ -10,9 +10,7 @@ import "fmt" ...@@ -10,9 +10,7 @@ import "fmt"
var result string var result string
func addInt(i int) { func addInt(i int) { result += fmt.Sprint(i) }
result += fmt.Sprint(i)
}
func test1helper() { func test1helper() {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
...@@ -21,16 +19,14 @@ func test1helper() { ...@@ -21,16 +19,14 @@ func test1helper() {
} }
func test1() { func test1() {
result = ""; result = ""
test1helper(); test1helper()
if result != "9876543210" { 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 ...) { func addDotDotDot(v ...interface{}) { result += fmt.Sprint(v) }
result += fmt.Sprint(v)
}
func test2helper() { func test2helper() {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
...@@ -39,14 +35,14 @@ func test2helper() { ...@@ -39,14 +35,14 @@ func test2helper() {
} }
func test2() { func test2() {
result = ""; result = ""
test2helper(); test2helper()
if result != "9876543210" { 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() { func main() {
test1(); test1()
test2(); test2()
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment