aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/iexport.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-12-23 01:15:58 -0800
committerMatthew Dempsky <mdempsky@google.com>2020-12-23 10:29:05 +0000
commit87a592b35602e89c55218d2a54a1e0dade5db7e2 (patch)
treeb1ff8f9e6ac2ad34d04d10f70d67c6a0097463e8 /src/cmd/compile/internal/typecheck/iexport.go
parent5898025026e3ec38451e86c7837f6faf3633cf27 (diff)
downloadgo-87a592b35602e89c55218d2a54a1e0dade5db7e2.tar.gz
go-87a592b35602e89c55218d2a54a1e0dade5db7e2.zip
[dev.regabi] cmd/compile: cleanup import/export code
Now that we have concrete AST node types and better constructor APIs, we can more cleanup a lot of the import code and some export code too. Passes toolstash -cmp. Change-Id: Ie3425d9dac11ac4245e5da675dd298984a926df4 Reviewed-on: https://go-review.googlesource.com/c/go/+/279954 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/iexport.go')
-rw-r--r--src/cmd/compile/internal/typecheck/iexport.go27
1 files changed, 6 insertions, 21 deletions
diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go
index 4ddee01b5a..95a100e6a5 100644
--- a/src/cmd/compile/internal/typecheck/iexport.go
+++ b/src/cmd/compile/internal/typecheck/iexport.go
@@ -1155,7 +1155,7 @@ func (w *exportWriter) stmt(n ir.Node) {
w.pos(n.Pos())
w.stmtList(n.Init())
w.exprsOrNil(nil, nil) // TODO(rsc): Delete (and fix importer).
- w.caseList(n)
+ w.caseList(n.Cases, false)
case ir.OSWITCH:
n := n.(*ir.SwitchStmt)
@@ -1163,7 +1163,7 @@ func (w *exportWriter) stmt(n ir.Node) {
w.pos(n.Pos())
w.stmtList(n.Init())
w.exprsOrNil(n.Tag, nil)
- w.caseList(n)
+ w.caseList(n.Cases, isNamedTypeSwitch(n.Tag))
// case OCASE:
// handled by caseList
@@ -1187,27 +1187,12 @@ func (w *exportWriter) stmt(n ir.Node) {
}
}
-func isNamedTypeSwitch(n ir.Node) bool {
- if n.Op() != ir.OSWITCH {
- return false
- }
- sw := n.(*ir.SwitchStmt)
- if sw.Tag == nil || sw.Tag.Op() != ir.OTYPESW {
- return false
- }
- guard := sw.Tag.(*ir.TypeSwitchGuard)
- return guard.Tag != nil
+func isNamedTypeSwitch(x ir.Node) bool {
+ guard, ok := x.(*ir.TypeSwitchGuard)
+ return ok && guard.Tag != nil
}
-func (w *exportWriter) caseList(sw ir.Node) {
- namedTypeSwitch := isNamedTypeSwitch(sw)
-
- var cases []ir.Node
- if sw.Op() == ir.OSWITCH {
- cases = sw.(*ir.SwitchStmt).Cases
- } else {
- cases = sw.(*ir.SelectStmt).Cases
- }
+func (w *exportWriter) caseList(cases []ir.Node, namedTypeSwitch bool) {
w.uint64(uint64(len(cases)))
for _, cas := range cases {
cas := cas.(*ir.CaseStmt)