Documentation
¶
Index ¶
- Variables
- func DetermineArithmeticOperationResultType(operand1 *Expression, operand2 *Expression) (ExpressionType, *TypeReference, error)
- func GoPackageAlias(packageName string) string
- type Array
- type BaseScope
- type BitmaskType
- type BitmaskValue
- type Choice
- type ChoiceCase
- type ChoiceCaseExpression
- type CompoundScope
- type Const
- type Enum
- type EnumItem
- type EvaluationState
- type Expression
- type ExpressionType
- type Field
- type Function
- type Import
- type InstantiateType
- type MissingEnumValue
- type OriginalTypeReference
- type Package
- func (p *Package) CollectSymbols() error
- func (p *Package) GetCompoundType(compoundSymbolName, name string) (*SymbolReference, error)
- func (p *Package) GetCurrentCompoundType(name string) (*SymbolReference, error)
- func (p *Package) GetImportedScope(name string) (*Package, error)
- func (p *Package) GetOriginalSymbol(symbolReference *SymbolReference) (*SymbolReference, error)
- func (p *Package) GetOriginalType(typeRef *TypeReference) (*OriginalTypeReference, error)
- func (p *Package) GetOtherType(name string) (*SymbolReference, error)
- func (p *Package) GetSymbol(name string) (*SymbolReference, error)
- func (p *Package) GetType(name string) (*SymbolReference, error)
- func (p *Package) GetTypeParameter(typeRef *TypeReference) ([]*Parameter, error)
- func (p *Package) GoArrayTraits(t *TypeReference) (string, error)
- func (p *Package) GoType(t *TypeReference) (string, error)
- func (p *Package) HasType(name string) bool
- func (p *Package) IsDeltaPackable(t *TypeReference) (bool, error)
- func (p *Package) OriginalType(t *TypeReference) (*OriginalTypeReference, error)
- type Parameter
- type RootScope
- func (s *RootScope) GoArrayTraits(t *TypeReference) (string, error)
- func (s *RootScope) GoType(t *TypeReference) (string, error)
- func (s *RootScope) HasType(t string) bool
- func (s *RootScope) IsDeltaPackable(t *TypeReference) (bool, error)
- func (s *RootScope) OriginalType(t *TypeReference) (*OriginalTypeReference, error)
- type Scope
- type Struct
- type Subtype
- type SymbolReference
- type SymbolScope
- type TypeReference
- type Union
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownType = errors.New("unknown type")
Functions ¶
func DetermineArithmeticOperationResultType ¶ added in v0.7.0
func DetermineArithmeticOperationResultType(operand1 *Expression, operand2 *Expression) (ExpressionType, *TypeReference, error)
DetermineArithmeticOperationResultType determines the result type of an expression that involves two operands in an arithmetic operation. For example, when adding integers with floats, the resulting type should be float, and how to handle operations that mix unsigned/signed types, or types of different bit length.
func GoPackageAlias ¶
Types ¶
type Array ¶
type Array struct { IsPacked bool Length *Expression }
type BaseScope ¶
type BaseScope struct {
Parent Scope
}
func (*BaseScope) GoArrayTraits ¶
func (s *BaseScope) GoArrayTraits(t *TypeReference) (string, error)
func (*BaseScope) GoType ¶
func (s *BaseScope) GoType(t *TypeReference) (string, error)
GoType looks up a name in the scope, and provides the Go type name for it. If the type is not found ErrUnkownType is returned.
func (*BaseScope) HasType ¶
HasType checks if a type is defined *in this scope*. It does not check parent scopes.
func (*BaseScope) OriginalType ¶ added in v0.7.0
func (s *BaseScope) OriginalType(t *TypeReference) (*OriginalTypeReference, error)
type BitmaskType ¶
type BitmaskType struct { Name string Comment string Type *TypeReference Values []*BitmaskValue }
func (*BitmaskType) Evaluate ¶
func (bitmask *BitmaskType) Evaluate(p *Package) error
type BitmaskValue ¶
type BitmaskValue struct { Name string *Expression }
type Choice ¶
type Choice struct { Name string Comment string TemplateParameters []string TypeParameters []*Parameter SelectorExpression *Expression Cases []*ChoiceCase DefaultCase *ChoiceCase Functions []*Function }
func (*Choice) BuildScope ¶
type ChoiceCase ¶
type ChoiceCase struct { Conditions []*ChoiceCaseExpression Field *Field Comment string }
type ChoiceCaseExpression ¶
type ChoiceCaseExpression struct { Condition *Expression Comment string }
type CompoundScope ¶
type Const ¶
type Const struct { Name string Comment string Type *TypeReference ValueExpression *Expression }
Const is a zserio constant
type EnumItem ¶
type EnumItem struct { Name string Comment string *Expression // contains filtered or unexported fields }
type EvaluationState ¶
type EvaluationState int
EvaluationState is the type of the expression evaluation state
const ( EvaluationStateNotStarted EvaluationState = iota EvaluationStateInProgress EvaluationStateComplete )
type Expression ¶
type Expression struct { // Type is the type of an expression, as defined in the ZserioParser. Type int // Text is the text of the expression. Text string // Operand1 is the first operand of the expression (if used). Operand1 *Expression // Operand2 is the second operand of the expression (if used). Operand2 *Expression // Operand3 is the third operand of the expression (if used). Operand3 *Expression // ResultType is the type of the evaluated expression, e.g. ExpressionTypeInteger. ResultType ExpressionType // EvaluationState is the evaluation state of the expression. EvaluationState EvaluationState // ResultIntValue is the value of the expression if ResultType is // ExpressionTypeInteger or ExpressionTypeBitmask. ResultIntValue int64 // ResultFloatValue is the value of the expression if ResutlType is // ExpressionTypeFloat. ResultFloatValue float64 // ResultStringValue is the value of the expression if ResultType is // ExpressionTypeString. ResultStringValue string // ResultBoolValue is the value of the expression if ResultType is // ExpressionTypeBool ResultBoolValue bool // NativeZserioType stores the exact zserio type, in case ResultType is // an integer or float type. This is needed to make type casts in the // generated Go code when mixing different types - for example // mixing varint with uint32, or mixing float types with integer types. NativeZserioType *TypeReference // ResultSymbol points to the symbol if ResultType is ExpressionTypeEnum or // ExpressionTypeStruct. ResultSymbol *SymbolReference // FullyResolved specifies if the expression is fully resolved (no variables) FullyResolved bool }
Expression satisfies IExpressionContext
func (*Expression) Evaluate ¶
func (expr *Expression) Evaluate(scope *Package) error
Evaluate evalues the value of the expression, by evaluating all child expressions. If successful, expr will have valid ExpressionType and Values set.
type ExpressionType ¶
type ExpressionType string
ExpressionType is the type of an expression
const ( ExpressionTypeInteger ExpressionType = "int" ExpressionTypeFloat ExpressionType = "float" ExpressionTypeString ExpressionType = "string" ExpressionTypeBool ExpressionType = "bool" ExpressionTypeBitmask ExpressionType = "bitmask" ExpressionTypeEnum ExpressionType = "enum" ExpressionTypeCompound ExpressionType = "compound" )
type Field ¶
type Field struct { Name string // ZserioName is the original name of the field, as it appears in the // zserio file. ZserioName string // Comment is the comment of the field in the zserio file. Comment string // Optional fields are always serialised as a boolean that indicates // if the value field is set. If the field is not set no value is // serialised. // http://zserio.org/doc/ZserioLanguageOverview.html#optional-members IsOptional bool Alignment uint8 Type *TypeReference Initializer *Expression Constraint *Expression OptionalClause *Expression // Array stored the array properties if the field is an array Array *Array }
type Function ¶
type Function struct { Name string Comment string Result *Expression ReturnType *TypeReference }
type InstantiateType ¶
type InstantiateType struct { Name string Comment string Type *TypeReference }
InstantiateType is an instantiation of a template.
type MissingEnumValue ¶
type MissingEnumValue struct {
Name string
}
func (MissingEnumValue) Error ¶
func (e MissingEnumValue) Error() string
type OriginalTypeReference ¶ added in v0.7.0
type OriginalTypeReference struct { Type *TypeReference RequiresCast bool IsMarshaler bool }
OriginalTypeReference is a reference to the original zserio type, for example fundamental types, but also enums/structs, that were aliased by a subtype.
type Package ¶
type Package struct { BaseScope Name string Comment string Imports []*Import Consts map[string]*Const Subtypes map[string]*Subtype InstantiatedTypes map[string]*InstantiateType Enums map[string]*Enum Unions map[string]*Union Bitmasks map[string]*BitmaskType Structs map[string]*Struct Choices map[string]*Choice ImportedPackages []*Package LocalSymbols *SymbolScope }
func NewPackage ¶
func (*Package) CollectSymbols ¶
CollectSymbols collects all symbols from a package, and organizes them in the scope
func (*Package) GetCompoundType ¶
func (p *Package) GetCompoundType(compoundSymbolName, name string) (*SymbolReference, error)
func (*Package) GetCurrentCompoundType ¶
func (p *Package) GetCurrentCompoundType(name string) (*SymbolReference, error)
func (*Package) GetImportedScope ¶
GetImportedScope returns a scope, if it can be found within the imported scope
func (*Package) GetOriginalSymbol ¶ added in v0.7.0
func (p *Package) GetOriginalSymbol(symbolReference *SymbolReference) (*SymbolReference, error)
func (*Package) GetOriginalType ¶ added in v0.7.0
func (p *Package) GetOriginalType(typeRef *TypeReference) (*OriginalTypeReference, error)
func (*Package) GetOtherType ¶
func (p *Package) GetOtherType(name string) (*SymbolReference, error)
func (*Package) GetSymbol ¶
func (p *Package) GetSymbol(name string) (*SymbolReference, error)
GetSymbol searches for a symbol not only in the current scope, but also in all imported scopes.
func (*Package) GetTypeParameter ¶
func (p *Package) GetTypeParameter(typeRef *TypeReference) ([]*Parameter, error)
GetTypeParameter returns the parameters of a referenced type
func (*Package) GoArrayTraits ¶
func (p *Package) GoArrayTraits(t *TypeReference) (string, error)
GoArrayTraits returns the array traits object for non-basic zserio types, such as enums, subtypes, or structures.
func (*Package) GoType ¶
func (p *Package) GoType(t *TypeReference) (string, error)
GoType looks up a name in the scope, and provides the Go type name for it. If the type is not found ErrUnkownType is returned.
func (*Package) HasType ¶
HasType checks if a type is defined *in this scope*. It does not check parent scopes.
func (*Package) IsDeltaPackable ¶ added in v0.2.6
func (p *Package) IsDeltaPackable(t *TypeReference) (bool, error)
IsDeltaPackable indicates if a non-basic zserio type (struct, enum, subtype, ...) can be delta-packed.
func (*Package) OriginalType ¶ added in v0.7.0
func (p *Package) OriginalType(t *TypeReference) (*OriginalTypeReference, error)
GoType looks up a name in the scope, and provides the Go type name for it. If the type is not found ErrUnkownType is returned.
type Parameter ¶
type Parameter struct { Name string Type *TypeReference }
type RootScope ¶
type RootScope struct{}
RootScope is the root zserio scope, which contains all built-in types
func (*RootScope) GoArrayTraits ¶
func (s *RootScope) GoArrayTraits(t *TypeReference) (string, error)
GoArrayTraits returns the array traits for a zserio basic type (int, float, ...)
func (*RootScope) HasType ¶
HasType checks if a type is defined *in this scope*. It does not check parent scopes.
func (*RootScope) IsDeltaPackable ¶ added in v0.2.6
func (s *RootScope) IsDeltaPackable(t *TypeReference) (bool, error)
IsDeltaPackable reutrns if a zserio basic type is delta-packabe. If the type is not a basic type, the function will return an error.
func (*RootScope) OriginalType ¶ added in v0.7.0
func (s *RootScope) OriginalType(t *TypeReference) (*OriginalTypeReference, error)
type Scope ¶
type Scope interface { // GoType looks up a name in the scope, and provides the Go type name for it. // If the type is not found ErrUnkownType is returned. GoType(t *TypeReference) (string, error) // Returns the original zserio type, removing all indirections caused by // subtyping. OriginalType(T *TypeReference) (*OriginalTypeReference, error) // GoArrayTraits looks up a name in the scope, and provides the array traits // for it. GoArrayTraits(t *TypeReference) (string, error) // IsDeltaPackable returns if a data type can be delta-packed: when stored in an // array, a delta compression can be applied, which only stored the delta to // the previous value, not the entire value. Only works for integer types. IsDeltaPackable(t *TypeReference) (bool, error) // HasType checks if a type is defined *in this scope*. It does not check parent // scopes. HasType(t string) bool }
type Struct ¶
type Struct struct { Name string Comment string TemplateParameters []string TypeParameters []*Parameter Fields []*Field Functions []*Function }
func (*Struct) BuildScope ¶
type Subtype ¶
type Subtype struct { Name string Comment string Type *TypeReference }
type SymbolReference ¶
type SymbolScope ¶
type SymbolScope struct { // TypeScope contains all types that are currently in the scope TypeScope map[string]any // OtherScope contains all symbols that are not Types (e.g. enum values) OtherScope map[string]any // CompoundScope contains all symbols that are restricted to the current // evaluation scope (e.g. the struct parameters when evaluating a struct) CompoundScopes map[string]*CompoundScope CurrentCompoundScope *string }
SymbolScope keeps track of all symbols that are available in this scope
func (*SymbolScope) GetCompoundType ¶
func (v *SymbolScope) GetCompoundType(compoundType, name string) (*SymbolReference, error)
func (*SymbolScope) GetOtherType ¶
func (v *SymbolScope) GetOtherType(name string) (*SymbolReference, error)
func (*SymbolScope) GetType ¶
func (v *SymbolScope) GetType(name string) (*SymbolReference, error)
type TypeReference ¶
type TypeReference struct { // IsBuiltin is set to true for standard zserio types IsBuiltin bool Package string Name string Bits int TemplateArguments []*TypeReference // TypeArguments are the type arguments if the underlying type supports // parameters. TypeArguments []*Expression // LengthExpression is an optional expression, specifying the length of a bit // mask, for example int<Expression>. If the expression evaluates to 18, the // resulting type will be int<18> LengthExpression *Expression }
func (*TypeReference) Evaluate ¶
func (tr *TypeReference) Evaluate(p *Package) error