aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2016-05-27 14:42:30 -0700
committerMatthew Dempsky <mdempsky@google.com>2016-08-16 14:32:06 -0700
commit4b1cc51518dc383a0b2826ad40ca4b59978c9440 (patch)
tree9cb0ba57a3e167f0052440e4aedee1aa1771b004
parent4f989a487d8812666f7f2dd3573122a1a6faa0ce (diff)
downloadgo-4b1cc51518dc383a0b2826ad40ca4b59978c9440.tar.gz
go-4b1cc51518dc383a0b2826ad40ca4b59978c9440.zip
cmd/compile/internal/syntax: simplify IfStmt
Change IfStmt's Else field from []Stmt to Stmt like in go/ast. Change-Id: I835577beaf12b6e5895bc93041c13403143b4d2d
-rw-r--r--src/cmd/compile/internal/syntax/nodes.go2
-rw-r--r--src/cmd/compile/internal/syntax/parser.go4
-rw-r--r--src/cmd/compile/internal/syntax/printer.go9
3 files changed, 4 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/syntax/nodes.go b/src/cmd/compile/internal/syntax/nodes.go
index f190e8aec9..0aeb3ddd60 100644
--- a/src/cmd/compile/internal/syntax/nodes.go
+++ b/src/cmd/compile/internal/syntax/nodes.go
@@ -336,7 +336,7 @@ type (
Init SimpleStmt
Cond Expr
Then []Stmt
- Else []Stmt
+ Else Stmt // either *IfStmt or *BlockStmt
stmt
}
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index d9cc96ed54..78df06f533 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -1634,9 +1634,9 @@ func (p *parser) ifStmt() *IfStmt {
if p.got(_Else) {
if p.tok == _If {
- s.Else = []Stmt{p.ifStmt()}
+ s.Else = p.ifStmt()
} else {
- s.Else = p.stmtBody("else clause")
+ s.Else = p.blockStmt()
}
}
diff --git a/src/cmd/compile/internal/syntax/printer.go b/src/cmd/compile/internal/syntax/printer.go
index 73459b27ad..ce3377afc1 100644
--- a/src/cmd/compile/internal/syntax/printer.go
+++ b/src/cmd/compile/internal/syntax/printer.go
@@ -534,14 +534,7 @@ func (p *printer) printRawNode(n Node) {
p.print(n.Cond, blank)
p.printBody(n.Then)
if n.Else != nil {
- p.print(blank, _Else, blank)
- if len(n.Else) == 1 {
- if n, ok := n.Else[0].(*IfStmt); ok {
- p.print(n)
- break
- }
- }
- p.printBody(n.Else)
+ p.print(blank, _Else, blank, n.Else)
}
case *SwitchStmt: