aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/type.go
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2020-12-02 16:13:45 -0500
committerAlexander Rakoczy <alex@golang.org>2020-12-14 11:43:51 -0500
commit7e17b46c58cbb0aff2b42490a73e807bb04757d7 (patch)
treeb9c03cdcfbb721425048b4ce3d88c66be9c31361 /src/cmd/compile/internal/types/type.go
parent2b76429eb01ec1752f7622e3011babd7140ab870 (diff)
downloadgo-7e17b46c58cbb0aff2b42490a73e807bb04757d7.tar.gz
go-7e17b46c58cbb0aff2b42490a73e807bb04757d7.zip
[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 <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Than McIntosh <thanm@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types/type.go')
-rw-r--r--src/cmd/compile/internal/types/type.go14
1 files changed, 14 insertions, 0 deletions
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)
}