當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Type.DotDotDot方法代碼示例

本文整理匯總了Golang中reflect.Type.DotDotDot方法的典型用法代碼示例。如果您正苦於以下問題:Golang Type.DotDotDot方法的具體用法?Golang Type.DotDotDot怎麽用?Golang Type.DotDotDot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在reflect.Type的用法示例。


在下文中一共展示了Type.DotDotDot方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TypeFromNative

// TypeFromNative converts a regular Go type into a the corresponding
// interpreter Type.
func TypeFromNative(t reflect.Type) Type {
	if et, ok := evalTypes[t]; ok {
		return et
	}

	var nt *NamedType
	if t.Name() != "" {
		name := t.PkgPath() + "·" + t.Name()
		nt = &NamedType{token.Position{}, name, nil, true, make(map[string]Method)}
		evalTypes[t] = nt
	}

	var et Type
	switch t := t.(type) {
	case *reflect.BoolType:
		et = BoolType
	case *reflect.FloatType:
		switch t.Kind() {
		case reflect.Float32:
			et = Float32Type
		case reflect.Float64:
			et = Float64Type
		case reflect.Float:
			et = FloatType
		}
	case *reflect.IntType:
		switch t.Kind() {
		case reflect.Int16:
			et = Int16Type
		case reflect.Int32:
			et = Int32Type
		case reflect.Int64:
			et = Int64Type
		case reflect.Int8:
			et = Int8Type
		case reflect.Int:
			et = IntType
		}
	case *reflect.UintType:
		switch t.Kind() {
		case reflect.Uint16:
			et = Uint16Type
		case reflect.Uint32:
			et = Uint32Type
		case reflect.Uint64:
			et = Uint64Type
		case reflect.Uint8:
			et = Uint8Type
		case reflect.Uint:
			et = UintType
		case reflect.Uintptr:
			et = UintptrType
		}
	case *reflect.StringType:
		et = StringType
	case *reflect.ArrayType:
		et = NewArrayType(int64(t.Len()), TypeFromNative(t.Elem()))
	case *reflect.ChanType:
		log.Panicf("%T not implemented", t)
	case *reflect.FuncType:
		nin := t.NumIn()
		// Variadic functions have DotDotDotType at the end
		variadic := t.DotDotDot()
		if variadic {
			nin--
		}
		in := make([]Type, nin)
		for i := range in {
			in[i] = TypeFromNative(t.In(i))
		}
		out := make([]Type, t.NumOut())
		for i := range out {
			out[i] = TypeFromNative(t.Out(i))
		}
		et = NewFuncType(in, variadic, out)
	case *reflect.InterfaceType:
		log.Panicf("%T not implemented", t)
	case *reflect.MapType:
		log.Panicf("%T not implemented", t)
	case *reflect.PtrType:
		et = NewPtrType(TypeFromNative(t.Elem()))
	case *reflect.SliceType:
		et = NewSliceType(TypeFromNative(t.Elem()))
	case *reflect.StructType:
		n := t.NumField()
		fields := make([]StructField, n)
		for i := 0; i < n; i++ {
			sf := t.Field(i)
			// TODO(austin) What to do about private fields?
			fields[i].Name = sf.Name
			fields[i].Type = TypeFromNative(sf.Type)
			fields[i].Anonymous = sf.Anonymous
		}
		et = NewStructType(fields)
	case *reflect.UnsafePointerType:
		log.Panicf("%T not implemented", t)
	default:
		log.Panicf("unexpected reflect.Type: %T", t)
//.........這裏部分代碼省略.........
開發者ID:GNA-SERVICES-INC,項目名稱:MoNGate,代碼行數:101,代碼來源:bridge.go


注:本文中的reflect.Type.DotDotDot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。