]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove OCASE and rename OXCASE to OCASE
authorMatthew Dempsky <mdempsky@google.com>
Wed, 18 Sep 2019 01:32:04 +0000 (18:32 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 18 Sep 2019 02:31:34 +0000 (02:31 +0000)
We used to use OXCASE to represent general, possibly multi-valued
cases, and then desugar these during walk into single-value cases
represented by OCASE.

In CL 194660, we switched to eliminated the desugaring step and
instead handle the multi-valued cases directly, which eliminates the
need for an OCASE Op. Instead, we can simply remove OCASE, and rename
OXCASE to just OCASE.

Passes toolstash-check.

Change-Id: I3cc184340f9081d37453927cca1c059267fdbc12
Reviewed-on: https://go-review.googlesource.com/c/go/+/196117
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/iexport.go
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/noder.go
src/cmd/compile/internal/gc/op_string.go
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/select.go
src/cmd/compile/internal/gc/swt.go
src/cmd/compile/internal/gc/syntax.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go

index 53d6b9d2cce385d5d88ee1e6763e9e1bd5e19551..cb6b571f833f2e2ef276863e6166bfa4636c14f7 100644 (file)
@@ -1035,7 +1035,7 @@ func (n *Node) stmtfmt(s fmt.State, mode fmtMode) {
 
                mode.Fprintf(s, " { %v }", n.List)
 
-       case OXCASE:
+       case OCASE:
                if n.List.Len() != 0 {
                        mode.Fprintf(s, "case %.v", n.List)
                } else {
@@ -1043,22 +1043,6 @@ func (n *Node) stmtfmt(s fmt.State, mode fmtMode) {
                }
                mode.Fprintf(s, ": %v", n.Nbody)
 
-       case OCASE:
-               switch {
-               case n.Left != nil:
-                       // single element
-                       mode.Fprintf(s, "case %v", n.Left)
-               case n.List.Len() > 0:
-                       // range
-                       if n.List.Len() != 2 {
-                               Fatalf("bad OCASE list length %d", n.List.Len())
-                       }
-                       mode.Fprintf(s, "case %v..%v", n.List.First(), n.List.Second())
-               default:
-                       fmt.Fprint(s, "default")
-               }
-               mode.Fprintf(s, ": %v", n.Nbody)
-
        case OBREAK, OCONTINUE, OGOTO, OFALL:
                if n.Sym != nil {
                        mode.Fprintf(s, "%#v %v", n.Op, n.Sym)
@@ -1192,7 +1176,6 @@ var opprec = []int{
        ORETURN:     -1,
        OSELECT:     -1,
        OSWITCH:     -1,
-       OXCASE:      -1,
 
        OEND: 0,
 }
index 0e5a313bafcfdc9029090209fcd9b89141642fcc..eeca0b4083a7a8ce3cca5e99f24106667b5f3b44 100644 (file)
@@ -1079,8 +1079,8 @@ func (w *exportWriter) stmt(n *Node) {
                w.exprsOrNil(n.Left, nil)
                w.stmtList(n.List)
 
-       case OCASE, OXCASE:
-               w.op(OXCASE)
+       case OCASE:
+               w.op(OCASE)
                w.pos(n.Pos)
                w.stmtList(n.List)
                w.stmtList(n.Nbody)
index 7d134f3a5f246d51d33e0be02ed6dc0650ba4bb0..4862f86344ff971fb7bef3d174e98e45806a68f1 100644 (file)
@@ -1003,20 +1003,14 @@ func (r *importReader) node() *Node {
                n.List.Set(r.stmtList())
                return n
 
-       // case OCASE, OXCASE:
-       //      unreachable - mapped to OXCASE case below by exporter
-
-       case OXCASE:
-               n := nodl(r.pos(), OXCASE, nil, nil)
+       case OCASE:
+               n := nodl(r.pos(), OCASE, nil, nil)
                n.List.Set(r.exprList())
                // TODO(gri) eventually we must declare variables for type switch
                // statements (type switch statements are not yet exported)
                n.Nbody.Set(r.stmtList())
                return n
 
-       // case OFALL:
-       //      unreachable - mapped to OXFALL case below by exporter
-
        case OFALL:
                n := nodl(r.pos(), OFALL, nil, nil)
                return n
index 6bbabb45ddd4f5a594d38f705d58cc226b8a0b3b..91c7fd49b1791728e1bf2c02e7c3be1d8910bd2f 100644 (file)
@@ -1188,7 +1188,7 @@ func (p *noder) caseClauses(clauses []*syntax.CaseClause, tswitch *Node, rbrace
                }
                p.openScope(clause.Pos())
 
-               n := p.nod(clause, OXCASE, nil, nil)
+               n := p.nod(clause, OCASE, nil, nil)
                if clause.Cases != nil {
                        n.List.Set(p.exprList(clause.Cases))
                }
@@ -1244,7 +1244,7 @@ func (p *noder) commClauses(clauses []*syntax.CommClause, rbrace syntax.Pos) []*
                }
                p.openScope(clause.Pos())
 
-               n := p.nod(clause, OXCASE, nil, nil)
+               n := p.nod(clause, OCASE, nil, nil)
                if clause.Comm != nil {
                        n.List.Set1(p.stmt(clause.Comm))
                }
index 796e13a071802550b5975ba7ccf5c7548dde17e4..1586c70f1be6828e6338a873291990b369affeab 100644 (file)
@@ -1,4 +1,4 @@
-// Code generated by "stringer -type=Op -trimprefix=O"; DO NOT EDIT.
+// Code generated by "stringer -type Op -trimprefix O"; DO NOT EDIT.
 
 package gc
 
@@ -121,8 +121,7 @@ func _() {
        _ = x[OSIZEOF-110]
        _ = x[OBLOCK-111]
        _ = x[OBREAK-112]
-       _ = x[OCASE-113]
-       _ = x[OXCASE-114]
+       _ = x[OCASE-114]
        _ = x[OCONTINUE-115]
        _ = x[ODEFER-116]
        _ = x[OEMPTY-117]
@@ -164,13 +163,24 @@ func _() {
        _ = x[OEND-153]
 }
 
-const _Op_name = "XXXNAMENONAMETYPEPACKLITERALADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLFIELDDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMULDIVMODLSHRSHANDANDNOTNEWNEWOBJNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECVSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFBLOCKBREAKCASEXCASECONTINUEDEFEREMPTYFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYDDDDDDARGINLCALLEFACEITABIDATASPTRCLOSUREVARCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKRETJMPGETGEND"
+const (
+       _Op_name_0 = "XXXNAMENONAMETYPEPACKLITERALADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLFIELDDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMULDIVMODLSHRSHANDANDNOTNEWNEWOBJNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECVSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFBLOCKBREAK"
+       _Op_name_1 = "CASECONTINUEDEFEREMPTYFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYDDDDDDARGINLCALLEFACEITABIDATASPTRCLOSUREVARCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKRETJMPGETGEND"
+)
 
-var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 36, 39, 45, 49, 55, 61, 70, 82, 91, 100, 112, 121, 123, 126, 136, 143, 150, 157, 161, 165, 173, 181, 190, 198, 201, 206, 213, 220, 226, 235, 243, 251, 257, 261, 270, 277, 281, 284, 291, 299, 307, 314, 320, 323, 329, 336, 344, 348, 355, 363, 365, 367, 369, 371, 373, 375, 380, 385, 393, 396, 405, 408, 412, 420, 427, 436, 439, 442, 445, 448, 451, 454, 460, 463, 469, 472, 478, 482, 485, 489, 494, 499, 505, 510, 514, 519, 527, 535, 541, 550, 561, 568, 572, 579, 586, 594, 598, 602, 606, 613, 620, 628, 634, 639, 644, 648, 653, 661, 666, 671, 675, 678, 686, 690, 692, 697, 699, 704, 710, 716, 722, 728, 733, 737, 744, 750, 755, 761, 764, 770, 777, 782, 786, 791, 795, 805, 810, 818, 824, 831, 838, 844, 851, 857, 861, 864}
+var (
+       _Op_index_0 = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 36, 39, 45, 49, 55, 61, 70, 82, 91, 100, 112, 121, 123, 126, 136, 143, 150, 157, 161, 165, 173, 181, 190, 198, 201, 206, 213, 220, 226, 235, 243, 251, 257, 261, 270, 277, 281, 284, 291, 299, 307, 314, 320, 323, 329, 336, 344, 348, 355, 363, 365, 367, 369, 371, 373, 375, 380, 385, 393, 396, 405, 408, 412, 420, 427, 436, 439, 442, 445, 448, 451, 454, 460, 463, 469, 472, 478, 482, 485, 489, 494, 499, 505, 510, 514, 519, 527, 535, 541, 550, 561, 568, 572, 579, 586, 594, 598, 602, 606, 613, 620, 628, 634, 639, 644}
+       _Op_index_1 = [...]uint8{0, 4, 12, 17, 22, 26, 29, 37, 41, 43, 48, 50, 55, 61, 67, 73, 79, 84, 88, 95, 101, 106, 112, 115, 121, 128, 133, 137, 142, 146, 156, 161, 169, 175, 182, 189, 195, 202, 208, 212, 215}
+)
 
 func (i Op) String() string {
-       if i >= Op(len(_Op_index)-1) {
+       switch {
+       case 0 <= i && i <= 112:
+               return _Op_name_0[_Op_index_0[i]:_Op_index_0[i+1]]
+       case 114 <= i && i <= 153:
+               i -= 114
+               return _Op_name_1[_Op_index_1[i]:_Op_index_1[i+1]]
+       default:
                return "Op(" + strconv.FormatInt(int64(i), 10) + ")"
        }
-       return _Op_name[_Op_index[i]:_Op_index[i+1]]
 }
index ee04b69a680399d20dce63b7dc4d504f6575ddca..e6350ef721e1d3a194ce14663adff866d2a911a9 100644 (file)
@@ -779,7 +779,7 @@ func (o *Order) stmt(n *Node) {
                t := o.markTemp()
 
                for _, n2 := range n.List.Slice() {
-                       if n2.Op != OXCASE {
+                       if n2.Op != OCASE {
                                Fatalf("order select case %v", n2.Op)
                        }
                        r := n2.Left
@@ -938,7 +938,7 @@ func (o *Order) stmt(n *Node) {
                t := o.markTemp()
                n.Left = o.expr(n.Left, nil)
                for _, ncas := range n.List.Slice() {
-                       if ncas.Op != OXCASE {
+                       if ncas.Op != OCASE {
                                Fatalf("order switch case %v", ncas.Op)
                        }
                        o.exprListInPlace(ncas.List)
index e0ed1e2a9f320a4be0febbe89f2bb19bbdabfb9f..07c5c5a2a963cef17e4dcf68c08287f2e210ba26 100644 (file)
@@ -12,7 +12,7 @@ func typecheckselect(sel *Node) {
        lno := setlineno(sel)
        typecheckslice(sel.Ninit.Slice(), ctxStmt)
        for _, ncase := range sel.List.Slice() {
-               if ncase.Op != OXCASE {
+               if ncase.Op != OCASE {
                        setlineno(ncase)
                        Fatalf("typecheckselect %v", ncase.Op)
                }
index 004ff3c4c09d22685b5bd80f0286fa8088d5aad5..d53efefa7240ecf21c2e626311846b550615af17 100644 (file)
@@ -434,7 +434,7 @@ func allCaseExprsAreSideEffectFree(sw *Node) bool {
        // enough.
 
        for _, ncase := range sw.List.Slice() {
-               if ncase.Op != OXCASE {
+               if ncase.Op != OCASE {
                        Fatalf("switch string(byteslice) bad op: %v", ncase.Op)
                }
                for _, v := range ncase.List.Slice() {
index e8a527a8fcc44ce3184ba4ba104601aea36af033..e8900edd3a5731c678b80940e0547ff604a017af 100644 (file)
@@ -704,8 +704,8 @@ const (
        // statements
        OBLOCK    // { List } (block of code)
        OBREAK    // break [Sym]
-       OCASE     // case Left or List[0]..List[1]: Nbody (select case after processing; Left==nil and List==nil means default)
-       OXCASE    // case List: Nbody (select case before processing; List==nil means default)
+       _         // For toolstash -cmp. TODO(mdempsky): Remove.
+       OCASE     // case List: Nbody (List==nil means default)
        OCONTINUE // continue [Sym]
        ODEFER    // defer Left (Left must be call)
        OEMPTY    // no-op (empty statement)
@@ -727,8 +727,8 @@ const (
        OGO     // go Left (Left must be call)
        ORANGE  // for List = range Right { Nbody }
        ORETURN // return List
-       OSELECT // select { List } (List is list of OXCASE or OCASE)
-       OSWITCH // switch Ninit; Left { List } (List is a list of OXCASE or OCASE)
+       OSELECT // select { List } (List is list of OCASE)
+       OSWITCH // switch Ninit; Left { List } (List is a list of OCASE)
        OTYPESW // Left = Right.(type) (appears as .Left of OSWITCH)
 
        // types
index 050a74b1e60938c23f09d83ffda9ffeb0bba6d00..48a3e1100e0fba0ea634461f54422918ca2642ca 100644 (file)
@@ -2014,7 +2014,7 @@ func typecheck1(n *Node, top int) (res *Node) {
                n.Type = nil
                return n
 
-       case OXCASE:
+       case OCASE:
                ok |= ctxStmt
                typecheckslice(n.List.Slice(), ctxExpr)
                typecheckslice(n.Nbody.Slice(), ctxStmt)
index 8dd60f4285a20333cbe7fbb3652d978cede34087..4c89ae639babbe5d0bfec7b7d9f87eccd8bc74ef 100644 (file)
@@ -209,13 +209,8 @@ func walkstmt(n *Node) *Node {
        case OBLOCK:
                walkstmtlist(n.List.Slice())
 
-       case OXCASE:
-               yyerror("case statement out of place")
-               n.Op = OCASE
-               fallthrough
-
        case OCASE:
-               n.Right = walkstmt(n.Right)
+               yyerror("case statement out of place")
 
        case ODEFER:
                Curfn.Func.SetHasDefer(true)