Documentation
¶
Overview ¶
Package derive is the code generator library used by all plugins.
Index ¶
- func GetStructFields(s *types.Struct) []*types.Var
- func ImportPaths(args []string) []string
- func IsComparable(tt types.Type) bool
- func IsError(t types.Type) bool
- func RenameBlankIdentifier(sig *types.Signature) *types.Signature
- func RenameBlankIdentifierWith(sig *types.Signature, prefix string) *types.Signature
- func Zero(typ types.Type) string
- type Dependency
- type Field
- type Generator
- type Import
- type Named
- type Plugin
- type Plugins
- type Printer
- type Program
- type TypesMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ImportPaths ¶
ImportPaths returns the import paths to use for the given command line.
func IsComparable ¶
func RenameBlankIdentifier ¶
RenameBlankIdentifier returns a signature where all blank parameter names are renamed.
func RenameBlankIdentifierWith ¶
RenameBlankIdentifierWith returns a signature where all blank parameter names are renamed. The given prefix is used to rename.
Types ¶
type Dependency ¶
Dependency is used by other plugins to generate more functions.
type Field ¶
Field describes a struct field.
func (*Field) DebugName ¶
DebugName simply returns the field name, without the receiver or any unsafe magic.
type Generator ¶
type Generator interface {
TypesMap
Add(name string, typs []types.Type) (string, error)
Generate(typs []types.Type) error
}
Generator generates code for input types.
type Import ¶
type Import func() string
Import is a closure that returns the import alias and only adds the import to the generated code if the function is actually called.
type Plugin ¶
type Plugin interface {
GetPrefix() string
SetPrefix(string)
Name() string
New(typesMap TypesMap, p Printer, deps map[string]Dependency) Generator
}
Plugin is used to create a Generator.
func NewPlugin ¶
func NewPlugin(name, prefix string, newFunc func(typesMap TypesMap, p Printer, deps map[string]Dependency) Generator) Plugin
NewPlugin is used by a plugin library to create a plugin, that can be added to the Plugins list. For example:
func NewPlugin() derive.Plugin {
return derive.NewPlugin("all", "deriveAll", New)
}
type Printer ¶
type Printer interface {
P(format string, a ...interface{})
In()
Out()
WriteTo(w io.Writer) (int64, error)
NewImport(name, path string) Import
HasContent() bool
}
Printer is used to print the generated code to a file.
type Program ¶
type Program interface {
Generate() error
}
Program is ready to generate code for a whole program.
type TypesMap ¶
type TypesMap interface {
SetFuncName(name string, typs ...types.Type) (newName string, err error)
GetFuncName(typs ...types.Type) string
Generating(typs ...types.Type)
ToGenerate() [][]types.Type
Prefix() string
TypeString(typ types.Type) string
FieldStrings(fields []*types.Var) ([]string, error)
IsExternal(typ *types.Named) bool
Done() bool
}
TypesMap is a map of input types to function names. It also keeps track of which functions have been generated.