forked from clipperhouse/typewriter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredicates.go
37 lines (28 loc) · 905 Bytes
/
predicates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// From: https://code.google.com/p/go/source/browse/go/types/predicates.go?repo=tools
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file implements commonly used type predicates.
package typewriter
import (
"go/types"
)
func isComparable(typ types.Type) bool {
return types.Comparable(typ)
}
func isNumeric(typ types.Type) bool {
t, ok := typ.Underlying().(*types.Basic)
return ok && t.Info()&types.IsNumeric != 0
}
func isOrdered(typ types.Type) bool {
t, ok := typ.Underlying().(*types.Basic)
return ok && t.Info()&types.IsOrdered != 0
}
func isInvalid(typ types.Type) bool {
t, ok := typ.Underlying().(*types.Basic)
return ok && t.Kind() == types.Invalid
}
func isPointer(typ types.Type) Pointer {
_, ok := typ.Underlying().(*types.Pointer)
return Pointer(ok)
}