ast

package
v0.0.0-...-d25f35a Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2019 License: ISC Imports: 4 Imported by: 0

Documentation

Overview

XDR Abstract Syntax Tree definition - a binary interchange format for XDR specifications

Index

Constants

View Source
const XDR_BIN_MAGIC = 0x895844520D0A1A0A

Binary magic: the `magic` field of the `specification` should be set to this value

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Name  string    `json:"name"`
	Value *Constant `json:"value"`
}

An attribute of an object

type Attributes

type Attributes map[string]*Constant

A set of attributes

func (Attributes) GetString

func (as Attributes) GetString(name string) string

GetString attempts to look up the named attribute as a string, or returns the empty string

func (Attributes) GetStringDefault

func (as Attributes) GetStringDefault(name, def string) string

GetStringDefault attempts to look up the named attribute as a string, or returns the specified default

type Constant

type Constant struct {
	Type    ConstantKind `json:"type"`
	VBool   bool         `json:"v_bool,omitempty"`
	VPosInt uint64       `json:"v_pos_int,omitempty"`
	VNegInt uint64       `json:"v_neg_int,omitempty"`
	VFloat  float64      `json:"v_float,omitempty"`
	VString string       `json:"v_string,omitempty"`
	VEnum   uint32       `json:"v_enum,omitempty"`
}

Constant is union constant

func (*Constant) ArmForSwitch

func (u *Constant) ArmForSwitch(sw uint32) (string, bool)

func (*Constant) AsU32

func (c *Constant) AsU32() (uint32, error)

AsU32 attempts to reinterpret a constant as an unsigned 32-bit number

func (*Constant) SwitchFieldName

func (u *Constant) SwitchFieldName() string

func (*Constant) UnionDiscriminant

func (u *Constant) UnionDiscriminant() interface{}

func (*Constant) UnionValue

func (u *Constant) UnionValue() (interface{}, error)

type ConstantKind

type ConstantKind uint32

Type of a constant. These are a subset of XDR types

const (
	CONST_BOOL    ConstantKind = 0
	CONST_POS_INT ConstantKind = 1
	CONST_NEG_INT ConstantKind = 2
	CONST_FLOAT   ConstantKind = 3
	CONST_STRING  ConstantKind = 4
	CONST_ENUM    ConstantKind = 5
)

func (ConstantKind) MarshalText

func (v ConstantKind) MarshalText() ([]byte, error)

func (ConstantKind) String

func (v ConstantKind) String() string

func (*ConstantKind) UnmarshalText

func (v *ConstantKind) UnmarshalText(buf []byte) error

func (ConstantKind) ValidEnum

func (_ ConstantKind) ValidEnum(v int32) bool

type Declaration

type Declaration struct {
	// Type of the field
	Type *Type `json:"type"`
	// Name of the field
	Name string `json:"name"`
	// Modifier of the type
	Modifier *Declaration_Modifier `json:"modifier"`
	// Field attributes
	Attributes Attributes `json:"attributes"`
}

Field declaration

func (*Declaration) Equal

func (l *Declaration) Equal(r *Declaration) bool

Equal returns if two declarations are equal

func (*Declaration) IsVoid

func (d *Declaration) IsVoid() bool

IsVoid returns if this is a void (empty) declaration

type DeclarationModifier

type DeclarationModifier uint32

How a declaration modifies its type

const (
	DECLARATION_MODIFIER_NONE      DeclarationModifier = 0
	DECLARATION_MODIFIER_OPTIONAL  DeclarationModifier = 1
	DECLARATION_MODIFIER_FIXED     DeclarationModifier = 2
	DECLARATION_MODIFIER_FLEXIBLE  DeclarationModifier = 3
	DECLARATION_MODIFIER_UNBOUNDED DeclarationModifier = 5
)

func (DeclarationModifier) MarshalText

func (v DeclarationModifier) MarshalText() ([]byte, error)

func (DeclarationModifier) String

func (v DeclarationModifier) String() string

func (*DeclarationModifier) UnmarshalText

func (v *DeclarationModifier) UnmarshalText(buf []byte) error

func (DeclarationModifier) ValidEnum

func (_ DeclarationModifier) ValidEnum(v int32) bool

type Declaration_Modifier

type Declaration_Modifier struct {
	Kind DeclarationModifier `json:"kind"`
	Size uint32              `json:"size,omitempty"`
}

Modifier of the type

func (*Declaration_Modifier) ArmForSwitch

func (u *Declaration_Modifier) ArmForSwitch(sw uint32) (string, bool)

func (*Declaration_Modifier) SwitchFieldName

func (u *Declaration_Modifier) SwitchFieldName() string

func (*Declaration_Modifier) UnionDiscriminant

func (u *Declaration_Modifier) UnionDiscriminant() interface{}

func (*Declaration_Modifier) UnionValue

func (u *Declaration_Modifier) UnionValue() (interface{}, error)

type Definition

type Definition struct {
	// The name of the definition
	Name string `json:"name"`
	// The attributes of the definition
	Attributes Attributes       `json:"attributes"`
	Body       *Definition_Body `json:"body"`
}

A top-level definition

type DefinitionKind

type DefinitionKind uint32

The kind of a definition

const (
	DEFINITION_KIND_TYPE     DefinitionKind = 0
	DEFINITION_KIND_CONSTANT DefinitionKind = 1
)

func (DefinitionKind) MarshalText

func (v DefinitionKind) MarshalText() ([]byte, error)

func (DefinitionKind) String

func (v DefinitionKind) String() string

func (*DefinitionKind) UnmarshalText

func (v *DefinitionKind) UnmarshalText(buf []byte) error

func (DefinitionKind) ValidEnum

func (_ DefinitionKind) ValidEnum(v int32) bool

type Definition_Body

type Definition_Body struct {
	Kind DefinitionKind `json:"kind"`
	// Body, for type definitions
	Type *Type `json:"type,omitempty"`
	// Body, for constant definitions
	Constant *Constant `json:"constant,omitempty"`
}

Definition_Body is union definition.body

func (*Definition_Body) ArmForSwitch

func (u *Definition_Body) ArmForSwitch(sw uint32) (string, bool)

func (*Definition_Body) SwitchFieldName

func (u *Definition_Body) SwitchFieldName() string

func (*Definition_Body) UnionDiscriminant

func (u *Definition_Body) UnionDiscriminant() interface{}

func (*Definition_Body) UnionValue

func (u *Definition_Body) UnionValue() (interface{}, error)

type EnumSpec

type EnumSpec struct {
	// Set of all options
	Options []*EnumSpec_Options `json:"options"`
}

Definition of an enum

func (*EnumSpec) GetName

func (es *EnumSpec) GetName(val uint32) string

GetName returns the canonical (first) name for the specified numeric value

func (*EnumSpec) HasOption

func (es *EnumSpec) HasOption(name string) bool

HasOption returns if a named option exists

type EnumSpec_Options

type EnumSpec_Options struct {
	// Name of the enumerant
	Name string `json:"name"`
	// Value of the enumerant
	Value uint32 `json:"value"`
}

Set of all options

type Specification

type Specification struct {
	// Magic number: set to XDR_BIN_MAGIC
	Magic uint64 `json:"magic"`
	// Spec attributes (set using pragma directives)
	Attributes Attributes `json:"attributes"`
	// List of all definitions
	Definitions []*Definition `json:"definitions"`
}

Root object of a specification

func (*Specification) GetConstant

func (s *Specification) GetConstant(n string) (*Constant, error)

GetConstant looks up the named constant, returning an error if it is not found

func (*Specification) GetType

func (s *Specification) GetType(n string) (*Type, error)

GetType looks up the named type, returning an error if it is not found

func (*Specification) NamedDefinition

func (s *Specification) NamedDefinition(n string) *Definition

NamedDefinition looks for a definition with the specified name

func (*Specification) PutDefinition

func (s *Specification) PutDefinition(d *Definition) error

PutDefinition appends a definition with the speicifed name, if it would not conflict with one which already exists

type StructSpec

type StructSpec struct {
	// Set of struct members
	Members []*Declaration `json:"members"`
}

Definition of an enum

func (*StructSpec) HasMember

func (ss *StructSpec) HasMember(name string) bool

HasMember returns if a named member exists

type Type

type Type struct {
	Kind       TypeKind     `json:"kind"`
	EnumSpec   *EnumSpec    `json:"enum_spec,omitempty"`
	StructSpec *StructSpec  `json:"struct_spec,omitempty"`
	UnionSpec  *UnionSpec   `json:"union_spec,omitempty"`
	Ref        string       `json:"ref,omitempty"`
	TypeDef    *Declaration `json:"type_def,omitempty"`
}

Definition of a type

func Bool

func Bool() *Type

Bool returns a type of TYPE_BOOL

func Double

func Double() *Type

Double returns a type of TYPE_DOUBLE

func Float

func Float() *Type

Float returns a type of TYPE_FLOAT

func Hyper

func Hyper() *Type

Hyper returns a type of TYPE_HYPER

func Int

func Int() *Type

Int returns a type of TYPE_INT

func Opaque

func Opaque() *Type

Opaque returns a type of TYPE_OPAQUE

func Ref

func Ref(name string) *Type

Ref returns a type which is a reference to the specified name

func String

func String() *Type

String returns a type of TYPE_STRING

func UnsignedHyper

func UnsignedHyper() *Type

UnsignedHyper returns a type of TYPE_UNSIGNED_HYPER

func UnsignedInt

func UnsignedInt() *Type

UnsignedInt returns a type of TYPE_UNSIGNED_INT

func Void

func Void() *Type

Void returns a type of TYPE_VOID

func (*Type) ArmForSwitch

func (u *Type) ArmForSwitch(sw uint32) (string, bool)

func (*Type) Resolve

func (t *Type) Resolve(s *Specification) (*Type, error)

Resolve attempts to resolve a TYPE_REF into the underlying type, by looking at the passed specification

func (*Type) SwitchFieldName

func (u *Type) SwitchFieldName() string

func (*Type) UnionDiscriminant

func (u *Type) UnionDiscriminant() interface{}

func (*Type) UnionValue

func (u *Type) UnionValue() (interface{}, error)

type TypeKind

type TypeKind uint32

The kind of the type

const (
	TYPE_VOID           TypeKind = 0
	TYPE_BOOL           TypeKind = 1
	TYPE_INT            TypeKind = 2
	TYPE_UNSIGNED_INT   TypeKind = 3
	TYPE_HYPER          TypeKind = 4
	TYPE_UNSIGNED_HYPER TypeKind = 5
	TYPE_FLOAT          TypeKind = 6
	TYPE_DOUBLE         TypeKind = 7
	TYPE_STRING         TypeKind = 8
	TYPE_OPAQUE         TypeKind = 9
	TYPE_ENUM           TypeKind = 10
	TYPE_STRUCT         TypeKind = 11
	TYPE_UNION          TypeKind = 12
	TYPE_REF            TypeKind = 13
	TYPE_TYPEDEF        TypeKind = 14
)

func (TypeKind) MarshalText

func (v TypeKind) MarshalText() ([]byte, error)

func (TypeKind) String

func (v TypeKind) String() string

func (*TypeKind) UnmarshalText

func (v *TypeKind) UnmarshalText(buf []byte) error

func (TypeKind) ValidEnum

func (_ TypeKind) ValidEnum(v int32) bool

type UnionSpec

type UnionSpec struct {
	// Discriminant field
	Discriminant *Declaration `json:"discriminant"`
	// Set of union member fields
	Members []*Declaration `json:"members"`
	// Mapping from values to union member. `member` is the index of the member in `members`
	Options map[uint32]uint32 `json:"options"`
	// If a default member is present, defines it
	DefaultMember *uint32 `xdr:"opt" json:"default_member,omitempty"`
}

Definition of a union

func (*UnionSpec) GetMember

func (us *UnionSpec) GetMember(name string) (uint32, *Declaration)

GetMember returns the member with the specified name, and its index, if it exists

func (*UnionSpec) HasMember

func (us *UnionSpec) HasMember(name string) bool

HasMember returns if a member is already defined with the specified name

func (*UnionSpec) HasOption

func (us *UnionSpec) HasOption(val uint32) bool

HasOption returns if the numeric value specified is defined

type UnionSpec_Options

type UnionSpec_Options struct {
	Value  uint32 `json:"value"`
	Member uint32 `json:"member"`
}

Mapping from values to union member. `member` is the index of the member in `members`

Jump to

Keyboard shortcuts

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