2
0
mirror of synced 2025-02-23 14:58:12 +00:00

mobile/bind: skip unsupported functions, vars, fields and methods

Bind attempts to generate bindings for everything a package exports,
generating an error for what it cannot handle.
For multiple bound packages, unexporting what should not be bound
is sometimes awkward or outright impossible.

Lacking the equivalent of Cgo's //export directory, this CL change
the behaviour of bind to simply ignore everything it can't generate
bindings for, even if otherwise exported. For every declaration it
ignores, a comment is generated instead, to help any confusion as
to why a particular export was not included.

Change-Id: I2c7a5bee0f19a58009293b4e5ac2c95687e62e80
Reviewed-on: https://go-review.googlesource.com/20651
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Elias Naur 2016-03-13 15:15:56 +01:00
parent 74ee969d3f
commit 390f7b3813
14 changed files with 621 additions and 14 deletions

View File

@ -33,6 +33,7 @@ var tests = []string{
"testdata/issue12403.go",
"testdata/try.go",
"testdata/vars.go",
"testdata/ignore.go",
}
var fset = token.NewFileSet()

View File

@ -107,10 +107,6 @@ func (g *generator) init() {
g.otherNames = append(g.otherNames, obj)
}
case *types.Const:
if _, ok := obj.Type().(*types.Basic); !ok {
g.errorf("unsupported exported const for %s: %T", obj.Name(), obj)
continue
}
g.constants = append(g.constants, obj)
case *types.Var:
g.vars = append(g.vars, obj)

View File

@ -180,6 +180,10 @@ func (g *goGen) genFuncSignature(o *types.Func, objName string) {
}
func (g *goGen) genFunc(o *types.Func) {
if !isSigSupported(o.Type()) {
g.Printf("// skipped function %s with unsupported parameter or result types\n", o.Name())
return
}
g.genFuncSignature(o, "")
g.Indent()
g.genFuncBody(o, g.pkgName(g.pkg))
@ -192,6 +196,10 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {
methods := exportedMethodSet(types.NewPointer(obj.Type()))
for _, f := range fields {
if t := f.Type(); !isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", obj.Name(), f.Name(), t)
continue
}
g.Printf("//export proxy%s_%s_%s_Set\n", g.pkgPrefix, obj.Name(), f.Name())
g.Printf("func proxy%s_%s_%s_Set(refnum C.int32_t, v C.%s) {\n", g.pkgPrefix, obj.Name(), f.Name(), g.cgoType(f.Type()))
g.Indent()
@ -213,6 +221,10 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {
}
for _, m := range methods {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
g.genFuncSignature(m, obj.Name())
g.Indent()
g.Printf("ref := _seq.FromRefNum(int32(refnum))\n")
@ -224,6 +236,10 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {
}
func (g *goGen) genVar(o *types.Var) {
if t := o.Type(); !isSupported(t) {
g.Printf("// skipped variable %s with unsupported type %T\n\n", o.Name(), t)
return
}
// TODO(hyangah): non-struct pointer types (*int), struct type.
v := fmt.Sprintf("%s.%s", g.pkgName(g.pkg), o.Name())
@ -257,6 +273,10 @@ func (g *goGen) genInterface(obj *types.TypeName) {
// Define the entry points.
for _, m := range summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
g.genFuncSignature(m, obj.Name())
g.Indent()
g.Printf("ref := _seq.FromRefNum(int32(refnum))\n")
@ -278,6 +298,10 @@ func (g *goGen) genInterface(obj *types.TypeName) {
g.Printf("func (p *proxy%s_%s) Bind_proxy_refnum__() int32 { return p.Num }\n\n", g.pkgPrefix, obj.Name())
for _, m := range summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or result types\n", obj.Name(), m.Name())
continue
}
sig := m.Type().(*types.Signature)
params := sig.Params()
res := sig.Results()

View File

@ -44,12 +44,20 @@ func (g *javaGen) genStruct(obj *types.TypeName, T *types.Struct) {
g.Printf("public final go.Seq.Ref ref() { return ref; }\n\n")
for _, f := range fields {
if t := f.Type(); !isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", f.Name(), t)
continue
}
g.Printf("public final native %s get%s();\n", g.javaType(f.Type()), f.Name())
g.Printf("public final native void set%s(%s v);\n\n", f.Name(), g.javaType(f.Type()))
}
var isStringer bool
for _, m := range methods {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
g.genFuncSignature(m, false, false)
t := m.Type().(*types.Signature)
isStringer = isStringer || (m.Name() == "String" && t.Params().Len() == 0 && t.Results().Len() == 1 &&
@ -61,6 +69,10 @@ func (g *javaGen) genStruct(obj *types.TypeName, T *types.Struct) {
g.Printf("if (o == null || !(o instanceof %s)) {\n return false;\n}\n", n)
g.Printf("%s that = (%s)o;\n", n, n)
for _, f := range fields {
if t := f.Type(); !isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", f.Name(), t)
continue
}
nf := f.Name()
g.Printf("%s this%s = get%s();\n", g.javaType(f.Type()), nf, nf)
g.Printf("%s that%s = that.get%s();\n", g.javaType(f.Type()), nf, nf)
@ -80,10 +92,15 @@ func (g *javaGen) genStruct(obj *types.TypeName, T *types.Struct) {
g.Printf("@Override public int hashCode() {\n")
g.Printf(" return java.util.Arrays.hashCode(new Object[] {")
for i, f := range fields {
if i > 0 {
idx := 0
for _, f := range fields {
if t := f.Type(); !isSupported(t) {
continue
}
if idx > 0 {
g.Printf(", ")
}
idx++
g.Printf("get%s()", f.Name())
}
g.Printf("});\n")
@ -98,6 +115,9 @@ func (g *javaGen) genStruct(obj *types.TypeName, T *types.Struct) {
g.Printf(`b.append("%s").append("{");`, obj.Name())
g.Printf("\n")
for _, f := range fields {
if t := f.Type(); !isSupported(t) {
continue
}
n := f.Name()
g.Printf(`b.append("%s:").append(get%s()).append(",");`, n, n)
g.Printf("\n")
@ -130,6 +150,10 @@ func (g *javaGen) genInterface(iface interfaceInfo) {
methodSigErr := false
for _, m := range iface.summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
continue
}
g.genFuncSignature(m, false, true)
}
if methodSigErr {
@ -144,6 +168,10 @@ func (g *javaGen) genInterface(iface interfaceInfo) {
g.Indent()
for _, m := range iface.summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
continue
}
g.genFuncSignature(m, false, false)
}
@ -212,13 +240,13 @@ func (g *javaGen) jniType(T types.Type) string {
if _, ok := T.Elem().(*types.Named); ok {
return g.jniType(T.Elem())
}
panic(fmt.Sprintf("unsupported pointer to type: %s", T))
g.errorf("unsupported pointer to type: %s", T)
case *types.Named:
return "jobject"
default:
g.errorf("unsupported jniType: %#+v, %s\n", T, T)
return "TODO"
}
return "TODO"
}
func (g *javaGen) javaBasicType(T *types.Basic) string {
@ -397,6 +425,10 @@ func (g *javaGen) genFuncSignature(o *types.Func, static, header bool) {
}
func (g *javaGen) genVar(o *types.Var) {
if t := o.Type(); !isSupported(t) {
g.Printf("// skipped variable %s with unsupported type: %T\n\n", o.Name(), t)
return
}
jType := g.javaType(o.Type())
// setter
@ -436,7 +468,7 @@ func (g *javaGen) genJavaToC(varName string, t types.Type, mode varMode) {
case *types.Interface:
g.Printf("int32_t _%s = go_seq_to_refnum(env, %s);\n", varName, varName)
default:
panic(fmt.Sprintf("unsupported named type: %s / %T", u, u))
g.errorf("unsupported named type: %s / %T", u, u)
}
case *types.Pointer:
g.Printf("int32_t _%s = go_seq_to_refnum(env, %s);\n", varName, varName)
@ -550,6 +582,10 @@ func className(pkg *types.Package) string {
}
func (g *javaGen) genConst(o *types.Const) {
if _, ok := o.Type().(*types.Basic); !ok {
g.Printf("// skipped const %s with unsupported type: %T\n\n", o.Name(), o)
return
}
// TODO(hyangah): should const names use upper cases + "_"?
// TODO(hyangah): check invalid names.
jType := g.javaType(o.Type())
@ -579,6 +615,10 @@ func (g *javaGen) genConst(o *types.Const) {
}
func (g *javaGen) genJNIField(o *types.TypeName, f *types.Var) {
if t := f.Type(); !isSupported(t) {
g.Printf("// skipped field %s with unsupported type: %T\n\n", o.Name(), t)
return
}
// setter
g.Printf("JNIEXPORT void JNICALL\n")
g.Printf("Java_%s_%s_00024%s_set%s(JNIEnv *env, jobject this, %s v) {\n", g.jniPkgName(), g.className(), o.Name(), f.Name(), g.jniType(f.Type()))
@ -604,6 +644,10 @@ func (g *javaGen) genJNIField(o *types.TypeName, f *types.Var) {
}
func (g *javaGen) genJNIVar(o *types.Var) {
if t := o.Type(); !isSupported(t) {
g.Printf("// skipped variable %s with unsupported type: %T\n\n", o.Name(), t)
return
}
// setter
g.Printf("JNIEXPORT void JNICALL\n")
g.Printf("Java_%s_%s_set%s(JNIEnv *env, jclass clazz, %s v) {\n", g.jniPkgName(), g.className(), o.Name(), g.jniType(o.Type()))
@ -627,6 +671,14 @@ func (g *javaGen) genJNIVar(o *types.Var) {
}
func (g *javaGen) genJNIFunc(o *types.Func, sName string, proxy bool) {
if !isSigSupported(o.Type()) {
n := o.Name()
if sName != "" {
n = sName + "." + n
}
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", o.Name())
return
}
g.genJNIFuncSignature(o, sName, proxy)
sig := o.Type().(*types.Signature)
res := sig.Results()
@ -708,6 +760,10 @@ func (g *javaGen) genRelease(varName string, t types.Type, mode varMode) {
}
func (g *javaGen) genMethodInterfaceProxy(oName string, m *types.Func) {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s with unsupported parameter or return types\n\n", oName)
return
}
sig := m.Type().(*types.Signature)
params := sig.Params()
res := sig.Results()
@ -771,6 +827,10 @@ func (g *javaGen) genH() error {
g.Printf("extern jmethodID proxy_class_%s_%s_cons;\n", g.pkgPrefix, iface.obj.Name())
g.Printf("\n")
for _, m := range iface.summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
continue
}
g.genInterfaceMethodSignature(m, iface.obj.Name(), true)
g.Printf("\n")
}
@ -813,7 +873,6 @@ func (g *javaGen) jniCallType(t types.Type) string {
return "Object"
default:
g.errorf("unsupported basic type: %s", t)
return "TODO"
}
case *types.Slice:
return "Object"
@ -821,12 +880,13 @@ func (g *javaGen) jniCallType(t types.Type) string {
if _, ok := t.Elem().(*types.Named); ok {
return g.jniCallType(t.Elem())
}
panic(fmt.Sprintf("unsupported pointer to type: %s", t))
g.errorf("unsupported pointer to type: %s", t)
case *types.Named:
return "Object"
default:
return "Object"
}
return "TODO"
}
func (g *javaGen) jniClassSigType(obj *types.TypeName) string {
@ -870,13 +930,13 @@ func (g *javaGen) jniSigType(T types.Type) string {
if _, ok := T.Elem().(*types.Named); ok {
return g.jniSigType(T.Elem())
}
panic(fmt.Sprintf("unsupported pointer to type: %s", T))
g.errorf("unsupported pointer to type: %s", T)
case *types.Named:
return "L" + g.jniClassSigType(T.Obj()) + ";"
default:
g.errorf("unsupported jniType: %#+v, %s\n", T, T)
return "TODO"
}
return "TODO"
}
func (g *javaGen) genC() error {
@ -893,6 +953,10 @@ func (g *javaGen) genC() error {
g.Printf("jclass proxy_class_%s_%s;\n", g.pkgPrefix, iface.obj.Name())
g.Printf("jmethodID proxy_class_%s_%s_cons;\n", g.pkgPrefix, iface.obj.Name())
for _, m := range iface.summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
continue
}
g.Printf("static jmethodID mid_%s_%s;\n", iface.obj.Name(), m.Name())
}
}
@ -916,6 +980,10 @@ func (g *javaGen) genC() error {
g.Printf("proxy_class_%s_%s_cons = (*env)->GetMethodID(env, clazz, \"<init>\", \"(Lgo/Seq$Ref;)V\");\n", g.pkgPrefix, iface.obj.Name())
g.Printf("clazz = (*env)->FindClass(env, %q);\n", g.jniClassSigType(iface.obj))
for _, m := range iface.summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
continue
}
sig := m.Type().(*types.Signature)
res := sig.Results()
retSig := "V"
@ -998,6 +1066,10 @@ func (g *javaGen) genJava() error {
g.genVar(v)
}
for _, f := range g.funcs {
if !isSigSupported(f.Type()) {
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", f.Name())
continue
}
g.genFuncSignature(f, true, false)
}

View File

@ -66,6 +66,10 @@ func (g *objcGen) genGoH() error {
continue
}
for _, m := range i.summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", i.obj.Name(), m.Name())
continue
}
g.genInterfaceMethodSignature(m, i.obj.Name(), true)
g.Printf("\n")
}
@ -120,6 +124,10 @@ func (g *objcGen) genH() error {
// const
// TODO: prefix with k?, or use a class method?
for _, obj := range g.constants {
if _, ok := obj.Type().(*types.Basic); !ok {
g.Printf("// skipped const %s with unsupported type: %T\n\n", obj.Name(), obj)
continue
}
switch b := obj.Type().(*types.Basic); b.Kind() {
case types.String, types.UntypedString:
g.Printf("FOUNDATION_EXPORT NSString* const %s%s;\n", g.namePrefix, obj.Name())
@ -135,6 +143,10 @@ func (g *objcGen) genH() error {
if len(g.vars) > 0 {
g.Printf("@interface %s : NSObject\n", g.namePrefix)
for _, obj := range g.vars {
if t := obj.Type(); !isSupported(t) {
g.Printf("// skipped variable %s with unsupported type: %T\n\n", obj.Name(), t)
continue
}
objcType := g.objcType(obj.Type())
g.Printf("+ (%s) %s;\n", objcType, lowerFirst(obj.Name()))
g.Printf("+ (void) set%s:(%s)v;\n", obj.Name(), objcType)
@ -223,12 +235,20 @@ func (g *objcGen) genM() error {
g.Printf("\n")
for _, obj := range g.funcs {
if !isSigSupported(obj.Type()) {
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", obj.Name())
continue
}
g.genFuncM(obj)
g.Printf("\n")
}
for _, i := range g.interfaces {
for _, m := range i.summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", i.obj.Name(), m.Name())
continue
}
g.genInterfaceMethodProxy(i.obj, m)
}
}
@ -247,6 +267,10 @@ func (g *objcGen) genM() error {
}
func (g *objcGen) genVarM(o *types.Var) {
if t := o.Type(); !isSupported(t) {
g.Printf("// skipped variable %s with unsupported type: %T\n\n", o.Name(), t)
return
}
objcType := g.objcType(o.Type())
// setter
@ -270,6 +294,10 @@ func (g *objcGen) genVarM(o *types.Var) {
}
func (g *objcGen) genConstM(o *types.Const) {
if _, ok := o.Type().(*types.Basic); !ok {
g.Printf("// skipped const %s with unsupported type: %T\n\n", o.Name(), o)
return
}
cName := fmt.Sprintf("%s%s", g.namePrefix, o.Name())
objcType := g.objcType(o.Type())
@ -449,6 +477,10 @@ func (s *funcSummary) returnsVal() bool {
}
func (g *objcGen) genFuncH(obj *types.Func) {
if !isSigSupported(obj.Type()) {
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", obj.Name())
return
}
if s := g.funcSummary(obj); s != nil {
g.Printf("FOUNDATION_EXPORT %s;\n", s.asFunc(g))
}
@ -528,7 +560,7 @@ func (g *objcGen) genWrite(varName string, t types.Type, mode varMode) {
case *types.Interface:
g.genRefWrite(varName, t)
default:
panic(fmt.Sprintf("unsupported named type: %s / %T", u, u))
g.errorf("unsupported named type: %s / %T", u, u)
}
case *types.Pointer:
g.genRefWrite(varName, t)
@ -680,6 +712,10 @@ func (g *objcGen) genInterfaceInterface(obj *types.TypeName, summary ifaceSummar
g.Printf("\n")
g.Printf("- (id)initWithRef:(id)ref;\n")
for _, m := range summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
return
}
s := g.funcSummary(m)
g.Printf("- %s;\n", s.asMethod(g))
}
@ -694,6 +730,10 @@ func (g *objcGen) genInterfaceH(obj *types.TypeName, t *types.Interface) {
}
g.Printf("@protocol %s%s\n", g.namePrefix, obj.Name())
for _, m := range makeIfaceSummary(t).callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(m)
g.Printf("- %s;\n", s.asMethod(g))
}
@ -717,6 +757,10 @@ func (g *objcGen) genInterfaceM(obj *types.TypeName, t *types.Interface) bool {
g.Printf("\n")
for _, m := range summary.callable {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(m)
g.Printf("- %s {\n", s.asMethod(g))
g.Indent()
@ -839,6 +883,10 @@ func (g *objcGen) genStructH(obj *types.TypeName, t *types.Struct) {
// accessors to exported fields.
for _, f := range exportedFields(t) {
if t := f.Type(); !isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", obj.Name(), f.Name(), t)
continue
}
name, typ := f.Name(), g.objcFieldType(f.Type())
g.Printf("- (%s)%s;\n", typ, lowerFirst(name))
g.Printf("- (void)set%s:(%s)v;\n", name, typ)
@ -846,6 +894,10 @@ func (g *objcGen) genStructH(obj *types.TypeName, t *types.Struct) {
// exported methods
for _, m := range exportedMethodSet(types.NewPointer(obj.Type())) {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(m)
g.Printf("- %s;\n", lowerFirst(s.asMethod(g)))
}
@ -868,11 +920,19 @@ func (g *objcGen) genStructM(obj *types.TypeName, t *types.Struct) {
g.Printf("}\n\n")
for _, f := range fields {
if !isSupported(f.Type()) {
g.Printf("// skipped unsupported field %s with type %T\n\n", f.Name(), f)
continue
}
g.genGetter(obj.Name(), f)
g.genSetter(obj.Name(), f)
}
for _, m := range methods {
if !isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(m)
g.Printf("- %s {\n", s.asMethod(g))
g.Indent()

45
bind/testdata/ignore.go vendored Normal file
View File

@ -0,0 +1,45 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// package ignore tests that exported, but otherwise
// unsupported functions, variables, fields and methods
// are ignored by the generators
package ignore
var Var interface{}
type (
NamedString string
)
const NamedConst NamedString = "foo"
var V interface{}
func Argument(_ interface{}) {
}
func Result() interface{} {
return nil
}
type S struct {
F interface{}
}
type (
F func()
)
func (_ *S) Argument(_ interface{}) {
}
func (_ *S) Result() interface{} {
return nil
}
type I interface {
Argument(_ interface{})
Result() interface{}
}

44
bind/testdata/ignore.go.golden vendored Normal file
View File

@ -0,0 +1,44 @@
// Package gomobile_bind is an autogenerated binder stub for package ignore.
// gobind -lang=go ignore
//
// File is generated by gobind. Do not edit.
package gomobile_bind
/*
#include <stdlib.h>
#include <stdint.h>
#include "seq.h"
#include "ignore.h"
*/
import "C"
import (
_seq "golang.org/x/mobile/bind/seq"
)
// suppress the error if seq ends up unused
var _ = _seq.FromRefNum
// skipped field S.F with unsupported type: *types.Interface
// skipped method S.Argument with unsupported parameter or return types
// skipped method S.Result with unsupported parameter or return types
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
type proxyignore_I _seq.Ref
func (p *proxyignore_I) Bind_proxy_refnum__() int32 { return p.Num }
// skipped method I.Argument 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 Var with unsupported type *types.Interface
// skipped function Argument with unsupported parameter or result types
// skipped function Result with unsupported parameter or result types

59
bind/testdata/ignore.java.c.golden vendored Normal file
View File

@ -0,0 +1,59 @@
// JNI functions for the Go <=> Java bridge.
// gobind -lang=java ignore
//
// File is generated by gobind. Do not edit.
#include <android/log.h>
#include <stdint.h>
#include "seq.h"
#include "_cgo_export.h"
#include "ignore.h"
jclass proxy_class_ignore_I;
jmethodID proxy_class_ignore_I_cons;
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
jclass proxy_class_ignore_S;
jmethodID proxy_class_ignore_S_cons;
JNIEXPORT void JNICALL
Java_go_ignore_Ignore_init(JNIEnv *env, jclass _unused) {
jclass clazz;
clazz = (*env)->FindClass(env, "go/ignore/Ignore$S");
proxy_class_ignore_S = (*env)->NewGlobalRef(env, clazz);
proxy_class_ignore_S_cons = (*env)->GetMethodID(env, clazz, "<init>", "(Lgo/Seq$Ref;)V");
clazz = (*env)->FindClass(env, "go/ignore/Ignore$I$Proxy");
proxy_class_ignore_I = (*env)->NewGlobalRef(env, clazz);
proxy_class_ignore_I_cons = (*env)->GetMethodID(env, clazz, "<init>", "(Lgo/Seq$Ref;)V");
clazz = (*env)->FindClass(env, "go/ignore/Ignore$I");
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
}
// skipped function Argument with unsupported parameter or return types
// skipped function Result with unsupported parameter or return types
// skipped function Argument with unsupported parameter or return types
// skipped function Result with unsupported parameter or return types
// skipped field S with unsupported type: *types.Interface
// skipped function Argument with unsupported parameter or return types
// skipped method I with unsupported parameter or return types
// skipped function Result 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 Var with unsupported type: *types.Interface

96
bind/testdata/ignore.java.golden vendored Normal file
View File

@ -0,0 +1,96 @@
// Java class go.ignore.Ignore is a proxy for talking to a Go program.
// gobind -lang=java ignore
//
// File is generated by gobind. Do not edit.
package go.ignore;
import go.Seq;
public abstract class Ignore {
static {
Seq.touch(); // for loading the native library
init();
}
private Ignore() {} // uninstantiable
// touch is called from other bound packages to initialize this package
public static void touch() {}
private static native void init();
public static final class S implements go.Seq.Object, I {
private final go.Seq.Ref ref;
private S(go.Seq.Ref ref) { this.ref = ref; }
public final go.Seq.Ref ref() { return ref; }
// skipped field F.interface{} with unsupported type: %!T(MISSING)
// skipped method S.Argument with unsupported parameter or return types
// skipped method S.Result with unsupported parameter or return types
@Override public boolean equals(Object o) {
if (o == null || !(o instanceof S)) {
return false;
}
S that = (S)o;
// skipped field F.interface{} with unsupported type: %!T(MISSING)
return true;
}
@Override public int hashCode() {
return java.util.Arrays.hashCode(new Object[] {});
}
@Override public String toString() {
StringBuilder b = new StringBuilder();
b.append("S").append("{");
return b.append("}").toString();
}
}
public interface I extends go.Seq.Object {
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
public static abstract class Stub implements I {
private final go.Seq.Ref ref;
public Stub() {
ref = go.Seq.createRef(this);
}
public final go.Seq.Ref ref() { return ref; }
}
static final class Proxy implements I {
private go.Seq.Ref ref;
Proxy(go.Seq.Ref ref) { this.ref = ref; }
public final go.Seq.Ref ref() { return ref; }
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
}
}
// skipped const NamedConst with unsupported type: *types.Const
// skipped variable V with unsupported type: *types.Interface
// skipped variable Var with unsupported type: *types.Interface
// skipped function Argument with unsupported parameter or return types
// skipped function Result with unsupported parameter or return types
}

20
bind/testdata/ignore.java.h.golden vendored Normal file
View File

@ -0,0 +1,20 @@
// JNI function headers for the Go <=> Java bridge.
// gobind -lang=java ignore
//
// File is generated by gobind. Do not edit.
#ifndef __Ignore_H__
#define __Ignore_H__
#include <jni.h>
extern jclass proxy_class_ignore_I;
extern jmethodID proxy_class_ignore_I_cons;
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
extern jclass proxy_class_ignore_S;
extern jmethodID proxy_class_ignore_S_cons;
#endif

15
bind/testdata/ignore.objc.go.h.golden vendored Normal file
View File

@ -0,0 +1,15 @@
// Objective-C API for talking to ignore Go package.
// gobind -lang=objc ignore
//
// File is generated by gobind. Do not edit.
#ifndef __ignore_H__
#define __ignore_H__
#include <stdint.h>
#include <objc/objc.h>
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
#endif

61
bind/testdata/ignore.objc.h.golden vendored Normal file
View File

@ -0,0 +1,61 @@
// Objective-C API for talking to ignore Go package.
// gobind -lang=objc ignore
//
// File is generated by gobind. Do not edit.
#ifndef __GoIgnore_H__
#define __GoIgnore_H__
#include <Foundation/Foundation.h>
@class GoIgnoreS;
@protocol GoIgnoreI;
@class GoIgnoreI;
@interface GoIgnoreS : NSObject {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
// skipped field S.F with unsupported type: *types.Interface
// skipped method S.Argument with unsupported parameter or return types
// skipped method S.Result with unsupported parameter or return types
@end
@protocol GoIgnoreI
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
@end
// skipped const NamedConst with unsupported type: *types.Const
@interface GoIgnore : NSObject
// skipped variable V with unsupported type: *types.Interface
// skipped variable Var with unsupported type: *types.Interface
@end
// skipped function Argument with unsupported parameter or return types
// skipped function Result with unsupported parameter or return types
@class GoIgnoreI;
@interface GoIgnoreI : NSObject <GoIgnoreI> {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
// skipped method I.Argument with unsupported parameter or return types
#endif

68
bind/testdata/ignore.objc.m.golden vendored Normal file
View File

@ -0,0 +1,68 @@
// Objective-C API for talking to ignore Go package.
// gobind -lang=objc ignore
//
// File is generated by gobind. Do not edit.
#include <Foundation/Foundation.h>
#include "seq.h"
#include "_cgo_export.h"
#include "GoIgnore.h"
static NSString* errDomain = @"go.ignore";
@implementation GoIgnoreS {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
// skipped unsupported field F with type *types.Var
// skipped method S.Argument with unsupported parameter or return types
// skipped method S.Result with unsupported parameter or return types
@end
@implementation GoIgnoreI {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
@end
// skipped const NamedConst with unsupported type: *types.Const
@implementation GoIgnore
// skipped variable V with unsupported type: *types.Interface
// skipped variable Var with unsupported type: *types.Interface
@end
// skipped function Argument with unsupported parameter or return types
// skipped function Result with unsupported parameter or return types
// skipped method I.Argument with unsupported parameter or return types
// skipped method I.Result with unsupported parameter or return types
__attribute__((constructor)) static void init() {
init_seq();
}

View File

@ -101,6 +101,52 @@ func isErrorType(t types.Type) bool {
return types.Identical(t, types.Universe.Lookup("error").Type())
}
// isSigSupported returns whether the generators can handle a given
// function signature
func isSigSupported(t types.Type) bool {
sig := t.(*types.Signature)
params := sig.Params()
for i := 0; i < params.Len(); i++ {
if !isSupported(params.At(i).Type()) {
return false
}
}
res := sig.Results()
for i := 0; i < res.Len(); i++ {
if !isSupported(res.At(i).Type()) {
return false
}
}
return true
}
// isSupported returns whether the generators can handle the type.
func isSupported(t types.Type) bool {
if isErrorType(t) {
return true
}
switch t := t.(type) {
case *types.Basic:
return true
case *types.Slice:
switch e := t.Elem().(type) {
case *types.Basic:
return e.Kind() == types.Uint8
}
case *types.Pointer:
switch t.Elem().(type) {
case *types.Named:
return true
}
case *types.Named:
switch t.Underlying().(type) {
case *types.Interface, *types.Pointer:
return true
}
}
return false
}
func isExported(t types.Type) bool {
if isErrorType(t) {
return true