cgo

package
v0.0.0-...-4d88b5a Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET_REF_FUNC_NAME         = "cgo_get_ref"
	GET_UUID_FROM_PTR_NAME    = "cgo_get_uuid_from_ptr"
	INCREMENT_REF_FUNC_NAME   = "cgo_incref"
	DECREMENT_REF_FUNC_NAME   = "cgo_decref"
	ERROR_TO_STRING_FUNC_NAME = "cgo_error_to_string"
	IS_ERROR_NIL_FUNC_NAME    = "cgo_is_error_nil"
	CFREE_FUNC_NAME           = "cgo_cfree"
	COBJECT_STRUCT_TYPE_NAME  = "cobject"
	REFS_VAR_NAME             = "refs"
	REFS_STRUCT_FIELD_NAME    = "refs"
)

Variables

This section is empty.

Functions

func ArrayConstructor

func ArrayConstructor(goType, cType string) *ast.FuncDecl

func CFree

func CFree() ast.Decl

CFree takes an unsafe pointer and frees the C memory associated with that pointer

func CObjectStruct

func CObjectStruct() ast.Decl

CObjectStruct produces an AST struct which will represent a C exposed Object

func CastBasicArg

func CastBasicArg(kind types.BasicKind, name ast.Expr) ast.Expr

func CastExpr

func CastExpr(t types.Type, ident ast.Expr) ast.Expr

func CastOut

func CastOut(t types.Type, name ast.Expr) ast.Expr

func CastUnsafePtr

func CastUnsafePtr(castType, target ast.Expr) *ast.CallExpr

CastUnsafePtr take a cast type and target expression and returns a cast expression

func CastUnsafePtrOfTypeUuid

func CastUnsafePtrOfTypeUuid(castType, target ast.Expr) ast.Expr

func DeRef

func DeRef(expr ast.Expr) *ast.StarExpr

DeRef takes an expression and prefaces the expression with a *

func DeclareVar

func DeclareVar(name *ast.Ident, t ast.Expr) *ast.DeclStmt

DeclareVar declares a local variable

func DecrementRef

func DecrementRef() ast.Decl

func DecrementRefCall

func DecrementRefCall(target ast.Expr) *ast.ExprStmt

DecrementRefCall takes a target expression to decrement it's cgo pointer ref and returns the expression

func ErrorToString

func ErrorToString() ast.Decl

func ExportComments

func ExportComments(exportName string) []*ast.Comment

ExportComments takes a name to export as string and returns a comment group

func Fields

func Fields(funcParams *types.Tuple) *ast.FieldList

Fields transforms parameters into a list of AST fields

func FormatSprintf

func FormatSprintf(format string, target ast.Expr) *ast.CallExpr

FormatSprintf takes a format and a target expression and returns a fmt.Sprintf expression

func FuncAst

func FuncAst(f *Func) *ast.FuncDecl

FuncAst returns an FuncDecl which wraps the func

func GetRef

func GetRef() ast.Decl

func GetUuidFromPtr

func GetUuidFromPtr() ast.Decl

func ImplementsError

func ImplementsError(t types.Type) bool

ImplementsError returns true if a type has an Error() string function signature

func Imports

func Imports(imports ...string) *ast.GenDecl

Imports creates a GenDecl for a series of imports

func ImportsFromMap

func ImportsFromMap(imports maps.Map) ast.Decl

ImportsFromMap create import ASTs from alias keys and package path values

func IncludeComments

func IncludeComments(includeNames ...string) []*ast.Comment

IncludeComments takes includeNames and returns AST comments for each include

func IncrementRef

func IncrementRef() ast.Decl

func IncrementRefCall

func IncrementRefCall(target ast.Expr) ast.Expr

IncrementRefCall takes a target expression to increment it's cgo pointer ref and returns the expression

func Init

func Init() ast.Decl

func InstanceMethodParams

func InstanceMethodParams(fields ...*ast.Field) *ast.FieldList

InstanceMethodParams returns a constructed field list for an instance method

func IsErrorNil

func IsErrorNil() ast.Decl

func MainFunc

func MainFunc() *ast.FuncDecl

func NamedToField

func NamedToField(p *types.Var, named *types.Named) *ast.Field

NameToField transforms a Var that's a Named type into an AST Field

func NewAst

func NewAst(functionName string, goType ast.Expr) ast.Decl

NewAst produces the []ast.Decl to construct a slice type and increment it's reference count

func NewAstWithInitialization

func NewAstWithInitialization(functionName string, goType ast.Expr, params []*ast.Field, inits func(*ast.Ident) []ast.Stmt) ast.Decl

func NewIdent

func NewIdent(name string) *ast.Ident

NewIdent takes a name as string and returns an *ast.Ident in that name

func Panic

func Panic(message string) ast.Expr

func ParamExpr

func ParamExpr(param *types.Var, t types.Type) ast.Expr

func ParamIdents

func ParamIdents(funcParams *types.Tuple) []ast.Expr

ParamIdents transforms parameter tuples into a slice of AST expressions

func PkgPathAliasFromString

func PkgPathAliasFromString(path string) string

PkgPathAliasFromString takes a golang path as a string and returns an import alias for that path

func RawComments

func RawComments(strs ...string) []*ast.Comment

func Ref

func Ref(expr ast.Expr) ast.Expr

Ref takes an expression and prefaces the expression with a &

func RefsStruct

func RefsStruct() ast.Decl

RefsStruct produces an AST struct which will keep track of references to pointers used by the host CFFI

func Return

func Return(expressions ...ast.Expr) *ast.ReturnStmt

Return takes an expression and returns a return statement containing the expression

func ShouldGenerate

func ShouldGenerate(v *types.Var) bool

func ShouldGenerateField

func ShouldGenerateField(v *types.Var) bool

func StringAst

func StringAst(functionName string, goType ast.Expr) ast.Decl

StringAst produces the []ast.Decl to provide a string representation of the slice

func ToC

func ToC(typeName string, targets ...ast.Expr) ast.Expr

func ToCChar

func ToCChar(targets ...ast.Expr) ast.Expr

func ToCDouble

func ToCDouble(targets ...ast.Expr) ast.Expr

func ToCFloat

func ToCFloat(targets ...ast.Expr) ast.Expr

func ToCInt

func ToCInt(targets ...ast.Expr) ast.Expr

func ToCLong

func ToCLong(targets ...ast.Expr) ast.Expr

func ToCLongLong

func ToCLongLong(targets ...ast.Expr) ast.Expr

func ToCShort

func ToCShort(targets ...ast.Expr) ast.Expr

func ToCString

func ToCString(targets ...ast.Expr) ast.Expr

func ToCUInt

func ToCUInt(targets ...ast.Expr) ast.Expr

func ToCULong

func ToCULong(targets ...ast.Expr) ast.Expr

func ToCULongLong

func ToCULongLong(targets ...ast.Expr) ast.Expr

func ToCUShort

func ToCUShort(targets ...ast.Expr) ast.Expr

func ToGoString

func ToGoString(targets ...ast.Expr) ast.Expr

func ToUnsafePointer

func ToUnsafePointer(targets ...ast.Expr) ast.Expr

func TypeExpression

func TypeExpression(typ types.Type) ast.Expr

func TypeExpressionToString

func TypeExpressionToString(expr ast.Expr) string

func TypeToArgumentTypeExpr

func TypeToArgumentTypeExpr(t types.Type) ast.Expr

func UnsafePtrOrBasic

func UnsafePtrOrBasic(p *types.Var, t types.Type) *ast.Field

UnsafePtrOrBasic returns a Basic typed field or an unsafe pointer if not a Basic type

func UuidToCBytes

func UuidToCBytes(uuidExpr ast.Expr) ast.Expr

func VarToField

func VarToField(p *types.Var, t types.Type) *ast.Field

VarToField transforms a Var into an AST field

Types

type Aliased

type Aliased interface {
	Alias() string
	Path() string
}

type Array

type Array struct {
	// contains filtered or unexported fields
}

ArrayWrapper is a wrapper for the

func NewArray

func NewArray(elem types.Type, len int64) *Array

NewArrayWrapper wraps types.Array to provide a consistent comparison

func (Array) String

func (a Array) String() string

Underlying returns the string representation of the type (types.Type)

func (Array) ToAst

func (a Array) ToAst() []ast.Decl

ToAst returns the go/ast representation of the CGo wrapper of the Array type

func (Array) Underlying

func (a Array) Underlying() types.Type

Underlying returns the underlying type of the Array (types.Type)

type AstTransformer

type AstTransformer interface {
	ToAst() []ast.Decl
	Underlying() types.Type
	Exportable
}

type Exportable

type Exportable interface {
	IsExportable() bool
	ExportName() string
}

type Func

type Func struct {
	*types.Func
	BoundRecv *Named
}

FuncWrapper is a wrapper for a Function

func NewBoundFunc

func NewBoundFunc(fun *types.Func, boundRecv *Named) *Func

func NewFunc

func NewFunc(fun *types.Func) *Func

func (Func) AliasedGoName

func (f Func) AliasedGoName() ast.Expr

func (Func) CDefs

func (f Func) CDefs() (retTypes string, funcPtrs string, calls string)

func (Func) CName

func (f Func) CName() string

func (Func) CallbackFuncName

func (f Func) CallbackFuncName() string

func (Func) CallbackFuncPtrName

func (f Func) CallbackFuncPtrName() string

func (Func) ExportName

func (f Func) ExportName() string

func (Func) InterfaceCallbackAst

func (f Func) InterfaceCallbackAst(iface Interface) ast.Decl

InterfaceCallbackAst produces proxy functions for interface methods which act as a C bridge between Golang and the hosting language. It translates Golang Args to C args, calls a function callback into the hosting language providing arguments, an object handle, and captures a return. The return struct is then transformed back into Golang and C arguments are freed.

The function looks like the following.

func (iface veil_io_Reader_helper) Read(p []byte) (n int, err error) {
	fun, ok := iface.callbacks["Read"]
	if ok {
		arg0 := C.CBytes(cgo_incref(unsafe.Pointer(&p)).Bytes())
		res := C.CallHandleFunc_2_1(arg0, iface.handle, (*C.FuncPtr_2_1)(fun))
		cgo_decref(arg0)
		var r0 int
		if res.r0 == nil {
			panic("result: 0 is nil and must have a value")
		} else {
			r0 = *(*int)(res.r0)
		}
		var r1 error
		if res.r1 == nil {
			r1 = nil
		} else {
			r1 = *(*error)(res.r1)
		}
		return r0, r1
	} else {
		panic("can't find registerd method: Read")
	}
}

func (Func) IsExportable

func (f Func) IsExportable() bool

func (Func) PackagePath

func (f Func) PackagePath() string

func (Func) Signature

func (f Func) Signature() *types.Signature

func (Func) String

func (f Func) String() string

Underlying returns the string representation of the type (types.Type)

func (Func) ToAst

func (f Func) ToAst() []ast.Decl

ToAst returns the go/ast representation of the CGo wrapper of the Func type

func (Func) Underlying

func (f Func) Underlying() types.Type

Underlying returns the underlying type

type Interface

type Interface struct {
	// contains filtered or unexported fields
}

Inerface is a helpful facade over types.Named which is intended to only contain an Interface

func NewInterface

func NewInterface(named *types.Named) *Interface

func (Interface) CDefs

func (iface Interface) CDefs() (retTypes []string, funcPtrs []string, calls []string)

func (Interface) CName

func (iface Interface) CName() string

func (Interface) CTypeName

func (iface Interface) CTypeName() ast.Expr

CTypeName returns the selector expression for the Named aliased package and type

func (Interface) ExportName

func (iface Interface) ExportName() string

func (Interface) ExportedMethods

func (iface Interface) ExportedMethods() []*Func

func (Interface) HelperCallbackRegistrationAst

func (iface Interface) HelperCallbackRegistrationAst() ast.Decl

func (Interface) HelperStructAst

func (iface Interface) HelperStructAst() ast.Decl

func (Interface) Interface

func (iface Interface) Interface() *types.Interface

func (Interface) IsExportable

func (iface Interface) IsExportable() bool

func (Interface) MethodAsts

func (iface Interface) MethodAsts() []ast.Decl

func (Interface) Name

func (iface Interface) Name() string

func (Interface) NewAst

func (iface Interface) NewAst() ast.Decl

NewAst produces the []ast.Decl to construct a named type and increment it's reference count

func (Interface) StringAst

func (iface Interface) StringAst() ast.Decl

StringAst produces the []ast.Decl to provide a string representation of the named type

func (Interface) ToAst

func (iface Interface) ToAst() []ast.Decl

ToAst returns the go/ast representation of the CGo wrapper of the named type

func (Interface) Underlying

func (iface Interface) Underlying() types.Type

type Named

type Named struct {
	*types.Named
}

func NewNamed

func NewNamed(named *types.Named) *Named

func (Named) Alias

func (n Named) Alias() string

func (Named) CName

func (n Named) CName() string

CName returns the fully resolved name to the named type

func (Named) CShortName

func (n Named) CShortName() string

func (Named) CTypeName

func (n Named) CTypeName() ast.Expr

CTypeName returns the selector expression for the Named aliased package and type

func (Named) ExportName

func (n Named) ExportName() string

func (Named) ExportedMethods

func (n Named) ExportedMethods() []*Func

Methods returns the list of methods decorated on the named type

func (Named) IsExportable

func (n Named) IsExportable() bool

func (Named) MethodAsts

func (n Named) MethodAsts() []ast.Decl

func (Named) NewAst

func (n Named) NewAst() ast.Decl

NewAst produces the []ast.Decl to construct a named type and increment it's reference count

func (Named) NewMethodName

func (n Named) NewMethodName() string

func (Named) Path

func (n Named) Path() string

func (Named) StringAst

func (n Named) StringAst() ast.Decl

StringAst produces the []ast.Decl to provide a string representation of the named type

func (Named) ToAst

func (n Named) ToAst() []ast.Decl

ToAst returns the go/ast representation of the CGo wrapper of the named type

func (Named) ToStringMethodName

func (n Named) ToStringMethodName() string

type Package

type Package struct {
	// contains filtered or unexported fields
}

Package is a container for ast.Types and Docs

func NewPackage

func NewPackage(pkgPath string, workDir string) (*Package, error)

NewPackage constructs a Package from pkgPath using the specified working directory

func (Package) AstTransformers

func (p Package) AstTransformers() []AstTransformer

func (Package) CDefinitions

func (p Package) CDefinitions() []string

func (Package) ExportedTypes

func (p Package) ExportedTypes() []types.Type

func (Package) Funcs

func (p Package) Funcs() []*Func

func (Package) ImportAliases

func (p Package) ImportAliases() maps.Map

func (Package) Interfaces

func (p Package) Interfaces() []*Interface

func (Package) IsConstructor

func (p Package) IsConstructor(f *Func) bool

func (Package) Name

func (p Package) Name() string

func (Package) Structs

func (p Package) Structs() []*Struct

func (Package) ToAst

func (p Package) ToAst() []ast.Decl

type Slice

type Slice struct {
	// contains filtered or unexported fields
}

ArrayWrapper is a wrapper for the

func NewSlice

func NewSlice(elem types.Type) *Slice

NewSliceWrapper wraps types.Slice to provide a consistent comparison

func (Slice) CGoName

func (s Slice) CGoName() string

func (Slice) Elem

func (s Slice) Elem() types.Type

func (Slice) ElementName

func (s Slice) ElementName() string

func (Slice) ElementPackageAliasAndPath

func (s Slice) ElementPackageAliasAndPath(typ types.Type) string

func (Slice) ExportName

func (s Slice) ExportName() string

func (Slice) GoTypeExpr

func (s Slice) GoTypeExpr() ast.Expr

func (Slice) IsExportable

func (s Slice) IsExportable() bool

func (Slice) ItemAppendAst

func (s Slice) ItemAppendAst() ast.Decl

ItemAppendAst returns a function declaration which appends an item to the slice

func (Slice) ItemAst

func (s Slice) ItemAst() ast.Decl

func (Slice) ItemDeleteAst

func (s Slice) ItemDeleteAst() ast.Decl

ItemDeleteAst returns a function declaration which deletes an item from the slice

func (Slice) ItemInsertAst

func (s Slice) ItemInsertAst() ast.Decl

ItemInsertAst returns a function declaration which inserts an item into the slice

func (Slice) ItemSetAst

func (s Slice) ItemSetAst() ast.Decl

func (Slice) LenAst

func (s Slice) LenAst() ast.Decl

func (Slice) MethodName

func (s Slice) MethodName() string

func (Slice) NewAst

func (s Slice) NewAst() ast.Decl

NewAst produces the []ast.Decl to construct a slice type and increment it's reference count

func (Slice) String

func (s Slice) String() string

Underlying returns the string representation of the type (types.Type)

func (Slice) StringAst

func (s Slice) StringAst() ast.Decl

StringAst produces the []ast.Decl to provide a string representation of the slice

func (Slice) ToAst

func (s Slice) ToAst() []ast.Decl

ToAst returns the go/ast representation of the CGo wrapper of the Slice type

func (Slice) Underlying

func (s Slice) Underlying() types.Type

Underlying returns the underlying type of the Slice (types.Type)

type Struct

type Struct struct {
	*Named
}

Struct is a helpful facade over types.Named which is intended to only contain a struct

func NewStruct

func NewStruct(named *types.Named) *Struct

func (Struct) ConstructorName

func (s Struct) ConstructorName(f *Func) string

func (Struct) FieldAccessorsAst

func (s Struct) FieldAccessorsAst() []ast.Decl

func (Struct) FieldName

func (s Struct) FieldName(field *types.Var) string

func (Struct) Getter

func (s Struct) Getter(field *types.Var) ast.Decl

func (Struct) IsConstructor

func (s Struct) IsConstructor(f *Func) bool

func (Struct) Setter

func (s Struct) Setter(field *types.Var) ast.Decl

func (Struct) Struct

func (s Struct) Struct() *types.Struct

Struct returns the underlying struct

func (Struct) ToAst

func (s Struct) ToAst() []ast.Decl

ToAst returns the go/ast representation of the CGo wrapper of the Array type

Jump to

Keyboard shortcuts

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