Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: output diagnostic messages when skipping variables and methods #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bind/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const (
modeRetained
)

type Reporter interface {
Message(s string)
}

func (list ErrorList) Error() string {
buf := new(bytes.Buffer)
for i, err := range list {
Expand Down Expand Up @@ -85,6 +89,8 @@ type Generator struct {
Pkg *types.Package
err ErrorList

Reporter Reporter

// fields set by init.
pkgName string
pkgPrefix string
Expand Down
21 changes: 15 additions & 6 deletions bind/gengo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package bind
import (
"bytes"
"fmt"
"go/token"
"go/types"
"strings"
)
Expand Down Expand Up @@ -189,7 +190,7 @@ func (g *goGen) paramName(params *types.Tuple, pos int) string {

func (g *goGen) genFunc(o *types.Func) {
if !g.isSigSupported(o.Type()) {
g.Printf("// skipped function %s with unsupported parameter or result types\n", o.Name())
g.warnf(o.Pos(), "skipped function %s with unsupported parameter or result types", o.Name())
return
}
g.genFuncSignature(o, "")
Expand All @@ -205,7 +206,7 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {

for _, f := range fields {
if t := f.Type(); !g.isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", obj.Name(), f.Name(), t)
g.warnf(f.Pos(), "skipped field %s.%s with unsupported type: %s", obj.Name(), f.Name(), t)
continue
}
g.Printf("//export proxy%s_%s_%s_Set\n", g.pkgPrefix, obj.Name(), f.Name())
Expand All @@ -230,7 +231,7 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {

for _, m := range methods {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name())
continue
}
g.genFuncSignature(m, obj.Name())
Expand All @@ -252,7 +253,7 @@ func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {

func (g *goGen) genVar(o *types.Var) {
if t := o.Type(); !g.isSupported(t) {
g.Printf("// skipped variable %s with unsupported type %s\n\n", o.Name(), t)
g.warnf(o.Pos(), "skipped variable %s with unsupported type %s", o.Name(), t)
return
}
// TODO(hyangah): non-struct pointer types (*int), struct type.
Expand Down Expand Up @@ -289,7 +290,7 @@ func (g *goGen) genInterface(obj *types.TypeName) {
// Define the entry points.
for _, m := range summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name())
continue
}
g.genFuncSignature(m, obj.Name())
Expand Down Expand Up @@ -318,7 +319,7 @@ func (g *goGen) genInterface(obj *types.TypeName) {

for _, m := range summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or result types\n", obj.Name(), m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or result types", obj.Name(), m.Name())
continue
}
sig := m.Type().(*types.Signature)
Expand Down Expand Up @@ -591,3 +592,11 @@ func (g *goGen) pkgName(pkg *types.Package) string {
g.importMap[pkg] = name
return name + "."
}

func (g *goGen) warnf(pos token.Pos, format string, args ...interface{}) {
if g.Reporter != nil {
fpos := g.Fset.Position(pos)
g.Reporter.Message(fmt.Sprintf(fpos.String()+": "+format, args...))
}
g.Printf("// "+format+"\n\n", args...)
}
41 changes: 25 additions & 16 deletions bind/genjava.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package bind
import (
"fmt"
"go/constant"
"go/token"
"go/types"
"html"
"math"
Expand Down Expand Up @@ -295,7 +296,7 @@ func (g *JavaGen) genStruct(s structInfo) {
cons := g.constructors[s.obj]
for _, f := range cons {
if !g.isConsSigSupported(f.Type()) {
g.Printf("// skipped constructor %s.%s with unsupported parameter or return types\n\n", n, f.Name())
g.warnf(f.Pos(), "skipped constructor %s.%s with unsupported parameter or return types", n, f.Name())
continue
}
g.genConstructor(f, n, jinf != nil)
Expand All @@ -312,7 +313,7 @@ func (g *JavaGen) genStruct(s structInfo) {

for _, f := range fields {
if t := f.Type(); !g.isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", n, f.Name(), t)
g.warnf(f.Pos(), "skipped field %s.%s with unsupported type: %s", n, f.Name(), t)
continue
}

Expand All @@ -326,7 +327,7 @@ func (g *JavaGen) genStruct(s structInfo) {
var isStringer bool
for _, m := range methods {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", n, m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", n, m.Name())
continue
}
g.javadoc(doc.Member(m.Name()))
Expand Down Expand Up @@ -487,7 +488,7 @@ func (g *JavaGen) genObjectMethods(n string, fields []*types.Var, isStringer boo
g.Printf("%s that = (%s)o;\n", n, n)
for _, f := range fields {
if t := f.Type(); !g.isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", n, f.Name(), t)
g.warnf(f.Pos(), "skipped field %s.%s with unsupported type: %s", n, f.Name(), t)
continue
}
nf := f.Name()
Expand Down Expand Up @@ -581,7 +582,7 @@ func (g *JavaGen) genInterface(iface interfaceInfo) {

for _, m := range iface.summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name())
continue
}
g.javadoc(doc.Member(m.Name()))
Expand Down Expand Up @@ -862,7 +863,7 @@ func (g *JavaGen) genFuncSignature(o *types.Func, jm *java.Func, hasThis bool) {

func (g *JavaGen) genVar(o *types.Var) {
if t := o.Type(); !g.isSupported(t) {
g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t)
g.warnf(o.Pos(), "skipped variable %s with unsupported type: %s", o.Name(), t)
return
}
jType := g.javaType(o.Type())
Expand Down Expand Up @@ -1043,7 +1044,7 @@ func JavaClassName(pkg *types.Package) string {

func (g *JavaGen) genConst(o *types.Const) {
if _, ok := o.Type().(*types.Basic); !ok || !g.isSupported(o.Type()) {
g.Printf("// skipped const %s with unsupported type: %s\n\n", o.Name(), o.Type())
g.warnf(o.Pos(), "skipped const %s with unsupported type: %s", o.Name(), o.Type())
return
}
// TODO(hyangah): should const names use upper cases + "_"?
Expand Down Expand Up @@ -1077,7 +1078,7 @@ func (g *JavaGen) genConst(o *types.Const) {

func (g *JavaGen) genJNIField(o *types.TypeName, f *types.Var) {
if t := f.Type(); !g.isSupported(t) {
g.Printf("// skipped field %s with unsupported type: %s\n\n", o.Name(), t)
g.warnf(f.Pos(), "skipped field %s with unsupported type: %s", o.Name(), t)
return
}
n := java.JNIMangle(g.javaTypeName(o.Name()))
Expand Down Expand Up @@ -1107,7 +1108,7 @@ func (g *JavaGen) genJNIField(o *types.TypeName, f *types.Var) {

func (g *JavaGen) genJNIVar(o *types.Var) {
if t := o.Type(); !g.isSupported(t) {
g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t)
g.warnf(o.Pos(), "skipped variable %s with unsupported type: %s", o.Name(), t)
return
}
n := java.JNIMangle(g.javaTypeName(o.Name()))
Expand Down Expand Up @@ -1187,7 +1188,7 @@ func (g *JavaGen) genJNIFunc(o *types.Func, sName string, jm *java.Func, proxy,
if sName != "" {
n = sName + "." + n
}
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", n)
g.warnf(o.Pos(), "skipped function %s with unsupported parameter or return types", n)
return
}
g.genJNIFuncSignature(o, sName, jm, proxy, isjava)
Expand Down Expand Up @@ -1276,7 +1277,7 @@ func (g *JavaGen) genRelease(varName string, t types.Type, mode varMode) {

func (g *JavaGen) genMethodInterfaceProxy(oName string, m *types.Func) {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s with unsupported parameter or return types\n\n", oName)
g.warnf(m.Pos(), "skipped method %s with unsupported parameter or return types", oName)
return
}
sig := m.Type().(*types.Signature)
Expand Down Expand Up @@ -1345,7 +1346,7 @@ func (g *JavaGen) GenH() error {
g.Printf("\n")
for _, m := range iface.summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name())
continue
}
g.genInterfaceMethodSignature(m, iface.obj.Name(), true, g.paramName)
Expand Down Expand Up @@ -1477,7 +1478,7 @@ func (g *JavaGen) GenC() error {
g.Printf("jmethodID proxy_class_%s_%s_cons;\n", g.pkgPrefix, iface.obj.Name())
for _, m := range iface.summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name())
continue
}
g.Printf("static jmethodID mid_%s_%s;\n", iface.obj.Name(), m.Name())
Expand Down Expand Up @@ -1519,7 +1520,7 @@ func (g *JavaGen) GenC() error {
g.Printf("clazz = (*env)->FindClass(env, %q);\n", g.jniClassSigPrefix(pkg)+g.javaTypeName(iface.obj.Name()))
for _, m := range iface.summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name())
continue
}
sig := m.Type().(*types.Signature)
Expand Down Expand Up @@ -1630,7 +1631,7 @@ func (g *JavaGen) GenJava() error {
}
for _, m := range iface.summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", n, m.Name())
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", n, m.Name())
continue
}
g.Printf("public native ")
Expand All @@ -1652,7 +1653,7 @@ func (g *JavaGen) GenJava() error {
}
for _, f := range g.funcs {
if !g.isSigSupported(f.Type()) {
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", f.Name())
g.warnf(f.Pos(), "skipped function %s with unsupported parameter or return types", f.Name())
continue
}
g.javadoc(g.docs[f.Name()].Doc())
Expand All @@ -1669,6 +1670,14 @@ func (g *JavaGen) GenJava() error {
return nil
}

func (g *JavaGen) warnf(pos token.Pos, format string, args ...interface{}) {
if g.Reporter != nil {
fpos := g.Fset.Position(pos)
g.Reporter.Message(fmt.Sprintf(fpos.String()+": "+format, args...))
}
g.Printf("// "+format+"\n\n", args...)
}

// embeddedJavaClasses returns the possible empty list of Java types embedded
// in the given struct type.
func embeddedJavaClasses(t *types.Struct) []string {
Expand Down
Loading