fidlgen_cpp

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FamilyKinds = namespacedEnum(familyKinds{}).(familyKinds)

FamilyKinds are general categories identifying what operation we should use to pass a value without a move (LLCPP). It also defines the way we should initialize a field.

View Source
var Kinds = struct {
	Const    constKind
	Bits     bitsKind
	Enum     enumKind
	Protocol protocolKind
	Service  serviceKind
	Struct   structKind
	Table    tableKind
	Union    unionKind
}{}
View Source
var TypeKinds = namespacedEnum(typeKinds{}).(typeKinds)

TypeKinds are the kinds of declarations (arrays, primitives, structs, ...).

Functions

func EndOfFile

func EndOfFile() string

func EnsureNamespace

func EnsureNamespace(arg interface{}) string

EnsureNamespace changes the current namespace to the one supplied and returns the C++ code required to switch to that namespace.

func NewClangFormatter

func NewClangFormatter(clangFormatPath string) fidl.Formatter

NewClangFormatter a formatter that invokes clang-format. TODO(fxbug.dev/49757) Use --style=file and copy the .clang-format file to the correct location. An alternate way to do this is to load the config directly from .clang_format and put the style as JSON in quotes.

func PopNamespace

func PopNamespace() string

func PushNamespace

func PushNamespace() string

func UseNatural

func UseNatural() string

func UseWire

func UseWire() string

Types

type Bits

type Bits struct {
	fidl.Attributes
	fidl.Strictness
	DeclName
	Type      TypeName
	Mask      string
	MaskName  DeclName
	Members   []BitsMember
	WireAlias DeclVariant

	// Kind should be default initialized.
	Kind bitsKind
}

type BitsMember

type BitsMember struct {
	fidl.Attributes
	Name  string
	Value ConstantValue
}

type Const

type Const struct {
	fidl.Attributes
	DeclName
	Extern    bool
	Decorator string
	Type      Type
	Value     ConstantValue

	// Kind should be default initialized.
	Kind constKind
}

type ConstantValue

type ConstantValue struct {
	Natural string
	Wire    string
}

func (*ConstantValue) IsSet

func (cv *ConstantValue) IsSet() bool

func (*ConstantValue) String

func (cv *ConstantValue) String() string

type Decl

type Decl interface{}

A Decl is any type with a .Kind field.

type DeclName

type DeclName struct {
	Natural DeclVariant
	Wire    DeclVariant
}

func CommonDeclName

func CommonDeclName(decl DeclVariant) DeclName

CommonDeclName returns a DeclName with the same DeclVariant for both Wire and Natural variants.

func (DeclName) AppendName

func (dn DeclName) AppendName(suffix string) DeclName

AppendName returns a new DeclName with an suffix appended to the name portions.

func (DeclName) AppendNamespace

func (dn DeclName) AppendNamespace(c string) DeclName

AppendNamespace returns a new DeclName with additional C++ namespace components appended.

func (DeclName) MapNatural

func (dn DeclName) MapNatural(f DeclVariantFunc) DeclName

func (DeclName) MapWire

func (dn DeclName) MapWire(f DeclVariantFunc) DeclName

func (DeclName) Member

func (dn DeclName) Member(member string) MemberName

func (DeclName) Name

func (dn DeclName) Name() string

func (DeclName) Namespace

func (dn DeclName) Namespace() Namespace

func (DeclName) PrependName

func (dn DeclName) PrependName(prefix string) DeclName

PrependName returns a new DeclName with an prefix prepended to the name portions.

func (DeclName) String

func (dn DeclName) String() string

func (DeclName) TypeName

func (dn DeclName) TypeName() TypeName

TypeName turns a DeclName into a TypeName.

type DeclVariant

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

DeclVariant represents the name of a C++ declaration within a namespace.

func NewDeclVariant

func NewDeclVariant(name string, namespace Namespace) DeclVariant

NewDeclVariant creates a new DeclVariant with a name and a namespace.

func (DeclVariant) AppendName

func (d DeclVariant) AppendName(suffix string) DeclVariant

AppendName returns a new DeclVariant with an suffix appended to the name portion.

func (DeclVariant) AppendNamespace

func (d DeclVariant) AppendNamespace(part string) DeclVariant

AppendNamespace returns a new DeclVariant with an additional C++ namespace component appended.

func (DeclVariant) DropLastNamespaceComponent

func (d DeclVariant) DropLastNamespaceComponent() DeclVariant

DropLastNamespaceComponent returns a new DeclVariant with the same name but with the final component of the namespace removed.

func (DeclVariant) Name

func (d DeclVariant) Name() string

func (DeclVariant) Namespace

func (d DeclVariant) Namespace() Namespace

func (DeclVariant) PrependName

func (d DeclVariant) PrependName(prefix string) DeclVariant

PrependName returns a new DeclVariant with an prefix prepended to the name portion.

func (DeclVariant) String

func (d DeclVariant) String() string

func (DeclVariant) Type

func (d DeclVariant) Type() TypeVariant

type DeclVariantFunc

type DeclVariantFunc func(DeclVariant) DeclVariant

DeclVariantFunc is a function that operates over a DeclVariant.

type Enum

type Enum struct {
	fidl.Attributes
	fidl.Strictness
	DeclName
	Enum      fidl.Enum
	Type      TypeName
	Members   []EnumMember
	WireAlias DeclVariant

	// Kind should be default initialized.
	Kind enumKind
}

func (*Enum) UnknownValueForTmpl

func (e *Enum) UnknownValueForTmpl() interface{}

type EnumMember

type EnumMember struct {
	fidl.EnumMember
	Name  string
	Value ConstantValue
}

type HandleInformation

type HandleInformation struct {
	ObjectType string
	Rights     string
}

type LLContext

type LLContext int

LLContext indicates where the request/response is used. The allocation strategies differ for client and server contexts.

type LLContextProps

type LLContextProps struct {
	// Should the request be allocated on the stack, in the managed flavor.
	StackAllocRequest bool
	// Should the response be allocated on the stack, in the managed flavor.
	StackAllocResponse bool
	// Total number of bytes of stack used for storing the request.
	StackUseRequest int
	// Total number of bytes of stack used for storing the response.
	StackUseResponse int
}

LLContextProps contain context-dependent properties of a method specific to llcpp. Context is client (write request and read response) or server (read request and write response).

type LLProps

type LLProps struct {
	ProtocolName      DeclVariant
	LinearizeRequest  bool
	LinearizeResponse bool
	ClientContext     LLContextProps
	ServerContext     LLContextProps
}

LLProps contain properties of a method specific to llcpp

type Member

type Member interface {
	NameAndType() (string, Type)
}

type MemberName

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

func (MemberName) Decl

func (mn MemberName) Decl() DeclName

func (MemberName) Name

func (mn MemberName) Name() string

type Method

type Method struct {
	NameInLowerSnakeCase string
	// The name of a constant that defines the ordinal value.
	OrdinalName             string
	RequestSize             int
	RequestMaxHandles       int
	RequestMaxOutOfLine     int
	RequestSentMaxSize      int
	RequestPadding          bool
	RequestFlexible         bool
	RequestHasPointer       bool
	RequestIsResource       bool
	ResponseSize            int
	ResponseMaxHandles      int
	ResponseMaxOutOfLine    int
	ResponseSentMaxSize     int
	ResponseReceivedMaxSize int
	ResponsePadding         bool
	ResponseFlexible        bool
	ResponseHasPointer      bool
	ResponseIsResource      bool
	CallbackType            string
	ResponseHandlerType     string
	ResponderType           string
	LLProps                 LLProps
	// contains filtered or unexported fields
}

Method should be created using methodInner.build(). TODO: Consider factoring out common fields between Request and Response.

func (*Method) CallbackWrapper

func (m *Method) CallbackWrapper() string

func (*Method) ShouldEmitTypedChannelCascadingInheritance

func (m *Method) ShouldEmitTypedChannelCascadingInheritance() bool

ShouldEmitTypedChannelCascadingInheritance determines if the code generator should emit two overloads in the server interface API for this method, one with typed channels and the other with regular Zircon channels, during the migration to typed channels in LLCPP. TODO(fxbug.dev/65212): We should always only generate the version with typed channels.

type Namespace

type Namespace []string

Namespace represents a C++ namespace.

func (Namespace) Append

func (ns Namespace) Append(part string) Namespace

Append returns a new namespace with an additional component.

func (Namespace) DropLastComponent

func (ns Namespace) DropLastComponent() Namespace

DropLastComponent returns a new namespace with the final component removed.

func (Namespace) Namespace

func (ns Namespace) Namespace() Namespace

Namespace is implemented to satisfy the Namespaced interface.

func (Namespace) String

func (ns Namespace) String() string

type Namespaced

type Namespaced interface {
	Namespace() Namespace
}

Namespaced is implemented by types that have a C++ namespace.

type Parameter

type Parameter struct {
	Type              Type
	Name              string
	Offset            int
	HandleInformation *HandleInformation
}

func (Parameter) NameAndType

func (p Parameter) NameAndType() (string, Type)

type Protocol

type Protocol struct {

	// OneWayMethods contains the list of one-way (i.e. fire-and-forget) methods
	// in the protocol.
	OneWayMethods []Method

	// TwoWayMethods contains the list of two-way (i.e. has both request and
	// response) methods in the protocol.
	TwoWayMethods []Method

	// ClientMethods contains the list of client-initiated methods (i.e. any
	// interaction that is not an event). It is the union of one-way and two-way
	// methods.
	ClientMethods []Method

	// Events contains the list of events (i.e. initiated by servers)
	// in the protocol.
	Events []Method

	// Kind should always be default initialized.
	Kind protocolKind
	// contains filtered or unexported fields
}

Protocol should be created using protocolInner.build().

func (*Protocol) Name

func (p *Protocol) Name() string

func (*Protocol) NaturalType

func (p *Protocol) NaturalType() string

func (*Protocol) ShouldEmitTypedChannelCascadingInheritance

func (p *Protocol) ShouldEmitTypedChannelCascadingInheritance() bool

ShouldEmitTypedChannelCascadingInheritance determines if the code generator should emit two versions of the server interface pure virtual class for this protocol, one with typed channels and the other with regular Zircon channels, during the migration to typed channels in LLCPP. TODO(fxbug.dev/65212): We should always only generate the version with typed channels.

func (*Protocol) WireType

func (p *Protocol) WireType() string

type Result

type Result struct {
	ValueMembers    []Parameter
	ResultDecl      DeclName
	ErrorDecl       TypeName
	ValueDecl       TypeVariant
	ValueStructDecl TypeName
	ValueTupleDecl  TypeVariant
}

Holds information about error results on methods

func (Result) ValueArity

func (r Result) ValueArity() int

type Root

type Root struct {
	PrimaryHeader   string
	IncludeStem     string
	Headers         []string
	FuzzerHeaders   []string
	HandleTypes     []string
	Library         fidl.LibraryIdentifier
	LibraryReversed fidl.LibraryIdentifier
	Decls           []Decl
}

func CompileHL

func CompileHL(r fidl.Root) Root

func CompileLL

func CompileLL(r fidl.Root) Root

func CompileLibFuzzer

func CompileLibFuzzer(r fidl.Root) Root

type Service

type Service struct {
	fidl.Attributes
	DeclName
	ServiceName string
	Members     []ServiceMember

	// Kind should be default initialized.
	Kind serviceKind
}

type ServiceMember

type ServiceMember struct {
	fidl.Attributes
	ProtocolType DeclName
	Name         string
	MethodName   string
}

type Struct

type Struct struct {
	fidl.Attributes
	fidl.Resourceness
	DeclName
	TableType     string
	Members       []StructMember
	InlineSize    int
	MaxHandles    int
	MaxOutOfLine  int
	MaxSentSize   int
	HasPadding    bool
	IsResultValue bool
	HasPointer    bool
	Result        *Result
	WireAlias     DeclVariant
	// Full decls needed to check if a type is memcpy compatible.
	// Only set if it may be possible for a type to be memcpy compatible,
	// e.g. has no padding.
	// See the struct template for usage.
	FullDeclMemcpyCompatibleDeps []string

	// Kind should be default initialized.
	Kind structKind
}

type StructMember

type StructMember struct {
	fidl.Attributes
	Type              Type
	Name              string
	DefaultValue      ConstantValue
	Offset            int
	HandleInformation *HandleInformation
}

func (*StructMember) AsParameter

func (m *StructMember) AsParameter() Parameter

func (StructMember) NameAndType

func (sm StructMember) NameAndType() (string, Type)

type Table

type Table struct {
	fidl.Attributes
	fidl.Resourceness
	DeclName
	TableType      string
	Members        []TableMember
	InlineSize     int
	BiggestOrdinal int
	MaxHandles     int
	MaxOutOfLine   int
	MaxSentSize    int
	HasPointer     bool
	WireAlias      DeclVariant

	// FrameItems stores the members in ordinal order; "null" for reserved.
	FrameItems []TableFrameItem

	// Kind should be default initialized.
	Kind tableKind
}

type TableFrameItem

type TableFrameItem *TableMember

type TableMember

type TableMember struct {
	fidl.Attributes
	Type               Type
	Name               string
	DefaultValue       ConstantValue
	Ordinal            int
	FieldPresenceIsSet string
	FieldPresenceSet   string
	FieldPresenceClear string
	FieldDataName      string
	MethodHasName      string
	MethodClearName    string
	ValueUnionName     string
	HandleInformation  *HandleInformation
}

func (TableMember) NameAndType

func (tm TableMember) NameAndType() (string, Type)

type Type

type Type struct {
	TypeName

	WirePointer bool

	// Defines what operation we should use to pass a value without a move (LLCPP). It also
	// defines the way we should initialize a field.
	WireFamily familyKind

	// NeedsDtor indicates whether this type needs to be destructed explicitely
	// or not.
	NeedsDtor bool

	Kind typeKind

	IsResource bool

	DeclarationName fidl.EncodedCompoundIdentifier

	// Set iff IsArray || IsVector
	ElementType *Type
	// Valid iff IsArray
	ElementCount int
}

func (*Type) IsPrimitiveType

func (t *Type) IsPrimitiveType() bool

IsPrimitiveType returns true if this type is primitive.

func (*Type) WireArgumentDeclaration

func (t *Type) WireArgumentDeclaration(n string) string

WireArgumentDeclaration returns the argument declaration for this type for the wire variant.

func (*Type) WireInitMessage

func (t *Type) WireInitMessage(n string) string

WireInitMessage returns message field initialization for the wire variant.

func (*Type) WireNoTypedChannels

func (t *Type) WireNoTypedChannels() TypeVariant

WireNoTypedChannels returns the LLCPP declaration when the relevant API would like to opt out of typed channels. TODO(fxbug.dev/65212): Uses of this method should be be replaced by WireDecl.

type TypeName

type TypeName struct {
	Natural TypeVariant
	Wire    TypeVariant
}

TypeName is the name of a type for wire and natural types.

func CommonTypeName

func CommonTypeName(name TypeVariant) TypeName

CommonTypeName returns a TypeName with same name for both natural and wire types.

func PrimitiveTypeName

func PrimitiveTypeName(primitive string) TypeName

PrimitiveTypeName returns a TypeName for a primitive type, common across all bindings.

func TypeNameForHandle

func TypeNameForHandle(t fidl.HandleSubtype) TypeName

TypeNameForHandle returns the C++ name for a handle type

func TypeNameForPrimitive

func TypeNameForPrimitive(t fidl.PrimitiveSubtype) TypeName

TypeNameForPrimitive returns the C++ name of a FIDL primitive type.

func (TypeName) MapNatural

func (tn TypeName) MapNatural(f TypeVariantFunc) TypeName

func (TypeName) MapWire

func (tn TypeName) MapWire(f TypeVariantFunc) TypeName

func (TypeName) String

func (tn TypeName) String() string

func (TypeName) WithArrayTemplates

func (tn TypeName) WithArrayTemplates(natural, wire string, arg int) TypeName

WithArrayTemplates wraps type names with templates applications that take integers.

func (TypeName) WithTemplates

func (tn TypeName) WithTemplates(natural, wire string) TypeName

WithTemplates wraps type names with template applications.

type TypeVariant

type TypeVariant string

TypeVariant is implemented by something that can be a type name for a particular binding style.

func (TypeVariant) WithArrayTemplate

func (name TypeVariant) WithArrayTemplate(template string, arg int) TypeVariant

WithArrayTemplate wraps a TypeVariant with a template application that takes an integer.

func (TypeVariant) WithTemplate

func (name TypeVariant) WithTemplate(template string) TypeVariant

WithTemplate wraps a TypeVariant with a template application.

type TypeVariantFunc

type TypeVariantFunc func(TypeVariant) TypeVariant

TypeVariantFunc is a function that operates over a TypeVariant.

type Union

type Union struct {
	fidl.Attributes
	fidl.Strictness
	fidl.Resourceness
	DeclName
	TableType    string
	Members      []UnionMember
	InlineSize   int
	MaxHandles   int
	MaxOutOfLine int
	Result       *Result
	HasPointer   bool
	WireAlias    DeclVariant

	// Kind should be default initialized.
	Kind unionKind
}

type UnionMember

type UnionMember struct {
	fidl.Attributes
	Ordinal           uint64
	Type              Type
	Name              string
	StorageName       string
	TagName           string
	Offset            int
	HandleInformation *HandleInformation
}

func (UnionMember) NameAndType

func (um UnionMember) NameAndType() (string, Type)

func (UnionMember) UpperCamelCaseName

func (um UnionMember) UpperCamelCaseName() string

Jump to

Keyboard shortcuts

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