Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Field
- func (f *Field) GetterName() string
- func (f *Field) GoType() string
- func (f *Field) IsBool() bool
- func (f *Field) IsBytes() bool
- func (f *Field) IsNumeric() bool
- func (f *Field) IsString() bool
- func (f *Field) IsVarLen() bool
- func (f *Field) ReadCall() string
- func (f *Field) SetterName() string
- func (f *Field) TestValue() string
- func (f *Field) TypeConstant() int
- func (f *Field) WriteCall() string
- func (f *Field) WriteCallRec() string
- type GenerateFunc
- type Generator
- type Graph
- type GraphTemplate
- type Hook
- type StructSchema
- type Template
- func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error)
- func (t *Template) Funcs(funcMap template.FuncMap) *Template
- func (t *Template) Parse(text string) (*Template, error)
- func (t *Template) ParseFS(fsys fs.FS, patterns ...string) (*Template, error)
- func (t *Template) ParseFiles(filenames ...string) (*Template, error)
- func (t *Template) SkipIf(cond func(*Graph) bool) *Template
- type Type
- func (t *Type) HasBytesField() bool
- func (t *Type) HasStringField() bool
- func (t *Type) HasVarLenField() bool
- func (t *Type) Header() string
- func (t *Type) Label() string
- func (t *Type) LayoutFuncName() string
- func (t *Type) NewStoreFuncName() string
- func (t *Type) OpenStoreFuncName() string
- func (t *Type) Receiver() string
- func (t *Type) RecordName() string
- func (t *Type) StoreName() string
- type TypeTemplate
Constants ¶
const DefaultHeader = "// Code generated by mmapforge. DO NOT EDIT."
DefaultHeader is used when Config.Header is empty.
Variables ¶
var GraphTemplates = []GraphTemplate{}
GraphTemplates is the list of graph-wide templates to execute.
var TypeTemplates = []TypeTemplate{ { Name: "store", Format: func(t *Type) string { return strings.ToLower(t.Name) + "_store.go" }, }, { Name: "store_test", Format: func(t *Type) string { return strings.ToLower(t.Name) + "_store_test.go" }, }, }
TypeTemplates is the list of per-type templates to execute.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Target is the output directory for generated files.
Target string
// Package is the Go package for generated code.
Package string
// Header is an optional file header. Defaults to the DefaultHeader constant.
Header string
// Templates specifics optional external templates to execute
// or override the defaults.
Templates []*Template
// Hooks holds an optional list of Hooks to apply on the graph
// before/after code generation.
Hooks []Hook
}
Config holds the global codegen configuration, shared between all generated nodes.
type Field ¶
type Field struct {
mmapforge.FieldLayout
}
Field wraps mmapforge.FieldLayout and adds template helper methods.
func (*Field) GetterName ¶
GetterName returns the name for the getter method
func (*Field) SetterName ¶
SetterName returns the name for the setter method
func (*Field) TypeConstant ¶
TypeConstant returns the fmmap.FieldType integer for template use.
func (*Field) WriteCall ¶
WriteCall returns the Store.Write* method call using "val" as the value arg.
func (*Field) WriteCallRec ¶
WriteCallRec returns the Store.Write* method call using "rec.<GoName>" as the value.
type GenerateFunc ¶
GenerateFunc adapts an ordinary function to the Generator interface.
type Graph ¶
Graph holds all Type nodes and derive code generation.
type GraphTemplate ¶
type GraphTemplate struct {
Name string // matches a {{ define "name" }} in a .tmpl file
Skip func(*Graph) bool // optional: skip if returns true
Format string // output file name
}
GraphTemplate is executed once for the whole Graph.
type StructSchema ¶
type StructSchema struct {
// Name in the Go struct name
Name string
// Package is the Go package name
Package string
// Fields are the parsed field definitions.
Fields []mmapforge.FieldDef
// SchemaVersion is from the version=N directive.
SchemaVersion uint32
}
StructSchema is the parsed output of a Go struct annotated with // mmapforge:schema version=N. It carries everything the emitter
func ParseFile ¶
func ParseFile(path string) ([]StructSchema, error)
ParseFile parses a Go source file and extracts all structs annotated with // mmapforge:schema version=N.
type Template ¶
type Template struct {
*template.Template
FuncMap template.FuncMap
// contains filtered or unexported fields
}
func NewTemplate ¶
func (*Template) AddParseTree ¶
type Type ¶
type Type struct {
*Config
// Name is the Go struct name from the schema
Name string
// Package is the Go package name for the generated file.
Package string
// Fields holds the computed field layouts for this type.
Fields []*Field
// SchemaVersion is the schema migration version.
SchemaVersion uint32
// RecordSize is the total byte size of one record.
RecordSize uint32
}
Type represents a single mmapforge schema node — the central object
func (*Type) HasBytesField ¶
HasBytesField reports if any field is a bytes field.
func (*Type) HasStringField ¶
HasStringField reports if any field is a string.
func (*Type) HasVarLenField ¶
HasVarLenField reports if any field is variable-length (string or bytes).
func (*Type) LayoutFuncName ¶
LayoutFuncName returns the name of the Layout() func
func (*Type) NewStoreFuncName ¶
NewStoreFuncName returns the name for CreateStore
func (*Type) OpenStoreFuncName ¶
OpenStoreFuncName returns the name for OpenStore
func (*Type) RecordName ¶
RecordName returns the generated record struct name