mobile/bind: replace panics with errors

cgoType panics on types not yet supported by bind. Replace the panics
with more appropriate error messages.

Change-Id: I0b8609b50de07ca93db13c50654f62ffbd9f25c2
Reviewed-on: https://go-review.googlesource.com/20472
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Elias Naur 2016-03-09 14:37:44 +01:00
parent 2e1e39e5a6
commit 0d3fdd1e30
1 changed files with 6 additions and 5 deletions

View File

@ -159,7 +159,7 @@ func (g *generator) cgoType(t types.Type) string {
case types.String: case types.String:
return "nstring" return "nstring"
default: default:
panic(fmt.Sprintf("unsupported basic type: %s", t)) g.errorf("unsupported basic type: %s", t)
} }
case *types.Slice: case *types.Slice:
switch e := t.Elem().(type) { switch e := t.Elem().(type) {
@ -168,21 +168,22 @@ func (g *generator) cgoType(t types.Type) string {
case types.Uint8: // Byte. case types.Uint8: // Byte.
return "nbyteslice" return "nbyteslice"
default: default:
panic(fmt.Sprintf("unsupported slice type: %s", t)) g.errorf("unsupported slice type: %s", t)
} }
default: default:
panic(fmt.Sprintf("unsupported slice type: %s", t)) g.errorf("unsupported slice type: %s", t)
} }
case *types.Pointer: case *types.Pointer:
if _, ok := t.Elem().(*types.Named); ok { if _, ok := t.Elem().(*types.Named); ok {
return g.cgoType(t.Elem()) return g.cgoType(t.Elem())
} }
panic(fmt.Sprintf("unsupported pointer to type: %s", t)) g.errorf("unsupported pointer to type: %s", t)
case *types.Named: case *types.Named:
return "int32_t" return "int32_t"
default: default:
panic(fmt.Sprintf("unsupported type: %s", t)) g.errorf("unsupported type: %s", t)
} }
return "TODO"
} }
func (g *generator) genInterfaceMethodSignature(m *types.Func, iName string, header bool) { func (g *generator) genInterfaceMethodSignature(m *types.Func, iName string, header bool) {