Clean up variadic functions and methods.
This commit is contained in:
parent
1cc0f0e26a
commit
840a055a11
|
@ -78,18 +78,26 @@ func main() {
|
||||||
})
|
})
|
||||||
|
|
||||||
nst := ns.NSStringWithGoString
|
nst := ns.NSStringWithGoString
|
||||||
fmt.Printf("\nGetObjectsAndKeysCount()\n")
|
fmt.Printf("\nNSDictionaryWithObjectsForKeys()\n")
|
||||||
d := ns.NSDictionaryWithObjectsForKeys(
|
d := ns.NSDictionaryWithObjectsForKeys(
|
||||||
ns.NSArrayWithObjects(nst("obj1"),nst("obj2")),
|
ns.NSArrayWithObjects(nst("obj1"),nst("obj2")),
|
||||||
ns.NSArrayWithObjects(nst("key1"),nst("key2")),
|
ns.NSArrayWithObjects(nst("key1"),nst("key2")),
|
||||||
)
|
)
|
||||||
os := make([]ns.Id,4)
|
os := make([]ns.Id,4)
|
||||||
|
fmt.Printf("Length of os is %d\n",len(os))
|
||||||
ks := make([]ns.Id,4)
|
ks := make([]ns.Id,4)
|
||||||
|
fmt.Printf("\nGetObjects()\n")
|
||||||
d.GetObjects(&os,&ks,4)
|
d.GetObjects(&os,&ks,4)
|
||||||
for _,o := range os {
|
fmt.Printf("Length of os is now %d\n",len(os))
|
||||||
fmt.Printf("--%s\n",o.NSString())
|
for i,k := range ks {
|
||||||
}
|
fmt.Printf("--%s -> %s\n",k.NSString(),os[i].NSString())
|
||||||
for _,o := range ks {
|
|
||||||
fmt.Printf("--%s\n",o.NSString())
|
|
||||||
}
|
}
|
||||||
|
fmt.Printf("\nNSStringWithContentsOfURLEncoding()\n")
|
||||||
|
err := make([]ns.NSError,1)
|
||||||
|
n1 = ns.NSStringWithContentsOfURLEncoding(ns.NSURLWithGoString("htttypo://example.com"),0,&err)
|
||||||
|
fmt.Printf("err: %s\n",err[0].LocalizedDescription())
|
||||||
|
|
||||||
|
fmt.Printf("\nNSStringWithFormat()\n")
|
||||||
|
str := ns.NSStringWithFormat(nst("(%@) (%@)\n(%@)\n"),n2,n3,s1)
|
||||||
|
fmt.Printf("%s\n",str)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ classes:
|
||||||
- NSLocale
|
- NSLocale
|
||||||
- NSCharacterSet
|
- NSCharacterSet
|
||||||
- NSString
|
- NSString
|
||||||
|
- NSURL
|
||||||
|
- NSError
|
||||||
- NSScanner
|
- NSScanner
|
||||||
- NSFileManager
|
- NSFileManager
|
||||||
- NSObject
|
- NSObject
|
||||||
|
|
|
@ -305,6 +305,16 @@ func (t *Type) IsFunction() bool {
|
||||||
return t.Node.IsFunction()
|
return t.Node.IsFunction()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Type) IsValist() bool {
|
||||||
|
if t == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if t.GoType() == "__va_list_tag" { // OS dependent
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Type) ReturnType() *Type {
|
func (t *Type) ReturnType() *Type {
|
||||||
if rt := t.Node.ReturnType(); rt != nil {
|
if rt := t.Node.ReturnType(); rt != nil {
|
||||||
return NewType(rt,t.Class)
|
return NewType(rt,t.Class)
|
||||||
|
|
41
wrap/main.go
41
wrap/main.go
|
@ -161,6 +161,12 @@ func (m *Method) LongName() string {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Method) HasUnsupportedType() bool {
|
||||||
|
return m.Type.IsFunction() ||
|
||||||
|
m.Type.IsFunctionPtr() ||
|
||||||
|
m.hasUnsupportedParam()
|
||||||
|
}
|
||||||
|
|
||||||
type Enum struct {
|
type Enum struct {
|
||||||
Name string
|
Name string
|
||||||
Type *types.Type
|
Type *types.Type
|
||||||
|
@ -190,7 +196,7 @@ func (a ByParams) Len() int { return len(a) }
|
||||||
func (a ByParams) Swap(i,j int) { a[i], a[j] = a[j], a[i] }
|
func (a ByParams) Swap(i,j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a ByParams) Less(i, j int) bool { return len(a[i].Parameters) < len(a[j].Parameters) }
|
func (a ByParams) Less(i, j int) bool { return len(a[i].Parameters) < len(a[j].Parameters) }
|
||||||
|
|
||||||
//Disambiguate polyorphic method names
|
//Disambiguate overloaded method names
|
||||||
func Disambiguate(mc *MethodCollection) {
|
func Disambiguate(mc *MethodCollection) {
|
||||||
lst := map[string][]*Method{}
|
lst := map[string][]*Method{}
|
||||||
for _,m := range mc.Methods {
|
for _,m := range mc.Methods {
|
||||||
|
@ -229,12 +235,15 @@ func (m Method) isVoid() bool {
|
||||||
return m.Type.CType() == "void"
|
return m.Type.CType() == "void"
|
||||||
}
|
}
|
||||||
|
|
||||||
//hasFunctionParam() returns true if a method has a function as a parameter.
|
//hasUnsupportedParam() returns true if a method has a function as a parameter.
|
||||||
func (m Method) hasFunctionParam() bool {
|
func (m Method) hasUnsupportedParam() bool {
|
||||||
for _,p := range m.Parameters {
|
for _,p := range m.Parameters {
|
||||||
if p.Type.IsFunction() || p.Type.IsFunctionPtr() {
|
if p.Type.IsFunction() || p.Type.IsFunctionPtr() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if pt := p.Type.PointsTo(); pt.IsValist() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -273,7 +282,7 @@ func (w Wrapper) objcparamlist(m *Method) string {
|
||||||
first = false
|
first = false
|
||||||
} else {
|
} else {
|
||||||
if p.Type.Variadic {
|
if p.Type.Variadic {
|
||||||
str := []string{p.Pname + ":arr[0]"}
|
str := []string{p.Pname + ", arr[0]"}
|
||||||
for i := 1; i < w.Vaargs; i++ {
|
for i := 1; i < w.Vaargs; i++ {
|
||||||
str = append(str,"arr["+strconv.Itoa(i)+"]")
|
str = append(str,"arr["+strconv.Itoa(i)+"]")
|
||||||
}
|
}
|
||||||
|
@ -391,12 +400,20 @@ func (w *Wrapper) AddFunction(n *ast.FunctionDecl) {
|
||||||
m.Parameters = append(m.Parameters,p)
|
m.Parameters = append(m.Parameters,p)
|
||||||
i++
|
i++
|
||||||
//fmt.Printf(" %s\n",p.Type.CType())
|
//fmt.Printf(" %s\n",p.Type.CType())
|
||||||
|
case *ast.Variadic:
|
||||||
|
p := &Parameter{
|
||||||
|
Vname: "object",
|
||||||
|
Type: types.NewTypeFromString("NSObject*",""),
|
||||||
|
}
|
||||||
|
p.Type.Variadic = true
|
||||||
|
m.Parameters = append(m.Parameters,p)
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i > 0 && len(f.Children) > i {
|
if i > 0 && len(f.Children) > i {
|
||||||
if e := f.Children[i]; len(e.Children) > 0 {
|
if e := f.Children[i]; len(e.Children) > 0 {
|
||||||
//fmt.Println(" Next parameter: ",e.Children[0].String())
|
//fmt.Println(" Next parameter: ",e.Children[0].String())
|
||||||
m.Parameters[i-1].Type.Variadic = true
|
//m.Parameters[i-1].Type.Variadic = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.Functions[n.Name] = m
|
w.Functions[n.Name] = m
|
||||||
|
@ -670,7 +687,14 @@ func (w *Wrapper) GetParms(n ast.Node,class string) ([]*Parameter,bool) {
|
||||||
ret = append(ret,p)
|
ret = append(ret,p)
|
||||||
j++
|
j++
|
||||||
case *ast.Variadic:
|
case *ast.Variadic:
|
||||||
ret[j-1].Type.Variadic = true
|
//ret[j-1].Type.Variadic = true
|
||||||
|
p := &Parameter{
|
||||||
|
Vname: "object",
|
||||||
|
Type: types.NewTypeFromString("NSObject*",""),
|
||||||
|
}
|
||||||
|
p.Type.Variadic = true
|
||||||
|
ret = append(ret,p)
|
||||||
|
j++
|
||||||
case *ast.AvailabilityAttr, *ast.UnavailableAttr, *ast.DeprecatedAttr:
|
case *ast.AvailabilityAttr, *ast.UnavailableAttr, *ast.DeprecatedAttr:
|
||||||
avail.Add(x)
|
avail.Add(x)
|
||||||
case *ast.Unknown:
|
case *ast.Unknown:
|
||||||
|
@ -847,7 +871,7 @@ func (w *Wrapper) _processMethod(m *Method,fun bool) {
|
||||||
if Debug {
|
if Debug {
|
||||||
fmt.Printf(" method: %s (%s)\n", m.Name, m.Type)
|
fmt.Printf(" method: %s (%s)\n", m.Name, m.Type)
|
||||||
}
|
}
|
||||||
if m.Type.IsFunction() || m.Type.IsFunctionPtr() || m.hasFunctionParam() {
|
if m.HasUnsupportedType() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.processType(m.Type)
|
w.processType(m.Type)
|
||||||
|
@ -1098,7 +1122,6 @@ func (w *Wrapper) MethodFromSig(sig,class string) *Method {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wrapper) ProcessSubclass(sname string, sc *Subclass) {
|
func (w *Wrapper) ProcessSubclass(sname string, sc *Subclass) {
|
||||||
fmt.Printf("Wrapping %s\n",sname)
|
|
||||||
gname := strings.Title(sname)
|
gname := strings.Title(sname)
|
||||||
types.Wrap(gname)
|
types.Wrap(gname)
|
||||||
types.SetSuper(gname,sc.Super)
|
types.SetSuper(gname,sc.Super)
|
||||||
|
@ -1187,7 +1210,7 @@ func (w *Wrapper) _ProcessDelSub(dname string, ps map[string][]string, nms []*Me
|
||||||
if !matches(string(m.Name[0])+m.GoName[1:],pats) {
|
if !matches(string(m.Name[0])+m.GoName[1:],pats) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if m.Type.IsFunction() || m.Type.IsFunctionPtr() || m.hasFunctionParam() {
|
if m.HasUnsupportedType() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
methods = append(methods,m)
|
methods = append(methods,m)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user