cxgo

package module
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: 24 Imported by: 0

README

C to Go translator

GitHub license Gitter GoDoc

CxGo is a tool for translating C source code to Go (aka transpiler, source-to-source compiler).

It uses cc for preprocessing and parsing C (no clang/gcc dependencies!) and a custom type-checker and AST translation layer to make the best output possible.

The only requirement is: C code must compile with cxgo, including headers.

Having said that, cxgo uses a few tricks to make this process easier.

TL;DR for the project goals:

  1. Implement a practical C to Go translator (no C++ for now).
  2. Keep the output program code correct.
  3. Make the generated code human-readable and as idiomatic as possible.
  4. Make it easy to use and customize.

Check the FAQ for more common question about the project.

Status

The project is experimental! Do not rely on it in production and other sensitive environments!

Although it was successfully tested on multiple projects, it might change the behavior of the code due to yet unknown bugs.

Compiler test results:

  • TCC: 62/89 (70%)
  • GCC: 783/1236 (63%)

Transpiled projects:

Installation

go get -u github.com/gotranspile/cxgo/cmd/cxgo

or download the latest release from Github.

How to use

The fastest way to try it is:

cxgo file main.c

For more details, check our examples section.

It will guide you through basic usage patterns as well as a more advanced ones (on real-world projects).

You may also check FAQ if you have any issues.

Caveats

The following C features are currently accepted by cxgo, but may be implemented partially or not implemented at all:

  • preserving comments from C code (#2)
  • static (#4)
  • auto (#5)
  • bitfields (#6)
  • union with C-identical data layout (#7)
  • packed structs (#8)
  • asm
  • case in weird places (#9)
  • goto forbidden by Go (there is a workaround, though, see #10)
  • label variables (#11)
  • thread local storage (#12)
  • setjmp (will compile, but panics at runtime)
  • some stdlib functions and types are missing (good first issue!)
  • deep type inference (when converting to Go string/slices)
  • considering multiple #ifdef paths for different OS/envs

Community

Join our community! We'd like to hear back from you!

Contributing

See CONTRIBUTING.

License

MIT

Documentation

Index

Constants

View Source
const (
	CLitChar = CLitKind(iota)
	CLitWChar
)
View Source
const (
	HintBool   = TypeHint("bool")   // force the type to Go bool
	HintSlice  = TypeHint("slice")  // force type to Go slice (for pointers and arrays)
	HintIface  = TypeHint("iface")  // force type to Go interface{}
	HintString = TypeHint("string") // force type to Go string
)

Variables

This section is empty.

Functions

func CallFinals

func CallFinals() error

func ErrorWithPos added in v0.3.7

func ErrorWithPos(err error, where token.Position) error

func ErrorfWithPos added in v0.3.7

func ErrorfWithPos(where token.Position, format string, args ...any) error

func IsNil

func IsNil(e Expr) bool

func Parse

func Parse(c *libs.Env, root, fname string, sconf SourceConfig) (*cc.AST, error)

func ParseSource

func ParseSource(env *libs.Env, c ParseConfig) (*cc.AST, error)

func PrintGo

func PrintGo(w io.Writer, pkg string, decls []GoDecl) error

func RegisterASTHookC

func RegisterASTHookC(fnc ASTHookCFunc)

func RegisterFinal

func RegisterFinal(fnc func() error)

func ToFuncExpr

func ToFuncExpr(exp types.Type) *types.FuncType

func Translate

func Translate(root, fname, out string, env *libs.Env, conf Config) error

Types

type ASTHookCFunc

type ASTHookCFunc func(c Config, fname string, decls []CDecl) error

type BaseBlock

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

func (*BaseBlock) AddPrevBlock

func (b *BaseBlock) AddPrevBlock(b2 Block)

func (*BaseBlock) PrevBlocks

func (b *BaseBlock) PrevBlocks() []Block

type BinaryBoolExpr

type BinaryBoolExpr struct {
	X  BoolExpr
	Op BoolOp
	Y  BoolExpr
}

func (*BinaryBoolExpr) AsExpr

func (e *BinaryBoolExpr) AsExpr() GoExpr

func (*BinaryBoolExpr) CType

func (e *BinaryBoolExpr) CType(types.Type) types.Type

func (*BinaryBoolExpr) HasSideEffects

func (e *BinaryBoolExpr) HasSideEffects() bool

func (*BinaryBoolExpr) IsConst

func (e *BinaryBoolExpr) IsConst() bool

func (*BinaryBoolExpr) Negate

func (e *BinaryBoolExpr) Negate() BoolExpr

func (*BinaryBoolExpr) Uses

func (e *BinaryBoolExpr) Uses() []types.Usage

func (*BinaryBoolExpr) Visit

func (e *BinaryBoolExpr) Visit(v Visitor)

type BinaryOp

type BinaryOp string
const (
	BinOpMult BinaryOp = "*"
	BinOpDiv  BinaryOp = "/"
	BinOpMod  BinaryOp = "%"

	BinOpAdd BinaryOp = "+"
	BinOpSub BinaryOp = "-"

	BinOpLsh BinaryOp = "<<"
	BinOpRsh BinaryOp = ">>"

	BinOpBitAnd BinaryOp = "&"
	BinOpBitOr  BinaryOp = "|"
	BinOpBitXor BinaryOp = "^"
)

func (BinaryOp) GoAssignToken

func (op BinaryOp) GoAssignToken() token.Token

func (BinaryOp) GoToken

func (op BinaryOp) GoToken() token.Token

func (BinaryOp) IsArithm

func (op BinaryOp) IsArithm() bool

func (BinaryOp) IsCommutative

func (op BinaryOp) IsCommutative() bool

func (BinaryOp) Precedence

func (op BinaryOp) Precedence() int

type Block

type Block interface {
	AddPrevBlock(b2 Block)
	PrevBlocks() []Block
	NextBlocks() []Block
	ReplaceNext(old, rep Block)
}

type BlockSet

type BlockSet map[Block]struct{}

func (BlockSet) Clone

func (b BlockSet) Clone() BlockSet

func (BlockSet) Contains

func (b BlockSet) Contains(b2 BlockSet) bool

func (BlockSet) Intersect

func (b BlockSet) Intersect(b2 BlockSet) BlockSet

func (BlockSet) Union

func (b BlockSet) Union(b2 BlockSet) BlockSet

type BlockStmt

type BlockStmt struct {
	Stmts []CStmt
	// contains filtered or unexported fields
}

func (*BlockStmt) AsStmt

func (s *BlockStmt) AsStmt() []GoStmt

func (*BlockStmt) EachStmt

func (s *BlockStmt) EachStmt(fnc CStmtFunc) bool

func (*BlockStmt) GoBlockStmt

func (s *BlockStmt) GoBlockStmt() *ast.BlockStmt

func (*BlockStmt) In

func (s *BlockStmt) In(ft *types.FuncType) *BlockStmt

func (*BlockStmt) Uses

func (s *BlockStmt) Uses() []types.Usage

func (*BlockStmt) Visit

func (s *BlockStmt) Visit(v Visitor)

type Bool

type Bool bool

Bool is a constant bool value.

func (Bool) AsExpr

func (e Bool) AsExpr() GoExpr

func (Bool) CType

func (e Bool) CType(types.Type) types.Type

func (Bool) HasSideEffects

func (e Bool) HasSideEffects() bool

func (Bool) IsConst

func (e Bool) IsConst() bool

func (Bool) Negate

func (e Bool) Negate() BoolExpr

func (Bool) Uses

func (e Bool) Uses() []types.Usage

func (Bool) Visit

func (Bool) Visit(v Visitor)

type BoolAssert

type BoolAssert struct {
	X Expr
}

func (BoolAssert) AsExpr

func (e BoolAssert) AsExpr() GoExpr

func (BoolAssert) CType

func (e BoolAssert) CType(types.Type) types.Type

func (BoolAssert) HasSideEffects

func (e BoolAssert) HasSideEffects() bool

func (BoolAssert) IsConst

func (e BoolAssert) IsConst() bool

func (BoolAssert) Negate

func (e BoolAssert) Negate() BoolExpr

func (BoolAssert) Uses

func (e BoolAssert) Uses() []types.Usage

func (BoolAssert) Visit

func (e BoolAssert) Visit(v Visitor)

type BoolExpr

type BoolExpr interface {
	Expr
	// Negate a bool expression. Alternative of !x, but for any expression.
	// It may invert the comparison operator or just return !x.
	Negate() BoolExpr
}

BoolExpr is a expression that returns a bool value.

func And

func And(x, y BoolExpr) BoolExpr

func CompareFuncs

func CompareFuncs(x FuncExpr, op ComparisonOp, y FuncExpr) BoolExpr

func ComparePtrs

func ComparePtrs(x PtrExpr, op ComparisonOp, y PtrExpr) BoolExpr

func Or

func Or(x, y BoolExpr) BoolExpr

type BoolIdent

type BoolIdent struct {
	*types.Ident
}

func (BoolIdent) AsExpr

func (e BoolIdent) AsExpr() GoExpr

func (BoolIdent) HasSideEffects

func (e BoolIdent) HasSideEffects() bool

func (BoolIdent) Identifier

func (e BoolIdent) Identifier() *types.Ident

func (BoolIdent) IsConst

func (e BoolIdent) IsConst() bool

func (BoolIdent) Negate

func (e BoolIdent) Negate() BoolExpr

func (BoolIdent) Uses

func (e BoolIdent) Uses() []types.Usage

func (BoolIdent) Visit

func (BoolIdent) Visit(v Visitor)

type BoolOp

type BoolOp string
const (
	BinOpAnd BoolOp = "&&"
	BinOpOr  BoolOp = "||"
)

func (BoolOp) GoToken

func (op BoolOp) GoToken() token.Token

func (BoolOp) Negate added in v0.3.7

func (op BoolOp) Negate() BoolOp

type BoolToInt

type BoolToInt struct {
	X BoolExpr
}

func (*BoolToInt) AsExpr

func (e *BoolToInt) AsExpr() GoExpr

func (*BoolToInt) CType

func (e *BoolToInt) CType(types.Type) types.Type

func (*BoolToInt) HasSideEffects

func (e *BoolToInt) HasSideEffects() bool

func (*BoolToInt) IsConst

func (e *BoolToInt) IsConst() bool

func (*BoolToInt) Uses

func (e *BoolToInt) Uses() []types.Usage

func (*BoolToInt) Visit

func (e *BoolToInt) Visit(v Visitor)

type CAlignofExpr

type CAlignofExpr struct {
	Type types.Type
	// contains filtered or unexported fields
}

func (*CAlignofExpr) AsExpr

func (e *CAlignofExpr) AsExpr() GoExpr

func (*CAlignofExpr) CType

func (e *CAlignofExpr) CType(types.Type) types.Type

func (*CAlignofExpr) HasSideEffects

func (e *CAlignofExpr) HasSideEffects() bool

func (*CAlignofExpr) IsConst

func (e *CAlignofExpr) IsConst() bool

func (*CAlignofExpr) Uses

func (e *CAlignofExpr) Uses() []types.Usage

func (*CAlignofExpr) Visit

func (e *CAlignofExpr) Visit(v Visitor)

type CAsmExpr

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

func (*CAsmExpr) AsExpr

func (e *CAsmExpr) AsExpr() GoExpr

func (*CAsmExpr) CType

func (e *CAsmExpr) CType(types.Type) types.Type

func (*CAsmExpr) HasSideEffects

func (e *CAsmExpr) HasSideEffects() bool

func (*CAsmExpr) IsConst

func (e *CAsmExpr) IsConst() bool

func (*CAsmExpr) Uses

func (e *CAsmExpr) Uses() []types.Usage

func (*CAsmExpr) Visit

func (e *CAsmExpr) Visit(_ Visitor)

type CAssignExpr

type CAssignExpr struct {
	Stmt *CAssignStmt
}

func (*CAssignExpr) AsExpr

func (e *CAssignExpr) AsExpr() GoExpr

func (*CAssignExpr) CType

func (e *CAssignExpr) CType(types.Type) types.Type

func (*CAssignExpr) HasSideEffects

func (e *CAssignExpr) HasSideEffects() bool

func (*CAssignExpr) IsConst

func (e *CAssignExpr) IsConst() bool

func (*CAssignExpr) ToStmt

func (e *CAssignExpr) ToStmt() []CStmt

func (*CAssignExpr) Uses

func (e *CAssignExpr) Uses() []types.Usage

func (*CAssignExpr) Visit

func (e *CAssignExpr) Visit(v Visitor)

type CAssignStmt

type CAssignStmt struct {
	Left  Expr
	Op    BinaryOp
	Right Expr
	// contains filtered or unexported fields
}

func (*CAssignStmt) AsStmt

func (s *CAssignStmt) AsStmt() []GoStmt

func (*CAssignStmt) Uses

func (s *CAssignStmt) Uses() []types.Usage

func (*CAssignStmt) Visit

func (s *CAssignStmt) Visit(v Visitor)

type CBinaryExpr

type CBinaryExpr struct {
	Left  Expr
	Op    BinaryOp
	Right Expr
}

func (*CBinaryExpr) AsExpr

func (e *CBinaryExpr) AsExpr() GoExpr

func (*CBinaryExpr) CType

func (e *CBinaryExpr) CType(exp types.Type) types.Type

func (*CBinaryExpr) HasSideEffects

func (e *CBinaryExpr) HasSideEffects() bool

func (*CBinaryExpr) IsConst

func (e *CBinaryExpr) IsConst() bool

func (*CBinaryExpr) Uses

func (e *CBinaryExpr) Uses() []types.Usage

func (*CBinaryExpr) Visit

func (e *CBinaryExpr) Visit(v Visitor)

type CBreakStmt

type CBreakStmt struct{}

func (*CBreakStmt) AsStmt

func (s *CBreakStmt) AsStmt() []GoStmt

func (*CBreakStmt) Uses

func (s *CBreakStmt) Uses() []types.Usage

func (*CBreakStmt) Visit

func (s *CBreakStmt) Visit(v Visitor)

type CCaseStmt

type CCaseStmt struct {
	Expr  Expr
	Stmts []CStmt
	// contains filtered or unexported fields
}

func (*CCaseStmt) AsStmt

func (s *CCaseStmt) AsStmt() []GoStmt

func (*CCaseStmt) GoCaseClause

func (s *CCaseStmt) GoCaseClause() *ast.CaseClause

func (*CCaseStmt) Uses

func (s *CCaseStmt) Uses() []types.Usage

func (*CCaseStmt) Visit

func (s *CCaseStmt) Visit(v Visitor)

type CCastExpr

type CCastExpr struct {
	Assert bool
	Expr   Expr
	Type   types.Type
}

func (*CCastExpr) AsExpr

func (e *CCastExpr) AsExpr() GoExpr

func (*CCastExpr) CType

func (e *CCastExpr) CType(_ types.Type) types.Type

func (*CCastExpr) HasSideEffects

func (e *CCastExpr) HasSideEffects() bool

func (*CCastExpr) IsConst

func (e *CCastExpr) IsConst() bool

func (*CCastExpr) Uses

func (e *CCastExpr) Uses() []types.Usage

func (*CCastExpr) Visit

func (e *CCastExpr) Visit(v Visitor)

type CCompLitExpr

type CCompLitExpr struct {
	Type   types.Type
	Fields []*CompLitField
}

func (*CCompLitExpr) AsExpr

func (e *CCompLitExpr) AsExpr() GoExpr

func (*CCompLitExpr) CType

func (e *CCompLitExpr) CType(types.Type) types.Type

func (*CCompLitExpr) HasSideEffects

func (e *CCompLitExpr) HasSideEffects() bool

func (*CCompLitExpr) IsConst

func (e *CCompLitExpr) IsConst() bool

func (*CCompLitExpr) Uses

func (e *CCompLitExpr) Uses() []types.Usage

func (*CCompLitExpr) Visit

func (e *CCompLitExpr) Visit(v Visitor)

type CCompStmt

type CCompStmt interface {
	CStmt
	EachStmt(fnc CStmtFunc) bool
}

type CContinueStmt

type CContinueStmt struct{}

func (*CContinueStmt) AsStmt

func (s *CContinueStmt) AsStmt() []GoStmt

func (*CContinueStmt) Uses

func (s *CContinueStmt) Uses() []types.Usage

func (*CContinueStmt) Visit

func (s *CContinueStmt) Visit(v Visitor)

type CDecl

type CDecl interface {
	Node
	AsDecl() []GoDecl
	Uses() []types.Usage
}

func TranslateCAST

func TranslateCAST(fname string, tu *cc.AST, env *libs.Env, conf Config) ([]CDecl, error)

TranslateCAST takes a C translation unit and converts it to a list of cxgo declarations.

type CDeclStmt

type CDeclStmt struct {
	Decl CDecl
}

func (*CDeclStmt) AsStmt

func (s *CDeclStmt) AsStmt() []GoStmt

func (*CDeclStmt) Uses

func (s *CDeclStmt) Uses() []types.Usage

func (*CDeclStmt) Visit

func (s *CDeclStmt) Visit(v Visitor)

type CExprStmt

type CExprStmt struct {
	Expr Expr
}

func (*CExprStmt) AsExpr

func (s *CExprStmt) AsExpr() GoExpr

func (*CExprStmt) AsStmt

func (s *CExprStmt) AsStmt() []GoStmt

func (*CExprStmt) CType

func (s *CExprStmt) CType() types.Type

func (*CExprStmt) Uses

func (s *CExprStmt) Uses() []types.Usage

func (*CExprStmt) Visit

func (s *CExprStmt) Visit(v Visitor)

type CForStmt

type CForStmt struct {
	Init CStmt
	Cond Expr
	Iter CStmt
	Body BlockStmt
}

func (*CForStmt) AsStmt

func (s *CForStmt) AsStmt() []GoStmt

func (*CForStmt) EachStmt

func (s *CForStmt) EachStmt(fnc CStmtFunc) bool

func (*CForStmt) Uses

func (s *CForStmt) Uses() []types.Usage

func (*CForStmt) Visit

func (s *CForStmt) Visit(v Visitor)

type CFuncDecl

type CFuncDecl struct {
	Name  *types.Ident
	Type  *types.FuncType
	Body  *BlockStmt
	Range *Range
}

func (*CFuncDecl) AsDecl

func (d *CFuncDecl) AsDecl() []GoDecl

func (*CFuncDecl) Uses

func (d *CFuncDecl) Uses() []types.Usage

func (*CFuncDecl) Visit

func (d *CFuncDecl) Visit(v Visitor)

type CGotoStmt

type CGotoStmt struct {
	Label string
}

func (*CGotoStmt) AsStmt

func (s *CGotoStmt) AsStmt() []GoStmt

func (*CGotoStmt) Uses

func (s *CGotoStmt) Uses() []types.Usage

func (*CGotoStmt) Visit

func (s *CGotoStmt) Visit(v Visitor)

type CIfStmt

type CIfStmt struct {
	Cond BoolExpr
	Then *BlockStmt
	Else IfElseStmt
	// contains filtered or unexported fields
}

func (*CIfStmt) AsStmt

func (s *CIfStmt) AsStmt() []GoStmt

func (*CIfStmt) EachStmt

func (s *CIfStmt) EachStmt(fnc CStmtFunc) bool

func (*CIfStmt) Uses

func (s *CIfStmt) Uses() []types.Usage

func (*CIfStmt) Visit

func (s *CIfStmt) Visit(v Visitor)

type CIncrExpr

type CIncrExpr struct {
	Expr   Expr
	Prefix bool
	Decr   bool
	// contains filtered or unexported fields
}

func (*CIncrExpr) AsExpr

func (e *CIncrExpr) AsExpr() GoExpr

func (*CIncrExpr) CType

func (e *CIncrExpr) CType(types.Type) types.Type

func (*CIncrExpr) HasSideEffects

func (e *CIncrExpr) HasSideEffects() bool

func (*CIncrExpr) IsConst

func (e *CIncrExpr) IsConst() bool

func (*CIncrExpr) ToStmt

func (e *CIncrExpr) ToStmt() []CStmt

func (*CIncrExpr) Uses

func (e *CIncrExpr) Uses() []types.Usage

func (*CIncrExpr) Visit

func (e *CIncrExpr) Visit(v Visitor)

type CIncrStmt

type CIncrStmt struct {
	Expr Expr
	Decr bool
	// contains filtered or unexported fields
}

func (*CIncrStmt) AsStmt

func (s *CIncrStmt) AsStmt() []GoStmt

func (*CIncrStmt) Uses

func (s *CIncrStmt) Uses() []types.Usage

func (*CIncrStmt) Visit

func (s *CIncrStmt) Visit(v Visitor)

type CIndexExpr

type CIndexExpr struct {
	Expr  Expr
	Index Expr
	// contains filtered or unexported fields
}

func (*CIndexExpr) AsExpr

func (e *CIndexExpr) AsExpr() GoExpr

func (*CIndexExpr) CType

func (e *CIndexExpr) CType(types.Type) types.Type

func (*CIndexExpr) HasSideEffects

func (e *CIndexExpr) HasSideEffects() bool

func (*CIndexExpr) IndexZero

func (e *CIndexExpr) IndexZero() bool

func (*CIndexExpr) IsConst

func (e *CIndexExpr) IsConst() bool

func (*CIndexExpr) Uses

func (e *CIndexExpr) Uses() []types.Usage

func (*CIndexExpr) Visit

func (e *CIndexExpr) Visit(v Visitor)

type CLabelStmt

type CLabelStmt struct {
	Label string
}

func (*CLabelStmt) AsStmt

func (s *CLabelStmt) AsStmt() []GoStmt

func (*CLabelStmt) Uses

func (s *CLabelStmt) Uses() []types.Usage

func (*CLabelStmt) Visit

func (s *CLabelStmt) Visit(v Visitor)

type CLitKind

type CLitKind int

type CLiteral

type CLiteral struct {
	Value string
	Kind  CLitKind
	Type  types.Type
}

func (*CLiteral) AsExpr

func (e *CLiteral) AsExpr() GoExpr

func (*CLiteral) CType

func (e *CLiteral) CType(types.Type) types.Type

func (*CLiteral) HasSideEffects

func (e *CLiteral) HasSideEffects() bool

func (*CLiteral) IsConst

func (e *CLiteral) IsConst() bool

func (*CLiteral) Uses

func (e *CLiteral) Uses() []types.Usage

func (*CLiteral) Visit

func (*CLiteral) Visit(v Visitor)

type CMultiExpr

type CMultiExpr struct {
	Exprs []Expr
	// contains filtered or unexported fields
}

CMultiExpr is a list of C expressions executed one by one, and returning the result of the last one.

func (*CMultiExpr) AsExpr

func (e *CMultiExpr) AsExpr() GoExpr

func (*CMultiExpr) CType

func (e *CMultiExpr) CType(exp types.Type) types.Type

func (*CMultiExpr) HasSideEffects

func (e *CMultiExpr) HasSideEffects() bool

func (*CMultiExpr) IsConst

func (e *CMultiExpr) IsConst() bool

func (*CMultiExpr) Uses

func (e *CMultiExpr) Uses() []types.Usage

func (*CMultiExpr) Visit

func (e *CMultiExpr) Visit(v Visitor)

type CParentExpr

type CParentExpr struct {
	Expr Expr
}

func (*CParentExpr) AsExpr

func (e *CParentExpr) AsExpr() GoExpr

func (*CParentExpr) CType

func (e *CParentExpr) CType(types.Type) types.Type

func (*CParentExpr) HasSideEffects

func (e *CParentExpr) HasSideEffects() bool

func (*CParentExpr) IsConst

func (e *CParentExpr) IsConst() bool

func (*CParentExpr) Uses

func (e *CParentExpr) Uses() []types.Usage

func (*CParentExpr) Visit

func (e *CParentExpr) Visit(v Visitor)

type CReturnStmt

type CReturnStmt struct {
	Expr Expr
}

func (*CReturnStmt) AsStmt

func (s *CReturnStmt) AsStmt() []GoStmt

func (*CReturnStmt) Uses

func (s *CReturnStmt) Uses() []types.Usage

func (*CReturnStmt) Visit

func (s *CReturnStmt) Visit(v Visitor)

type CSelectExpr

type CSelectExpr struct {
	Expr Expr
	Sel  *types.Ident
}

func (*CSelectExpr) AsExpr

func (e *CSelectExpr) AsExpr() GoExpr

func (*CSelectExpr) CType

func (e *CSelectExpr) CType(exp types.Type) types.Type

func (*CSelectExpr) HasSideEffects

func (e *CSelectExpr) HasSideEffects() bool

func (*CSelectExpr) IsConst

func (e *CSelectExpr) IsConst() bool

func (*CSelectExpr) Uses

func (e *CSelectExpr) Uses() []types.Usage

func (*CSelectExpr) Visit

func (e *CSelectExpr) Visit(v Visitor)

type CSizeofExpr

type CSizeofExpr struct {
	Type types.Type
	// contains filtered or unexported fields
}

func (*CSizeofExpr) AsExpr

func (e *CSizeofExpr) AsExpr() GoExpr

func (*CSizeofExpr) CType

func (e *CSizeofExpr) CType(types.Type) types.Type

func (*CSizeofExpr) HasSideEffects

func (e *CSizeofExpr) HasSideEffects() bool

func (*CSizeofExpr) IsConst

func (e *CSizeofExpr) IsConst() bool

func (*CSizeofExpr) Uses

func (e *CSizeofExpr) Uses() []types.Usage

func (*CSizeofExpr) Visit

func (e *CSizeofExpr) Visit(v Visitor)

type CStmt

type CStmt interface {
	Node
	AsStmt() []GoStmt
	Uses() []types.Usage
}

func NewCExprStmt

func NewCExprStmt(e Expr) []CStmt

func NewCExprStmt1

func NewCExprStmt1(e Expr) CStmt

type CStmtConv

type CStmtConv interface {
	ToStmt() []CStmt
}

type CStmtFunc

type CStmtFunc func(s CStmt) ([]CStmt, bool)

type CSwitchStmt

type CSwitchStmt struct {
	Cond  Expr
	Cases []*CCaseStmt
	// contains filtered or unexported fields
}

func (*CSwitchStmt) AsStmt

func (s *CSwitchStmt) AsStmt() []GoStmt

func (*CSwitchStmt) EachStmt

func (s *CSwitchStmt) EachStmt(fnc CStmtFunc) bool

func (*CSwitchStmt) Uses

func (s *CSwitchStmt) Uses() []types.Usage

func (*CSwitchStmt) Visit

func (s *CSwitchStmt) Visit(v Visitor)

type CTernaryExpr

type CTernaryExpr struct {
	Cond BoolExpr
	Then Expr
	Else Expr
	// contains filtered or unexported fields
}

func (*CTernaryExpr) AsExpr

func (e *CTernaryExpr) AsExpr() GoExpr

func (*CTernaryExpr) CType

func (e *CTernaryExpr) CType(types.Type) types.Type

func (*CTernaryExpr) HasSideEffects

func (e *CTernaryExpr) HasSideEffects() bool

func (*CTernaryExpr) IsConst

func (e *CTernaryExpr) IsConst() bool

func (*CTernaryExpr) ToStmt

func (e *CTernaryExpr) ToStmt() []CStmt

func (*CTernaryExpr) Uses

func (e *CTernaryExpr) Uses() []types.Usage

func (*CTernaryExpr) Visit

func (e *CTernaryExpr) Visit(v Visitor)

type CTypeDef

type CTypeDef struct {
	types.Named
}

func (*CTypeDef) AsDecl

func (d *CTypeDef) AsDecl() []GoDecl

func (*CTypeDef) Uses

func (d *CTypeDef) Uses() []types.Usage

func (*CTypeDef) Visit

func (d *CTypeDef) Visit(v Visitor)

type CUnaryExpr

type CUnaryExpr struct {
	Op   UnaryOp
	Expr Expr
	// contains filtered or unexported fields
}

func (*CUnaryExpr) AsExpr

func (e *CUnaryExpr) AsExpr() GoExpr

func (*CUnaryExpr) CType

func (e *CUnaryExpr) CType(exp types.Type) types.Type

func (*CUnaryExpr) HasSideEffects

func (e *CUnaryExpr) HasSideEffects() bool

func (*CUnaryExpr) IsConst

func (e *CUnaryExpr) IsConst() bool

func (*CUnaryExpr) Uses

func (e *CUnaryExpr) Uses() []types.Usage

func (*CUnaryExpr) Visit

func (e *CUnaryExpr) Visit(v Visitor)

type CVarDecl

type CVarDecl struct {
	Const  bool
	Single bool
	CVarSpec
}

func (*CVarDecl) AsDecl

func (d *CVarDecl) AsDecl() []GoDecl

func (*CVarDecl) GoField

func (d *CVarDecl) GoField() *GoField

func (*CVarDecl) Visit

func (d *CVarDecl) Visit(v Visitor)

type CVarSpec

type CVarSpec struct {
	Type  types.Type
	Names []*types.Ident
	Inits []Expr
	// contains filtered or unexported fields
}

func (*CVarSpec) GoSpecs

func (d *CVarSpec) GoSpecs(isConst bool) *ast.ValueSpec

func (*CVarSpec) Uses

func (d *CVarSpec) Uses() []types.Usage

func (*CVarSpec) Visit

func (d *CVarSpec) Visit(v Visitor)

type CallExpr

type CallExpr struct {
	Fun  FuncExpr
	Args []Expr
}

func (*CallExpr) AsExpr

func (e *CallExpr) AsExpr() GoExpr

func (*CallExpr) CType

func (e *CallExpr) CType(types.Type) types.Type

func (*CallExpr) HasSideEffects

func (e *CallExpr) HasSideEffects() bool

func (*CallExpr) IsConst

func (e *CallExpr) IsConst() bool

func (*CallExpr) Uses

func (e *CallExpr) Uses() []types.Usage

func (*CallExpr) Visit

func (e *CallExpr) Visit(v Visitor)

type CodeBlock

type CodeBlock struct {
	BaseBlock
	Stmts []CStmt
	Next  Block
}

func (*CodeBlock) NextBlocks

func (b *CodeBlock) NextBlocks() []Block

func (*CodeBlock) ReplaceNext

func (b *CodeBlock) ReplaceNext(old, rep Block)

type CompLitField

type CompLitField struct {
	Index Expr
	Field *types.Ident
	Value Expr
}

func (*CompLitField) Visit

func (e *CompLitField) Visit(v Visitor)

type Comparison

type Comparison struct {
	X  Expr
	Op ComparisonOp
	Y  Expr
	// contains filtered or unexported fields
}

func (*Comparison) AsExpr

func (e *Comparison) AsExpr() GoExpr

func (*Comparison) CType

func (e *Comparison) CType(types.Type) types.Type

func (*Comparison) HasSideEffects

func (e *Comparison) HasSideEffects() bool

func (*Comparison) IsConst

func (e *Comparison) IsConst() bool

func (*Comparison) Negate

func (e *Comparison) Negate() BoolExpr

func (*Comparison) Uses

func (e *Comparison) Uses() []types.Usage

func (*Comparison) Visit

func (e *Comparison) Visit(v Visitor)

type ComparisonOp

type ComparisonOp string

ComparisonOp is a comparison operator.

const (
	BinOpEq  ComparisonOp = "=="
	BinOpNeq ComparisonOp = "!="
	BinOpLt  ComparisonOp = "<"
	BinOpGt  ComparisonOp = ">"
	BinOpLte ComparisonOp = "<="
	BinOpGte ComparisonOp = ">="
)

func (ComparisonOp) GoToken

func (op ComparisonOp) GoToken() token.Token

func (ComparisonOp) IsEquality

func (op ComparisonOp) IsEquality() bool

func (ComparisonOp) IsRelational

func (op ComparisonOp) IsRelational() bool

func (ComparisonOp) Negate

func (op ComparisonOp) Negate() ComparisonOp

type CondBlock

type CondBlock struct {
	BaseBlock
	Expr Expr
	Then Block
	Else Block
}

func NewCondBlock

func NewCondBlock(expr Expr, then, els Block) *CondBlock

func (*CondBlock) NextBlocks

func (b *CondBlock) NextBlocks() []Block

func (*CondBlock) ReplaceNext

func (b *CondBlock) ReplaceNext(old, rep Block)

type Config

type Config struct {
	Root               string
	Package            string
	GoFile             string
	GoFilePref         string
	Include            []string
	SysInclude         []string
	MaxDecls           int
	Predef             string
	Define             []Define
	FlattenAll         bool
	ForwardDecl        bool
	SkipDecl           map[string]bool
	Idents             []IdentConfig
	Replace            []Replacer
	Hooks              bool
	FixImplicitReturns bool
	IgnoreIncludeDir   bool
	UnexportedFields   bool // do not export struct fields for Go
}

type ControlFlow

type ControlFlow struct {
	Start Block
	// contains filtered or unexported fields
}

func (*ControlFlow) Dom

func (cf *ControlFlow) Dom(a, b Block) bool

func (*ControlFlow) Flatten

func (cf *ControlFlow) Flatten() []CStmt

func (*ControlFlow) IDom

func (cf *ControlFlow) IDom(a Block) Block

func (*ControlFlow) SDom

func (cf *ControlFlow) SDom(a, b Block) bool

type Define

type Define struct {
	Name  string `yaml:"name" json:"name"`
	Value string `yaml:"value" json:"value"`
}

type Deref

type Deref struct {
	X PtrExpr
	// contains filtered or unexported fields
}

func (*Deref) AsExpr

func (e *Deref) AsExpr() GoExpr

func (*Deref) CType

func (e *Deref) CType(types.Type) types.Type

func (*Deref) HasSideEffects

func (e *Deref) HasSideEffects() bool

func (*Deref) IsConst

func (e *Deref) IsConst() bool

func (*Deref) Uses

func (e *Deref) Uses() []types.Usage

func (*Deref) Visit

func (e *Deref) Visit(v Visitor)

type ExpandExpr

type ExpandExpr struct {
	X Expr
}

func (*ExpandExpr) AsExpr

func (e *ExpandExpr) AsExpr() GoExpr

func (*ExpandExpr) CType

func (e *ExpandExpr) CType(_ types.Type) types.Type

func (*ExpandExpr) HasSideEffects

func (e *ExpandExpr) HasSideEffects() bool

func (*ExpandExpr) IsConst

func (e *ExpandExpr) IsConst() bool

func (*ExpandExpr) Uses

func (e *ExpandExpr) Uses() []types.Usage

func (*ExpandExpr) Visit

func (e *ExpandExpr) Visit(v Visitor)

type Expr

type Expr interface {
	Node
	// CType returns a type of this expression, given an expected type from the parent.
	// If any type is acceptable, pass nil.
	CType(exp types.Type) types.Type
	AsExpr() GoExpr
	IsConst() bool
	HasSideEffects() bool
	Uses() []types.Usage
}

func NewCSelectExpr

func NewCSelectExpr(x Expr, f *types.Ident) Expr

type FileError added in v0.3.7

type FileError struct {
	Err   error
	Where token.Position
}

func (*FileError) Error added in v0.3.7

func (e *FileError) Error() string

func (*FileError) Unwrap added in v0.3.7

func (e *FileError) Unwrap() error

type FloatLit

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

func (FloatLit) AsExpr

func (l FloatLit) AsExpr() GoExpr

func (FloatLit) CType

func (l FloatLit) CType(exp types.Type) types.Type

func (FloatLit) HasSideEffects

func (l FloatLit) HasSideEffects() bool

func (FloatLit) IsConst

func (l FloatLit) IsConst() bool

func (FloatLit) IsNegative added in v0.3.7

func (l FloatLit) IsNegative() bool

func (FloatLit) IsOne

func (l FloatLit) IsOne() bool

func (FloatLit) IsZero

func (l FloatLit) IsZero() bool

func (FloatLit) Negate

func (l FloatLit) Negate() Number

func (FloatLit) Uses

func (l FloatLit) Uses() []types.Usage

func (FloatLit) Visit

func (FloatLit) Visit(v Visitor)

type FuncAssert

type FuncAssert struct {
	X Expr
}

func (FuncAssert) AsExpr

func (e FuncAssert) AsExpr() GoExpr

func (FuncAssert) CType

func (e FuncAssert) CType(types.Type) types.Type

func (FuncAssert) FuncType

func (e FuncAssert) FuncType(*types.FuncType) *types.FuncType

func (FuncAssert) HasSideEffects

func (e FuncAssert) HasSideEffects() bool

func (FuncAssert) IsConst

func (e FuncAssert) IsConst() bool

func (FuncAssert) Uses

func (e FuncAssert) Uses() []types.Usage

func (FuncAssert) Visit

func (e FuncAssert) Visit(v Visitor)

type FuncComparison

type FuncComparison struct {
	X  FuncExpr
	Op ComparisonOp
	Y  FuncExpr
}

func (*FuncComparison) AsExpr

func (e *FuncComparison) AsExpr() GoExpr

func (*FuncComparison) CType

func (e *FuncComparison) CType(types.Type) types.Type

func (*FuncComparison) HasSideEffects

func (e *FuncComparison) HasSideEffects() bool

func (*FuncComparison) IsConst

func (e *FuncComparison) IsConst() bool

func (*FuncComparison) Negate

func (e *FuncComparison) Negate() BoolExpr

func (*FuncComparison) Uses

func (e *FuncComparison) Uses() []types.Usage

func (*FuncComparison) Visit

func (e *FuncComparison) Visit(v Visitor)

type FuncExpr

type FuncExpr interface {
	Expr
	// FuncType return an underlying function type.
	FuncType(exp *types.FuncType) *types.FuncType
}

FuncExpr is an expression that returns a function value.

type FuncIdent

type FuncIdent struct {
	*types.Ident
}

func (FuncIdent) AsExpr

func (e FuncIdent) AsExpr() GoExpr

func (FuncIdent) FuncType

func (e FuncIdent) FuncType(exp *types.FuncType) *types.FuncType

func (FuncIdent) HasSideEffects

func (e FuncIdent) HasSideEffects() bool

func (FuncIdent) Identifier

func (e FuncIdent) Identifier() *types.Ident

func (FuncIdent) IsConst

func (e FuncIdent) IsConst() bool

func (FuncIdent) Uses

func (e FuncIdent) Uses() []types.Usage

func (FuncIdent) Visit

func (FuncIdent) Visit(v Visitor)

type FuncLit

type FuncLit struct {
	Type *types.FuncType
	Body *BlockStmt
}

func (*FuncLit) AsExpr

func (e *FuncLit) AsExpr() GoExpr

func (*FuncLit) CType

func (e *FuncLit) CType(types.Type) types.Type

func (*FuncLit) FuncType

func (e *FuncLit) FuncType(*types.FuncType) *types.FuncType

func (*FuncLit) HasSideEffects

func (e *FuncLit) HasSideEffects() bool

func (*FuncLit) IsConst

func (e *FuncLit) IsConst() bool

func (*FuncLit) Uses

func (e *FuncLit) Uses() []types.Usage

func (*FuncLit) Visit

func (e *FuncLit) Visit(v Visitor)

type FuncToInt

type FuncToInt struct {
	X  FuncExpr
	To types.IntType
}

func (*FuncToInt) AsExpr

func (e *FuncToInt) AsExpr() GoExpr

func (*FuncToInt) CType

func (e *FuncToInt) CType(types.Type) types.Type

func (*FuncToInt) HasSideEffects

func (e *FuncToInt) HasSideEffects() bool

func (*FuncToInt) IsConst

func (e *FuncToInt) IsConst() bool

func (*FuncToInt) Uses

func (e *FuncToInt) Uses() []types.Usage

func (*FuncToInt) Visit

func (e *FuncToInt) Visit(v Visitor)

type FuncToPtr

type FuncToPtr struct {
	X FuncExpr
	// contains filtered or unexported fields
}

func (*FuncToPtr) AsExpr

func (e *FuncToPtr) AsExpr() GoExpr

func (*FuncToPtr) CType

func (e *FuncToPtr) CType(types.Type) types.Type

func (*FuncToPtr) HasSideEffects

func (e *FuncToPtr) HasSideEffects() bool

func (*FuncToPtr) IsConst

func (e *FuncToPtr) IsConst() bool

func (*FuncToPtr) PtrType

func (e *FuncToPtr) PtrType(types.PtrType) types.PtrType

func (*FuncToPtr) Uses

func (e *FuncToPtr) Uses() []types.Usage

func (*FuncToPtr) Visit

func (e *FuncToPtr) Visit(v Visitor)

type GoDecl

type GoDecl = ast.Decl

func ImportsFor added in v0.3.6

func ImportsFor(e *libs.Env, decls []GoDecl) []GoDecl

ImportsFor generates import specs for well-known imports required for given declarations.

func TranslateAST

func TranslateAST(fname string, tu *cc.AST, env *libs.Env, conf Config) ([]GoDecl, error)

TranslateAST takes a C translation unit and converts it to a list of Go declarations.

type GoExpr

type GoExpr = ast.Expr

type GoField

type GoField = ast.Field

type GoStmt

type GoStmt = ast.Stmt

type GoType

type GoType = ast.Expr

type Ident

type Ident interface {
	Expr
	Identifier() *types.Ident
}

type IdentConfig

type IdentConfig struct {
	Name    string        `yaml:"name" json:"name"`       // identifier name in C
	Index   int           `yaml:"index" json:"index"`     // argument index, only for Fields in the function decl
	Rename  string        `yaml:"rename" json:"rename"`   // rename the identifier
	Alias   bool          `yaml:"alias" json:"alias"`     // omit declaration, use underlying type instead
	Type    TypeHint      `yaml:"type" json:"type"`       // changes the Go type of this identifier
	Flatten *bool         `yaml:"flatten" json:"flatten"` // flattens function control flow to workaround invalid gotos
	Fields  []IdentConfig `yaml:"fields" json:"fields"`   // configs for struct fields or func arguments
}

type IdentExpr

type IdentExpr struct {
	*types.Ident
}

func (IdentExpr) AsExpr

func (e IdentExpr) AsExpr() GoExpr

func (IdentExpr) HasSideEffects

func (e IdentExpr) HasSideEffects() bool

func (IdentExpr) Identifier

func (e IdentExpr) Identifier() *types.Ident

func (IdentExpr) IsConst

func (e IdentExpr) IsConst() bool

func (IdentExpr) Uses

func (e IdentExpr) Uses() []types.Usage

func (IdentExpr) Visit

func (e IdentExpr) Visit(v Visitor)

type IfElseStmt

type IfElseStmt interface {
	CStmt
	// contains filtered or unexported methods
}

type IntLit

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

func (IntLit) AsExpr

func (l IntLit) AsExpr() GoExpr

func (IntLit) CType

func (l IntLit) CType(exp types.Type) types.Type

func (IntLit) HasSideEffects

func (IntLit) HasSideEffects() bool

func (IntLit) Int

func (l IntLit) Int() int64

func (IntLit) IsConst

func (IntLit) IsConst() bool

func (IntLit) IsNeg

func (l IntLit) IsNeg() bool

func (IntLit) IsNegative added in v0.3.7

func (l IntLit) IsNegative() bool

func (IntLit) IsOne

func (l IntLit) IsOne() bool

func (IntLit) IsUint

func (l IntLit) IsUint() bool

func (IntLit) IsZero

func (l IntLit) IsZero() bool

func (IntLit) MulLit

func (l IntLit) MulLit(v int64) IntLit

func (IntLit) Negate

func (l IntLit) Negate() Number

func (IntLit) NegateLit

func (l IntLit) NegateLit() IntLit

func (IntLit) OverflowInt

func (l IntLit) OverflowInt(sz int) IntLit

func (IntLit) OverflowUint

func (l IntLit) OverflowUint(sz int) IntLit

func (IntLit) String

func (l IntLit) String() string

func (IntLit) Uint

func (l IntLit) Uint() uint64

func (IntLit) Uses

func (l IntLit) Uses() []types.Usage

func (IntLit) Visit

func (IntLit) Visit(v Visitor)

type IntToFunc

type IntToFunc struct {
	X  Expr
	To *types.FuncType
}

func (*IntToFunc) AsExpr

func (e *IntToFunc) AsExpr() GoExpr

func (*IntToFunc) CType

func (e *IntToFunc) CType(types.Type) types.Type

func (*IntToFunc) FuncType

func (e *IntToFunc) FuncType(*types.FuncType) *types.FuncType

func (*IntToFunc) HasSideEffects

func (e *IntToFunc) HasSideEffects() bool

func (*IntToFunc) IsConst

func (e *IntToFunc) IsConst() bool

func (*IntToFunc) Uses

func (e *IntToFunc) Uses() []types.Usage

func (*IntToFunc) Visit

func (e *IntToFunc) Visit(v Visitor)

type IntToPtr

type IntToPtr struct {
	X  Expr
	To types.PtrType
}

func (*IntToPtr) AsExpr

func (e *IntToPtr) AsExpr() GoExpr

func (*IntToPtr) CType

func (e *IntToPtr) CType(types.Type) types.Type

func (*IntToPtr) HasSideEffects

func (e *IntToPtr) HasSideEffects() bool

func (*IntToPtr) IsConst

func (e *IntToPtr) IsConst() bool

func (*IntToPtr) PtrType

func (e *IntToPtr) PtrType(types.PtrType) types.PtrType

func (*IntToPtr) Uses

func (e *IntToPtr) Uses() []types.Usage

func (*IntToPtr) Visit

func (e *IntToPtr) Visit(v Visitor)

type MakeExpr

type MakeExpr struct {
	Elem types.Type
	Size Expr
	Cap  Expr
	// contains filtered or unexported fields
}

func (*MakeExpr) AsExpr

func (e *MakeExpr) AsExpr() GoExpr

func (*MakeExpr) CType

func (e *MakeExpr) CType(_ types.Type) types.Type

func (*MakeExpr) HasSideEffects

func (e *MakeExpr) HasSideEffects() bool

func (*MakeExpr) IsConst

func (e *MakeExpr) IsConst() bool

func (*MakeExpr) Uses

func (e *MakeExpr) Uses() []types.Usage

func (*MakeExpr) Visit

func (e *MakeExpr) Visit(v Visitor)

type NewExpr

type NewExpr struct {
	Elem types.Type
	// contains filtered or unexported fields
}

func (*NewExpr) AsExpr

func (e *NewExpr) AsExpr() GoExpr

func (*NewExpr) CType

func (e *NewExpr) CType(_ types.Type) types.Type

func (*NewExpr) HasSideEffects

func (e *NewExpr) HasSideEffects() bool

func (*NewExpr) IsConst

func (e *NewExpr) IsConst() bool

func (*NewExpr) PtrType

func (e *NewExpr) PtrType(_ types.PtrType) types.PtrType

func (*NewExpr) Uses

func (e *NewExpr) Uses() []types.Usage

func (*NewExpr) Visit

func (e *NewExpr) Visit(_ Visitor)

type Nil

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

func NewNil

func NewNil(size int) Nil

func (Nil) AsExpr

func (Nil) AsExpr() GoExpr

func (Nil) CType

func (e Nil) CType(exp types.Type) types.Type

func (Nil) FuncType

func (e Nil) FuncType(exp *types.FuncType) *types.FuncType

func (Nil) HasSideEffects

func (Nil) HasSideEffects() bool

func (Nil) IsConst

func (Nil) IsConst() bool

func (Nil) PtrType

func (e Nil) PtrType(exp types.PtrType) types.PtrType

func (Nil) Uses

func (e Nil) Uses() []types.Usage

func (Nil) Visit

func (Nil) Visit(v Visitor)

type Node

type Node interface {
	// Visit calls the provided interface for all child nodes.
	// It's the visitor's responsibility to recurse by calling n.Visit(v).
	Visit(v Visitor)
}

type Not

type Not struct {
	X BoolExpr
}

Not negates a bool expression. It's only useful for identifiers and function calls.

func (*Not) AsExpr

func (e *Not) AsExpr() GoExpr

func (*Not) CType

func (e *Not) CType(types.Type) types.Type

func (*Not) HasSideEffects

func (e *Not) HasSideEffects() bool

func (*Not) IsConst

func (e *Not) IsConst() bool

func (*Not) Negate

func (e *Not) Negate() BoolExpr

func (*Not) Uses

func (e *Not) Uses() []types.Usage

func (*Not) Visit

func (e *Not) Visit(v Visitor)

type Number

type Number interface {
	Expr
	IsZero() bool
	IsOne() bool
	IsNegative() bool
	Negate() Number
}

type ParseConfig

type ParseConfig struct {
	WorkDir     string
	Includes    []string
	SysIncludes []string
	Predefines  bool
	Define      []Define
	Sources     []cc.Source
}

type PtrAssert

type PtrAssert struct {
	X Expr
}

func (PtrAssert) AsExpr

func (e PtrAssert) AsExpr() GoExpr

func (PtrAssert) CType

func (e PtrAssert) CType(types.Type) types.Type

func (PtrAssert) HasSideEffects

func (e PtrAssert) HasSideEffects() bool

func (PtrAssert) IsConst

func (e PtrAssert) IsConst() bool

func (PtrAssert) PtrType

func (e PtrAssert) PtrType(types.PtrType) types.PtrType

func (PtrAssert) Uses

func (e PtrAssert) Uses() []types.Usage

func (PtrAssert) Visit

func (e PtrAssert) Visit(v Visitor)

type PtrComparison

type PtrComparison struct {
	X  PtrExpr
	Op ComparisonOp
	Y  PtrExpr
}

func (*PtrComparison) AsExpr

func (e *PtrComparison) AsExpr() GoExpr

func (*PtrComparison) CType

func (e *PtrComparison) CType(types.Type) types.Type

func (*PtrComparison) HasSideEffects

func (e *PtrComparison) HasSideEffects() bool

func (*PtrComparison) IsConst

func (e *PtrComparison) IsConst() bool

func (*PtrComparison) Negate

func (e *PtrComparison) Negate() BoolExpr

func (*PtrComparison) Uses

func (e *PtrComparison) Uses() []types.Usage

func (*PtrComparison) Visit

func (e *PtrComparison) Visit(v Visitor)

type PtrDiff

type PtrDiff struct {
	X PtrExpr
	Y PtrExpr
}

func (*PtrDiff) AsExpr

func (e *PtrDiff) AsExpr() GoExpr

func (*PtrDiff) CType

func (e *PtrDiff) CType(exp types.Type) types.Type

func (*PtrDiff) HasSideEffects

func (e *PtrDiff) HasSideEffects() bool

func (*PtrDiff) IsConst

func (e *PtrDiff) IsConst() bool

func (*PtrDiff) Uses

func (e *PtrDiff) Uses() []types.Usage

func (*PtrDiff) Visit

func (e *PtrDiff) Visit(v Visitor)

type PtrElemOffset

type PtrElemOffset struct {
	X    PtrExpr
	Ind  Expr
	Conv *types.PtrType
}

PtrElemOffset acts like a pointer arithmetic with a variable value. The index is always multiplied only by the pointer elements size, as opposed to PtrVarOffset. This operation is preferable over PtrVarOffset because the size of C and Go structs may not match.

func (*PtrElemOffset) AsExpr

func (e *PtrElemOffset) AsExpr() GoExpr

func (*PtrElemOffset) CType

func (e *PtrElemOffset) CType(exp types.Type) types.Type

func (*PtrElemOffset) HasSideEffects

func (e *PtrElemOffset) HasSideEffects() bool

func (*PtrElemOffset) IsConst

func (e *PtrElemOffset) IsConst() bool

func (*PtrElemOffset) PtrType

func (e *PtrElemOffset) PtrType(exp types.PtrType) types.PtrType

func (*PtrElemOffset) Uses

func (e *PtrElemOffset) Uses() []types.Usage

func (*PtrElemOffset) Visit

func (e *PtrElemOffset) Visit(v Visitor)

type PtrExpr

type PtrExpr interface {
	Expr
	// PtrType return an underlying pointer type.
	PtrType(exp types.PtrType) types.PtrType
}

PtrExpr is an expression that returns a pointer value.

type PtrIdent

type PtrIdent struct {
	*types.Ident
}

func (PtrIdent) AsExpr

func (e PtrIdent) AsExpr() GoExpr

func (PtrIdent) HasSideEffects

func (e PtrIdent) HasSideEffects() bool

func (PtrIdent) Identifier

func (e PtrIdent) Identifier() *types.Ident

func (PtrIdent) IsConst

func (e PtrIdent) IsConst() bool

func (PtrIdent) PtrType

func (e PtrIdent) PtrType(exp types.PtrType) types.PtrType

func (PtrIdent) Uses

func (e PtrIdent) Uses() []types.Usage

func (PtrIdent) Visit

func (PtrIdent) Visit(v Visitor)

type PtrOffset

type PtrOffset struct {
	X    PtrExpr
	Ind  int64
	Conv *types.PtrType
}

PtrOffset acts like a pointer arithmetic with a constant value. The index is NOT multiplied by the pointer element size. It optionally converts the pointer to Conv type.

func (*PtrOffset) AsExpr

func (e *PtrOffset) AsExpr() GoExpr

func (*PtrOffset) CType

func (e *PtrOffset) CType(exp types.Type) types.Type

func (*PtrOffset) HasSideEffects

func (e *PtrOffset) HasSideEffects() bool

func (*PtrOffset) IsConst

func (e *PtrOffset) IsConst() bool

func (*PtrOffset) PtrType

func (e *PtrOffset) PtrType(exp types.PtrType) types.PtrType

func (*PtrOffset) Uses

func (e *PtrOffset) Uses() []types.Usage

func (*PtrOffset) Visit

func (e *PtrOffset) Visit(v Visitor)

type PtrToFunc

type PtrToFunc struct {
	X  PtrExpr
	To *types.FuncType
}

func (*PtrToFunc) AsExpr

func (e *PtrToFunc) AsExpr() GoExpr

func (*PtrToFunc) CType

func (e *PtrToFunc) CType(types.Type) types.Type

func (*PtrToFunc) FuncType

func (e *PtrToFunc) FuncType(*types.FuncType) *types.FuncType

func (*PtrToFunc) HasSideEffects

func (e *PtrToFunc) HasSideEffects() bool

func (*PtrToFunc) IsConst

func (e *PtrToFunc) IsConst() bool

func (*PtrToFunc) Uses

func (e *PtrToFunc) Uses() []types.Usage

func (*PtrToFunc) Visit

func (e *PtrToFunc) Visit(v Visitor)

type PtrToInt

type PtrToInt struct {
	X  PtrExpr
	To types.Type
}

func (*PtrToInt) AsExpr

func (e *PtrToInt) AsExpr() GoExpr

func (*PtrToInt) CType

func (e *PtrToInt) CType(types.Type) types.Type

func (*PtrToInt) HasSideEffects

func (e *PtrToInt) HasSideEffects() bool

func (*PtrToInt) IsConst

func (e *PtrToInt) IsConst() bool

func (*PtrToInt) Uses

func (e *PtrToInt) Uses() []types.Usage

func (*PtrToInt) Visit

func (e *PtrToInt) Visit(v Visitor)

type PtrToPtr

type PtrToPtr struct {
	X  PtrExpr
	To types.PtrType
}

func (*PtrToPtr) AsExpr

func (e *PtrToPtr) AsExpr() GoExpr

func (*PtrToPtr) CType

func (e *PtrToPtr) CType(types.Type) types.Type

func (*PtrToPtr) HasSideEffects

func (e *PtrToPtr) HasSideEffects() bool

func (*PtrToPtr) IsConst

func (e *PtrToPtr) IsConst() bool

func (*PtrToPtr) PtrType

func (e *PtrToPtr) PtrType(types.PtrType) types.PtrType

func (*PtrToPtr) Uses

func (e *PtrToPtr) Uses() []types.Usage

func (*PtrToPtr) Visit

func (e *PtrToPtr) Visit(v Visitor)

type PtrVarOffset

type PtrVarOffset struct {
	X    PtrExpr
	Mul  int
	Ind  Expr
	Conv *types.PtrType
}

PtrVarOffset acts like a pointer arithmetic with a variable value. The index is multiplied only by a Mul, but not the pointer element size. It optionally converts the pointer to Conv type.

func (*PtrVarOffset) AsExpr

func (e *PtrVarOffset) AsExpr() GoExpr

func (*PtrVarOffset) CType

func (e *PtrVarOffset) CType(exp types.Type) types.Type

func (*PtrVarOffset) HasSideEffects

func (e *PtrVarOffset) HasSideEffects() bool

func (*PtrVarOffset) IsConst

func (e *PtrVarOffset) IsConst() bool

func (*PtrVarOffset) PtrType

func (e *PtrVarOffset) PtrType(exp types.PtrType) types.PtrType

func (*PtrVarOffset) Uses

func (e *PtrVarOffset) Uses() []types.Usage

func (*PtrVarOffset) Visit

func (e *PtrVarOffset) Visit(v Visitor)

type Range

type Range struct {
	Start     int
	StartLine int
	End       int
}

type Replacer

type Replacer struct {
	Old string
	Re  *regexp.Regexp
	New string
}

type ReturnBlock

type ReturnBlock struct {
	BaseBlock
	*CReturnStmt
}

func (*ReturnBlock) NextBlocks

func (b *ReturnBlock) NextBlocks() []Block

func (*ReturnBlock) ReplaceNext

func (b *ReturnBlock) ReplaceNext(old, rep Block)

type SliceExpr

type SliceExpr struct {
	Expr   Expr
	Low    Expr
	High   Expr
	Max    Expr
	Slice3 bool
}

func (*SliceExpr) AsExpr

func (e *SliceExpr) AsExpr() GoExpr

func (*SliceExpr) CType

func (e *SliceExpr) CType(exp types.Type) types.Type

func (*SliceExpr) HasSideEffects

func (e *SliceExpr) HasSideEffects() bool

func (*SliceExpr) IsConst

func (e *SliceExpr) IsConst() bool

func (*SliceExpr) Uses

func (e *SliceExpr) Uses() []types.Usage

func (*SliceExpr) Visit

func (e *SliceExpr) Visit(v Visitor)

type SourceConfig

type SourceConfig struct {
	Predef           string
	Define           []Define
	Include          []string
	SysInclude       []string
	IgnoreIncludeDir bool
}

type SrcFunc

type SrcFunc struct {
	File        string `json:"file,omitempty"`
	Line        int    `json:"line,omitempty"`
	OffsetStart int    `json:"offset_start,omitempty"`
	OffsetEnd   int    `json:"offset_end,omitempty"`
	Func        string `json:"func"`
	Src         string `json:"src,omitempty"`
	Proto       string `json:"proto,omitempty"`
}

func SourceFunc

func SourceFunc(fname string, src []byte, fd *CFuncDecl) SrcFunc

type StringLit

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

func (StringLit) AsExpr

func (l StringLit) AsExpr() GoExpr

func (StringLit) CType

func (l StringLit) CType(types.Type) types.Type

func (StringLit) HasSideEffects

func (l StringLit) HasSideEffects() bool

func (StringLit) IsConst

func (l StringLit) IsConst() bool

func (StringLit) IsWide

func (l StringLit) IsWide() bool

func (StringLit) String

func (l StringLit) String() string

func (StringLit) Uses

func (l StringLit) Uses() []types.Usage

func (StringLit) Value

func (l StringLit) Value() string

func (StringLit) Visit

func (StringLit) Visit(v Visitor)

type StringToPtr

type StringToPtr struct {
	X StringLit
	// contains filtered or unexported fields
}

func (*StringToPtr) AsExpr

func (e *StringToPtr) AsExpr() GoExpr

func (*StringToPtr) CType

func (e *StringToPtr) CType(exp types.Type) types.Type

func (*StringToPtr) HasSideEffects

func (e *StringToPtr) HasSideEffects() bool

func (*StringToPtr) IsConst

func (e *StringToPtr) IsConst() bool

func (*StringToPtr) PtrType

func (e *StringToPtr) PtrType(types.PtrType) types.PtrType

func (*StringToPtr) Uses

func (e *StringToPtr) Uses() []types.Usage

func (*StringToPtr) Visit

func (e *StringToPtr) Visit(v Visitor)

type SwitchBlock

type SwitchBlock struct {
	BaseBlock
	Expr   Expr
	Cases  []Expr
	Blocks []Block
}

func (*SwitchBlock) NextBlocks

func (b *SwitchBlock) NextBlocks() []Block

func (*SwitchBlock) ReplaceNext

func (b *SwitchBlock) ReplaceNext(old, rep Block)

type TakeAddr

type TakeAddr struct {
	X Expr
	// contains filtered or unexported fields
}

func (*TakeAddr) AsExpr

func (e *TakeAddr) AsExpr() GoExpr

func (*TakeAddr) CType

func (e *TakeAddr) CType(exp types.Type) types.Type

func (*TakeAddr) HasSideEffects

func (e *TakeAddr) HasSideEffects() bool

func (*TakeAddr) IsConst

func (e *TakeAddr) IsConst() bool

func (*TakeAddr) PtrType

func (e *TakeAddr) PtrType(types.PtrType) types.PtrType

func (*TakeAddr) Uses

func (e *TakeAddr) Uses() []types.Usage

func (*TakeAddr) Visit

func (e *TakeAddr) Visit(v Visitor)

type TypeAssert

type TypeAssert struct {
	Type types.Type
	Expr Expr
}

func (*TypeAssert) AsExpr

func (e *TypeAssert) AsExpr() GoExpr

func (*TypeAssert) CType

func (e *TypeAssert) CType(types.Type) types.Type

func (*TypeAssert) HasSideEffects

func (e *TypeAssert) HasSideEffects() bool

func (*TypeAssert) IsConst

func (e *TypeAssert) IsConst() bool

type TypeHint

type TypeHint string

type UnaryOp

type UnaryOp string
const (
	UnarySizeof UnaryOp = "sizeof"

	UnaryPlus  UnaryOp = "+"
	UnaryMinus UnaryOp = "-"
	UnaryXor   UnaryOp = "^"
)

type UnusedVar

type UnusedVar struct {
	Name *types.Ident
}

func (*UnusedVar) AsStmt

func (s *UnusedVar) AsStmt() []GoStmt

func (*UnusedVar) Uses

func (s *UnusedVar) Uses() []types.Usage

func (*UnusedVar) Visit

func (s *UnusedVar) Visit(v Visitor)

type Visitor

type Visitor func(n Node)

Directories

Path Synopsis
cmd
internal
git
runtime

Jump to

Keyboard shortcuts

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