Documentation
¶
Overview ¶
Package funcs is a wrapper for functions to create a uniform representation for function-like constructs in Go.
We define representation of Definition (i.e. callee perspective) and Instance (i.e. caller perspective) for:
- Builtin function
- Ordinary function
- Pointer to function (function in a variable)
- Closures (functions that carries variable with it)
Definitions created by this package can be used as store.Value.
Index ¶
- type Call
- func (c *Call) Bind(i int) store.Key
- func (c *Call) Definition() *Definition
- func (c *Call) Function() *ssa.Function
- func (c *Call) NBind() int
- func (c *Call) NParam() int
- func (c *Call) NReturn() int
- func (c *Call) Param(i int) store.Key
- func (c *Call) Return(i int) store.Key
- func (c *Call) String() string
- func (c *Call) UniqName() string
- type Definition
- type Instance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct { Parameters []store.Key // Aggregated parameter. Args []store.Key // Caller arguments (raw). Returns []store.Key // Caller return values (raw). // contains filtered or unexported fields }
A Call is a function call definition, i.e. function definition from the perspective of the caller.
Args are the function arguments at the caller.
func MakeCall ¶
func MakeCall(d *Definition, call *ssa.CallCommon, ret ssa.Value) *Call
MakeCall instantiates function call given its definition and a CallCommon.
func (*Call) Definition ¶
func (c *Call) Definition() *Definition
type Definition ¶
type Definition struct { Function *ssa.Function // Function parameters, returns, signature and body. Parameters []store.Key // Aggregated parameters. NParam int // Number of formal parameters. NFreeVar int // Number of captures. NReturn int // Number of return values. IsVararg bool // Is the last parameter variadic? // contains filtered or unexported fields }
Definition is a uniform representation for a function for abstracting function-like constructs in Go, namely:
- Builtin function
- Ordinary function
- Pointer to function (function in a variable)
- Closures (functions that carries variable with it)
In this form, a function definition consolidates all parameters to a function including captured free variables (closure), and return values to parameters. Structures are flattened so that all fields are represented separately.
func MakeClosureDefinition ¶
func MakeClosureDefinition(fn *ssa.Function, bindings []ssa.Value) *Definition
MakeClosureDefinition returns a definition for a given closure function + bindings.
func MakeDefinition ¶
func MakeDefinition(fn *ssa.Function) *Definition
MakeDefinition returns a definition for a given function.
func (*Definition) FreeVar ¶
func (d *Definition) FreeVar(i int) store.Key
FreeVar returns the i-th free variable of the function definition.
func (*Definition) IsReturn ¶
func (d *Definition) IsReturn(k store.Key) bool
IsReturn return true if the given name is a return value.
func (*Definition) Param ¶
func (d *Definition) Param(i int) store.Key
PAram returns the i-th function parameter of the function definition.
func (*Definition) Return ¶
func (d *Definition) Return(i int) store.Key
Return returns the i-th return values in the function body. Note that it only returns the most commonly used
func (*Definition) String ¶
func (d *Definition) String() string
func (*Definition) UniqName ¶
func (d *Definition) UniqName() string
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
An Instance of a function call. It is guaranteed unique by the seq field.
func Instantiate ¶
Instantiate materialises a new function call instance.
func (Instance) Definition ¶
func (i Instance) Definition() *Definition
Call returns the function definition (function definition at callee).