gotypes

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: BSD-3-Clause Imports: 8 Imported by: 13

Documentation

Overview

Package gotypes provides helpers for interacting with Go types within avo functions.

Index

Examples

Constants

This section is empty.

Variables

View Source
var PointerSize = Sizes.Sizeof(types.Typ[types.UnsafePointer])

PointerSize is the size of a pointer on amd64.

View Source
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 Basic

type Basic struct {
	Addr operand.Mem
	Type *types.Basic
}

Basic represents a primitive/basic type at a given memory address.

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.

func NewComponent

func NewComponent(t types.Type, addr operand.Mem) Component

NewComponent builds a component for the named type at the given address.

type Signature

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

Signature represents a Go function signature.

func LookupSignature

func LookupSignature(pkg *types.Package, name string) (*Signature, error)

LookupSignature returns the signature of the named function in the provided package.

func NewSignature

func NewSignature(pkg *types.Package, sig *types.Signature) *Signature

NewSignature constructs a Signature.

func NewSignatureVoid

func NewSignatureVoid() *Signature

NewSignatureVoid builds the void signature "func()".

func ParseSignature

func ParseSignature(expr string) (*Signature, error)

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

func ParseSignatureInPackage(pkg *types.Package, expr string) (*Signature, error)

ParseSignatureInPackage builds a Signature by parsing a Go function type expression. The expression may reference types in the provided package.

func (*Signature) Bytes

func (s *Signature) Bytes() int

Bytes returns the total size of the function arguments and return values.

func (*Signature) Params

func (s *Signature) Params() *Tuple

Params returns the function signature argument types.

func (*Signature) Results

func (s *Signature) Results() *Tuple

Results returns the function return types.

func (*Signature) String

func (s *Signature) String() string

String writes Signature as a string. This does not include the "func" keyword.

type Tuple

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

Tuple represents a tuple of variables, such as function arguments or results.

func (*Tuple) At

func (t *Tuple) At(i int) Component

At returns the variable at index i.

func (*Tuple) Bytes

func (t *Tuple) Bytes() int

Bytes returns the size of the Tuple. This may include additional padding.

func (*Tuple) Lookup

func (t *Tuple) Lookup(name string) Component

Lookup returns the variable with the given name.

Jump to

Keyboard shortcuts

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