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)
| 13 | // pyWrapOnly = only generate python wrapper code, not go code |
| 14 | // slob = official slice object -- for package-processed slices -- has methods |
| 15 | func (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 |
| 41 | class %[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 | |
| 62 | func (g *pyGen) genSliceInit(slc *symbol, extTypes, pyWrapOnly bool, slob *Slice) { |
| 63 | pkgname := slc.gopkg.Name() |
no test coverage detected