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


Golang Type.String方法代码示例

本文整理汇总了Golang中golang.org/x/tools/go/types.Type.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Type.String方法的具体用法?Golang Type.String怎么用?Golang Type.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在golang.org/x/tools/go/types.Type的用法示例。


在下文中一共展示了Type.String方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: MustWriteGoTypes

func MustWriteGoTypes(thisPackagePath string, typi types.Type) (s string, addPkgPathList []string) {
	switch typ := typi.(type) {
	case *types.Basic:
		return typ.String(), nil
	case *types.Named:
		if typ.Obj().Pkg() == nil {
			return typ.Obj().Name(), nil
		}
		typPkgPath := typ.Obj().Pkg().Path()
		if thisPackagePath == typPkgPath {
			return typ.Obj().Name(), nil
		}
		return path.Base(typPkgPath) + "." + typ.Obj().Name(), []string{typPkgPath}
	case *types.Pointer:
		s, addPkgPathList = MustWriteGoTypes(thisPackagePath, typ.Elem())
		return "*" + s, addPkgPathList
	case *types.Slice:
		s, addPkgPathList = MustWriteGoTypes(thisPackagePath, typ.Elem())
		return "[]" + s, addPkgPathList
	case *types.Interface:
		return typ.String(), nil
		//s, addPkgPathList = MustWriteGoTypes(thisPackagePath, typ.Elem())
		//return "[]" + s, addPkgPathList
	default:
		panic(fmt.Errorf("[MustWriteGoTypes] Not implement go/types [%T] [%s]",
			typi, typi.String()))
	}
	return "", nil
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:29,代码来源:types.go

示例2: sizeof

func sizeof(t types.Type) uint {

	switch t := t.(type) {
	case *types.Tuple:
		// TODO: usage of reflect most likely wrong!
		// uint(reflect.TypeOf(t).Elem().Size())
		panic("Tuples are unsupported")
	case *types.Basic:
		return sizeBasic(t.Kind())
	case *types.Pointer:
		return sizePtr()
	case *types.Slice:
		return sizeSlice(t)
	case *types.Array:
		return sizeArray(t)
	case *types.Named:
		if sse2, ok := sse2Info(t); ok {
			return sse2.size
		} else if info, ok := simdInfo(t); ok {
			return info.size
		} else {
			panic(ice(fmt.Sprintf("unknown named type \"%v\"", t.String())))
		}
	}
	panic(ice(fmt.Sprintf("unknown type: %v", t)))
}
开发者ID:bjwbell,项目名称:gensimd,代码行数:26,代码来源:sizeinfo.go

示例3: getStructType

func getStructType(t types.Type) string {
	ts := t.String()
	if ts != "time.Time" && ts != "bson.ObjectId" {
		return "struct"
	}

	return ts
}
开发者ID:vsouza,项目名称:storable,代码行数:8,代码来源:processor.go

示例4: typefmt

func typefmt(typ types.Type) string {
	// Ugh.
	typename := typ.String()
	for _, p := range strings.Split(os.Getenv("GOPATH"), ":") {
		typename = strings.Replace(typename, p+"/src/", "", -1)
	}
	return typename
}
开发者ID:johan--,项目名称:kube-annotator,代码行数:8,代码来源:intermediate.go

示例5: MakeInterface

func (l langType) MakeInterface(register string, regTyp types.Type, v interface{}, errorInfo string) string {
	ret := `new Interface(` + l.PogoComp().LogTypeUse(v.(ssa.Value).Type() /*NOT underlying()*/) + `,` +
		l.IndirectValue(v, errorInfo) + ")"
	if getHaxeClass(regTyp.String()) != "" {
		ret = "Force.toHaxeParam(" + ret + ")" // as interfaces are not native to haxe, so need to convert
		// TODO optimize when stable
	}
	return register + `=` + ret + ";"
}
开发者ID:henrylee2cn,项目名称:tardisgo,代码行数:9,代码来源:types.go

示例6: 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:himanshugpt,项目名称:evergreen,代码行数:11,代码来源:implements.go

示例7: cgoTypeName

func cgoTypeName(typ types.Type) string {
	switch typ := typ.(type) {
	case *types.Basic:
		kind := typ.Kind()
		o, ok := typedescr[kind]
		if ok {
			return o.cgotype
		}
	}
	return typ.String()
}
开发者ID:justinfx,项目名称:gopy,代码行数:11,代码来源:types.go

示例8: newVar

func newVar(p *Package, typ types.Type, objname, name, doc string) *Var {
	sym := p.syms.symtype(typ)
	if sym == nil {
		panic(fmt.Errorf("could not find symbol for type [%s]!", typ.String()))
	}
	return &Var{
		pkg:  p,
		sym:  sym,
		id:   p.Name() + "_" + objname,
		doc:  doc,
		name: name,
	}
}
开发者ID:kellrott,项目名称:gopy,代码行数:13,代码来源:vars.go

示例9: align

func align(t types.Type) uint {

	switch t := t.(type) {
	case *types.Tuple:
		return alignTuple(t)
	case *types.Array, *types.Basic, *types.Pointer, *types.Slice:
		return uint(reflectType(t).Align())
	case *types.Named:
		if sse2, ok := sse2Info(t); ok {
			return sse2.align
		} else if info, ok := simdInfo(t); ok {
			return info.align
		} else {
			panic(ice(fmt.Sprintf("unknown named type \"%v\"", t.String())))
		}
	}
	panic(ice(fmt.Sprintf("unknown type (%v)", t)))
}
开发者ID:bjwbell,项目名称:gensimd,代码行数:18,代码来源:sizeinfo.go

示例10: qualifiedType

func (g *goGen) qualifiedType(typ types.Type) string {
	switch typ := typ.(type) {
	case *types.Basic:
		return typ.Name()
	case *types.Named:
		obj := typ.Obj()
		//return obj.Pkg().Name() + "." + obj.Name()
		return "GoPy_" + obj.Name()
		switch typ := typ.Underlying().(type) {
		case *types.Struct:
			return typ.String()
		default:
			return "GoPy_ooops_" + obj.Name()
		}
	}

	return fmt.Sprintf("%#T", typ)
}
开发者ID:justinfx,项目名称:gopy,代码行数:18,代码来源:gengo.go

示例11: sizeofElem

func sizeofElem(t types.Type) uint {
	var e types.Type
	switch t := t.(type) {
	default:
		panic(ice(fmt.Sprintf("type (%v) not an array or slice\n", t.String())))
	case *types.Slice:
		e = t.Elem()
	case *types.Array:
		e = t.Elem()
	case *types.Named:
		if typeinfo, ok := simdInfo(t); ok {
			return typeinfo.elemSize
		}
		panic(ice(
			fmt.Sprintf("t (%v), isSimd (%v)\n", t.String(), isSimd(t))))

	}
	return sizeof(e)
}
开发者ID:bjwbell,项目名称:gensimd,代码行数:19,代码来源:sizeinfo.go

示例12: rtypeBuild

func (l langType) rtypeBuild(i int, sizes types.Sizes, t types.Type, name string) (string, reflect.Kind) {
	var kind reflect.Kind
	kind, name = getTypeInfo(t, name)
	sof := int64(4)
	aof := int64(4)
	if kind != reflect.Invalid {
		sof = sizes.Sizeof(t)
		aof = sizes.Alignof(t)
	}

	ret := "Go_haxegoruntime_newRRtype.callFromRT(0,\n"
	ret += fmt.Sprintf("\t/*size:*/ %d,\n", sof)
	ret += fmt.Sprintf("\t/*align:*/ %d,\n", aof)
	ret += fmt.Sprintf("\t/*fieldAlign:*/ %d,\n", aof) // TODO check correct for fieldAlign
	ret += fmt.Sprintf("\t/*kind:*/ %d, // %s\n", kind, (kind & ((1 << 5) - 1)).String())
	alg := "false"
	if types.Comparable(t) {
		alg = "true"
	}
	ret += fmt.Sprintf("\t/*comprable:*/ %s,\n", alg) // TODO change this to be the actual function
	ret += fmt.Sprintf("\t/*string:*/ \"%s\", // %s\n", escapedTypeString(t.String()), t.String())
	ret += fmt.Sprintf("\t/*uncommonType:*/ %s,\n", l.uncommonBuild(i, sizes, name, t))
	ptt := "null"
	for pti, pt := range l.hc.typesByID {
		_, isPtr := pt.(*types.Pointer)
		if isPtr {
			ele := l.hc.pte.At(pt.(*types.Pointer).Elem())
			if ele != nil {
				if i == ele.(int) {
					ptt = fmt.Sprintf("type%d()", pti)
				}
			}
		}
	}
	ret += fmt.Sprintf("\t/*ptrToThis:*/ %s", ptt)
	ret += ")"
	return ret, kind
}
开发者ID:jmptrader,项目名称:tardisgo,代码行数:38,代码来源:tgotypes.go

示例13: getBackendType

func (tm *llvmTypeMap) getBackendType(t types.Type) backendType {
	switch t := t.(type) {
	case *types.Named:
		return tm.getBackendType(t.Underlying())

	case *types.Basic:
		switch t.Kind() {
		case types.Bool, types.Uint8:
			return &intBType{1, false}
		case types.Int8:
			return &intBType{1, true}
		case types.Uint16:
			return &intBType{2, false}
		case types.Int16:
			return &intBType{2, true}
		case types.Uint32:
			return &intBType{4, false}
		case types.Int32:
			return &intBType{4, true}
		case types.Uint64:
			return &intBType{8, false}
		case types.Int64:
			return &intBType{8, true}
		case types.Uint, types.Uintptr:
			return &intBType{tm.target.PointerSize(), false}
		case types.Int:
			return &intBType{tm.target.PointerSize(), true}
		case types.Float32:
			return &floatBType{false}
		case types.Float64:
			return &floatBType{true}
		case types.UnsafePointer:
			return &ptrBType{}
		case types.Complex64:
			f32 := &floatBType{false}
			return &structBType{[]backendType{f32, f32}}
		case types.Complex128:
			f64 := &floatBType{true}
			return &structBType{[]backendType{f64, f64}}
		case types.String:
			return &structBType{[]backendType{&ptrBType{}, &intBType{tm.target.PointerSize(), false}}}
		}

	case *types.Struct:
		var fields []backendType
		for i := 0; i != t.NumFields(); i++ {
			f := t.Field(i)
			fields = append(fields, tm.getBackendType(f.Type()))
		}
		return &structBType{fields}

	case *types.Pointer, *types.Signature, *types.Map, *types.Chan:
		return &ptrBType{}

	case *types.Interface:
		i8ptr := &ptrBType{}
		return &structBType{[]backendType{i8ptr, i8ptr}}

	case *types.Slice:
		return tm.sliceBackendType()

	case *types.Array:
		return &arrayBType{uint64(t.Len()), tm.getBackendType(t.Elem())}
	}

	panic("unhandled type: " + t.String())
}
开发者ID:hinike,项目名称:llgo,代码行数:67,代码来源:cabi.go

示例14: typeBuild

func (l langType) typeBuild(i int, t types.Type) string {
	sizes := &haxeStdSizes
	ret := fmt.Sprintf( // sizeof largest struct (funcType) is 76
		"private static var type%dptr:Pointer=null; // %s\npublic static function type%d():Pointer { if(type%dptr==null) { type%dptr=Pointer.make(Object.make(80));",
		i, t.String(), i, i, i)
	ret += ""

	name := ""
	if namedT, named := t.(*types.Named); named {
		name = namedT.Obj().Name()
	}
	if basic, isBasic := t.(*types.Basic); isBasic {
		name = basic.Name()
	}
	rtype, kind := l.rtypeBuild(i, sizes, t, name)

	switch t.(type) {
	case *types.Named:
		t = t.(*types.Named).Underlying()
	}

	switch kind & kindMask {
	case reflect.Invalid, reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
		reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
		reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.String, reflect.UnsafePointer:
		ret += fmt.Sprintf("Go_haxegoruntime_fillRRtype.callFromRT(0,type%dptr,%s)", i, rtype)

	case reflect.Ptr:
		ret += fmt.Sprintf("Go_haxegoruntime_fillPPtrTType.callFromRT(0,type%dptr,\n/*rtype:*/ ", i) + rtype + ",\n"
		if l.hc.pte.At(t.(*types.Pointer).Elem()) == nil {
			ret += fmt.Sprintf("/*elem:*/ nil,\n")
		} else {
			ret += fmt.Sprintf("/*elem:*/ type%d()\n",
				l.hc.pte.At(t.(*types.Pointer).Elem()).(int))
		}
		ret += ")"

	case reflect.Array:
		ret += fmt.Sprintf("Go_haxegoruntime_fillAArrayTType.callFromRT(0,type%dptr,\n/*rtype:*/ ", i) + rtype + ",\n"
		ret += fmt.Sprintf("/*elem:*/ type%d(),\n",
			l.hc.pte.At(t.(*types.Array).Elem()).(int))
		asl := "null" // slice type
		for _, tt := range l.hc.pte.Keys() {
			slt, isSlice := tt.(*types.Slice)
			if isSlice {
				if l.hc.pte.At(slt.Elem()) == l.hc.pte.At(t.(*types.Array).Elem()) {
					asl = fmt.Sprintf("type%d()",
						l.hc.pte.At(slt).(int))
					break
				}
			}
		}
		// TODO make missing slice types before we start outputting types to avoid not having one?
		ret += fmt.Sprintf("/*slice:*/ %s,\n", asl)
		ret += fmt.Sprintf("/*len:*/ %d\n", t.(*types.Array).Len())
		ret += ")"

	case reflect.Slice:
		ret += fmt.Sprintf("Go_haxegoruntime_fillSSliceTType.callFromRT(0,type%dptr,\n/*rtype:*/ ", i) + rtype + ",\n"
		ret += fmt.Sprintf("/*elem:*/ type%d()\n", l.hc.pte.At(t.(*types.Slice).Elem()).(int))
		ret += ")"

	case reflect.Struct:
		fields := []*types.Var{}
		for fld := 0; fld < t.(*types.Struct).NumFields(); fld++ {
			fldInfo := t.(*types.Struct).Field(fld)
			//if fldInfo.IsField() {
			fields = append(fields, fldInfo)
			//}
		}
		offs := sizes.Offsetsof(fields)

		ret += fmt.Sprintf("Go_haxegoruntime_fillSStructTType.callFromRT(0,type%dptr,\n/*rtype:*/ ", i) + rtype + ",\n/*fields:*/ "
		fret := "Go_haxegoruntime_newSStructFFieldSSlice.callFromRT(0)"
		numFlds := t.(*types.Struct).NumFields()
		for fld := 0; fld < numFlds; fld++ {
			fldInfo := t.(*types.Struct).Field(fld)
			name := fldInfo.Name()
			path := fldInfo.Pkg().Path()
			if fldInfo.Exported() {
				path = ""
			}
			if fldInfo.Anonymous() {
				name = ""
			}

			fret = "\tGo_haxegoruntime_addSStructFFieldSSlice.callFromRT(0," + fret + ","
			fret += "\n\t\t/*name:*/ \"" + name + "\",\n"
			fret += "\t\t/*pkgPath:*/ \"" + path + "\",\n"
			fret += fmt.Sprintf("\t\t/*typ:*/ type%d(),// %s\n", l.hc.pte.At(fldInfo.Type()), fldInfo.Type().String())
			fret += "\t\t/*tag:*/ \"" + escapedTypeString(t.(*types.Struct).Tag(fld)) + "\", // " + t.(*types.Struct).Tag(fld) + "\n"
			fret += fmt.Sprintf("\t\t/*offset:*/ %d\n", offs[fld])

			fret += "\t)"
		}

		ret += fret + ")"

	case reflect.Interface:
		ret += fmt.Sprintf("Go_haxegoruntime_fillIInterfaceTType.callFromRT(0,type%dptr,\n/*rtype:*/ ", i) + rtype + ",\n/*methods:*/ "
//.........这里部分代码省略.........
开发者ID:jmptrader,项目名称:tardisgo,代码行数:101,代码来源:tgotypes.go


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