translator

package
v0.0.0-...-ce3604e Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BoolSpec          = GoTypeSpec{Base: "bool"}
	IntSpec           = GoTypeSpec{Base: "int"}
	UintSpec          = GoTypeSpec{Base: "int", Unsigned: true}
	Int8Spec          = GoTypeSpec{Base: "int", Bits: 8}
	Uint8Spec         = GoTypeSpec{Base: "int", Bits: 8, Unsigned: true}
	Int16Spec         = GoTypeSpec{Base: "int", Bits: 16}
	Uint16Spec        = GoTypeSpec{Base: "int", Bits: 16, Unsigned: true}
	Int32Spec         = GoTypeSpec{Base: "int", Bits: 32}
	Uint32Spec        = GoTypeSpec{Base: "int", Bits: 32, Unsigned: true}
	Int64Spec         = GoTypeSpec{Base: "int", Bits: 64}
	Uint64Spec        = GoTypeSpec{Base: "int", Bits: 64, Unsigned: true}
	RuneSpec          = GoTypeSpec{Base: "rune"}
	ByteSpec          = GoTypeSpec{Base: "byte"}
	UByteSpec         = GoTypeSpec{Base: "byte", Unsigned: true}
	StringSpec        = GoTypeSpec{Base: "string"}
	UStringSpec       = GoTypeSpec{Base: "string", Unsigned: true}
	Float32Spec       = GoTypeSpec{Base: "float", Bits: 32}
	Float64Spec       = GoTypeSpec{Base: "float", Bits: 64}
	Complex64Spec     = GoTypeSpec{Base: "complex", Bits: 64}
	Complex128Spec    = GoTypeSpec{Base: "complex", Bits: 128}
	UnsafePointerSpec = GoTypeSpec{Base: "unsafe.Pointer", Pointers: 1}
	VoidSpec          = GoTypeSpec{Base: "byte", OuterArr: "[0]"}
	//
	InterfaceSliceSpec = GoTypeSpec{Base: "[]interface{}"}
)

Functions

This section is empty.

Types

type ArraySizeSpec

type ArraySizeSpec struct {
	N   uint64
	Str string
}

type ArraySpec

type ArraySpec string

func (*ArraySpec) AddSized

func (a *ArraySpec) AddSized(size uint64)

func (*ArraySpec) Prepend

func (a *ArraySpec) Prepend(spec ArraySpec)

func (ArraySpec) Sizes

func (a ArraySpec) Sizes() (sizes []ArraySizeSpec)

func (ArraySpec) String

func (a ArraySpec) String() string

type CDecl

type CDecl struct {
	Spec       CType
	Name       string
	Value      Value
	Expression string
	IsStatic   bool
	IsTypedef  bool
	IsDefine   bool
	Pos        token.Pos
	Src        string
}

func (CDecl) String

func (c CDecl) String() string

type CEnumSpec

type CEnumSpec struct {
	Tag      string
	Typedef  string
	Members  []*CDecl
	Type     CTypeSpec
	Pointers uint8
	InnerArr ArraySpec
	OuterArr ArraySpec
}

func (*CEnumSpec) AddInnerArr

func (c *CEnumSpec) AddInnerArr(size uint64)

func (*CEnumSpec) AddOuterArr

func (c *CEnumSpec) AddOuterArr(size uint64)

func (CEnumSpec) AtLevel

func (c CEnumSpec) AtLevel(level int) CType

func (*CEnumSpec) CGoName

func (c *CEnumSpec) CGoName() string

func (CEnumSpec) Copy

func (c CEnumSpec) Copy() CType

func (*CEnumSpec) GetBase

func (c *CEnumSpec) GetBase() string

func (*CEnumSpec) GetPointers

func (c *CEnumSpec) GetPointers() uint8

func (*CEnumSpec) GetTag

func (c *CEnumSpec) GetTag() string

func (*CEnumSpec) InnerArraySizes

func (c *CEnumSpec) InnerArraySizes() []ArraySizeSpec

func (*CEnumSpec) InnerArrays

func (c *CEnumSpec) InnerArrays() ArraySpec

func (*CEnumSpec) IsComplete

func (c *CEnumSpec) IsComplete() bool

func (*CEnumSpec) IsConst

func (c *CEnumSpec) IsConst() bool

func (*CEnumSpec) IsOpaque

func (c *CEnumSpec) IsOpaque() bool

func (*CEnumSpec) Kind

func (c *CEnumSpec) Kind() CTypeKind

func (*CEnumSpec) OuterArraySizes

func (c *CEnumSpec) OuterArraySizes() []ArraySizeSpec

func (*CEnumSpec) OuterArrays

func (c *CEnumSpec) OuterArrays() ArraySpec

func (*CEnumSpec) PromoteType

func (c *CEnumSpec) PromoteType(v Value) *CTypeSpec

func (*CEnumSpec) SetPointers

func (c *CEnumSpec) SetPointers(n uint8)

func (*CEnumSpec) SetRaw

func (c *CEnumSpec) SetRaw(x string)

func (CEnumSpec) String

func (spec CEnumSpec) String() string

type CFunctionSpec

type CFunctionSpec struct {
	Raw      string
	Typedef  string
	Return   CType
	Params   []*CDecl
	Pointers uint8
}

func (*CFunctionSpec) AddInnerArr

func (c *CFunctionSpec) AddInnerArr(uint64)

func (*CFunctionSpec) AddOuterArr

func (c *CFunctionSpec) AddOuterArr(uint64)

func (CFunctionSpec) AtLevel

func (c CFunctionSpec) AtLevel(level int) CType

func (*CFunctionSpec) CGoName

func (c *CFunctionSpec) CGoName() string

func (CFunctionSpec) Copy

func (c CFunctionSpec) Copy() CType

func (*CFunctionSpec) GetBase

func (c *CFunctionSpec) GetBase() string

func (*CFunctionSpec) GetPointers

func (c *CFunctionSpec) GetPointers() uint8

func (*CFunctionSpec) GetTag

func (c *CFunctionSpec) GetTag() string

func (*CFunctionSpec) InnerArraySizes

func (c *CFunctionSpec) InnerArraySizes() []ArraySizeSpec

func (*CFunctionSpec) InnerArrays

func (c *CFunctionSpec) InnerArrays() ArraySpec

func (*CFunctionSpec) IsComplete

func (c *CFunctionSpec) IsComplete() bool

func (*CFunctionSpec) IsConst

func (c *CFunctionSpec) IsConst() bool

func (*CFunctionSpec) IsOpaque

func (c *CFunctionSpec) IsOpaque() bool

func (*CFunctionSpec) Kind

func (c *CFunctionSpec) Kind() CTypeKind

func (*CFunctionSpec) OuterArraySizes

func (c *CFunctionSpec) OuterArraySizes() []ArraySizeSpec

func (*CFunctionSpec) OuterArrays

func (c *CFunctionSpec) OuterArrays() ArraySpec

func (*CFunctionSpec) SetPointers

func (c *CFunctionSpec) SetPointers(n uint8)

func (*CFunctionSpec) SetRaw

func (c *CFunctionSpec) SetRaw(x string)

func (CFunctionSpec) String

func (c CFunctionSpec) String() string

type CGoSpec

type CGoSpec struct {
	Base     string
	Pointers uint8
	OuterArr ArraySpec
	InnerArr ArraySpec
}

func (*CGoSpec) AtLevel

func (spec *CGoSpec) AtLevel(level uint8) string

func (*CGoSpec) PointersAtLevel

func (spec *CGoSpec) PointersAtLevel(level uint8) uint8

func (*CGoSpec) SpecAtLevel

func (spec *CGoSpec) SpecAtLevel(level uint8) CGoSpec

func (CGoSpec) String

func (spec CGoSpec) String() string

type CStructSpec

type CStructSpec struct {
	Tag      string
	Typedef  string
	IsUnion  bool
	Members  []*CDecl
	Pointers uint8
	InnerArr ArraySpec
	OuterArr ArraySpec
}

func (*CStructSpec) AddInnerArr

func (c *CStructSpec) AddInnerArr(size uint64)

func (*CStructSpec) AddOuterArr

func (c *CStructSpec) AddOuterArr(size uint64)

func (CStructSpec) AtLevel

func (c CStructSpec) AtLevel(level int) CType

func (*CStructSpec) CGoName

func (c *CStructSpec) CGoName() string

func (CStructSpec) Copy

func (c CStructSpec) Copy() CType

func (*CStructSpec) GetBase

func (c *CStructSpec) GetBase() string

func (*CStructSpec) GetPointers

func (c *CStructSpec) GetPointers() uint8

func (*CStructSpec) GetTag

func (c *CStructSpec) GetTag() string

func (*CStructSpec) InnerArraySizes

func (c *CStructSpec) InnerArraySizes() []ArraySizeSpec

func (*CStructSpec) InnerArrays

func (c *CStructSpec) InnerArrays() ArraySpec

func (*CStructSpec) IsComplete

func (c *CStructSpec) IsComplete() bool

func (*CStructSpec) IsConst

func (c *CStructSpec) IsConst() bool

func (*CStructSpec) IsOpaque

func (c *CStructSpec) IsOpaque() bool

func (*CStructSpec) Kind

func (c *CStructSpec) Kind() CTypeKind

func (*CStructSpec) OuterArraySizes

func (c *CStructSpec) OuterArraySizes() []ArraySizeSpec

func (*CStructSpec) OuterArrays

func (c *CStructSpec) OuterArrays() ArraySpec

func (*CStructSpec) SetPointers

func (c *CStructSpec) SetPointers(n uint8)

func (*CStructSpec) SetRaw

func (c *CStructSpec) SetRaw(x string)

func (CStructSpec) String

func (spec CStructSpec) String() string

type CType

type CType interface {
	GetBase() string
	GetTag() string
	SetRaw(x string)
	CGoName() string
	GetPointers() uint8
	SetPointers(uint8)
	AddOuterArr(uint64)
	AddInnerArr(uint64)
	OuterArrays() ArraySpec
	InnerArrays() ArraySpec
	OuterArraySizes() []ArraySizeSpec
	InnerArraySizes() []ArraySizeSpec
	//
	IsConst() bool
	IsOpaque() bool
	IsComplete() bool
	Kind() CTypeKind
	String() string
	Copy() CType
	AtLevel(level int) CType
}

type CTypeKind

type CTypeKind int
const (
	TypeKind CTypeKind = iota
	PlainTypeKind
	StructKind
	OpaqueStructKind
	UnionKind
	FunctionKind
	EnumKind
)

type CTypeMap

type CTypeMap map[CTypeSpec]GoTypeSpec

type CTypeSpec

type CTypeSpec struct {
	Raw      string
	Base     string
	Const    bool
	Signed   bool
	Unsigned bool
	Short    bool
	Long     bool
	Complex  bool
	Opaque   bool
	Pointers uint8
	InnerArr ArraySpec
	OuterArr ArraySpec
}

func (*CTypeSpec) AddInnerArr

func (c *CTypeSpec) AddInnerArr(size uint64)

func (*CTypeSpec) AddOuterArr

func (c *CTypeSpec) AddOuterArr(size uint64)

func (CTypeSpec) AtLevel

func (c CTypeSpec) AtLevel(level int) CType

func (*CTypeSpec) CGoName

func (c *CTypeSpec) CGoName() (name string)

func (CTypeSpec) Copy

func (c CTypeSpec) Copy() CType

func (*CTypeSpec) GetBase

func (c *CTypeSpec) GetBase() string

func (*CTypeSpec) GetPointers

func (c *CTypeSpec) GetPointers() uint8

func (*CTypeSpec) GetTag

func (c *CTypeSpec) GetTag() string

func (*CTypeSpec) InnerArraySizes

func (c *CTypeSpec) InnerArraySizes() []ArraySizeSpec

func (*CTypeSpec) InnerArrays

func (c *CTypeSpec) InnerArrays() ArraySpec

func (*CTypeSpec) IsComplete

func (c *CTypeSpec) IsComplete() bool

func (*CTypeSpec) IsConst

func (c *CTypeSpec) IsConst() bool

func (*CTypeSpec) IsOpaque

func (c *CTypeSpec) IsOpaque() bool

func (*CTypeSpec) Kind

func (c *CTypeSpec) Kind() CTypeKind

func (*CTypeSpec) OuterArraySizes

func (c *CTypeSpec) OuterArraySizes() []ArraySizeSpec

func (*CTypeSpec) OuterArrays

func (c *CTypeSpec) OuterArrays() ArraySpec

func (*CTypeSpec) SetPointers

func (c *CTypeSpec) SetPointers(n uint8)

func (*CTypeSpec) SetRaw

func (c *CTypeSpec) SetRaw(x string)

func (CTypeSpec) String

func (spec CTypeSpec) String() string

type CachedNameTransform

type CachedNameTransform struct {
	Target     RuleTarget
	Visibility RuleTarget
	Name       string
}

type Config

type Config struct {
	Rules      Rules      `yaml:"Rules"`
	ConstRules ConstRules `yaml:"ConstRules"`
	PtrTips    PtrTips    `yaml:"PtrTips"`
	TypeTips   TypeTips   `yaml:"TypeTips"`
	MemTips    MemTips    `yaml:"MemTips"`
	Typemap    CTypeMap   `yaml:"Typemap"`

	IgnoredFiles []string `yaml:"-"`
}

type ConstRule

type ConstRule string
const (
	ConstCGOAlias ConstRule = "cgo"
	ConstExpand   ConstRule = "expand"
	ConstEval     ConstRule = "eval"
)

type ConstRules

type ConstRules map[ConstScope]ConstRule

type ConstScope

type ConstScope string
const (
	ConstEnum    ConstScope = "enum"
	ConstDecl    ConstScope = "decl"
	ConstDefines ConstScope = "defines"
)

type GoTypeMap

type GoTypeMap map[string]GoTypeSpec

type GoTypeSpec

type GoTypeSpec struct {
	Slices   uint8
	Pointers uint8
	InnerArr ArraySpec
	OuterArr ArraySpec
	Unsigned bool
	Kind     CTypeKind
	Base     string
	Raw      string
	Bits     uint16
}

func (GoTypeSpec) IsGoString

func (spec GoTypeSpec) IsGoString() bool

func (GoTypeSpec) IsPlain

func (spec GoTypeSpec) IsPlain() bool

func (GoTypeSpec) IsPlainKind

func (spec GoTypeSpec) IsPlainKind() bool

func (*GoTypeSpec) PlainType

func (spec *GoTypeSpec) PlainType() string

func (GoTypeSpec) String

func (spec GoTypeSpec) String() string

func (GoTypeSpec) UnderlyingString

func (spec GoTypeSpec) UnderlyingString() string

type MemTipRxList

type MemTipRxList []TipSpecRx

type MemTips

type MemTips []TipSpec

type NameTransformCache

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

func (*NameTransformCache) Get

func (n *NameTransformCache) Get(target, visibility RuleTarget, name string) ([]byte, bool)

func (*NameTransformCache) Set

func (n *NameTransformCache) Set(target, visibility RuleTarget, name string, result []byte)

type PtrTipRxMap

type PtrTipRxMap map[TipScope][]TipSpecRx

type PtrTips

type PtrTips map[TipScope][]TipSpec

type RuleAction

type RuleAction string
const (
	ActionNone     RuleAction = ""
	ActionAccept   RuleAction = "accept"
	ActionIgnore   RuleAction = "ignore"
	ActionReplace  RuleAction = "replace"
	ActionDocument RuleAction = "doc"
)

type RuleSpec

type RuleSpec struct {
	From, To  string
	Action    RuleAction
	Transform RuleTransform
	Load      string
}

func (*RuleSpec) LoadSpec

func (r *RuleSpec) LoadSpec(r2 RuleSpec)

type RuleTarget

type RuleTarget string
const (
	NoTarget         RuleTarget = ""
	TargetGlobal     RuleTarget = "global"
	TargetPostGlobal RuleTarget = "post-global"
	//
	TargetConst    RuleTarget = "const"
	TargetType     RuleTarget = "type"
	TargetFunction RuleTarget = "function"
	//
	TargetPublic  RuleTarget = "public"
	TargetPrivate RuleTarget = "private"
)

type RuleTransform

type RuleTransform string
const (
	TransformLower    RuleTransform = "lower"
	TransformTitle    RuleTransform = "title"
	TransformExport   RuleTransform = "export"
	TransformUnexport RuleTransform = "unexport"
	TransformUpper    RuleTransform = "upper"
)

type Rules

type Rules map[RuleTarget][]RuleSpec

type Rx

type Rx struct {
	From *regexp.Regexp
	To   []byte
	//
	Transform RuleTransform
}

type RxMap

type RxMap map[RuleTarget][]Rx

type Tip

type Tip string
const (
	TipPtrSRef   Tip = "sref"
	TipPtrRef    Tip = "ref"
	TipPtrArr    Tip = "arr"
	TipPtrInst   Tip = "inst"
	TipMemRaw    Tip = "raw"
	TipTypeNamed Tip = "named"
	TipTypePlain Tip = "plain"
	NoTip        Tip = ""
)

func (Tip) IsValid

func (t Tip) IsValid() bool

func (Tip) Kind

func (t Tip) Kind() TipKind

type TipCache

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

func (*TipCache) Get

func (n *TipCache) Get(scope TipScope, name string) (TipSpecRx, bool)

func (*TipCache) Set

func (n *TipCache) Set(scope TipScope, name string, result TipSpecRx)

type TipKind

type TipKind string
const (
	TipKindUnknown TipKind = "unknown"
	TipKindPtr     TipKind = "ptr"
	TipKindType    TipKind = "type"
	TipKindMem     TipKind = "mem"
)

type TipScope

type TipScope string
const (
	TipScopeAny      TipScope = "any"
	TipScopeStruct   TipScope = "struct"
	TipScopeType     TipScope = "type"
	TipScopeFunction TipScope = "function"
)

type TipSpec

type TipSpec struct {
	Target  string
	Tips    Tips
	Self    Tip
	Default Tip
}

type TipSpecRx

type TipSpecRx struct {
	Target  *regexp.Regexp
	Default Tip
	// contains filtered or unexported fields
}

func (TipSpecRx) Self

func (t TipSpecRx) Self() Tip

func (TipSpecRx) TipAt

func (t TipSpecRx) TipAt(i int) Tip

type Tips

type Tips []Tip

type Translator

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

func New

func New(cfg *Config) (*Translator, error)

func (*Translator) CGoSpec

func (t *Translator) CGoSpec(spec CType, asArg bool) CGoSpec

func (*Translator) Declares

func (t *Translator) Declares() []*CDecl

func (*Translator) Defines

func (t *Translator) Defines() []*CDecl

func (*Translator) ExpressionMap

func (t *Translator) ExpressionMap() map[string]string

func (*Translator) IsAcceptableName

func (t *Translator) IsAcceptableName(target RuleTarget, name string) bool

func (*Translator) IsTokenIgnored

func (t *Translator) IsTokenIgnored(p token.Pos) bool

func (*Translator) Learn

func (t *Translator) Learn(unit *cc.TranslationUnit)

func (*Translator) MemTipRx

func (t *Translator) MemTipRx(name string) (TipSpecRx, bool)

func (*Translator) NormalizeSpecPointers

func (t *Translator) NormalizeSpecPointers(spec CType) CType

func (*Translator) PtrTipRx

func (t *Translator) PtrTipRx(scope TipScope, name string) (TipSpecRx, bool)

func (*Translator) SrcLocation

func (t *Translator) SrcLocation(docTarget RuleTarget, name string, p token.Pos) string

func (*Translator) TagMap

func (t *Translator) TagMap() map[string]*CDecl

func (*Translator) TipRxsForSpec

func (t *Translator) TipRxsForSpec(scope TipScope,
	name string, spec CType) (ptr, typ, mem TipSpecRx)

func (*Translator) TransformName

func (t *Translator) TransformName(target RuleTarget, str string, publicOpt ...bool) []byte

func (*Translator) TranslateSpec

func (t *Translator) TranslateSpec(spec CType, tips ...Tip) GoTypeSpec

func (*Translator) TypeTipRx

func (t *Translator) TypeTipRx(scope TipScope, name string) (TipSpecRx, bool)

func (*Translator) Typedefs

func (t *Translator) Typedefs() []*CDecl

func (*Translator) ValueMap

func (t *Translator) ValueMap() map[string]Value

type TypeCache

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

func (*TypeCache) Delete

func (t *TypeCache) Delete(id string)

func (*TypeCache) Get

func (t *TypeCache) Get(id string) bool

func (*TypeCache) Set

func (t *TypeCache) Set(id string)

type TypeTipRxMap

type TypeTipRxMap map[TipScope][]TipSpecRx

type TypeTips

type TypeTips map[TipScope][]TipSpec

type Value

type Value interface{}

Jump to

Keyboard shortcuts

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