gir

package
v0.0.0-...-387ad28 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: LGPL-2.1 Imports: 11 Imported by: 0

Documentation

Overview

Package gir provides a roughly-written gir generator.

Index

Constants

View Source
const (
	CommentsColumnLimit = 80 - 3 // account for prefix "// "
	CommentsTabWidth    = 4
)

Variables

This section is empty.

Functions

func CGoType

func CGoType(ctype string) (gotype string)

func CallbackExternCName

func CallbackExternCName(callbackName string) string

func CallbackGenAssign

func CallbackGenAssign(fnValue *jen.Statement) *jen.Statement

CallbackGenAssign generates a call to callback.Assign with the given fnValue.

func CallbackGenDelete

func CallbackGenDelete() *jen.Statement

func EmbeddedField

func EmbeddedField(goType string) string

func EmbeddedFieldCheck

func EmbeddedFieldCheck(goType, containsType string) bool

EmbeddedFieldCheck checks if the given goType embeds the required containsType.

func EmbeddedFieldNoPanic

func EmbeddedFieldNoPanic(goType string) string

func GenCasterInterface

func GenCasterInterface() *jen.Statement

GenCasterInterface generates the constant caster interface that helps conceal the underlying Widget.

func GenCommentReflowLines

func GenCommentReflowLines(prefix, cmt string) *jen.Statement

func GenCommentReflowLinesIndent

func GenCommentReflowLinesIndent(indentLvl uint, prefix, cmt string) *jen.Statement

func GenInterfaceWrapper

func GenInterfaceWrapper(ifaceGObjName string, widget bool) *jen.Statement

GenInterfaceWrappper generates the interface struct. This function assumes the object is named "obj".

func GenMarshalerFn

func GenMarshalerFn(typeName string, body *jen.Statement) *jen.Statement

GenMarshalerFn generates the marshal function's surroundings. The generated function would be named typeName prefixed by "marshal". The uintptr argument is named p.

func GenMarshalerFnName

func GenMarshalerFnName(typeName string) *jen.Statement

func GenMarshalerItem

func GenMarshalerItem(getType, typeName string) *jen.Statement

func InterfaceName

func InterfaceName(ifaceName string) string

InterfaceName turns glib interface naming conventions to Go.

func NewGotk3Generator

func NewGotk3Generator(name string) *jen.File

func ParseRepositoryFile

func ParseRepositoryFile(path string) error

func SetActiveNamespace

func SetActiveNamespace(i int) namespaceGenerator

SetActiveNamespace sets the active global namespace to generate from. This method is not thread safe. As such, only ONE namespace can be generated at a time.

func TypeMap

func TypeMap(typeName string) *jen.Statement

TypeMap maps the type to a Go type in Go code.

func ZeroByteCast

func ZeroByteCast(caller *jen.Statement) *jen.Statement

ZeroByteCast works around Go misdetecting C function pointers as (*[0]byte). Refer to https://github.com/golang/go/issues/19835.

Types

type Annotation

type Annotation struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 attribute"`
	Name    string   `xml:"name,attr"`
	Value   string   `xml:"value,attr"`
}

type Array

type Array struct {
	XMLName        xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 array"`
	Length         int      `xml:"http://www.gtk.org/introspection/core/1.0 length"`
	ZeroTerminated int      `xml:"http://www.gtk.org/introspection/core/1.0 zero-terminated"`

	CType string `xml:"http://www.gtk.org/introspection/c/1.0 type,attr"`

	Type Type `xml:"http://www.gtk.org/introspection/core/1.0 type"`
}

type CInclude

type CInclude struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/c/1.0 include"`
	Name    string   `xml:"name,attr"`
}

type CallableAttrs

type CallableAttrs struct {
	Name        string `xml:"name,attr"`
	CType       string `xml:"http://www.gtk.org/introspection/c/1.0 type,attr"`
	CIdentifier string `xml:"http://www.gtk.org/introspection/c/1.0 identifier,attr"`

	Deprecated        int    `xml:"deprecated,attr"`
	DeprecatedVersion string `xml:"deprecated-version,attr"`

	Parameters  *Parameters
	ReturnValue *ReturnValue `xml:"http://www.gtk.org/introspection/core/1.0 return-value"`
	Doc         *Doc
}

func (CallableAttrs) HasArrayParameter

func (c CallableAttrs) HasArrayParameter() bool

HasArrayParameter returns true if the function has an array as a parameter or return value.

func (CallableAttrs) HasInstanceParameter

func (c CallableAttrs) HasInstanceParameter() bool

func (CallableAttrs) IsBlocked

func (c CallableAttrs) IsBlocked() bool

IsBlocked returns true if the current function contains a blocked parameter type.

func (CallableAttrs) IsDeprecated

func (c CallableAttrs) IsDeprecated() bool

IsDeprecated returns true if the current object is deprecated.

func (CallableAttrs) IsIgnored

func (c CallableAttrs) IsIgnored() bool

func (CallableAttrs) IsVariadic

func (c CallableAttrs) IsVariadic() bool

IsVariadic returns true if the current function is variadic.

func (CallableAttrs) UserDataParameter

func (c CallableAttrs) UserDataParameter(i int) *Parameter

UserDataParameter returns a non-nil parameter if the given index points to a valid user data parameter.

type Callback

type Callback struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 callback"`
	CallableAttrs
}

func (Callback) ExternCName

func (c Callback) ExternCName() string

func (Callback) GenCGoFunc

func (c Callback) GenCGoFunc() *jen.Statement

GenCGoFunc generates the CGo function to be used in the arguments.

func (Callback) GenExternC

func (c Callback) GenExternC() string

func (Callback) GenGlobalGoFunction

func (c Callback) GenGlobalGoFunction() *jen.Statement

GenGlobalGoFunction generates a Go function with the export comment. This function is used to be called from C. It triggers the callback inside the map.

func (Callback) GenGoType

func (c Callback) GenGoType() *jen.Statement

func (Callback) GoName

func (c Callback) GoName() string

type Class

type Class struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 class"`
	Name    string   `xml:"name,attr"`

	CType         string `xml:"http://www.gtk.org/introspection/c/1.0 type,attr"`
	CSymbolPrefix string `xml:"http://www.gtk.org/introspection/c/1.0 symbol-prefix,attr"`

	Parent string `xml:"parent,attr"`

	GLibTypeName   string `xml:"http://www.gtk.org/introspection/glib/1.0 type-name,attr"`
	GLibGetType    string `xml:"http://www.gtk.org/introspection/glib/1.0 get-type,attr"`
	GLibTypeStruct string `xml:"http://www.gtk.org/introspection/glib/1.0 type-struct,attr"`

	Implements   []Implements  `xml:"http://www.gtk.org/introspection/core/1.0 implements"`
	Constructors []Constructor `xml:"http://www.gtk.org/introspection/core/1.0 constructor"`
	Methods      []Method      `xml:"http://www.gtk.org/introspection/core/1.0 method"`
	Fields       []Field       `xml:"http://www.gtk.org/introspection/core/1.0 field"`
}

func (Class) CGoType

func (c Class) CGoType() string

func (Class) FnWithC

func (c Class) FnWithC(CIdentifier string) interface{}

func (Class) GenConstructors

func (c Class) GenConstructors() *jen.Statement

func (Class) GenMarshaler

func (c Class) GenMarshaler() *jen.Statement

func (Class) GenMarshalerItem

func (c Class) GenMarshalerItem() *jen.Statement

func (Class) GenMethods

func (c Class) GenMethods() *jen.Statement

func (Class) GenNative

func (c Class) GenNative() *jen.Statement

func (Class) GenParentInstanceType

func (c Class) GenParentInstanceType() *jen.Statement

func (Class) GenType

func (c Class) GenType() *jen.Statement

func (Class) GenWrapper

func (c Class) GenWrapper() *jen.Statement

func (Class) GenerateAll

func (c Class) GenerateAll() *jen.Statement

func (Class) GoName

func (c Class) GoName() string

func (Class) ParentInstanceType

func (c Class) ParentInstanceType() string

func (Class) WrapperFnName

func (c Class) WrapperFnName() string

type Constructor

type Constructor struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 constructor"`
	CallableAttrs
}

func (Constructor) GenFunc

func (c Constructor) GenFunc(class Class) *jen.Statement

func (Constructor) GoName

func (c Constructor) GoName() string

func (Constructor) TypeName

func (c Constructor) TypeName() string

type Doc

type Doc struct {
	XMLName  xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 doc"`
	Filename string   `xml:"filename,attr"`
	Line     int      `xml:"line,attr"`
	String   string   `xml:",innerxml"`
}

func (Doc) GenComments

func (d Doc) GenComments() *jen.Statement

func (Doc) GenGoComments

func (d Doc) GenGoComments(selfName, prefix string) *jen.Statement

GenGoComments generates comments in idiomatic Go style. The given selfName replaces @self with the given receiver.

func (Doc) GenGoCommentsIndent

func (d Doc) GenGoCommentsIndent(indentLvl uint, selfName, prefix string) *jen.Statement

func (Doc) Lower

func (d Doc) Lower() string

Lower returns the comment with the first character lower-cased.

type Enum

type Enum struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 enumeration"`
	Name    string   `xml:"name,attr"` // Go case
	Version string   `xml:"version,attr"`

	Doc *Doc

	GLibTypeName string `xml:"http://www.gtk.org/introspection/glib/1.0 type-name,attr"`
	GLibGetType  string `xml:"http://www.gtk.org/introspection/glib/1.0 get-type,attr"`

	CType string `xml:"http://www.gtk.org/introspection/c/1.0 type,attr"`

	Members []Member `xml:"http://www.gtk.org/introspection/core/1.0 member"`
}

func (Enum) GenConsts

func (e Enum) GenConsts() *jen.Statement

func (Enum) GenMarshaler

func (e Enum) GenMarshaler() *jen.Statement

func (Enum) GenMarshalerItem

func (e Enum) GenMarshalerItem() *jen.Statement

func (Enum) GenType

func (e Enum) GenType() *jen.Statement

func (Enum) GenerateAll

func (e Enum) GenerateAll() *jen.Statement

func (Enum) GoName

func (e Enum) GoName() string

type Field

type Field struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 field"`
	Name    string   `xml:"name,attr"`
	Type    Type
	Doc     *Doc
}

func (*Field) GoName

func (f *Field) GoName() string

func (*Field) TypeName

func (f *Field) TypeName() (t string)

TypeName returns the type name or an empty string if Field is nil.

type Function

type Function struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 function"`
	CallableAttrs
}

func (Function) GenFunc

func (f Function) GenFunc() *jen.Statement

func (Function) GoName

func (f Function) GoName() string

type GoNamer

type GoNamer interface {
	GoName() string
}

GoNamer is the interface for structs that can output idiomatic Go type names.

type Implements

type Implements struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 implements"`
	Name    string   `xml:"name,attr"`
}

type Include

type Include struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 include"`
	Name    string   `xml:"name,attr"`
	Version *string  `xml:"version,attr"`
}

type InstanceParameter

type InstanceParameter struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 instance-parameter"`
	ParameterAttrs
}

type Interface

type Interface struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 interface"`
	Name    string   `xml:"name,attr"`

	CType         string `xml:"http://www.gtk.org/introspection/c/1.0 type,attr"`
	CSymbolPrefix string `xml:"http://www.gtk.org/introspection/c/1.0 symbol-prefix,attr"`

	GLibTypeName   string `xml:"http://www.gtk.org/introspection/glib/1.0 type-name,attr"`
	GLibGetType    string `xml:"http://www.gtk.org/introspection/glib/1.0 get-type,attr"`
	GLibTypeStruct string `xml:"http://www.gtk.org/introspection/glib/1.0 type-struct,attr"`

	Functions     []Function     `xml:"http://www.gtk.org/introspection/core/1.0 function"`
	Methods       []Method       `xml:"http://www.gtk.org/introspection/core/1.0 method"` // translated to Go fns
	Prerequisites []Prerequisite `xml:"http://www.gtk.org/introspection/core/1.0 prerequisite"`
}

func (Interface) CGoType

func (i Interface) CGoType() string

func (Interface) GenInterface

func (i Interface) GenInterface() *jen.Statement

func (Interface) GenMethods

func (i Interface) GenMethods() *jen.Statement

func (Interface) GenNative

func (i Interface) GenNative() *jen.Statement

func (Interface) GenType

func (i Interface) GenType() *jen.Statement

func (Interface) GenerateAll

func (i Interface) GenerateAll() *jen.Statement

func (Interface) GoName

func (i Interface) GoName() string

func (Interface) InterfaceName

func (i Interface) InterfaceName() string

InterfaceName generates an idiomatic Go interface name.

func (Interface) RequiresWidget

func (i Interface) RequiresWidget() bool

RequiresWidget returns true if the interface requires a widget.

type Member

type Member struct {
	XMLName     xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 member"`
	Name        string   `xml:"name,attr"`
	Value       int      `xml:"value,attr"`
	CIdentifier string   `xml:"http://www.gtk.org/introspection/c/1.0 identifer,attr"`

	Doc *Doc
}

func (Member) GoName

func (m Member) GoName() string

type Method

type Method struct {
	XMLName     xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 method"`
	Name        string   `xml:"name,attr"`
	CIdentifier string   `xml:"http://www.gtk.org/introspection/c/1.0 identifier,attr"`
	CallableAttrs
}

func (Method) GenFunc

func (m Method) GenFunc(parentType string) *jen.Statement

func (Method) GoName

func (m Method) GoName() string

type Namespace

type Namespace struct {
	XMLName            xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 namespace"`
	Version            string   `xml:"version,attr"`
	SharedLibrary      string   `xml:"shared-library,attr"`
	IdentifierPrefixes string   `xml:"http://www.gtk.org/introspection/c/1.0 identifier-prefixes,attr"`
	SymbolPrefixes     string   `xml:"http://www.gtk.org/introspection/c/1.0 symbol-prefixes,attr"`

	Classes     []Class      `xml:"http://www.gtk.org/introspection/core/1.0 class"`
	Enums       []Enum       `xml:"http://www.gtk.org/introspection/core/1.0 enumeration"`
	Functions   []Function   `xml:"http://www.gtk.org/introspection/core/1.0 function"`
	Callbacks   []Callback   `xml:"http://www.gtk.org/introspection/core/1.0 callback"`
	Interfaces  []Interface  `xml:"http://www.gtk.org/introspection/core/1.0 interface"`
	Annotations []Annotation `xml:"http://www.gtk.org/introspection/core/1.0 attribute"`
}

func Namespaces

func Namespaces() []Namespace

type Package

type Package struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 package"`
	Name    string   `xml:"name,attr"`
}

type Parameter

type Parameter struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 parameter"`
	ParameterAttrs
}

type ParameterAttrs

type ParameterAttrs struct {
	Name      string `xml:"name,attr"`
	AllowNone int    `xml:"allow-none,attr"` // 1 == true?
	TransferOwnership
	Type Type
	Doc  *Doc
}

func (ParameterAttrs) GenValueCall

func (p ParameterAttrs) GenValueCall(argName, valueName *jen.Statement) *jen.Statement

GenValueCall generates a value conversion call from the given names. If argName is nil, then the returned value will be a zero-value. Specifically for UserData, a callback should be passed in as an argument.

func (ParameterAttrs) GoName

func (p ParameterAttrs) GoName() string

func (ParameterAttrs) IsBlockedType

func (p ParameterAttrs) IsBlockedType() bool

IsBlockedType returns true if the parameter has a blocked type.

func (ParameterAttrs) IsDestroyNotifyFunc

func (p ParameterAttrs) IsDestroyNotifyFunc() bool

func (ParameterAttrs) IsIgnored

func (p ParameterAttrs) IsIgnored() bool

func (ParameterAttrs) IsNotNamespaceFunc

func (p ParameterAttrs) IsNotNamespaceFunc() bool

IsNotNamespaceFunc returns true if the parameter is a function and is not the current namespace's callback.

func (ParameterAttrs) IsUserData

func (p ParameterAttrs) IsUserData() bool

func (ParameterAttrs) IsUserDataFreeFunc

func (p ParameterAttrs) IsUserDataFreeFunc() bool

func (ParameterAttrs) IsVariadic

func (p ParameterAttrs) IsVariadic() bool

IsVariadic returns true if the current parameter is variadic.

type Parameters

type Parameters struct {
	XMLName           xml.Name           `xml:"http://www.gtk.org/introspection/core/1.0 parameters"`
	InstanceParameter *InstanceParameter `xml:"http://www.gtk.org/introspection/core/1.0 instance-parameter"`
	Parameters        []Parameter        `xml:"http://www.gtk.org/introspection/core/1.0 parameter"`
}

func (Parameters) HasBlockedType

func (p Parameters) HasBlockedType() bool

HasBlockedType returns if the list of parameters contain a parameter of blocked types.

func (*Parameters) HasInstanceParameter

func (p *Parameters) HasInstanceParameter() bool

HasInstanceParameter returns true if p and InstanceParameter are not nil.

func (Parameters) IsVariadic

func (p Parameters) IsVariadic() bool

IsVariadic returns if the list of parameters contain a variadic parameter.

func (*Parameters) SearchUserData

func (p *Parameters) SearchUserData() *Parameter

SearchUserData searches for the UserData parameter. It returns nil if p is nil or if userData is not in the list of parameters.

type Prerequisite

type Prerequisite struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 prerequisite"`
	Name    string   `xml:"name,attr"`
}

type ReturnValue

type ReturnValue struct {
	XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 return-value"`
	TransferOwnership
	Doc *Doc

	// Possible enums.
	Type  *Type
	Array *Array
}

func (*ReturnValue) GenReturnFunc

func (r *ReturnValue) GenReturnFunc(call *jen.Statement) *jen.Statement

GenReturn generates a statement with the return token.

func (*ReturnValue) IsVoid

func (r *ReturnValue) IsVoid() bool

IsVoid returns true if the type name is "none" or if *ReturnValue is nil.

type TransferOwnership

type TransferOwnership struct {
	TransferOwnership *string `xml:"transfer-ownership,attr"`
}

type Type

type Type struct {
	XMLName        xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 type"`
	Name           string   `xml:"name,attr"`
	CType          string   `xml:"http://www.gtk.org/introspection/c/1.0 type,attr"`
	Introspectable *bool    `xml:"introspectable,attr"`
}

func (Type) CGoType

func (t Type) CGoType() string

CGoType returns the C type in CGo.

func (Type) CNeedsFree

func (t Type) CNeedsFree() bool

CNeedsFree returns true if the generated value from GenCCaster needs freeing. Pay attention to transfer-ownership when doing this.

func (Type) GenCCaster

func (t Type) GenCCaster(value *jen.Statement) *jen.Statement

GenCCaster generates a function or type cast to convert Go values to C.

func (Type) GenCGoType

func (t Type) GenCGoType() *jen.Statement

func (Type) GenCaster

func (t Type) GenCaster(tmpVar, value *jen.Statement) *jen.Statement

GenCaster generates the type or function to be used to cast or convert C to Go types.

func (Type) GoType

func (t Type) GoType() string

GoType returns the type in Go.

func (Type) IsConst

func (t Type) IsConst() bool

func (Type) IsEnum

func (t Type) IsEnum() bool

func (Type) IsFunc

func (t Type) IsFunc() bool

IsFunc returns true if the given type is a callback.

func (Type) IsInterface

func (t Type) IsInterface() bool

func (Type) IsNamespaceFunc

func (t Type) IsNamespaceFunc() bool

IsNamespaceFunc returns true if the current type is a callback that belongs to the current namespace.

func (Type) IsPtr

func (t Type) IsPtr() bool

func (Type) Map

func (t Type) Map() *jen.Statement

Map maps the type from C to a Go type in Go code.

func (Type) Type

func (t Type) Type() *jen.Statement

Type returns the generated Go type in Go code.

func (Type) TypeParam

func (t Type) TypeParam() *jen.Statement

TypeParam returns a type specifically used for interface

func (Type) ZeroValue

func (t Type) ZeroValue() *jen.Statement

Jump to

Keyboard shortcuts

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