| {{/* | |
| // Copyright 2023 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| */}} | |
| {{- define "Filename:CodingTables" -}} | |
| {{- .LibrarySlashes }}/cpp/tables.c | |
| {{- end }} | |
| {{- define "File:CodingTables" -}} | |
| // WARNING: This file is machine generated by fidlgen. | |
| {{ range $experiment := .Experiments }} | |
| // fidl_experiment = {{ $experiment }} | |
| {{- end }} | |
| #include <lib/fidl/internal.h> | |
| {{ "" }} | |
| {{- /* In the rest of this template, `.` is coding_tables.Root, not fidlgen_cpp.Root. */ -}} | |
| {{- with GetCodingTables -}} | |
| {{- range .ForwardDecls }} | |
| {{ .StorageClass }} const struct {{ .CType }} {{ .Name }}; | |
| {{- end }} | |
| {{ "" }} | |
| {{- range .Bits }} | |
| const struct FidlCodedBits {{ .Name }} = { | |
| .tag = kFidlTypeBits, | |
| .name = "{{ .FidlName }}", | |
| .underlying_type = {{ .UnderlyingType }}, | |
| .strictness = {{ .Strictness }}, | |
| .mask = {{ .Mask | printf "%#x" }}, | |
| }; | |
| {{ end }} | |
| {{- range .Enums }} | |
| {{- if .Validator }} | |
| static bool {{ .Validator }}(uint64_t v) { | |
| switch (v) { | |
| {{- range .Values }} | |
| case {{ . }}: | |
| {{- end }} | |
| return true; | |
| default: | |
| return false; | |
| } | |
| } | |
| {{- end }} | |
| const struct FidlCodedEnum {{ .Name }} = { | |
| .tag = kFidlTypeEnum, | |
| .name = "{{ .FidlName }}", | |
| .underlying_type = {{ .UnderlyingType }}, | |
| .strictness = {{ .Strictness }}, | |
| .validate = {{ or .Validator "NULL" }}, | |
| }; | |
| {{ end }} | |
| {{- range .Structs }} | |
| {{- if .Members }} | |
| static const struct FidlStructElement {{ .MembersName }}[] = { | |
| {{- range .Members }} | |
| { | |
| {{- if .Type }} | |
| .field = { | |
| .header = { | |
| .element_type = kFidlStructElementType_Field, | |
| .is_resource = {{ .Resourceness }}, | |
| }, | |
| .offset_v2 = {{ .Offset }}, | |
| .field_type = {{ .Type }}, | |
| }, | |
| {{- else }} | |
| .padding = { | |
| .header = { | |
| .element_type = kFidlStructElementType_Padding{{ .PaddingMaskBitWidth }}, | |
| .is_resource = kFidlIsResource_NotResource, | |
| }, | |
| .offset_v2 = {{ .Offset }}, | |
| .mask_{{ .PaddingMaskBitWidth }} = {{ .PaddingMask | printf "%#x" }}, | |
| }, | |
| {{- end }} | |
| }, | |
| {{- end }} | |
| }; | |
| {{- end }} | |
| const struct FidlCodedStruct {{ .Name }} = { | |
| .tag = kFidlTypeStruct, | |
| .name = "{{ .FidlName }}", | |
| .is_empty = {{ .Emptiness }}, | |
| .size_v2 = {{ .InlineSize }}, | |
| .elements = {{ .MembersName }}, | |
| .element_count = {{ len .Members }}, | |
| }; | |
| {{ end }} | |
| {{- range .Tables }} | |
| {{- if .Members }} | |
| static const struct FidlTableField {{ .MembersName }}[] = { | |
| {{- range .Members }} | |
| { .ordinal = {{ .Ordinal }}, .type = {{ .Type }} }, | |
| {{- end }} | |
| }; | |
| {{- end }} | |
| const struct FidlCodedTable {{ .Name }} = { | |
| .tag = kFidlTypeTable, | |
| .name = "{{ .FidlName }}", | |
| .is_resource = {{ .Resourceness }}, | |
| .fields = {{ .MembersName }}, | |
| .field_count = {{ len .Members }}, | |
| }; | |
| {{ end }} | |
| {{- range .Unions }} | |
| {{- if .Members }} | |
| static const struct FidlUnionField {{ .MembersName }}[] = { | |
| {{- range .Members }} | |
| { .type = {{ .Type }} }, | |
| {{- end }} | |
| }; | |
| {{- end }} | |
| const struct FidlCodedUnion {{ .Name }} = { | |
| .tag = kFidlTypeUnion, | |
| .name = "{{ .FidlName }}", | |
| .strictness = {{ .Strictness }}, | |
| .is_resource = {{ .Resourceness }}, | |
| .nullable = kFidlNullability_Nonnullable, | |
| .fields = {{ .MembersName }}, | |
| .field_count = {{ len .Members }}, | |
| }; | |
| {{- /* For every union, we emit a second coding table for when it's nullable. | |
| We must do this even if the library doesn't use it with `:optional`, | |
| because a dependent library might do so, and dependent libraries don't | |
| have enough information in the IR to construct the FidlCodedUnion. */}} | |
| const struct FidlCodedUnion {{ .NullableName }} = { | |
| .tag = kFidlTypeUnion, | |
| .name = "{{ .FidlName }}", | |
| .strictness = {{ .Strictness }}, | |
| .is_resource = {{ .Resourceness }}, | |
| .nullable = kFidlNullability_Nullable, | |
| .fields = {{ .MembersName }}, | |
| .field_count = {{ len .Members }}, | |
| }; | |
| {{ end }} | |
| {{- range .Arrays }} | |
| static const struct FidlCodedArray {{ .Name }} = { | |
| .tag = kFidlTypeArray, | |
| .element = {{ .ElementType }}, | |
| .array_size_v2 = {{ .InlineSize }}, | |
| .element_size_v2 = {{ .ElementSize }}, | |
| }; | |
| {{ end }} | |
| {{- range .Vectors }} | |
| static const struct FidlCodedVector {{ .Name }} = { | |
| .tag = kFidlTypeVector, | |
| .element = {{ .ElementType }}, | |
| .max_count = {{ .MaxCount }}, | |
| .nullable = {{ .Nullability }}, | |
| .element_size_v2 = {{ .ElementSize }}, | |
| }; | |
| {{ end }} | |
| {{- range .Strings }} | |
| static const struct FidlCodedString {{ .Name }} = { | |
| .tag = kFidlTypeString, | |
| .max_size = {{ .MaxCount }}, | |
| .nullable = {{ .Nullability }}, | |
| }; | |
| {{ end }} | |
| {{- range .Handles }} | |
| static const struct FidlCodedHandle {{ .Name }} = { | |
| .tag = kFidlTypeHandle, | |
| .handle_subtype = {{ .ObjectType }}, | |
| .handle_rights = {{ .Rights }}, | |
| .nullable = {{ .Nullability }}, | |
| }; | |
| {{ end }} | |
| {{- range .Boxes }} | |
| static const struct FidlCodedStructPointer {{ .Name }} = { | |
| .tag = kFidlTypeStructPointer, | |
| .struct_type = &{{ .StructName }}, | |
| }; | |
| {{ end }} | |
| {{- end }} | |
| {{- end }} |