types

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessUnknown = AccessKind(iota)
	AccessDefine
	AccessRead
	AccessWrite
)
View Source
const (
	Unknown = Kind(0)
	Untyped = Kind(1 << iota)

	Ptr
	Int
	Float
	Bool
	Struct
	Func
	Array
	Signed
	Unsigned

	UnsafePtr  = unsafeKind | Ptr
	UntypedInt = Untyped | Int
	Nil        = Untyped | Ptr
)
View Source
const GoPrefix = "_cxgo_go_"

Variables

This section is empty.

Functions

func IsInt

func IsInt(t Type) bool

func IsPtr

func IsPtr(t Type) bool

func IsUnsafePtr

func IsUnsafePtr(t Type) bool

func IsUnsafePtr2

func IsUnsafePtr2(t Type) bool

func Same

func Same(x, y Type) bool

Types

type AccessKind

type AccessKind int

type ArrayType

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

func (ArrayType) Elem

func (t ArrayType) Elem() Type

func (ArrayType) GoType

func (t ArrayType) GoType() GoType

func (ArrayType) IsSlice

func (t ArrayType) IsSlice() bool

func (ArrayType) Kind

func (t ArrayType) Kind() Kind

func (ArrayType) Len

func (t ArrayType) Len() int

func (ArrayType) Sizeof

func (t ArrayType) Sizeof() int

type BoolType

type BoolType struct{}

func (BoolType) GoType

func (t BoolType) GoType() GoType

func (BoolType) Kind

func (t BoolType) Kind() Kind

func (BoolType) Sizeof

func (t BoolType) Sizeof() int

type C

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

func (*C) AssertFunc added in v0.3.7

func (c *C) AssertFunc() *Ident

AssertFunc returns C assert function ident.

func (*C) Bool

func (c *C) Bool() Type

Bool returns C bool type.

func (*C) BytesN

func (c *C) BytesN(n int) Type

BytesN returns C char[N] type.

func (*C) CallocFunc

func (c *C) CallocFunc() *Ident

CallocFunc returns C calloc function ident.

func (*C) Char

func (c *C) Char() Type

Char returns C char type.

func (*C) Double

func (c *C) Double() Type

Double returns C double type.

func (*C) Float

func (c *C) Float() Type

Float returns C float type.

func (*C) FreeFunc added in v0.2.1

func (c *C) FreeFunc() *Ident

FreeFunc returns C free function ident.

func (*C) Int

func (c *C) Int() Type

Int returns C int type.

func (*C) Long

func (c *C) Long() Type

Long returns C long type.

func (*C) LongLong

func (c *C) LongLong() Type

LongLong returns C long long type.

func (*C) MallocFunc

func (c *C) MallocFunc() *Ident

MallocFunc returns C malloc function ident.

func (*C) MemcpyFunc

func (c *C) MemcpyFunc() *Ident

MemcpyFunc returns C memcpy function ident.

func (*C) MemmoveFunc

func (c *C) MemmoveFunc() *Ident

MemmoveFunc returns C memmove function ident.

func (*C) MemsetFunc

func (c *C) MemsetFunc() *Ident

MemsetFunc returns C memset function ident.

func (*C) NamedType

func (c *C) NamedType(name string) Named

Named finds a named C builtin type.

func (*C) Short

func (c *C) Short() Type

Short returns C short type.

func (*C) SignedChar

func (c *C) SignedChar() Type

SignedChar returns C signed char type.

func (*C) StrdupFunc added in v0.3.7

func (c *C) StrdupFunc() *Ident

StrdupFunc returns C strdup function ident.

func (*C) String

func (c *C) String() PtrType

String returns C char* type.

func (*C) StrndupFunc added in v0.3.7

func (c *C) StrndupFunc() *Ident

StrndupFunc returns C strndup function ident.

func (*C) Type

func (c *C) Type(name string) Type

Type finds a C builtin type by name.

func (*C) UnsignedChar

func (c *C) UnsignedChar() Type

UnsignedChar returns C unsigned char type.

func (*C) UnsignedInt

func (c *C) UnsignedInt() Type

UnsignedInt returns C unsigned int type.

func (*C) UnsignedLong

func (c *C) UnsignedLong() Type

UnsignedLong returns C unsigned long type.

func (*C) UnsignedLongLong

func (c *C) UnsignedLongLong() Type

UnsignedLongLong returns C unsigned long long type.

func (*C) UnsignedShort

func (c *C) UnsignedShort() Type

UnsignedShort returns C unsigned short type.

func (*C) WChar

func (c *C) WChar() Type

WChar returns C wchar_t type.

func (*C) WCharSigned

func (c *C) WCharSigned() bool

func (*C) WCharSize

func (c *C) WCharSize() int

func (*C) WIntSize

func (c *C) WIntSize() int

func (*C) WString

func (c *C) WString() PtrType

WString returns C wchar_t* type.

type Config

type Config struct {
	PtrSize     int  // size of pointers in bytes
	IntSize     int  // default int size in bytes
	WCharSize   int  // wchar_t size
	WCharSigned bool // is wchar_t signed?
	UseGoInt    bool // use Go int for C int and long
}

Config stores configuration for base types.

func Config32

func Config32() Config

Config32 returns a default types config for 32 bit systems.

func Config64

func Config64() Config

Config64 returns a default types config for 64 bit systems.

func Default

func Default() Config

Default returns a default config.

type Env

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

func NewEnv

func NewEnv(c Config) *Env

func (*Env) C

func (e *Env) C() *C

C returns a package containing builtin C types.

func (*Env) CommonType

func (e *Env) CommonType(x, y Type) (otyp Type)

CommonType find common type to convert two operands to.

func (*Env) DefIntT

func (e *Env) DefIntT() Type

DefIntT returns a default signed int type. It is different from Go().Int(), since it returns int32/int64 type directly.

func (*Env) DefUintT

func (e *Env) DefUintT() Type

DefUintT returns a default unsigned int type. It is different from Go().Uint(), since it returns uint32/uint64 type directly.

func (*Env) FuncT

func (e *Env) FuncT(ret Type, args ...*Field) *FuncType

FuncT returns a function type with a given return type and named arguments. It's mostly useful for function declarations. See FuncTT for simplified version.

func (*Env) FuncTT

func (e *Env) FuncTT(ret Type, args ...Type) *FuncType

FuncTT returns a function type with a given return type and arguments. To name arguments, use FuncT.

func (*Env) Go

func (e *Env) Go() *Go

Go returns a package containing builtin Go types.

func (*Env) IntPtrT

func (e *Env) IntPtrT() IntType

IntPtrT returns a signed int type that can hold a pointer diff.

func (*Env) IntSize

func (e *Env) IntSize() int

IntSize returns default size of the integer.

func (*Env) MethStructT

func (e *Env) MethStructT(meth map[string]*FuncType) *StructType

func (*Env) NewPackage

func (e *Env) NewPackage(name, path string) *Package

func (*Env) PackageByPath

func (e *Env) PackageByPath(path string) *Package

func (*Env) Packages

func (e *Env) Packages() []*Package

func (*Env) PtrSize

func (e *Env) PtrSize() int

PtrSize returns size of the pointer.

func (*Env) PtrT

func (e *Env) PtrT(t Type) PtrType

PtrT returns a pointer type with a specified element.

func (*Env) StringC2Go

func (e *Env) StringC2Go() *Ident

StringC2Go is a builtin function that converts C string to Go string.

func (*Env) StringGo2C

func (e *Env) StringGo2C() *Ident

StringGo2C is a builtin function that converts Go string to C string.

func (*Env) UintPtrT

func (e *Env) UintPtrT() IntType

UintPtrT returns a unsigned int type that can hold a pointer. It is different from Go().Uintptr(), since it returns uint32/uint64 type directly.

func (*Env) VarFuncT

func (e *Env) VarFuncT(ret Type, args ...*Field) *FuncType

VarFuncT returns a variadic function type with a given return type and named arguments. It's mostly useful for function declarations. See VarFuncTT for simplified version.

func (*Env) VarFuncTT

func (e *Env) VarFuncTT(ret Type, args ...Type) *FuncType

VarFuncTT returns a variadic function type with a given return type and arguments. To name arguments, use VarFuncT.

func (*Env) WStringC2Go

func (e *Env) WStringC2Go() *Ident

WStringC2Go is a builtin function that converts C wchar_t string to Go string.

func (*Env) WStringGo2C

func (e *Env) WStringGo2C() *Ident

WStringGo2C is a builtin function that converts Go string to C wchar_t string.

type Field

type Field struct {
	Name *Ident
}

func (*Field) GoField

func (f *Field) GoField() *ast.Field

func (*Field) Type

func (f *Field) Type() Type

type FloatType

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

func (FloatType) GoType

func (t FloatType) GoType() GoType

func (FloatType) Kind

func (t FloatType) Kind() Kind

func (FloatType) Sizeof

func (t FloatType) Sizeof() int

type FuncType

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

func FuncT

func FuncT(ptrSize int, ret Type, args ...*Field) *FuncType

func FuncTT

func FuncTT(ptrSize int, ret Type, args ...Type) *FuncType

func IsFuncPtr

func IsFuncPtr(t Type) (*FuncType, bool)

func VarFuncT

func VarFuncT(ptrSize int, ret Type, args ...*Field) *FuncType

func VarFuncTT

func VarFuncTT(ptrSize int, ret Type, args ...Type) *FuncType

func (*FuncType) ArgN

func (t *FuncType) ArgN() int

func (*FuncType) Args

func (t *FuncType) Args() []*Field

func (*FuncType) GoFuncType

func (t *FuncType) GoFuncType() *ast.FuncType

func (*FuncType) GoType

func (t *FuncType) GoType() GoType

func (*FuncType) Kind

func (t *FuncType) Kind() Kind

func (*FuncType) Return

func (t *FuncType) Return() Type

func (*FuncType) Sizeof

func (t *FuncType) Sizeof() int

func (*FuncType) Variadic

func (t *FuncType) Variadic() bool

type Go

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

func GoArch added in v0.3.7

func GoArch(size int) *Go

func (*Go) Any added in v0.3.7

func (g *Go) Any() Type

Any returns Go any type.

func (*Go) AppendFunc added in v0.3.7

func (g *Go) AppendFunc() *Ident

AppendFunc returns Go append function identifier.

func (*Go) Bool

func (g *Go) Bool() Type

Bool returns Go bool type.

func (*Go) Byte

func (g *Go) Byte() Type

Byte returns Go byte type.

func (*Go) Bytes

func (g *Go) Bytes() Type

Bytes returns Go []byte type.

func (*Go) CapFunc added in v0.3.7

func (g *Go) CapFunc() *Ident

CapFunc returns Go cap function identifier.

func (*Go) CopyFunc

func (g *Go) CopyFunc() *Ident

CopyFunc returns Go copy function identifier.

func (*Go) Int

func (g *Go) Int() Type

Int returns Go int type.

func (*Go) Iota

func (g *Go) Iota() *Ident

Iota returns Go iota identifier.

func (*Go) IsBuiltinType added in v0.3.0

func (g *Go) IsBuiltinType(t Type) bool

func (*Go) LenFunc

func (g *Go) LenFunc() *Ident

LenFunc returns Go len function identifier.

func (*Go) MakeFunc added in v0.3.7

func (g *Go) MakeFunc() *Ident

MakeFunc returns Go make function identifier.

func (*Go) OsExitFunc

func (g *Go) OsExitFunc() *Ident

OsExitFunc returns Go os.Exit function identifier.

func (*Go) PanicFunc

func (g *Go) PanicFunc() *Ident

PanicFunc returns Go panic function identifier.

func (*Go) Rune

func (g *Go) Rune() Type

Rune returns Go rune type.

func (*Go) SliceFunc added in v0.3.7

func (g *Go) SliceFunc() *Ident

SliceFunc returns Go function identifier equivalent to Go slice expression.

func (*Go) SliceOfAny added in v0.3.7

func (g *Go) SliceOfAny() Type

SliceOfAny returns Go []any type.

func (*Go) String

func (g *Go) String() Type

String returns Go string type.

func (*Go) Types

func (g *Go) Types() []Type

func (*Go) Uint

func (g *Go) Uint() Type

Uint returns Go uint type.

func (*Go) Uintptr

func (g *Go) Uintptr() Type

Uintptr returns Go uintptr type.

func (*Go) UnsafePtr

func (g *Go) UnsafePtr() Type

UnsafePtr returns Go unsafe.Pointer type.

type GoType

type GoType = ast.Expr

type Ident

type Ident struct {
	Name   string
	GoName string
	// contains filtered or unexported fields
}

func NewIdent

func NewIdent(name string, typ Type) *Ident

func NewIdentGo

func NewIdentGo(cname, goname string, typ Type) *Ident

func NewUnnamed

func NewUnnamed(typ Type) *Ident

func (*Ident) CType

func (e *Ident) CType(exp Type) Type

func (*Ident) GoIdent

func (e *Ident) GoIdent() *ast.Ident

func (*Ident) IsUnnamed

func (e *Ident) IsUnnamed() bool

func (*Ident) String

func (e *Ident) String() string

type IntType

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

func AsTypedIntT

func AsTypedIntT(t IntType) IntType

func AsUntypedIntT

func AsUntypedIntT(t IntType) IntType

func IntT

func IntT(size int) IntType

func UintT

func UintT(size int) IntType

func UntypedIntT

func UntypedIntT(minSize int) IntType

func (IntType) GoType

func (t IntType) GoType() GoType

func (IntType) Kind

func (t IntType) Kind() Kind

func (IntType) Signed

func (t IntType) Signed() bool

func (IntType) Sizeof

func (t IntType) Sizeof() int

type Kind

type Kind int

func (Kind) Is

func (k Kind) Is(k2 Kind) bool

func (Kind) IsBool

func (k Kind) IsBool() bool

func (Kind) IsFloat

func (k Kind) IsFloat() bool

func (Kind) IsFunc

func (k Kind) IsFunc() bool

func (Kind) IsInt

func (k Kind) IsInt() bool

func (Kind) IsPtr

func (k Kind) IsPtr() bool

func (Kind) IsRef

func (k Kind) IsRef() bool

func (Kind) IsSigned added in v0.3.2

func (k Kind) IsSigned() bool

func (Kind) IsUnsafePtr

func (k Kind) IsUnsafePtr() bool

func (Kind) IsUnsigned added in v0.3.2

func (k Kind) IsUnsigned() bool

func (Kind) IsUntyped

func (k Kind) IsUntyped() bool

func (Kind) Major

func (k Kind) Major() Kind

func (Kind) String

func (k Kind) String() string

type Named

type Named interface {
	Type
	Name() *Ident
	Underlying() Type
}

func NamedT

func NamedT(name string, typ Type) Named

func NamedTGo

func NamedTGo(cname, goname string, typ Type) Named

type Node

type Node interface {
	Uses() []Usage
}

type Package

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

func (*Package) CNamedType

func (p *Package) CNamedType(name string) Named

func (*Package) CType

func (p *Package) CType(name string) Type

func (*Package) GoNamedType

func (p *Package) GoNamedType(name string) Named

func (*Package) GoType

func (p *Package) GoType(name string) Type

func (*Package) NewAlias

func (p *Package) NewAlias(cname, goname string, t Type) Type

func (*Package) NewTypeC

func (p *Package) NewTypeC(cname string, t Type) Named

func (*Package) NewTypeGo

func (p *Package) NewTypeGo(cname, goname string, t Type) Named

type PtrType

type PtrType interface {
	Type
	Elem() Type
	SetElem(e Type)
	ElemKind() Kind
	ElemSizeof() int
}

func NilT

func NilT(size int) PtrType

func PtrT

func PtrT(size int, elem Type) PtrType

func ToPtrType

func ToPtrType(exp Type) PtrType

func UnwrapPtr

func UnwrapPtr(t Type) PtrType

type StructType

type StructType struct {
	Where string
	// contains filtered or unexported fields
}

func StructT

func StructT(fields []*Field) *StructType

func UnionT

func UnionT(fields []*Field) *StructType

func (*StructType) Fields

func (t *StructType) Fields() []*Field

func (*StructType) GoType

func (t *StructType) GoType() GoType

func (*StructType) Kind

func (t *StructType) Kind() Kind

func (*StructType) Sizeof

func (t *StructType) Sizeof() int

type Type

type Type interface {
	Sizeof() int
	Kind() Kind
	GoType() GoType
}

func ArrayT

func ArrayT(elem Type, size int) Type

func BoolT

func BoolT() Type

func FloatT

func FloatT(size int) Type

func SliceT

func SliceT(elem Type) Type

func UnkT

func UnkT(size int) Type

func Unwrap

func Unwrap(t Type) Type

type Usage

type Usage struct {
	*Ident
	Access AccessKind
}

func UseRead

func UseRead(n ...Node) []Usage

func UseWrite

func UseWrite(n ...Node) []Usage

Jump to

Keyboard shortcuts

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