当前位置: 首页>>代码示例>>Golang>>正文


Golang Type.String方法代码示例

本文整理汇总了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
}
开发者ID:pcc,项目名称:llgo,代码行数:26,代码来源:debug.go

示例2: typeTypeToJson

func typeTypeToJson(t types.Type) interface{} {
	if t != nil {
		return t.String()
	} else {
		return nil
	}
}
开发者ID:sqs,项目名称:go-symb,代码行数:7,代码来源:symb_test.go

示例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
}
开发者ID:NeoTse,项目名称:completion,代码行数:12,代码来源:complete.go

示例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),
	}
}
开发者ID:ufo22940268,项目名称:two-server-others,代码行数:11,代码来源:implements.go

示例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
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:35,代码来源:describe.go

示例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()
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:32,代码来源:print.go

示例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
}
开发者ID:minux,项目名称:llgo,代码行数:36,代码来源:typemap.go

示例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
}
开发者ID:pombredanne,项目名称:go.tools,代码行数:5,代码来源:value.go


注:本文中的code/google/com/p/go/tools/go/types.Type.String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。