diff options
Diffstat (limited to 'src/cmd/compile/internal/ir/fmt.go')
-rw-r--r-- | src/cmd/compile/internal/ir/fmt.go | 108 |
1 files changed, 24 insertions, 84 deletions
diff --git a/src/cmd/compile/internal/ir/fmt.go b/src/cmd/compile/internal/ir/fmt.go index 0c553a9963..31c610348b 100644 --- a/src/cmd/compile/internal/ir/fmt.go +++ b/src/cmd/compile/internal/ir/fmt.go @@ -27,7 +27,6 @@ var OpNames = []string{ OADDR: "&", OADD: "+", OADDSTR: "+", - OALIGNOF: "unsafe.Alignof", OANDAND: "&&", OANDNOT: "&^", OAND: "&", @@ -70,12 +69,11 @@ var OpNames = []string{ ONEW: "new", ONE: "!=", ONOT: "!", - OOFFSETOF: "unsafe.Offsetof", OOROR: "||", OOR: "|", OPANIC: "panic", OPLUS: "+", - OPRINTN: "println", + OPRINTLN: "println", OPRINT: "print", ORANGE: "range", OREAL: "real", @@ -85,7 +83,6 @@ var OpNames = []string{ ORSH: ">>", OSELECT: "select", OSEND: "<-", - OSIZEOF: "unsafe.Sizeof", OSUB: "-", OSWITCH: "switch", OUNSAFEADD: "unsafe.Add", @@ -173,7 +170,6 @@ func fmtNode(n Node, s fmt.State, verb rune) { } var OpPrec = []int{ - OALIGNOF: 8, OAPPEND: 8, OBYTES2STR: 8, OARRAYLIT: 8, @@ -188,7 +184,6 @@ var OpPrec = []int{ OCLOSE: 8, OCOMPLIT: 8, OCONVIFACE: 8, - OCONVIDATA: 8, OCONVNOP: 8, OCONV: 8, OCOPY: 8, @@ -206,13 +201,11 @@ var OpPrec = []int{ ONEW: 8, ONIL: 8, ONONAME: 8, - OOFFSETOF: 8, OPANIC: 8, OPAREN: 8, - OPRINTN: 8, + OPRINTLN: 8, OPRINT: 8, ORUNESTR: 8, - OSIZEOF: 8, OSLICE2ARR: 8, OSLICE2ARRPTR: 8, OSTR2BYTES: 8, @@ -526,12 +519,6 @@ func exprFmt(n Node, s fmt.State, prec int) { return } - // We always want the original, if any. - if o := Orig(n); o != n { - n = o - continue - } - // Skip implicit operations introduced during typechecking. switch nn := n; nn.Op() { case OADDR: @@ -546,7 +533,7 @@ func exprFmt(n Node, s fmt.State, prec int) { n = nn.X continue } - case OCONV, OCONVNOP, OCONVIFACE, OCONVIDATA: + case OCONV, OCONVNOP, OCONVIFACE: nn := nn.(*ConvExpr) if nn.Implicit() { n = nn.X @@ -567,11 +554,6 @@ func exprFmt(n Node, s fmt.State, prec int) { return } - if n, ok := n.(*RawOrigExpr); ok { - fmt.Fprint(s, n.Raw) - return - } - switch n.Op() { case OPAREN: n := n.(*ParenExpr) @@ -580,46 +562,29 @@ func exprFmt(n Node, s fmt.State, prec int) { case ONIL: fmt.Fprint(s, "nil") - case OLITERAL: // this is a bit of a mess - if !exportFormat && n.Sym() != nil { + case OLITERAL: + if n.Sym() != nil { fmt.Fprint(s, n.Sym()) return } - needUnparen := false - if n.Type() != nil && !n.Type().IsUntyped() { - // Need parens when type begins with what might - // be misinterpreted as a unary operator: * or <-. - if n.Type().IsPtr() || (n.Type().IsChan() && n.Type().ChanDir() == types.Crecv) { - fmt.Fprintf(s, "(%v)(", n.Type()) - } else { - fmt.Fprintf(s, "%v(", n.Type()) - } - needUnparen = true - } - - if n.Type() == types.UntypedRune { - switch x, ok := constant.Uint64Val(n.Val()); { - case !ok: - fallthrough - default: - fmt.Fprintf(s, "('\\x00' + %v)", n.Val()) + typ := n.Type() + val := n.Val() - case x < utf8.RuneSelf: + // Special case for rune constants. + if typ == types.RuneType || typ == types.UntypedRune { + if x, ok := constant.Uint64Val(val); ok && x <= utf8.MaxRune { fmt.Fprintf(s, "%q", x) - - case x < 1<<16: - fmt.Fprintf(s, "'\\u%04x'", x) - - case x <= utf8.MaxRune: - fmt.Fprintf(s, "'\\U%08x'", x) + return } - } else { - fmt.Fprint(s, types.FmtConst(n.Val(), s.Flag('#'))) } - if needUnparen { - fmt.Fprintf(s, ")") + // Only include typ if it's neither the default nor untyped type + // for the constant value. + if k := val.Kind(); typ == types.Types[types.DefaultKinds[k]] || typ == types.UntypedTypes[k] { + fmt.Fprint(s, val) + } else { + fmt.Fprintf(s, "%v(%v)", typ, val) } case ODCLFUNC: @@ -661,33 +626,17 @@ func exprFmt(n Node, s fmt.State, prec int) { } fmt.Fprintf(s, "%v { %v }", n.Type(), n.Func.Body) - case OCOMPLIT: - n := n.(*CompLitExpr) - if !exportFormat { - if n.Implicit() { - fmt.Fprintf(s, "... argument") - return - } - if typ := n.Type(); typ != nil { - fmt.Fprintf(s, "%v{%s}", typ, ellipsisIf(len(n.List) != 0)) - return - } - fmt.Fprint(s, "composite literal") - return - } - fmt.Fprintf(s, "(%v{ %.v })", n.Type(), n.List) - case OPTRLIT: n := n.(*AddrExpr) fmt.Fprintf(s, "&%v", n.X) - case OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT: + case OCOMPLIT, OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT: n := n.(*CompLitExpr) - if !exportFormat { - fmt.Fprintf(s, "%v{%s}", n.Type(), ellipsisIf(len(n.List) != 0)) + if n.Implicit() { + fmt.Fprintf(s, "... argument") return } - fmt.Fprintf(s, "(%v{ %.v })", n.Type(), n.List) + fmt.Fprintf(s, "%v{%s}", n.Type(), ellipsisIf(len(n.List) != 0)) case OKEY: n := n.(*KeyExpr) @@ -758,7 +707,6 @@ func exprFmt(n Node, s fmt.State, prec int) { case OCONV, OCONVIFACE, - OCONVIDATA, OCONVNOP, OBYTES2STR, ORUNES2STR, @@ -782,10 +730,7 @@ func exprFmt(n Node, s fmt.State, prec int) { OCLOSE, OLEN, ONEW, - OPANIC, - OALIGNOF, - OOFFSETOF, - OSIZEOF: + OPANIC: n := n.(*UnaryExpr) fmt.Fprintf(s, "%v(%v)", n.Op(), n.X) @@ -796,7 +741,7 @@ func exprFmt(n Node, s fmt.State, prec int) { OMIN, ORECOVER, OPRINT, - OPRINTN: + OPRINTLN: n := n.(*CallExpr) if n.IsDDD { fmt.Fprintf(s, "%v(%.v...)", n.Op(), n.Args) @@ -806,7 +751,7 @@ func exprFmt(n Node, s fmt.State, prec int) { case OCALL, OCALLFUNC, OCALLINTER, OCALLMETH, OGETG: n := n.(*CallExpr) - exprFmt(n.X, s, nprec) + exprFmt(n.Fun, s, nprec) if n.IsDDD { fmt.Fprintf(s, "(%.v...)", n.Args) return @@ -1184,11 +1129,6 @@ func dumpNode(w io.Writer, n Node, depth int) { dumpNode(w, cv, depth+1) } } - if len(fn.Enter) > 0 { - indent(w, depth) - fmt.Fprintf(w, "%+v-Enter", n.Op()) - dumpNodes(w, fn.Enter, depth+1) - } if len(fn.Body) > 0 { indent(w, depth) fmt.Fprintf(w, "%+v-body", n.Op()) |