typ := closureType(clo)
- clos := ir.Nod(ir.OCOMPLIT, nil, typenod(typ))
+ clos := ir.Nod(ir.OCOMPLIT, nil, ir.TypeNode(typ))
clos.SetEsc(clo.Esc())
clos.PtrList().Set(append([]ir.Node{ir.Nod(ir.OCFUNC, fn.Nname, nil)}, fn.ClosureEnter.Slice()...))
typ := partialCallType(n)
- clos := ir.Nod(ir.OCOMPLIT, nil, typenod(typ))
+ clos := ir.Nod(ir.OCOMPLIT, nil, ir.TypeNode(typ))
clos.SetEsc(n.Esc())
clos.PtrList().Set2(ir.Nod(ir.OCFUNC, n.Func().Nname, nil), n.Left())
return n
}
-func typenod(t *types.Type) ir.Node {
- return typenodl(src.NoXPos, t)
-}
-
-func typenodl(pos src.XPos, t *types.Type) ir.Node {
- // if we copied another type with *t = *u
- // 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.NodAt(pos, ir.OTYPE, nil, nil)
- ir.AsNode(t.Nod).SetType(t)
- ir.AsNode(t.Nod).SetSym(t.Sym)
- }
-
- return ir.AsNode(t.Nod)
-}
-
func anonfield(typ *types.Type) ir.Node {
return symfield(nil, typ)
}
}
w.startType(definedType)
- w.qualifiedIdent(typenod(t))
+ w.qualifiedIdent(ir.TypeNode(t))
return
}
// unreachable - should have been resolved by typechecking
case ir.OTYPE:
- return typenod(r.typ())
+ return ir.TypeNode(r.typ())
case ir.OTYPESW:
n := ir.NodAt(r.pos(), ir.OTYPESW, nil, nil)
// TODO(mdempsky): Export position information for OSTRUCTKEY nodes.
savedlineno := base.Pos
base.Pos = r.pos()
- n := ir.NodAt(base.Pos, ir.OCOMPLIT, nil, typenod(r.typ()))
+ n := ir.NodAt(base.Pos, ir.OCOMPLIT, nil, ir.TypeNode(r.typ()))
n.PtrList().Set(r.elemList()) // special handling of field names
base.Pos = savedlineno
return n
// unreachable - mapped to case OCOMPLIT below by exporter
case ir.OCOMPLIT:
- n := ir.NodAt(r.pos(), ir.OCOMPLIT, nil, typenod(r.typ()))
+ n := ir.NodAt(r.pos(), ir.OCOMPLIT, nil, ir.TypeNode(r.typ()))
n.PtrList().Set(r.exprList())
return n
case ir.OMAKEMAP, ir.OMAKECHAN, ir.OMAKESLICE:
n := npos(r.pos(), builtinCall(ir.OMAKE))
- n.PtrList().Append(typenod(r.typ()))
+ n.PtrList().Append(ir.TypeNode(r.typ()))
n.PtrList().Append(r.exprList()...)
return n
case ir.ODCL:
pos := r.pos()
lhs := npos(pos, dclname(r.ident()))
- typ := typenod(r.typ())
+ typ := ir.TypeNode(r.typ())
return npos(pos, liststmt(variter([]ir.Node{lhs}, typ, nil))) // TODO(gri) avoid list creation
// case ODCLFIELD:
vas.SetRight(nodnil())
vas.Right().SetType(param.Type)
} else {
- vas.SetRight(ir.Nod(ir.OCOMPLIT, nil, typenod(param.Type)))
+ vas.SetRight(ir.Nod(ir.OCOMPLIT, nil, ir.TypeNode(param.Type)))
vas.Right().PtrList().Set(varargs)
}
}
a = ir.Nod(ir.OADDR, a, nil)
} else {
a = ir.Nod(ir.ONEW, nil, nil)
- a.PtrList().Set1(typenod(t))
+ a.PtrList().Set1(ir.TypeNode(t))
}
a = ir.Nod(ir.OAS, vauto, a)
// make the map var
a := ir.Nod(ir.OMAKE, nil, nil)
a.SetEsc(n.Esc())
- a.PtrList().Set2(typenod(n.Type()), nodintconst(int64(n.List().Len())))
+ a.PtrList().Set2(ir.TypeNode(n.Type()), nodintconst(int64(n.List().Len())))
litas(m, a, init)
entries := n.List().Slice()
switch {
case iscomptype(t):
// For T, return T{...}.
- n.SetRight(typenod(t))
+ n.SetRight(ir.TypeNode(t))
case t.IsPtr() && iscomptype(t.Elem()):
// For *T, return &T{...}.
- n.SetRight(typenod(t.Elem()))
+ n.SetRight(ir.TypeNode(t.Elem()))
n = ir.NodAt(n.Pos(), ir.OADDR, n, nil)
n.SetImplicit(true)
i++
}
- nn := ir.Nod(ir.OCOMPLIT, nil, typenod(n.Type()))
+ nn := ir.Nod(ir.OCOMPLIT, nil, ir.TypeNode(n.Type()))
nn.PtrList().Set(l)
nn = typecheck(nn, ctxExpr)
return nn
}
types.Types[etype] = t
}
- s2.Def = typenod(t)
+ s2.Def = ir.TypeNode(t)
}
for _, s := range &builtinFuncs {
t := types.New(types.TUNSAFEPTR)
types.Types[types.TUNSAFEPTR] = t
t.Sym = unsafepkg.Lookup("Pointer")
- t.Sym.Def = typenod(t)
+ t.Sym.Def = ir.TypeNode(t)
dowidth(types.Types[types.TUNSAFEPTR])
for et := types.TINT8; et <= types.TUINT64; et++ {
types.Errortype = makeErrorInterface()
types.Errortype.Sym = s
types.Errortype.Orig = makeErrorInterface()
- s.Def = typenod(types.Errortype)
+ s.Def = ir.TypeNode(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 = typenod(types.Bytetype)
+ s.Def = ir.TypeNode(types.Bytetype)
dowidth(types.Bytetype)
// rune alias
s = ir.BuiltinPkg.Lookup("rune")
types.Runetype = types.New(types.TINT32)
types.Runetype.Sym = s
- s.Def = typenod(types.Runetype)
+ s.Def = ir.TypeNode(types.Runetype)
dowidth(types.Runetype)
// backend-dependent builtin types (e.g. int).
t := types.New(s.etype)
t.Sym = s1
types.Types[s.etype] = t
- s1.Def = typenod(t)
+ s1.Def = ir.TypeNode(t)
s1.Origpkg = ir.BuiltinPkg
dowidth(t)
n = nodnil()
n.SetType(typ)
} else {
- n = ir.Nod(ir.OCOMPLIT, nil, typenod(typ))
+ n = ir.Nod(ir.OCOMPLIT, nil, ir.TypeNode(typ))
n.PtrList().Append(args...)
n.SetImplicit(true)
}
fn = "concatstrings"
t := types.NewSlice(types.Types[types.TSTRING])
- slice := ir.Nod(ir.OCOMPLIT, nil, typenod(t))
+ slice := ir.Nod(ir.OCOMPLIT, nil, ir.TypeNode(t))
if prealloc[n] != nil {
prealloc[slice] = prealloc[n]
}
--- /dev/null
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ir
+
+import (
+ "cmd/compile/internal/types"
+ "cmd/internal/src"
+)
+
+func TypeNode(t *types.Type) Node {
+ return TypeNodeAt(src.NoXPos, t)
+}
+
+func TypeNodeAt(pos src.XPos, t *types.Type) Node {
+ // if we copied another type with *t = *u
+ // then t->nod might be out of date, so
+ // check t->nod->type too
+ if AsNode(t.Nod) == nil || AsNode(t.Nod).Type() != t {
+ t.Nod = NodAt(pos, OTYPE, nil, nil)
+ AsNode(t.Nod).SetType(t)
+ AsNode(t.Nod).SetSym(t.Sym)
+ }
+
+ return AsNode(t.Nod)
+}