本文整理汇总了Golang中go/types.Basic.Kind方法的典型用法代码示例。如果您正苦于以下问题:Golang Basic.Kind方法的具体用法?Golang Basic.Kind怎么用?Golang Basic.Kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.Basic
的用法示例。
在下文中一共展示了Basic.Kind方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: convertBasic
func (c *converter) convertBasic(v *gotypes.Basic) *types.Basic {
if v == nil {
return nil
}
if v, ok := c.converted[v]; ok {
return v.(*types.Basic)
}
var ret *types.Basic
for i, b := range gotypes.Typ {
if v == b {
ret = types.Typ[i]
break
}
}
switch v.Kind() {
case gotypes.Byte:
ret = types.ByteType
case gotypes.Rune:
ret = types.RuneType
}
if ret == nil {
panic(fmt.Sprintf("unknown basic type %v", v))
}
c.converted[v] = ret
return ret
}
示例2: javaBasicType
func (g *javaGen) javaBasicType(T *types.Basic) string {
switch T.Kind() {
case types.Bool, types.UntypedBool:
return "boolean"
case types.Int:
return "long"
case types.Int8:
return "byte"
case types.Int16:
return "short"
case types.Int32, types.UntypedRune: // types.Rune
return "int"
case types.Int64, types.UntypedInt:
return "long"
case types.Uint8: // types.Byte
// TODO(crawshaw): Java bytes are signed, so this is
// questionable, but vital.
return "byte"
// TODO(crawshaw): case types.Uint, types.Uint16, types.Uint32, types.Uint64:
case types.Float32:
return "float"
case types.Float64, types.UntypedFloat:
return "double"
case types.String, types.UntypedString:
return "String"
default:
g.errorf("unsupported basic type: %s", T)
return "TODO"
}
}
示例3: toJavaScriptType
func toJavaScriptType(t *types.Basic) string {
switch t.Kind() {
case types.UntypedInt:
return "Int"
case types.Byte:
return "Uint8"
case types.Rune:
return "Int32"
case types.UnsafePointer:
return "UnsafePointer"
default:
name := t.String()
return strings.ToUpper(name[:1]) + name[1:]
}
}
示例4: fixNumber
func (c *funcContext) fixNumber(value *expression, basic *types.Basic) *expression {
switch basic.Kind() {
case types.Int8:
return c.formatParenExpr("%s << 24 >> 24", value)
case types.Uint8:
return c.formatParenExpr("%s << 24 >>> 24", value)
case types.Int16:
return c.formatParenExpr("%s << 16 >> 16", value)
case types.Uint16:
return c.formatParenExpr("%s << 16 >>> 16", value)
case types.Int32, types.Int, types.UntypedInt:
return c.formatParenExpr("%s >> 0", value)
case types.Uint32, types.Uint, types.Uintptr:
return c.formatParenExpr("%s >>> 0", value)
case types.Float32:
return c.formatExpr("$fround(%s)", value)
case types.Float64:
return value
default:
panic(fmt.Sprintf("fixNumber: unhandled basic.Kind(): %s", basic.String()))
}
}
示例5: basicKindString
func basicKindString(b *types.Basic) string {
switch b.Kind() {
case types.Invalid:
return "invalid"
case types.Bool:
return "bool"
case types.Int:
return "int"
case types.Int8:
return "int8"
case types.Int16:
return "int16"
case types.Int32:
return "int32"
case types.Int64:
return "int64"
case types.Uint:
return "uint"
case types.Uint8:
return "uint8"
case types.Uint16:
return "uint16"
case types.Uint32:
return "uint32"
case types.Uint64:
return "uint64"
case types.Uintptr:
return "uintptr"
case types.Float32:
return "float32"
case types.Float64:
return "float64"
case types.Complex64:
return "complex64"
case types.Complex128:
return "complex128"
case types.String:
return "string"
case types.UnsafePointer:
return "unsafepointer"
// types for untyped values
case types.UntypedBool:
return "bool"
case types.UntypedInt:
return "int"
case types.UntypedRune:
return "rune"
case types.UntypedFloat:
return "float"
case types.UntypedComplex:
return "complex"
case types.UntypedString:
return "string"
case types.UntypedNil:
return "nil"
default:
return "unsupported"
}
}
示例6: is64Bit
func is64Bit(t *types.Basic) bool {
return t.Kind() == types.Int64 || t.Kind() == types.Uint64
}