本文整理匯總了Golang中code/google/com/p/rsc/cc.Type.Base方法的典型用法代碼示例。如果您正苦於以下問題:Golang Type.Base方法的具體用法?Golang Type.Base怎麽用?Golang Type.Base使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/rsc/cc.Type
的用法示例。
在下文中一共展示了Type.Base方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: toGoType
func toGoType(g *flowGroup, x cc.Syntax, typ *cc.Type, cache map[*cc.Type]*cc.Type) (ret *cc.Type) {
if typ == nil {
return nil
}
// Array and func implicitly convert to pointer types, so don't
// trust the group they are in - they'll turn into pointers incorrectly.
if g != nil && typ.Kind != cc.Array && typ.Kind != cc.Func {
if g.goType != nil {
return g.goType
}
defer func() {
if ret != nil && ret.Kind <= cc.Enum {
panic("bad go type override")
}
g.goType = ret
}()
}
// Look in cache first. This cuts off recursion for self-referential types.
// The cache only contains aggregate types - numeric types are shared
// by many expressions in the program and we might want to translate
// them differently in different contexts.
if cache[typ] != nil {
return cache[typ]
}
var force *cc.Type
if d, ok := x.(*cc.Decl); ok {
key := declKey(d)
force = override[key]
}
switch typ.Kind {
default:
panic(fmt.Sprintf("unexpected C type %s", typ))
case c2go.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:
// TODO: Use group.
if force != nil {
return force
}
return &cc.Type{Kind: c2goKind[typ.Kind]}
case cc.Ptr:
t := &cc.Type{Kind: cc.Ptr}
cache[typ] = t
t.Base = toGoType(nil, nil, typ.Base, cache)
if g != nil {
if g.goKind != 0 {
t.Kind = g.goKind
return t
}
for _, f := range g.syntax {
if f.ptrAdd || f.ptrIndex {
t.Kind = c2go.Slice
}
}
}
if force != nil {
if force.Base != nil {
return force
}
if force.Kind == cc.Ptr || force.Kind == c2go.Slice {
t.Kind = force.Kind
return t
}
}
if typ.Base.Kind == cc.Char {
t.Kind = c2go.String
t.Base = nil
return t
}
return t
case cc.Array:
if typ.Base.Def().Kind == cc.Char {
return &cc.Type{Kind: c2go.String}
}
t := &cc.Type{Kind: cc.Array, Width: typ.Width}
cache[typ] = t
t.Base = toGoType(nil, nil, typ.Base, cache)
return t
case cc.TypedefType:
// If this is a typedef like uchar, translate the base type directly.
def := typ.Base
if cc.Char <= def.Kind && def.Kind <= cc.Enum {
return toGoType(g, x, def, cache)
//.........這裏部分代碼省略.........