1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:36:52 -07:00

[dev.regabi] cmd/compile: stop using ONONAME with Name

This CL changes NewDeclNameAt to take an Op argument to set the Op up
front, and updates all callers to provide the appropriate Op. This
allows dropping the Name.SetOp method.

Passes buildall w/ toolstash -cmp.

Change-Id: I20e580f62d3c8a81223d1c162327c11b37bbf3f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/279314
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Matthew Dempsky 2020-12-18 20:14:45 -08:00
parent cb4898a77d
commit 94cfeca0a5
6 changed files with 21 additions and 35 deletions

View File

@ -141,7 +141,6 @@ func variter(vl []ir.Node, t ir.Ntype, el []ir.Node) []ir.Node {
as2.PtrRlist().Set1(e) as2.PtrRlist().Set1(e)
for _, v := range vl { for _, v := range vl {
v := v.(*ir.Name) v := v.(*ir.Name)
v.SetOp(ir.ONAME)
declare(v, dclcontext) declare(v, dclcontext)
v.Ntype = t v.Ntype = t
v.Defn = as2 v.Defn = as2
@ -166,7 +165,6 @@ func variter(vl []ir.Node, t ir.Ntype, el []ir.Node) []ir.Node {
el = el[1:] el = el[1:]
} }
v.SetOp(ir.ONAME)
declare(v, dclcontext) declare(v, dclcontext)
v.Ntype = t v.Ntype = t

View File

@ -82,9 +82,8 @@ func importsym(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Cl
base.Fatalf("importsym of symbol that already exists: %v", n) base.Fatalf("importsym of symbol that already exists: %v", n)
} }
n := ir.NewDeclNameAt(pos, s) n := ir.NewDeclNameAt(pos, op, s)
n.SetOp(op) // TODO(mdempsky): Add as argument to NewDeclNameAt. n.SetClass(ctxt) // TODO(mdempsky): Move this into NewDeclNameAt too?
n.SetClass(ctxt)
s.SetPkgDef(n) s.SetPkgDef(n)
s.Importdef = ipkg s.Importdef = ipkg
return n return n

View File

@ -971,7 +971,7 @@ func (r *importReader) node() ir.Node {
// statements // statements
case ir.ODCL: case ir.ODCL:
pos := r.pos() pos := r.pos()
lhs := ir.NewDeclNameAt(pos, r.ident()) lhs := ir.NewDeclNameAt(pos, ir.ONAME, r.ident())
typ := ir.TypeNode(r.typ()) typ := ir.TypeNode(r.typ())
return npos(pos, liststmt(variter([]ir.Node{lhs}, typ, nil))) // TODO(gri) avoid list creation return npos(pos, liststmt(variter([]ir.Node{lhs}, typ, nil))) // TODO(gri) avoid list creation

View File

@ -374,7 +374,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
} }
func (p *noder) varDecl(decl *syntax.VarDecl) []ir.Node { func (p *noder) varDecl(decl *syntax.VarDecl) []ir.Node {
names := p.declNames(decl.NameList) names := p.declNames(ir.ONAME, decl.NameList)
typ := p.typeExprOrNil(decl.Type) typ := p.typeExprOrNil(decl.Type)
var exprs []ir.Node var exprs []ir.Node
@ -425,7 +425,7 @@ func (p *noder) constDecl(decl *syntax.ConstDecl, cs *constState) []ir.Node {
p.checkUnused(pragma) p.checkUnused(pragma)
} }
names := p.declNames(decl.NameList) names := p.declNames(ir.OLITERAL, decl.NameList)
typ := p.typeExprOrNil(decl.Type) typ := p.typeExprOrNil(decl.Type)
var values []ir.Node var values []ir.Node
@ -450,8 +450,6 @@ func (p *noder) constDecl(decl *syntax.ConstDecl, cs *constState) []ir.Node {
if decl.Values == nil { if decl.Values == nil {
v = ir.DeepCopy(n.Pos(), v) v = ir.DeepCopy(n.Pos(), v)
} }
n.SetOp(ir.OLITERAL)
declare(n, dclcontext) declare(n, dclcontext)
n.Ntype = typ n.Ntype = typ
@ -471,8 +469,7 @@ func (p *noder) constDecl(decl *syntax.ConstDecl, cs *constState) []ir.Node {
} }
func (p *noder) typeDecl(decl *syntax.TypeDecl) ir.Node { func (p *noder) typeDecl(decl *syntax.TypeDecl) ir.Node {
n := p.declName(decl.Name) n := p.declName(ir.OTYPE, decl.Name)
n.SetOp(ir.OTYPE)
declare(n, dclcontext) declare(n, dclcontext)
// decl.Type may be nil but in that case we got a syntax error during parsing // decl.Type may be nil but in that case we got a syntax error during parsing
@ -495,16 +492,16 @@ func (p *noder) typeDecl(decl *syntax.TypeDecl) ir.Node {
return nod return nod
} }
func (p *noder) declNames(names []*syntax.Name) []ir.Node { func (p *noder) declNames(op ir.Op, names []*syntax.Name) []ir.Node {
nodes := make([]ir.Node, 0, len(names)) nodes := make([]ir.Node, 0, len(names))
for _, name := range names { for _, name := range names {
nodes = append(nodes, p.declName(name)) nodes = append(nodes, p.declName(op, name))
} }
return nodes return nodes
} }
func (p *noder) declName(name *syntax.Name) *ir.Name { func (p *noder) declName(op ir.Op, name *syntax.Name) *ir.Name {
return ir.NewDeclNameAt(p.pos(name), p.name(name)) return ir.NewDeclNameAt(p.pos(name), op, p.name(name))
} }
func (p *noder) funcDecl(fun *syntax.FuncDecl) ir.Node { func (p *noder) funcDecl(fun *syntax.FuncDecl) ir.Node {

View File

@ -97,8 +97,7 @@ func initUniverse() {
defBasic := func(kind types.Kind, pkg *types.Pkg, name string) *types.Type { defBasic := func(kind types.Kind, pkg *types.Pkg, name string) *types.Type {
sym := pkg.Lookup(name) sym := pkg.Lookup(name)
n := ir.NewDeclNameAt(src.NoXPos, sym) n := ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, sym)
n.SetOp(ir.OTYPE)
t := types.NewBasic(kind, n) t := types.NewBasic(kind, n)
n.SetType(t) n.SetType(t)
sym.Def = n sym.Def = n
@ -134,8 +133,7 @@ func initUniverse() {
// error type // error type
s := types.BuiltinPkg.Lookup("error") s := types.BuiltinPkg.Lookup("error")
n := ir.NewDeclNameAt(src.NoXPos, s) n := ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, s)
n.SetOp(ir.OTYPE)
types.ErrorType = types.NewNamed(n) types.ErrorType = types.NewNamed(n)
types.ErrorType.SetUnderlying(makeErrorInterface()) types.ErrorType.SetUnderlying(makeErrorInterface())
n.SetType(types.ErrorType) n.SetType(types.ErrorType)

View File

@ -164,13 +164,19 @@ func NewIota(pos src.XPos, sym *types.Sym) *Name {
return newNameAt(pos, OIOTA, sym) return newNameAt(pos, OIOTA, sym)
} }
// NewDeclNameAt returns a new ONONAME Node associated with symbol s at position pos. // NewDeclNameAt returns a new Name associated with symbol s at position pos.
// The caller is responsible for setting Curfn. // The caller is responsible for setting Curfn.
func NewDeclNameAt(pos src.XPos, sym *types.Sym) *Name { func NewDeclNameAt(pos src.XPos, op Op, sym *types.Sym) *Name {
if sym == nil { if sym == nil {
base.Fatalf("NewDeclNameAt nil") base.Fatalf("NewDeclNameAt nil")
} }
return newNameAt(pos, ONONAME, sym) switch op {
case ONAME, OTYPE, OLITERAL:
// ok
default:
base.Fatalf("NewDeclNameAt op %v", op)
}
return newNameAt(pos, op, sym)
} }
// newNameAt is like NewNameAt but allows sym == nil. // newNameAt is like NewNameAt but allows sym == nil.
@ -207,18 +213,6 @@ func (*Name) CanBeNtype() {}
func (*Name) CanBeAnSSASym() {} func (*Name) CanBeAnSSASym() {}
func (*Name) CanBeAnSSAAux() {} func (*Name) CanBeAnSSAAux() {}
func (n *Name) SetOp(op Op) {
if n.op != ONONAME {
base.Fatalf("%v already has Op %v", n, n.op)
}
switch op {
default:
panic(n.no("SetOp " + op.String()))
case OLITERAL, ONAME, OTYPE, OIOTA:
n.op = op
}
}
// Pragma returns the PragmaFlag for p, which must be for an OTYPE. // Pragma returns the PragmaFlag for p, which must be for an OTYPE.
func (n *Name) Pragma() PragmaFlag { return n.pragma } func (n *Name) Pragma() PragmaFlag { return n.pragma }