Documentation
¶
Index ¶
- func AddFunctionDefinition(f FunctionDefinition)
- type FunctionDefinition
- type Program
- func (p *Program) AddImport(importPath string)
- func (p *Program) AddImports(importPaths ...string)
- func (p *Program) AppendStartupExpr(e goast.Expr)
- func (p *Program) AppendStartupStatement(stmt goast.Stmt)
- func (p *Program) GetNextIdentifier(prefix string) string
- func (p *Program) ImportType(name string) string
- func (p *Program) Imports() []string
- func (p *Program) StartupStatements() []goast.Stmt
- func (p *Program) TypeIsAlreadyDefined(typeName string) bool
- func (p *Program) TypeIsNowDefined(typeName string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFunctionDefinition ¶ added in v0.9.2
func AddFunctionDefinition(f FunctionDefinition)
AddFunctionDefinition registers a function definition. If the definition already exists it will be replaced.
Types ¶
type FunctionDefinition ¶ added in v0.9.2
type FunctionDefinition struct {
// The name of the function, like "printf".
Name string
// The C return type, like "int".
ReturnType string
// The C argument types, like ["bool", "int"]. There is currently no way
// to represent a varargs.
ArgumentTypes []string
// If this is not empty then this function name should be used instead
// of the Name. Many low level functions have an exact match with a Go
// function. For example, "sin()".
Substitution string
// Can be overriden with the substitution to rearrange the return variables
// and parameters. When either of these are nil the behavior is to keep the
// single return value and parameters the same.
ReturnParameters []int
Parameters []int
}
FunctionDefinition contains the prototype definition for a function.
func GetFunctionDefinition ¶ added in v0.9.2
func GetFunctionDefinition(functionName string) *FunctionDefinition
GetFunctionDefinition will return nil if the function does not exist (is not registered).
type Program ¶
type Program struct {
// These are for the output Go AST.
FileSet *token.FileSet
File *ast.File
// Contains the current function name during the transpilation.
FunctionName string
// contains filtered or unexported fields
}
Program contains all of the input, output and transpition state of a C program to a Go program.
func (*Program) AddImport ¶
AddImport will append an absolute import if it is unique to the list of imports for this program.
func (*Program) AddImports ¶ added in v0.11.0
AddImports is a convienience method for adding multiple imports.
func (*Program) AppendStartupExpr ¶ added in v0.11.0
func (*Program) AppendStartupStatement ¶ added in v0.11.0
func (*Program) GetNextIdentifier ¶ added in v0.11.0
GetNextIdentifier generates a new gloablly unique identifier name. This can be used for variables and functions in generated code.
The value of prefix is only useful for readability in the code. If the prefix is an empty string then the prefix "__temp" will be used.