decls = append(decls, v)
fld := types.NewField(src.NoXPos, v.Sym(), v.Type())
- fld.Nname = ir.AsTypesNode(v)
+ fld.Nname = v
params = append(params, fld)
}
// typecheckslice() requires that Curfn is set when processing an ORETURN.
Curfn = dcl
typecheckslice(dcl.Body().Slice(), ctxStmt)
- sym.Def = ir.AsTypesNode(dcl)
+ sym.Def = dcl
xtop = append(xtop, dcl)
Curfn = savecurfn
base.Pos = saveLineNo
s.Block = types.Block
s.Lastlineno = base.Pos
- s.Def = ir.AsTypesNode(n)
+ s.Def = n
n.Name().Vargen = int32(gen)
n.SetClass(ctxt)
if ctxt == ir.PFUNC {
// then t->nod might be out of date, so
// check t->nod->type too
if ir.AsNode(t.Nod) == nil || ir.AsNode(t.Nod).Type() != t {
- t.Nod = ir.AsTypesNode(ir.NodAt(pos, ir.OTYPE, nil, nil))
+ t.Nod = ir.NodAt(pos, ir.OTYPE, nil, nil)
ir.AsNode(t.Nod).SetType(t)
ir.AsNode(t.Nod).SetSym(t.Sym)
}
return
}
n := ir.NewNameAt(f.Pos, f.Sym)
- f.Nname = ir.AsTypesNode(n)
+ f.Nname = n
n.SetType(f.Type)
n.SetIsDDD(f.IsDDD())
declare(n, ctxt)
f.SetIsDDD(n.IsDDD())
if n.Right() != nil {
n.Right().SetType(f.Type)
- f.Nname = ir.AsTypesNode(n.Right())
+ f.Nname = n.Right()
}
if f.Broke() {
t.SetBroke(true)
}
f := types.NewField(base.Pos, msym, t)
- f.Nname = ir.AsTypesNode(n.Func().Nname)
+ f.Nname = n.Func().Nname
f.SetNointerface(nointerface)
mt.Methods().Append(f)
if dclcontext != ir.PEXTERN {
numLocalEmbed++
v = ir.NewNameAt(v.Pos(), lookupN("embed.", numLocalEmbed))
- v.Sym().Def = ir.AsTypesNode(v)
+ v.Sym().Def = v
v.Name().Param.Ntype = typ
v.SetClass(ir.PEXTERN)
externdcl = append(externdcl, v)
ir.InspectList(fn.Body(), func(n *ir.Node) bool {
switch n.Op() {
case ir.OLABEL:
- n.Sym().Label = ir.AsTypesNode(nonlooping)
+ n.Sym().Label = nonlooping
case ir.OGOTO:
// If we visited the label before the goto,
// then this is a looping label.
- if n.Sym().Label == ir.AsTypesNode(nonlooping) {
- n.Sym().Label = ir.AsTypesNode(looping)
+ if n.Sym().Label == nonlooping {
+ n.Sym().Label = looping
}
}
}
n = dclname(s)
- s.SetPkgDef(ir.AsTypesNode(n))
+ s.SetPkgDef(n)
s.Importdef = ipkg
}
if n.Op() != ir.ONONAME && n.Op() != op {
if n.Op() != ir.OTYPE {
t := types.New(types.TFORW)
t.Sym = s
- t.Nod = ir.AsTypesNode(n)
+ t.Nod = n
n.SetOp(ir.OTYPE)
n.SetPos(pos)
Pkg: ir.LocalPkg,
}
n := ir.NewNameAt(pos, s)
- s.Def = ir.AsTypesNode(n)
+ s.Def = n
n.SetType(t)
n.SetClass(ir.PAUTO)
n.SetEsc(EscNever)
ir.NumImport[pkgName]++
// TODO(mdempsky): This belongs somewhere else.
- pkg.Lookup("_").Def = ir.AsTypesNode(ir.BlankNode)
+ pkg.Lookup("_").Def = ir.BlankNode
} else {
if pkg.Name != pkgName {
base.Fatalf("conflicting package names %v and %v for path %q", pkg.Name, pkgName, pkg.Path)
if s.Def != nil {
base.Fatalf("unexpected definition for %v: %v", s, ir.AsNode(s.Def))
}
- s.Def = ir.AsTypesNode(npos(src.NoXPos, dclname(s)))
+ s.Def = npos(src.NoXPos, dclname(s))
}
}
// methodSym already marked m.Sym as a function.
f := types.NewField(mpos, msym, mtyp)
- f.Nname = ir.AsTypesNode(m)
+ f.Nname = m
ms[i] = f
}
t.Methods().Set(ms)
nn := NewName(sym)
nn.SetType(types.Types[types.TUINT8]) // fake type
nn.SetClass(ir.PEXTERN)
- sym.Def = ir.AsTypesNode(nn)
+ sym.Def = nn
exportsym(nn)
lsym := sym.Linksym()
ot := 0
if my.Def != nil {
redeclare(pack.Pos(), my, "as imported package name")
}
- my.Def = ir.AsTypesNode(pack)
+ my.Def = pack
my.Lastlineno = pack.Pos()
my.Block = 1 // at top level
}
symname := fmt.Sprintf(".gobytes.%d", slicedataGen)
sym := ir.LocalPkg.Lookup(symname)
symnode := NewName(sym)
- sym.Def = ir.AsTypesNode(symnode)
+ sym.Def = symnode
lsym := sym.Linksym()
off := dstringdata(lsym, 0, s, pos, "slice")
n.SetType(types.Types[types.TUINT8])
n.SetClass(ir.PEXTERN)
n.SetTypecheck(1)
- s.Def = ir.AsTypesNode(n)
+ s.Def = n
}
n := ir.Nod(ir.OADDR, ir.AsNode(s.Def), nil)
n.SetType(types.Types[types.TUINT8])
n.SetClass(ir.PEXTERN)
n.SetTypecheck(1)
- s.Def = ir.AsTypesNode(n)
+ s.Def = n
itabs = append(itabs, itabEntry{t: t, itype: itype, lsym: s.Linksym()})
}
x.SetType(types.Types[types.TUINT8])
x.SetClass(ir.PEXTERN)
x.SetTypecheck(1)
- s.Def = ir.AsTypesNode(x)
+ s.Def = x
}
z := ir.Nod(ir.OADDR, ir.AsNode(s.Def), nil)
z.SetType(types.NewPtr(types.Types[types.TUINT8]))
s := &types.Sym{Name: node.Sym().Name + suffix, Pkg: ir.LocalPkg}
n := ir.NewNameAt(parent.N.Pos(), s)
- s.Def = ir.AsTypesNode(n)
+ s.Def = n
ir.AsNode(s.Def).Name().SetUsed(true)
n.SetType(t)
n.SetClass(ir.PAUTO)
*t = *underlying
// Restore unnecessarily clobbered attributes.
- t.Nod = ir.AsTypesNode(n)
+ t.Nod = n
t.Sym = n.Sym()
if n.Name() != nil {
t.Vargen = n.Name().Vargen
// For package-level type aliases, set n.Sym.Def so we can identify
// it as a type alias during export. See also #31959.
if n.Name().Curfn == nil {
- n.Sym().Def = ir.AsTypesNode(p.Ntype)
+ n.Sym().Def = p.Ntype
}
}
break
if n.Op() == ir.OLABEL && i+1 < len(s) && n.Name().Defn == s[i+1] {
switch n.Name().Defn.Op() {
case ir.OFOR, ir.OFORUNTIL, ir.OSWITCH, ir.OTYPESW, ir.OSELECT, ir.ORANGE:
- n.Sym().Label = ir.AsTypesNode(n.Name().Defn)
+ n.Sym().Label = n.Name().Defn
markbreak(n.Name().Defn, n.Name().Defn)
n.Sym().Label = nil
i++
func setTypeNode(n *ir.Node, t *types.Type) {
n.SetOp(ir.OTYPE)
n.SetType(t)
- n.Type().Nod = ir.AsTypesNode(n)
+ n.Type().Nod = n
}
// getIotaValue returns the current value for "iota",
}
types.Types[etype] = t
}
- s2.Def = ir.AsTypesNode(typenod(t))
+ s2.Def = typenod(t)
ir.AsNode(s2.Def).SetName(new(ir.Name))
}
for _, s := range &builtinFuncs {
s2 := ir.BuiltinPkg.Lookup(s.name)
- s2.Def = ir.AsTypesNode(NewName(s2))
+ s2.Def = NewName(s2)
ir.AsNode(s2.Def).SetSubOp(s.op)
}
for _, s := range &unsafeFuncs {
s2 := unsafepkg.Lookup(s.name)
- s2.Def = ir.AsTypesNode(NewName(s2))
+ s2.Def = NewName(s2)
ir.AsNode(s2.Def).SetSubOp(s.op)
}
types.Types[types.TANY] = types.New(types.TANY)
s := ir.BuiltinPkg.Lookup("true")
- s.Def = ir.AsTypesNode(nodbool(true))
+ s.Def = nodbool(true)
ir.AsNode(s.Def).SetSym(lookup("true"))
ir.AsNode(s.Def).SetName(new(ir.Name))
ir.AsNode(s.Def).SetType(types.UntypedBool)
s = ir.BuiltinPkg.Lookup("false")
- s.Def = ir.AsTypesNode(nodbool(false))
+ s.Def = nodbool(false)
ir.AsNode(s.Def).SetSym(lookup("false"))
ir.AsNode(s.Def).SetName(new(ir.Name))
ir.AsNode(s.Def).SetType(types.UntypedBool)
s = lookup("_")
s.Block = -100
- s.Def = ir.AsTypesNode(NewName(s))
+ s.Def = NewName(s)
types.Types[types.TBLANK] = types.New(types.TBLANK)
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
ir.BlankNode = ir.AsNode(s.Def)
s = ir.BuiltinPkg.Lookup("_")
s.Block = -100
- s.Def = ir.AsTypesNode(NewName(s))
+ s.Def = NewName(s)
types.Types[types.TBLANK] = types.New(types.TBLANK)
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
types.Types[types.TNIL] = types.New(types.TNIL)
s = ir.BuiltinPkg.Lookup("nil")
- s.Def = ir.AsTypesNode(nodnil())
+ s.Def = nodnil()
ir.AsNode(s.Def).SetSym(s)
ir.AsNode(s.Def).SetName(new(ir.Name))
s = ir.BuiltinPkg.Lookup("iota")
- s.Def = ir.AsTypesNode(ir.Nod(ir.OIOTA, nil, nil))
+ s.Def = ir.Nod(ir.OIOTA, nil, nil)
ir.AsNode(s.Def).SetSym(s)
ir.AsNode(s.Def).SetName(new(ir.Name))
}
t := types.New(types.TUNSAFEPTR)
types.Types[types.TUNSAFEPTR] = t
t.Sym = unsafepkg.Lookup("Pointer")
- t.Sym.Def = ir.AsTypesNode(typenod(t))
+ t.Sym.Def = typenod(t)
ir.AsNode(t.Sym.Def).SetName(new(ir.Name))
dowidth(types.Types[types.TUNSAFEPTR])
types.Errortype = makeErrorInterface()
types.Errortype.Sym = s
types.Errortype.Orig = makeErrorInterface()
- s.Def = ir.AsTypesNode(typenod(types.Errortype))
+ s.Def = typenod(types.Errortype)
dowidth(types.Errortype)
// We create separate byte and rune types for better error messages
s = ir.BuiltinPkg.Lookup("byte")
types.Bytetype = types.New(types.TUINT8)
types.Bytetype.Sym = s
- s.Def = ir.AsTypesNode(typenod(types.Bytetype))
+ s.Def = typenod(types.Bytetype)
ir.AsNode(s.Def).SetName(new(ir.Name))
dowidth(types.Bytetype)
s = ir.BuiltinPkg.Lookup("rune")
types.Runetype = types.New(types.TINT32)
types.Runetype.Sym = s
- s.Def = ir.AsTypesNode(typenod(types.Runetype))
+ s.Def = typenod(types.Runetype)
ir.AsNode(s.Def).SetName(new(ir.Name))
dowidth(types.Runetype)
t := types.New(s.etype)
t.Sym = s1
types.Types[s.etype] = t
- s1.Def = ir.AsTypesNode(typenod(t))
+ s1.Def = typenod(t)
ir.AsNode(s1.Def).SetName(new(ir.Name))
s1.Origpkg = ir.BuiltinPkg
case src.XPos:
p.printf("%s", base.FmtPos(v))
return
-
- case *types.Node:
- x = reflect.ValueOf(AsNode(v))
}
switch x.Kind() {
"go/constant"
"sort"
"strings"
- "unsafe"
"cmd/compile/internal/base"
"cmd/compile/internal/types"
Pos src.XPos // line of call
}
-func AsNode(n *types.Node) *Node { return (*Node)(unsafe.Pointer(n)) }
-
-func AsTypesNode(n *Node) *types.Node { return (*types.Node)(unsafe.Pointer(n)) }
+func AsNode(n types.IRNode) *Node {
+ if n == nil {
+ return nil
+ }
+ return n.(*Node)
+}
var BlankNode *Node
// restored once the block scope ends.
type dsym struct {
sym *Sym // sym == nil indicates stack mark
- def *Node
+ def IRNode
block int32
lastlineno src.XPos // last declaration for diagnostic
}
}
// PkgDef returns the definition associated with s at package scope.
-func (s *Sym) PkgDef() *Node {
+func (s *Sym) PkgDef() IRNode {
return *s.pkgDefPtr()
}
// SetPkgDef sets the definition associated with s at package scope.
-func (s *Sym) SetPkgDef(n *Node) {
+func (s *Sym) SetPkgDef(n IRNode) {
*s.pkgDefPtr() = n
}
-func (s *Sym) pkgDefPtr() **Node {
+func (s *Sym) pkgDefPtr() *IRNode {
// Look for outermost saved declaration, which must be the
// package scope definition, if present.
for _, d := range dclstack {
_32bit uintptr // size on 32bit platforms
_64bit uintptr // size on 64bit platforms
}{
- {Sym{}, 52, 88},
- {Type{}, 52, 88},
+ {Sym{}, 60, 104},
+ {Type{}, 56, 96},
{Map{}, 20, 40},
{Forward{}, 20, 32},
{Func{}, 28, 48},
Name string // object name
// saved and restored by dcopy
- Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
+ Def IRNode // definition: ONAME OTYPE OPACK or OLITERAL
Block int32 // blocknumber to catch redeclaration
Lastlineno src.XPos // last declaration for diagnostic
flags bitset8
- Label *Node // corresponding label (ephemeral)
+ Label IRNode // corresponding label (ephemeral)
Origpkg *Pkg // original package for . import
}
"fmt"
)
-// Our own “Node” so we can refer to *gc.Node without actually
-// having a gc.Node. Necessary to break import cycles.
-// TODO(gri) try to eliminate soon
-type Node struct{ _ int }
+// IRNode represents an ir.Node, but without needing to import cmd/compile/internal/ir,
+// which would cause an import cycle. The uses in other packages must type assert
+// values of type IRNode to ir.Node or a more specific type.
+type IRNode interface{ Type() *Type }
//go:generate stringer -type EType -trimprefix T
methods Fields
allMethods Fields
- Nod *Node // canonical OTYPE node
- Orig *Type // original type (type literal or predefined type)
+ Nod IRNode // canonical OTYPE node
+ Orig *Type // original type (type literal or predefined type)
// Cache of composite types, with this type being the element type.
Cache struct {
// For fields that represent function parameters, Nname points
// to the associated ONAME Node.
- Nname *Node
+ Nname IRNode
// Offset in bytes of this field or method within its enclosing struct
// or interface Type.