gen

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPrintable

func IsPrintable(e Elem) bool

Types

type Array

type Array struct {
	Index string // index variable name
	Size  string // array size
	Els   Elem   // child
	// contains filtered or unexported fields
}

func (*Array) Alias

func (c *Array) Alias(typ string)

func (*Array) Complexity

func (a *Array) Complexity() int

func (*Array) Copy

func (a *Array) Copy() Elem

func (*Array) SetVarname

func (a *Array) SetVarname(s string)

func (*Array) TypeName

func (a *Array) TypeName() string

func (*Array) Varname

func (c *Array) Varname() string

type BaseElem

type BaseElem struct {
	ShimToBase   string    // shim to base type, or empty
	ShimFromBase string    // shim from base type, or empty
	Value        Primitive // Type of element
	Convert      bool      // should we do an explicit conversion?
	// contains filtered or unexported fields
}

BaseElem is an element that can be represented by a primitive MessagePack type.

func Ident

func Ident(id string) *BaseElem

Ident returns the *BaseElem that corresponds to the provided identity.

func (*BaseElem) Alias

func (s *BaseElem) Alias(typ string)

func (*BaseElem) BaseName

func (s *BaseElem) BaseName() string

BaseName returns the string form of the base type (e.g. Float64, Ident, etc)

func (*BaseElem) BaseType

func (s *BaseElem) BaseType() string

func (*BaseElem) Complexity

func (s *BaseElem) Complexity() int

func (*BaseElem) Copy

func (s *BaseElem) Copy() Elem

func (*BaseElem) FromBase

func (s *BaseElem) FromBase() string

FromBase, used if Convert==true, is used as {{Varname}} = {{FromBase}}(tmp)

func (*BaseElem) Needsref

func (s *BaseElem) Needsref(b bool)

func (*BaseElem) Printable

func (s *BaseElem) Printable() bool

func (*BaseElem) Resolved

func (s *BaseElem) Resolved() bool

Resolved returns whether or not the type of the element is a primitive or a builtin provided by the package.

func (*BaseElem) SetVarname

func (s *BaseElem) SetVarname(a string)

func (*BaseElem) ToBase

func (s *BaseElem) ToBase() string

ToBase, used if Convert==true, is used as tmp = {{ToBase}}({{Varname}})

func (*BaseElem) TypeName

func (s *BaseElem) TypeName() string

TypeName returns the syntactically correct Go type name for the base element.

func (*BaseElem) Varname

func (c *BaseElem) Varname() string

type Elem

type Elem interface {
	// SetVarname sets this nodes
	// variable name and recursively
	// sets the names of all its children.
	// In general, this should only be
	// called on the parent of the tree.
	SetVarname(s string)

	// Varname returns the variable
	// name of the element.
	Varname() string

	// TypeName is the canonical
	// go type name of the node
	// e.g. "string", "int", "map[string]float64"
	// OR the alias name, if it has been set.
	TypeName() string

	// Alias sets a type (alias) name
	Alias(typ string)

	// Copy should perform a deep copy of the object
	Copy() Elem

	// Complexity returns a measure of the
	// complexity of element (greater than
	// or equal to 1.)
	Complexity() int
	// contains filtered or unexported methods
}

Elem is a go type capable of being serialized into MessagePack. It is implemented by *Ptr, *Struct, *Array, *Slice, *Map, and *BaseElem.

type Map

type Map struct {
	Keyidx string // key variable name
	Validx string // value variable name
	Value  Elem   // value element
	// contains filtered or unexported fields
}

Map is a map[string]Elem

func (*Map) Alias

func (c *Map) Alias(typ string)

func (*Map) Complexity

func (m *Map) Complexity() int

func (*Map) Copy

func (m *Map) Copy() Elem

func (*Map) SetVarname

func (m *Map) SetVarname(s string)

func (*Map) TypeName

func (m *Map) TypeName() string

func (*Map) Varname

func (c *Map) Varname() string

type Method

type Method uint8

Method is a bitfield representing something that the generator knows how to print.

const (
	Decode    Method = 1 << iota // msgp.Decodable
	Encode                       // msgp.Encodable
	Marshal                      // msgp.Marshaler
	Unmarshal                    // msgp.Unmarshaler
	Size                         // msgp.Sizer
	Test                         // generate tests

)

func (Method) String

func (m Method) String() string

String implements fmt.Stringer

type Primitive

type Primitive uint8

Base is one of the base types

const (
	Invalid Primitive = iota
	Bytes
	String
	Float32
	Float64
	Complex64
	Complex128
	Uint
	Uint8
	Uint16
	Uint32
	Uint64
	Byte
	Int
	Int8
	Int16
	Int32
	Int64
	Bool
	Intf // interface{}
	Time // time.Time
	Ext  // extension

	IDENT // IDENT means an unrecognized identifier
)

this is effectively the list of currently available ReadXxxx / WriteXxxx methods.

func (Primitive) String

func (k Primitive) String() string

type Printer

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

func NewPrinter

func NewPrinter(m Method, out io.Writer, tests io.Writer) *Printer

func (*Printer) ApplyDirective

func (p *Printer) ApplyDirective(pass Method, t TransformPass)

ApplyDirective applies a directive to a named pass and all of its dependents.

func (*Printer) Print

func (p *Printer) Print(e Elem) error

Print prints an Elem.

type Ptr

type Ptr struct {
	Value Elem
	// contains filtered or unexported fields
}

func (*Ptr) Alias

func (c *Ptr) Alias(typ string)

func (*Ptr) Complexity

func (s *Ptr) Complexity() int

func (*Ptr) Copy

func (s *Ptr) Copy() Elem

func (*Ptr) Needsinit

func (s *Ptr) Needsinit() bool

func (*Ptr) SetVarname

func (s *Ptr) SetVarname(a string)

func (*Ptr) TypeName

func (s *Ptr) TypeName() string

func (*Ptr) Varname

func (c *Ptr) Varname() string

type Slice

type Slice struct {
	Index string
	Els   Elem // The type of each element
	// contains filtered or unexported fields
}

func (*Slice) Alias

func (c *Slice) Alias(typ string)

func (*Slice) Complexity

func (s *Slice) Complexity() int

func (*Slice) Copy

func (s *Slice) Copy() Elem

func (*Slice) SetVarname

func (s *Slice) SetVarname(a string)

func (*Slice) TypeName

func (s *Slice) TypeName() string

func (*Slice) Varname

func (c *Slice) Varname() string

type Struct

type Struct struct {
	Fields  []StructField // field list
	AsTuple bool          // write as an array instead of a map
	// contains filtered or unexported fields
}

func (*Struct) Alias

func (c *Struct) Alias(typ string)

func (*Struct) Complexity

func (s *Struct) Complexity() int

func (*Struct) Copy

func (s *Struct) Copy() Elem

func (*Struct) SetVarname

func (s *Struct) SetVarname(a string)

func (*Struct) TypeName

func (s *Struct) TypeName() string

func (*Struct) Varname

func (c *Struct) Varname() string

type StructField

type StructField struct {
	FieldTag  string // the string inside the `msg:""` tag
	FieldName string // the name of the struct field
	FieldElem Elem   // the field type
}

type TransformPass

type TransformPass func(Elem) Elem

TransformPass is a pass that transforms individual elements. (Note that if the returned is different from the argument, it should not point to the same objects.)

func IgnoreTypename

func IgnoreTypename(name string) TransformPass

IgnoreTypename is a pass that just ignores types of a given name.

Jump to

Keyboard shortcuts

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