bind: ignore unsupported basic types
Before this change, binding unsupported basic types such as uint failed with an error. Instead, add them to the list of ignored types so that no error is generated and a comment is generated explaining why the offending function, constant or variable was skipped. Unsigned integers are probably easy to support in ObjC, but leave them unsupported for now. While here, improve the printing of the ignored types in the explaining comments. Fixes golang/go#24762 Change-Id: I0d9ab471b2245728270f6ee588f554d4a105d500 Reviewed-on: https://go-review.googlesource.com/105377 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
parent
90139f6bae
commit
1f177cbe4d
14
bind/gen.go
14
bind/gen.go
@ -484,7 +484,19 @@ func (g *Generator) isSupported(t types.Type) bool {
|
|||||||
}
|
}
|
||||||
switch t := t.(type) {
|
switch t := t.(type) {
|
||||||
case *types.Basic:
|
case *types.Basic:
|
||||||
return true
|
switch t.Kind() {
|
||||||
|
case types.Bool, types.UntypedBool,
|
||||||
|
types.Int,
|
||||||
|
types.Int8, types.Uint8, // types.Byte
|
||||||
|
types.Int16,
|
||||||
|
types.Int32, types.UntypedRune, // types.Rune
|
||||||
|
types.Int64, types.UntypedInt,
|
||||||
|
types.Float32,
|
||||||
|
types.Float64, types.UntypedFloat,
|
||||||
|
types.String, types.UntypedString:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
case *types.Slice:
|
case *types.Slice:
|
||||||
switch e := t.Elem().(type) {
|
switch e := t.Elem().(type) {
|
||||||
case *types.Basic:
|
case *types.Basic:
|
||||||
|
@ -206,7 +206,7 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {
|
|||||||
|
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
if t := f.Type(); !g.isSupported(t) {
|
if t := f.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", obj.Name(), f.Name(), t)
|
g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", obj.Name(), f.Name(), t)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.Printf("//export proxy%s_%s_%s_Set\n", g.pkgPrefix, obj.Name(), f.Name())
|
g.Printf("//export proxy%s_%s_%s_Set\n", g.pkgPrefix, obj.Name(), f.Name())
|
||||||
@ -253,7 +253,7 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {
|
|||||||
|
|
||||||
func (g *goGen) genVar(o *types.Var) {
|
func (g *goGen) genVar(o *types.Var) {
|
||||||
if t := o.Type(); !g.isSupported(t) {
|
if t := o.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped variable %s with unsupported type %T\n\n", o.Name(), t)
|
g.Printf("// skipped variable %s with unsupported type %s\n\n", o.Name(), t)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO(hyangah): non-struct pointer types (*int), struct type.
|
// TODO(hyangah): non-struct pointer types (*int), struct type.
|
||||||
|
@ -313,7 +313,7 @@ func (g *JavaGen) genStruct(s structInfo) {
|
|||||||
|
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
if t := f.Type(); !g.isSupported(t) {
|
if t := f.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", n, f.Name(), t)
|
g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", n, f.Name(), t)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +465,7 @@ func (g *JavaGen) genObjectMethods(n string, fields []*types.Var, isStringer boo
|
|||||||
g.Printf("%s that = (%s)o;\n", n, n)
|
g.Printf("%s that = (%s)o;\n", n, n)
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
if t := f.Type(); !g.isSupported(t) {
|
if t := f.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", n, f.Name(), t)
|
g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", n, f.Name(), t)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
nf := f.Name()
|
nf := f.Name()
|
||||||
@ -840,7 +840,7 @@ func (g *JavaGen) genFuncSignature(o *types.Func, jm *java.Func, hasThis bool) {
|
|||||||
|
|
||||||
func (g *JavaGen) genVar(o *types.Var) {
|
func (g *JavaGen) genVar(o *types.Var) {
|
||||||
if t := o.Type(); !g.isSupported(t) {
|
if t := o.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped variable %s with unsupported type: %T\n\n", o.Name(), t)
|
g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
jType := g.javaType(o.Type())
|
jType := g.javaType(o.Type())
|
||||||
@ -1020,8 +1020,8 @@ func JavaClassName(pkg *types.Package) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *JavaGen) genConst(o *types.Const) {
|
func (g *JavaGen) genConst(o *types.Const) {
|
||||||
if _, ok := o.Type().(*types.Basic); !ok {
|
if _, ok := o.Type().(*types.Basic); !ok || !g.isSupported(o.Type()) {
|
||||||
g.Printf("// skipped const %s with unsupported type: %T\n\n", o.Name(), o)
|
g.Printf("// skipped const %s with unsupported type: %s\n\n", o.Name(), o.Type())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO(hyangah): should const names use upper cases + "_"?
|
// TODO(hyangah): should const names use upper cases + "_"?
|
||||||
@ -1055,7 +1055,7 @@ func (g *JavaGen) genConst(o *types.Const) {
|
|||||||
|
|
||||||
func (g *JavaGen) genJNIField(o *types.TypeName, f *types.Var) {
|
func (g *JavaGen) genJNIField(o *types.TypeName, f *types.Var) {
|
||||||
if t := f.Type(); !g.isSupported(t) {
|
if t := f.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped field %s with unsupported type: %T\n\n", o.Name(), t)
|
g.Printf("// skipped field %s with unsupported type: %s\n\n", o.Name(), t)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n := java.JNIMangle(g.javaTypeName(o.Name()))
|
n := java.JNIMangle(g.javaTypeName(o.Name()))
|
||||||
@ -1085,7 +1085,7 @@ func (g *JavaGen) genJNIField(o *types.TypeName, f *types.Var) {
|
|||||||
|
|
||||||
func (g *JavaGen) genJNIVar(o *types.Var) {
|
func (g *JavaGen) genJNIVar(o *types.Var) {
|
||||||
if t := o.Type(); !g.isSupported(t) {
|
if t := o.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped variable %s with unsupported type: %T\n\n", o.Name(), t)
|
g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n := java.JNIMangle(g.javaTypeName(o.Name()))
|
n := java.JNIMangle(g.javaTypeName(o.Name()))
|
||||||
|
@ -190,8 +190,8 @@ func (g *ObjcGen) GenH() error {
|
|||||||
// const
|
// const
|
||||||
// TODO: prefix with k?, or use a class method?
|
// TODO: prefix with k?, or use a class method?
|
||||||
for _, obj := range g.constants {
|
for _, obj := range g.constants {
|
||||||
if _, ok := obj.Type().(*types.Basic); !ok {
|
if _, ok := obj.Type().(*types.Basic); !ok || !g.isSupported(obj.Type()) {
|
||||||
g.Printf("// skipped const %s with unsupported type: %T\n\n", obj.Name(), obj)
|
g.Printf("// skipped const %s with unsupported type: %s\n\n", obj.Name(), obj.Type())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.objcdoc(g.docs[obj.Name()].Doc())
|
g.objcdoc(g.docs[obj.Name()].Doc())
|
||||||
@ -211,7 +211,7 @@ func (g *ObjcGen) GenH() error {
|
|||||||
g.Printf("@interface %s : NSObject\n", g.namePrefix)
|
g.Printf("@interface %s : NSObject\n", g.namePrefix)
|
||||||
for _, obj := range g.vars {
|
for _, obj := range g.vars {
|
||||||
if t := obj.Type(); !g.isSupported(t) {
|
if t := obj.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped variable %s with unsupported type: %T\n\n", obj.Name(), t)
|
g.Printf("// skipped variable %s with unsupported type: %s\n\n", obj.Name(), t)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
objcType := g.objcType(obj.Type())
|
objcType := g.objcType(obj.Type())
|
||||||
@ -338,7 +338,7 @@ func (g *ObjcGen) GenM() error {
|
|||||||
|
|
||||||
func (g *ObjcGen) genVarM(o *types.Var) {
|
func (g *ObjcGen) genVarM(o *types.Var) {
|
||||||
if t := o.Type(); !g.isSupported(t) {
|
if t := o.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped variable %s with unsupported type: %T\n\n", o.Name(), t)
|
g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
objcType := g.objcType(o.Type())
|
objcType := g.objcType(o.Type())
|
||||||
@ -364,8 +364,8 @@ func (g *ObjcGen) genVarM(o *types.Var) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *ObjcGen) genConstM(o *types.Const) {
|
func (g *ObjcGen) genConstM(o *types.Const) {
|
||||||
if _, ok := o.Type().(*types.Basic); !ok {
|
if _, ok := o.Type().(*types.Basic); !ok || !g.isSupported(o.Type()) {
|
||||||
g.Printf("// skipped const %s with unsupported type: %T\n\n", o.Name(), o)
|
g.Printf("// skipped const %s with unsupported type: %s\n\n", o.Name(), o.Type())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cName := fmt.Sprintf("%s%s", g.namePrefix, o.Name())
|
cName := fmt.Sprintf("%s%s", g.namePrefix, o.Name())
|
||||||
@ -1114,7 +1114,7 @@ func (g *ObjcGen) genStructH(obj *types.TypeName, t *types.Struct) {
|
|||||||
// accessors to exported fields.
|
// accessors to exported fields.
|
||||||
for _, f := range exportedFields(t) {
|
for _, f := range exportedFields(t) {
|
||||||
if t := f.Type(); !g.isSupported(t) {
|
if t := f.Type(); !g.isSupported(t) {
|
||||||
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", obj.Name(), f.Name(), t)
|
g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", obj.Name(), f.Name(), t)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name, typ := f.Name(), g.objcFieldType(f.Type())
|
name, typ := f.Name(), g.objcFieldType(f.Type())
|
||||||
@ -1184,7 +1184,7 @@ func (g *ObjcGen) genStructM(obj *types.TypeName, t *types.Struct) {
|
|||||||
|
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
if !g.isSupported(f.Type()) {
|
if !g.isSupported(f.Type()) {
|
||||||
g.Printf("// skipped unsupported field %s with type %T\n\n", f.Name(), f)
|
g.Printf("// skipped unsupported field %s with type %s\n\n", f.Name(), f.Type())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.genGetter(obj.Name(), f)
|
g.genGetter(obj.Name(), f)
|
||||||
|
14
bind/testdata/ignore.go
vendored
14
bind/testdata/ignore.go
vendored
@ -43,3 +43,17 @@ type I interface {
|
|||||||
Argument(_ interface{})
|
Argument(_ interface{})
|
||||||
Result() interface{}
|
Result() interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
Uint uint
|
||||||
|
Uint32 uint32
|
||||||
|
Uint64 uint64
|
||||||
|
C64 complex64 = 0
|
||||||
|
C128 complex128 = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
Cuint uint = 0
|
||||||
|
Cuint32 uint32 = 0
|
||||||
|
Cuint64 uint64 = 0
|
||||||
|
)
|
||||||
|
16
bind/testdata/ignore.go.golden
vendored
16
bind/testdata/ignore.go.golden
vendored
@ -21,7 +21,7 @@ import (
|
|||||||
// suppress the error if seq ends up unused
|
// suppress the error if seq ends up unused
|
||||||
var _ = _seq.FromRefNum
|
var _ = _seq.FromRefNum
|
||||||
|
|
||||||
// skipped field S.F with unsupported type: *types.Interface
|
// skipped field S.F with unsupported type: interface{}
|
||||||
|
|
||||||
// skipped method S.Argument with unsupported parameter or return types
|
// skipped method S.Argument with unsupported parameter or return types
|
||||||
|
|
||||||
@ -42,9 +42,19 @@ func (p *proxyignore_I) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind
|
|||||||
|
|
||||||
// skipped method I.Argument with unsupported parameter or result types
|
// skipped method I.Argument with unsupported parameter or result types
|
||||||
// skipped method I.Result with unsupported parameter or result types
|
// skipped method I.Result with unsupported parameter or result types
|
||||||
// skipped variable V with unsupported type *types.Interface
|
// skipped variable C128 with unsupported type complex128
|
||||||
|
|
||||||
// skipped variable Var with unsupported type *types.Interface
|
// skipped variable C64 with unsupported type complex64
|
||||||
|
|
||||||
|
// skipped variable Uint with unsupported type uint
|
||||||
|
|
||||||
|
// skipped variable Uint32 with unsupported type uint32
|
||||||
|
|
||||||
|
// skipped variable Uint64 with unsupported type uint64
|
||||||
|
|
||||||
|
// skipped variable V with unsupported type interface{}
|
||||||
|
|
||||||
|
// skipped variable Var with unsupported type interface{}
|
||||||
|
|
||||||
// skipped function Argument with unsupported parameter or result types
|
// skipped function Argument with unsupported parameter or result types
|
||||||
// skipped function Result with unsupported parameter or result types
|
// skipped function Result with unsupported parameter or result types
|
||||||
|
16
bind/testdata/ignore.java.c.golden
vendored
16
bind/testdata/ignore.java.c.golden
vendored
@ -49,7 +49,7 @@ Java_ignore_S__1_1New(JNIEnv *env, jclass clazz) {
|
|||||||
|
|
||||||
// skipped function S.Result with unsupported parameter or return types
|
// skipped function S.Result with unsupported parameter or return types
|
||||||
|
|
||||||
// skipped field S with unsupported type: *types.Interface
|
// skipped field S with unsupported type: interface{}
|
||||||
|
|
||||||
// skipped function I.Argument with unsupported parameter or return types
|
// skipped function I.Argument with unsupported parameter or return types
|
||||||
|
|
||||||
@ -59,7 +59,17 @@ Java_ignore_S__1_1New(JNIEnv *env, jclass clazz) {
|
|||||||
|
|
||||||
// skipped method I with unsupported parameter or return types
|
// skipped method I with unsupported parameter or return types
|
||||||
|
|
||||||
// skipped variable V with unsupported type: *types.Interface
|
// skipped variable C128 with unsupported type: complex128
|
||||||
|
|
||||||
// skipped variable Var with unsupported type: *types.Interface
|
// skipped variable C64 with unsupported type: complex64
|
||||||
|
|
||||||
|
// skipped variable Uint with unsupported type: uint
|
||||||
|
|
||||||
|
// skipped variable Uint32 with unsupported type: uint32
|
||||||
|
|
||||||
|
// skipped variable Uint64 with unsupported type: uint64
|
||||||
|
|
||||||
|
// skipped variable V with unsupported type: interface{}
|
||||||
|
|
||||||
|
// skipped variable Var with unsupported type: interface{}
|
||||||
|
|
||||||
|
26
bind/testdata/ignore.java.golden
vendored
26
bind/testdata/ignore.java.golden
vendored
@ -23,7 +23,7 @@ public final class S implements Seq.Proxy, I {
|
|||||||
|
|
||||||
private static native Seq.Ref __New();
|
private static native Seq.Ref __New();
|
||||||
|
|
||||||
// skipped field S.F with unsupported type: *types.Interface
|
// skipped field S.F with unsupported type: interface{}
|
||||||
|
|
||||||
// skipped method S.Argument with unsupported parameter or return types
|
// skipped method S.Argument with unsupported parameter or return types
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public final class S implements Seq.Proxy, I {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
S that = (S)o;
|
S that = (S)o;
|
||||||
// skipped field S.F with unsupported type: *types.Interface
|
// skipped field S.F with unsupported type: interface{}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -104,12 +104,28 @@ public abstract class Ignore {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// skipped const NamedConst with unsupported type: *types.Const
|
// skipped const Cuint with unsupported type: uint
|
||||||
|
|
||||||
|
// skipped const Cuint32 with unsupported type: uint32
|
||||||
|
|
||||||
|
// skipped const Cuint64 with unsupported type: uint64
|
||||||
|
|
||||||
|
// skipped const NamedConst with unsupported type: ignore.NamedString
|
||||||
|
|
||||||
|
|
||||||
// skipped variable V with unsupported type: *types.Interface
|
// skipped variable C128 with unsupported type: complex128
|
||||||
|
|
||||||
// skipped variable Var with unsupported type: *types.Interface
|
// skipped variable C64 with unsupported type: complex64
|
||||||
|
|
||||||
|
// skipped variable Uint with unsupported type: uint
|
||||||
|
|
||||||
|
// skipped variable Uint32 with unsupported type: uint32
|
||||||
|
|
||||||
|
// skipped variable Uint64 with unsupported type: uint64
|
||||||
|
|
||||||
|
// skipped variable V with unsupported type: interface{}
|
||||||
|
|
||||||
|
// skipped variable Var with unsupported type: interface{}
|
||||||
|
|
||||||
// skipped function Argument with unsupported parameter or return types
|
// skipped function Argument with unsupported parameter or return types
|
||||||
|
|
||||||
|
24
bind/testdata/ignore.objc.h.golden
vendored
24
bind/testdata/ignore.objc.h.golden
vendored
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
- (instancetype)initWithRef:(id)ref;
|
- (instancetype)initWithRef:(id)ref;
|
||||||
- (instancetype)init;
|
- (instancetype)init;
|
||||||
// skipped field S.F with unsupported type: *types.Interface
|
// skipped field S.F with unsupported type: interface{}
|
||||||
|
|
||||||
// skipped method S.Argument with unsupported parameter or return types
|
// skipped method S.Argument with unsupported parameter or return types
|
||||||
|
|
||||||
@ -35,13 +35,29 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// skipped const NamedConst with unsupported type: *types.Const
|
// skipped const Cuint with unsupported type: uint
|
||||||
|
|
||||||
|
// skipped const Cuint32 with unsupported type: uint32
|
||||||
|
|
||||||
|
// skipped const Cuint64 with unsupported type: uint64
|
||||||
|
|
||||||
|
// skipped const NamedConst with unsupported type: ignore.NamedString
|
||||||
|
|
||||||
|
|
||||||
@interface Ignore : NSObject
|
@interface Ignore : NSObject
|
||||||
// skipped variable V with unsupported type: *types.Interface
|
// skipped variable C128 with unsupported type: complex128
|
||||||
|
|
||||||
// skipped variable Var with unsupported type: *types.Interface
|
// skipped variable C64 with unsupported type: complex64
|
||||||
|
|
||||||
|
// skipped variable Uint with unsupported type: uint
|
||||||
|
|
||||||
|
// skipped variable Uint32 with unsupported type: uint32
|
||||||
|
|
||||||
|
// skipped variable Uint64 with unsupported type: uint64
|
||||||
|
|
||||||
|
// skipped variable V with unsupported type: interface{}
|
||||||
|
|
||||||
|
// skipped variable Var with unsupported type: interface{}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
24
bind/testdata/ignore.objc.m.golden
vendored
24
bind/testdata/ignore.objc.m.golden
vendored
@ -26,7 +26,7 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skipped unsupported field F with type *types.Var
|
// skipped unsupported field F with type interface{}
|
||||||
|
|
||||||
// skipped method S.Argument with unsupported parameter or return types
|
// skipped method S.Argument with unsupported parameter or return types
|
||||||
|
|
||||||
@ -51,13 +51,29 @@
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
// skipped const NamedConst with unsupported type: *types.Const
|
// skipped const Cuint with unsupported type: uint
|
||||||
|
|
||||||
|
// skipped const Cuint32 with unsupported type: uint32
|
||||||
|
|
||||||
|
// skipped const Cuint64 with unsupported type: uint64
|
||||||
|
|
||||||
|
// skipped const NamedConst with unsupported type: ignore.NamedString
|
||||||
|
|
||||||
|
|
||||||
@implementation Ignore
|
@implementation Ignore
|
||||||
// skipped variable V with unsupported type: *types.Interface
|
// skipped variable C128 with unsupported type: complex128
|
||||||
|
|
||||||
// skipped variable Var with unsupported type: *types.Interface
|
// skipped variable C64 with unsupported type: complex64
|
||||||
|
|
||||||
|
// skipped variable Uint with unsupported type: uint
|
||||||
|
|
||||||
|
// skipped variable Uint32 with unsupported type: uint32
|
||||||
|
|
||||||
|
// skipped variable Uint64 with unsupported type: uint64
|
||||||
|
|
||||||
|
// skipped variable V with unsupported type: interface{}
|
||||||
|
|
||||||
|
// skipped variable Var with unsupported type: interface{}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user