Documentation ¶
Overview ¶
Package gotypes provides helpers for interacting with Go types within avo functions.
Index ¶
- Variables
- type Basic
- type Component
- type Signature
- func LookupSignature(pkg *types.Package, name string) (*Signature, error)
- func NewSignature(pkg *types.Package, sig *types.Signature) *Signature
- func NewSignatureVoid() *Signature
- func ParseSignature(expr string) (*Signature, error)
- func ParseSignatureInPackage(pkg *types.Package, expr string) (*Signature, error)
- type Tuple
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var PointerSize = Sizes.Sizeof(types.Typ[types.UnsafePointer])
PointerSize is the size of a pointer on amd64.
var Sizes = types.SizesFor("gc", "amd64")
Sizes provides type sizes used by the standard Go compiler on amd64.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component interface { // When the component has no further sub-components, Resolve will return a // reference to the components type and memory address. If there was an error // during any previous calls to Component methods, they will be returned at // resolution time. Resolve() (*Basic, error) Dereference(r reg.Register) Component // dereference a pointer Base() Component // base pointer of a string or slice Len() Component // length of a string or slice Cap() Component // capacity of a slice Real() Component // real part of a complex value Imag() Component // imaginary part of a complex value Index(int) Component // index into an array Field(string) Component // access a struct field }
Component provides access to sub-components of a Go type.
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
Signature represents a Go function signature.
func LookupSignature ¶
LookupSignature returns the signature of the named function in the provided package.
func NewSignature ¶
NewSignature constructs a Signature.
func NewSignatureVoid ¶
func NewSignatureVoid() *Signature
NewSignatureVoid builds the void signature "func()".
func ParseSignature ¶
ParseSignature builds a Signature by parsing a Go function type expression. The function type must reference builtin types only; see ParseSignatureInPackage if custom types are required.
Example ¶
package main import ( "fmt" "github.com/mmcloughlin/avo/gotypes" ) func main() { s, err := gotypes.ParseSignature("func(s string, n int) string") fmt.Println(s) fmt.Println(err) }
Output: (s string, n int) string <nil>
func ParseSignatureInPackage ¶
ParseSignatureInPackage builds a Signature by parsing a Go function type expression. The expression may reference types in the provided package.