Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
d2fc5d68
Commit
d2fc5d68
authored
Feb 02, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change type of Printf's args to ... interface{}
R=rsc CC=golang-dev
https://golang.org/cl/197043
parent
1f11ece6
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
248 additions
and
141 deletions
+248
-141
src/cmd/cgo/util.go
src/cmd/cgo/util.go
+2
-2
src/cmd/goyacc/goyacc.go
src/cmd/goyacc/goyacc.go
+1
-1
src/pkg/debug/proc/proc_linux.go
src/pkg/debug/proc/proc_linux.go
+3
-3
src/pkg/exp/eval/compiler.go
src/pkg/exp/eval/compiler.go
+1
-1
src/pkg/exp/eval/expr.go
src/pkg/exp/eval/expr.go
+1
-1
src/pkg/exp/eval/stmt.go
src/pkg/exp/eval/stmt.go
+1
-1
src/pkg/exp/parser/parser.go
src/pkg/exp/parser/parser.go
+1
-1
src/pkg/fmt/print.go
src/pkg/fmt/print.go
+205
-96
src/pkg/go/parser/parser.go
src/pkg/go/parser/parser.go
+1
-1
src/pkg/go/printer/printer.go
src/pkg/go/printer/printer.go
+1
-1
src/pkg/log/log.go
src/pkg/log/log.go
+12
-10
src/pkg/template/template.go
src/pkg/template/template.go
+2
-2
src/pkg/testing/testing.go
src/pkg/testing/testing.go
+6
-6
test/bench/pidigits.go
test/bench/pidigits.go
+1
-1
test/defer.go
test/defer.go
+10
-14
No files found.
src/cmd/cgo/util.go
View file @
d2fc5d68
...
@@ -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
)
...
...
src/cmd/goyacc/goyacc.go
View file @
d2fc5d68
...
@@ -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
)
...
...
src/pkg/debug/proc/proc_linux.go
View file @
d2fc5d68
...
@@ -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
}
}
...
...
src/pkg/exp/eval/compiler.go
View file @
d2fc5d68
...
@@ -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
++
}
}
...
...
src/pkg/exp/eval/expr.go
View file @
d2fc5d68
...
@@ -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
)
}
}
...
...
src/pkg/exp/eval/stmt.go
View file @
d2fc5d68
...
@@ -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
)
}
}
...
...
src/pkg/exp/parser/parser.go
View file @
d2fc5d68
...
@@ -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
))
...
...
src/pkg/fmt/print.go
View file @
d2fc5d68
...
@@ -212,26 +212,24 @@ func (p *pp) Write(b []byte) (ret int, err os.Error) {
...
@@ -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.
// These routines end in 'f' and take a format string.
// Fprintf formats according to a format specifier and writes to w.
// Fprintf formats according to a format specifier and writes to w.
func
Fprintf
(
w
io
.
Writer
,
format
string
,
a
...
)
(
n
int
,
error
os
.
Error
)
{
func
Fprintf
(
w
io
.
Writer
,
format
string
,
a
...
interface
{})
(
n
int
,
error
os
.
Error
)
{
v
:=
reflect
.
NewValue
(
a
)
.
(
*
reflect
.
StructValue
)
p
:=
newPrinter
()
p
:=
newPrinter
()
p
.
doprintf
(
format
,
v
)
p
.
doprintf
(
format
,
a
)
n64
,
error
:=
p
.
buf
.
WriteTo
(
w
)
n64
,
error
:=
p
.
buf
.
WriteTo
(
w
)
p
.
free
()
p
.
free
()
return
int
(
n64
),
error
return
int
(
n64
),
error
}
}
// Printf formats according to a format specifier and writes to standard output.
// Printf formats according to a format specifier and writes to standard output.
func
Printf
(
format
string
,
v
...
)
(
n
int
,
errno
os
.
Error
)
{
func
Printf
(
format
string
,
a
...
interface
{}
)
(
n
int
,
errno
os
.
Error
)
{
n
,
errno
=
Fprintf
(
os
.
Stdout
,
format
,
v
)
n
,
errno
=
Fprintf
(
os
.
Stdout
,
format
,
a
)
return
n
,
errno
return
n
,
errno
}
}
// Sprintf formats according to a format specifier and returns the resulting string.
// Sprintf formats according to a format specifier and returns the resulting string.
func
Sprintf
(
format
string
,
a
...
)
string
{
func
Sprintf
(
format
string
,
a
...
interface
{})
string
{
v
:=
reflect
.
NewValue
(
a
)
.
(
*
reflect
.
StructValue
)
p
:=
newPrinter
()
p
:=
newPrinter
()
p
.
doprintf
(
format
,
v
)
p
.
doprintf
(
format
,
a
)
s
:=
p
.
buf
.
String
()
s
:=
p
.
buf
.
String
()
p
.
free
()
p
.
free
()
return
s
return
s
...
@@ -241,10 +239,9 @@ func Sprintf(format string, a ...) string {
...
@@ -241,10 +239,9 @@ func Sprintf(format string, a ...) string {
// Fprint formats using the default formats for its operands and writes to w.
// Fprint formats using the default formats for its operands and writes to w.
// Spaces are added between operands when neither is a string.
// Spaces are added between operands when neither is a string.
func
Fprint
(
w
io
.
Writer
,
a
...
)
(
n
int
,
error
os
.
Error
)
{
func
Fprint
(
w
io
.
Writer
,
a
...
interface
{})
(
n
int
,
error
os
.
Error
)
{
v
:=
reflect
.
NewValue
(
a
)
.
(
*
reflect
.
StructValue
)
p
:=
newPrinter
()
p
:=
newPrinter
()
p
.
doprint
(
v
,
false
,
false
)
p
.
doprint
(
a
,
false
,
false
)
n64
,
error
:=
p
.
buf
.
WriteTo
(
w
)
n64
,
error
:=
p
.
buf
.
WriteTo
(
w
)
p
.
free
()
p
.
free
()
return
int
(
n64
),
error
return
int
(
n64
),
error
...
@@ -252,17 +249,16 @@ func Fprint(w io.Writer, a ...) (n int, error os.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.
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// Spaces are added between operands when neither is a string.
func
Print
(
v
...
)
(
n
int
,
errno
os
.
Error
)
{
func
Print
(
a
...
interface
{}
)
(
n
int
,
errno
os
.
Error
)
{
n
,
errno
=
Fprint
(
os
.
Stdout
,
v
)
n
,
errno
=
Fprint
(
os
.
Stdout
,
a
)
return
n
,
errno
return
n
,
errno
}
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
// Spaces are added between operands when neither is a string.
func
Sprint
(
a
...
)
string
{
func
Sprint
(
a
...
interface
{})
string
{
v
:=
reflect
.
NewValue
(
a
)
.
(
*
reflect
.
StructValue
)
p
:=
newPrinter
()
p
:=
newPrinter
()
p
.
doprint
(
v
,
false
,
false
)
p
.
doprint
(
a
,
false
,
false
)
s
:=
p
.
buf
.
String
()
s
:=
p
.
buf
.
String
()
p
.
free
()
p
.
free
()
return
s
return
s
...
@@ -274,10 +270,9 @@ func Sprint(a ...) string {
...
@@ -274,10 +270,9 @@ func Sprint(a ...) string {
// Fprintln formats using the default formats for its operands and writes to w.
// Fprintln formats using the default formats for its operands and writes to w.
// Spaces are always added between operands and a newline is appended.
// Spaces are always added between operands and a newline is appended.
func
Fprintln
(
w
io
.
Writer
,
a
...
)
(
n
int
,
error
os
.
Error
)
{
func
Fprintln
(
w
io
.
Writer
,
a
...
interface
{})
(
n
int
,
error
os
.
Error
)
{
v
:=
reflect
.
NewValue
(
a
)
.
(
*
reflect
.
StructValue
)
p
:=
newPrinter
()
p
:=
newPrinter
()
p
.
doprint
(
v
,
true
,
true
)
p
.
doprint
(
a
,
true
,
true
)
n64
,
error
:=
p
.
buf
.
WriteTo
(
w
)
n64
,
error
:=
p
.
buf
.
WriteTo
(
w
)
p
.
free
()
p
.
free
()
return
int
(
n64
),
error
return
int
(
n64
),
error
...
@@ -285,17 +280,16 @@ func Fprintln(w io.Writer, a ...) (n int, error os.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.
// 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.
// Spaces are always added between operands and a newline is appended.
func
Println
(
v
...
)
(
n
int
,
errno
os
.
Error
)
{
func
Println
(
a
...
interface
{}
)
(
n
int
,
errno
os
.
Error
)
{
n
,
errno
=
Fprintln
(
os
.
Stdout
,
v
)
n
,
errno
=
Fprintln
(
os
.
Stdout
,
a
)
return
n
,
errno
return
n
,
errno
}
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// 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.
// Spaces are always added between operands and a newline is appended.
func
Sprintln
(
a
...
)
string
{
func
Sprintln
(
a
...
interface
{})
string
{
v
:=
reflect
.
NewValue
(
a
)
.
(
*
reflect
.
StructValue
)
p
:=
newPrinter
()
p
:=
newPrinter
()
p
.
doprint
(
v
,
true
,
true
)
p
.
doprint
(
a
,
true
,
true
)
s
:=
p
.
buf
.
String
()
s
:=
p
.
buf
.
String
()
p
.
free
()
p
.
free
()
return
s
return
s
...
@@ -317,44 +311,84 @@ func getField(v *reflect.StructValue, i int) reflect.Value {
...
@@ -317,44 +311,84 @@ func getField(v *reflect.StructValue, i int) reflect.Value {
// Getters for the fields of the argument structure.
// Getters for the fields of the argument structure.
func
getBool
(
v
reflect
.
Value
)
(
val
bool
,
ok
bool
)
{
func
getBool
(
a
interface
{})
(
val
bool
,
ok
bool
)
{
if
b
,
ok
:=
v
.
(
*
reflect
.
BoolValue
);
ok
{
// 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
b
.
Get
(),
true
}
}
return
return
}
}
func
getInt
(
v
reflect
.
Value
)
(
val
int64
,
signed
,
ok
bool
)
{
func
getInt
(
a
interface
{})
(
val
int64
,
signed
,
ok
bool
)
{
switch
v
:=
v
.
(
type
)
{
// 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
:
case
*
reflect
.
IntValue
:
return
int64
(
v
.
Get
()),
true
,
true
return
int64
(
i
.
Get
()),
true
,
true
case
*
reflect
.
Int8Value
:
case
*
reflect
.
Int8Value
:
return
int64
(
v
.
Get
()),
true
,
true
return
int64
(
i
.
Get
()),
true
,
true
case
*
reflect
.
Int16Value
:
case
*
reflect
.
Int16Value
:
return
int64
(
v
.
Get
()),
true
,
true
return
int64
(
i
.
Get
()),
true
,
true
case
*
reflect
.
Int32Value
:
case
*
reflect
.
Int32Value
:
return
int64
(
v
.
Get
()),
true
,
true
return
int64
(
i
.
Get
()),
true
,
true
case
*
reflect
.
Int64Value
:
case
*
reflect
.
Int64Value
:
return
i
nt64
(
v
.
Get
()
),
true
,
true
return
i
.
Get
(
),
true
,
true
case
*
reflect
.
UintValue
:
case
*
reflect
.
UintValue
:
return
int64
(
v
.
Get
()),
false
,
true
return
int64
(
i
.
Get
()),
false
,
true
case
*
reflect
.
Uint8Value
:
case
*
reflect
.
Uint8Value
:
return
int64
(
v
.
Get
()),
false
,
true
return
int64
(
i
.
Get
()),
false
,
true
case
*
reflect
.
Uint16Value
:
case
*
reflect
.
Uint16Value
:
return
int64
(
v
.
Get
()),
false
,
true
return
int64
(
i
.
Get
()),
false
,
true
case
*
reflect
.
Uint32Value
:
case
*
reflect
.
Uint32Value
:
return
int64
(
v
.
Get
()),
false
,
true
return
int64
(
i
.
Get
()),
false
,
true
case
*
reflect
.
Uint64Value
:
case
*
reflect
.
Uint64Value
:
return
int64
(
v
.
Get
()),
false
,
true
return
int64
(
i
.
Get
()),
false
,
true
case
*
reflect
.
UintptrValue
:
case
*
reflect
.
UintptrValue
:
return
int64
(
v
.
Get
()),
false
,
true
return
int64
(
i
.
Get
()),
false
,
true
}
}
return
return
}
}
func
getString
(
v
reflect
.
Value
)
(
val
string
,
ok
bool
)
{
func
getString
(
a
interface
{})
(
val
string
,
ok
bool
)
{
if
v
,
ok
:=
v
.
(
*
reflect
.
StringValue
);
ok
{
// Is it a regular string or []byte type?
return
v
.
Get
(),
true
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
{
if
bytes
,
ok
:=
v
.
Interface
()
.
([]
byte
);
ok
{
return
string
(
bytes
),
true
return
string
(
bytes
),
true
...
@@ -362,26 +396,48 @@ func getString(v reflect.Value) (val string, ok bool) {
...
@@ -362,26 +396,48 @@ func getString(v reflect.Value) (val string, ok bool) {
return
return
}
}
func
getFloat32
(
v
reflect
.
Value
)
(
val
float32
,
ok
bool
)
{
var
floatBits
=
reflect
.
Typeof
(
float
(
0
))
.
Size
()
*
8
switch
v
:=
v
.
(
type
)
{
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
:
case
*
reflect
.
Float32Value
:
return
float32
(
v
.
Get
()),
true
return
float32
(
f
.
Get
()),
true
case
*
reflect
.
FloatValue
:
case
*
reflect
.
FloatValue
:
if
v
.
Type
()
.
Size
()
*
8
==
32
{
if
floatBits
==
32
{
return
float32
(
v
.
Get
()),
true
return
float32
(
f
.
Get
()),
true
}
}
}
}
return
return
}
}
func
getFloat64
(
v
reflect
.
Value
)
(
val
float64
,
ok
bool
)
{
func
getFloat64
(
a
interface
{})
(
val
float64
,
ok
bool
)
{
switch
v
:=
v
.
(
type
)
{
// Is it a regular floating-point type?
case
*
reflect
.
FloatValue
:
switch
f
:=
a
.
(
type
)
{
if
v
.
Type
()
.
Size
()
*
8
==
64
{
case
float64
:
return
float64
(
v
.
Get
()),
true
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
:
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
return
}
}
...
@@ -406,24 +462,80 @@ type uintptrGetter interface {
...
@@ -406,24 +462,80 @@ type uintptrGetter interface {
Get
()
uintptr
Get
()
uintptr
}
}
func
(
p
*
pp
)
printField
(
field
reflect
.
Value
,
plus
,
sharp
bool
,
depth
int
)
(
was_string
bool
)
{
func
(
p
*
pp
)
unknownType
(
v
interface
{})
{
inter
:=
field
.
Interface
()
if
v
==
nil
{
if
inter
!=
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
{
switch
{
default
:
default
:
if
stringer
,
ok
:=
inter
.
(
Stringer
);
ok
{
if
stringer
,
ok
:=
field
.
(
Stringer
);
ok
{
p
.
buf
.
WriteString
(
stringer
.
String
())
p
.
buf
.
WriteString
(
stringer
.
String
())
return
false
// this value is not a string
return
false
// this value is not a string
}
}
case
sharp
:
case
sharp
:
if
stringer
,
ok
:=
inter
.
(
GoStringer
);
ok
{
if
stringer
,
ok
:=
field
.
(
GoStringer
);
ok
{
p
.
buf
.
WriteString
(
stringer
.
GoString
())
p
.
buf
.
WriteString
(
stringer
.
GoString
())
return
false
// this value is not a string
return
false
// this value is not a string
}
}
}
}
}
}
BigSwitch
:
// Some types can be done without reflection.
switch
f
:=
field
.
(
type
)
{
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
:
case
*
reflect
.
BoolValue
:
p
.
fmt
.
fmt_boolean
(
f
.
Get
())
p
.
fmt
.
fmt_boolean
(
f
.
Get
())
case
*
reflect
.
Float32Value
:
case
*
reflect
.
Float32Value
:
...
@@ -431,7 +543,7 @@ BigSwitch:
...
@@ -431,7 +543,7 @@ BigSwitch:
case
*
reflect
.
Float64Value
:
case
*
reflect
.
Float64Value
:
p
.
fmt
.
fmt_g64
(
f
.
Get
())
p
.
fmt
.
fmt_g64
(
f
.
Get
())
case
*
reflect
.
FloatValue
:
case
*
reflect
.
FloatValue
:
if
f
ield
.
Type
()
.
Size
()
*
8
==
32
{
if
f
loatBits
==
32
{
p
.
fmt
.
fmt_g32
(
float32
(
f
.
Get
()))
p
.
fmt
.
fmt_g32
(
float32
(
f
.
Get
()))
}
else
{
}
else
{
p
.
fmt
.
fmt_g64
(
float64
(
f
.
Get
()))
p
.
fmt
.
fmt_g64
(
float64
(
f
.
Get
()))
...
@@ -445,7 +557,7 @@ BigSwitch:
...
@@ -445,7 +557,7 @@ BigSwitch:
}
}
case
*
reflect
.
MapValue
:
case
*
reflect
.
MapValue
:
if
sharp
{
if
sharp
{
p
.
buf
.
WriteString
(
f
ield
.
Type
()
.
String
())
p
.
buf
.
WriteString
(
f
.
Type
()
.
String
())
p
.
buf
.
WriteByte
(
'{'
)
p
.
buf
.
WriteByte
(
'{'
)
}
else
{
}
else
{
p
.
buf
.
Write
(
mapBytes
)
p
.
buf
.
Write
(
mapBytes
)
...
@@ -459,9 +571,9 @@ BigSwitch:
...
@@ -459,9 +571,9 @@ BigSwitch:
p
.
buf
.
WriteByte
(
' '
)
p
.
buf
.
WriteByte
(
' '
)
}
}
}
}
p
.
printField
(
key
,
plus
,
sharp
,
depth
+
1
)
p
.
printField
(
key
.
Interface
()
,
plus
,
sharp
,
depth
+
1
)
p
.
buf
.
WriteByte
(
':'
)
p
.
buf
.
WriteByte
(
':'
)
p
.
printField
(
f
.
Elem
(
key
),
plus
,
sharp
,
depth
+
1
)
p
.
printField
(
f
.
Elem
(
key
)
.
Interface
()
,
plus
,
sharp
,
depth
+
1
)
}
}
if
sharp
{
if
sharp
{
p
.
buf
.
WriteByte
(
'}'
)
p
.
buf
.
WriteByte
(
'}'
)
...
@@ -470,7 +582,7 @@ BigSwitch:
...
@@ -470,7 +582,7 @@ BigSwitch:
}
}
case
*
reflect
.
StructValue
:
case
*
reflect
.
StructValue
:
if
sharp
{
if
sharp
{
p
.
buf
.
WriteString
(
field
.
Type
(
)
.
String
())
p
.
buf
.
WriteString
(
reflect
.
Typeof
(
field
)
.
String
())
}
}
p
.
add
(
'{'
)
p
.
add
(
'{'
)
v
:=
f
v
:=
f
...
@@ -490,24 +602,24 @@ BigSwitch:
...
@@ -490,24 +602,24 @@ BigSwitch:
p
.
buf
.
WriteByte
(
':'
)
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
(
'}'
)
p
.
buf
.
WriteByte
(
'}'
)
case
*
reflect
.
InterfaceValue
:
case
*
reflect
.
InterfaceValue
:
value
:=
f
.
Elem
()
value
:=
f
.
Elem
()
if
value
==
nil
{
if
value
==
nil
{
if
sharp
{
if
sharp
{
p
.
buf
.
WriteString
(
field
.
Type
(
)
.
String
())
p
.
buf
.
WriteString
(
reflect
.
Typeof
(
field
)
.
String
())
p
.
buf
.
Write
(
nilParenBytes
)
p
.
buf
.
Write
(
nilParenBytes
)
}
else
{
}
else
{
p
.
buf
.
Write
(
nilAngleBytes
)
p
.
buf
.
Write
(
nilAngleBytes
)
}
}
}
else
{
}
else
{
return
p
.
printField
(
value
,
plus
,
sharp
,
depth
+
1
)
return
p
.
printField
(
value
.
Interface
()
,
plus
,
sharp
,
depth
+
1
)
}
}
case
reflect
.
ArrayOrSliceValue
:
case
reflect
.
ArrayOrSliceValue
:
if
sharp
{
if
sharp
{
p
.
buf
.
WriteString
(
field
.
Type
(
)
.
String
())
p
.
buf
.
WriteString
(
reflect
.
Typeof
(
field
)
.
String
())
p
.
buf
.
WriteByte
(
'{'
)
p
.
buf
.
WriteByte
(
'{'
)
}
else
{
}
else
{
p
.
buf
.
WriteByte
(
'['
)
p
.
buf
.
WriteByte
(
'['
)
...
@@ -520,7 +632,7 @@ BigSwitch:
...
@@ -520,7 +632,7 @@ BigSwitch:
p
.
buf
.
WriteByte
(
' '
)
p
.
buf
.
WriteByte
(
' '
)
}
}
}
}
p
.
printField
(
f
.
Elem
(
i
),
plus
,
sharp
,
depth
+
1
)
p
.
printField
(
f
.
Elem
(
i
)
.
Interface
()
,
plus
,
sharp
,
depth
+
1
)
}
}
if
sharp
{
if
sharp
{
p
.
buf
.
WriteByte
(
'}'
)
p
.
buf
.
WriteByte
(
'}'
)
...
@@ -535,17 +647,17 @@ BigSwitch:
...
@@ -535,17 +647,17 @@ BigSwitch:
switch
a
:=
f
.
Elem
()
.
(
type
)
{
switch
a
:=
f
.
Elem
()
.
(
type
)
{
case
reflect
.
ArrayOrSliceValue
:
case
reflect
.
ArrayOrSliceValue
:
p
.
buf
.
WriteByte
(
'&'
)
p
.
buf
.
WriteByte
(
'&'
)
p
.
printField
(
a
,
plus
,
sharp
,
depth
+
1
)
p
.
printField
(
a
.
Interface
()
,
plus
,
sharp
,
depth
+
1
)
break
BigSwitch
break
BigSwitch
case
*
reflect
.
StructValue
:
case
*
reflect
.
StructValue
:
p
.
buf
.
WriteByte
(
'&'
)
p
.
buf
.
WriteByte
(
'&'
)
p
.
printField
(
a
,
plus
,
sharp
,
depth
+
1
)
p
.
printField
(
a
.
Interface
()
,
plus
,
sharp
,
depth
+
1
)
break
BigSwitch
break
BigSwitch
}
}
}
}
if
sharp
{
if
sharp
{
p
.
buf
.
WriteByte
(
'('
)
p
.
buf
.
WriteByte
(
'('
)
p
.
buf
.
WriteString
(
field
.
Type
(
)
.
String
())
p
.
buf
.
WriteString
(
reflect
.
Typeof
(
field
)
.
String
())
p
.
buf
.
WriteByte
(
')'
)
p
.
buf
.
WriteByte
(
')'
)
p
.
buf
.
WriteByte
(
'('
)
p
.
buf
.
WriteByte
(
'('
)
if
v
==
0
{
if
v
==
0
{
...
@@ -567,7 +679,7 @@ BigSwitch:
...
@@ -567,7 +679,7 @@ BigSwitch:
v
:=
f
.
Get
()
v
:=
f
.
Get
()
if
sharp
{
if
sharp
{
p
.
buf
.
WriteByte
(
'('
)
p
.
buf
.
WriteByte
(
'('
)
p
.
buf
.
WriteString
(
field
.
Type
(
)
.
String
())
p
.
buf
.
WriteString
(
reflect
.
Typeof
(
field
)
.
String
())
p
.
buf
.
WriteByte
(
')'
)
p
.
buf
.
WriteByte
(
')'
)
p
.
buf
.
WriteByte
(
'('
)
p
.
buf
.
WriteByte
(
'('
)
if
v
==
0
{
if
v
==
0
{
...
@@ -596,14 +708,12 @@ BigSwitch:
...
@@ -596,14 +708,12 @@ BigSwitch:
}
}
break
break
}
}
p
.
buf
.
WriteByte
(
'?'
)
p
.
unknownType
(
f
)
p
.
buf
.
WriteString
(
field
.
Type
()
.
String
())
p
.
buf
.
WriteByte
(
'?'
)
}
}
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
end
:=
len
(
format
)
-
1
fieldnum
:=
0
// we process one field per non-trivial format
fieldnum
:=
0
// we process one field per non-trivial format
for
i
:=
0
;
i
<=
end
;
{
for
i
:=
0
;
i
<=
end
;
{
...
@@ -649,20 +759,19 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
...
@@ -649,20 +759,19 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
p
.
buf
.
WriteByte
(
'%'
)
// TODO: should we bother with width & prec?
p
.
buf
.
WriteByte
(
'%'
)
// TODO: should we bother with width & prec?
continue
continue
}
}
if
fieldnum
>=
v
.
NumField
(
)
{
// out of operands
if
fieldnum
>=
len
(
a
)
{
// out of operands
p
.
buf
.
WriteByte
(
'%'
)
p
.
buf
.
WriteByte
(
'%'
)
p
.
add
(
c
)
p
.
add
(
c
)
p
.
buf
.
Write
(
missingBytes
)
p
.
buf
.
Write
(
missingBytes
)
continue
continue
}
}
field
:=
getField
(
v
,
fieldnum
)
field
:=
a
[
fieldnum
]
fieldnum
++
fieldnum
++
// Try formatter except for %T,
// Try formatter except for %T,
// which is special and handled internally.
// which is special and handled internally.
inter
:=
field
.
Interface
()
if
field
!=
nil
&&
c
!=
'T'
{
if
inter
!=
nil
&&
c
!=
'T'
{
if
formatter
,
ok
:=
field
.
(
Formatter
);
ok
{
if
formatter
,
ok
:=
inter
.
(
Formatter
);
ok
{
formatter
.
Format
(
p
,
c
)
formatter
.
Format
(
p
,
c
)
continue
continue
}
}
...
@@ -787,9 +896,9 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
...
@@ -787,9 +896,9 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
// string
// string
case
's'
:
case
's'
:
if
inter
!=
nil
{
if
field
!=
nil
{
// if object implements String, use the result.
// 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
())
p
.
fmt
.
fmt_s
(
stringer
.
String
())
break
break
}
}
...
@@ -808,7 +917,7 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
...
@@ -808,7 +917,7 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
// pointer, including addresses of reference types.
// pointer, including addresses of reference types.
case
'p'
:
case
'p'
:
switch
v
:=
field
.
(
type
)
{
switch
v
:=
reflect
.
NewValue
(
field
)
.
(
type
)
{
case
getter
:
case
getter
:
p
.
fmt
.
fmt_s
(
"0x"
)
p
.
fmt
.
fmt_s
(
"0x"
)
p
.
fmt
.
fmt_uX64
(
uint64
(
v
.
Get
()))
p
.
fmt
.
fmt_uX64
(
uint64
(
v
.
Get
()))
...
@@ -825,27 +934,27 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
...
@@ -825,27 +934,27 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
// the value's type
// the value's type
case
'T'
:
case
'T'
:
p
.
buf
.
WriteString
(
field
.
Type
(
)
.
String
())
p
.
buf
.
WriteString
(
reflect
.
Typeof
(
field
)
.
String
())
default
:
default
:
badtype
:
badtype
:
p
.
buf
.
WriteByte
(
'%'
)
p
.
buf
.
WriteByte
(
'%'
)
p
.
add
(
c
)
p
.
add
(
c
)
p
.
buf
.
WriteByte
(
'('
)
p
.
buf
.
WriteByte
(
'('
)
p
.
buf
.
WriteString
(
field
.
Type
(
)
.
String
())
p
.
buf
.
WriteString
(
reflect
.
Typeof
(
field
)
.
String
())
p
.
buf
.
WriteByte
(
'='
)
p
.
buf
.
WriteByte
(
'='
)
p
.
printField
(
field
,
false
,
false
,
0
)
p
.
printField
(
field
,
false
,
false
,
0
)
p
.
buf
.
WriteByte
(
')'
)
p
.
buf
.
WriteByte
(
')'
)
}
}
}
}
if
fieldnum
<
v
.
NumField
(
)
{
if
fieldnum
<
len
(
a
)
{
p
.
buf
.
Write
(
extraBytes
)
p
.
buf
.
Write
(
extraBytes
)
for
;
fieldnum
<
v
.
NumField
(
);
fieldnum
++
{
for
;
fieldnum
<
len
(
a
);
fieldnum
++
{
field
:=
getField
(
v
,
fieldnum
)
field
:=
a
[
fieldnum
]
p
.
buf
.
WriteString
(
field
.
Type
(
)
.
String
())
p
.
buf
.
WriteString
(
reflect
.
Typeof
(
field
)
.
String
())
p
.
buf
.
WriteByte
(
'='
)
p
.
buf
.
WriteByte
(
'='
)
p
.
printField
(
field
,
false
,
false
,
0
)
p
.
printField
(
field
,
false
,
false
,
0
)
if
fieldnum
+
1
<
v
.
NumField
(
)
{
if
fieldnum
+
1
<
len
(
a
)
{
p
.
buf
.
Write
(
commaSpaceBytes
)
p
.
buf
.
Write
(
commaSpaceBytes
)
}
}
}
}
...
@@ -853,11 +962,11 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
...
@@ -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
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
// always add spaces if we're doing println
field
:=
getField
(
v
,
fieldnum
)
field
:=
a
[
fieldnum
]
if
fieldnum
>
0
{
if
fieldnum
>
0
{
_
,
is_string
:=
field
.
(
*
reflect
.
StringValue
)
_
,
is_string
:=
field
.
(
*
reflect
.
StringValue
)
if
addspace
||
!
is_string
&&
!
prev_string
{
if
addspace
||
!
is_string
&&
!
prev_string
{
...
...
src/pkg/go/parser/parser.go
View file @
d2fc5d68
...
@@ -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
))
...
...
src/pkg/go/printer/printer.go
View file @
d2fc5d68
...
@@ -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
)
...
...
src/pkg/log/log.go
View file @
d2fc5d68
...
@@ -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
))
}
src/pkg/template/template.go
View file @
d2fc5d68
...
@@ -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
)}
}
}
...
...
src/pkg/testing/testing.go
View file @
d2fc5d68
...
@@ -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
()
}
}
...
...
test/bench/pidigits.go
View file @
d2fc5d68
...
@@ -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
)
}
}
...
...
test/defer.go
View file @
d2fc5d68
...
@@ -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
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment