mirror of
https://github.com/golang/go
synced 2024-11-18 15:44:41 -07:00
cmd/compile: remove OCASE and rename OXCASE to OCASE
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>
This commit is contained in:
parent
1b2c794896
commit
2fc6366fb5
@ -1035,7 +1035,7 @@ func (n *Node) stmtfmt(s fmt.State, mode fmtMode) {
|
|||||||
|
|
||||||
mode.Fprintf(s, " { %v }", n.List)
|
mode.Fprintf(s, " { %v }", n.List)
|
||||||
|
|
||||||
case OXCASE:
|
case OCASE:
|
||||||
if n.List.Len() != 0 {
|
if n.List.Len() != 0 {
|
||||||
mode.Fprintf(s, "case %.v", n.List)
|
mode.Fprintf(s, "case %.v", n.List)
|
||||||
} else {
|
} else {
|
||||||
@ -1043,22 +1043,6 @@ func (n *Node) stmtfmt(s fmt.State, mode fmtMode) {
|
|||||||
}
|
}
|
||||||
mode.Fprintf(s, ": %v", n.Nbody)
|
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:
|
case OBREAK, OCONTINUE, OGOTO, OFALL:
|
||||||
if n.Sym != nil {
|
if n.Sym != nil {
|
||||||
mode.Fprintf(s, "%#v %v", n.Op, n.Sym)
|
mode.Fprintf(s, "%#v %v", n.Op, n.Sym)
|
||||||
@ -1192,7 +1176,6 @@ var opprec = []int{
|
|||||||
ORETURN: -1,
|
ORETURN: -1,
|
||||||
OSELECT: -1,
|
OSELECT: -1,
|
||||||
OSWITCH: -1,
|
OSWITCH: -1,
|
||||||
OXCASE: -1,
|
|
||||||
|
|
||||||
OEND: 0,
|
OEND: 0,
|
||||||
}
|
}
|
||||||
|
@ -1079,8 +1079,8 @@ func (w *exportWriter) stmt(n *Node) {
|
|||||||
w.exprsOrNil(n.Left, nil)
|
w.exprsOrNil(n.Left, nil)
|
||||||
w.stmtList(n.List)
|
w.stmtList(n.List)
|
||||||
|
|
||||||
case OCASE, OXCASE:
|
case OCASE:
|
||||||
w.op(OXCASE)
|
w.op(OCASE)
|
||||||
w.pos(n.Pos)
|
w.pos(n.Pos)
|
||||||
w.stmtList(n.List)
|
w.stmtList(n.List)
|
||||||
w.stmtList(n.Nbody)
|
w.stmtList(n.Nbody)
|
||||||
|
@ -1003,20 +1003,14 @@ func (r *importReader) node() *Node {
|
|||||||
n.List.Set(r.stmtList())
|
n.List.Set(r.stmtList())
|
||||||
return n
|
return n
|
||||||
|
|
||||||
// case OCASE, OXCASE:
|
case OCASE:
|
||||||
// unreachable - mapped to OXCASE case below by exporter
|
n := nodl(r.pos(), OCASE, nil, nil)
|
||||||
|
|
||||||
case OXCASE:
|
|
||||||
n := nodl(r.pos(), OXCASE, nil, nil)
|
|
||||||
n.List.Set(r.exprList())
|
n.List.Set(r.exprList())
|
||||||
// TODO(gri) eventually we must declare variables for type switch
|
// TODO(gri) eventually we must declare variables for type switch
|
||||||
// statements (type switch statements are not yet exported)
|
// statements (type switch statements are not yet exported)
|
||||||
n.Nbody.Set(r.stmtList())
|
n.Nbody.Set(r.stmtList())
|
||||||
return n
|
return n
|
||||||
|
|
||||||
// case OFALL:
|
|
||||||
// unreachable - mapped to OXFALL case below by exporter
|
|
||||||
|
|
||||||
case OFALL:
|
case OFALL:
|
||||||
n := nodl(r.pos(), OFALL, nil, nil)
|
n := nodl(r.pos(), OFALL, nil, nil)
|
||||||
return n
|
return n
|
||||||
|
@ -1188,7 +1188,7 @@ func (p *noder) caseClauses(clauses []*syntax.CaseClause, tswitch *Node, rbrace
|
|||||||
}
|
}
|
||||||
p.openScope(clause.Pos())
|
p.openScope(clause.Pos())
|
||||||
|
|
||||||
n := p.nod(clause, OXCASE, nil, nil)
|
n := p.nod(clause, OCASE, nil, nil)
|
||||||
if clause.Cases != nil {
|
if clause.Cases != nil {
|
||||||
n.List.Set(p.exprList(clause.Cases))
|
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())
|
p.openScope(clause.Pos())
|
||||||
|
|
||||||
n := p.nod(clause, OXCASE, nil, nil)
|
n := p.nod(clause, OCASE, nil, nil)
|
||||||
if clause.Comm != nil {
|
if clause.Comm != nil {
|
||||||
n.List.Set1(p.stmt(clause.Comm))
|
n.List.Set1(p.stmt(clause.Comm))
|
||||||
}
|
}
|
||||||
|
@ -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
|
package gc
|
||||||
|
|
||||||
@ -121,8 +121,7 @@ func _() {
|
|||||||
_ = x[OSIZEOF-110]
|
_ = x[OSIZEOF-110]
|
||||||
_ = x[OBLOCK-111]
|
_ = x[OBLOCK-111]
|
||||||
_ = x[OBREAK-112]
|
_ = x[OBREAK-112]
|
||||||
_ = x[OCASE-113]
|
_ = x[OCASE-114]
|
||||||
_ = x[OXCASE-114]
|
|
||||||
_ = x[OCONTINUE-115]
|
_ = x[OCONTINUE-115]
|
||||||
_ = x[ODEFER-116]
|
_ = x[ODEFER-116]
|
||||||
_ = x[OEMPTY-117]
|
_ = x[OEMPTY-117]
|
||||||
@ -164,13 +163,24 @@ func _() {
|
|||||||
_ = x[OEND-153]
|
_ = 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 {
|
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(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
return _Op_name[_Op_index[i]:_Op_index[i+1]]
|
|
||||||
}
|
}
|
||||||
|
@ -779,7 +779,7 @@ func (o *Order) stmt(n *Node) {
|
|||||||
t := o.markTemp()
|
t := o.markTemp()
|
||||||
|
|
||||||
for _, n2 := range n.List.Slice() {
|
for _, n2 := range n.List.Slice() {
|
||||||
if n2.Op != OXCASE {
|
if n2.Op != OCASE {
|
||||||
Fatalf("order select case %v", n2.Op)
|
Fatalf("order select case %v", n2.Op)
|
||||||
}
|
}
|
||||||
r := n2.Left
|
r := n2.Left
|
||||||
@ -938,7 +938,7 @@ func (o *Order) stmt(n *Node) {
|
|||||||
t := o.markTemp()
|
t := o.markTemp()
|
||||||
n.Left = o.expr(n.Left, nil)
|
n.Left = o.expr(n.Left, nil)
|
||||||
for _, ncas := range n.List.Slice() {
|
for _, ncas := range n.List.Slice() {
|
||||||
if ncas.Op != OXCASE {
|
if ncas.Op != OCASE {
|
||||||
Fatalf("order switch case %v", ncas.Op)
|
Fatalf("order switch case %v", ncas.Op)
|
||||||
}
|
}
|
||||||
o.exprListInPlace(ncas.List)
|
o.exprListInPlace(ncas.List)
|
||||||
|
@ -12,7 +12,7 @@ func typecheckselect(sel *Node) {
|
|||||||
lno := setlineno(sel)
|
lno := setlineno(sel)
|
||||||
typecheckslice(sel.Ninit.Slice(), ctxStmt)
|
typecheckslice(sel.Ninit.Slice(), ctxStmt)
|
||||||
for _, ncase := range sel.List.Slice() {
|
for _, ncase := range sel.List.Slice() {
|
||||||
if ncase.Op != OXCASE {
|
if ncase.Op != OCASE {
|
||||||
setlineno(ncase)
|
setlineno(ncase)
|
||||||
Fatalf("typecheckselect %v", ncase.Op)
|
Fatalf("typecheckselect %v", ncase.Op)
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ func allCaseExprsAreSideEffectFree(sw *Node) bool {
|
|||||||
// enough.
|
// enough.
|
||||||
|
|
||||||
for _, ncase := range sw.List.Slice() {
|
for _, ncase := range sw.List.Slice() {
|
||||||
if ncase.Op != OXCASE {
|
if ncase.Op != OCASE {
|
||||||
Fatalf("switch string(byteslice) bad op: %v", ncase.Op)
|
Fatalf("switch string(byteslice) bad op: %v", ncase.Op)
|
||||||
}
|
}
|
||||||
for _, v := range ncase.List.Slice() {
|
for _, v := range ncase.List.Slice() {
|
||||||
|
@ -704,8 +704,8 @@ const (
|
|||||||
// statements
|
// statements
|
||||||
OBLOCK // { List } (block of code)
|
OBLOCK // { List } (block of code)
|
||||||
OBREAK // break [Sym]
|
OBREAK // break [Sym]
|
||||||
OCASE // case Left or List[0]..List[1]: Nbody (select case after processing; Left==nil and List==nil means default)
|
_ // For toolstash -cmp. TODO(mdempsky): Remove.
|
||||||
OXCASE // case List: Nbody (select case before processing; List==nil means default)
|
OCASE // case List: Nbody (List==nil means default)
|
||||||
OCONTINUE // continue [Sym]
|
OCONTINUE // continue [Sym]
|
||||||
ODEFER // defer Left (Left must be call)
|
ODEFER // defer Left (Left must be call)
|
||||||
OEMPTY // no-op (empty statement)
|
OEMPTY // no-op (empty statement)
|
||||||
@ -727,8 +727,8 @@ const (
|
|||||||
OGO // go Left (Left must be call)
|
OGO // go Left (Left must be call)
|
||||||
ORANGE // for List = range Right { Nbody }
|
ORANGE // for List = range Right { Nbody }
|
||||||
ORETURN // return List
|
ORETURN // return List
|
||||||
OSELECT // select { List } (List is list of OXCASE or OCASE)
|
OSELECT // select { List } (List is list of OCASE)
|
||||||
OSWITCH // switch Ninit; Left { List } (List is a list of OXCASE or OCASE)
|
OSWITCH // switch Ninit; Left { List } (List is a list of OCASE)
|
||||||
OTYPESW // Left = Right.(type) (appears as .Left of OSWITCH)
|
OTYPESW // Left = Right.(type) (appears as .Left of OSWITCH)
|
||||||
|
|
||||||
// types
|
// types
|
||||||
|
@ -2014,7 +2014,7 @@ func typecheck1(n *Node, top int) (res *Node) {
|
|||||||
n.Type = nil
|
n.Type = nil
|
||||||
return n
|
return n
|
||||||
|
|
||||||
case OXCASE:
|
case OCASE:
|
||||||
ok |= ctxStmt
|
ok |= ctxStmt
|
||||||
typecheckslice(n.List.Slice(), ctxExpr)
|
typecheckslice(n.List.Slice(), ctxExpr)
|
||||||
typecheckslice(n.Nbody.Slice(), ctxStmt)
|
typecheckslice(n.Nbody.Slice(), ctxStmt)
|
||||||
|
@ -209,13 +209,8 @@ func walkstmt(n *Node) *Node {
|
|||||||
case OBLOCK:
|
case OBLOCK:
|
||||||
walkstmtlist(n.List.Slice())
|
walkstmtlist(n.List.Slice())
|
||||||
|
|
||||||
case OXCASE:
|
|
||||||
yyerror("case statement out of place")
|
|
||||||
n.Op = OCASE
|
|
||||||
fallthrough
|
|
||||||
|
|
||||||
case OCASE:
|
case OCASE:
|
||||||
n.Right = walkstmt(n.Right)
|
yyerror("case statement out of place")
|
||||||
|
|
||||||
case ODEFER:
|
case ODEFER:
|
||||||
Curfn.Func.SetHasDefer(true)
|
Curfn.Func.SetHasDefer(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user