github.com/axw/llgo@v0.0.0-20160805011314-95b5fe4dca20/irgen/predicates.go (about)

     1  //===- 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  
    14  package irgen
    15  
    16  import (
    17  	"llvm.org/llgo/third_party/gotools/go/types"
    18  )
    19  
    20  func isBoolean(typ types.Type) bool {
    21  	t, ok := typ.Underlying().(*types.Basic)
    22  	return ok && t.Info()&types.IsBoolean != 0
    23  }
    24  
    25  func isInteger(typ types.Type) bool {
    26  	t, ok := typ.Underlying().(*types.Basic)
    27  	return ok && t.Info()&types.IsInteger != 0
    28  }
    29  
    30  func isUnsigned(typ types.Type) bool {
    31  	t, ok := typ.Underlying().(*types.Basic)
    32  	return ok && t.Info()&types.IsUnsigned != 0
    33  }
    34  
    35  func isFloat(typ types.Type) bool {
    36  	t, ok := typ.Underlying().(*types.Basic)
    37  	return ok && t.Info()&types.IsFloat != 0
    38  }
    39  
    40  func isComplex(typ types.Type) bool {
    41  	t, ok := typ.Underlying().(*types.Basic)
    42  	return ok && t.Info()&types.IsComplex != 0
    43  }
    44  
    45  func isString(typ types.Type) bool {
    46  	t, ok := typ.Underlying().(*types.Basic)
    47  	return ok && t.Info()&types.IsString != 0
    48  }
    49  
    50  func isUntyped(typ types.Type) bool {
    51  	t, ok := typ.Underlying().(*types.Basic)
    52  	return ok && t.Info()&types.IsUntyped != 0
    53  }
    54  
    55  func 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  }