diff options
author | Matthew Dempsky <mdempsky@google.com> | 2020-12-01 02:58:41 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2020-12-01 17:16:39 +0000 |
commit | a17c5e2fce9340ec19d4019490b38a7645f244df (patch) | |
tree | 104f9a32021d30d8cf1dfed0ad0b2b40c9e11377 /src/cmd/compile/internal/types/type.go | |
parent | f37aa5e4e26a7212b6300e2021b8e6ea7000979b (diff) | |
download | go-a17c5e2fce9340ec19d4019490b38a7645f244df.tar.gz go-a17c5e2fce9340ec19d4019490b38a7645f244df.zip |
[dev.regabi] cmd/compile: add NewBasic and cleanup universe
This CL introduces types.NewBasic, for creating the predeclared
universal types, and reorganizes how the universe is initialized so
that all predeclared types are uniformly constructed.
There are now a bunch of Type fields that are no longer assigned
outside of the package, so this CL also introduces some new accessor
methods that a subsequent CL will mechanically introduce uses of.
Change-Id: Ie7996c3d5f1ca46cd5bfe45ecc91ebfa6a7b6c7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/274435
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types/type.go')
-rw-r--r-- | src/cmd/compile/internal/types/type.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index d6d56426a5..f0211a67fb 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -110,8 +110,8 @@ var ( Errortype *Type // Types to represent untyped string and boolean constants. - UntypedString *Type - UntypedBool *Type + UntypedString = New(TSTRING) + UntypedBool = New(TBOOL) // Types to represent untyped numeric constants. UntypedInt = New(TIDEAL) @@ -184,6 +184,15 @@ func (t *Type) SetNoalg(b bool) { t.flags.set(typeNoalg, b) } func (t *Type) SetDeferwidth(b bool) { t.flags.set(typeDeferwidth, b) } func (t *Type) SetRecur(b bool) { t.flags.set(typeRecur, b) } +// Kind returns the kind of type t. +func (t *Type) Kind() EType { return t.Etype } + +// Sym returns the name of type t. +func (t *Type) GetSym() *Sym { return t.Sym } + +// Underlying returns the underlying type of type t. +func (t *Type) Underlying() *Type { return t.Orig } + // SetNod associates t with syntax node n. func (t *Type) SetNod(n IRNode) { // t.nod can be non-nil already @@ -1601,3 +1610,11 @@ func (t *Type) SetUnderlying(underlying *Type) { } } } + +// NewNamed returns a new basic type of the given kind. +func NewBasic(kind EType, obj IRNode) *Type { + t := New(kind) + t.Sym = obj.Sym() + t.nod = obj + return t +} |