Skip to content

Commit 01a30c6

Browse files
committed
bind,cmd/gobind: report bind diagnostic messages back to command
1 parent 64e5ba5 commit 01a30c6

File tree

6 files changed

+97
-44
lines changed

6 files changed

+97
-44
lines changed

bind/gen.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ const (
4343
modeRetained
4444
)
4545

46+
type Reporter interface {
47+
Message(s string)
48+
}
49+
4650
func (list ErrorList) Error() string {
4751
buf := new(bytes.Buffer)
4852
for i, err := range list {
@@ -85,6 +89,8 @@ type Generator struct {
8589
Pkg *types.Package
8690
err ErrorList
8791

92+
Reporter Reporter
93+
8894
// fields set by init.
8995
pkgName string
9096
pkgPrefix string

bind/gengo.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package bind
77
import (
88
"bytes"
99
"fmt"
10+
"go/token"
1011
"go/types"
1112
"strings"
1213
)
@@ -189,7 +190,7 @@ func (g *goGen) paramName(params *types.Tuple, pos int) string {
189190

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

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

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

253254
func (g *goGen) genVar(o *types.Var) {
254255
if t := o.Type(); !g.isSupported(t) {
255-
g.Printf("// skipped variable %s with unsupported type %s\n\n", o.Name(), t)
256+
g.warnf(o.Pos(), "skipped variable %s with unsupported type %s", o.Name(), t)
256257
return
257258
}
258259
// TODO(hyangah): non-struct pointer types (*int), struct type.
@@ -289,7 +290,7 @@ func (g *goGen) genInterface(obj *types.TypeName) {
289290
// Define the entry points.
290291
for _, m := range summary.callable {
291292
if !g.isSigSupported(m.Type()) {
292-
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
293+
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", obj.Name(), m.Name())
293294
continue
294295
}
295296
g.genFuncSignature(m, obj.Name())
@@ -318,7 +319,7 @@ func (g *goGen) genInterface(obj *types.TypeName) {
318319

319320
for _, m := range summary.callable {
320321
if !g.isSigSupported(m.Type()) {
321-
g.Printf("// skipped method %s.%s with unsupported parameter or result types\n", obj.Name(), m.Name())
322+
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or result types", obj.Name(), m.Name())
322323
continue
323324
}
324325
sig := m.Type().(*types.Signature)
@@ -591,3 +592,11 @@ func (g *goGen) pkgName(pkg *types.Package) string {
591592
g.importMap[pkg] = name
592593
return name + "."
593594
}
595+
596+
func (g *goGen) warnf(pos token.Pos, format string, args ...interface{}) {
597+
if g.Reporter != nil {
598+
fpos := g.Fset.Position(pos)
599+
g.Reporter.Message(fmt.Sprintf(fpos.String()+": "+format, args...))
600+
}
601+
g.Printf("// "+format+"\n\n", args...)
602+
}

bind/genjava.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package bind
77
import (
88
"fmt"
99
"go/constant"
10+
"go/token"
1011
"go/types"
1112
"html"
1213
"math"
@@ -295,7 +296,7 @@ func (g *JavaGen) genStruct(s structInfo) {
295296
cons := g.constructors[s.obj]
296297
for _, f := range cons {
297298
if !g.isConsSigSupported(f.Type()) {
298-
g.Printf("// skipped constructor %s.%s with unsupported parameter or return types\n\n", n, f.Name())
299+
g.warnf(f.Pos(), "skipped constructor %s.%s with unsupported parameter or return types", n, f.Name())
299300
continue
300301
}
301302
g.genConstructor(f, n, jinf != nil)
@@ -312,7 +313,7 @@ func (g *JavaGen) genStruct(s structInfo) {
312313

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

@@ -326,7 +327,7 @@ func (g *JavaGen) genStruct(s structInfo) {
326327
var isStringer bool
327328
for _, m := range methods {
328329
if !g.isSigSupported(m.Type()) {
329-
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", n, m.Name())
330+
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", n, m.Name())
330331
continue
331332
}
332333
g.javadoc(doc.Member(m.Name()))
@@ -487,7 +488,7 @@ func (g *JavaGen) genObjectMethods(n string, fields []*types.Var, isStringer boo
487488
g.Printf("%s that = (%s)o;\n", n, n)
488489
for _, f := range fields {
489490
if t := f.Type(); !g.isSupported(t) {
490-
g.Printf("// skipped field %s.%s with unsupported type: %s\n\n", n, f.Name(), t)
491+
g.warnf(f.Pos(), "skipped field %s.%s with unsupported type: %s", n, f.Name(), t)
491492
continue
492493
}
493494
nf := f.Name()
@@ -581,7 +582,7 @@ func (g *JavaGen) genInterface(iface interfaceInfo) {
581582

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

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

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

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

11081109
func (g *JavaGen) genJNIVar(o *types.Var) {
11091110
if t := o.Type(); !g.isSupported(t) {
1110-
g.Printf("// skipped variable %s with unsupported type: %s\n\n", o.Name(), t)
1111+
g.warnf(o.Pos(), "skipped variable %s with unsupported type: %s", o.Name(), t)
11111112
return
11121113
}
11131114
n := java.JNIMangle(g.javaTypeName(o.Name()))
@@ -1187,7 +1188,7 @@ func (g *JavaGen) genJNIFunc(o *types.Func, sName string, jm *java.Func, proxy,
11871188
if sName != "" {
11881189
n = sName + "." + n
11891190
}
1190-
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", n)
1191+
g.warnf(o.Pos(), "skipped function %s with unsupported parameter or return types", n)
11911192
return
11921193
}
11931194
g.genJNIFuncSignature(o, sName, jm, proxy, isjava)
@@ -1276,7 +1277,7 @@ func (g *JavaGen) genRelease(varName string, t types.Type, mode varMode) {
12761277

12771278
func (g *JavaGen) genMethodInterfaceProxy(oName string, m *types.Func) {
12781279
if !g.isSigSupported(m.Type()) {
1279-
g.Printf("// skipped method %s with unsupported parameter or return types\n\n", oName)
1280+
g.warnf(m.Pos(), "skipped method %s with unsupported parameter or return types", oName)
12801281
return
12811282
}
12821283
sig := m.Type().(*types.Signature)
@@ -1345,7 +1346,7 @@ func (g *JavaGen) GenH() error {
13451346
g.Printf("\n")
13461347
for _, m := range iface.summary.callable {
13471348
if !g.isSigSupported(m.Type()) {
1348-
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
1349+
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name())
13491350
continue
13501351
}
13511352
g.genInterfaceMethodSignature(m, iface.obj.Name(), true, g.paramName)
@@ -1477,7 +1478,7 @@ func (g *JavaGen) GenC() error {
14771478
g.Printf("jmethodID proxy_class_%s_%s_cons;\n", g.pkgPrefix, iface.obj.Name())
14781479
for _, m := range iface.summary.callable {
14791480
if !g.isSigSupported(m.Type()) {
1480-
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
1481+
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name())
14811482
continue
14821483
}
14831484
g.Printf("static jmethodID mid_%s_%s;\n", iface.obj.Name(), m.Name())
@@ -1519,7 +1520,7 @@ func (g *JavaGen) GenC() error {
15191520
g.Printf("clazz = (*env)->FindClass(env, %q);\n", g.jniClassSigPrefix(pkg)+g.javaTypeName(iface.obj.Name()))
15201521
for _, m := range iface.summary.callable {
15211522
if !g.isSigSupported(m.Type()) {
1522-
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", iface.obj.Name(), m.Name())
1523+
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", iface.obj.Name(), m.Name())
15231524
continue
15241525
}
15251526
sig := m.Type().(*types.Signature)
@@ -1630,7 +1631,7 @@ func (g *JavaGen) GenJava() error {
16301631
}
16311632
for _, m := range iface.summary.callable {
16321633
if !g.isSigSupported(m.Type()) {
1633-
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", n, m.Name())
1634+
g.warnf(m.Pos(), "skipped method %s.%s with unsupported parameter or return types", n, m.Name())
16341635
continue
16351636
}
16361637
g.Printf("public native ")
@@ -1652,7 +1653,7 @@ func (g *JavaGen) GenJava() error {
16521653
}
16531654
for _, f := range g.funcs {
16541655
if !g.isSigSupported(f.Type()) {
1655-
g.Printf("// skipped function %s with unsupported parameter or return types\n\n", f.Name())
1656+
g.warnf(f.Pos(), "skipped function %s with unsupported parameter or return types", f.Name())
16561657
continue
16571658
}
16581659
g.javadoc(g.docs[f.Name()].Doc())
@@ -1669,6 +1670,14 @@ func (g *JavaGen) GenJava() error {
16691670
return nil
16701671
}
16711672

1673+
func (g *JavaGen) warnf(pos token.Pos, format string, args ...interface{}) {
1674+
if g.Reporter != nil {
1675+
fpos := g.Fset.Position(pos)
1676+
g.Reporter.Message(fmt.Sprintf(fpos.String()+": "+format, args...))
1677+
}
1678+
g.Printf("// "+format+"\n\n", args...)
1679+
}
1680+
16721681
// embeddedJavaClasses returns the possible empty list of Java types embedded
16731682
// in the given struct type.
16741683
func embeddedJavaClasses(t *types.Struct) []string {

0 commit comments

Comments
 (0)