本文整理汇总了Golang中github.com/cznic/cc.Type类的典型用法代码示例。如果您正苦于以下问题:Golang Type类的具体用法?Golang Type怎么用?Golang Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Type类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: arrayType
func (j *Job) arrayType(n cc.Node, t cc.Type) {
if ne := t.Elements(); ne >= 0 {
j.body("[%v]", ne)
j.typ(n, t.Element())
return
}
todo(n, t)
}
示例2: addTag
func (j *Job) addTag(t cc.Type) {
for t.Kind() == cc.Ptr || t.Kind() == cc.Array {
t = t.Element()
}
tag := t.Tag()
if tag == 0 {
return
}
n := j.In.Declarations.Tags[tag].Node
d := t.Declarator()
if j.ImportPath(n) == 0 && j.tags[tag] == nil {
j.tags[tag] = d
}
}
示例3: cast
func (j *Job) cast(ot cc.Type, n *cc.Expression) {
j.imports[idUnsafe] = struct{}{}
if ot.Kind() == cc.Ptr && n.Type.Kind() == cc.Ptr && n.Type.Element().Kind() != cc.Function {
j.body("(")
j.typ(n, ot)
j.body(")(unsafe.Pointer(")
j.expression(nil, n)
j.body("))")
return
}
j.body("(*(*")
j.typ(n, ot)
j.body(")(unsafe.Pointer(&struct{f ")
j.typ(n, n.Type)
j.body("}{")
j.expression(nil, n)
j.body("})))")
}
示例4: union
func (j *Job) union(n cc.Node, t cc.Type) {
j.body("\n_ [0]struct{")
m, _ := t.Members()
for _, v := range m {
j.body("\n%s", xc.Dict.S(v.Name))
j.typ(n, v.Type)
if t := v.Type; t.Kind() != cc.Union && t.Kind() != cc.Struct {
j.body(" // %s", v.Type)
}
}
j.body("\n}")
j.body("\nUnion [%v]byte", t.SizeOf())
}
示例5: inc
func (j *Job) inc(ot cc.Type, n *cc.Expression, op string, post bool) {
if ot != nil && ot.Kind() == cc.Void {
todo(n, ot, n.Type)
return
}
t := ot
if t == nil {
t = n.Type
}
j.body(" func() ")
j.typ(n, t)
j.body(" { p := &(")
j.expression(nil, n.Expression)
switch {
case post:
j.body("); r := *p; (*p)++; return r }()")
default:
j.body("); (*p)++; return *p }()")
}
}
示例6: initializerList
func (j *Job) initializerList(st cc.Type, n *cc.InitializerList) {
j.typ(n, st)
j.body("{\n")
defer j.body("\n}")
if st.Kind() == cc.Union {
return
}
if st.Kind() == cc.Array {
t := st.Element()
for ; n != nil; n = n.InitializerList {
if n.DesignationOpt != nil {
todo(n)
}
j.initializer(t, n.Initializer)
j.body(",")
j.body("\n")
}
return
}
var m []cc.Member
if st != nil {
m, _ = st.Members()
}
i := 0
for ; n != nil; n = n.InitializerList {
if n.DesignationOpt != nil {
todo(n)
}
var t cc.Type
if i < len(m) {
t = m[i].Type
}
j.initializer(t, n.Initializer)
j.body(",")
j.body("\n")
i++
}
}
示例7: eqTypes
func eqTypes(n cc.Node, a, b cc.Type) bool {
if a.Kind() == cc.Ptr {
if t := a.Element(); t.Kind() == cc.Function {
a = t
}
}
if b.Kind() == cc.Ptr {
if t := b.Element(); t.Kind() == cc.Function {
b = t
}
}
return removeQualifiers(a.String()) == removeQualifiers(b.String())
}
示例8: expression
func (j *Job) expression(ot cc.Type, n *cc.Expression) {
if ot != nil {
switch {
case n.Case == 25 /* '(' TypeName')' Expression */ && !eqTypes(n.Expression, ot, n.Expression.Type):
j.convert(ot, n.Expression)
return
case !eqTypes(n, ot, n.Type):
j.convert(ot, n)
return
}
}
if n.Value != nil {
j.constExpr(ot, n)
return
}
switch n.Case {
case 0: // IDENTIFIER
id := n.Token.Val
bn := n.IdentResolutionScope().Lookup(cc.NSIdentifiers, id).Node
if j.ImportPath(bn) != 0 && id == idErrno {
j.body(" 0/*TODO747*/")
break
}
j.qualifier(bn)
j.body(" %s", xc.Dict.S(mangleIdent(id, bn.(*cc.DirectDeclarator).TopDeclarator().Linkage == cc.External)))
case 1: // CHARCONST // Case 1
todo(n)
case 2: // FLOATCONST // Case 2
todo(n)
case 3: // INTCONST // Case 3
todo(n)
case 4: // LONGCHARCONST // Case 4
todo(n)
case 5: // LONGSTRINGLITERAL // Case 5
todo(n)
case 6: // STRINGLITERAL // Case 6
todo(n)
case 7: // '(' ExpressionList ')' // Case 7
j.expressionList(n.Type, n.ExpressionList)
case 8: // Expression '[' ExpressionList ']' // Case 8
switch n.Expression.Type.Kind() {
case cc.Array:
j.expression(nil, n.Expression)
j.body("[")
j.expressionList(nil, n.ExpressionList)
j.body("]")
case cc.Ptr:
j.imports[idUnsafe] = struct{}{}
j.body("(*(")
j.typ(nil, n.Expression.Type)
j.body(")(unsafe.Pointer(uintptr(unsafe.Pointer(")
j.expression(nil, n.Expression)
j.body(")) + uintptr(")
j.expressionList(nil, n.ExpressionList)
j.body("))))")
default:
todo(n, n.Expression.Type, n.Expression.Type.Kind(), ot, n.Type)
}
case 9: // Expression '(' ArgumentExpressionListOpt ')' // Case 9
e := n.Expression
if e.Case == 0 /* IDENTIFIER */ && e.Token.Val == idGO { // __GO__() magic.
for n := n.ArgumentExpressionListOpt.ArgumentExpressionList; n != nil; n = n.ArgumentExpressionList {
switch n := n.Expression; n.Case {
case 6: // STRINGLITERAL
j.body("%s", xc.Dict.S(int(n.Value.(cc.StringLitID))))
default:
panic("internal error")
}
}
break
}
j.expression(n.Expression.Type, n.Expression)
j.body("(")
if o := n.ArgumentExpressionListOpt; o != nil {
ps, _ := n.Expression.Type.Parameters()
i := 0
for n := o.ArgumentExpressionList; n != nil; n = n.ArgumentExpressionList {
j.expression(ps[i].Type, n.Expression)
j.body(", ")
i++
}
}
j.body(")")
case 10: // Expression '.' IDENTIFIER // Case 10
fallthrough
case 11: // Expression "->" IDENTIFIER // Case 11
j.selector(ot, n)
case 12: // Expression "++" // Case 12
j.inc(ot, n, "++", true)
case 13: // Expression "--" // Case 13
todo(n)
case 14: // '(' TypeName ')' '{' InitializerList CommaOpt '}' // Case 14
todo(n)
case 15: // "++" Expression // Case 15
j.inc(ot, n, "++", false)
case 16: // "--" Expression // Case 16
//.........这里部分代码省略.........
示例9: convert
func (j *Job) convert(ot cc.Type, n *cc.Expression) {
t := n.Type
switch otk := ot.Kind(); otk {
case cc.Ptr:
switch t.Kind() {
case cc.Int:
if v := n.Value; v != nil && isZero(n, v) {
j.body(" nil")
return
}
todo(n, ot, t)
}
if ot.Element().Kind() == cc.Void {
switch t.Kind() {
case cc.Ptr:
j.imports[idUnsafe] = struct{}{}
j.body(" unsafe.Pointer(uintptr(0)/*TODO536*/)")
break
//TODO j.body(" unsafe.Pointer/*DBG536 %v %s */(", n.Case, n.Type)
//TODO j.expression(nil, n)
//TODO j.body("/*DBG538*/)")
case cc.Array:
switch {
case t.Elements() > 0:
j.imports[idUnsafe] = struct{}{}
j.body(" unsafe.Pointer(&")
j.expression(nil, n)
j.body("[0])")
default:
todo(n, ot, t)
}
default:
todo(n, ot, t)
}
break
}
switch t.Kind() {
case cc.Ptr:
switch t.Element().Kind() {
case cc.Void:
j.body("(")
j.typ(n, ot)
j.body(")(")
j.expression(nil, n)
j.body(")")
default:
j.cast(ot, n)
}
return
case cc.Array:
switch {
case t.Elements() > 0:
j.body(" &")
j.expression(nil, n)
j.body("[0]")
default:
todo(n, ot, t)
}
return
}
switch l := ot.Element(); l.Kind() {
case cc.Function:
switch t.Kind() {
case cc.Function:
j.cast(ot, n)
default:
todo(n, l, t)
}
case cc.Char:
switch t.Kind() {
case cc.Ptr:
switch r := t.Element(); r.Kind() {
case cc.Char:
j.expression(nil, n)
default:
todo(n, l, r)
}
default:
todo(n, l, t)
}
default:
todo(n, ot, t)
}
case cc.Char, cc.Int, cc.LongLong, cc.SChar, cc.Short, cc.UChar, cc.UInt,
cc.ULong, cc.ULongLong, cc.UShort:
j.body(" %s(", j.Model.Items[otk].More)
j.expression(nil, n)
j.body(")")
case cc.Void:
if isLiteral(n) {
break
}
j.expression(nil, n)
default:
todo(n, ot, t)
//.........这里部分代码省略.........
示例10: signature
func (j *Job) signature(n cc.Node, t cc.Type) {
ps, variadic := t.Parameters()
j.body("(")
names := false
var groups [][]cc.Parameter
var group []cc.Parameter
var prevT cc.Type
for i, p := range ps {
if p.Name != 0 {
names = true
}
if i == 0 {
group = []cc.Parameter{p}
prevT = p.Type
continue
}
if !eqTypes(n, prevT, p.Type) {
groups = append(groups, group)
group = []cc.Parameter{p}
prevT = p.Type
continue
}
group = append(group, p)
}
if group != nil {
groups = append(groups, group)
}
for _, g := range groups {
switch {
case names:
for i, p := range g {
j.body("%s", xc.Dict.S(mangleIdent(p.Name, false)))
if i < len(g)-1 {
j.body(", ")
}
}
t := g[0].Type
if t.Kind() == cc.Array {
j.body("*")
}
j.typ(g[0].Declarator, t)
j.body(", ")
default:
t := g[0].Type
for range g {
if t.Kind() == cc.Array {
j.body("*")
}
j.typ(g[0].Declarator, t)
j.body(", ")
}
}
}
if variadic {
if names {
j.body("args")
}
j.body("...interface{}")
}
j.body(")")
if t := t.Result(); t.Kind() != cc.Void {
if t.Kind() == cc.Array {
j.body("*")
}
j.typ(n, t)
}
}
示例11: typ
func (j *Job) typ(n cc.Node, t cc.Type) {
if t.Declarator().RawSpecifier().TypedefName() == idVaList {
j.body("[]interface{}")
return
}
stars := 0
for t.Kind() == cc.Ptr {
stars++
t = t.Element()
}
stars0 := stars
if (t.Kind() == cc.Void || t.Kind() == cc.Function) && stars > 0 {
stars--
}
j.body("%s", strings.Repeat("*", stars))
switch k := t.Kind(); k {
case cc.Char, cc.Double, cc.Int, cc.Long, cc.LongDouble, cc.LongLong, cc.SChar,
cc.Short, cc.UChar, cc.ULong, cc.ULongLong, cc.UInt, cc.UShort:
j.body(" %s", j.Model.Items[k].More)
case cc.Void:
if stars0 == 0 {
todo(n)
}
j.body(" unsafe.Pointer")
j.imports[idUnsafe] = struct{}{}
case cc.Struct, cc.Union:
// Use tag if available.
if tag := t.Tag(); tag != 0 {
nm := mangleTag(tag, true)
j.qualifier(j.In.Declarations.Tags[tag].Node)
j.body(" %s", xc.Dict.S(nm))
break
}
// Use typedef name if available.
if tdn := t.Declarator().RawSpecifier().TypedefName(); tdn != 0 {
nm := mangleIdent(tdn, true)
j.qualifier(j.In.Declarations.Identifiers[tdn].Node)
j.body(" %s", xc.Dict.S(nm))
break
}
j.body(" struct {")
switch m, incomplete := t.Members(); {
case incomplete:
j.body("// Incomplete type\n_ byte")
case t.Kind() == cc.Union:
j.union(n, t)
var f func(cc.Type)
f = func(t cc.Type) {
j.addTag(t)
m, _ := t.Members()
for _, v := range m {
f(v.Type)
}
}
default:
for _, v := range m {
if v.Bits != 0 {
j.bits(n, v)
continue
}
j.addTag(v.Type)
id := v.Name
nm := mangleIdent(id, true)
j.body("\n%s", xc.Dict.S(nm))
j.typ(v.Declarator, v.Type)
if t := v.Type; t.Kind() != cc.Union && t.Kind() != cc.Struct {
j.body("// %s", v.Type)
}
}
}
j.body("\n}")
case cc.Function:
j.body(" func")
j.signature(n, t)
case cc.Array:
j.arrayType(n, t)
default:
todo(n, t, t.Kind())
}
}
示例12: addTag2
func (j *Job) addTag2(t cc.Type) {
for t.Kind() == cc.Ptr || t.Kind() == cc.Array {
t = t.Element()
}
tag := t.Tag()
var n cc.Node
if tag != 0 {
n = j.In.Declarations.Tags[tag].Node
}
d := t.Declarator()
if (n != nil && j.ImportPath(n) != 0) || j.tags[tag] != nil {
return
}
if tag != 0 {
j.tags[tag] = d
}
m, _ := t.Members()
for _, v := range m {
j.addTag2(v.Type)
}
}