codegen

package
v0.0.0-...-8023e94 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProxySuffix            = "Interface"
	StubSuffix             = "Stub"
	EventProxySuffix       = "EventProxy"
	TransitionalBaseSuffix = "TransitionalBase"
	ServiceNameSuffix      = "Name"
	RequestSuffix          = "InterfaceRequest"
	TagSuffix              = "Tag"
	WithCtxSuffix          = "WithCtx"

	SyscallZxPackage = "syscall/zx"
	SyscallZxAlias   = "_zx"

	BindingsPackage = "syscall/zx/fidl"
	BindingsAlias   = "_bindings"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bits

type Bits struct {
	fidl.Bits

	// Name is the name of the bits type alias.
	Name string

	// Type is the underlying primitive type for the bits.
	Type Type

	// Members is the list of bits variants that are a part of this bits.
	// The values of the Members must not overlap.
	Members []BitsMember
}

Bits represents the idiomatic representation of an bits in golang.

That is, something like: type MyBits int32 const (

MyBitsMember1 MyBits = 1
MyBitsMember2        = 4
...

)

type BitsMember

type BitsMember struct {
	fidl.Attributes

	// Name is the name of the bits variant without any prefix.
	Name string

	// Value is the raw value of the bits variant, represented as a string
	// to support many types.
	Value string
}

BitsMember represents a single bits variant. See Bits for more details.

type Const

type Const struct {
	fidl.Attributes

	// Name is the name of the constant.
	Name string

	// Type is the constant's type.
	Type Type

	// Value is the constant's value.
	Value string
}

Const represents the idiomatic representation of a constant in golang.

type Enum

type Enum struct {
	fidl.Enum

	// Name is the name of the enum type alias.
	Name string

	// Type is the underlying primitive type for the enum.
	Type Type

	// Members is the list of enum variants that are a part of this enum.
	// The values of the Members must not overlap.
	Members []EnumMember
}

Enum represents the idiomatic representation of an enum in golang.

That is, something like: type MyEnum int32 const (

MyEnumMember1 MyEnum = 1
MyEnumMember2        = 2
...

)

type EnumMember

type EnumMember struct {
	fidl.EnumMember

	// Name is the name of the enum variant without any prefix.
	Name string

	// Value is the raw value of the enum variant, represented as a string
	// to support many types.
	Value string
}

EnumMember represents a single enum variant. See Enum for more details.

type Generator

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

func NewGenerator

func NewGenerator() *Generator

func (*Generator) GenerateImplFile

func (gen *Generator) GenerateImplFile(tree Root, filename string) error

func (*Generator) GeneratePkgNameFile

func (gen *Generator) GeneratePkgNameFile(tree Root, filename string) error

type Library

type Library struct {
	// Alias is the alias of the golang package referring to a FIDL library.
	Alias string

	// Path is the path to the golang package referring to a FIDL library.
	Path string
}

Library represents a FIDL library as a golang package.

type Method

type Method struct {
	fidl.Attributes

	Ordinal     uint64
	OrdinalName string

	// Name is the name of the Method, including the protocol name as a prefix.
	Name string

	// HasRequest is true if this method has a request
	HasRequest bool

	// Request represents a golang struct containing the request parameters.
	Request *Struct

	// HasResponse is true if this method has a response
	HasResponse bool

	// Response represents an optional golang struct containing the response parameters.
	Response *Struct

	// EventExpectName is the name of the method for the client-side event proxy.
	// Only relevant if the method is an event.
	EventExpectName string

	// IsEvent is set to true if the method is an event. In this case, Response will always be
	// non-nil while Request will always be nil. EventExpectName will also be non-empty.
	IsEvent bool

	// IsTransitional is set to true if the method has the Transitional attribute.
	IsTransitional bool
}

Method represents a method of a FIDL protocol in terms of golang structures.

type Protocol

type Protocol struct {
	fidl.Attributes

	// Name is the Golang name of the protocol.
	Name string

	// ProxyName is the name of the proxy type for this FIDL protocol.
	ProxyName string

	// ProxyType is concrete type of proxy used for this FIDL protocol.
	ProxyType string

	// StubName is the name of the stub type for this FIDL protocol.
	StubName string

	// EventProxyName is the name of the event proxy type for this FIDL protocol.
	EventProxyName string

	// TransitionalBaseName is the name of the base implementation for transitional methods
	// for this FIDL protocol.
	TransitionalBaseName string

	// RequestName is the name of the protocol request type for this FIDL protocol.
	RequestName string

	// ServiceNameString is the string service name for this FIDL protocol.
	ServiceNameString string

	// ServiceNameConstant is the name of the service name constant for this FIDL protocol.
	ServiceNameConstant string

	// Methods is a list of methods for this FIDL protocol.
	Methods []Method
}

Protocol represents a FIDL protocol in terms of golang structures.

type Root

type Root struct {
	// Name is the name of the library.
	Name string

	// PackageName is the name of the golang package as other Go programs would
	// import it.
	PackageName string

	// BindingsAlias is the alias name of the golang package of the FIDL
	// bindings.
	BindingsAlias string

	// Bits represents a list of FIDL bits represented as Go bits.
	Bits []Bits

	// Consts represents a list of FIDL constants represented as Go constants.
	Consts []Const

	// Enums represents a list of FIDL enums represented as Go enums.
	Enums []Enum

	// Structs represents the list of FIDL structs represented as Go structs.
	Structs []Struct

	// Unions represents the list of FIDL unions represented as Go structs.
	Unions []Union

	// Table represents the list of FIDL tables represented as Go structs.
	Tables []Table

	// Protocols represents the list of FIDL protocols represented as Go types.
	Protocols []Protocol

	// Libraries represents the set of library dependencies for this FIDL library.
	Libraries []Library
}

Root is the root of the golang backend IR structure.

The golang backend IR structure is loosely modeled after an abstract syntax tree, and is used to generate golang code from templates.

func Compile

func Compile(fidlData fidl.Root) Root

Compile translates parsed FIDL IR into golang backend IR for code generation.

type StackOfBoundsTag

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

StackOfBoundsTag corresponds to the original "fidl" tag.

func (StackOfBoundsTag) IsEmpty

func (t StackOfBoundsTag) IsEmpty() bool

func (StackOfBoundsTag) String

func (t StackOfBoundsTag) String() string

String generates a string representation for the tag.

type Struct

type Struct struct {
	fidl.Attributes

	// Name is the name of the golang struct.
	Name string

	// Members is a list of the golang struct members.
	Members []StructMember

	Tags Tags
}

Struct represents a golang struct.

type StructMember

type StructMember struct {
	fidl.Attributes

	// Name is the name of the golang struct member.
	Name string

	// PrivateName is the unexported version of the name of the struct member.
	PrivateName string

	// Type is the type of the golang struct member.
	Type Type

	// Corresponds to fidl tag in generated go.
	Tags Tags
}

StructMember represents the member of a golang struct.

type Table

type Table struct {
	fidl.Attributes
	Name            string
	Members         []TableMember
	Tags            Tags
	UnknownDataType string
}

Table represents a FIDL table as a golang struct.

type TableMember

type TableMember struct {
	fidl.Attributes

	// DataField is the exported name of the FIDL table member.
	DataField string

	// PrivateDataField is an unexported name of the FIDL table member, used as
	// argument.
	PrivateDataField string

	// PresenceField is the exported name of boolean indicating presence of
	// the FIDL table member.
	PresenceField string

	// Setter is the exported name of the FIDL table member setter.
	Setter string

	// Getter is the exported name of the FIDL table member getter.
	Getter string

	// GetterWithDefault is the exported name of the FIDL table member getter
	// with a default value.
	GetterWithDefault string

	// Clearer is the exported name of the FIDL table member clearer.
	Clearer string

	// Haser is the exported name of the presence checker of the FIDL table
	// member.
	Haser string

	// Type is the golang type of the table member.
	Type Type

	// Corresponds to fidl: tag in generated go.
	Tags Tags
}

TableMember represents a FIDL table member as two golang struct members, one for the member itself, and one to indicate presence or absence.

type Tag

type Tag int32

Tag represents a go tag in the generated code.

const (
	FidlTag Tag // "fidl" tag with value from StackOfBoundsTag
	FidlSizeV1Tag
	FidlOffsetV1Tag
	FidlAlignmentV1Tag
	FidlHandleSubtypeTag
	FidlHandleRightsTag
	FidlBoundsTag
	FidlOrdinalTag
	FidlIsResourceTag
	EndTag   // This value must be last in the list to allow iteration over all tags.
	StartTag = FidlTag
)

func (Tag) String

func (t Tag) String() string

type Tags

type Tags map[Tag]interface{}

Tags is a collection containing the tag definitions.

func (Tags) String

func (t Tags) String() string

type Type

type Type string

Type represents a golang type.

type Union

type Union struct {
	fidl.Attributes
	Name    string
	TagName string
	Members []UnionMember
	Tags    Tags
	fidl.Strictness
	UnknownDataType string
}

type UnionMember

type UnionMember struct {
	fidl.Attributes
	Ordinal     uint64
	Name        string
	PrivateName string
	Type        Type
	Tags        Tags
}

Jump to

Keyboard shortcuts

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