Bug fix and start improvements to subclassing.
This commit is contained in:
parent
a616761475
commit
38c7856b89
|
@ -216,8 +216,8 @@ func Start() (err error) {
|
||||||
case *ast.ObjCInterfaceDecl:
|
case *ast.ObjCInterfaceDecl:
|
||||||
w.AddInterface(x)
|
w.AddInterface(x)
|
||||||
for _,ss := range Config.Subclasses {
|
for _,ss := range Config.Subclasses {
|
||||||
for ps,_ := range ss {
|
if sc,ok := ss["superclass"]; ok {
|
||||||
if matches(x.Name,[]string{ps}) {
|
if matches(x.Name,sc) {
|
||||||
Config.Classes = append(Config.Classes,x.Name)
|
Config.Classes = append(Config.Classes,x.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,11 @@ import (
|
||||||
ns "gitlab.wow.st/gmp/nswrap/examples/simple/ClassOne"
|
ns "gitlab.wow.st/gmp/nswrap/examples/simple/ClassOne"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func cb(super ns.ClassThreeSupermethods) ns.Int {
|
||||||
|
fmt.Printf("In Go callback\n")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
o := ns.ClassOneAlloc().Init()
|
o := ns.ClassOneAlloc().Init()
|
||||||
fmt.Println("i1 = ",o.Geti1())
|
fmt.Println("i1 = ",o.Geti1())
|
||||||
|
@ -20,7 +25,10 @@ func main() {
|
||||||
fmt.Println(o.Hi2(np))
|
fmt.Println(o.Hi2(np))
|
||||||
o2 := ns.ClassTwoAlloc().Init()
|
o2 := ns.ClassTwoAlloc().Init()
|
||||||
fmt.Println(o2.Hi1(ns1))
|
fmt.Println(o2.Hi1(ns1))
|
||||||
o3 := ns.ClassThreeAlloc().Init()
|
o3 := ns.ClassThreeAlloc()
|
||||||
|
o3.Init()
|
||||||
|
o3.Geti1Callback(cb)
|
||||||
fmt.Println(o3.Hi2(np))
|
fmt.Println(o3.Hi2(np))
|
||||||
|
fmt.Println(o3.Geti1())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ classes:
|
||||||
subclasses:
|
subclasses:
|
||||||
ClassThree:
|
ClassThree:
|
||||||
ClassTwo:
|
ClassTwo:
|
||||||
- .*
|
- geti1
|
||||||
|
- (void)myMethod:int
|
||||||
|
|
||||||
imports: [ simple.h ]
|
imports: [ simple.h ]
|
||||||
frameworks: [ Foundation ]
|
frameworks: [ Foundation ]
|
||||||
|
|
|
@ -24,6 +24,7 @@ func IsGoInterface(gt string) bool {
|
||||||
return goInterfaces[gt]
|
return goInterfaces[gt]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TypeParameters maps, for each class, a TypedefName to a type, representing
|
//TypeParameters maps, for each class, a TypedefName to a type, representing
|
||||||
//the Objective-C type parameters for that class
|
//the Objective-C type parameters for that class
|
||||||
var TypeParameters map[string]map[string]string
|
var TypeParameters map[string]map[string]string
|
||||||
|
@ -194,6 +195,9 @@ func _goType(ct string) string {
|
||||||
if ct == "Id" {
|
if ct == "Id" {
|
||||||
ct = "Id"
|
ct = "Id"
|
||||||
}
|
}
|
||||||
|
if len(ct) > 1 && ShouldWrap(ct[1:]) {
|
||||||
|
return ct[1:]
|
||||||
|
}
|
||||||
if len(ct) > 4 && ct[len(ct)-4:len(ct)] == "Void" {
|
if len(ct) > 4 && ct[len(ct)-4:len(ct)] == "Void" {
|
||||||
ct = ct[:len(ct)-5] + "unsafe.Pointer"
|
ct = ct[:len(ct)-5] + "unsafe.Pointer"
|
||||||
}
|
}
|
||||||
|
|
25
wrap/main.go
25
wrap/main.go
|
@ -981,14 +981,30 @@ func (w *Wrapper) _ProcessDelSub(dname string, ps map[string][]string,sub bool)
|
||||||
i++
|
i++
|
||||||
var ms map[string]*Method
|
var ms map[string]*Method
|
||||||
if sub {
|
if sub {
|
||||||
|
if i > 1 {
|
||||||
|
fmt.Printf("Multiple inheritance is not permitted:\n subclass %s already inherits from %s\n",dname,supr)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
interf := w.Interfaces[pname]
|
interf := w.Interfaces[pname]
|
||||||
if interf == nil {
|
if interf == nil {
|
||||||
fmt.Printf("Failed to find interface %s for subclass %s\n",pname,dname)
|
fmt.Printf("Failed to find interface %s for subclass %s\n",pname,dname)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
//fmt.Printf(" subclass for %s\n",pname)
|
|
||||||
ms = interf.InstanceMethods
|
|
||||||
supr = interf.GoName
|
supr = interf.GoName
|
||||||
|
//fmt.Printf(" subclass for %s\n",pname)
|
||||||
|
ms = map[string]*Method{}
|
||||||
|
var addmeths func(s string)
|
||||||
|
addmeths = func(s string) {
|
||||||
|
if sup := types.Super(s); w.Interfaces[sup] != nil {
|
||||||
|
addmeths(sup)
|
||||||
|
}
|
||||||
|
fmt.Printf("Adding methods for %s\n",s)
|
||||||
|
for k,v := range w.Interfaces[s].InstanceMethods {
|
||||||
|
ms[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//for subclasses, add all superclass methods, depth first
|
||||||
|
addmeths(interf.Name)
|
||||||
} else {
|
} else {
|
||||||
proto := w.Protocols[pname]
|
proto := w.Protocols[pname]
|
||||||
if proto == nil {
|
if proto == nil {
|
||||||
|
@ -1003,6 +1019,9 @@ func (w *Wrapper) _ProcessDelSub(dname string, ps map[string][]string,sub bool)
|
||||||
//note:we may have capitalized the first character to make a goname,
|
//note:we may have capitalized the first character to make a goname,
|
||||||
//but m.Name is not disambiguated for polymorphics...
|
//but m.Name is not disambiguated for polymorphics...
|
||||||
if !matches(string(m.Name[0])+gname[1:],pats) {
|
if !matches(string(m.Name[0])+gname[1:],pats) {
|
||||||
|
if sub {
|
||||||
|
//Add newly defined methods that don't match anything...
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if m.Type.IsFunction() || m.Type.IsFunctionPtr() || m.hasFunctionParam() {
|
if m.Type.IsFunction() || m.Type.IsFunctionPtr() || m.hasFunctionParam() {
|
||||||
|
@ -1486,7 +1505,7 @@ import (
|
||||||
of.WriteString(w.goCode.String())
|
of.WriteString(w.goCode.String())
|
||||||
of.Close()
|
of.Close()
|
||||||
|
|
||||||
if len(w.Delegates) > 0 {
|
if len(w.Delegates) > 0 || len(w.Subclasses) > 0 {
|
||||||
ef.WriteString("package " + w.Package + "\n\n")
|
ef.WriteString("package " + w.Package + "\n\n")
|
||||||
ef.WriteString(w.cgoFlags.String() + "\n")
|
ef.WriteString(w.cgoFlags.String() + "\n")
|
||||||
ef.WriteString(w.cImports.String() + "\n")
|
ef.WriteString(w.cImports.String() + "\n")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user