mirror of
https://github.com/golang/go
synced 2024-11-11 19:21:37 -07:00
[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>
This commit is contained in:
parent
2b76429eb0
commit
7e17b46c58
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user