mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: don't export unneeded OAS, OASWB nodes
Also: - "rewrite" node Op in exporter for some nodes instead of importer - more comments Change-Id: I809e6754d14987b28f1da9379951ffa2e690c2a7 Reviewed-on: https://go-review.googlesource.com/22008 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
44f80f6d49
commit
6e5027a37a
2 changed files with 36 additions and 32 deletions
|
|
@ -783,7 +783,11 @@ func (p *exporter) param(q *Field, n int, numbered bool) {
|
|||
// supply the parameter package here. We need the package
|
||||
// when the function is inlined so we can properly resolve
|
||||
// the name.
|
||||
// TODO(gri) should do this only once per function/method
|
||||
// TODO(gri) This is compiler-specific. Try using importpkg
|
||||
// here and then update the symbols if we find an inlined
|
||||
// body only. Otherwise, the parameter name is ignored and
|
||||
// the package doesn't matter. This would remove an int
|
||||
// (likely 1 byte) for each named parameter.
|
||||
p.pkg(q.Sym.Pkg)
|
||||
}
|
||||
// TODO(gri) This is compiler-specific (escape info).
|
||||
|
|
@ -1266,12 +1270,11 @@ func (p *exporter) stmt(n *Node) {
|
|||
// unimplemented - handled by default case
|
||||
|
||||
case OAS, OASWB:
|
||||
p.op(op)
|
||||
// Don't export "v = <N>" initializing statements, hope they're always
|
||||
// preceded by the DCL which will be re-parsed and typecheck to reproduce
|
||||
// the "v = <N>" again.
|
||||
// TODO(gri) if n.Right == nil, don't emit anything
|
||||
if p.bool(n.Right != nil) {
|
||||
if n.Right != nil {
|
||||
p.op(OAS)
|
||||
p.expr(n.Left)
|
||||
p.expr(n.Right)
|
||||
}
|
||||
|
|
@ -1284,16 +1287,14 @@ func (p *exporter) stmt(n *Node) {
|
|||
p.expr(n.Right)
|
||||
}
|
||||
|
||||
case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
|
||||
fallthrough
|
||||
|
||||
case OAS2:
|
||||
p.op(OAS2)
|
||||
p.exprList(n.List)
|
||||
p.exprList(n.Rlist)
|
||||
|
||||
case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
|
||||
p.op(op)
|
||||
p.exprList(n.List)
|
||||
p.exprList(n.Rlist)
|
||||
|
||||
case ORETURN:
|
||||
p.op(ORETURN)
|
||||
p.exprList(n.List)
|
||||
|
|
@ -1332,11 +1333,15 @@ func (p *exporter) stmt(n *Node) {
|
|||
p.stmtList(n.List)
|
||||
|
||||
case OCASE, OXCASE:
|
||||
p.op(op)
|
||||
p.op(OXCASE)
|
||||
p.stmtList(n.List)
|
||||
p.stmtList(n.Nbody)
|
||||
|
||||
case OBREAK, OCONTINUE, OGOTO, OFALL, OXFALL:
|
||||
case OFALL:
|
||||
op = OXFALL
|
||||
fallthrough
|
||||
|
||||
case OBREAK, OCONTINUE, OGOTO, OXFALL:
|
||||
p.op(op)
|
||||
p.exprsOrNil(n.Left, nil)
|
||||
|
||||
|
|
|
|||
|
|
@ -626,6 +626,10 @@ func (p *importer) float(x *Mpflt) {
|
|||
// re-establish the syntax tree's invariants. At some future point we might be
|
||||
// able to avoid this round-about way and create the rewritten nodes directly,
|
||||
// possibly avoiding a lot of duplicate work (name resolution, type checking).
|
||||
//
|
||||
// Refined nodes (e.g., ODOTPTR as a refinement of OXDOT) are exported as their
|
||||
// unrefined nodes (since this is what the importer uses). The respective case
|
||||
// entries are unreachable in the importer.
|
||||
|
||||
func (p *importer) stmtList() []*Node {
|
||||
var list []*Node
|
||||
|
|
@ -871,14 +875,11 @@ func (p *importer) node() *Node {
|
|||
// case ODCLFIELD:
|
||||
// unimplemented
|
||||
|
||||
case OAS, OASWB:
|
||||
if p.bool() {
|
||||
lhs := p.expr()
|
||||
rhs := p.expr()
|
||||
return Nod(OAS, lhs, rhs)
|
||||
}
|
||||
// TODO(gri) we should not have emitted anything here
|
||||
return Nod(OEMPTY, nil, nil)
|
||||
// case OAS, OASWB:
|
||||
// unreachable - mapped to OAS case below by exporter
|
||||
|
||||
case OAS:
|
||||
return Nod(OAS, p.expr(), p.expr())
|
||||
|
||||
case OASOP:
|
||||
n := Nod(OASOP, nil, nil)
|
||||
|
|
@ -892,15 +893,10 @@ func (p *importer) node() *Node {
|
|||
}
|
||||
return n
|
||||
|
||||
case OAS2:
|
||||
lhs := p.exprList()
|
||||
rhs := p.exprList()
|
||||
n := Nod(OAS2, nil, nil)
|
||||
n.List.Set(lhs)
|
||||
n.Rlist.Set(rhs)
|
||||
return n
|
||||
// case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
|
||||
// unreachable - mapped to OAS2 case below by exporter
|
||||
|
||||
case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
|
||||
case OAS2:
|
||||
n := Nod(OAS2, nil, nil)
|
||||
n.List.Set(p.exprList())
|
||||
n.Rlist.Set(p.exprList())
|
||||
|
|
@ -954,7 +950,10 @@ func (p *importer) node() *Node {
|
|||
popdcl()
|
||||
return n
|
||||
|
||||
case OCASE, OXCASE:
|
||||
// case OCASE, OXCASE:
|
||||
// unreachable - mapped to OXCASE case below by exporter
|
||||
|
||||
case OXCASE:
|
||||
markdcl()
|
||||
n := Nod(OXCASE, nil, nil)
|
||||
n.List.Set(p.exprList())
|
||||
|
|
@ -964,10 +963,10 @@ func (p *importer) node() *Node {
|
|||
popdcl()
|
||||
return n
|
||||
|
||||
case OBREAK, OCONTINUE, OGOTO, OFALL, OXFALL:
|
||||
if op == OFALL {
|
||||
op = OXFALL
|
||||
}
|
||||
// case OFALL:
|
||||
// unreachable - mapped to OXFALL case below by exporter
|
||||
|
||||
case OBREAK, OCONTINUE, OGOTO, OXFALL:
|
||||
left, _ := p.exprsOrNil()
|
||||
return Nod(op, left, nil)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue