mirror of
https://github.com/golang/go
synced 2024-11-22 14:15:05 -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:
parent
cb4898a77d
commit
94cfeca0a5
@ -141,7 +141,6 @@ func variter(vl []ir.Node, t ir.Ntype, el []ir.Node) []ir.Node {
|
||||
as2.PtrRlist().Set1(e)
|
||||
for _, v := range vl {
|
||||
v := v.(*ir.Name)
|
||||
v.SetOp(ir.ONAME)
|
||||
declare(v, dclcontext)
|
||||
v.Ntype = t
|
||||
v.Defn = as2
|
||||
@ -166,7 +165,6 @@ func variter(vl []ir.Node, t ir.Ntype, el []ir.Node) []ir.Node {
|
||||
el = el[1:]
|
||||
}
|
||||
|
||||
v.SetOp(ir.ONAME)
|
||||
declare(v, dclcontext)
|
||||
v.Ntype = t
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
n := ir.NewDeclNameAt(pos, s)
|
||||
n.SetOp(op) // TODO(mdempsky): Add as argument to NewDeclNameAt.
|
||||
n.SetClass(ctxt)
|
||||
n := ir.NewDeclNameAt(pos, op, s)
|
||||
n.SetClass(ctxt) // TODO(mdempsky): Move this into NewDeclNameAt too?
|
||||
s.SetPkgDef(n)
|
||||
s.Importdef = ipkg
|
||||
return n
|
||||
|
@ -971,7 +971,7 @@ func (r *importReader) node() ir.Node {
|
||||
// statements
|
||||
case ir.ODCL:
|
||||
pos := r.pos()
|
||||
lhs := ir.NewDeclNameAt(pos, r.ident())
|
||||
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
|
||||
|
||||
|
@ -374,7 +374,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
var exprs []ir.Node
|
||||
@ -425,7 +425,7 @@ func (p *noder) constDecl(decl *syntax.ConstDecl, cs *constState) []ir.Node {
|
||||
p.checkUnused(pragma)
|
||||
}
|
||||
|
||||
names := p.declNames(decl.NameList)
|
||||
names := p.declNames(ir.OLITERAL, decl.NameList)
|
||||
typ := p.typeExprOrNil(decl.Type)
|
||||
|
||||
var values []ir.Node
|
||||
@ -450,8 +450,6 @@ func (p *noder) constDecl(decl *syntax.ConstDecl, cs *constState) []ir.Node {
|
||||
if decl.Values == nil {
|
||||
v = ir.DeepCopy(n.Pos(), v)
|
||||
}
|
||||
|
||||
n.SetOp(ir.OLITERAL)
|
||||
declare(n, dclcontext)
|
||||
|
||||
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 {
|
||||
n := p.declName(decl.Name)
|
||||
n.SetOp(ir.OTYPE)
|
||||
n := p.declName(ir.OTYPE, decl.Name)
|
||||
declare(n, dclcontext)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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))
|
||||
for _, name := range names {
|
||||
nodes = append(nodes, p.declName(name))
|
||||
nodes = append(nodes, p.declName(op, name))
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
func (p *noder) declName(name *syntax.Name) *ir.Name {
|
||||
return ir.NewDeclNameAt(p.pos(name), p.name(name))
|
||||
func (p *noder) declName(op ir.Op, name *syntax.Name) *ir.Name {
|
||||
return ir.NewDeclNameAt(p.pos(name), op, p.name(name))
|
||||
}
|
||||
|
||||
func (p *noder) funcDecl(fun *syntax.FuncDecl) ir.Node {
|
||||
|
@ -97,8 +97,7 @@ func initUniverse() {
|
||||
|
||||
defBasic := func(kind types.Kind, pkg *types.Pkg, name string) *types.Type {
|
||||
sym := pkg.Lookup(name)
|
||||
n := ir.NewDeclNameAt(src.NoXPos, sym)
|
||||
n.SetOp(ir.OTYPE)
|
||||
n := ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, sym)
|
||||
t := types.NewBasic(kind, n)
|
||||
n.SetType(t)
|
||||
sym.Def = n
|
||||
@ -134,8 +133,7 @@ func initUniverse() {
|
||||
|
||||
// error type
|
||||
s := types.BuiltinPkg.Lookup("error")
|
||||
n := ir.NewDeclNameAt(src.NoXPos, s)
|
||||
n.SetOp(ir.OTYPE)
|
||||
n := ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, s)
|
||||
types.ErrorType = types.NewNamed(n)
|
||||
types.ErrorType.SetUnderlying(makeErrorInterface())
|
||||
n.SetType(types.ErrorType)
|
||||
|
@ -164,13 +164,19 @@ func NewIota(pos src.XPos, sym *types.Sym) *Name {
|
||||
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.
|
||||
func NewDeclNameAt(pos src.XPos, sym *types.Sym) *Name {
|
||||
func NewDeclNameAt(pos src.XPos, op Op, sym *types.Sym) *Name {
|
||||
if sym == 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.
|
||||
@ -207,18 +213,6 @@ func (*Name) CanBeNtype() {}
|
||||
func (*Name) CanBeAnSSASym() {}
|
||||
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.
|
||||
func (n *Name) Pragma() PragmaFlag { return n.pragma }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user