本文整理汇总了Golang中code/google/com/p/go/tools/go/types.Type.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Type.String方法的具体用法?Golang Type.String怎么用?Golang Type.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/go/tools/go/types.Type
的用法示例。
在下文中一共展示了Type.String方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tollvmDebugDescriptor
func (c *compiler) tollvmDebugDescriptor(t types.Type) llvm.DebugDescriptor {
switch t := t.(type) {
case *types.Pointer:
return llvm.NewPointerDerivedType(c.tollvmDebugDescriptor(t.Elem()))
case nil:
return void_debug_type
}
bt := &llvm.BasicTypeDescriptor{
Name: t.String(),
Size: uint64(c.types.Sizeof(t) * 8),
Alignment: uint64(c.types.Alignof(t) * 8),
}
if basic, ok := t.(*types.Basic); ok {
switch bi := basic.Info(); {
case bi&types.IsBoolean != 0:
bt.TypeEncoding = llvm.DW_ATE_boolean
case bi&types.IsUnsigned != 0:
bt.TypeEncoding = llvm.DW_ATE_unsigned
case bi&types.IsInteger != 0:
bt.TypeEncoding = llvm.DW_ATE_signed
case bi&types.IsFloat != 0:
bt.TypeEncoding = llvm.DW_ATE_float
}
}
return bt
}
示例2: typeTypeToJson
func typeTypeToJson(t types.Type) interface{} {
if t != nil {
return t.String()
} else {
return nil
}
}
示例3: pkg_type
// TODO(): This does not return the right think for *, [], map[] types
func (g *Go) pkg_type(t types.Type) (ret content.Type) {
n := t.String()
if i := strings.LastIndex(n, "."); i > 0 {
ret.Name.Relative = n[i+1:]
ret.Name.Absolute = n
} else {
ret.Name.Relative = n
ret.Name.Absolute = n
}
return
}
示例4: makeImplementsType
func makeImplementsType(T types.Type, fset *token.FileSet) serial.ImplementsType {
var pos token.Pos
if nt, ok := deref(T).(*types.Named); ok { // implementsResult.t may be non-named
pos = nt.Obj().Pos()
}
return serial.ImplementsType{
Name: T.String(),
Pos: fset.Position(pos).String(),
Kind: typeKind(T),
}
}
示例5: describeType
func describeType(o *Oracle, qpos *QueryPos, path []ast.Node) (*describeTypeResult, error) {
var description string
var t types.Type
switch n := path[0].(type) {
case *ast.Ident:
t = qpos.info.TypeOf(n)
switch t := t.(type) {
case *types.Basic:
description = "reference to built-in type " + t.String()
case *types.Named:
isDef := t.Obj().Pos() == n.Pos() // see caveats at isDef above
if isDef {
description = "definition of type " + t.String()
} else {
description = "reference to type " + t.String()
}
}
case ast.Expr:
t = qpos.info.TypeOf(n)
description = "type " + t.String()
default:
// Unreachable?
return nil, fmt.Errorf("unexpected AST for type: %T", n)
}
return &describeTypeResult{
node: path[0],
description: description,
typ: t,
methods: accessibleMethods(t, qpos.info.Pkg),
}, nil
}
示例6: relType
// relType is like t.String(), but if t is a Named type belonging to
// package from, optionally wrapped by one or more Pointer
// constructors, package qualification is suppressed.
//
// TODO(gri): provide this functionality in go/types (using a
// *types.Package, obviously).
//
// TODO(adonovan): use this more widely, e.g.
// ChangeType, Literal, Convert, MakeInterface;
// when displaying receiver, params, locals, captures of a Function;
// and in the RHS type column for Value-defining Instructions.
//
// TODO(adonovan): fix: unsafe.Pointer has no ssa.Package.
//
func relType(t types.Type, from *Package) string {
if from != nil {
t2 := t
var nptr int // number of Pointers stripped off
for {
ptr, ok := t2.(*types.Pointer)
if !ok {
break
}
t2 = ptr.Elem()
nptr++
}
if n, ok := t2.(*types.Named); ok && n.Obj().Pkg() == from.Object {
return strings.Repeat("*", nptr) + n.Obj().Name()
}
}
return t.String()
}
示例7: makeRtype
func (tm *TypeMap) makeRtype(t types.Type, k reflect.Kind) llvm.Value {
// Not sure if there's an easier way to do this, but if you just
// use ConstStruct, you end up getting a different llvm.Type.
typ := llvm.ConstNull(tm.runtime.rtype.llvm)
elementTypes := tm.runtime.rtype.llvm.StructElementTypes()
// Size.
size := llvm.ConstInt(elementTypes[0], uint64(tm.Sizeof(t)), false)
typ = llvm.ConstInsertValue(typ, size, []uint32{0})
// TODO hash
// TODO padding
// Alignment.
align := llvm.ConstInt(llvm.Int8Type(), uint64(tm.Alignof(t)), false)
typ = llvm.ConstInsertValue(typ, align, []uint32{3}) // var
typ = llvm.ConstInsertValue(typ, align, []uint32{4}) // field
// Kind.
kind := llvm.ConstInt(llvm.Int8Type(), uint64(k), false)
typ = llvm.ConstInsertValue(typ, kind, []uint32{5})
// Algorithm table.
alg := tm.makeAlgorithmTable(t)
algptr := llvm.AddGlobal(tm.module, alg.Type(), "")
algptr.SetInitializer(alg)
algptr = llvm.ConstBitCast(algptr, elementTypes[6])
typ = llvm.ConstInsertValue(typ, algptr, []uint32{6})
// String representation.
stringrep := tm.globalStringPtr(t.String())
typ = llvm.ConstInsertValue(typ, stringrep, []uint32{8})
// TODO gc
return typ
}
示例8: hashType
// hashType returns a hash for t such that
// types.IsIdentical(x, y) => hashType(x) == hashType(y).
func hashType(t types.Type) int {
return hashString(t.String()) // TODO(gri): provide a better hash
}