[dev.regabi] cmd/compile: add NewNamed

The start of abstracting away Type fields. This adds a new constructor
for named types, styled after go/types.NewNamed. Along with helper
methods for SetNod and Pos, this allows hiding Nod.

Change-Id: Ica107034b6346c7b523bf6ae2a34009e350a9aa8
Reviewed-on: https://go-review.googlesource.com/c/go/+/274434
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Matthew Dempsky 2020-12-01 01:42:47 -08:00
parent 63a6f08b39
commit f37aa5e4e2
11 changed files with 75 additions and 63 deletions

View file

@ -337,11 +337,12 @@ func makeErrorInterface() *types.Type {
func lexinit1() {
// error type
s := ir.BuiltinPkg.Lookup("error")
types.Errortype = makeErrorInterface()
types.Errortype.Sym = s
types.Errortype.Orig = makeErrorInterface()
s.Def = ir.TypeNode(types.Errortype)
n := ir.NewNameAt(src.NoXPos, ir.BuiltinPkg.Lookup("error"))
types.Errortype = types.NewNamed(n)
types.Errortype.SetUnderlying(makeErrorInterface())
n.SetOp(ir.OTYPE)
n.SetType(types.Errortype)
n.Sym().Def = n
dowidth(types.Errortype)
// We create separate byte and rune types for better error messages
@ -353,7 +354,7 @@ func lexinit1() {
// type aliases, albeit at the cost of having to deal with it everywhere).
// byte alias
s = ir.BuiltinPkg.Lookup("byte")
s := ir.BuiltinPkg.Lookup("byte")
types.Bytetype = types.New(types.TUINT8)
types.Bytetype.Sym = s
s.Def = ir.TypeNode(types.Bytetype)