upb: move IsSubMessage() and IsRepeatedOrMap() from mini_table/internal/field.h

PiperOrigin-RevId: 584082079
pull/14803/head
Eric Salo 1 year ago committed by Copybara-Service
parent 9b8b2760f8
commit 7fa050d8c1
  1. 38
      upb/message/accessors.h
  2. 4
      upb/message/copy.c
  3. 2
      upb/message/internal/accessors.h
  4. 1
      upb/mini_descriptor/BUILD
  5. 14
      upb/mini_descriptor/decode.c
  6. 18
      upb/mini_table/field.h
  7. 10
      upb/mini_table/internal/field.h
  8. 4
      upb/wire/decode.c
  9. 4
      upb_generator/protoc-gen-upb.cc

@ -63,7 +63,7 @@ UPB_API_INLINE bool upb_Message_GetBool(const upb_Message* msg,
bool default_val) { bool default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Bool); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Bool);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
bool ret; bool ret;
_upb_Message_GetField(msg, field, &default_val, &ret); _upb_Message_GetField(msg, field, &default_val, &ret);
return ret; return ret;
@ -74,7 +74,7 @@ UPB_API_INLINE bool upb_Message_SetBool(upb_Message* msg,
bool value, upb_Arena* a) { bool value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Bool); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Bool);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
@ -84,7 +84,7 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const upb_Message* msg,
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 || UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(field) == kUpb_CType_Enum); upb_MiniTableField_CType(field) == kUpb_CType_Enum);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
int32_t ret; int32_t ret;
_upb_Message_GetField(msg, field, &default_val, &ret); _upb_Message_GetField(msg, field, &default_val, &ret);
return ret; return ret;
@ -96,7 +96,7 @@ UPB_API_INLINE bool upb_Message_SetInt32(upb_Message* msg,
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 || UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(field) == kUpb_CType_Enum); upb_MiniTableField_CType(field) == kUpb_CType_Enum);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
@ -105,7 +105,7 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const upb_Message* msg,
uint32_t default_val) { uint32_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt32); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt32);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
uint32_t ret; uint32_t ret;
_upb_Message_GetField(msg, field, &default_val, &ret); _upb_Message_GetField(msg, field, &default_val, &ret);
return ret; return ret;
@ -116,7 +116,7 @@ UPB_API_INLINE bool upb_Message_SetUInt32(upb_Message* msg,
uint32_t value, upb_Arena* a) { uint32_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt32); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt32);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
@ -125,7 +125,7 @@ UPB_API_INLINE void upb_Message_SetClosedEnum(
const upb_MiniTableField* field, int32_t value) { const upb_MiniTableField* field, int32_t value) {
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(field)); UPB_ASSERT(upb_MiniTableField_IsClosedEnum(field));
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
UPB_ASSERT(upb_MiniTableEnum_CheckValue( UPB_ASSERT(upb_MiniTableEnum_CheckValue(
upb_MiniTable_GetSubEnumTable(msg_mini_table, field), value)); upb_MiniTable_GetSubEnumTable(msg_mini_table, field), value));
_upb_Message_SetNonExtensionField(msg, field, &value); _upb_Message_SetNonExtensionField(msg, field, &value);
@ -136,7 +136,7 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg,
uint64_t default_val) { uint64_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int64); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int64);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
int64_t ret; int64_t ret;
_upb_Message_GetField(msg, field, &default_val, &ret); _upb_Message_GetField(msg, field, &default_val, &ret);
return ret; return ret;
@ -147,7 +147,7 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg,
int64_t value, upb_Arena* a) { int64_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int64); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Int64);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
@ -156,7 +156,7 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const upb_Message* msg,
uint64_t default_val) { uint64_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt64); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt64);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
uint64_t ret; uint64_t ret;
_upb_Message_GetField(msg, field, &default_val, &ret); _upb_Message_GetField(msg, field, &default_val, &ret);
return ret; return ret;
@ -167,7 +167,7 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg,
uint64_t value, upb_Arena* a) { uint64_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt64); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_UInt64);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
@ -176,7 +176,7 @@ UPB_API_INLINE float upb_Message_GetFloat(const upb_Message* msg,
float default_val) { float default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Float); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Float);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
float ret; float ret;
_upb_Message_GetField(msg, field, &default_val, &ret); _upb_Message_GetField(msg, field, &default_val, &ret);
return ret; return ret;
@ -187,7 +187,7 @@ UPB_API_INLINE bool upb_Message_SetFloat(upb_Message* msg,
float value, upb_Arena* a) { float value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Float); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Float);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
@ -196,7 +196,7 @@ UPB_API_INLINE double upb_Message_GetDouble(const upb_Message* msg,
double default_val) { double default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Double); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Double);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
double ret; double ret;
_upb_Message_GetField(msg, field, &default_val, &ret); _upb_Message_GetField(msg, field, &default_val, &ret);
return ret; return ret;
@ -207,7 +207,7 @@ UPB_API_INLINE bool upb_Message_SetDouble(upb_Message* msg,
double value, upb_Arena* a) { double value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Double); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Double);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_8Byte);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
@ -217,7 +217,7 @@ upb_Message_GetString(const upb_Message* msg, const upb_MiniTableField* field,
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_String || UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_String ||
upb_MiniTableField_CType(field) == kUpb_CType_Bytes); upb_MiniTableField_CType(field) == kUpb_CType_Bytes);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_StringView); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_StringView);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
upb_StringView ret; upb_StringView ret;
_upb_Message_GetField(msg, field, &def_val, &ret); _upb_Message_GetField(msg, field, &def_val, &ret);
return ret; return ret;
@ -229,7 +229,7 @@ UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg,
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_String || UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_String ||
upb_MiniTableField_CType(field) == kUpb_CType_Bytes); upb_MiniTableField_CType(field) == kUpb_CType_Bytes);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_StringView); UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_StringView);
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
return _upb_Message_SetField(msg, field, &value, a); return _upb_Message_SetField(msg, field, &value, a);
} }
@ -239,7 +239,7 @@ UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == UPB_ASSUME(_upb_MiniTableField_GetRep(field) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
upb_TaggedMessagePtr tagged; upb_TaggedMessagePtr tagged;
_upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged);
return tagged; return tagged;
@ -262,7 +262,7 @@ UPB_API_INLINE void _upb_Message_SetTaggedMessagePtr(
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == UPB_ASSUME(_upb_MiniTableField_GetRep(field) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte)); UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(!upb_IsRepeatedOrMap(field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
UPB_ASSERT(mini_table->subs[field->UPB_PRIVATE(submsg_index)].submsg); UPB_ASSERT(mini_table->subs[field->UPB_PRIVATE(submsg_index)].submsg);
_upb_Message_SetNonExtensionField(msg, field, &sub_message); _upb_Message_SetNonExtensionField(msg, field, &sub_message);
} }

@ -196,7 +196,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
memcpy(dst, src, mini_table->size); memcpy(dst, src, mini_table->size);
for (size_t i = 0; i < mini_table->field_count; ++i) { for (size_t i = 0; i < mini_table->field_count; ++i) {
const upb_MiniTableField* field = &mini_table->fields[i]; const upb_MiniTableField* field = &mini_table->fields[i];
if (!upb_IsRepeatedOrMap(field)) { if (!upb_MiniTableField_IsRepeatedOrMap(field)) {
switch (upb_MiniTableField_CType(field)) { switch (upb_MiniTableField_CType(field)) {
case kUpb_CType_Message: { case kUpb_CType_Message: {
upb_TaggedMessagePtr tagged = upb_TaggedMessagePtr tagged =
@ -263,7 +263,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
upb_Message_Extension* dst_ext = upb_Message_Extension* dst_ext =
_upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena);
if (!dst_ext) return NULL; if (!dst_ext) return NULL;
if (!upb_IsRepeatedOrMap(field)) { if (!upb_MiniTableField_IsRepeatedOrMap(field)) {
if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) {
return NULL; return NULL;
} }

@ -212,7 +212,7 @@ _upb_MiniTable_ElementSizeLg2(const upb_MiniTableField* field) {
// const upb_MiniTableField* field, // const upb_MiniTableField* field,
// bool value, upb_Arena* a) { // bool value, upb_Arena* a) {
// UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool); // UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool);
// UPB_ASSUME(!upb_IsRepeatedOrMap(field)); // UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(field));
// UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte); // UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_1Byte);
// _upb_Message_SetField(msg, field, &value, a); // _upb_Message_SetField(msg, field, &value, a);
// } // }

@ -21,6 +21,7 @@ cc_library(
deps = [ deps = [
":internal", ":internal",
"//upb:base", "//upb:base",
"//upb:base_internal",
"//upb:mem", "//upb:mem",
"//upb:mini_table", "//upb:mini_table",
"//upb:mini_table_internal", "//upb:mini_table_internal",

@ -8,16 +8,24 @@
#include "upb/mini_descriptor/decode.h" #include "upb/mini_descriptor/decode.h"
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include "upb/base/descriptor_constants.h" #include "upb/base/descriptor_constants.h"
#include "upb/base/internal/log2.h"
#include "upb/base/status.h"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
#include "upb/mini_descriptor/internal/base92.h" #include "upb/mini_descriptor/internal/base92.h"
#include "upb/mini_descriptor/internal/decoder.h" #include "upb/mini_descriptor/internal/decoder.h"
#include "upb/mini_descriptor/internal/modifiers.h" #include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/mini_descriptor/internal/wire_constants.h" #include "upb/mini_descriptor/internal/wire_constants.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/internal/field.h" #include "upb/mini_table/internal/field.h"
#include "upb/mini_table/internal/message.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
// Must be last. // Must be last.
#include "upb/port/def.inc" #include "upb/port/def.inc"
@ -497,7 +505,7 @@ int upb_MtDecoder_CompareFields(const void* _a, const void* _b) {
#define UPB_COMBINE(rep, ty, idx) (((rep << type_bits) | ty) << idx_bits) | idx #define UPB_COMBINE(rep, ty, idx) (((rep << type_bits) | ty) << idx_bits) | idx
uint32_t a_packed = UPB_COMBINE(a->rep, a->type, a->field_index); uint32_t a_packed = UPB_COMBINE(a->rep, a->type, a->field_index);
uint32_t b_packed = UPB_COMBINE(b->rep, b->type, b->field_index); uint32_t b_packed = UPB_COMBINE(b->rep, b->type, b->field_index);
assert(a_packed != b_packed); UPB_ASSERT(a_packed != b_packed);
#undef UPB_COMBINE #undef UPB_COMBINE
return a_packed < b_packed ? -1 : 1; return a_packed < b_packed ? -1 : 1;
} }
@ -630,7 +638,7 @@ static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d,
name, expected_num, (int)f->number); name, expected_num, (int)f->number);
} }
if (upb_IsRepeatedOrMap(f)) { if (upb_MiniTableField_IsRepeatedOrMap(f)) {
upb_MdDecoder_ErrorJmp( upb_MdDecoder_ErrorJmp(
&d->base, "map %s cannot be repeated or map, or be in oneof", name); &d->base, "map %s cannot be repeated or map, or be in oneof", name);
} }
@ -805,7 +813,7 @@ static const char* upb_MtDecoder_DoBuildMiniTableExtension(
if (extendee->ext & kUpb_ExtMode_IsMessageSet) { if (extendee->ext & kUpb_ExtMode_IsMessageSet) {
// Extensions of MessageSet must be messages. // Extensions of MessageSet must be messages.
if (!upb_IsSubMessage(f)) return NULL; if (!upb_MiniTableField_IsSubMessage(f)) return NULL;
// Extensions of MessageSet must be non-repeating. // Extensions of MessageSet must be non-repeating.
if ((f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array) return NULL; if ((f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array) return NULL;

@ -40,20 +40,32 @@ UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) {
return upb_FieldType_CType(upb_MiniTableField_Type(f)); return upb_FieldType_CType(upb_MiniTableField_Type(f));
} }
UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum(
const upb_MiniTableField* field) {
return field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum;
}
UPB_API_INLINE bool upb_MiniTableField_IsExtension( UPB_API_INLINE bool upb_MiniTableField_IsExtension(
const upb_MiniTableField* field) { const upb_MiniTableField* field) {
return field->mode & kUpb_LabelFlags_IsExtension; return field->mode & kUpb_LabelFlags_IsExtension;
} }
UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( UPB_API_INLINE bool upb_MiniTableField_IsRepeatedOrMap(
const upb_MiniTableField* field) { const upb_MiniTableField* field) {
return field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; // This works because upb_FieldMode has no value 3.
return !(field->mode & kUpb_FieldMode_Scalar);
}
UPB_API_INLINE bool upb_MiniTableField_IsSubMessage(
const upb_MiniTableField* field) {
return field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message ||
field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group;
} }
UPB_API_INLINE bool upb_MiniTableField_HasPresence( UPB_API_INLINE bool upb_MiniTableField_HasPresence(
const upb_MiniTableField* field) { const upb_MiniTableField* field) {
if (upb_MiniTableField_IsExtension(field)) { if (upb_MiniTableField_IsExtension(field)) {
return !upb_IsRepeatedOrMap(field); return !upb_MiniTableField_IsRepeatedOrMap(field);
} else { } else {
return field->presence != 0; return field->presence != 0;
} }

@ -95,16 +95,6 @@ UPB_INLINE void _upb_MiniTableField_CheckIsMap(
UPB_ASSUME(field->presence == 0); UPB_ASSUME(field->presence == 0);
} }
UPB_INLINE bool upb_IsRepeatedOrMap(const struct upb_MiniTableField* field) {
// This works because upb_FieldMode has no value 3.
return !(field->mode & kUpb_FieldMode_Scalar);
}
UPB_INLINE bool upb_IsSubMessage(const struct upb_MiniTableField* field) {
return field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message ||
field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group;
}
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

@ -608,8 +608,8 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr,
UPB_ASSERT(entry); UPB_ASSERT(entry);
UPB_ASSERT(entry->field_count == 2); UPB_ASSERT(entry->field_count == 2);
UPB_ASSERT(!upb_IsRepeatedOrMap(&entry->fields[0])); UPB_ASSERT(!upb_MiniTableField_IsRepeatedOrMap(&entry->fields[0]));
UPB_ASSERT(!upb_IsRepeatedOrMap(&entry->fields[1])); UPB_ASSERT(!upb_MiniTableField_IsRepeatedOrMap(&entry->fields[1]));
if (!map) { if (!map) {
map = _upb_Decoder_CreateMap(d, entry); map = _upb_Decoder_CreateMap(d, entry);

@ -282,7 +282,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext,
R"cc( R"cc(
UPB_INLINE $0 $1_$2(const struct $3* msg) { UPB_INLINE $0 $1_$2(const struct $3* msg) {
const upb_MiniTableExtension* ext = &$4; const upb_MiniTableExtension* ext = &$4;
UPB_ASSUME(!upb_IsRepeatedOrMap(&ext->field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(&ext->field));
UPB_ASSUME(_upb_MiniTableField_GetRep(&ext->field) == $5); UPB_ASSUME(_upb_MiniTableField_GetRep(&ext->field) == $5);
$0 default_val = $6; $0 default_val = $6;
$0 ret; $0 ret;
@ -297,7 +297,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext,
R"cc( R"cc(
UPB_INLINE void $1_set_$2(struct $3* msg, $0 val, upb_Arena* arena) { UPB_INLINE void $1_set_$2(struct $3* msg, $0 val, upb_Arena* arena) {
const upb_MiniTableExtension* ext = &$4; const upb_MiniTableExtension* ext = &$4;
UPB_ASSUME(!upb_IsRepeatedOrMap(&ext->field)); UPB_ASSUME(!upb_MiniTableField_IsRepeatedOrMap(&ext->field));
UPB_ASSUME(_upb_MiniTableField_GetRep(&ext->field) == $5); UPB_ASSUME(_upb_MiniTableField_GetRep(&ext->field) == $5);
bool ok = _upb_Message_SetExtensionField(msg, ext, &val, arena); bool ok = _upb_Message_SetExtensionField(msg, ext, &val, arena);
UPB_ASSERT(ok); UPB_ASSERT(ok);

Loading…
Cancel
Save