aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/noder.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-12-26 23:03:25 -0800
committerMatthew Dempsky <mdempsky@google.com>2020-12-28 08:02:30 +0000
commit3bdafb0d82c9908ae04d2765847754df0646df35 (patch)
tree58ace2f281109e01ec8a80eea335b29a9c72fc7d /src/cmd/compile/internal/noder/noder.go
parent2ecf52b841cd48e76df1fe721d29a972c22bf93f (diff)
downloadgo-3bdafb0d82c9908ae04d2765847754df0646df35.tar.gz
go-3bdafb0d82c9908ae04d2765847754df0646df35.zip
[dev.regabi] cmd/compile: remove CommStmt.List
Package syntax's parser already ensures that select communication clauses only have one statement, so there's no need for ir's CommStmt to need to represent more than one. Instead, noder can just directly populate Comm in the first place. Incidentally, this also revealed a latent issue in the inline-body exporter: we were exporting List (where the case statement is before type-checking), rather than Comm (where the case statement would be after type-checking, when export happens). Passes toolstash -cmp. Change-Id: Ib4eb711527bed297c7332c79ed6e6562a1db2cfa Reviewed-on: https://go-review.googlesource.com/c/go/+/280444 Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/noder.go')
-rw-r--r--src/cmd/compile/internal/noder/noder.go23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go
index ff699cd54d..19a88e21a2 100644
--- a/src/cmd/compile/internal/noder/noder.go
+++ b/src/cmd/compile/internal/noder/noder.go
@@ -1149,9 +1149,11 @@ func (p *noder) blockStmt(stmt *syntax.BlockStmt) []ir.Node {
func (p *noder) ifStmt(stmt *syntax.IfStmt) ir.Node {
p.openScope(stmt.Pos())
- init := p.simpleStmt(stmt.Init)
+ init := p.stmt(stmt.Init)
n := ir.NewIfStmt(p.pos(stmt), p.expr(stmt.Cond), p.blockStmt(stmt.Then), nil)
- *n.PtrInit() = init
+ if init != nil {
+ *n.PtrInit() = []ir.Node{init}
+ }
if stmt.Else != nil {
e := p.stmt(stmt.Else)
if e.Op() == ir.OBLOCK {
@@ -1186,7 +1188,7 @@ func (p *noder) forStmt(stmt *syntax.ForStmt) ir.Node {
return n
}
- n := ir.NewForStmt(p.pos(stmt), p.simpleStmt(stmt.Init), p.expr(stmt.Cond), p.stmt(stmt.Post), p.blockStmt(stmt.Body))
+ n := ir.NewForStmt(p.pos(stmt), p.stmt(stmt.Init), p.expr(stmt.Cond), p.stmt(stmt.Post), p.blockStmt(stmt.Body))
p.closeAnotherScope()
return n
}
@@ -1194,9 +1196,11 @@ func (p *noder) forStmt(stmt *syntax.ForStmt) ir.Node {
func (p *noder) switchStmt(stmt *syntax.SwitchStmt) ir.Node {
p.openScope(stmt.Pos())
- init := p.simpleStmt(stmt.Init)
+ init := p.stmt(stmt.Init)
n := ir.NewSwitchStmt(p.pos(stmt), p.expr(stmt.Tag), nil)
- *n.PtrInit() = init
+ if init != nil {
+ *n.PtrInit() = []ir.Node{init}
+ }
var tswitch *ir.TypeSwitchGuard
if l := n.Tag; l != nil && l.Op() == ir.OTYPESW {
@@ -1259,13 +1263,6 @@ func (p *noder) selectStmt(stmt *syntax.SelectStmt) ir.Node {
return ir.NewSelectStmt(p.pos(stmt), p.commClauses(stmt.Body, stmt.Rbrace))
}
-func (p *noder) simpleStmt(stmt syntax.SimpleStmt) []ir.Node {
- if stmt == nil {
- return nil
- }
- return []ir.Node{p.stmt(stmt)}
-}
-
func (p *noder) commClauses(clauses []*syntax.CommClause, rbrace syntax.Pos) []*ir.CommStmt {
nodes := make([]*ir.CommStmt, len(clauses))
for i, clause := range clauses {
@@ -1275,7 +1272,7 @@ func (p *noder) commClauses(clauses []*syntax.CommClause, rbrace syntax.Pos) []*
}
p.openScope(clause.Pos())
- nodes[i] = ir.NewCommStmt(p.pos(clause), p.simpleStmt(clause.Comm), p.stmts(clause.Body))
+ nodes[i] = ir.NewCommStmt(p.pos(clause), p.stmt(clause.Comm), p.stmts(clause.Body))
}
if len(clauses) > 0 {
p.closeScope(rbrace)