|
|
@ -35,23 +35,13 @@ class EnumDef; |
|
|
|
class FieldDef; |
|
|
|
class FieldDef; |
|
|
|
class MessageDef; |
|
|
|
class MessageDef; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
typedef upb::Def upb_def; |
|
|
|
|
|
|
|
typedef upb::EnumDef upb_enumdef; |
|
|
|
|
|
|
|
typedef upb::FieldDef upb_fielddef; |
|
|
|
|
|
|
|
typedef upb::MessageDef upb_msgdef; |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
struct upb_def; |
|
|
|
|
|
|
|
struct upb_enumdef; |
|
|
|
|
|
|
|
struct upb_fielddef; |
|
|
|
|
|
|
|
struct upb_msgdef; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct upb_def upb_def; |
|
|
|
|
|
|
|
typedef struct upb_enumdef upb_enumdef; |
|
|
|
|
|
|
|
typedef struct upb_fielddef upb_fielddef; |
|
|
|
|
|
|
|
typedef struct upb_msgdef upb_msgdef; |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPB_DECLARE_TYPE(upb::Def, upb_def); |
|
|
|
|
|
|
|
UPB_DECLARE_TYPE(upb::EnumDef, upb_enumdef); |
|
|
|
|
|
|
|
UPB_DECLARE_TYPE(upb::FieldDef, upb_fielddef); |
|
|
|
|
|
|
|
UPB_DECLARE_TYPE(upb::MessageDef, upb_msgdef); |
|
|
|
|
|
|
|
|
|
|
|
// Maximum field number allowed for FieldDefs. This is an inherent limit of the
|
|
|
|
// Maximum field number allowed for FieldDefs. This is an inherent limit of the
|
|
|
|
// protobuf wire format.
|
|
|
|
// protobuf wire format.
|
|
|
|
#define UPB_MAX_FIELDNUMBER ((1 << 29) - 1) |
|
|
|
#define UPB_MAX_FIELDNUMBER ((1 << 29) - 1) |
|
|
@ -78,11 +68,9 @@ typedef enum { |
|
|
|
UPB_DEF_ANY = -1, // Wildcard for upb_symtab_get*()
|
|
|
|
UPB_DEF_ANY = -1, // Wildcard for upb_symtab_get*()
|
|
|
|
} upb_deftype_t; |
|
|
|
} upb_deftype_t; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The base class of all defs. Its base is upb::RefCounted (use upb::upcast()
|
|
|
|
// The base class of all defs. Its base is upb::RefCounted (use upb::upcast()
|
|
|
|
// to convert).
|
|
|
|
// to convert).
|
|
|
|
class upb::Def /* : public upb::Refcounted */ { |
|
|
|
UPB_DEFINE_CLASS1(upb::Def, upb::RefCounted, |
|
|
|
public: |
|
|
|
public: |
|
|
|
typedef upb_deftype_t Type; |
|
|
|
typedef upb_deftype_t Type; |
|
|
|
|
|
|
|
|
|
|
@ -123,11 +111,8 @@ class upb::Def /* : public upb::Refcounted */ { |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
UPB_DISALLOW_POD_OPS(Def, upb::Def); |
|
|
|
UPB_DISALLOW_POD_OPS(Def, upb::Def); |
|
|
|
|
|
|
|
, |
|
|
|
#else |
|
|
|
UPB_DEFINE_STRUCT(upb_def, upb_refcounted, |
|
|
|
struct upb_def { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
upb_refcounted base; |
|
|
|
|
|
|
|
const char *fullname; |
|
|
|
const char *fullname; |
|
|
|
upb_deftype_t type : 8; |
|
|
|
upb_deftype_t type : 8; |
|
|
|
// Used as a flag during the def's mutable stage. Must be false unless
|
|
|
|
// Used as a flag during the def's mutable stage. Must be false unless
|
|
|
@ -135,15 +120,14 @@ struct upb_def { |
|
|
|
// us to easily determine which defs were passed into the function's
|
|
|
|
// us to easily determine which defs were passed into the function's
|
|
|
|
// current invocation.
|
|
|
|
// current invocation.
|
|
|
|
bool came_from_user; |
|
|
|
bool came_from_user; |
|
|
|
}; |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
#define UPB_DEF_INIT(name, type, refs, ref2s) \ |
|
|
|
#define UPB_DEF_INIT(name, type, refs, ref2s) \ |
|
|
|
{ UPB_REFCOUNT_INIT(refs, ref2s), name, type, false } |
|
|
|
{ UPB_REFCOUNT_INIT(refs, ref2s), name, type, false } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPB_BEGIN_EXTERN_C // {
|
|
|
|
|
|
|
|
|
|
|
|
// Native C API.
|
|
|
|
// Native C API.
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
upb_def *upb_def_dup(const upb_def *def, const void *owner); |
|
|
|
upb_def *upb_def_dup(const upb_def *def, const void *owner); |
|
|
|
|
|
|
|
|
|
|
|
// From upb_refcounted.
|
|
|
|
// From upb_refcounted.
|
|
|
@ -157,10 +141,70 @@ upb_deftype_t upb_def_type(const upb_def *d); |
|
|
|
const char *upb_def_fullname(const upb_def *d); |
|
|
|
const char *upb_def_fullname(const upb_def *d); |
|
|
|
bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s); |
|
|
|
bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s); |
|
|
|
bool upb_def_freeze(upb_def *const *defs, int n, upb_status *s); |
|
|
|
bool upb_def_freeze(upb_def *const *defs, int n, upb_status *s); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPB_END_EXTERN_C // }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* upb::Def casts *************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
#ifdef __cplusplus |
|
|
|
} // extern "C"
|
|
|
|
#define UPB_CPP_CASTS(cname, cpptype) \ |
|
|
|
|
|
|
|
namespace upb { \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline cpptype *down_cast<cpptype *, Def>(Def * def) { \
|
|
|
|
|
|
|
|
return upb_downcast_##cname##_mutable(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline cpptype *dyn_cast<cpptype *, Def>(Def * def) { \
|
|
|
|
|
|
|
|
return upb_dyncast_##cname##_mutable(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline const cpptype *down_cast<const cpptype *, const Def>( \
|
|
|
|
|
|
|
|
const Def *def) { \
|
|
|
|
|
|
|
|
return upb_downcast_##cname(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline const cpptype *dyn_cast<const cpptype *, const Def>(const Def *def) { \
|
|
|
|
|
|
|
|
return upb_dyncast_##cname(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline const cpptype *down_cast<const cpptype *, Def>(Def * def) { \
|
|
|
|
|
|
|
|
return upb_downcast_##cname(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline const cpptype *dyn_cast<const cpptype *, Def>(Def * def) { \
|
|
|
|
|
|
|
|
return upb_dyncast_##cname(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
} // namespace upb
|
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
#define UPB_CPP_CASTS(cname, cpptype) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dynamic casts, for determining if a def is of a particular type at runtime.
|
|
|
|
|
|
|
|
// Downcasts, for when some wants to assert that a def is of a particular type.
|
|
|
|
|
|
|
|
// These are only checked if we are building debug.
|
|
|
|
|
|
|
|
#define UPB_DEF_CASTS(lower, upper, cpptype) \ |
|
|
|
|
|
|
|
UPB_INLINE const upb_##lower *upb_dyncast_##lower(const upb_def *def) { \
|
|
|
|
|
|
|
|
if (upb_def_type(def) != UPB_DEF_##upper) return NULL; \
|
|
|
|
|
|
|
|
return (upb_##lower *)def; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
UPB_INLINE const upb_##lower *upb_downcast_##lower(const upb_def *def) { \
|
|
|
|
|
|
|
|
assert(upb_def_type(def) == UPB_DEF_##upper); \
|
|
|
|
|
|
|
|
return (const upb_##lower *)def; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
UPB_INLINE upb_##lower *upb_dyncast_##lower##_mutable(upb_def *def) { \
|
|
|
|
|
|
|
|
return (upb_##lower *)upb_dyncast_##lower(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
UPB_INLINE upb_##lower *upb_downcast_##lower##_mutable(upb_def *def) { \
|
|
|
|
|
|
|
|
return (upb_##lower *)upb_downcast_##lower(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
UPB_CPP_CASTS(lower, cpptype) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define UPB_DEFINE_DEF(cppname, lower, upper, cppmethods, members) \ |
|
|
|
|
|
|
|
UPB_DEFINE_CLASS2(cppname, upb::Def, upb::RefCounted, UPB_QUOTE(cppmethods), \
|
|
|
|
|
|
|
|
members) \
|
|
|
|
|
|
|
|
UPB_DEF_CASTS(lower, upper, cppname) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* upb::FieldDef **************************************************************/ |
|
|
|
/* upb::FieldDef **************************************************************/ |
|
|
|
|
|
|
|
|
|
|
@ -218,14 +262,13 @@ typedef enum { |
|
|
|
UPB_DESCRIPTOR_TYPE_SINT64 = 18, |
|
|
|
UPB_DESCRIPTOR_TYPE_SINT64 = 18, |
|
|
|
} upb_descriptortype_t; |
|
|
|
} upb_descriptortype_t; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A upb_fielddef describes a single field in a message. It is most often
|
|
|
|
// A upb_fielddef describes a single field in a message. It is most often
|
|
|
|
// found as a part of a upb_msgdef, but can also stand alone to represent
|
|
|
|
// found as a part of a upb_msgdef, but can also stand alone to represent
|
|
|
|
// an extension.
|
|
|
|
// an extension.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Its base class is upb::Def (use upb::upcast() to convert).
|
|
|
|
// Its base class is upb::Def (use upb::upcast() to convert).
|
|
|
|
class upb::FieldDef /* : public upb::Def */ { |
|
|
|
UPB_DEFINE_DEF(upb::FieldDef, fielddef, FIELD, |
|
|
|
public: |
|
|
|
public: |
|
|
|
typedef upb_fieldtype_t Type; |
|
|
|
typedef upb_fieldtype_t Type; |
|
|
|
typedef upb_label_t Label; |
|
|
|
typedef upb_label_t Label; |
|
|
@ -449,11 +492,8 @@ class upb::FieldDef /* : public upb::Def */ { |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
UPB_DISALLOW_POD_OPS(FieldDef, upb::FieldDef); |
|
|
|
UPB_DISALLOW_POD_OPS(FieldDef, upb::FieldDef); |
|
|
|
|
|
|
|
, |
|
|
|
#else |
|
|
|
UPB_DEFINE_STRUCT(upb_fielddef, upb_def, |
|
|
|
struct upb_fielddef { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
upb_def base; |
|
|
|
|
|
|
|
union { |
|
|
|
union { |
|
|
|
int64_t sint; |
|
|
|
int64_t sint; |
|
|
|
uint64_t uint; |
|
|
|
uint64_t uint; |
|
|
@ -482,7 +522,7 @@ struct upb_fielddef { |
|
|
|
uint32_t number_; |
|
|
|
uint32_t number_; |
|
|
|
uint32_t selector_base; // Used to index into a upb::Handlers table.
|
|
|
|
uint32_t selector_base; // Used to index into a upb::Handlers table.
|
|
|
|
uint32_t index_; |
|
|
|
uint32_t index_; |
|
|
|
}; |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
#define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \ |
|
|
|
#define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \ |
|
|
|
name, num, msgdef, subdef, selector_base, index, \
|
|
|
|
name, num, msgdef, subdef, selector_base, index, \
|
|
|
@ -494,10 +534,9 @@ struct upb_fielddef { |
|
|
|
lazy, intfmt, tagdelim, type, label, num, selector_base, index \
|
|
|
|
lazy, intfmt, tagdelim, type, label, num, selector_base, index \
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPB_BEGIN_EXTERN_C // {
|
|
|
|
|
|
|
|
|
|
|
|
// Native C API.
|
|
|
|
// Native C API.
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
upb_fielddef *upb_fielddef_new(const void *owner); |
|
|
|
upb_fielddef *upb_fielddef_new(const void *owner); |
|
|
|
upb_fielddef *upb_fielddef_dup(const upb_fielddef *f, const void *owner); |
|
|
|
upb_fielddef *upb_fielddef_dup(const upb_fielddef *f, const void *owner); |
|
|
|
|
|
|
|
|
|
|
@ -584,21 +623,17 @@ bool upb_fielddef_checktype(int32_t type); |
|
|
|
bool upb_fielddef_checkdescriptortype(int32_t type); |
|
|
|
bool upb_fielddef_checkdescriptortype(int32_t type); |
|
|
|
bool upb_fielddef_checkintfmt(int32_t fmt); |
|
|
|
bool upb_fielddef_checkintfmt(int32_t fmt); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
UPB_END_EXTERN_C // }
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* upb::MessageDef ************************************************************/ |
|
|
|
/* upb::MessageDef ************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
typedef upb_inttable_iter upb_msg_iter; |
|
|
|
typedef upb_inttable_iter upb_msg_iter; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Structure that describes a single .proto message type.
|
|
|
|
// Structure that describes a single .proto message type.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Its base class is upb::Def (use upb::upcast() to convert).
|
|
|
|
// Its base class is upb::Def (use upb::upcast() to convert).
|
|
|
|
class upb::MessageDef /* : public upb::Def */ { |
|
|
|
UPB_DEFINE_DEF(upb::MessageDef, msgdef, MSG, UPB_QUOTE( |
|
|
|
public: |
|
|
|
public: |
|
|
|
// Returns NULL if memory allocation failed.
|
|
|
|
// Returns NULL if memory allocation failed.
|
|
|
|
static reffed_ptr<MessageDef> New(); |
|
|
|
static reffed_ptr<MessageDef> New(); |
|
|
@ -684,11 +719,8 @@ class upb::MessageDef /* : public upb::Def */ { |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
UPB_DISALLOW_POD_OPS(MessageDef, upb::MessageDef); |
|
|
|
UPB_DISALLOW_POD_OPS(MessageDef, upb::MessageDef); |
|
|
|
|
|
|
|
), |
|
|
|
#else |
|
|
|
UPB_DEFINE_STRUCT(upb_msgdef, upb_def, |
|
|
|
struct upb_msgdef { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
upb_def base; |
|
|
|
|
|
|
|
size_t selector_count; |
|
|
|
size_t selector_count; |
|
|
|
uint32_t submsg_field_count; |
|
|
|
uint32_t submsg_field_count; |
|
|
|
|
|
|
|
|
|
|
@ -697,7 +729,7 @@ struct upb_msgdef { |
|
|
|
upb_strtable ntof; // name to field
|
|
|
|
upb_strtable ntof; // name to field
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(haberman): proper extension ranges (there can be multiple).
|
|
|
|
// TODO(haberman): proper extension ranges (there can be multiple).
|
|
|
|
}; |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \ |
|
|
|
#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \ |
|
|
|
refs, ref2s) \
|
|
|
|
refs, ref2s) \
|
|
|
@ -706,9 +738,8 @@ struct upb_msgdef { |
|
|
|
submsg_field_count, itof, ntof \
|
|
|
|
submsg_field_count, itof, ntof \
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
UPB_BEGIN_EXTERN_C // {
|
|
|
|
extern "C" { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
// Returns NULL if memory allocation failed.
|
|
|
|
// Returns NULL if memory allocation failed.
|
|
|
|
upb_msgdef *upb_msgdef_new(const void *owner); |
|
|
|
upb_msgdef *upb_msgdef_new(const void *owner); |
|
|
|
|
|
|
|
|
|
|
@ -748,20 +779,17 @@ void upb_msg_next(upb_msg_iter *iter); |
|
|
|
bool upb_msg_done(const upb_msg_iter *iter); |
|
|
|
bool upb_msg_done(const upb_msg_iter *iter); |
|
|
|
upb_fielddef *upb_msg_iter_field(const upb_msg_iter *iter); |
|
|
|
upb_fielddef *upb_msg_iter_field(const upb_msg_iter *iter); |
|
|
|
void upb_msg_iter_setdone(upb_msg_iter *iter); |
|
|
|
void upb_msg_iter_setdone(upb_msg_iter *iter); |
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
} // extern "C
|
|
|
|
UPB_END_EXTERN_C // }
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* upb::EnumDef ***************************************************************/ |
|
|
|
/* upb::EnumDef ***************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
typedef upb_strtable_iter upb_enum_iter; |
|
|
|
typedef upb_strtable_iter upb_enum_iter; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Class that represents an enum. Its base class is upb::Def (convert with
|
|
|
|
// Class that represents an enum. Its base class is upb::Def (convert with
|
|
|
|
// upb::upcast()).
|
|
|
|
// upb::upcast()).
|
|
|
|
class upb::EnumDef /* : public upb::Def */ { |
|
|
|
UPB_DEFINE_DEF(upb::EnumDef, enumdef, ENUM, |
|
|
|
public: |
|
|
|
public: |
|
|
|
// Returns NULL if memory allocation failed.
|
|
|
|
// Returns NULL if memory allocation failed.
|
|
|
|
static reffed_ptr<EnumDef> New(); |
|
|
|
static reffed_ptr<EnumDef> New(); |
|
|
@ -832,23 +860,19 @@ class upb::EnumDef /* : public upb::Def */ { |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
UPB_DISALLOW_POD_OPS(EnumDef, upb::EnumDef); |
|
|
|
UPB_DISALLOW_POD_OPS(EnumDef, upb::EnumDef); |
|
|
|
|
|
|
|
, |
|
|
|
#else |
|
|
|
UPB_DEFINE_STRUCT(upb_enumdef, upb_def, |
|
|
|
struct upb_enumdef { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
upb_def base; |
|
|
|
|
|
|
|
upb_strtable ntoi; |
|
|
|
upb_strtable ntoi; |
|
|
|
upb_inttable iton; |
|
|
|
upb_inttable iton; |
|
|
|
int32_t defaultval; |
|
|
|
int32_t defaultval; |
|
|
|
}; |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
#define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \ |
|
|
|
#define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \ |
|
|
|
{ UPB_DEF_INIT(name, UPB_DEF_ENUM, refs, ref2s), ntoi, iton, defaultval } |
|
|
|
{ UPB_DEF_INIT(name, UPB_DEF_ENUM, refs, ref2s), ntoi, iton, defaultval } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPB_BEGIN_EXTERN_C // {
|
|
|
|
|
|
|
|
|
|
|
|
// Native C API.
|
|
|
|
// Native C API.
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
upb_enumdef *upb_enumdef_new(const void *owner); |
|
|
|
upb_enumdef *upb_enumdef_new(const void *owner); |
|
|
|
upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner); |
|
|
|
upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner); |
|
|
|
|
|
|
|
|
|
|
@ -883,117 +907,9 @@ void upb_enum_next(upb_enum_iter *iter); |
|
|
|
bool upb_enum_done(upb_enum_iter *iter); |
|
|
|
bool upb_enum_done(upb_enum_iter *iter); |
|
|
|
const char *upb_enum_iter_name(upb_enum_iter *iter); |
|
|
|
const char *upb_enum_iter_name(upb_enum_iter *iter); |
|
|
|
int32_t upb_enum_iter_number(upb_enum_iter *iter); |
|
|
|
int32_t upb_enum_iter_number(upb_enum_iter *iter); |
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* upb_def casts **************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace upb { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
|
|
class Pointer<Def> { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
explicit Pointer(Def* ptr) : ptr_(ptr) {} |
|
|
|
|
|
|
|
operator Def*() { return ptr_; } |
|
|
|
|
|
|
|
operator RefCounted*() { return UPB_UPCAST(ptr_); } |
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
Def* ptr_; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
|
|
class Pointer<const Def> { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
explicit Pointer(const Def* ptr) : ptr_(ptr) {} |
|
|
|
|
|
|
|
operator const Def*() { return ptr_; } |
|
|
|
|
|
|
|
operator const RefCounted*() { return UPB_UPCAST(ptr_); } |
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
const Def* ptr_; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace upb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define UPB_CPP_CASTS(cname, cpptype) \ |
|
|
|
|
|
|
|
namespace upb { \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
class Pointer<cpptype> { \
|
|
|
|
|
|
|
|
public: \
|
|
|
|
|
|
|
|
explicit Pointer(cpptype* ptr) : ptr_(ptr) {} \
|
|
|
|
|
|
|
|
operator cpptype*() { return ptr_; } \
|
|
|
|
|
|
|
|
operator Def*() { return UPB_UPCAST(ptr_); } \
|
|
|
|
|
|
|
|
operator RefCounted*() { return Pointer<Def>(UPB_UPCAST(ptr_)); } \
|
|
|
|
|
|
|
|
private: \
|
|
|
|
|
|
|
|
cpptype* ptr_; \
|
|
|
|
|
|
|
|
}; \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
class Pointer<const cpptype> { \
|
|
|
|
|
|
|
|
public: \
|
|
|
|
|
|
|
|
explicit Pointer(const cpptype* ptr) : ptr_(ptr) {} \
|
|
|
|
|
|
|
|
operator const cpptype*() { return ptr_; } \
|
|
|
|
|
|
|
|
operator const Def*() { return UPB_UPCAST(ptr_); } \
|
|
|
|
|
|
|
|
operator const RefCounted*() { \
|
|
|
|
|
|
|
|
return Pointer<const Def>(UPB_UPCAST(ptr_)); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
private: \
|
|
|
|
|
|
|
|
const cpptype* ptr_; \
|
|
|
|
|
|
|
|
}; \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline cpptype *down_cast<cpptype*, Def>(Def *def) { \
|
|
|
|
|
|
|
|
return upb_downcast_##cname##_mutable(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline cpptype *dyn_cast<cpptype*, Def>(Def *def) { \
|
|
|
|
|
|
|
|
return upb_dyncast_##cname##_mutable(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline const cpptype *down_cast<const cpptype*, const Def>(const Def *def) { \
|
|
|
|
|
|
|
|
return upb_downcast_##cname(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline const cpptype *dyn_cast<const cpptype*, const Def>(const Def *def) { \
|
|
|
|
|
|
|
|
return upb_dyncast_##cname(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline const cpptype *down_cast<const cpptype*, Def>(Def *def) { \
|
|
|
|
|
|
|
|
return upb_downcast_##cname(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
template <> \
|
|
|
|
|
|
|
|
inline const cpptype *dyn_cast<const cpptype*, Def>(Def *def) { \
|
|
|
|
|
|
|
|
return upb_dyncast_##cname(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
} // namespace upb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else |
|
|
|
UPB_END_EXTERN_C // }
|
|
|
|
#define UPB_CPP_CASTS(cname, cpptype) |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dynamic casts, for determining if a def is of a particular type at runtime.
|
|
|
|
|
|
|
|
// Downcasts, for when some wants to assert that a def is of a particular type.
|
|
|
|
|
|
|
|
// These are only checked if we are building debug.
|
|
|
|
|
|
|
|
#define UPB_DEF_CASTS(lower, upper, cpptype) \ |
|
|
|
|
|
|
|
UPB_INLINE const upb_##lower *upb_dyncast_##lower(const upb_def *def) { \
|
|
|
|
|
|
|
|
if (upb_def_type(def) != UPB_DEF_##upper) return NULL; \
|
|
|
|
|
|
|
|
return (upb_##lower *)def; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
UPB_INLINE const upb_##lower *upb_downcast_##lower(const upb_def *def) { \
|
|
|
|
|
|
|
|
assert(upb_def_type(def) == UPB_DEF_##upper); \
|
|
|
|
|
|
|
|
return (const upb_##lower *)def; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
UPB_INLINE upb_##lower *upb_dyncast_##lower##_mutable(upb_def *def) { \
|
|
|
|
|
|
|
|
return (upb_##lower *)upb_dyncast_##lower(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
UPB_INLINE upb_##lower *upb_downcast_##lower##_mutable(upb_def *def) { \
|
|
|
|
|
|
|
|
return (upb_##lower *)upb_downcast_##lower(def); \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
UPB_CPP_CASTS(lower, cpptype) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPB_DEF_CASTS(msgdef, MSG, MessageDef); |
|
|
|
|
|
|
|
UPB_DEF_CASTS(fielddef, FIELD, FieldDef); |
|
|
|
|
|
|
|
UPB_DEF_CASTS(enumdef, ENUM, EnumDef); |
|
|
|
|
|
|
|
#undef UPB_DEF_CASTS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
|
|
|
@ -1404,4 +1320,8 @@ inline void EnumDef::Iterator::Next() { return upb_enum_next(&iter_); } |
|
|
|
} // namespace upb
|
|
|
|
} // namespace upb
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef UPB_DEFINE_DEF |
|
|
|
|
|
|
|
#undef UPB_DEF_CASTS |
|
|
|
|
|
|
|
#undef UPB_CPP_CASTS |
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_DEF_H_ */ |
|
|
|
#endif /* UPB_DEF_H_ */ |
|
|
|