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
el = el[1:]
}
- v.SetOp(ir.ONAME)
declare(v, dclcontext)
v.Ntype = t
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
// 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
}
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
p.checkUnused(pragma)
}
- names := p.declNames(decl.NameList)
+ names := p.declNames(ir.OLITERAL, decl.NameList)
typ := p.typeExprOrNil(decl.Type)
var values []ir.Node
if decl.Values == nil {
v = ir.DeepCopy(n.Pos(), v)
}
-
- n.SetOp(ir.OLITERAL)
declare(n, dclcontext)
n.Ntype = typ
}
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
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 {
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
// 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)
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.
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 }