blob: 2ef133647e1d4e866efc503ec2e2a96164062eaf [file] [log] [blame]
Peter Collingbournead9841e2014-11-27 00:06:42 +00001//===- predicates.go - type predicates ------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements commonly used type predicates.
11//
12//===----------------------------------------------------------------------===//
13
14package irgen
15
16import (
Peter Collingbourne56109b72015-01-13 20:45:08 +000017 "llvm.org/llgo/third_party/gotools/go/types"
Peter Collingbournead9841e2014-11-27 00:06:42 +000018)
19
20func isBoolean(typ types.Type) bool {
21 t, ok := typ.Underlying().(*types.Basic)
22 return ok && t.Info()&types.IsBoolean != 0
23}
24
25func isInteger(typ types.Type) bool {
26 t, ok := typ.Underlying().(*types.Basic)
27 return ok && t.Info()&types.IsInteger != 0
28}
29
30func isUnsigned(typ types.Type) bool {
31 t, ok := typ.Underlying().(*types.Basic)
32 return ok && t.Info()&types.IsUnsigned != 0
33}
34
35func isFloat(typ types.Type) bool {
36 t, ok := typ.Underlying().(*types.Basic)
37 return ok && t.Info()&types.IsFloat != 0
38}
39
40func isComplex(typ types.Type) bool {
41 t, ok := typ.Underlying().(*types.Basic)
42 return ok && t.Info()&types.IsComplex != 0
43}
44
45func isString(typ types.Type) bool {
46 t, ok := typ.Underlying().(*types.Basic)
47 return ok && t.Info()&types.IsString != 0
48}
49
50func isUntyped(typ types.Type) bool {
51 t, ok := typ.Underlying().(*types.Basic)
52 return ok && t.Info()&types.IsUntyped != 0
53}
54
55func isSlice(typ types.Type, bkind types.BasicKind) bool {
56 t, ok := typ.Underlying().(*types.Slice)
57 return ok && types.Identical(t.Elem().Underlying(), types.Typ[bkind])
58}