本文整理匯總了Golang中rsc/io/c2go/cc.Type.Kind方法的典型用法代碼示例。如果您正苦於以下問題:Golang Type.Kind方法的具體用法?Golang Type.Kind怎麽用?Golang Type.Kind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rsc/io/c2go/cc.Type
的用法示例。
在下文中一共展示了Type.Kind方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: toGoType
func toGoType(cfg *Config, x cc.Syntax, typ *cc.Type, cache map[*cc.Type]*cc.Type) *cc.Type {
if typ == nil {
return nil
}
if cache[typ] != nil {
return cache[typ]
}
switch typ.Kind {
default:
panic(fmt.Sprintf("unexpected C type %s", typ))
case Ideal:
return typ
case cc.Void:
return &cc.Type{Kind: cc.Struct} // struct{}
case cc.Char, cc.Uchar, cc.Short, cc.Ushort, cc.Int, cc.Uint, cc.Long, cc.Ulong, cc.Longlong, cc.Ulonglong, cc.Float, cc.Double, cc.Enum:
t := &cc.Type{Kind: c2goKind[typ.Kind]}
if d, ok := x.(*cc.Decl); ok {
if cfg.bool[declKey(d)] {
t.Kind = Bool
} else if strings.HasPrefix(d.Name, "no") {
println("not bool", d.Name, declKey(d))
}
}
return t
case cc.TypedefType:
if cfg.typeMap[typ.Name] != "" {
t := &cc.Type{Kind: cc.TypedefType, Name: cfg.typeMap[typ.Name], TypeDecl: typ.TypeDecl}
cache[typ] = t
return t
}
// If this is a typedef like uchar, translate the type by name.
// Otherwise fall back to base.
def := typ.Base
if cc.Char <= def.Kind && def.Kind <= cc.Enum {
var t *cc.Type
if c2goName[typ.Name] != 0 {
t = &cc.Type{Kind: c2goName[typ.Name]}
} else {
t = &cc.Type{Kind: c2goKind[typ.Base.Kind]}
}
if d, ok := x.(*cc.Decl); ok {
if cfg.bool[declKey(d)] {
t.Kind = Bool
} else if strings.HasPrefix(d.Name, "no") {
println("not bool", d.Name, declKey(d))
}
}
return t
}
if typ.Name == "va_list" {
return &cc.Type{Kind: cc.TypedefType, Name: "[]interface{}"}
}
// Otherwise assume it is a struct or some such,
// and preserve the name but translate the base.
t := &cc.Type{Kind: cc.TypedefType, Name: typ.Name, TypeDecl: typ.TypeDecl}
cache[typ] = t
t.Base = toGoType(cfg, nil, typ.Base, cache)
return t
case cc.Array:
if typ.Base.Def().Kind == cc.Char {
return &cc.Type{Kind: String}
}
t := &cc.Type{Kind: cc.Array, Width: typ.Width}
cache[typ] = t
t.Base = toGoType(cfg, nil, typ.Base, cache)
return t
case cc.Ptr:
t := &cc.Type{Kind: cc.Ptr}
cache[typ] = t
base := x
if typ.Base.Kind != cc.Func {
base = nil
}
t.Base = toGoType(cfg, base, typ.Base, cache)
// Convert void* to interface{}.
if typ.Base.Kind == cc.Void {
t.Base = nil
t.Kind = cc.TypedefType
t.Name = "interface{}"
return t
}
if typ.Base.Kind == cc.Char {
t.Kind = String
t.Base = nil
return t
}
//.........這裏部分代碼省略.........