本文整理汇总了Golang中llvm/org/llgo/third_party/gotools/go/types.Type类的典型用法代码示例。如果您正苦于以下问题:Golang Type类的具体用法?Golang Type怎么用?Golang Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getInterfaceValue
// Reads the value from the given interface type, assuming that the
// interface holds a value of the correct type.
func (fr *frame) getInterfaceValue(v *govalue, ty types.Type) *govalue {
val := fr.builder.CreateExtractValue(v.value, 1, "")
if _, ok := ty.Underlying().(*types.Pointer); !ok {
typedval := fr.builder.CreateBitCast(val, llvm.PointerType(fr.types.ToLLVM(ty), 0), "")
val = fr.builder.CreateLoad(typedval, "")
}
return newValue(val, ty)
}
示例2: hash
func (x array) hash(t types.Type) int {
h := 0
tElt := t.Underlying().(*types.Array).Elem()
for _, xi := range x {
h += hash(tElt, xi)
}
return h
}
示例3: makeInterface
func (fr *frame) makeInterface(llv llvm.Value, vty types.Type, iface types.Type) *govalue {
if _, ok := vty.Underlying().(*types.Pointer); !ok {
ptr := fr.createTypeMalloc(vty)
fr.builder.CreateStore(llv, ptr)
llv = ptr
}
return fr.makeInterfaceFromPointer(llv, vty, iface)
}
示例4: makeInterfaceFromPointer
func (fr *frame) makeInterfaceFromPointer(vptr llvm.Value, vty types.Type, iface types.Type) *govalue {
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
llv := fr.builder.CreateBitCast(vptr, i8ptr, "")
value := llvm.Undef(fr.types.ToLLVM(iface))
itab := fr.types.getItabPointer(vty, iface.Underlying().(*types.Interface))
value = fr.builder.CreateInsertValue(value, itab, 0, "")
value = fr.builder.CreateInsertValue(value, llv, 1, "")
return newValue(value, iface)
}
示例5: getInterfaceValueOrNull
// If cond is true, reads the value from the given interface type, otherwise
// returns a nil value.
func (fr *frame) getInterfaceValueOrNull(cond llvm.Value, v *govalue, ty types.Type) *govalue {
val := fr.builder.CreateExtractValue(v.value, 1, "")
if _, ok := ty.Underlying().(*types.Pointer); ok {
val = fr.builder.CreateSelect(cond, val, llvm.ConstNull(val.Type()), "")
} else {
val = fr.loadOrNull(cond, val, ty).value
}
return newValue(val, ty)
}
示例6: eq
func (x array) eq(t types.Type, _y interface{}) bool {
y := _y.(array)
tElt := t.Underlying().(*types.Array).Elem()
for i, xi := range x {
if !equals(tElt, xi, y[i]) {
return false
}
}
return true
}
示例7: usesBuiltinMap
// usesBuiltinMap returns true if the built-in hash function and
// equivalence relation for type t are consistent with those of the
// interpreter's representation of type t. Such types are: all basic
// types (bool, numbers, string), pointers and channels.
//
// usesBuiltinMap returns false for types that require a custom map
// implementation: interfaces, arrays and structs.
//
// Panic ensues if t is an invalid map key type: function, map or slice.
func usesBuiltinMap(t types.Type) bool {
switch t := t.(type) {
case *types.Basic, *types.Chan, *types.Pointer:
return true
case *types.Named:
return usesBuiltinMap(t.Underlying())
case *types.Interface, *types.Array, *types.Struct:
return false
}
panic(fmt.Sprintf("invalid map key type: %T", t))
}
示例8: CanHaveDynamicTypes
// CanHaveDynamicTypes reports whether the type T can "hold" dynamic types,
// i.e. is an interface (incl. reflect.Type) or a reflect.Value.
//
func CanHaveDynamicTypes(T types.Type) bool {
switch T := T.(type) {
case *types.Named:
if obj := T.Obj(); obj.Name() == "Value" && obj.Pkg().Path() == "reflect" {
return true // reflect.Value
}
return CanHaveDynamicTypes(T.Underlying())
case *types.Interface:
return true
}
return false
}
示例9: interfaceTypeAssert
func (fr *frame) interfaceTypeAssert(val *govalue, ty types.Type) *govalue {
if _, ok := ty.Underlying().(*types.Interface); ok {
return fr.changeInterface(val, ty, true)
} else {
valtytd := fr.types.ToRuntime(val.Type())
valtd := fr.getInterfaceTypeDescriptor(val)
tytd := fr.types.ToRuntime(ty)
fr.runtime.checkInterfaceType.call(fr, valtd, tytd, valtytd)
return fr.getInterfaceValue(val, ty)
}
}
示例10: CanPoint
// CanPoint reports whether the type T is pointerlike,
// for the purposes of this analysis.
func CanPoint(T types.Type) bool {
switch T := T.(type) {
case *types.Named:
if obj := T.Obj(); obj.Name() == "Value" && obj.Pkg().Path() == "reflect" {
return true // treat reflect.Value like interface{}
}
return CanPoint(T.Underlying())
case *types.Pointer, *types.Interface, *types.Map, *types.Chan, *types.Signature, *types.Slice:
return true
}
return false // array struct tuple builtin basic
}
示例11: eqnil
// eqnil returns the comparison x == y using the equivalence relation
// appropriate for type t.
// If t is a reference type, at most one of x or y may be a nil value
// of that type.
//
func eqnil(t types.Type, x, y value) bool {
switch t.Underlying().(type) {
case *types.Map, *types.Signature, *types.Slice:
// Since these types don't support comparison,
// one of the operands must be a literal nil.
switch x := x.(type) {
case *hashmap:
return (x != nil) == (y.(*hashmap) != nil)
case map[value]value:
return (x != nil) == (y.(map[value]value) != nil)
case *ssa.Function:
switch y := y.(type) {
case *ssa.Function:
return (x != nil) == (y != nil)
case *closure:
return true
}
case *closure:
return (x != nil) == (y.(*ssa.Function) != nil)
case []value:
return (x != nil) == (y.([]value) != nil)
}
panic(fmt.Sprintf("eqnil(%s): illegal dynamic type: %T", t, x))
}
return equals(t, x, y)
}
示例12: zeroValue
// zeroValue emits to f code to produce a zero value of type t,
// and returns it.
//
func zeroValue(f *Function, t types.Type) Value {
switch t.Underlying().(type) {
case *types.Struct, *types.Array:
return emitLoad(f, f.addLocal(t, token.NoPos))
default:
return zeroConst(t)
}
}
示例13: store
// store stores value v of type T into *addr.
func store(T types.Type, addr *value, v value) {
switch T := T.Underlying().(type) {
case *types.Struct:
lhs := (*addr).(structure)
rhs := v.(structure)
for i := range lhs {
store(T.Field(i).Type(), &lhs[i], rhs[i])
}
case *types.Array:
lhs := (*addr).(array)
rhs := v.(array)
for i := range lhs {
store(T.Elem(), &lhs[i], rhs[i])
}
default:
*addr = v
}
}
示例14: IntuitiveMethodSet
// IntuitiveMethodSet returns the intuitive method set of a type, T.
//
// The result contains MethodSet(T) and additionally, if T is a
// concrete type, methods belonging to *T if there is no identically
// named method on T itself. This corresponds to user intuition about
// method sets; this function is intended only for user interfaces.
//
// The order of the result is as for types.MethodSet(T).
//
func IntuitiveMethodSet(T types.Type, msets *types.MethodSetCache) []*types.Selection {
var result []*types.Selection
mset := msets.MethodSet(T)
if _, ok := T.Underlying().(*types.Interface); ok {
for i, n := 0, mset.Len(); i < n; i++ {
result = append(result, mset.At(i))
}
} else {
pmset := msets.MethodSet(types.NewPointer(T))
for i, n := 0, pmset.Len(); i < n; i++ {
meth := pmset.At(i)
if m := mset.Lookup(meth.Obj().Pkg(), meth.Obj().Name()); m != nil {
meth = m
}
result = append(result, meth)
}
}
return result
}
示例15: load
// load returns the value of type T in *addr.
func load(T types.Type, addr *value) value {
switch T := T.Underlying().(type) {
case *types.Struct:
v := (*addr).(structure)
a := make(structure, len(v))
for i := range a {
a[i] = load(T.Field(i).Type(), &v[i])
}
return a
case *types.Array:
v := (*addr).(array)
a := make(array, len(v))
for i := range a {
a[i] = load(T.Elem(), &v[i])
}
return a
default:
return *addr
}
}