Fix types in c and go parameter lists.
This commit is contained in:
parent
9e3c7c2ce8
commit
3ecb3b1eeb
42
wrap/main.go
42
wrap/main.go
|
@ -34,8 +34,8 @@ var builtinTypes map[string]string = map[string]string{
|
||||||
"unsigned long": "int",
|
"unsigned long": "int",
|
||||||
"long long": "int",
|
"long long": "int",
|
||||||
"unsigned long long": "int",
|
"unsigned long long": "int",
|
||||||
"float": "float",
|
"float": "float64",
|
||||||
"double": "float",
|
"double": "float64",
|
||||||
"complex float": "C.complexfloat",
|
"complex float": "C.complexfloat",
|
||||||
"complex double": "C.complexdouble",
|
"complex double": "C.complexdouble",
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ var builtinTypes map[string]string = map[string]string{
|
||||||
var gobuiltinTypes map[string]bool = map[string]bool{
|
var gobuiltinTypes map[string]bool = map[string]bool{
|
||||||
"byte": true,
|
"byte": true,
|
||||||
"int": true,
|
"int": true,
|
||||||
"float": true,
|
"float64": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -82,6 +82,7 @@ func goType(t,class string) (string, error) {
|
||||||
if len(nt) > 3 && nt[0:3] == "id<" {
|
if len(nt) > 3 && nt[0:3] == "id<" {
|
||||||
nt = t[3:len(t)-1]
|
nt = t[3:len(t)-1]
|
||||||
}
|
}
|
||||||
|
nt = strings.ReplaceAll(nt,"const ","")
|
||||||
nt = strings.ReplaceAll(nt," _Nullable","")
|
nt = strings.ReplaceAll(nt," _Nullable","")
|
||||||
nt = strings.ReplaceAll(nt," _Nonnull","")
|
nt = strings.ReplaceAll(nt," _Nonnull","")
|
||||||
if t == "instancetype" {
|
if t == "instancetype" {
|
||||||
|
@ -141,18 +142,22 @@ func (m Method) isVoid() bool {
|
||||||
return typeOrType2(m.Type,m.Type2) == "void"
|
return typeOrType2(m.Type,m.Type2) == "void"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w Wrapper) isObject(m Method) bool { // FIXME NEEDED?
|
func (w Wrapper) isObject(tp string) bool { // takes a goType
|
||||||
tp,_ := goType(typeOrType2(m.Type,m.Type2),m.Class)
|
|
||||||
if _,ok := w.Interfaces[tp]; ok {
|
if _,ok := w.Interfaces[tp]; ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Method) cparamlist() string {
|
func (w Wrapper) cparamlist(m Method) string {
|
||||||
ret := []string{"void* obj"}
|
ret := []string{"void* obj"}
|
||||||
for _,p := range m.Parameters {
|
for _,p := range m.Parameters {
|
||||||
ret = append(ret,fmt.Sprintf("%s %s",typeOrType2(p.Type,p.Type2),p.Vname))
|
tp := typeOrType2(p.Type,p.Type2)
|
||||||
|
gtp,_ := goType(tp,m.Class)
|
||||||
|
if w.isObject(gtp) {
|
||||||
|
tp = "void*"
|
||||||
|
}
|
||||||
|
ret = append(ret,fmt.Sprintf("%s %s",tp,p.Vname))
|
||||||
}
|
}
|
||||||
return strings.Join(ret,", ")
|
return strings.Join(ret,", ")
|
||||||
}
|
}
|
||||||
|
@ -178,7 +183,7 @@ var goreserved map[string]bool = map[string]bool{
|
||||||
"range": true,
|
"range": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Method) goparamlist() (string,[]string,bool) {
|
func (w Wrapper) goparamlist(m Method) (string,[]string,bool) {
|
||||||
ret := []string{}
|
ret := []string{}
|
||||||
tps := []string{}
|
tps := []string{}
|
||||||
for _,p := range m.Parameters {
|
for _,p := range m.Parameters {
|
||||||
|
@ -187,6 +192,9 @@ func (m Method) goparamlist() (string,[]string,bool) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "UNSUPPORTED TYPE", []string{},false
|
return "UNSUPPORTED TYPE", []string{},false
|
||||||
}
|
}
|
||||||
|
if w.isObject(tp) {
|
||||||
|
tp = "*" + tp
|
||||||
|
}
|
||||||
if goreserved[gname] {
|
if goreserved[gname] {
|
||||||
gname = gname + "_"
|
gname = gname + "_"
|
||||||
}
|
}
|
||||||
|
@ -196,13 +204,17 @@ func (m Method) goparamlist() (string,[]string,bool) {
|
||||||
return strings.Join(ret,", "),tps,true
|
return strings.Join(ret,", "),tps,true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Method) goparamnames() string {
|
func (w Wrapper) goparamnames(m Method) string {
|
||||||
ret := []string{"o.ptr"}
|
ret := []string{"o.ptr"}
|
||||||
for _,p := range m.Parameters {
|
for _,p := range m.Parameters {
|
||||||
gname := p.Vname
|
gname := p.Vname
|
||||||
if goreserved[gname] {
|
if goreserved[gname] {
|
||||||
gname = gname + "_"
|
gname = gname + "_"
|
||||||
}
|
}
|
||||||
|
gt,_ := goType(typeOrType2(p.Type,p.Type2),m.Class)
|
||||||
|
if w.isObject(gt) {
|
||||||
|
gname = gname + ".ptr"
|
||||||
|
}
|
||||||
ret = append(ret,gname)
|
ret = append(ret,gname)
|
||||||
}
|
}
|
||||||
return strings.Join(ret, ", ")
|
return strings.Join(ret, ", ")
|
||||||
|
@ -357,6 +369,9 @@ func (w *Wrapper) ProcessType(gotype string) {
|
||||||
if gotype == "" {
|
if gotype == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if gotype[0] == '*' {
|
||||||
|
gotype = gotype[1:]
|
||||||
|
}
|
||||||
if _,ok := gobuiltinTypes[gotype]; ok {
|
if _,ok := gobuiltinTypes[gotype]; ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -466,8 +481,11 @@ New%s() {
|
||||||
gcast2 = ")"
|
gcast2 = ")"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if grtype == "id" { // can't return id
|
||||||
|
continue
|
||||||
|
}
|
||||||
w.ProcessType(grtype)
|
w.ProcessType(grtype)
|
||||||
gplist, gptypes,ok := y.goparamlist()
|
gplist, gptypes, ok := w.goparamlist(y)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -475,7 +493,7 @@ New%s() {
|
||||||
w.goCode.WriteString(fmt.Sprintf(`
|
w.goCode.WriteString(fmt.Sprintf(`
|
||||||
func (o *%s) %s(%s) %s%s {
|
func (o *%s) %s(%s) %s%s {
|
||||||
%sC.%s_%s(%s)%s
|
%sC.%s_%s(%s)%s
|
||||||
}`,v.Name, gname, gplist, grptr, grtype, gcast, v.Name, y.Name, y.goparamnames(),gcast2))
|
}`,v.Name, gname, gplist, grptr, grtype, gcast, v.Name, y.Name, w.goparamnames(y),gcast2))
|
||||||
|
|
||||||
cret := ""
|
cret := ""
|
||||||
if !y.isVoid() {
|
if !y.isVoid() {
|
||||||
|
@ -485,7 +503,7 @@ func (o *%s) %s(%s) %s%s {
|
||||||
%s
|
%s
|
||||||
%s_%s(%s) {
|
%s_%s(%s) {
|
||||||
%s[(id)obj %s];
|
%s[(id)obj %s];
|
||||||
}`, cmtype, v.Name, y.Name, y.cparamlist(), cret, y.objcparamlist()))
|
}`, cmtype, v.Name, y.Name, w.cparamlist(y), cret, y.objcparamlist()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(`package main
|
fmt.Println(`package main
|
||||||
|
|
Loading…
Reference in New Issue
Block a user