From 7e17b46c58cbb0aff2b42490a73e807bb04757d7 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Wed, 2 Dec 2020 16:13:45 -0500 Subject: [PATCH] [dev.regabi] cmd/compile/internal/types: add IsScalar query method Add method Type.IsScalar() method, which returns TRUE for numeric and pointer-shaped types, false for composites such as string/array/slice/struct. Change-Id: Ie53c71c07c5b3fbae11b48addd172343dc6bf3fd Reviewed-on: https://go-review.googlesource.com/c/go/+/274857 Run-TryBot: Than McIntosh TryBot-Result: Go Bot Trust: Than McIntosh Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/types/type.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index e968a799e3..4d1d30133c 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -1335,6 +1335,20 @@ func (t *Type) IsEmptyInterface() bool { return t.IsInterface() && t.NumFields() == 0 } +// IsScalar reports whether 't' is a scalar Go type, e.g. +// bool/int/float/complex. Note that struct and array types consisting +// of a single scalar element are not considered scalar, likewise +// pointer types are also not considered scalar. +func (t *Type) IsScalar() bool { + switch t.kind { + case TBOOL, TINT8, TUINT8, TINT16, TUINT16, TINT32, + TUINT32, TINT64, TUINT64, TINT, TUINT, + TUINTPTR, TCOMPLEX64, TCOMPLEX128, TFLOAT32, TFLOAT64: + return true + } + return false +} + func (t *Type) PtrTo() *Type { return NewPtr(t) } -- 2.50.0