Commit ef62f641 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: use ONAME instead of OPACK in binary export format

This is addressing feedback given on golang.org/cl/23052;
we do it in a separate CL to separate the functional from
the rename change.

ONAME was not used in the export data, but it's the natural node op
where we used OPACK instead. Renamed.

Furthermore, OPACK and ONONAME nodes are replaced by the type checker
with ONAME nodes, so OPACK nodes cannot occur when exporting type-checked
code. Removed a special-case for OPACK nodes since they don't appear.

Change-Id: I78b01a1badbf60e9283eaadeca2578a65d28cbd2
Reviewed-on: https://go-review.googlesource.com/23053
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent aff48890
...@@ -1157,15 +1157,13 @@ func (p *exporter) expr(n *Node) { ...@@ -1157,15 +1157,13 @@ func (p *exporter) expr(n *Node) {
// Special case: name used as local variable in export. // Special case: name used as local variable in export.
// _ becomes ~b%d internally; print as _ for export // _ becomes ~b%d internally; print as _ for export
if n.Sym != nil && n.Sym.Name[0] == '~' && n.Sym.Name[1] == 'b' { if n.Sym != nil && n.Sym.Name[0] == '~' && n.Sym.Name[1] == 'b' {
// case 0: mapped to OPACK p.op(ONAME)
p.op(OPACK)
p.string("_") // inlined and customized version of p.sym(n) p.string("_") // inlined and customized version of p.sym(n)
break break
} }
if n.Sym != nil && !isblank(n) && n.Name.Vargen > 0 { if n.Sym != nil && !isblank(n) && n.Name.Vargen > 0 {
// case 1: mapped to OPACK p.op(ONAME)
p.op(OPACK)
p.sym(n) p.sym(n)
break break
} }
...@@ -1174,20 +1172,18 @@ func (p *exporter) expr(n *Node) { ...@@ -1174,20 +1172,18 @@ func (p *exporter) expr(n *Node) {
// but for export, this should be rendered as (*pkg.T).meth. // but for export, this should be rendered as (*pkg.T).meth.
// These nodes have the special property that they are names with a left OTYPE and a right ONAME. // These nodes have the special property that they are names with a left OTYPE and a right ONAME.
if n.Left != nil && n.Left.Op == OTYPE && n.Right != nil && n.Right.Op == ONAME { if n.Left != nil && n.Left.Op == OTYPE && n.Right != nil && n.Right.Op == ONAME {
// case 2: mapped to OXDOT
p.op(OXDOT) p.op(OXDOT)
p.expr(n.Left) // n.Left.Op == OTYPE p.expr(n.Left) // n.Left.Op == OTYPE
p.fieldSym(n.Right.Sym, true) p.fieldSym(n.Right.Sym, true)
break break
} }
// case 3: mapped to OPACK p.op(ONAME)
fallthrough
case OPACK, ONONAME:
p.op(OPACK)
p.sym(n) p.sym(n)
// case OPACK, ONONAME:
// should have been resolved by typechecking - handled by default case
case OTYPE: case OTYPE:
p.op(OTYPE) p.op(OTYPE)
if p.bool(n.Type == nil) { if p.bool(n.Type == nil) {
...@@ -1400,10 +1396,7 @@ func (p *exporter) stmt(n *Node) { ...@@ -1400,10 +1396,7 @@ func (p *exporter) stmt(n *Node) {
p.expr(n.Right) p.expr(n.Right)
} }
case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV: case OAS2, OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
fallthrough
case OAS2:
p.op(OAS2) p.op(OAS2)
p.exprList(n.List) p.exprList(n.List)
p.exprList(n.Rlist) p.exprList(n.Rlist)
......
...@@ -798,12 +798,12 @@ func (p *importer) node() *Node { ...@@ -798,12 +798,12 @@ func (p *importer) node() *Node {
} }
return n return n
// case ONAME, OPACK, ONONAME: case ONAME:
// unreachable - mapped to case OPACK below by exporter
case OPACK:
return mkname(p.sym()) return mkname(p.sym())
// case OPACK, ONONAME:
// unreachable - should have been resolved by typechecking
case OTYPE: case OTYPE:
if p.bool() { if p.bool() {
return mkname(p.sym()) return mkname(p.sym())
...@@ -854,14 +854,7 @@ func (p *importer) node() *Node { ...@@ -854,14 +854,7 @@ func (p *importer) node() *Node {
case OXDOT: case OXDOT:
// see parser.new_dotname // see parser.new_dotname
obj := p.expr() return NodSym(OXDOT, p.expr(), p.fieldSym())
sel := p.fieldSym()
if obj.Op == OPACK {
s := restrictlookup(sel.Name, obj.Name.Pkg)
obj.Used = true
return oldname(s)
}
return NodSym(OXDOT, obj, sel)
// case ODOTTYPE, ODOTTYPE2: // case ODOTTYPE, ODOTTYPE2:
// unreachable - mapped to case ODOTTYPE below by exporter // unreachable - mapped to case ODOTTYPE below by exporter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment