本文整理匯總了Golang中code/google/com/p/rsc/cc.Type.Def方法的典型用法代碼示例。如果您正苦於以下問題:Golang Type.Def方法的具體用法?Golang Type.Def怎麽用?Golang Type.Def使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/rsc/cc.Type
的用法示例。
在下文中一共展示了Type.Def方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: zeroFor
func zeroFor(targ *cc.Type) *cc.Expr {
if targ != nil {
k := targ.Def().Kind
switch k {
case c2go.String:
return &cc.Expr{Op: cc.String, Texts: []string{`""`}}
case c2go.Slice, cc.Ptr:
return &cc.Expr{Op: cc.Name, Text: "nil"}
case cc.Struct, cc.Array:
return &cc.Expr{Op: cc.CastInit, Type: targ, Init: &cc.Init{}}
case c2go.Bool:
return &cc.Expr{Op: cc.Name, Text: "false"}
}
if c2go.Int8 <= k && k <= c2go.Float64 {
return &cc.Expr{Op: cc.Number, Text: "0"}
}
return &cc.Expr{Op: cc.Number, Text: "0 /*" + targ.String() + "*/"}
}
return &cc.Expr{Op: cc.Number, Text: "0 /*untyped*/"}
}
示例2: sameType
func sameType(t, u *cc.Type) bool {
t = t.Def()
u = u.Def()
if t == u {
return true
}
if t == nil || u == nil {
return false
}
if t.Kind != u.Kind {
return false
}
if t.Name != "" || u.Name != "" {
return t.Name == u.Name
}
if !sameType(t.Base, u.Base) || len(t.Decls) != len(u.Decls) {
return false
}
for i, td := range t.Decls {
ud := u.Decls[i]
if !sameType(td.Type, ud.Type) || t.Kind == cc.Struct && td.Name != ud.Name {
return false
}
}
return true
}
示例3: inferCompatible
func inferCompatible(t1, t2 *cc.Type) bool {
t1 = t1.Def()
t2 = t2.Def()
if isNumericCType(t1) && isNumericCType(t2) {
return true
}
if t1.Kind == cc.Ptr && t1.Base.Kind == cc.Func {
t1 = t1.Base
}
if t2.Kind == cc.Ptr && t2.Base.Kind == cc.Func {
t2 = t2.Base
}
if sameType(t1, t2) {
return true
}
if t1.Kind > t2.Kind {
t1, t2 = t2, t1
}
if t1.Kind == cc.Ptr && t2.Kind == cc.Array && (t1.Base.Is(cc.Void) || sameType(t1.Base, t2.Base)) {
return true
}
if t1.Kind == cc.Ptr && t2.Kind == cc.Ptr && (t1.Base.Is(cc.Void) || t2.Base.Is(cc.Void)) {
return true
}
return false
}
示例4: printInit
func (p *Printer) printInit(typ *cc.Type, x *cc.Init) {
p.Print(x.Comments.Before)
defer p.Print(x.Comments.Suffix, x.Comments.After)
if len(x.Prefix) > 0 {
for _, pre := range x.Prefix {
p.Print(pre)
}
}
if x.Expr != nil {
if x.Expr.Op == cc.Number && (typ.Is(cc.Ptr) || typ.Is(Slice)) {
p.Print("nil")
return
}
p.printExpr(x.Expr, precComma)
return
}
nl := len(x.Braced) > 0 && x.Braced[0].Span.Start.Line != x.Braced[len(x.Braced)-1].Span.End.Line
if typ != nil {
p.printType(typ)
}
p.Print("{")
if nl {
p.Print(Indent)
}
warned := false
for i, y := range x.Braced {
if nl {
p.Print(Newline)
} else if i > 0 {
p.Print(" ")
}
var subtyp *cc.Type
if typ != nil {
if typ.Is(cc.Struct) && i < len(typ.Def().Decls) && len(y.Prefix) == 0 {
subtyp = typ.Def().Decls[i].Type
} else if typ.Is(cc.Struct) && len(y.Prefix) == 1 && y.Prefix[0].XDecl != nil {
subtyp = y.Prefix[0].XDecl.Type
} else if typ.Is(cc.Array) || typ.Is(Slice) {
subtyp = typ.Def().Base
} else if !warned {
warned = true
fprintf(x.Span, "too many fields in braced initializer of %s", GoString(typ))
}
}
p.printInit(subtyp, y)
p.Print(",")
}
if typ != nil && typ.Is(cc.Struct) && len(x.Braced) > 0 && len(x.Braced[0].Prefix) == 0 && len(x.Braced) < len(typ.Def().Decls) {
for i := len(x.Braced); i < len(typ.Def().Decls); i++ {
subtyp := typ.Def().Decls[i].Type
if subtyp.Is(cc.Ptr) || subtyp.Is(Slice) {
p.Print(" nil,")
} else if subtyp.Is(cc.Array) {
p.Print(" ", subtyp, "{},")
} else {
p.Print(" 0,")
}
}
}
if nl {
p.Print(Unindent, Newline)
}
p.Print("}")
}