Commit 5f55011a authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/internal/gc, cmd/internal/obj: clean up string returns

An artifact of the c2go translation was
a handful of instances of code like:

var s string
s += "foo"
return s

This CL converts those to simply 'return "foo"'.

The conversion was done mechanically with the
quick-and-dirty cleanup script at
https://gist.github.com/josharian/1fa4408044c163983e62.

I then manually moved a couple of comments in fmt.go.

toolstash -cmp thinks that there are no functional changes.

Change-Id: Ic0ebdd10f0fb8de0360a1041ce5cd10ae1168be9
Reviewed-on: https://go-review.googlesource.com/6265Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c2025c41
...@@ -170,21 +170,15 @@ var goopnames = []string{ ...@@ -170,21 +170,15 @@ var goopnames = []string{
func Oconv(o int, flag int) string { func Oconv(o int, flag int) string {
if (flag&obj.FmtSharp != 0 /*untyped*/) || fmtmode != FDbg { if (flag&obj.FmtSharp != 0 /*untyped*/) || fmtmode != FDbg {
if o >= 0 && o < len(goopnames) && goopnames[o] != "" { if o >= 0 && o < len(goopnames) && goopnames[o] != "" {
var fp string return goopnames[o]
fp += goopnames[o]
return fp
} }
} }
if o >= 0 && o < len(opnames) && opnames[o] != "" { if o >= 0 && o < len(opnames) && opnames[o] != "" {
var fp string return opnames[o]
fp += opnames[o]
return fp
} }
var fp string return fmt.Sprintf("O-%d", o)
fp += fmt.Sprintf("O-%d", o)
return fp
} }
var classnames = []string{ var classnames = []string{
...@@ -308,9 +302,7 @@ func Vconv(v *Val, flag int) string { ...@@ -308,9 +302,7 @@ func Vconv(v *Val, flag int) string {
switch v.Ctype { switch v.Ctype {
case CTINT: case CTINT:
if (flag&obj.FmtSharp != 0 /*untyped*/) || fmtmode == FExp { if (flag&obj.FmtSharp != 0 /*untyped*/) || fmtmode == FExp {
var fp string return fmt.Sprintf("%v", Bconv(v.U.Xval, obj.FmtSharp))
fp += fmt.Sprintf("%v", Bconv(v.U.Xval, obj.FmtSharp))
return fp
} }
var fp string var fp string
fp += fmt.Sprintf("%v", Bconv(v.U.Xval, 0)) fp += fmt.Sprintf("%v", Bconv(v.U.Xval, 0))
...@@ -319,19 +311,13 @@ func Vconv(v *Val, flag int) string { ...@@ -319,19 +311,13 @@ func Vconv(v *Val, flag int) string {
case CTRUNE: case CTRUNE:
x := Mpgetfix(v.U.Xval) x := Mpgetfix(v.U.Xval)
if ' ' <= x && x < 0x80 && x != '\\' && x != '\'' { if ' ' <= x && x < 0x80 && x != '\\' && x != '\'' {
var fp string return fmt.Sprintf("'%c'", int(x))
fp += fmt.Sprintf("'%c'", int(x))
return fp
} }
if 0 <= x && x < 1<<16 { if 0 <= x && x < 1<<16 {
var fp string return fmt.Sprintf("'\\u%04x'", uint(int(x)))
fp += fmt.Sprintf("'\\u%04x'", uint(int(x)))
return fp
} }
if 0 <= x && x <= utf8.MaxRune { if 0 <= x && x <= utf8.MaxRune {
var fp string return fmt.Sprintf("'\\U%08x'", uint64(x))
fp += fmt.Sprintf("'\\U%08x'", uint64(x))
return fp
} }
var fp string var fp string
fp += fmt.Sprintf("('\\x00' + %v)", Bconv(v.U.Xval, 0)) fp += fmt.Sprintf("('\\x00' + %v)", Bconv(v.U.Xval, 0))
...@@ -339,9 +325,7 @@ func Vconv(v *Val, flag int) string { ...@@ -339,9 +325,7 @@ func Vconv(v *Val, flag int) string {
case CTFLT: case CTFLT:
if (flag&obj.FmtSharp != 0 /*untyped*/) || fmtmode == FExp { if (flag&obj.FmtSharp != 0 /*untyped*/) || fmtmode == FExp {
var fp string return fmt.Sprintf("%v", Fconv(v.U.Fval, 0))
fp += fmt.Sprintf("%v", Fconv(v.U.Fval, 0))
return fp
} }
var fp string var fp string
fp += fmt.Sprintf("%v", Fconv(v.U.Fval, obj.FmtSharp)) fp += fmt.Sprintf("%v", Fconv(v.U.Fval, obj.FmtSharp))
...@@ -349,24 +333,16 @@ func Vconv(v *Val, flag int) string { ...@@ -349,24 +333,16 @@ func Vconv(v *Val, flag int) string {
case CTCPLX: case CTCPLX:
if (flag&obj.FmtSharp != 0 /*untyped*/) || fmtmode == FExp { if (flag&obj.FmtSharp != 0 /*untyped*/) || fmtmode == FExp {
var fp string return fmt.Sprintf("(%v+%vi)", Fconv(&v.U.Cval.Real, 0), Fconv(&v.U.Cval.Imag, 0))
fp += fmt.Sprintf("(%v+%vi)", Fconv(&v.U.Cval.Real, 0), Fconv(&v.U.Cval.Imag, 0))
return fp
} }
if mpcmpfltc(&v.U.Cval.Real, 0) == 0 { if mpcmpfltc(&v.U.Cval.Real, 0) == 0 {
var fp string return fmt.Sprintf("%vi", Fconv(&v.U.Cval.Imag, obj.FmtSharp))
fp += fmt.Sprintf("%vi", Fconv(&v.U.Cval.Imag, obj.FmtSharp))
return fp
} }
if mpcmpfltc(&v.U.Cval.Imag, 0) == 0 { if mpcmpfltc(&v.U.Cval.Imag, 0) == 0 {
var fp string return fmt.Sprintf("%v", Fconv(&v.U.Cval.Real, obj.FmtSharp))
fp += fmt.Sprintf("%v", Fconv(&v.U.Cval.Real, obj.FmtSharp))
return fp
} }
if mpcmpfltc(&v.U.Cval.Imag, 0) < 0 { if mpcmpfltc(&v.U.Cval.Imag, 0) < 0 {
var fp string return fmt.Sprintf("(%v%vi)", Fconv(&v.U.Cval.Real, obj.FmtSharp), Fconv(&v.U.Cval.Imag, obj.FmtSharp))
fp += fmt.Sprintf("(%v%vi)", Fconv(&v.U.Cval.Real, obj.FmtSharp), Fconv(&v.U.Cval.Imag, obj.FmtSharp))
return fp
} }
var fp string var fp string
fp += fmt.Sprintf("(%v+%vi)", Fconv(&v.U.Cval.Real, obj.FmtSharp), Fconv(&v.U.Cval.Imag, obj.FmtSharp)) fp += fmt.Sprintf("(%v+%vi)", Fconv(&v.U.Cval.Real, obj.FmtSharp), Fconv(&v.U.Cval.Imag, obj.FmtSharp))
...@@ -379,9 +355,7 @@ func Vconv(v *Val, flag int) string { ...@@ -379,9 +355,7 @@ func Vconv(v *Val, flag int) string {
case CTBOOL: case CTBOOL:
if v.U.Bval != 0 { if v.U.Bval != 0 {
var fp string return "true"
fp += "true"
return fp
} }
var fp string var fp string
fp += "false" fp += "false"
...@@ -393,17 +367,13 @@ func Vconv(v *Val, flag int) string { ...@@ -393,17 +367,13 @@ func Vconv(v *Val, flag int) string {
return fp return fp
} }
var fp string return fmt.Sprintf("<ctype=%d>", v.Ctype)
fp += fmt.Sprintf("<ctype=%d>", v.Ctype)
return fp
} }
// Fmt "%Z": escaped string literals // Fmt "%Z": escaped string literals
func Zconv(sp *Strlit, flag int) string { func Zconv(sp *Strlit, flag int) string {
if sp == nil { if sp == nil {
var fp string return "<nil>"
fp += "<nil>"
return fp
} }
// NOTE: Keep in sync with ../ld/go.c:/^Zconv. // NOTE: Keep in sync with ../ld/go.c:/^Zconv.
...@@ -491,13 +461,9 @@ var etnames = []string{ ...@@ -491,13 +461,9 @@ var etnames = []string{
// Fmt "%E": etype // Fmt "%E": etype
func Econv(et int, flag int) string { func Econv(et int, flag int) string {
if et >= 0 && et < len(etnames) && etnames[et] != "" { if et >= 0 && et < len(etnames) && etnames[et] != "" {
var fp string return etnames[et]
fp += etnames[et]
return fp
} }
var fp string return fmt.Sprintf("E-%d", et)
fp += fmt.Sprintf("E-%d", et)
return fp
} }
// Fmt "%S": syms // Fmt "%S": syms
...@@ -506,16 +472,12 @@ func symfmt(s *Sym, flag int) string { ...@@ -506,16 +472,12 @@ func symfmt(s *Sym, flag int) string {
switch fmtmode { switch fmtmode {
case FErr: // This is for the user case FErr: // This is for the user
if s.Pkg == localpkg { if s.Pkg == localpkg {
var fp string return s.Name
fp += s.Name
return fp
} }
// If the name was used by multiple packages, display the full path, // If the name was used by multiple packages, display the full path,
if s.Pkg.Name != "" && Pkglookup(s.Pkg.Name, nil).Npkg > 1 { if s.Pkg.Name != "" && Pkglookup(s.Pkg.Name, nil).Npkg > 1 {
var fp string return fmt.Sprintf("\"%v\".%s", Zconv(s.Pkg.Path, 0), s.Name)
fp += fmt.Sprintf("\"%v\".%s", Zconv(s.Pkg.Path, 0), s.Name)
return fp
} }
var fp string var fp string
fp += fmt.Sprintf("%s.%s", s.Pkg.Name, s.Name) fp += fmt.Sprintf("%s.%s", s.Pkg.Name, s.Name)
...@@ -528,9 +490,7 @@ func symfmt(s *Sym, flag int) string { ...@@ -528,9 +490,7 @@ func symfmt(s *Sym, flag int) string {
case FTypeId: case FTypeId:
if flag&obj.FmtUnsigned != 0 /*untyped*/ { if flag&obj.FmtUnsigned != 0 /*untyped*/ {
var fp string return fmt.Sprintf("%s.%s", s.Pkg.Name, s.Name) // dcommontype, typehash
fp += fmt.Sprintf("%s.%s", s.Pkg.Name, s.Name)
return fp // dcommontype, typehash
} }
var fp string var fp string
fp += fmt.Sprintf("%s.%s", s.Pkg.Prefix, s.Name) fp += fmt.Sprintf("%s.%s", s.Pkg.Prefix, s.Name)
...@@ -541,15 +501,13 @@ func symfmt(s *Sym, flag int) string { ...@@ -541,15 +501,13 @@ func symfmt(s *Sym, flag int) string {
Fatal("exporting synthetic symbol %s", s.Name) Fatal("exporting synthetic symbol %s", s.Name)
} }
if s.Pkg != builtinpkg { if s.Pkg != builtinpkg {
var fp string return fmt.Sprintf("@\"%v\".%s", Zconv(s.Pkg.Path, 0), s.Name)
fp += fmt.Sprintf("@\"%v\".%s", Zconv(s.Pkg.Path, 0), s.Name)
return fp
} }
} }
} }
if flag&obj.FmtByte != 0 /*untyped*/ { // FmtByte (hh) implies FmtShort (h) if flag&obj.FmtByte != 0 /*untyped*/ {
// FmtByte (hh) implies FmtShort (h)
// skip leading "type." in method name // skip leading "type." in method name
p := s.Name p := s.Name
if i := strings.LastIndex(s.Name, "."); i >= 0 { if i := strings.LastIndex(s.Name, "."); i >= 0 {
...@@ -558,19 +516,13 @@ func symfmt(s *Sym, flag int) string { ...@@ -558,19 +516,13 @@ func symfmt(s *Sym, flag int) string {
// exportname needs to see the name without the prefix too. // exportname needs to see the name without the prefix too.
if (fmtmode == FExp && !exportname(p)) || fmtmode == FDbg { if (fmtmode == FExp && !exportname(p)) || fmtmode == FDbg {
var fp string return fmt.Sprintf("@\"%v\".%s", Zconv(s.Pkg.Path, 0), p)
fp += fmt.Sprintf("@\"%v\".%s", Zconv(s.Pkg.Path, 0), p)
return fp
} }
var fp string return p
fp += p
return fp
} }
var fp string return s.Name
fp += s.Name
return fp
} }
var basicnames = []string{ var basicnames = []string{
...@@ -599,25 +551,19 @@ var basicnames = []string{ ...@@ -599,25 +551,19 @@ var basicnames = []string{
func typefmt(t *Type, flag int) string { func typefmt(t *Type, flag int) string {
if t == nil { if t == nil {
var fp string return "<T>"
fp += "<T>"
return fp
} }
if t == bytetype || t == runetype { if t == bytetype || t == runetype {
// in %-T mode collapse rune and byte with their originals. // in %-T mode collapse rune and byte with their originals.
if fmtmode != FTypeId { if fmtmode != FTypeId {
var fp string return fmt.Sprintf("%v", Sconv(t.Sym, obj.FmtShort))
fp += fmt.Sprintf("%v", Sconv(t.Sym, obj.FmtShort))
return fp
} }
t = Types[t.Etype] t = Types[t.Etype]
} }
if t == errortype { if t == errortype {
var fp string return "error"
fp += "error"
return fp
} }
// 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.
...@@ -626,34 +572,24 @@ func typefmt(t *Type, flag int) string { ...@@ -626,34 +572,24 @@ func typefmt(t *Type, flag int) string {
case FTypeId: case FTypeId:
if flag&obj.FmtShort != 0 /*untyped*/ { if flag&obj.FmtShort != 0 /*untyped*/ {
if t.Vargen != 0 { if t.Vargen != 0 {
var fp string return fmt.Sprintf("%v·%d", Sconv(t.Sym, obj.FmtShort), t.Vargen)
fp += fmt.Sprintf("%v·%d", Sconv(t.Sym, obj.FmtShort), t.Vargen)
return fp
} }
var fp string return fmt.Sprintf("%v", Sconv(t.Sym, obj.FmtShort))
fp += fmt.Sprintf("%v", Sconv(t.Sym, obj.FmtShort))
return fp
} }
if flag&obj.FmtUnsigned != 0 /*untyped*/ { if flag&obj.FmtUnsigned != 0 /*untyped*/ {
var fp string return fmt.Sprintf("%v", Sconv(t.Sym, obj.FmtUnsigned))
fp += fmt.Sprintf("%v", Sconv(t.Sym, obj.FmtUnsigned))
return fp
} }
fallthrough fallthrough
// fallthrough // fallthrough
case FExp: case FExp:
if t.Sym.Pkg == localpkg && t.Vargen != 0 { if t.Sym.Pkg == localpkg && t.Vargen != 0 {
var fp string return fmt.Sprintf("%v·%d", Sconv(t.Sym, 0), t.Vargen)
fp += fmt.Sprintf("%v·%d", Sconv(t.Sym, 0), t.Vargen)
return fp
} }
} }
var fp string return fmt.Sprintf("%v", Sconv(t.Sym, 0))
fp += fmt.Sprintf("%v", Sconv(t.Sym, 0))
return fp
} }
var fp string var fp string
...@@ -1228,9 +1164,7 @@ func exprfmt(n *Node, prec int) string { ...@@ -1228,9 +1164,7 @@ func exprfmt(n *Node, prec int) string {
} }
if n == nil { if n == nil {
var f string return "<N>"
f += "<N>"
return f
} }
nprec := opprec[n.Op] nprec := opprec[n.Op]
...@@ -1239,9 +1173,7 @@ func exprfmt(n *Node, prec int) string { ...@@ -1239,9 +1173,7 @@ func exprfmt(n *Node, prec int) string {
} }
if prec > nprec { if prec > nprec {
var f string return fmt.Sprintf("(%v)", Nconv(n, 0))
f += fmt.Sprintf("(%v)", Nconv(n, 0))
return f
} }
switch n.Op { switch n.Op {
...@@ -1262,26 +1194,18 @@ func exprfmt(n *Node, prec int) string { ...@@ -1262,26 +1194,18 @@ func exprfmt(n *Node, prec int) string {
case OLITERAL: // this is a bit of a mess case OLITERAL: // this is a bit of a mess
if n.Orig != nil && n.Orig != n { if n.Orig != nil && n.Orig != n {
var f string return exprfmt(n.Orig, prec)
f += exprfmt(n.Orig, prec)
return f
} }
if fmtmode == FErr && n.Sym != nil { if fmtmode == FErr && n.Sym != nil {
var f string return fmt.Sprintf("%v", Sconv(n.Sym, 0))
f += fmt.Sprintf("%v", Sconv(n.Sym, 0))
return f
} }
if n.Type != nil && n.Type != Types[n.Type.Etype] && n.Type != idealbool && n.Type != idealstring { if n.Type != nil && n.Type != Types[n.Type.Etype] && n.Type != idealbool && n.Type != idealstring {
// Need parens when type begins with what might // Need parens when type begins with what might
// be misinterpreted as a unary operator: * or <-. // be misinterpreted as a unary operator: * or <-.
if Isptr[n.Type.Etype] != 0 || (n.Type.Etype == TCHAN && n.Type.Chan == Crecv) { if Isptr[n.Type.Etype] != 0 || (n.Type.Etype == TCHAN && n.Type.Chan == Crecv) {
var f string return fmt.Sprintf("(%v)(%v)", Tconv(n.Type, 0), Vconv(&n.Val, 0))
f += fmt.Sprintf("(%v)(%v)", Tconv(n.Type, 0), Vconv(&n.Val, 0))
return f
} else { } else {
var f string return fmt.Sprintf("%v(%v)", Tconv(n.Type, 0), Vconv(&n.Val, 0))
f += fmt.Sprintf("%v(%v)", Tconv(n.Type, 0), Vconv(&n.Val, 0))
return f
} }
} }
...@@ -1293,14 +1217,10 @@ func exprfmt(n *Node, prec int) string { ...@@ -1293,14 +1217,10 @@ func exprfmt(n *Node, prec int) string {
// _ becomes ~b%d internally; print as _ for export // _ becomes ~b%d internally; print as _ for export
case ONAME: case ONAME:
if fmtmode == FExp && n.Sym != nil && n.Sym.Name[0] == '~' && n.Sym.Name[1] == 'b' { if fmtmode == FExp && n.Sym != nil && n.Sym.Name[0] == '~' && n.Sym.Name[1] == 'b' {
var f string return fmt.Sprintf("_")
f += fmt.Sprintf("_")
return f
} }
if fmtmode == FExp && n.Sym != nil && !isblank(n) && n.Vargen > 0 { if fmtmode == FExp && n.Sym != nil && !isblank(n) && n.Vargen > 0 {
var f string return fmt.Sprintf("%v·%d", Sconv(n.Sym, 0), n.Vargen)
f += fmt.Sprintf("%v·%d", Sconv(n.Sym, 0), n.Vargen)
return f
} }
// Special case: explicit name of func (*T) method(...) is turned into pkg.(*T).method, // Special case: explicit name of func (*T) method(...) is turned into pkg.(*T).method,
...@@ -1308,13 +1228,9 @@ func exprfmt(n *Node, prec int) string { ...@@ -1308,13 +1228,9 @@ func exprfmt(n *Node, prec int) string {
// These nodes have the special property that they are names with a left OTYPE and a right ONAME. // These nodes have the special property that they are names with a left OTYPE and a right ONAME.
if fmtmode == FExp && n.Left != nil && n.Left.Op == OTYPE && n.Right != nil && n.Right.Op == ONAME { if fmtmode == FExp && n.Left != nil && n.Left.Op == OTYPE && n.Right != nil && n.Right.Op == ONAME {
if Isptr[n.Left.Type.Etype] != 0 { if Isptr[n.Left.Type.Etype] != 0 {
var f string return fmt.Sprintf("(%v).%v", Tconv(n.Left.Type, 0), Sconv(n.Right.Sym, obj.FmtShort|obj.FmtByte))
f += fmt.Sprintf("(%v).%v", Tconv(n.Left.Type, 0), Sconv(n.Right.Sym, obj.FmtShort|obj.FmtByte))
return f
} else { } else {
var f string return fmt.Sprintf("%v.%v", Tconv(n.Left.Type, 0), Sconv(n.Right.Sym, obj.FmtShort|obj.FmtByte))
f += fmt.Sprintf("%v.%v", Tconv(n.Left.Type, 0), Sconv(n.Right.Sym, obj.FmtShort|obj.FmtByte))
return f
} }
} }
fallthrough fallthrough
...@@ -1328,9 +1244,7 @@ func exprfmt(n *Node, prec int) string { ...@@ -1328,9 +1244,7 @@ func exprfmt(n *Node, prec int) string {
case OTYPE: case OTYPE:
if n.Type == nil && n.Sym != nil { if n.Type == nil && n.Sym != nil {
var f string return fmt.Sprintf("%v", Sconv(n.Sym, 0))
f += fmt.Sprintf("%v", Sconv(n.Sym, 0))
return f
} }
var f string var f string
f += fmt.Sprintf("%v", Tconv(n.Type, 0)) f += fmt.Sprintf("%v", Tconv(n.Type, 0))
...@@ -1338,9 +1252,7 @@ func exprfmt(n *Node, prec int) string { ...@@ -1338,9 +1252,7 @@ func exprfmt(n *Node, prec int) string {
case OTARRAY: case OTARRAY:
if n.Left != nil { if n.Left != nil {
var f string return fmt.Sprintf("[]%v", Nconv(n.Left, 0))
f += fmt.Sprintf("[]%v", Nconv(n.Left, 0))
return f
} }
var f string var f string
f += fmt.Sprintf("[]%v", Nconv(n.Right, 0)) f += fmt.Sprintf("[]%v", Nconv(n.Right, 0))
...@@ -1365,13 +1277,9 @@ func exprfmt(n *Node, prec int) string { ...@@ -1365,13 +1277,9 @@ func exprfmt(n *Node, prec int) string {
default: default:
if n.Left != nil && n.Left.Op == OTCHAN && n.Left.Sym == nil && n.Left.Etype == Crecv { if n.Left != nil && n.Left.Op == OTCHAN && n.Left.Sym == nil && n.Left.Etype == Crecv {
var f string return fmt.Sprintf("chan (%v)", Nconv(n.Left, 0))
f += fmt.Sprintf("chan (%v)", Nconv(n.Left, 0))
return f
} else { } else {
var f string return fmt.Sprintf("chan %v", Nconv(n.Left, 0))
f += fmt.Sprintf("chan %v", Nconv(n.Left, 0))
return f
} }
} }
fallthrough fallthrough
...@@ -1393,14 +1301,10 @@ func exprfmt(n *Node, prec int) string { ...@@ -1393,14 +1301,10 @@ func exprfmt(n *Node, prec int) string {
case OCLOSURE: case OCLOSURE:
if fmtmode == FErr { if fmtmode == FErr {
var f string return "func literal"
f += "func literal"
return f
} }
if n.Nbody != nil { if n.Nbody != nil {
var f string return fmt.Sprintf("%v { %v }", Tconv(n.Type, 0), Hconv(n.Nbody, 0))
f += fmt.Sprintf("%v { %v }", Tconv(n.Type, 0), Hconv(n.Nbody, 0))
return f
} }
var f string var f string
f += fmt.Sprintf("%v { %v }", Tconv(n.Type, 0), Hconv(n.Closure.Nbody, 0)) f += fmt.Sprintf("%v { %v }", Tconv(n.Type, 0), Hconv(n.Closure.Nbody, 0))
...@@ -1411,26 +1315,18 @@ func exprfmt(n *Node, prec int) string { ...@@ -1411,26 +1315,18 @@ func exprfmt(n *Node, prec int) string {
if fmtmode == FErr { if fmtmode == FErr {
if n.Right != nil && n.Right.Type != nil && n.Implicit == 0 { if n.Right != nil && n.Right.Type != nil && n.Implicit == 0 {
if ptrlit { if ptrlit {
var f string return fmt.Sprintf("&%v literal", Tconv(n.Right.Type.Type, 0))
f += fmt.Sprintf("&%v literal", Tconv(n.Right.Type.Type, 0))
return f
} else { } else {
var f string return fmt.Sprintf("%v literal", Tconv(n.Right.Type, 0))
f += fmt.Sprintf("%v literal", Tconv(n.Right.Type, 0))
return f
} }
} }
var f string return "composite literal"
f += "composite literal"
return f
} }
if fmtmode == FExp && ptrlit { if fmtmode == FExp && ptrlit {
// typecheck has overwritten OIND by OTYPE with pointer type. // typecheck has overwritten OIND by OTYPE with pointer type.
var f string return fmt.Sprintf("(&%v{ %v })", Tconv(n.Right.Type.Type, 0), Hconv(n.List, obj.FmtComma))
f += fmt.Sprintf("(&%v{ %v })", Tconv(n.Right.Type.Type, 0), Hconv(n.List, obj.FmtComma))
return f
} }
var f string var f string
...@@ -1439,9 +1335,7 @@ func exprfmt(n *Node, prec int) string { ...@@ -1439,9 +1335,7 @@ func exprfmt(n *Node, prec int) string {
case OPTRLIT: case OPTRLIT:
if fmtmode == FExp && n.Left.Implicit != 0 { if fmtmode == FExp && n.Left.Implicit != 0 {
var f string return fmt.Sprintf("%v", Nconv(n.Left, 0))
f += fmt.Sprintf("%v", Nconv(n.Left, 0))
return f
} }
var f string var f string
f += fmt.Sprintf("&%v", Nconv(n.Left, 0)) f += fmt.Sprintf("&%v", Nconv(n.Left, 0))
...@@ -1479,14 +1373,10 @@ func exprfmt(n *Node, prec int) string { ...@@ -1479,14 +1373,10 @@ func exprfmt(n *Node, prec int) string {
case OARRAYLIT, case OARRAYLIT,
OMAPLIT: OMAPLIT:
if fmtmode == FErr { if fmtmode == FErr {
var f string return fmt.Sprintf("%v literal", Tconv(n.Type, 0))
f += fmt.Sprintf("%v literal", Tconv(n.Type, 0))
return f
} }
if fmtmode == FExp && n.Implicit != 0 { if fmtmode == FExp && n.Implicit != 0 {
var f string return fmt.Sprintf("{ %v }", Hconv(n.List, obj.FmtComma))
f += fmt.Sprintf("{ %v }", Hconv(n.List, obj.FmtComma))
return f
} }
var f string var f string
f += fmt.Sprintf("(%v{ %v })", Tconv(n.Type, 0), Hconv(n.List, obj.FmtComma)) f += fmt.Sprintf("(%v{ %v })", Tconv(n.Type, 0), Hconv(n.List, obj.FmtComma))
...@@ -1496,25 +1386,17 @@ func exprfmt(n *Node, prec int) string { ...@@ -1496,25 +1386,17 @@ func exprfmt(n *Node, prec int) string {
if n.Left != nil && n.Right != nil { if n.Left != nil && n.Right != nil {
if fmtmode == FExp && n.Left.Type != nil && n.Left.Type.Etype == TFIELD { if fmtmode == FExp && n.Left.Type != nil && n.Left.Type.Etype == TFIELD {
// requires special handling of field names // requires special handling of field names
var f string return fmt.Sprintf("%v:%v", Sconv(n.Left.Sym, obj.FmtShort|obj.FmtByte), Nconv(n.Right, 0))
f += fmt.Sprintf("%v:%v", Sconv(n.Left.Sym, obj.FmtShort|obj.FmtByte), Nconv(n.Right, 0))
return f
} else { } else {
var f string return fmt.Sprintf("%v:%v", Nconv(n.Left, 0), Nconv(n.Right, 0))
f += fmt.Sprintf("%v:%v", Nconv(n.Left, 0), Nconv(n.Right, 0))
return f
} }
} }
if n.Left == nil && n.Right != nil { if n.Left == nil && n.Right != nil {
var f string return fmt.Sprintf(":%v", Nconv(n.Right, 0))
f += fmt.Sprintf(":%v", Nconv(n.Right, 0))
return f
} }
if n.Left != nil && n.Right == nil { if n.Left != nil && n.Right == nil {
var f string return fmt.Sprintf("%v:", Nconv(n.Left, 0))
f += fmt.Sprintf("%v:", Nconv(n.Left, 0))
return f
} }
var f string var f string
f += ":" f += ":"
...@@ -1573,14 +1455,10 @@ func exprfmt(n *Node, prec int) string { ...@@ -1573,14 +1455,10 @@ func exprfmt(n *Node, prec int) string {
OSTRARRAYRUNE, OSTRARRAYRUNE,
ORUNESTR: ORUNESTR:
if n.Type == nil || n.Type.Sym == nil { if n.Type == nil || n.Type.Sym == nil {
var f string return fmt.Sprintf("(%v)(%v)", Tconv(n.Type, 0), Nconv(n.Left, 0))
f += fmt.Sprintf("(%v)(%v)", Tconv(n.Type, 0), Nconv(n.Left, 0))
return f
} }
if n.Left != nil { if n.Left != nil {
var f string return fmt.Sprintf("%v(%v)", Tconv(n.Type, 0), Nconv(n.Left, 0))
f += fmt.Sprintf("%v(%v)", Tconv(n.Type, 0), Nconv(n.Left, 0))
return f
} }
var f string var f string
f += fmt.Sprintf("%v(%v)", Tconv(n.Type, 0), Hconv(n.List, obj.FmtComma)) f += fmt.Sprintf("%v(%v)", Tconv(n.Type, 0), Hconv(n.List, obj.FmtComma))
...@@ -1600,14 +1478,10 @@ func exprfmt(n *Node, prec int) string { ...@@ -1600,14 +1478,10 @@ func exprfmt(n *Node, prec int) string {
OPRINT, OPRINT,
OPRINTN: OPRINTN:
if n.Left != nil { if n.Left != nil {
var f string return fmt.Sprintf("%v(%v)", Oconv(int(n.Op), obj.FmtSharp), Nconv(n.Left, 0))
f += fmt.Sprintf("%v(%v)", Oconv(int(n.Op), obj.FmtSharp), Nconv(n.Left, 0))
return f
} }
if n.Isddd != 0 { if n.Isddd != 0 {
var f string return fmt.Sprintf("%v(%v...)", Oconv(int(n.Op), obj.FmtSharp), Hconv(n.List, obj.FmtComma))
f += fmt.Sprintf("%v(%v...)", Oconv(int(n.Op), obj.FmtSharp), Hconv(n.List, obj.FmtComma))
return f
} }
var f string var f string
f += fmt.Sprintf("%v(%v)", Oconv(int(n.Op), obj.FmtSharp), Hconv(n.List, obj.FmtComma)) f += fmt.Sprintf("%v(%v)", Oconv(int(n.Op), obj.FmtSharp), Hconv(n.List, obj.FmtComma))
...@@ -1630,19 +1504,13 @@ func exprfmt(n *Node, prec int) string { ...@@ -1630,19 +1504,13 @@ func exprfmt(n *Node, prec int) string {
OMAKECHAN, OMAKECHAN,
OMAKESLICE: OMAKESLICE:
if n.List != nil { // pre-typecheck if n.List != nil { // pre-typecheck
var f string return fmt.Sprintf("make(%v, %v)", Tconv(n.Type, 0), Hconv(n.List, obj.FmtComma))
f += fmt.Sprintf("make(%v, %v)", Tconv(n.Type, 0), Hconv(n.List, obj.FmtComma))
return f
} }
if n.Right != nil { if n.Right != nil {
var f string return fmt.Sprintf("make(%v, %v, %v)", Tconv(n.Type, 0), Nconv(n.Left, 0), Nconv(n.Right, 0))
f += fmt.Sprintf("make(%v, %v, %v)", Tconv(n.Type, 0), Nconv(n.Left, 0), Nconv(n.Right, 0))
return f
} }
if n.Left != nil && (n.Op == OMAKESLICE || !isideal(n.Left.Type)) { if n.Left != nil && (n.Op == OMAKESLICE || !isideal(n.Left.Type)) {
var f string return fmt.Sprintf("make(%v, %v)", Tconv(n.Type, 0), Nconv(n.Left, 0))
f += fmt.Sprintf("make(%v, %v)", Tconv(n.Type, 0), Nconv(n.Left, 0))
return f
} }
var f string var f string
f += fmt.Sprintf("make(%v)", Tconv(n.Type, 0)) f += fmt.Sprintf("make(%v)", Tconv(n.Type, 0))
...@@ -1713,9 +1581,7 @@ func exprfmt(n *Node, prec int) string { ...@@ -1713,9 +1581,7 @@ func exprfmt(n *Node, prec int) string {
return f return f
} }
var f string return fmt.Sprintf("<node %v>", Oconv(int(n.Op), 0))
f += fmt.Sprintf("<node %v>", Oconv(int(n.Op), 0))
return f
} }
func nodefmt(n *Node, flag int) string { func nodefmt(n *Node, flag int) string {
...@@ -1730,13 +1596,9 @@ func nodefmt(n *Node, flag int) string { ...@@ -1730,13 +1596,9 @@ func nodefmt(n *Node, flag int) string {
if flag&obj.FmtLong != 0 /*untyped*/ && t != nil { if flag&obj.FmtLong != 0 /*untyped*/ && t != nil {
if t.Etype == TNIL { if t.Etype == TNIL {
var f string return fmt.Sprintf("nil")
f += fmt.Sprintf("nil")
return f
} else { } else {
var f string return fmt.Sprintf("%v (type %v)", Nconv(n, 0), Tconv(t, 0))
f += fmt.Sprintf("%v (type %v)", Nconv(n, 0), Tconv(t, 0))
return f
} }
} }
...@@ -1746,9 +1608,7 @@ func nodefmt(n *Node, flag int) string { ...@@ -1746,9 +1608,7 @@ func nodefmt(n *Node, flag int) string {
return stmtfmt(n) return stmtfmt(n)
} }
var f string return exprfmt(n, 0)
f += exprfmt(n, 0)
return f
} }
var dumpdepth int var dumpdepth int
...@@ -1872,15 +1732,11 @@ func Sconv(s *Sym, flag int) string { ...@@ -1872,15 +1732,11 @@ func Sconv(s *Sym, flag int) string {
} }
if s == nil { if s == nil {
var fp string return "<S>"
fp += "<S>"
return fp
} }
if s.Name == "_" { if s.Name == "_" {
var fp string return "_"
fp += "_"
return fp
} }
sf := flag sf := flag
...@@ -1899,15 +1755,11 @@ func Sconv(s *Sym, flag int) string { ...@@ -1899,15 +1755,11 @@ func Sconv(s *Sym, flag int) string {
// 'u' package name, not prefix (FTypeId mode, sticky) // 'u' package name, not prefix (FTypeId mode, sticky)
func Tconv(t *Type, flag int) string { func Tconv(t *Type, flag int) string {
if t == nil { if t == nil {
var fp string return "<T>"
fp += "<T>"
return fp
} }
if t.Trecur > 4 { if t.Trecur > 4 {
var fp string return "<...>"
fp += "<...>"
return fp
} }
t.Trecur++ t.Trecur++
...@@ -1940,9 +1792,7 @@ func Tconv(t *Type, flag int) string { ...@@ -1940,9 +1792,7 @@ func Tconv(t *Type, flag int) string {
// '+h' in debug mode, don't recurse, no multiline output // '+h' in debug mode, don't recurse, no multiline output
func Nconv(n *Node, flag int) string { func Nconv(n *Node, flag int) string {
if n == nil { if n == nil {
var fp string return "<N>"
fp += "<N>"
return fp
} }
sf := flag sf := flag
sm := setfmode(&flag) sm := setfmode(&flag)
...@@ -1973,9 +1823,7 @@ func Nconv(n *Node, flag int) string { ...@@ -1973,9 +1823,7 @@ func Nconv(n *Node, flag int) string {
// Flags: all those of %N plus ',': separate with comma's instead of semicolons. // Flags: all those of %N plus ',': separate with comma's instead of semicolons.
func Hconv(l *NodeList, flag int) string { func Hconv(l *NodeList, flag int) string {
if l == nil && fmtmode == FDbg { if l == nil && fmtmode == FDbg {
var fp string return "<nil>"
fp += "<nil>"
return fp
} }
sf := flag sf := flag
......
...@@ -594,9 +594,8 @@ func Bconv(xval *Mpint, flag int) string { ...@@ -594,9 +594,8 @@ func Bconv(xval *Mpint, flag int) string {
p-- p--
buf[p] = '-' buf[p] = '-'
} }
var fp string
fp += string(buf[p:]) return string(buf[p:])
return fp
} }
func Fconv(fvp *Mpflt, flag int) string { func Fconv(fvp *Mpflt, flag int) string {
......
...@@ -77,10 +77,7 @@ func Pconv(p *obj.Prog) string { ...@@ -77,10 +77,7 @@ func Pconv(p *obj.Prog) string {
} }
func Aconv(i int) string { func Aconv(i int) string {
var fp string return Anames[i]
fp += Anames[i]
return fp
} }
var Register = []string{ var Register = []string{
......
...@@ -89,10 +89,7 @@ func Pconv(p *obj.Prog) string { ...@@ -89,10 +89,7 @@ func Pconv(p *obj.Prog) string {
} }
func Aconv(i int) string { func Aconv(i int) string {
var fp string return Anames[i]
fp += Anames[i]
return fp
} }
var Register = []string{ var Register = []string{
......
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