Fix handling of wrapped types. Use new type system for go
function declarations. Working wrapper for simple test case.
This commit is contained in:
parent
e143dbb6a7
commit
98e19ca726
|
@ -89,13 +89,18 @@ func (t *Type) CGoType() string {
|
|||
}
|
||||
|
||||
func (t *Type) GoType() string {
|
||||
ct := swapstars(t.CType())
|
||||
return _goType(t.CType())
|
||||
}
|
||||
|
||||
func _goType(ct string) string {
|
||||
ct = swapstars(ct)
|
||||
ct = strings.Title(ct)
|
||||
ct = strings.ReplaceAll(ct," ","")
|
||||
ct = strings.ReplaceAll(ct,"Struct","")
|
||||
return ct
|
||||
}
|
||||
|
||||
|
||||
func (t *Type) CType() string {
|
||||
if t.ctype != "" { // cache
|
||||
return t.ctype
|
||||
|
@ -116,22 +121,32 @@ func (t *Type) CType() string {
|
|||
|
||||
func (t *Type) GoTypeDecl() string {
|
||||
if wrapped[t.GoType()] {
|
||||
fmt.Printf("%s -> %s: %s is wrapped\n",t.GoType(),t.CGoType(),t.Class)
|
||||
return t.GoInterfaceDecl()
|
||||
}
|
||||
tp := t.BaseType()
|
||||
return fmt.Sprintf(`
|
||||
type %s %s
|
||||
`,t.GoType(),t.CGoType())
|
||||
`,tp.GoType(),tp.CGoType())
|
||||
}
|
||||
|
||||
func (t *Type) GoInterfaceDecl() string {
|
||||
super := Super(t.Class)
|
||||
return _goInterfaceDecl(t.GoType())
|
||||
}
|
||||
|
||||
func _goInterfaceDecl(c string) string {
|
||||
if c[0] == '*' {
|
||||
c = c[1:] // dereference wrapped types
|
||||
}
|
||||
x := ""
|
||||
super := Super(c)
|
||||
if super == "" {
|
||||
super = "ptr unsafe.Pointer"
|
||||
} else {
|
||||
x = _goInterfaceDecl(super) + "\n"
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
type %s struct { %s }
|
||||
`,t.GoType(), super)
|
||||
%stype %s struct { %s }
|
||||
`,x,c,super)
|
||||
}
|
||||
|
||||
func (t *Type) CToGo(cval string) string { // cast C value to CGo
|
||||
|
|
25
wrap/main.go
25
wrap/main.go
|
@ -238,9 +238,13 @@ var goreserved map[string]bool = map[string]bool{
|
|||
"range": true,
|
||||
}
|
||||
|
||||
func gpntp(m Method) ([]string,[]*types.Type) {
|
||||
func (m *Method) gpntp() ([]string,[]*types.Type,string) {
|
||||
ns := []string{}
|
||||
tps := []*types.Type{}
|
||||
if !m.ClassMethod {
|
||||
ns = append(ns,"o")
|
||||
tps = append(tps,types.NewTypeFromString(m.Class + "*",""))
|
||||
}
|
||||
for _,p := range m.Parameters {
|
||||
gname := p.Vname
|
||||
if goreserved[gname] {
|
||||
|
@ -249,7 +253,13 @@ func gpntp(m Method) ([]string,[]*types.Type) {
|
|||
ns = append(ns,gname)
|
||||
tps = append(tps,p.Tp)
|
||||
}
|
||||
return ns,tps
|
||||
ret := []string{}
|
||||
i := 0
|
||||
if !m.ClassMethod { i = 1 }
|
||||
for ; i < len(ns); i++ {
|
||||
ret = append(ret,ns[i] + " " + tps[i].GoType())
|
||||
}
|
||||
return ns, tps, strings.Join(ret,", ")
|
||||
}
|
||||
|
||||
func (w Wrapper) goparamlist(m Method) (string,[]string,bool) {
|
||||
|
@ -475,14 +485,12 @@ func (w *Wrapper) pt2(tps ...*types.Type) {
|
|||
return
|
||||
}
|
||||
tp := tps[0].BaseType()
|
||||
if w.Processed2[tp.GoType()] {
|
||||
return
|
||||
}
|
||||
if w.Processed2[tp.GoType()] { return }
|
||||
w.Processed2[tp.GoType()] = true
|
||||
if tp.Node.IsFunction() {
|
||||
return
|
||||
}
|
||||
w.goTypes.WriteString(tp.GoTypeDecl())
|
||||
w.goTypes.WriteString(tps[0].GoTypeDecl())
|
||||
}
|
||||
|
||||
func (w *Wrapper) ProcessType(gotype string) {
|
||||
|
@ -593,16 +601,15 @@ New%s() {
|
|||
|
||||
w.AddType(m.Type,i.Name)
|
||||
//cmtype := w.ctMap[w.goType(m.Type,i.Name)].CtypeSimplified()
|
||||
gplist,_,_ := w.goparamlist(m)
|
||||
cmtype := m.Tp.CType()
|
||||
ns,tps := gpntp(m)
|
||||
ns,tps,gplist := m.gpntp()
|
||||
w.pt2(tps...)
|
||||
w.pt2(m.Tp)
|
||||
w.goCode.WriteString(fmt.Sprintf(`
|
||||
func (o *%s) %s(%s) %s {
|
||||
`,i.Name,gname,gplist,m.Tp.GoType()))
|
||||
w.goCode.WriteString(
|
||||
types.GoToC(cname,ns,m.Tp,tps) + "}\n")
|
||||
types.GoToC(cname,ns,m.Tp,tps) + "}\n\n")
|
||||
|
||||
cret := ""
|
||||
if !m.isVoid() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user