Commit 9c2e5f29 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile/internal/gc: better names for (b|c|f)conf (cleanup)

Use String and GoString methods instead of the xconf names
for the numeric conversion routines.

Also, fixed a couple of comments in fmt.go.

Change-Id: I1b8acdd95dbff3fc30273070fbb1ac4860031a3c
Reviewed-on: https://go-review.googlesource.com/136197Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 3f99d273
...@@ -476,7 +476,7 @@ func toflt(v Val) Val { ...@@ -476,7 +476,7 @@ func toflt(v Val) Val {
f := newMpflt() f := newMpflt()
f.Set(&u.Real) f.Set(&u.Real)
if u.Imag.CmpFloat64(0) != 0 { if u.Imag.CmpFloat64(0) != 0 {
yyerror("constant %v truncated to real", cconv(u)) yyerror("constant %v truncated to real", u.GoString())
} }
v.U = f v.U = f
} }
...@@ -509,11 +509,11 @@ func toint(v Val) Val { ...@@ -509,11 +509,11 @@ func toint(v Val) Val {
// value from the error message. // value from the error message.
// (See issue #11371). // (See issue #11371).
var t big.Float var t big.Float
t.Parse(fconv(u), 10) t.Parse(u.GoString(), 10)
if t.IsInt() { if t.IsInt() {
yyerror("constant truncated to integer") yyerror("constant truncated to integer")
} else { } else {
yyerror("constant %v truncated to integer", fconv(u)) yyerror("constant %v truncated to integer", u.GoString())
} }
} }
} }
...@@ -522,7 +522,7 @@ func toint(v Val) Val { ...@@ -522,7 +522,7 @@ func toint(v Val) Val {
case *Mpcplx: case *Mpcplx:
i := new(Mpint) i := new(Mpint)
if !i.SetFloat(&u.Real) || u.Imag.CmpFloat64(0) != 0 { if !i.SetFloat(&u.Real) || u.Imag.CmpFloat64(0) != 0 {
yyerror("constant %v truncated to integer", cconv(u)) yyerror("constant %v truncated to integer", u.GoString())
} }
v.U = i v.U = i
......
...@@ -119,7 +119,7 @@ const ( ...@@ -119,7 +119,7 @@ const (
// *types.Type: // *types.Type:
// %#v Go format // %#v Go format
// %#L type definition instead of name // %#L type definition instead of name
// %#S omit"func" and receiver in function signature // %#S omit "func" and receiver in function signature
// //
// %-v type identifiers // %-v type identifiers
// %-S type identifiers without "func" and arg names in type signatures (methodsym) // %-S type identifiers without "func" and arg names in type signatures (methodsym)
...@@ -514,10 +514,10 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) { ...@@ -514,10 +514,10 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) {
case *Mpint: case *Mpint:
if !u.Rune { if !u.Rune {
if flag&FmtSharp != 0 { if flag&FmtSharp != 0 {
fmt.Fprint(s, bconv(u)) fmt.Fprint(s, u.String())
return return
} }
fmt.Fprint(s, u.String()) fmt.Fprint(s, u.GoString())
return return
} }
...@@ -540,23 +540,16 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) { ...@@ -540,23 +540,16 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) {
fmt.Fprint(s, u.String()) fmt.Fprint(s, u.String())
return return
} }
fmt.Fprint(s, fconv(u)) fmt.Fprint(s, u.GoString())
return return
case *Mpcplx: case *Mpcplx:
switch { if flag&FmtSharp != 0 {
case flag&FmtSharp != 0: fmt.Fprint(s, u.String())
fmt.Fprintf(s, "(%v+%vi)", &u.Real, &u.Imag) return
case v.U.(*Mpcplx).Real.CmpFloat64(0) == 0:
fmt.Fprintf(s, "%vi", fconv(&u.Imag))
case v.U.(*Mpcplx).Imag.CmpFloat64(0) == 0:
fmt.Fprint(s, fconv(&u.Real))
default:
fmt.Fprintf(s, "(%v)", cconv(u))
} }
fmt.Fprint(s, u.GoString())
return
case string: case string:
fmt.Fprint(s, strconv.Quote(u)) fmt.Fprint(s, strconv.Quote(u))
...@@ -668,7 +661,7 @@ func typefmt(t *types.Type, flag FmtFlag, mode fmtMode, depth int) string { ...@@ -668,7 +661,7 @@ func typefmt(t *types.Type, flag FmtFlag, mode fmtMode, depth int) string {
return "error" return "error"
} }
// Unless the 'l' flag was specified, if the type has a name, just print that name. // Unless the 'L' flag was specified, if the type has a name, just print that name.
if flag&FmtLong == 0 && t.Sym != nil && t != types.Types[t.Etype] { if flag&FmtLong == 0 && t.Sym != nil && t != types.Types[t.Etype] {
switch mode { switch mode {
case FTypeId, FTypeIdName: case FTypeId, FTypeIdName:
...@@ -1529,9 +1522,8 @@ func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) { ...@@ -1529,9 +1522,8 @@ func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) {
func (n *Node) nodefmt(s fmt.State, flag FmtFlag, mode fmtMode) { func (n *Node) nodefmt(s fmt.State, flag FmtFlag, mode fmtMode) {
t := n.Type t := n.Type
// We almost always want the original, except in export mode for literals. // We almost always want the original.
// This saves the importer some work, and avoids us having to redo some // TODO(gri) Why the special case for OLITERAL?
// special casing for package unsafe.
if n.Op != OLITERAL && n.Orig != nil { if n.Op != OLITERAL && n.Orig != nil {
n = n.Orig n = n.Orig
} }
......
...@@ -204,7 +204,7 @@ func (f *Mpflt) String() string { ...@@ -204,7 +204,7 @@ func (f *Mpflt) String() string {
return f.Val.Text('b', 0) return f.Val.Text('b', 0)
} }
func fconv(fvp *Mpflt) string { func (fvp *Mpflt) GoString() string {
// determine sign // determine sign
sign := "" sign := ""
f := &fvp.Val f := &fvp.Val
...@@ -327,11 +327,33 @@ func (v *Mpcplx) Div(rv *Mpcplx) bool { ...@@ -327,11 +327,33 @@ func (v *Mpcplx) Div(rv *Mpcplx) bool {
return true return true
} }
func cconv(v *Mpcplx) string { func (v *Mpcplx) String() string {
re := fconv(&v.Real) return fmt.Sprintf("(%s+%si)", v.Real.String(), v.Imag.String())
im := fconv(&v.Imag) }
if im[0] == '-' {
return re + im + "i" func (v *Mpcplx) GoString() string {
var re string
sre := v.Real.CmpFloat64(0)
if sre != 0 {
re = v.Real.GoString()
}
var im string
sim := v.Imag.CmpFloat64(0)
if sim != 0 {
im = v.Imag.GoString()
}
switch {
case sre == 0 && sim == 0:
return "0"
case sre == 0:
return im + "i"
case sim == 0:
return re
case sim < 0:
return fmt.Sprintf("(%s%si)", re, im)
default:
return fmt.Sprintf("(%s+%si)", re, im)
} }
return re + "+" + im + "i"
} }
...@@ -299,10 +299,10 @@ func (a *Mpint) SetString(as string) { ...@@ -299,10 +299,10 @@ func (a *Mpint) SetString(as string) {
} }
} }
func (a *Mpint) String() string { func (a *Mpint) GoString() string {
return a.Val.String() return a.Val.String()
} }
func bconv(a *Mpint) string { func (a *Mpint) String() string {
return fmt.Sprintf("%#x", &a.Val) return fmt.Sprintf("%#x", &a.Val)
} }
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