generator

package
v0.0.0-...-eee87fb Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause, Unlicense Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExported

func IsExported(typeName string) bool

func Name

func Name(ty analysis.Type) string

Name returns the representation of the given type in generated code, either its local name or its String

func ParseFunctionName

func ParseFunctionName(typeName string) string

Types

type Accu

type Accu map[string]bool

type Buffer

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

Buffer is used to accumulate and de-deduplicate function declarations

func NewBuffer

func NewBuffer(accu Accu) Buffer

NewBuffer returns a ready to use buffer, which will add the new decleration to [accu].

func (*Buffer) Add

func (db *Buffer) Add(decl Declaration)

func (Buffer) Code

func (db Buffer) Code(childTypes map[*types.Named]bool) string

Code removes the unused declaration and returns the final code.

type Context

type Context struct {

	// Type is the name of the type being generated
	Type Expression

	// ObjectVar if the name of the variable being parsed or dumped
	ObjectVar Expression

	// Slice is the name of the []byte being read or written
	Slice Expression

	// Offset holds the variable name for the current offset,
	// and its value when known at compile time
	Offset Offset

	// IgnoreUpdateOffset is true if the update offset statement
	// should not be written
	IgnoreUpdateOffset bool
}

Context holds the names of the objects used in the generated code

func (Context) ErrReturn

func (cc Context) ErrReturn(errVariable Err) string

ErrReturn returns a "return ..., err" statement

func (Context) ParsingFunc

func (cc Context) ParsingFunc(origin *types.Named, args, scopes []string) Declaration

ParsingFunc adds the context to the given [scopes] and [args]

func (Context) ParsingFuncComment

func (cc Context) ParsingFuncComment(origin *types.Named, args, scopes []string, comment string) Declaration

ParsingFunc adds the context to the given [scopes] and [args], also adding the given comment as documentation

func (Context) Selector

func (cc Context) Selector(field string) string

Selector returns a "<ObjectVar>.<field>" statement

func (*Context) SubSlice

func (cc *Context) SubSlice(subSlice Expression) string

SubSlice slices the current input slice at the current offset and assigns it to `subSlice`. It also updates the [Context.Slice] field

type Declaration

type Declaration struct {
	ID         string
	Content    string
	IsExported bool
	Origin     *types.Named
}

Declaration is a chunk of generated go code, with an id used to avoid duplication

type Err

type Err interface {
	// contains filtered or unexported methods
}

type ErrFormated

type ErrFormated string

represent a fmt.Errorf(..., args) statement

type ErrVariable

type ErrVariable string

simple 'err' statement

type Expression

type Expression = string

Expression is a Go expression, such as a variable name, a static number, or an expression

func ArrayOffset

func ArrayOffset(offset Expression, count Expression, elementSize int) Expression

ArrayOffset returns the expression for <offset> + <count> * <elementSize>, usable for offsets or array length

type Offset

type Offset struct {
	// Name is the name of the variable containing the offset
	Name Expression
	// contains filtered or unexported fields
}

Offset represents an offset in a byte of slice. It is designed to produce the optimal output regardless of whether its value is known at compile time or not.

func NewOffset

func NewOffset(name Expression, initialValue int) Offset

func NewOffsetDynamic

func NewOffsetDynamic(name Expression) Offset

func (*Offset) Increment

func (of *Offset) Increment(size analysis.BinarySize)

Increment updates the current value, adding [size]. It is a no-op if the tracked value is unknown.

func (*Offset) SetStatement

func (of *Offset) SetStatement(value Expression) Expression

SetStatement returns the code for <offset> = <value>, and remove the tracked value which is now unknown

func (*Offset) UpdateStatement

func (of *Offset) UpdateStatement(size analysis.BinarySize) Expression

UpdateStatement returns a statement for <offset> += size, without changing the tracked value, since it has already been done with [Increment] calls. It also reset the temporary increment.

func (*Offset) UpdateStatementDynamic

func (of *Offset) UpdateStatementDynamic(size Expression) Expression

UpdateStatementDynamic returns a statement for <offset> += size, and remove the tracked value which is now unknown.

func (Offset) Value

func (of Offset) Value() Expression

Value returns the optimal Go expression for the offset current value.

func (Offset) With

func (of Offset) With(size analysis.BinarySize) Expression

With returns the optimal expression for <offset> + <size>

func (Offset) WithAffine

func (of Offset) WithAffine(count Expression, size analysis.BinarySize) Expression

WithAffine returns the optimal expression for <offset> + <count>*<size>

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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