1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:41:36 -07:00

[dev.regabi] cmd/compile: change noder.declNames to returns ir.Names

declNames always returns a slice of *ir.Names, so return that directly
rather than as []ir.Node.

While here, also change iimport to directly create ir.ODCL/ir.OAS
statements, rather than calling variter. Allows eliminating a use of
ir.TypeNode.

Passes buildall w/ toolstash -cmp.

Change-Id: Icb75e993c4957b6050c797ba64ee71cfb7a19644
Reviewed-on: https://go-review.googlesource.com/c/go/+/279315
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Matthew Dempsky 2020-12-18 20:49:50 -08:00
parent 301af2cb71
commit 2755361e6a
4 changed files with 20 additions and 19 deletions

View File

@ -130,17 +130,16 @@ func declare(n *ir.Name, ctxt ir.Class) {
// declare variables from grammar
// new_name_list (type | [type] = expr_list)
func variter(vl []ir.Node, t ir.Ntype, el []ir.Node) []ir.Node {
func variter(vl []*ir.Name, t ir.Ntype, el []ir.Node) []ir.Node {
var init []ir.Node
doexpr := len(el) > 0
if len(el) == 1 && len(vl) > 1 {
e := el[0]
as2 := ir.Nod(ir.OAS2, nil, nil)
as2.PtrList().Set(vl)
as2.PtrRlist().Set1(e)
for _, v := range vl {
v := v.(*ir.Name)
as2.PtrList().Append(v)
declare(v, dclcontext)
v.Ntype = t
v.Defn = as2
@ -152,17 +151,14 @@ func variter(vl []ir.Node, t ir.Ntype, el []ir.Node) []ir.Node {
return append(init, as2)
}
nel := len(el)
for _, v := range vl {
v := v.(*ir.Name)
for i, v := range vl {
var e ir.Node
if doexpr {
if len(el) == 0 {
base.Errorf("assignment mismatch: %d variables but %d values", len(vl), nel)
if i >= len(el) {
base.Errorf("assignment mismatch: %d variables but %d values", len(vl), len(el))
break
}
e = el[0]
el = el[1:]
e = el[i]
}
declare(v, dclcontext)
@ -180,8 +176,8 @@ func variter(vl []ir.Node, t ir.Ntype, el []ir.Node) []ir.Node {
}
}
if len(el) != 0 {
base.Errorf("assignment mismatch: %d variables but %d values", len(vl), nel)
if len(el) > len(vl) {
base.Errorf("assignment mismatch: %d variables but %d values", len(vl), len(el))
}
return init
}

View File

@ -24,7 +24,7 @@ const (
embedFiles
)
func varEmbed(p *noder, names []ir.Node, typ ir.Ntype, exprs []ir.Node, embeds []PragmaEmbed) (newExprs []ir.Node) {
func varEmbed(p *noder, names []*ir.Name, typ ir.Ntype, exprs []ir.Node, embeds []PragmaEmbed) (newExprs []ir.Node) {
haveEmbed := false
for _, decl := range p.file.DeclList {
imp, ok := decl.(*syntax.ImportDecl)
@ -66,7 +66,7 @@ func varEmbed(p *noder, names []ir.Node, typ ir.Ntype, exprs []ir.Node, embeds [
return exprs
}
v := names[0].(*ir.Name)
v := names[0]
Target.Embeds = append(Target.Embeds, v)
v.Embed = new([]ir.Embed)
for _, e := range embeds {

View File

@ -972,8 +972,14 @@ func (r *importReader) node() ir.Node {
case ir.ODCL:
pos := r.pos()
lhs := ir.NewDeclNameAt(pos, ir.ONAME, r.ident())
typ := ir.TypeNode(r.typ())
return npos(pos, liststmt(variter([]ir.Node{lhs}, typ, nil))) // TODO(gri) avoid list creation
lhs.SetType(r.typ())
declare(lhs, ir.PAUTO)
var stmts ir.Nodes
stmts.Append(ir.Nod(ir.ODCL, lhs, nil))
stmts.Append(ir.Nod(ir.OAS, lhs, nil))
return npos(pos, liststmt(stmts.Slice()))
// case OAS, OASWB:
// unreachable - mapped to OAS case below by exporter

View File

@ -441,7 +441,6 @@ func (p *noder) constDecl(decl *syntax.ConstDecl, cs *constState) []ir.Node {
nn := make([]ir.Node, 0, len(names))
for i, n := range names {
n := n.(*ir.Name)
if i >= len(values) {
base.Errorf("missing value in const declaration")
break
@ -492,8 +491,8 @@ func (p *noder) typeDecl(decl *syntax.TypeDecl) ir.Node {
return nod
}
func (p *noder) declNames(op ir.Op, names []*syntax.Name) []ir.Node {
nodes := make([]ir.Node, 0, len(names))
func (p *noder) declNames(op ir.Op, names []*syntax.Name) []*ir.Name {
nodes := make([]*ir.Name, 0, len(names))
for _, name := range names {
nodes = append(nodes, p.declName(op, name))
}