callable

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package callable provides a generic callable generator.

Index

Constants

This section is empty.

Variables

View Source
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

func AnyTypeName(typ gir.AnyType, or string) string

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

func CoalesceTail(tail string) string

CoalesceTail coalesces certain parameters with the same type to be shorter.

func Find

func Find(callables []Generator, goName string) int

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

func RenameGetter(name string) (string, bool)

RenameGetter renames a getter. True is returned if the name is changed.

func RenameGetters

func RenameGetters(parentName string, callables []Generator)

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

func Grow(callables []Generator, n int) []Generator

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) Header

func (g *Generator) Header() *file.Header

Header returns the generator's current headers.

func (*Generator) Logln

func (g *Generator) Logln(lvl logger.Level, v ...interface{})

func (*Generator) Recv

func (g *Generator) Recv() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL