typeconv

package
v0.0.0-...-aefa52a Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package typeconv provides conversions between C and Go types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConversionDirection

type ConversionDirection uint8

ConversionDirection is the conversion direction between Go and C.

const (
	ConvertGoToC ConversionDirection
	ConvertCToGo
)

type ConversionProcessFunc

type ConversionProcessFunc func(conv *Converter)

ConversionProcessFunc is a function that satisfies the ConversionProcessor interface.

func (ConversionProcessFunc) ProcessConverter

func (f ConversionProcessFunc) ProcessConverter(conv *Converter)

Process calls f.

type ConversionProcessor

type ConversionProcessor interface {
	ProcessConverter(conv *Converter)
}

ConversionProcessor is a processor that can override an entire converter.

func ProcessCallback

func ProcessCallback(girType string, f func(conv *Converter)) ConversionProcessor

ProcessCallback creates a new conversion processor that calls f on every callback type matching the given girType. The GIR type is matched absolutely.

type ConversionValue

type ConversionValue struct {
	gir.ParameterAttrs

	InName  string
	OutName string

	// Direction is the direction of conversion.
	Direction ConversionDirection

	// ParameterIndex explicitly gives this value an index used for matching
	// with the given index clues from the GIR files, such as closure, destroy
	// or length.
	ParameterIndex ConversionValueIndex

	// KeepType overrides the abstract type if true.
	KeepType bool

	// InContainer, if true, will increment the C type pointer by 1 to indicate
	// that the type is stored indirectly as a pointer in a container. A
	// container has to be a <type> wrapped inside another <type>.
	InContainer bool
}

ConversionValue describes the generic properties of a Go or C value for conversion.

func NewFieldSetValue

func NewFieldSetValue(in, out string, field gir.Field) ConversionValue

NewFieldSetValue creates a new ConversionValue from the given C struct field that converts a Go to C type.

func NewFieldValue

func NewFieldValue(in, out string, field gir.Field) ConversionValue

NewFieldValue creates a new ConversionValue from the given C struct field. The struct is assumed to have a native field.

func NewReceiverValue

func NewReceiverValue(
	in, out string, dir ConversionDirection, param *gir.InstanceParameter) ConversionValue

NewReceiverValue creates a new ConversionValue specifically for the method receiver.

func NewReturnValue

func NewReturnValue(in, out string, dir ConversionDirection, ret gir.ReturnValue) ConversionValue

NewReturnValue creates a new ConversionValue from the given return attribute.

func NewThrowValue

func NewThrowValue(in, out string) ConversionValue

NewThrowValue creates a new GError value. Thrown values are always assumed to be conversions from C to Go. Errors should ALWAYS go AFTER the return!

func NewValue

func NewValue(
	in, out string, i int, dir ConversionDirection, param gir.Parameter) ConversionValue

NewValue creates a new ConversionValue from the given parameter attributes.

func (*ConversionValue) IsOptional

func (value *ConversionValue) IsOptional() bool

IsOptional returns true if either Optional or Nullable is true.

func (*ConversionValue) IsZero

func (value *ConversionValue) IsZero() bool

IsZero returns true if ConversionValue is empty.

func (*ConversionValue) ParameterIsOutput

func (value *ConversionValue) ParameterIsOutput() bool

ParameterIsOutput returns true if the direction is out.

func (*ConversionValue) ParameterIsReturn

func (value *ConversionValue) ParameterIsReturn() bool

ParameterIsReturn returns true if the direction is out or if the parameter is a return value.

type ConversionValueIndex

type ConversionValueIndex int8

ConversionValueIndex describes an overloaded index type that reserves its negative values for special values.

const (
	UnknownValueIndex ConversionValueIndex
	ReceiverValueIndex
	ErrorValueIndex
	ReturnValueIndex
)

func (ConversionValueIndex) Index

func (ix ConversionValueIndex) Index() int

Index returns the actual underlying index if any, or it returns -1.

func (ConversionValueIndex) Is

func (ix ConversionValueIndex) Is(at int) bool

Is checks that the index matches. This method should be used as it guarantees that the given index isn't special.

type Converter

type Converter struct {
	Parent   *gir.TypeFindResult
	Results  []ValueConverted
	Callback bool
	// MustCast, if true, will force the converter to generate code that
	// force-casts InName and OutName to the right type.
	MustCast bool
	// contains filtered or unexported fields
}

func NewConverter

func NewConverter(
	fgen types.FileGenerator, parent *gir.TypeFindResult, values []ConversionValue) *Converter

NewConverter creates a new type converter from the given file generator. The converter will add no side effects to the given file generator.

func (*Converter) CCallParams

func (conv *Converter) CCallParams() []string

CCallParams generates the call parameters for calling the C function.

func (*Converter) Convert

func (conv *Converter) Convert(i int) *ValueConverted

Convert converts the value at the given index.

func (*Converter) ConvertAll

func (conv *Converter) ConvertAll() []ValueConverted

ConvertAll converts all values.

func (*Converter) Header

func (conv *Converter) Header() *file.Header

Header returns the header of all converted values. This method should only be used once ConvertAll or Convert has been called.

func (*Converter) Logln

func (conv *Converter) Logln(lvl logger.Level, v ...interface{})

func (*Converter) UseLogger

func (conv *Converter) UseLogger(logger logger.LineLogger)

UseLogger sets the logger to be used instead of the given NamespaceGenrator.

type ValueConverted

type ValueConverted struct {
	*ConversionValue // original

	In  ValueName
	Out ValueName

	Conversion string

	// internal states
	ValueType
	Inner []ValueType
	// contains filtered or unexported fields
}

ValueConverted is the result of conversion for a single value.

Quick convention note:

  • {In,Out}Name is for the original name with no modifications.
  • {In,Out}Call is used for the C or Go function arguments.

Usually, these are the same, but they're sometimes different depending on the edge case.

func (*ValueConverted) Header

func (value *ValueConverted) Header() *file.Header

Header returns the header of the current value.

func (*ValueConverted) InNPtr

func (value *ValueConverted) InNPtr() int

func (*ValueConverted) InNamePtr

func (value *ValueConverted) InNamePtr(want int) string

InNamePtr returns the name with the pointer prefixed using InPtr.

func (*ValueConverted) InNamePtrPubl

func (value *ValueConverted) InNamePtrPubl(want int) string

InNamePtrPubl adds in an edge case if the value being inputted is possibly a Go interface.

func (*ValueConverted) InPtr

func (value *ValueConverted) InPtr(want int) string

func (*ValueConverted) Logln

func (value *ValueConverted) Logln(lvl logger.Level, v ...interface{})

func (*ValueConverted) MustRealloc

func (value *ValueConverted) MustRealloc() bool

MustRealloc returns true if we need to malloc our values to give it to C. Generally, if a conversion routine has a no-alloc path, it should check MustRealloc first. If MustRealloc is true, then it must check ShouldFree.

if value.MustAlloc() {
    v = &oldValue
} else {
    v = malloc()
    if value.ShouldFree() {
        defer free(v)
    }
}

func (*ValueConverted) OutCast

func (value *ValueConverted) OutCast(want int) string

OutCast returns the left-hand side consisting of the pointer dereference and the pointer-prefixed type.

func (*ValueConverted) OutInNamePtr

func (value *ValueConverted) OutInNamePtr(want int) string

OutInNamePtr is like InNamePtr but for OutInPtr.

func (*ValueConverted) OutInPtr

func (value *ValueConverted) OutInPtr(want int) string

OutInPtr returns the left-hand side for the output name and type SPECIFICALLY for inputting the output name elsewhere, like giving it to SetFinalizer.

func (*ValueConverted) OutNPtr

func (value *ValueConverted) OutNPtr() int

func (*ValueConverted) OutPtr

func (value *ValueConverted) OutPtr(want int) string

func (*ValueConverted) ShouldFree

func (value *ValueConverted) ShouldFree() bool

ShouldFree returns true if the C value must be freed once we're done.

type ValueName

type ValueName struct {
	Name    string
	Call    string
	Set     string
	Type    string
	Declare string
}

ValueName contains the different names to use during and after conversion.

type ValueType

type ValueType struct {
	Resolved       *types.Resolved // only for type conversions
	GoType         string
	IsPublic       bool
	NeedsNamespace bool
}

ValueType contains the type information for one value.

func (*ValueType) Import

func (vt *ValueType) Import(gen types.FileGenerator, h *file.Header, public bool)

Jump to

Keyboard shortcuts

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