domain

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Domain model, outputs of parser, inputs for generator. No dependencies here.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedType = errors.New("unsupported type")

Functions

func IsFixedSize

func IsFixedSize[
	T StructField | SimpleFieldType | ArrayFieldType | SliceFieldType | int](a T) bool

Returns true if total argument's size can be interpreted as known at declaration time. E.g. (primitives, arrays). NOT slices.

func ParenthesizeIntExpr

func ParenthesizeIntExpr(expr string) string

Adds parentheses to Go's int expression if it is a) not a simple int value, b) not already cast to int.

Types

type ArrayFieldType

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

func NewArrayFieldType

func NewArrayFieldType(length int, el FieldType) *ArrayFieldType

func (ArrayFieldType) ElType

func (t ArrayFieldType) ElType() FieldType

func (ArrayFieldType) IsInteger

func (t ArrayFieldType) IsInteger() bool

func (ArrayFieldType) IsSequence

func (t ArrayFieldType) IsSequence() bool

func (ArrayFieldType) LenExpr

func (t ArrayFieldType) LenExpr() string

func (ArrayFieldType) Length

func (t ArrayFieldType) Length() int

func (ArrayFieldType) Name

func (t ArrayFieldType) Name() string

func (ArrayFieldType) Size

func (t ArrayFieldType) Size() int

func (ArrayFieldType) SizeExpr

func (t ArrayFieldType) SizeExpr() string

type FieldType

type FieldType interface {
	Name() string
	// Total size of the field.
	// If Size() < 0, then size is not fixed, and SizeExpr() should be used.
	Size() int
	// Expression that determines the size of the field.
	// Should always be constructed in a way to return int type.
	SizeExpr() string
	// Don't confuse with IsInt. Checks if type is intX OR uintX OR byte
	IsInteger() bool
	// Should return true if the type is an array or slice
	IsSequence() bool
}

type InputStruct

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

func NewInputStruct

func NewInputStruct(name string, typ *types.Struct) *InputStruct

func (InputStruct) Field

func (s InputStruct) Field(idx int) StructField

func (InputStruct) FieldCount

func (s InputStruct) FieldCount() int

func (InputStruct) Name

func (s InputStruct) Name() string

func (*InputStruct) SetFields

func (s *InputStruct) SetFields(f []StructField)

func (InputStruct) Type

func (s InputStruct) Type() *types.Struct

type SequenceFieldType

type SequenceFieldType interface {
	ElType() FieldType
	LenExpr() string
}

Field type that is a sequence, i.e. array or slice, which have a number of certain elements

type SimpleFieldType

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

func NewSimpleFieldType

func NewSimpleFieldType(name string, size int, underlying *SimpleFieldType) *SimpleFieldType

func (SimpleFieldType) BitSize

func (t SimpleFieldType) BitSize() int

func (SimpleFieldType) IsInteger

func (bt SimpleFieldType) IsInteger() bool

func (SimpleFieldType) IsSequence

func (t SimpleFieldType) IsSequence() bool

func (SimpleFieldType) Name

func (t SimpleFieldType) Name() string

func (SimpleFieldType) Size

func (t SimpleFieldType) Size() int

func (SimpleFieldType) SizeExpr

func (t SimpleFieldType) SizeExpr() string

func (SimpleFieldType) Underlying

func (t SimpleFieldType) Underlying() *SimpleFieldType

type SliceFieldType

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

func NewSliceFieldType

func NewSliceFieldType(lenExpr string, el FieldType) *SliceFieldType

func (SliceFieldType) ElType

func (t SliceFieldType) ElType() FieldType

func (SliceFieldType) IsInteger

func (t SliceFieldType) IsInteger() bool

func (SliceFieldType) IsSequence

func (t SliceFieldType) IsSequence() bool

func (SliceFieldType) LenExpr

func (t SliceFieldType) LenExpr() string

func (SliceFieldType) Name

func (t SliceFieldType) Name() string

func (SliceFieldType) Size

func (t SliceFieldType) Size() int

func (SliceFieldType) SizeExpr

func (t SliceFieldType) SizeExpr() string

type StructField

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

func NewStructField

func NewStructField(name string, typ FieldType, tag map[string]string) StructField

func (StructField) Name

func (f StructField) Name() string

func (StructField) Type

func (f StructField) Type() FieldType

Jump to

Keyboard shortcuts

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