// 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).
// 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)
}
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)
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)
// 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
// 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)
}
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())
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())
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)