aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2019-09-17 18:32:04 -0700
committerMatthew Dempsky <mdempsky@google.com>2019-09-18 02:31:34 +0000
commit2fc6366fb56aa77efa3cecd44ce941472786a418 (patch)
tree5f318cc0351f408ed8d34dc0b246a5ef1c77c98e
parent1b2c7948963543286516f78f0b0d52956f58d82c (diff)
downloadgo-2fc6366fb56aa77efa3cecd44ce941472786a418.tar.xz
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>
-rw-r--r--src/cmd/compile/internal/gc/fmt.go19
-rw-r--r--src/cmd/compile/internal/gc/iexport.go4
-rw-r--r--src/cmd/compile/internal/gc/iimport.go10
-rw-r--r--src/cmd/compile/internal/gc/noder.go4
-rw-r--r--src/cmd/compile/internal/gc/op_string.go24
-rw-r--r--src/cmd/compile/internal/gc/order.go4
-rw-r--r--src/cmd/compile/internal/gc/select.go2
-rw-r--r--src/cmd/compile/internal/gc/swt.go2
-rw-r--r--src/cmd/compile/internal/gc/syntax.go8
-rw-r--r--src/cmd/compile/internal/gc/typecheck.go2
-rw-r--r--src/cmd/compile/internal/gc/walk.go7
11 files changed, 34 insertions, 52 deletions
diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go
index 53d6b9d2cc..cb6b571f83 100644
--- a/src/cmd/compile/internal/gc/fmt.go
+++ b/src/cmd/compile/internal/gc/fmt.go
@@ -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,
}
diff --git a/src/cmd/compile/internal/gc/iexport.go b/src/cmd/compile/internal/gc/iexport.go
index 0e5a313baf..eeca0b4083 100644
--- a/src/cmd/compile/internal/gc/iexport.go
+++ b/src/cmd/compile/internal/gc/iexport.go
@@ -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)
diff --git a/src/cmd/compile/internal/gc/iimport.go b/src/cmd/compile/internal/gc/iimport.go
index 7d134f3a5f..4862f86344 100644
--- a/src/cmd/compile/internal/gc/iimport.go
+++ b/src/cmd/compile/internal/gc/iimport.go
@@ -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
diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go
index 6bbabb45dd..91c7fd49b1 100644
--- a/src/cmd/compile/internal/gc/noder.go
+++ b/src/cmd/compile/internal/gc/noder.go
@@ -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))
}
diff --git a/src/cmd/compile/internal/gc/op_string.go b/src/cmd/compile/internal/gc/op_string.go
index 796e13a071..1586c70f1b 100644
--- a/src/cmd/compile/internal/gc/op_string.go
+++ b/src/cmd/compile/internal/gc/op_string.go
@@ -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]]
}
diff --git a/src/cmd/compile/internal/gc/order.go b/src/cmd/compile/internal/gc/order.go
index ee04b69a68..e6350ef721 100644
--- a/src/cmd/compile/internal/gc/order.go
+++ b/src/cmd/compile/internal/gc/order.go
@@ -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)
diff --git a/src/cmd/compile/internal/gc/select.go b/src/cmd/compile/internal/gc/select.go
index e0ed1e2a9f..07c5c5a2a9 100644
--- a/src/cmd/compile/internal/gc/select.go
+++ b/src/cmd/compile/internal/gc/select.go
@@ -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)
}
diff --git a/src/cmd/compile/internal/gc/swt.go b/src/cmd/compile/internal/gc/swt.go
index 004ff3c4c0..d53efefa72 100644
--- a/src/cmd/compile/internal/gc/swt.go
+++ b/src/cmd/compile/internal/gc/swt.go
@@ -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() {
diff --git a/src/cmd/compile/internal/gc/syntax.go b/src/cmd/compile/internal/gc/syntax.go
index e8a527a8fc..e8900edd3a 100644
--- a/src/cmd/compile/internal/gc/syntax.go
+++ b/src/cmd/compile/internal/gc/syntax.go
@@ -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
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go
index 050a74b1e6..48a3e1100e 100644
--- a/src/cmd/compile/internal/gc/typecheck.go
+++ b/src/cmd/compile/internal/gc/typecheck.go
@@ -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)
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index 8dd60f4285..4c89ae639b 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -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)