gengo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BuiltinVoid       = RelaxedIdentifier("void")
	BuiltinInt8       = RelaxedIdentifier("int8")
	BuiltinInt16      = RelaxedIdentifier("int16")
	BuiltinInt32      = RelaxedIdentifier("int32")
	BuiltinInt64      = RelaxedIdentifier("int64")
	BuiltinUint8      = RelaxedIdentifier("uint8")
	BuiltinUint16     = RelaxedIdentifier("uint16")
	BuiltinUint32     = RelaxedIdentifier("uint32")
	BuiltinUint64     = RelaxedIdentifier("uint64")
	BuiltinUint       = RelaxedIdentifier("uint")
	BuiltinInt        = RelaxedIdentifier("int")
	BuiltinFloat32    = RelaxedIdentifier("float32")
	BuiltinFloat64    = RelaxedIdentifier("float64")
	BuiltinComplex64  = RelaxedIdentifier("complex64")
	BuiltinComplex128 = RelaxedIdentifier("complex128")
	BuiltinBool       = RelaxedIdentifier("bool")
	BuiltinByte       = RelaxedIdentifier("byte")
	BuiltinRune       = RelaxedIdentifier("rune")
	BuiltinUintptr    = RelaxedIdentifier("uintptr")
	BuiltinAny        = RelaxedIdentifier("any")
)

Builtin types.

View Source
const PRELOAD = true

Variables

This section is empty.

Functions

func ConvertCase added in v0.2.0

func ConvertCase(s string, into NameConvention) string

Types

type BaseProvider

type BaseProvider struct {
	Types           map[string]TypeRef
	Builtins        map[string]Identifier
	RemovedPrefixes []string
	InferredMethods []MethodInferenceRule
	ForcedSynthetic map[string]struct{}
}

func NewBaseProvider

func NewBaseProvider(opt ...BaseProviderOption) *BaseProvider

func (*BaseProvider) AddType

func (p *BaseProvider) AddType(tc TypeClass, name string, decl dst.Expr) TypeRef

func (*BaseProvider) ConvertQualType

func (p *BaseProvider) ConvertQualType(q string) dst.Expr

func (*BaseProvider) ConvertTypeExpr

func (p *BaseProvider) ConvertTypeExpr(n clang.TypeNode) dst.Expr

func (*BaseProvider) FindType

func (p *BaseProvider) FindType(name string) (TypeRef, bool)

func (*BaseProvider) ForceSynthetic

func (p *BaseProvider) ForceSynthetic(name string) bool

func (*BaseProvider) InferMethod

func (p *BaseProvider) InferMethod(name string) (rcv string, newName string)

func (*BaseProvider) NameArg

func (p *BaseProvider) NameArg(name string, argType, funcName string) string

func (*BaseProvider) NameField

func (p *BaseProvider) NameField(name string, recordName string) string

func (*BaseProvider) NameFunc

func (p *BaseProvider) NameFunc(name string) string

func (*BaseProvider) NameGetter

func (p *BaseProvider) NameGetter(name string) string

func (*BaseProvider) NameSetter

func (p *BaseProvider) NameSetter(name string) string

func (*BaseProvider) NameType

func (p *BaseProvider) NameType(name string) string

func (*BaseProvider) NameValue

func (p *BaseProvider) NameValue(name string) string

func (*BaseProvider) RemapType

func (p *BaseProvider) RemapType(name string, tr TypeRef)

type BaseProviderOption

type BaseProviderOption func(*BaseProvider)

func WithForcedSynthetic

func WithForcedSynthetic(names ...string) BaseProviderOption

func WithInferredMethods

func WithInferredMethods(rules []MethodInferenceRule) BaseProviderOption

func WithRemovePrefix

func WithRemovePrefix(prefixes ...string) BaseProviderOption

type Identifier

type Identifier interface {
	String() string
	Ref() *dst.Ident
	Rename(string)
}

type MethodInferenceRule

type MethodInferenceRule struct {
	Name     string
	Receiver string
}

type Module

type Module struct {
	Parent *Package
	*dst.File
}

func (Module) AddInitFunc

func (m Module) AddInitFunc() *dst.FuncDecl

func (Module) AddType

func (m Module) AddType(tc TypeClass, name string, decl dst.Expr) TypeRef

func (Module) EmitEnum

func (mod Module) EmitEnum(n *clang.EnumDecl)

func (Module) EmitFrom

func (mod Module) EmitFrom(ast clang.Node, layouts *clang.LayoutMap)

func (Module) EmitFunction

func (mod Module) EmitFunction(n *clang.FunctionDecl)

func (Module) EmitStruct

func (mod Module) EmitStruct(n *clang.RecordDecl, layouts *clang.LayoutMap, deferred *deferred, vld *[]initTypeValidation)

func (Module) EmitSyntheticStruct

func (mod Module) EmitSyntheticStruct(n *clang.RecordDecl, layout *clang.RecordLayout, ty TypeRef, fl *dst.FieldList, vld *[]initTypeValidation)

func (Module) EmitTypedef

func (mod Module) EmitTypedef(n *clang.TypedefDecl)

func (Module) Fprint

func (m Module) Fprint(w io.Writer)

func (Module) GetInitFunc

func (m Module) GetInitFunc() *dst.FuncDecl

func (Module) Go

func (m Module) Go() (*ast.File, error)

func (Module) OnInit

func (m Module) OnInit(stmts ...dst.Stmt)

func (Module) Print

func (m Module) Print()

func (Module) String

func (m Module) String() string

func (Module) TryEmitNaturalStruct

func (mod Module) TryEmitNaturalStruct(n *clang.RecordDecl, layout *clang.RecordLayout, ty TypeRef, fl *dst.FieldList, vld *[]initTypeValidation) bool

type NameConvention added in v0.2.0

type NameConvention int
const (
	ConventionCamelCase  NameConvention = iota // camelCase
	ConventionSnakeCase                        // snake_case
	ConventionConstCase                        // CONST_CASE
	ConventionPascalCase                       // PascalCase
)

type Package

type Package struct {
	Name     string
	Restorer *decorator.Restorer
	Files    map[string]*dst.File
	Provider
}

func NewPackage

func NewPackage(name string, opts ...BaseProviderOption) *Package

func NewPackageWithProvider

func NewPackageWithProvider(name string, prov Provider) *Package

func (*Package) Fprint

func (p *Package) Fprint(fn func(path string) (io.WriteCloser, error)) error

func (*Package) Print

func (p *Package) Print()

func (*Package) Transform

func (p *Package) Transform(module string, opt *clang.Options) error

func (*Package) Upsert

func (p *Package) Upsert(module string) Module

func (*Package) WriteToDir

func (p *Package) WriteToDir(dir string) error

type Provider

type Provider interface {
	// NameField converts a field name to a Go compatible name.
	NameField(name string, recordName string) string
	// NameType converts a type name to a Go compatible name.
	NameType(name string) string
	// NameValue converts a value name to a Go compatible name.
	NameValue(name string) string
	// NameFunc converts a function name to a Go compatible name.
	NameFunc(name string) string
	// NameArg converts an argument name to a Go compatible name.
	NameArg(name string, argType, funcName string) string
	// NameGetter takes a transformed field name and returns the getter name.
	NameGetter(name string) string
	// NameSetter takes a transformed field name and returns the setter name.
	NameSetter(name string) string

	// ForceSynthetic returns true if the type should be syntethic (accessors instead of direct fields).
	ForceSynthetic(name string) bool
	// ConvertQualType converts a qualified type to a Go expression.
	ConvertQualType(q string) dst.Expr
	// ConvertTypeExpr converts a type node to a Go expression.
	ConvertTypeExpr(n clang.TypeNode) dst.Expr

	// AddType adds a type to the provider.
	AddType(tc TypeClass, name string, decl dst.Expr) TypeRef
	// RemapType remaps a given qualified typename to a type reference.
	RemapType(name string, tr TypeRef)
	// FindType resolves a type reference from a Go name.
	FindType(name string) (TypeRef, bool)

	// InferMethod returns the receiver type given the method name.
	InferMethod(name string) (rcv string, newName string)
}

Provider is a type provider allowing hooks for library specific type conversions.

type RelaxedIdentifier

type RelaxedIdentifier string

func (RelaxedIdentifier) Ref

func (r RelaxedIdentifier) Ref() *dst.Ident

func (RelaxedIdentifier) Rename

func (r RelaxedIdentifier) Rename(k string)

func (RelaxedIdentifier) String

func (r RelaxedIdentifier) String() string

type TrackedIdentifier

type TrackedIdentifier struct {
	Name string
	Refs []*dst.Ident
}

func (*TrackedIdentifier) Ref

func (t *TrackedIdentifier) Ref() *dst.Ident

func (*TrackedIdentifier) Rename

func (t *TrackedIdentifier) Rename(k string)

func (*TrackedIdentifier) String

func (t *TrackedIdentifier) String() string

type TypeClass

type TypeClass int
const (
	TcEnum TypeClass = iota
	TcStruct
	TcUnion
	TcTypedef
	TcCount
)

type TypeRef

type TypeRef struct {
	Identifier
	Decl *dst.GenDecl
}

Jump to

Keyboard shortcuts

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