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 } }
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) } }
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()) } }