Documentation
¶
Overview ¶
Package callable provides a generic callable generator.
Index ¶
- Variables
- func AnyTypeName(typ gir.AnyType, or string) string
- func CallablePreamble(g *Generator, sect *pen.BlockSection) (string, bool)
- func CoalesceTail(tail string) string
- func Find(callables []Generator, goName string) int
- func FindContextResult(g FileGenerator, result []typeconv.ValueConverted) int
- func MoveContextResult(g FileGenerator, result []typeconv.ValueConverted) bool
- func RenameGetter(name string) (string, bool)
- func RenameGetters(parentName string, callables []Generator)
- func ReturnName(attrs *gir.CallableAttrs) string
- type FileGenerator
- type Generator
- func (g *Generator) CoalesceTail()
- func (g *Generator) EachParamResult(f func(*typeconv.ValueConverted))
- func (g *Generator) EachReturnResult(f func(*typeconv.ValueConverted))
- func (g *Generator) FileGenerator() FileGenerator
- func (g *Generator) Header() *file.Header
- func (g *Generator) Logln(lvl logger.Level, v ...interface{})
- func (g *Generator) Recv() string
- func (g *Generator) Reset()
- func (g *Generator) Use(typ *gir.TypeFindResult, call *gir.CallableAttrs) bool
- func (g *Generator) UseConstructor(typ *gir.TypeFindResult, call *gir.CallableAttrs) bool
Constants ¶
This section is empty.
Variables ¶
var IgnoredNames = []string{
"ref",
"unref",
"free",
}
IgnoredNames is a list of method names that would be ignored. For more information, see typeconv/c-go.go.
Functions ¶
func AnyTypeName ¶
AnyTypeName returns the name from the given AnyType, or the given string if the type does not have a name.
func CallablePreamble ¶ added in v0.0.5
func CallablePreamble(g *Generator, sect *pen.BlockSection) (string, bool)
CallablePreamble returns CIdentifier or fails.
func CoalesceTail ¶ added in v0.0.2
CoalesceTail coalesces certain parameters with the same type to be shorter.
func Find ¶
Find finds a callable with the given Go name. The index within the slice is returned, or if nothing is found, then -1 is returned.
func FindContextResult ¶ added in v0.0.3
func FindContextResult(g FileGenerator, result []typeconv.ValueConverted) int
FindContextResult finds the context.Context type from the given list of callable results, but only if the list has one instance. -1 is returned otherwise.
func MoveContextResult ¶ added in v0.0.3
func MoveContextResult(g FileGenerator, result []typeconv.ValueConverted) bool
MoveContextResult moves the context variable. True is returned if the variable is found and moved.
func RenameGetter ¶
RenameGetter renames a getter. True is returned if the name is changed.
func RenameGetters ¶
RenameGetters renames the given list of callables to have idiomatic Go getter names.
func ReturnName ¶
func ReturnName(attrs *gir.CallableAttrs) string
Types ¶
type FileGenerator ¶
type FileGenerator interface { types.FileGenerator }
FileGenerator describes the interface of a file generator.
type Generator ¶
type Generator struct { *gir.CallableAttrs Name string Tail string Block string Converts []string Preamble func(g *Generator, sect *pen.BlockSection) (call string, ok bool) ExtraArgs [2][]string // {front, back} Conv *typeconv.Converter Results []typeconv.ValueConverted GoArgs pen.Joints GoRets pen.Joints ParamDocs []cmt.ParamDoc ReturnDocs []cmt.ParamDoc // contains filtered or unexported fields }
Generator is a generator instance that generates a GIR callable.
func Grow ¶
Grow grows or shrinks the callables slice to the given length. The returned slice will have a length of 0.
func NewGenerator ¶
func NewGenerator(gen FileGenerator) Generator
NewGenerator creates a new callable generator from the given generator.
func (*Generator) CoalesceTail ¶ added in v0.0.2
func (g *Generator) CoalesceTail()
CoalesceTail calls CoalesceTail on the generator's tail.
func (*Generator) EachParamResult ¶ added in v0.0.2
func (g *Generator) EachParamResult(f func(*typeconv.ValueConverted))
EachParamResult iterates over the list of Go function parameters.
func (*Generator) EachReturnResult ¶ added in v0.0.3
func (g *Generator) EachReturnResult(f func(*typeconv.ValueConverted))
EachReturnResult iterates over the list of Go function returns. Note that the direction is flipped if this is for a callback.
func (*Generator) FileGenerator ¶
func (g *Generator) FileGenerator() FileGenerator
FileGenerator returns the generator's internal file generator.
func (*Generator) Recv ¶
Recv returns the receiver variable name. This method should only be called for methods.
func (*Generator) Reset ¶
func (g *Generator) Reset()
Reset resets the state of the generator while reusing the backing pen.
func (*Generator) Use ¶
func (g *Generator) Use(typ *gir.TypeFindResult, call *gir.CallableAttrs) bool
Use uses the given CallableAttrs for the generator.
func (*Generator) UseConstructor ¶
func (g *Generator) UseConstructor(typ *gir.TypeFindResult, call *gir.CallableAttrs) bool
UseConstructor calls Use with the constructor flag.