Documentation
¶
Overview ¶
Package engine holds base implementation details for use by generated code. Users should not depend on any particular feature of this package.
Index ¶
- type Abstract
- type Action
- type ActionFn
- type Context
- func (Context) ActionCall(fn ActionFn) Action
- func (Context) ActionVisit(td *TypeData, value Ptr) Action
- func (Context) ActionVisitTypeID(id TypeID, value Ptr) Action
- func (Context) Actions(actions []Action) Decision
- func (Context) Continue() Decision
- func (Context) Error(err error) Decision
- func (Context) Halt() Decision
- func (Context) Skip() Decision
- type Decision
- type Engine
- type FacadeFn
- type FieldInfo
- type Kind
- type Ptr
- type TypeData
- type TypeID
- type TypeMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Abstract ¶
type Abstract struct {
// contains filtered or unexported fields
}
Abstract allows a visitable object to be manipulated as an abstract tree of nodes. This should be enclosed in a type-safe wrapper. An Abstract should only ever represent a struct or a slice; pointers and interfaces should be resolved to their respective targets before being wrapped in an Abstract.
func (*Abstract) ChildAt ¶
ChildAt returns the nth field or slice element. If that value is a pointer or an interface, it is dereferenced before returning. Nil pointers, interfaces, and empty slices will return nil here.
func (*Abstract) NumChildren ¶
NumChildren returns the number of fields or slice elements.
type Action ¶ added in v0.1.4
type Action struct {
// contains filtered or unexported fields
}
Action allows user-defined actions to be inserted into the visitation flow.
type ActionFn ¶ added in v0.1.4
type ActionFn func() error
ActionFn describes a simple callback function.
type Context ¶ added in v0.1.4
type Context struct{}
Context is provided to generated, type-safe facades.
func (Context) ActionCall ¶ added in v0.1.4
ActionCall constructs an action which will invoke the function.
func (Context) ActionVisit ¶ added in v0.1.4
ActionVisit constructs an action which will visit the given value.
func (Context) ActionVisitTypeID ¶ added in v0.1.4
ActionVisitTypeID constructs an action which will visit the given value.
type Decision ¶ added in v0.1.4
type Decision struct {
// contains filtered or unexported fields
}
Decision is wrapped by generated, type-safe facades.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
An Engine holds the necessary information to pass a visitor over a field.
func (*Engine) Execute ¶
func (e *Engine) Execute( fn FacadeFn, t TypeID, x Ptr, assignableTo TypeID, ) (retType TypeID, ret Ptr, changed bool, err error)
Execute drives the visitation process. This is an "unrolled recursive" function that maintains its own stack to avoid deeply-nested call stacks. We can also perform cycle-detection at fairly low cost. Any replacement of the top-level value must be assignable to the given TypeID.
type FacadeFn ¶
type FacadeFn interface{}
FacadeFn is a generated function type that depends on the visitable interface.
type FieldInfo ¶
type FieldInfo struct { Name string Offset uintptr Target TypeID // contains filtered or unexported fields }
FieldInfo describes a field within a struct.
type Kind ¶
type Kind int
Kind determines the dispatch strategy for a given visitable type.
const ( KindInterface Kind KindPointer KindSlice KindStruct )
A visitable type has some combinations of kinds which determine its access pattern.
type TypeData ¶
type TypeData struct { // Copy will effect a type aware copy of the data at from to dest. Copy func(dest, from Ptr) // Elem is the element type of a slice or of a pointer. Elem TypeID // Facade will call a user-provided facade function in a // type-safe fashion. Facade func(Context, FacadeFn, Ptr) Decision // Fields holds information about the fields of a struct. Fields []FieldInfo // IntfType accepts a pointer to an interface type and returns a // TypeID for the enclosed datatype. // // An interface's type-tag contains several flag bits which // fall into the category of "too much magic" for us to want // to handle ourselves. Instead, we generate functions which // will perform the necessary type mapping. IntfType func(Ptr) TypeID // IntfWrap provides the opposite function of IntfType. It accepts // a TypeID and a pointer to the interface's value and returns a // pointer to the resulting interface array. IntfWrap func(TypeID, Ptr) Ptr // Kind selects various strategies for handling the given type. Kind Kind // Name is the source name of the type. Name string // NewSlice constructs a slice of the given length and returns a // pointer to the slice's header. NewSlice func(size int) Ptr // NewStruct returns a pointer to a newly-allocated struct. NewStruct func() Ptr // SizeOf is the size of the data type. This is used for traversing // slices. It could be expanded in the future to generalizing the // Copy() function. SizeOf uintptr // TypeID is a generated id. TypeID TypeID // contains filtered or unexported fields }
TypeData contains metadata and accessors that are produced by the code generator.