From 216a45e7c33bcb428be3cc0f9d03f56a9e2197e1 Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Tue, 11 Aug 2015 17:35:18 +0200 Subject: [PATCH] bind: collect methods of all named types into symtab Change-Id: Ia8f8ed3f7b68a06fe09945d795403e3f10e69285 --- bind/symtab.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bind/symtab.go b/bind/symtab.go index 3c66ce8..850f09d 100644 --- a/bind/symtab.go +++ b/bind/symtab.go @@ -389,6 +389,19 @@ func (sym *symtab) addType(obj types.Object, t types.Type) { panic(fmt.Errorf("unhandled named-type: [%T]\n%#v\n", obj, t)) } + // add methods + for i := 0; i < typ.NumMethods(); i++ { + m := typ.Method(i) + if !m.Exported() { + continue + } + if true { + mid := id + "_" + m.Name() + mname := m.Name() + sym.addMethod(pkg, m, m.Type(), skFunc, mid, mname) + } + } + case *types.Pointer: // FIXME(sbinet): better handling? elm := *sym.symtype(typ.Elem()) @@ -529,6 +542,21 @@ func (sym *symtab) addSignatureType(pkg *types.Package, obj types.Object, t type } } +func (sym *symtab) addMethod(pkg *types.Package, obj types.Object, t types.Type, kind symkind, id, n string) { + fn := types.ObjectString(obj, nil) + kind |= skFunc + sym.syms[fn] = &symbol{ + gopkg: pkg, + goobj: obj, + gotyp: t, + kind: kind, + id: id, + goname: n, + cgoname: "cgo_func_" + id, + cpyname: "cpy_func_" + id, + } +} + func init() { look := types.Universe.Lookup