program

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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 NewProgram

func NewProgram() *Program

NewProgram creates a new blank program.

func (*Program) AddImport

func (p *Program) AddImport(importPath string)

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

func (p *Program) AddImports(importPaths ...string)

AddImports is a convienience method for adding multiple imports.

func (*Program) AppendStartupExpr added in v0.11.0

func (p *Program) AppendStartupExpr(e goast.Expr)

func (*Program) AppendStartupStatement added in v0.11.0

func (p *Program) AppendStartupStatement(stmt goast.Stmt)

func (*Program) GetNextIdentifier added in v0.11.0

func (p *Program) GetNextIdentifier(prefix string) string

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.

func (*Program) ImportType

func (p *Program) ImportType(name string) string

func (*Program) Imports

func (p *Program) Imports() []string

Imports returns all of the Go imports for this program.

func (*Program) StartupStatements added in v0.11.0

func (p *Program) StartupStatements() []goast.Stmt

func (*Program) TypeIsAlreadyDefined added in v0.9.0

func (p *Program) TypeIsAlreadyDefined(typeName string) bool

func (*Program) TypeIsNowDefined added in v0.9.0

func (p *Program) TypeIsNowDefined(typeName string)

Jump to

Keyboard shortcuts

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