binding

package
v0.0.0-...-8cb4219 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package binding provides helpers for building autogenerated cgo bindings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CgoConversionFor

func CgoConversionFor(name string, typ cc.Type, types ...map[TypeKey]*template.Template) string

CgoConversionFor returns a string representation of the given type using a mapping in types. CgoConversionFor will panic if no type mapping is found after searching the user-provided types mappings and then the following mapping:

{Kind: cc.Void, IsPointer: true}:          "unsafe.Pointer(&{{.}}[0])",
{Kind: cc.Int}:                            "C.int({{.}})",
{Kind: cc.Float}:                          "C.float({{.}})",
{Kind: cc.Float, IsPointer: true}:         "(*C.float)({{.}})",
{Kind: cc.Double}:                         "C.double({{.}})",
{Kind: cc.Double, IsPointer: true}:        "(*C.double)({{.}})",
{Kind: cc.Bool}:                           "C.bool({{.}})",
{Kind: cc.FloatComplex}:                   "unsafe.Pointer(&{{.}})",
{Kind: cc.DoubleComplex}:                  "unsafe.Pointer(&{{.}})",
{Kind: cc.FloatComplex, IsPointer: true}:  "unsafe.Pointer(&{{.}}[0])",
{Kind: cc.DoubleComplex, IsPointer: true}: "unsafe.Pointer(&{{.}}[0])",

func CgoConversionForEnum

func CgoConversionForEnum(name string, typ cc.Type, types ...map[string]*template.Template) string

CgoConversionForEnum returns a string representation of the given enum type using a mapping in types. GoTypeForEnum will panic if no type mapping is found after searching the user-provided types mappings or the type is not an enum.

func DocComments

func DocComments(path string) (docs map[string]map[string][]*ast.Comment, err error)

DocComments returns a map of method documentation comments for the package at the given path. The first key of the returned map is the type name and the second is the method name. Non-method function documentation are in docs[""].

func GoTypeFor

func GoTypeFor(typ cc.Type, name string, types ...map[TypeKey]*template.Template) string

GoTypeFor returns a string representation of the given type using a mapping in types. GoTypeFor will panic if no type mapping is found after searching the user-provided types mappings and then the following mapping:

{Kind: cc.Int}:                     "int",
{Kind: cc.Float}:                   "float32",
{Kind: cc.Float, IsPointer: true}:  "[]float32",
{Kind: cc.Double}:                  "float64",
{Kind: cc.Double, IsPointer: true}: "[]float64",
{Kind: cc.Bool}:                    "bool",
{Kind: cc.FloatComplex}:            "complex64",
{Kind: cc.DoubleComplex}:           "complex128",

func GoTypeForEnum

func GoTypeForEnum(typ cc.Type, name string, types ...map[string]*template.Template) string

GoTypeForEnum returns a string representation of the given enum type using a mapping in types. GoTypeForEnum will panic if no type mapping is found after searching the user-provided types mappings or the type is not an enum.

func LowerCaseFirst

func LowerCaseFirst(s string) string

LowerCaseFirst returns s with the first character lower-cased. LowerCaseFirst assumes s is an ASCII-represented string.

func UpperCaseFirst

func UpperCaseFirst(s string) string

UpperCaseFirst returns s with the first character upper-cased. UpperCaseFirst assumes s is an ASCII-represented string.

Types

type Declaration

type Declaration struct {
	Pos         token.Pos
	Name        string
	Return      cc.Type
	CParameters []cc.Parameter
	Variadic    bool
}

Declaration is a description of a C function declaration.

func Declarations

func Declarations(paths ...string) ([]Declaration, error)

Declarations returns the C function declarations in the given set of file paths.

func (*Declaration) Parameters

func (d *Declaration) Parameters() []Parameter

Parameters returns the declaration's CParameters converted to a []Parameter.

func (*Declaration) Position

func (d *Declaration) Position() token.Position

Position returns the token position of the declaration.

type Parameter

type Parameter struct{ Parameter cc.Parameter }

Parameter is a C function parameter.

func (*Parameter) Elem

func (p *Parameter) Elem() cc.Type

Elem returns the pointer type of a pointer parameter or the element type of an array parameter.

func (*Parameter) Kind

func (p *Parameter) Kind() cc.Kind

Kind returns the C kind of the parameter.

func (*Parameter) Name

func (p *Parameter) Name() string

Name returns the name of the parameter.

func (*Parameter) Type

func (p *Parameter) Type() cc.Type

Type returns the C type of the parameter.

type TypeKey

type TypeKey struct {
	IsPointer bool
	Kind      cc.Kind
}

TypeKey is a terse C type description.

Jump to

Keyboard shortcuts

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