2019-02-11 10:47:24 +00:00
|
|
|
// Copyright 2019 The go-python 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 bind
|
|
|
|
|
|
|
|
func (g *pybindGen) genType(sym *symbol) {
|
|
|
|
if !sym.isType() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if sym.isBasic() && !sym.isNamed() {
|
|
|
|
return
|
|
|
|
}
|
2019-02-13 21:13:10 +00:00
|
|
|
|
|
|
|
// todo: not handling yet:
|
|
|
|
if sym.isSignature() {
|
2019-02-13 08:02:26 +00:00
|
|
|
return
|
|
|
|
}
|
2019-02-11 10:47:24 +00:00
|
|
|
|
|
|
|
if sym.isPointer() {
|
2019-02-13 08:02:26 +00:00
|
|
|
g.genTypeHandlePtr(sym)
|
|
|
|
} else {
|
|
|
|
g.genTypeHandle(sym)
|
2019-02-11 10:47:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 08:02:26 +00:00
|
|
|
func (g *pybindGen) genTypeHandlePtr(sym *symbol) {
|
2019-02-13 05:53:20 +00:00
|
|
|
g.gofile.Printf("\n// Converters for pointer handles for type: %s\n", sym.gofmt())
|
2019-02-14 08:39:40 +00:00
|
|
|
g.gofile.Printf("func %s(h CGoHandle) %s {\n", sym.py2go, sym.gofmt())
|
2019-02-11 10:47:24 +00:00
|
|
|
g.gofile.Indent()
|
2019-02-13 05:53:20 +00:00
|
|
|
g.gofile.Printf("p := varHand.varFmHandle(h, %[1]q)\n", sym.gofmt())
|
|
|
|
g.gofile.Printf("if p == nil {\n")
|
|
|
|
g.gofile.Indent()
|
|
|
|
g.gofile.Printf("return nil\n")
|
|
|
|
g.gofile.Outdent()
|
|
|
|
g.gofile.Printf("}\n")
|
2019-02-13 08:02:26 +00:00
|
|
|
g.gofile.Printf("return p.(%[1]s)\n", sym.gofmt())
|
|
|
|
g.gofile.Outdent()
|
|
|
|
g.gofile.Printf("}\n")
|
2019-02-14 08:39:40 +00:00
|
|
|
g.gofile.Printf("func %s(p interface{}) CGoHandle {\n", sym.go2py)
|
2019-02-13 08:02:26 +00:00
|
|
|
g.gofile.Indent()
|
|
|
|
g.gofile.Printf("return varHand.register(\"%s\", p)\n", sym.gofmt())
|
|
|
|
g.gofile.Outdent()
|
|
|
|
g.gofile.Printf("}\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *pybindGen) genTypeHandle(sym *symbol) {
|
|
|
|
ptrnm := "*" + sym.gofmt()
|
|
|
|
g.gofile.Printf("\n// Converters for pointer handles for type: %s\n", sym.gofmt())
|
2019-02-14 08:39:40 +00:00
|
|
|
g.gofile.Printf("func %s(h CGoHandle) %s {\n", sym.py2go, ptrnm)
|
2019-02-13 08:02:26 +00:00
|
|
|
g.gofile.Indent()
|
|
|
|
g.gofile.Printf("p := varHand.varFmHandle(h, %[1]q)\n", sym.gofmt())
|
|
|
|
g.gofile.Printf("if p == nil {\n")
|
|
|
|
g.gofile.Indent()
|
|
|
|
g.gofile.Printf("return nil\n")
|
|
|
|
g.gofile.Outdent()
|
|
|
|
g.gofile.Printf("}\n")
|
|
|
|
g.gofile.Printf("return p.(%[1]s)\n", ptrnm)
|
2019-02-11 10:47:24 +00:00
|
|
|
g.gofile.Outdent()
|
|
|
|
g.gofile.Printf("}\n")
|
2019-02-14 08:39:40 +00:00
|
|
|
g.gofile.Printf("func %s(p interface{}) CGoHandle {\n", sym.go2py)
|
2019-02-11 10:47:24 +00:00
|
|
|
g.gofile.Indent()
|
2019-02-13 05:53:20 +00:00
|
|
|
g.gofile.Printf("return varHand.register(\"%s\", p)\n", sym.gofmt())
|
2019-02-11 10:47:24 +00:00
|
|
|
g.gofile.Outdent()
|
|
|
|
g.gofile.Printf("}\n")
|
|
|
|
}
|