upb: make all mini_table/ includes unidirectional

PiperOrigin-RevId: 593859422
pull/15192/head
Eric Salo 11 months ago committed by Copybara-Service
parent 3c3d77158f
commit 0896146034
  1. 1
      upb/message/accessors.h
  2. 4
      upb/mini_table/internal/enum.h
  3. 29
      upb/mini_table/internal/extension.h
  4. 37
      upb/mini_table/internal/field.h
  5. 26
      upb/mini_table/internal/file.h
  6. 4
      upb/mini_table/internal/message.c
  7. 41
      upb/mini_table/internal/message.h
  8. 26
      upb/mini_table/internal/sub.h

@ -25,6 +25,7 @@
#include "upb/message/tagged_ptr.h"
#include "upb/message/types.h"
#include "upb/mini_table/enum.h"
#include "upb/mini_table/sub.h"
// Must be last.
#include "upb/port/def.inc"

@ -10,8 +10,6 @@
#include <stdint.h>
#include "upb/mini_table/types.h"
// Must be last.
#include "upb/port/def.inc"
@ -26,7 +24,7 @@ extern "C" {
#endif
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(
const upb_MiniTableEnum* e, uint32_t val) {
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);

@ -10,41 +10,42 @@
#include <stdint.h>
#include "upb/mini_table/field.h"
#include "upb/mini_table/sub.h"
#include "upb/mini_table/internal/field.h"
#include "upb/mini_table/internal/sub.h"
// Must be last.
#include "upb/port/def.inc"
struct upb_MiniTableExtension {
// Do not move this field. We need to be able to alias pointers.
upb_MiniTableField UPB_PRIVATE(field);
struct upb_MiniTableField UPB_PRIVATE(field);
const upb_MiniTable* UPB_PRIVATE(extendee);
upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum
const struct upb_MiniTable* UPB_PRIVATE(extendee);
union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum
};
#ifdef __cplusplus
extern "C" {
#endif
UPB_INLINE const upb_MiniTableField* UPB_PRIVATE(
_upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) {
return (const upb_MiniTableField*)&e->UPB_PRIVATE(field);
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 uint32_t
UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) {
UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)(
const struct upb_MiniTableExtension* e) {
return e->UPB_PRIVATE(field).UPB_ONLYBITS(number);
}
UPB_INLINE const upb_MiniTable* UPB_PRIVATE(
_upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) {
return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub));
UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(
_upb_MiniTableExtension_GetSubMessage)(
const struct upb_MiniTableExtension* e) {
return UPB_PRIVATE(_upb_MiniTableSub_Message)(e->UPB_PRIVATE(sub));
}
UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(
upb_MiniTableExtension* e, const upb_MiniTable* m) {
struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) {
e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
}

@ -13,7 +13,6 @@
#include "upb/base/descriptor_constants.h"
#include "upb/mini_table/internal/size_log2.h"
#include "upb/mini_table/types.h"
// Must be last.
#include "upb/port/def.inc"
@ -76,47 +75,47 @@ extern "C" {
#endif
UPB_INLINE upb_FieldMode
UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) {
UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) {
return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask);
}
UPB_INLINE upb_FieldRep
UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) {
UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) {
return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift);
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array;
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map;
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar;
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0;
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0;
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0;
}
UPB_INLINE upb_FieldType
UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) {
UPB_PRIVATE(_upb_MiniTableField_Type)(const struct 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;
@ -127,7 +126,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) {
}
UPB_INLINE upb_CType
UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) {
UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) {
return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f));
}
@ -146,23 +145,23 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum;
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
return f->presence < 0;
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(
const upb_MiniTableField* f) {
const struct 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 upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) {
return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f);
} else {
@ -187,7 +186,7 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(
}
UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(
const upb_MiniTableField* f) {
const struct upb_MiniTableField* f) {
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_NativePointer);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f));
@ -195,15 +194,15 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(
}
UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(
const upb_MiniTableField* f) {
const struct 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 upb_MiniTableField* f) {
UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(
const struct upb_MiniTableField* f) {
const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f);
return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type);
}

@ -8,15 +8,13 @@
#ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_
#define UPB_MINI_TABLE_INTERNAL_FILE_H_
#include "upb/mini_table/types.h"
// Must be last.
#include "upb/port/def.inc"
struct upb_MiniTableFile {
const upb_MiniTable** UPB_PRIVATE(msgs);
const upb_MiniTableEnum** UPB_PRIVATE(enums);
const upb_MiniTableExtension** UPB_PRIVATE(exts);
const struct upb_MiniTable** UPB_PRIVATE(msgs);
const struct upb_MiniTableEnum** UPB_PRIVATE(enums);
const struct upb_MiniTableExtension** UPB_PRIVATE(exts);
int UPB_PRIVATE(msg_count);
int UPB_PRIVATE(enum_count);
int UPB_PRIVATE(ext_count);
@ -27,34 +25,34 @@ extern "C" {
#endif
UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)(
const upb_MiniTableFile* f) {
const struct upb_MiniTableFile* f) {
return f->UPB_PRIVATE(enum_count);
}
UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)(
const upb_MiniTableFile* f) {
const struct upb_MiniTableFile* f) {
return f->UPB_PRIVATE(ext_count);
}
UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)(
const upb_MiniTableFile* f) {
const struct upb_MiniTableFile* f) {
return f->UPB_PRIVATE(msg_count);
}
UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)(
const upb_MiniTableFile* f, int i) {
UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)(
const struct upb_MiniTableFile* f, int i) {
UPB_ASSERT(i < f->UPB_PRIVATE(enum_count));
return f->UPB_PRIVATE(enums)[i];
}
UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE(
_upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) {
UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE(
_upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) {
UPB_ASSERT(i < f->UPB_PRIVATE(ext_count));
return f->UPB_PRIVATE(exts)[i];
}
UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)(
const upb_MiniTableFile* f, int i) {
UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)(
const struct upb_MiniTableFile* f, int i) {
UPB_ASSERT(i < f->UPB_PRIVATE(msg_count));
return f->UPB_PRIVATE(msgs)[i];
}

@ -5,7 +5,7 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#include "upb/mini_table/message.h"
#include "upb/mini_table/internal/message.h"
#include <stddef.h>
@ -13,7 +13,7 @@
#include "upb/port/def.inc"
// A MiniTable for an empty message, used for unlinked sub-messages.
const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = {
const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = {
.UPB_PRIVATE(subs) = NULL,
.UPB_PRIVATE(fields) = NULL,
.UPB_PRIVATE(size) = 0,

@ -12,7 +12,6 @@
#include "upb/mini_table/internal/field.h"
#include "upb/mini_table/internal/sub.h"
#include "upb/mini_table/types.h"
// Must be last.
#include "upb/port/def.inc"
@ -45,8 +44,8 @@ typedef enum {
// LINT.IfChange(minitable_struct_definition)
struct upb_MiniTable {
const upb_MiniTableSub* UPB_PRIVATE(subs);
const upb_MiniTableField* UPB_ONLYBITS(fields);
const union upb_MiniTableSub* UPB_PRIVATE(subs);
const struct 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.
@ -70,43 +69,47 @@ struct upb_MiniTable {
extern "C" {
#endif
UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) {
extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty);
UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) {
extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty);
return &UPB_PRIVATE(_kUpb_MiniTable_Empty);
}
UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) {
UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(
const struct upb_MiniTable* m) {
return m->UPB_ONLYBITS(field_count);
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) {
extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty);
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(
const struct upb_MiniTable* m) {
extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty);
return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty);
}
UPB_INLINE const upb_MiniTableField* UPB_PRIVATE(
_upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) {
UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(
_upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) {
return &m->UPB_ONLYBITS(fields)[i];
}
UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(
const upb_MiniTable* m, uint32_t i) {
UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE(
_upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) {
return &m->UPB_PRIVATE(subs)[i];
}
UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(
const upb_MiniTable* m, const upb_MiniTableField* f) {
UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(
_upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m,
const struct upb_MiniTableField* f) {
UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message);
const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)(
const struct 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 upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(
const upb_MiniTable* m, const upb_MiniTableField* f) {
UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(
_upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m,
const struct 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)]);
@ -131,7 +134,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(
}
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(
const upb_MiniTable* m, const upb_MiniTableField* f) {
const struct upb_MiniTable* m, const struct upb_MiniTableField* f) {
return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL;
}
@ -142,7 +145,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 upb_MiniTable* m) {
UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) {
int n = m->UPB_PRIVATE(required_count);
UPB_ASSERT(0 < n && n <= 63);
return ((1ULL << n) - 1) << 1;

@ -8,41 +8,39 @@
#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_
#define UPB_MINI_TABLE_INTERNAL_SUB_H_
#include "upb/mini_table/types.h"
// Must be last.
#include "upb/port/def.inc"
union upb_MiniTableSub {
const upb_MiniTable* UPB_PRIVATE(submsg);
const upb_MiniTableEnum* UPB_PRIVATE(subenum);
const struct upb_MiniTable* UPB_PRIVATE(submsg);
const struct upb_MiniTableEnum* UPB_PRIVATE(subenum);
};
#ifdef __cplusplus
extern "C" {
#endif
UPB_INLINE upb_MiniTableSub
UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) {
upb_MiniTableSub out;
UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(
const struct upb_MiniTableEnum* subenum) {
union upb_MiniTableSub out;
out.UPB_PRIVATE(subenum) = subenum;
return out;
}
UPB_INLINE upb_MiniTableSub
UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) {
upb_MiniTableSub out;
UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(
const struct upb_MiniTable* submsg) {
union upb_MiniTableSub out;
out.UPB_PRIVATE(submsg) = submsg;
return out;
}
UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)(
const upb_MiniTableSub sub) {
UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)(
const union upb_MiniTableSub sub) {
return sub.UPB_PRIVATE(subenum);
}
UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)(
const upb_MiniTableSub sub) {
UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)(
const union upb_MiniTableSub sub) {
return sub.UPB_PRIVATE(submsg);
}

Loading…
Cancel
Save