Documentation ¶
Overview ¶
Package gir provides a roughly-written gir generator.
Index ¶
- Constants
- func CGoType(ctype string) (gotype string)
- func CallbackExternCName(callbackName string) string
- func CallbackGenAssign(fnValue *jen.Statement) *jen.Statement
- func CallbackGenDelete() *jen.Statement
- func EmbeddedField(goType string) string
- func EmbeddedFieldCheck(goType, containsType string) bool
- func EmbeddedFieldNoPanic(goType string) string
- func GenCasterInterface() *jen.Statement
- func GenCommentReflowLines(prefix, cmt string) *jen.Statement
- func GenCommentReflowLinesIndent(indentLvl uint, prefix, cmt string) *jen.Statement
- func GenInterfaceWrapper(ifaceGObjName string, widget bool) *jen.Statement
- func GenMarshalerFn(typeName string, body *jen.Statement) *jen.Statement
- func GenMarshalerFnName(typeName string) *jen.Statement
- func GenMarshalerItem(getType, typeName string) *jen.Statement
- func InterfaceName(ifaceName string) string
- func NewGotk3Generator(name string) *jen.File
- func ParseRepositoryFile(path string) error
- func SetActiveNamespace(i int) namespaceGenerator
- func TypeMap(typeName string) *jen.Statement
- func ZeroByteCast(caller *jen.Statement) *jen.Statement
- type Annotation
- type Array
- type CInclude
- type CallableAttrs
- func (c CallableAttrs) HasArrayParameter() bool
- func (c CallableAttrs) HasInstanceParameter() bool
- func (c CallableAttrs) IsBlocked() bool
- func (c CallableAttrs) IsDeprecated() bool
- func (c CallableAttrs) IsIgnored() bool
- func (c CallableAttrs) IsVariadic() bool
- func (c CallableAttrs) UserDataParameter(i int) *Parameter
- type Callback
- type Class
- func (c Class) CGoType() string
- func (c Class) FnWithC(CIdentifier string) interface{}
- func (c Class) GenConstructors() *jen.Statement
- func (c Class) GenMarshaler() *jen.Statement
- func (c Class) GenMarshalerItem() *jen.Statement
- func (c Class) GenMethods() *jen.Statement
- func (c Class) GenNative() *jen.Statement
- func (c Class) GenParentInstanceType() *jen.Statement
- func (c Class) GenType() *jen.Statement
- func (c Class) GenWrapper() *jen.Statement
- func (c Class) GenerateAll() *jen.Statement
- func (c Class) GoName() string
- func (c Class) ParentInstanceType() string
- func (c Class) WrapperFnName() string
- type Constructor
- type Doc
- type Enum
- type Field
- type Function
- type GoNamer
- type Implements
- type Include
- type InstanceParameter
- type Interface
- func (i Interface) CGoType() string
- func (i Interface) GenInterface() *jen.Statement
- func (i Interface) GenMethods() *jen.Statement
- func (i Interface) GenNative() *jen.Statement
- func (i Interface) GenType() *jen.Statement
- func (i Interface) GenerateAll() *jen.Statement
- func (i Interface) GoName() string
- func (i Interface) InterfaceName() string
- func (i Interface) RequiresWidget() bool
- type Member
- type Method
- type Namespace
- type Package
- type Parameter
- type ParameterAttrs
- func (p ParameterAttrs) GenValueCall(argName, valueName *jen.Statement) *jen.Statement
- func (p ParameterAttrs) GoName() string
- func (p ParameterAttrs) IsBlockedType() bool
- func (p ParameterAttrs) IsDestroyNotifyFunc() bool
- func (p ParameterAttrs) IsIgnored() bool
- func (p ParameterAttrs) IsNotNamespaceFunc() bool
- func (p ParameterAttrs) IsUserData() bool
- func (p ParameterAttrs) IsUserDataFreeFunc() bool
- func (p ParameterAttrs) IsVariadic() bool
- type Parameters
- type Prerequisite
- type ReturnValue
- type TransferOwnership
- type Type
- func (t Type) CGoType() string
- func (t Type) CNeedsFree() bool
- func (t Type) GenCCaster(value *jen.Statement) *jen.Statement
- func (t Type) GenCGoType() *jen.Statement
- func (t Type) GenCaster(tmpVar, value *jen.Statement) *jen.Statement
- func (t Type) GoType() string
- func (t Type) IsConst() bool
- func (t Type) IsEnum() bool
- func (t Type) IsFunc() bool
- func (t Type) IsInterface() bool
- func (t Type) IsNamespaceFunc() bool
- func (t Type) IsPtr() bool
- func (t Type) Map() *jen.Statement
- func (t Type) Type() *jen.Statement
- func (t Type) TypeParam() *jen.Statement
- func (t Type) ZeroValue() *jen.Statement
Constants ¶
const ( CommentsColumnLimit = 80 - 3 // account for prefix "// " CommentsTabWidth = 4 )
Variables ¶
This section is empty.
Functions ¶
func CallbackExternCName ¶
func CallbackGenAssign ¶
CallbackGenAssign generates a call to callback.Assign with the given fnValue.
func CallbackGenDelete ¶
func EmbeddedField ¶
func EmbeddedFieldCheck ¶
EmbeddedFieldCheck checks if the given goType embeds the required containsType.
func EmbeddedFieldNoPanic ¶
func GenCasterInterface ¶
GenCasterInterface generates the constant caster interface that helps conceal the underlying Widget.
func GenCommentReflowLines ¶
func GenInterfaceWrapper ¶
GenInterfaceWrappper generates the interface struct. This function assumes the object is named "obj".
func GenMarshalerFn ¶
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 GenMarshalerItem ¶
func InterfaceName ¶
InterfaceName turns glib interface naming conventions to Go.
func NewGotk3Generator ¶
func ParseRepositoryFile ¶
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 ZeroByteCast ¶
ZeroByteCast works around Go misdetecting C function pointers as (*[0]byte). Refer to https://github.com/golang/go/issues/19835.
Types ¶
type Annotation ¶
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 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 (Callback) GenCGoFunc ¶
GenCGoFunc generates the CGo function to be used in the arguments.
func (Callback) GenExternC ¶
func (Callback) GenGlobalGoFunction ¶
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.
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) GenConstructors ¶
func (Class) GenMarshaler ¶
func (Class) GenMarshalerItem ¶
func (Class) GenMethods ¶
func (Class) GenParentInstanceType ¶
func (Class) GenWrapper ¶
func (Class) GenerateAll ¶
func (Class) ParentInstanceType ¶
func (Class) WrapperFnName ¶
type Constructor ¶
type Constructor struct { XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 constructor"` CallableAttrs }
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 (Doc) GenGoComments ¶
GenGoComments generates comments in idiomatic Go style. The given selfName replaces @self with the given receiver.
func (Doc) GenGoCommentsIndent ¶
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) GenMarshaler ¶
func (Enum) GenMarshalerItem ¶
func (Enum) GenerateAll ¶
type Field ¶
type Function ¶
type Function struct { XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 function"` CallableAttrs }
type GoNamer ¶
type GoNamer interface {
GoName() string
}
GoNamer is the interface for structs that can output idiomatic Go type names.
type Implements ¶
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) GenInterface ¶
func (Interface) GenMethods ¶
func (Interface) GenerateAll ¶
func (Interface) InterfaceName ¶
InterfaceName generates an idiomatic Go interface name.
func (Interface) RequiresWidget ¶
RequiresWidget returns true if the interface requires a widget.
type Member ¶
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 }
type Namespace ¶
type Namespace struct { XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 namespace"` Version string `xml:"version,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 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 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) CNeedsFree ¶
CNeedsFree returns true if the generated value from GenCCaster needs freeing. Pay attention to transfer-ownership when doing this.
func (Type) GenCCaster ¶
GenCCaster generates a function or type cast to convert Go values to C.
func (Type) GenCGoType ¶
func (Type) GenCaster ¶
GenCaster generates the type or function to be used to cast or convert C to Go types.
func (Type) IsInterface ¶
func (Type) IsNamespaceFunc ¶
IsNamespaceFunc returns true if the current type is a callback that belongs to the current namespace.