MCPcopy Create free account
hub / github.com/go-python/gopy / genSlice

Method genSlice

bind/gen_slice.go:15–60  ·  view source on GitHub ↗

extTypes = these are types external to any targeted packages pyWrapOnly = only generate python wrapper code, not go code slob = official slice object -- for package-processed slices -- has methods

(slc *symbol, extTypes, pyWrapOnly bool, slob *Slice)

Source from the content-addressed store, hash-verified

13// pyWrapOnly = only generate python wrapper code, not go code
14// slob = official slice object -- for package-processed slices -- has methods
15func (g *pyGen) genSlice(slc *symbol, extTypes, pyWrapOnly bool, slob *Slice) {
16 if slc.isPointer() {
17 return // TODO: not sure what to do..
18 }
19 _, isslc := slc.GoType().Underlying().(*types.Slice)
20 _, isary := slc.GoType().Underlying().(*types.Array)
21 if !isslc && !isary {
22 return
23 }
24
25 pkgname := slc.gopkg.Name()
26
27 pysnm := slc.id
28 if !strings.Contains(pysnm, "Slice_") {
29 pysnm = strings.TrimPrefix(pysnm, pkgname+"_")
30 }
31
32 gocl := "go."
33 if g.pkg == goPackage {
34 gocl = ""
35 }
36
37 if !extTypes || pyWrapOnly {
38 // TODO: inherit from collections.Iterable too?
39 g.pywrap.Printf(`
40# Python type for slice %[4]s
41class %[2]s(%[5]sGoClass):
42 ""%[3]q""
43`,
44 pkgname,
45 pysnm,
46 slc.doc,
47 slc.goname,
48 gocl,
49 )
50 g.pywrap.Indent()
51 }
52
53 g.genSliceInit(slc, extTypes, pyWrapOnly, slob)
54 if slob != nil {
55 g.genSliceMethods(slob)
56 }
57 if !extTypes || pyWrapOnly {
58 g.pywrap.Outdent()
59 }
60}
61
62func (g *pyGen) genSliceInit(slc *symbol, extTypes, pyWrapOnly bool, slob *Slice) {
63 pkgname := slc.gopkg.Name()

Callers 2

genTypeMethod · 0.95
genAllMethod · 0.95

Calls 8

genSliceInitMethod · 0.95
genSliceMethodsMethod · 0.95
isPointerMethod · 0.80
PrintfMethod · 0.80
IndentMethod · 0.80
OutdentMethod · 0.80
GoTypeMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected