From 1db9465104d0a0338d5ce9df1485fd3980f78c16 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 20 Dec 2023 02:08:18 +0000 Subject: [PATCH] Auto-generate files after cl/592392732 --- php/ext/google/protobuf/php-upb.c | 45 +-- php/ext/google/protobuf/php-upb.h | 529 +++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.c | 45 +-- ruby/ext/google/protobuf_c/ruby-upb.h | 529 +++++++++++++------------- 4 files changed, 580 insertions(+), 568 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 1a4db4a89392..c3d968c2f269 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -6196,9 +6196,9 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { - size_t size = array->UPB_PRIVATE(size); - upb_Array* cloned_array = - UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); if (!cloned_array) { return NULL; } @@ -6386,7 +6386,8 @@ upb_Message* upb_Message_ShallowClone(const upb_Message* msg, // Must be last. upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return UPB_PRIVATE(_upb_Array_New)(a, 4, upb_CType_SizeLg2(type)); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); } const void* upb_Array_DataPtr(const upb_Array* arr) { @@ -8415,6 +8416,23 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( } +#include + +// Must be last. + +// A MiniTable for an empty message, used for unlinked sub-messages. +const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { + .UPB_PRIVATE(subs) = NULL, + .UPB_PRIVATE(fields) = NULL, + .UPB_PRIVATE(size) = 0, + .UPB_PRIVATE(field_count) = 0, + .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, + .UPB_PRIVATE(dense_below) = 0, + .UPB_PRIVATE(table_mask) = -1, + .UPB_PRIVATE(required_count) = 0, +}; + + #include #include #include @@ -8482,23 +8500,6 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, } -#include - -// Must be last. - -// A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { - .UPB_PRIVATE(subs) = NULL, - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = 0, - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; - - // Must be last. @@ -13258,7 +13259,7 @@ static const char* _upb_Decoder_DecodeEnumPacked( upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); - const size_t lg2 = upb_FieldType_SizeLg2(field_type); + const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 0df6c4fd9c4e..60e333a53bc8 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -979,84 +979,8 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #define UPB_MINI_TABLE_MESSAGE_H_ -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ - -// Must be last - -typedef struct upb_MiniTableEnum upb_MiniTableEnum; - -#ifdef __cplusplus -extern "C" { -#endif - -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_ENUM_H_ */ - -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ #include @@ -1082,7 +1006,7 @@ extern "C" { #endif // Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { static const int8_t size[] = { 0, // kUpb_CType_Bool 2, // kUpb_CType_Float @@ -1102,7 +1026,7 @@ UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { } // Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { static const int8_t size[] = { 3, // kUpb_FieldType_Double 2, // kUpb_FieldType_Float @@ -1135,6 +1059,21 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ +#ifndef UPB_MINI_TABLE_TYPES_H_ +#define UPB_MINI_TABLE_TYPES_H_ + +// Minitable types are recursively defined so declare them all together here. + +typedef struct upb_MiniTable upb_MiniTable; +typedef struct upb_MiniTableEnum upb_MiniTableEnum; +typedef struct upb_MiniTableExtension upb_MiniTableExtension; +typedef struct upb_MiniTableField upb_MiniTableField; +typedef struct upb_MiniTableFile upb_MiniTableFile; + +typedef union upb_MiniTableSub upb_MiniTableSub; + +#endif /* UPB_MINI_TABLE_TYPES_H_ */ + // Must be last. // LINT.IfChange(struct_definition) @@ -1195,47 +1134,47 @@ extern "C" { #endif UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) { return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); } UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) { return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; @@ -1246,7 +1185,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { } UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } @@ -1265,23 +1204,23 @@ _upb_MiniTableField_HasbitOffset(const struct upb_MiniTableField* f) { } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->presence < 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } else { @@ -1306,7 +1245,7 @@ _upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); @@ -1314,16 +1253,17 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); UPB_ASSUME(f->presence == 0); } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - return upb_FieldType_SizeLg2((upb_FieldType)f->UPB_PRIVATE(descriptortype)); +UPB_INLINE size_t +UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } // LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) @@ -1335,113 +1275,42 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( #endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ -// Must be last. - -typedef struct upb_MiniTableField upb_MiniTableField; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); -} - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ - -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ - - #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ + // Must be last. union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); + const upb_MiniTable* UPB_PRIVATE(submsg); + const upb_MiniTableEnum* UPB_PRIVATE(subenum); }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) { + upb_MiniTableSub out; out.UPB_PRIVATE(subenum) = subenum; return out; } -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) { + upb_MiniTableSub out; out.UPB_PRIVATE(submsg) = submsg; return out; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(subenum); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(submsg); } @@ -1478,10 +1347,11 @@ typedef enum { // upb_MiniTable represents the memory layout of a given upb_MessageDef. // The members are public so generated code can initialize them, // but users MUST NOT directly read or write any of its members. + // LINT.IfChange(minitable_struct_definition) struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); + const upb_MiniTableSub* UPB_PRIVATE(subs); + const upb_MiniTableField* UPB_ONLYBITS(fields); // Must be aligned to sizeof(void*). Doesn't include internal members like // unknown fields, extension dict, pointer to msglayout, etc. @@ -1505,47 +1375,43 @@ struct upb_MiniTable { extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) { return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) { return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)( + const upb_MiniTable* m, uint32_t i) { return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); UPB_ASSUME(ret); return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); return UPB_PRIVATE(_upb_MiniTableSub_Enum)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -1570,7 +1436,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + const upb_MiniTable* m, const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } @@ -1581,7 +1447,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( // RequiredMask(1) => 0b10 (0x2) // RequiredMask(5) => 0b111110 (0x3e) UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { int n = m->UPB_PRIVATE(required_count); UPB_ASSERT(0 < n && n <= 63); return ((1ULL << n) - 1) << 1; @@ -1596,8 +1462,6 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { // Must be last. -typedef struct upb_MiniTable upb_MiniTable; - #ifdef __cplusplus extern "C" { #endif @@ -1712,38 +1576,150 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg); #include +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ + +#include + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + +#ifndef UPB_MINI_TABLE_SUB_H_ +#define UPB_MINI_TABLE_SUB_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Constructors + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { + return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); +} + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { + return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); +} + +// Getters + +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_SUB_H_ */ + // Must be last. struct upb_MiniTableExtension { // Do not move this field. We need to be able to alias pointers. - struct upb_MiniTableField UPB_PRIVATE(field); + upb_MiniTableField UPB_PRIVATE(field); - const struct upb_MiniTable* UPB_PRIVATE(extendee); - union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum + const upb_MiniTable* UPB_PRIVATE(extendee); + upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { - return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) { + return (const upb_MiniTableField*)&e->UPB_PRIVATE(field); } -UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( - const struct upb_MiniTableExtension* e) { +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) { return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTableExtension_GetSubMessage)( - const struct upb_MiniTableExtension* e) { - return e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE( + _upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) { + return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( - struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; } @@ -1756,13 +1732,11 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( // Must be last. -typedef struct upb_MiniTableExtension upb_MiniTableExtension; - #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTableExtension_AsField( +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); } @@ -1772,13 +1746,13 @@ upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); } UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { return UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } @@ -2940,40 +2914,72 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, #endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ -#ifndef UPB_MINI_TABLE_SUB_H_ -#define UPB_MINI_TABLE_SUB_H_ +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ + +#include // Must be last. -typedef union upb_MiniTableSub upb_MiniTableSub; +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; #ifdef __cplusplus extern "C" { #endif -// Constructors +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromEnum(const struct upb_MiniTableEnum* subenum) { - return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; } -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromMessage(const struct upb_MiniTable* submsg) { - return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -// Getters -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableSub_Enum( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); -} +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +// Must be last + +#ifdef __cplusplus +extern "C" { +#endif + +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); } #ifdef __cplusplus @@ -2981,7 +2987,7 @@ UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( #endif -#endif /* UPB_MINI_TABLE_SUB_H_ */ +#endif /* UPB_MINI_TABLE_ENUM_H_ */ // Must be last. @@ -3747,12 +3753,13 @@ UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( #ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ #define UPB_MINI_TABLE_INTERNAL_FILE_H_ + // Must be last. struct upb_MiniTableFile { - const struct upb_MiniTable** UPB_PRIVATE(msgs); - const struct upb_MiniTableEnum** UPB_PRIVATE(enums); - const struct upb_MiniTableExtension** UPB_PRIVATE(exts); + const upb_MiniTable** UPB_PRIVATE(msgs); + const upb_MiniTableEnum** UPB_PRIVATE(enums); + const upb_MiniTableExtension** UPB_PRIVATE(exts); int UPB_PRIVATE(msg_count); int UPB_PRIVATE(enum_count); int UPB_PRIVATE(ext_count); @@ -3763,34 +3770,34 @@ extern "C" { #endif UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(enum_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(ext_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(msg_count); } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); return f->UPB_PRIVATE(enums)[i]; } -UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE( - _upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE( + _upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); return f->UPB_PRIVATE(exts)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); return f->UPB_PRIVATE(msgs)[i]; } @@ -3802,15 +3809,13 @@ UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( #endif /* UPB_MINI_TABLE_INTERNAL_FILE_H_ */ -typedef struct upb_MiniTableFile upb_MiniTableFile; - // Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableFile_Enum( +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableFile_Enum( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Enum)(f, i); } @@ -3819,7 +3824,7 @@ UPB_API_INLINE int upb_MiniTableFile_EnumCount(const upb_MiniTableFile* f) { return UPB_PRIVATE(_upb_MiniTableFile_EnumCount)(f); } -UPB_API_INLINE const struct upb_MiniTableExtension* upb_MiniTableFile_Extension( +UPB_API_INLINE const upb_MiniTableExtension* upb_MiniTableFile_Extension( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Extension)(f, i); } @@ -3829,7 +3834,7 @@ UPB_API_INLINE int upb_MiniTableFile_ExtensionCount( return UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)(f); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableFile_Message( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableFile_Message( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Message)(f, i); } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 7492b92102b3..6bff74c01004 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5710,9 +5710,9 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { - size_t size = array->UPB_PRIVATE(size); - upb_Array* cloned_array = - UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); if (!cloned_array) { return NULL; } @@ -5900,7 +5900,8 @@ upb_Message* upb_Message_ShallowClone(const upb_Message* msg, // Must be last. upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return UPB_PRIVATE(_upb_Array_New)(a, 4, upb_CType_SizeLg2(type)); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); } const void* upb_Array_DataPtr(const upb_Array* arr) { @@ -7929,6 +7930,23 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( } +#include + +// Must be last. + +// A MiniTable for an empty message, used for unlinked sub-messages. +const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { + .UPB_PRIVATE(subs) = NULL, + .UPB_PRIVATE(fields) = NULL, + .UPB_PRIVATE(size) = 0, + .UPB_PRIVATE(field_count) = 0, + .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, + .UPB_PRIVATE(dense_below) = 0, + .UPB_PRIVATE(table_mask) = -1, + .UPB_PRIVATE(required_count) = 0, +}; + + #include #include #include @@ -7996,23 +8014,6 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, } -#include - -// Must be last. - -// A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { - .UPB_PRIVATE(subs) = NULL, - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = 0, - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; - - // Must be last. @@ -12772,7 +12773,7 @@ static const char* _upb_Decoder_DecodeEnumPacked( upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); - const size_t lg2 = upb_FieldType_SizeLg2(field_type); + const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index d67f23518d9c..7ef7460eae5c 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -981,84 +981,8 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #define UPB_MINI_TABLE_MESSAGE_H_ -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ - -// Must be last - -typedef struct upb_MiniTableEnum upb_MiniTableEnum; - -#ifdef __cplusplus -extern "C" { -#endif - -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_ENUM_H_ */ - -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ #include @@ -1084,7 +1008,7 @@ extern "C" { #endif // Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { static const int8_t size[] = { 0, // kUpb_CType_Bool 2, // kUpb_CType_Float @@ -1104,7 +1028,7 @@ UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { } // Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { static const int8_t size[] = { 3, // kUpb_FieldType_Double 2, // kUpb_FieldType_Float @@ -1137,6 +1061,21 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ +#ifndef UPB_MINI_TABLE_TYPES_H_ +#define UPB_MINI_TABLE_TYPES_H_ + +// Minitable types are recursively defined so declare them all together here. + +typedef struct upb_MiniTable upb_MiniTable; +typedef struct upb_MiniTableEnum upb_MiniTableEnum; +typedef struct upb_MiniTableExtension upb_MiniTableExtension; +typedef struct upb_MiniTableField upb_MiniTableField; +typedef struct upb_MiniTableFile upb_MiniTableFile; + +typedef union upb_MiniTableSub upb_MiniTableSub; + +#endif /* UPB_MINI_TABLE_TYPES_H_ */ + // Must be last. // LINT.IfChange(struct_definition) @@ -1197,47 +1136,47 @@ extern "C" { #endif UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) { return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); } UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) { return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; @@ -1248,7 +1187,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { } UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } @@ -1267,23 +1206,23 @@ _upb_MiniTableField_HasbitOffset(const struct upb_MiniTableField* f) { } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->presence < 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } else { @@ -1308,7 +1247,7 @@ _upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); @@ -1316,16 +1255,17 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); UPB_ASSUME(f->presence == 0); } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - return upb_FieldType_SizeLg2((upb_FieldType)f->UPB_PRIVATE(descriptortype)); +UPB_INLINE size_t +UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } // LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) @@ -1337,113 +1277,42 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( #endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ -// Must be last. - -typedef struct upb_MiniTableField upb_MiniTableField; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); -} - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ - -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ - - #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ + // Must be last. union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); + const upb_MiniTable* UPB_PRIVATE(submsg); + const upb_MiniTableEnum* UPB_PRIVATE(subenum); }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) { + upb_MiniTableSub out; out.UPB_PRIVATE(subenum) = subenum; return out; } -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) { + upb_MiniTableSub out; out.UPB_PRIVATE(submsg) = submsg; return out; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(subenum); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(submsg); } @@ -1480,10 +1349,11 @@ typedef enum { // upb_MiniTable represents the memory layout of a given upb_MessageDef. // The members are public so generated code can initialize them, // but users MUST NOT directly read or write any of its members. + // LINT.IfChange(minitable_struct_definition) struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); + const upb_MiniTableSub* UPB_PRIVATE(subs); + const upb_MiniTableField* UPB_ONLYBITS(fields); // Must be aligned to sizeof(void*). Doesn't include internal members like // unknown fields, extension dict, pointer to msglayout, etc. @@ -1507,47 +1377,43 @@ struct upb_MiniTable { extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) { return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) { return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)( + const upb_MiniTable* m, uint32_t i) { return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); UPB_ASSUME(ret); return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); return UPB_PRIVATE(_upb_MiniTableSub_Enum)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -1572,7 +1438,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + const upb_MiniTable* m, const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } @@ -1583,7 +1449,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( // RequiredMask(1) => 0b10 (0x2) // RequiredMask(5) => 0b111110 (0x3e) UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { int n = m->UPB_PRIVATE(required_count); UPB_ASSERT(0 < n && n <= 63); return ((1ULL << n) - 1) << 1; @@ -1598,8 +1464,6 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { // Must be last. -typedef struct upb_MiniTable upb_MiniTable; - #ifdef __cplusplus extern "C" { #endif @@ -1714,38 +1578,150 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg); #include +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ + +#include + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + +#ifndef UPB_MINI_TABLE_SUB_H_ +#define UPB_MINI_TABLE_SUB_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Constructors + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { + return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); +} + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { + return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); +} + +// Getters + +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_SUB_H_ */ + // Must be last. struct upb_MiniTableExtension { // Do not move this field. We need to be able to alias pointers. - struct upb_MiniTableField UPB_PRIVATE(field); + upb_MiniTableField UPB_PRIVATE(field); - const struct upb_MiniTable* UPB_PRIVATE(extendee); - union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum + const upb_MiniTable* UPB_PRIVATE(extendee); + upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { - return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) { + return (const upb_MiniTableField*)&e->UPB_PRIVATE(field); } -UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( - const struct upb_MiniTableExtension* e) { +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) { return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTableExtension_GetSubMessage)( - const struct upb_MiniTableExtension* e) { - return e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE( + _upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) { + return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( - struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; } @@ -1758,13 +1734,11 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( // Must be last. -typedef struct upb_MiniTableExtension upb_MiniTableExtension; - #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTableExtension_AsField( +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); } @@ -1774,13 +1748,13 @@ upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); } UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { return UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } @@ -2942,40 +2916,72 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, #endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ -#ifndef UPB_MINI_TABLE_SUB_H_ -#define UPB_MINI_TABLE_SUB_H_ +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ + +#include // Must be last. -typedef union upb_MiniTableSub upb_MiniTableSub; +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; #ifdef __cplusplus extern "C" { #endif -// Constructors +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromEnum(const struct upb_MiniTableEnum* subenum) { - return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; } -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromMessage(const struct upb_MiniTable* submsg) { - return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -// Getters -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableSub_Enum( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); -} +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +// Must be last + +#ifdef __cplusplus +extern "C" { +#endif + +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); } #ifdef __cplusplus @@ -2983,7 +2989,7 @@ UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( #endif -#endif /* UPB_MINI_TABLE_SUB_H_ */ +#endif /* UPB_MINI_TABLE_ENUM_H_ */ // Must be last. @@ -3749,12 +3755,13 @@ UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( #ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ #define UPB_MINI_TABLE_INTERNAL_FILE_H_ + // Must be last. struct upb_MiniTableFile { - const struct upb_MiniTable** UPB_PRIVATE(msgs); - const struct upb_MiniTableEnum** UPB_PRIVATE(enums); - const struct upb_MiniTableExtension** UPB_PRIVATE(exts); + const upb_MiniTable** UPB_PRIVATE(msgs); + const upb_MiniTableEnum** UPB_PRIVATE(enums); + const upb_MiniTableExtension** UPB_PRIVATE(exts); int UPB_PRIVATE(msg_count); int UPB_PRIVATE(enum_count); int UPB_PRIVATE(ext_count); @@ -3765,34 +3772,34 @@ extern "C" { #endif UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(enum_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(ext_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(msg_count); } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); return f->UPB_PRIVATE(enums)[i]; } -UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE( - _upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE( + _upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); return f->UPB_PRIVATE(exts)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); return f->UPB_PRIVATE(msgs)[i]; } @@ -3804,15 +3811,13 @@ UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( #endif /* UPB_MINI_TABLE_INTERNAL_FILE_H_ */ -typedef struct upb_MiniTableFile upb_MiniTableFile; - // Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableFile_Enum( +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableFile_Enum( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Enum)(f, i); } @@ -3821,7 +3826,7 @@ UPB_API_INLINE int upb_MiniTableFile_EnumCount(const upb_MiniTableFile* f) { return UPB_PRIVATE(_upb_MiniTableFile_EnumCount)(f); } -UPB_API_INLINE const struct upb_MiniTableExtension* upb_MiniTableFile_Extension( +UPB_API_INLINE const upb_MiniTableExtension* upb_MiniTableFile_Extension( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Extension)(f, i); } @@ -3831,7 +3836,7 @@ UPB_API_INLINE int upb_MiniTableFile_ExtensionCount( return UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)(f); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableFile_Message( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableFile_Message( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Message)(f, i); }