diff options
Diffstat (limited to 'upb')
-rw-r--r-- | upb/bindings/stdc/error.h | 8 | ||||
-rw-r--r-- | upb/bindings/stdc/io.h | 8 | ||||
-rw-r--r-- | upb/def.c | 34 | ||||
-rw-r--r-- | upb/def.h | 276 | ||||
-rwxr-xr-x | upb/descriptor/descriptor.upb.h | 310 | ||||
-rw-r--r-- | upb/descriptor/reader.c | 2 | ||||
-rw-r--r-- | upb/descriptor/reader.h | 31 | ||||
-rw-r--r-- | upb/handlers-inl.h | 20 | ||||
-rw-r--r-- | upb/handlers.c | 6 | ||||
-rw-r--r-- | upb/handlers.h | 92 | ||||
-rw-r--r-- | upb/json/typed_printer.h | 29 | ||||
-rw-r--r-- | upb/pb/decoder.h | 107 | ||||
-rw-r--r-- | upb/pb/textprinter.h | 24 | ||||
-rw-r--r-- | upb/refcounted.h | 26 | ||||
-rw-r--r-- | upb/shim/shim.h | 14 | ||||
-rw-r--r-- | upb/sink.h | 93 | ||||
-rw-r--r-- | upb/symtab.h | 53 | ||||
-rw-r--r-- | upb/upb.h | 136 |
18 files changed, 700 insertions, 569 deletions
diff --git a/upb/bindings/stdc/error.h b/upb/bindings/stdc/error.h index 9802097..cfc7025 100644 --- a/upb/bindings/stdc/error.h +++ b/upb/bindings/stdc/error.h @@ -12,16 +12,12 @@ #ifndef UPB_STDC_ERROR_H_ #define UPB_STDC_ERROR_H_ -#ifdef __cplusplus -extern "C" { -#endif +UPB_BEGIN_EXTERN_C extern upb_errorspace upb_stdc_errorspace; void upb_status_fromerrno(upb_status *status, int code); bool upb_errno_is_wouldblock(int code); -#ifdef __cplusplus -} /* extern "C" */ -#endif +UPB_END_EXTERN_C #endif /* UPB_STDC_ERROR_H_ */ diff --git a/upb/bindings/stdc/io.h b/upb/bindings/stdc/io.h index fd19bef..7c6f282 100644 --- a/upb/bindings/stdc/io.h +++ b/upb/bindings/stdc/io.h @@ -13,9 +13,7 @@ #include <stdio.h> #include "upb/bytestream.h" -#ifdef __cplusplus -extern "C" { -#endif +UPB_BEGIN_EXTERN_C /* upb_stdio ******************************************************************/ @@ -66,8 +64,6 @@ void upb_stdio_open(upb_stdio *stdio, const char *filename, const char *mode, upb_bytesrc *upb_stdio_bytesrc(upb_stdio *stdio); upb_bytesink *upb_stdio_bytesink(upb_stdio *stdio); -#ifdef __cplusplus -} /* extern "C" */ -#endif +UPB_END_EXTERN_C #endif /* UPB_STDC_IO_H_ */ @@ -275,6 +275,40 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { } m->selector_count = selector; +#ifndef NDEBUG + // Verify that all selectors for the message are distinct. + // +#define TRY(type) \ + if (upb_handlers_getselector(f, type, &sel)) upb_inttable_insert(&t, sel, v); + + upb_inttable t; + upb_inttable_init(&t, UPB_CTYPE_BOOL); + upb_value v = upb_value_bool(true); + upb_selector_t sel; + upb_inttable_insert(&t, UPB_STARTMSG_SELECTOR, v); + upb_inttable_insert(&t, UPB_ENDMSG_SELECTOR, v); + for(upb_msg_begin(&j, m); !upb_msg_done(&j); upb_msg_next(&j)) { + upb_fielddef *f = upb_msg_iter_field(&j); + // These calls will assert-fail in upb_table if the value already exists. + TRY(UPB_HANDLER_INT32); + TRY(UPB_HANDLER_INT64) + TRY(UPB_HANDLER_UINT32) + TRY(UPB_HANDLER_UINT64) + TRY(UPB_HANDLER_FLOAT) + TRY(UPB_HANDLER_DOUBLE) + TRY(UPB_HANDLER_BOOL) + TRY(UPB_HANDLER_STARTSTR) + TRY(UPB_HANDLER_STRING) + TRY(UPB_HANDLER_ENDSTR) + TRY(UPB_HANDLER_STARTSUBMSG) + TRY(UPB_HANDLER_ENDSUBMSG) + TRY(UPB_HANDLER_STARTSEQ) + TRY(UPB_HANDLER_ENDSEQ) + } + upb_inttable_uninit(&t); +#undef TRY +#endif + free(fields); return true; } @@ -35,23 +35,13 @@ class EnumDef; class FieldDef; 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 +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 // protobuf wire format. #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1) @@ -78,11 +68,9 @@ typedef enum { UPB_DEF_ANY = -1, // Wildcard for upb_symtab_get*() } upb_deftype_t; -#ifdef __cplusplus - // The base class of all defs. Its base is upb::RefCounted (use upb::upcast() // to convert). -class upb::Def /* : public upb::Refcounted */ { +UPB_DEFINE_CLASS1(upb::Def, upb::RefCounted, public: typedef upb_deftype_t Type; @@ -123,11 +111,8 @@ class upb::Def /* : public upb::Refcounted */ { private: UPB_DISALLOW_POD_OPS(Def, upb::Def); - -#else -struct upb_def { -#endif - upb_refcounted base; +, +UPB_DEFINE_STRUCT(upb_def, upb_refcounted, const char *fullname; upb_deftype_t type : 8; // 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 // current invocation. bool came_from_user; -}; +)); #define UPB_DEF_INIT(name, type, refs, ref2s) \ { UPB_REFCOUNT_INIT(refs, ref2s), name, type, false } +UPB_BEGIN_EXTERN_C // { + // Native C API. -#ifdef __cplusplus -extern "C" { -#endif upb_def *upb_def_dup(const upb_def *def, const void *owner); // 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); 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); + +UPB_END_EXTERN_C // } + + +/* upb::Def casts *************************************************************/ + #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 +// 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 **************************************************************/ @@ -218,14 +262,13 @@ typedef enum { UPB_DESCRIPTOR_TYPE_SINT64 = 18, } upb_descriptortype_t; -#ifdef __cplusplus // 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 // an extension. // // 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: typedef upb_fieldtype_t Type; typedef upb_label_t Label; @@ -449,11 +492,8 @@ class upb::FieldDef /* : public upb::Def */ { private: UPB_DISALLOW_POD_OPS(FieldDef, upb::FieldDef); - -#else -struct upb_fielddef { -#endif - upb_def base; +, +UPB_DEFINE_STRUCT(upb_fielddef, upb_def, union { int64_t sint; uint64_t uint; @@ -482,7 +522,7 @@ struct upb_fielddef { uint32_t number_; uint32_t selector_base; // Used to index into a upb::Handlers table. uint32_t index_; -}; +)); #define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \ name, num, msgdef, subdef, selector_base, index, \ @@ -494,10 +534,9 @@ struct upb_fielddef { lazy, intfmt, tagdelim, type, label, num, selector_base, index \ } +UPB_BEGIN_EXTERN_C // { + // Native C API. -#ifdef __cplusplus -extern "C" { -#endif upb_fielddef *upb_fielddef_new(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_checkintfmt(int32_t fmt); -#ifdef __cplusplus -} // extern "C" -#endif +UPB_END_EXTERN_C // } /* upb::MessageDef ************************************************************/ typedef upb_inttable_iter upb_msg_iter; -#ifdef __cplusplus - // Structure that describes a single .proto message type. // // 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: // Returns NULL if memory allocation failed. static reffed_ptr<MessageDef> New(); @@ -684,11 +719,8 @@ class upb::MessageDef /* : public upb::Def */ { private: UPB_DISALLOW_POD_OPS(MessageDef, upb::MessageDef); - -#else -struct upb_msgdef { -#endif - upb_def base; +), +UPB_DEFINE_STRUCT(upb_msgdef, upb_def, size_t selector_count; uint32_t submsg_field_count; @@ -697,7 +729,7 @@ struct upb_msgdef { upb_strtable ntof; // name to field // TODO(haberman): proper extension ranges (there can be multiple). -}; +)); #define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \ refs, ref2s) \ @@ -706,9 +738,8 @@ struct upb_msgdef { submsg_field_count, itof, ntof \ } -#ifdef __cplusplus -extern "C" { -#endif +UPB_BEGIN_EXTERN_C // { + // Returns NULL if memory allocation failed. 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); upb_fielddef *upb_msg_iter_field(const upb_msg_iter *iter); void upb_msg_iter_setdone(upb_msg_iter *iter); -#ifdef __cplusplus -} // extern "C -#endif + +UPB_END_EXTERN_C // } /* upb::EnumDef ***************************************************************/ typedef upb_strtable_iter upb_enum_iter; -#ifdef __cplusplus - // Class that represents an enum. Its base class is upb::Def (convert with // upb::upcast()). -class upb::EnumDef /* : public upb::Def */ { +UPB_DEFINE_DEF(upb::EnumDef, enumdef, ENUM, public: // Returns NULL if memory allocation failed. static reffed_ptr<EnumDef> New(); @@ -832,23 +860,19 @@ class upb::EnumDef /* : public upb::Def */ { private: UPB_DISALLOW_POD_OPS(EnumDef, upb::EnumDef); - -#else -struct upb_enumdef { -#endif - upb_def base; +, +UPB_DEFINE_STRUCT(upb_enumdef, upb_def, upb_strtable ntoi; upb_inttable iton; int32_t defaultval; -}; +)); #define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \ { UPB_DEF_INIT(name, UPB_DEF_ENUM, refs, ref2s), ntoi, iton, defaultval } +UPB_BEGIN_EXTERN_C // { + // Native C API. -#ifdef __cplusplus -extern "C" { -#endif upb_enumdef *upb_enumdef_new(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); const char *upb_enum_iter_name(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 -#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_END_EXTERN_C // } -UPB_DEF_CASTS(msgdef, MSG, MessageDef); -UPB_DEF_CASTS(fielddef, FIELD, FieldDef); -UPB_DEF_CASTS(enumdef, ENUM, EnumDef); -#undef UPB_DEF_CASTS #ifdef __cplusplus @@ -1404,4 +1320,8 @@ inline void EnumDef::Iterator::Next() { return upb_enum_next(&iter_); } } // namespace upb #endif +#undef UPB_DEFINE_DEF +#undef UPB_DEF_CASTS +#undef UPB_CPP_CASTS + #endif /* UPB_DEF_H_ */ diff --git a/upb/descriptor/descriptor.upb.h b/upb/descriptor/descriptor.upb.h index 14b7308..3877afe 100755 --- a/upb/descriptor/descriptor.upb.h +++ b/upb/descriptor/descriptor.upb.h @@ -21,44 +21,296 @@ extern "C" { // Enums typedef enum { - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_FIXED64 = 6, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_STRING = 9, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_FLOAT = 2, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_DOUBLE = 1, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_INT32 = 5, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_SFIXED32 = 15, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_FIXED32 = 7, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_MESSAGE = 11, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_INT64 = 3, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_ENUM = 14, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_UINT32 = 13, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_UINT64 = 4, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_SFIXED64 = 16, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_BYTES = 12, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_SINT64 = 18, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_BOOL = 8, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_GROUP = 10, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_SINT32 = 17, -} google_protobuf_FieldDescriptorProto_Type; + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_OPTIONAL = 1, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REQUIRED = 2, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REPEATED = 3, +} google_protobuf_FieldDescriptorProto_Label; typedef enum { - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_LABEL_REQUIRED = 2, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_LABEL_REPEATED = 3, - GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_LABEL_OPTIONAL = 1, -} google_protobuf_FieldDescriptorProto_Label; + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_DOUBLE = 1, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FLOAT = 2, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_INT64 = 3, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_UINT64 = 4, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_INT32 = 5, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FIXED64 = 6, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FIXED32 = 7, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_BOOL = 8, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_STRING = 9, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_GROUP = 10, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE = 11, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_BYTES = 12, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_UINT32 = 13, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_ENUM = 14, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SFIXED32 = 15, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SFIXED64 = 16, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SINT32 = 17, + GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SINT64 = 18, +} google_protobuf_FieldDescriptorProto_Type; typedef enum { - GOOGLE_PROTOBUF_FIELDOPTIONS_CTYPE_CORD = 1, - GOOGLE_PROTOBUF_FIELDOPTIONS_CTYPE_STRING = 0, - GOOGLE_PROTOBUF_FIELDOPTIONS_CTYPE_STRING_PIECE = 2, + GOOGLE_PROTOBUF_FIELDOPTIONS_STRING = 0, + GOOGLE_PROTOBUF_FIELDOPTIONS_CORD = 1, + GOOGLE_PROTOBUF_FIELDOPTIONS_STRING_PIECE = 2, } google_protobuf_FieldOptions_CType; typedef enum { - GOOGLE_PROTOBUF_FILEOPTIONS_OPTIMIZEMODE_CODE_SIZE = 2, - GOOGLE_PROTOBUF_FILEOPTIONS_OPTIMIZEMODE_SPEED = 1, - GOOGLE_PROTOBUF_FILEOPTIONS_OPTIMIZEMODE_LITE_RUNTIME = 3, + GOOGLE_PROTOBUF_FILEOPTIONS_SPEED = 1, + GOOGLE_PROTOBUF_FILEOPTIONS_CODE_SIZE = 2, + GOOGLE_PROTOBUF_FILEOPTIONS_LITE_RUNTIME = 3, } google_protobuf_FileOptions_OptimizeMode; +// Selectors + +// google.protobuf.DescriptorProto +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_STARTSUBMSG 3 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_STARTSUBMSG 4 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_STARTSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_STARTSUBMSG 6 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_OPTIONS_STARTSUBMSG 7 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_STARTSEQ 8 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_ENDSEQ 9 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_ENDSUBMSG 10 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_STARTSEQ 11 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_ENDSEQ 12 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_ENDSUBMSG 13 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_STARTSEQ 14 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_ENDSEQ 15 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_ENDSUBMSG 16 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_STARTSEQ 17 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_ENDSEQ 18 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_ENDSUBMSG 19 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_STARTSEQ 20 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_ENDSEQ 21 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_ENDSUBMSG 22 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_OPTIONS_ENDSUBMSG 23 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_STRING 24 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_STARTSTR 25 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_ENDSTR 26 + +// google.protobuf.DescriptorProto.ExtensionRange +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSIONRANGE_START_INT32 2 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSIONRANGE_END_INT32 3 + +// google.protobuf.EnumDescriptorProto +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 3 +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_STARTSEQ 4 +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_ENDSEQ 5 +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_ENDSUBMSG 6 +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 7 +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_NAME_STRING 8 +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_NAME_STARTSTR 9 +#define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_NAME_ENDSTR 10 + +// google.protobuf.EnumOptions +#define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_ALLOW_ALIAS_BOOL 6 + +// google.protobuf.EnumValueDescriptorProto +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 3 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_NAME_STRING 4 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_NAME_STARTSTR 5 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_NAME_ENDSTR 6 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_NUMBER_INT32 7 + +// google.protobuf.EnumValueOptions +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 + +// google.protobuf.FieldDescriptorProto +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 3 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_NAME_STRING 4 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_NAME_STARTSTR 5 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_NAME_ENDSTR 6 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_EXTENDEE_STRING 7 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_EXTENDEE_STARTSTR 8 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_EXTENDEE_ENDSTR 9 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_NUMBER_INT32 10 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_INT32 11 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_INT32 12 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_NAME_STRING 13 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_NAME_STARTSTR 14 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_NAME_ENDSTR 15 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_STRING 16 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_STARTSTR 17 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_ENDSTR 18 + +// google.protobuf.FieldOptions +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_CTYPE_INT32 6 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_PACKED_BOOL 7 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_DEPRECATED_BOOL 8 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_LAZY_BOOL 9 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_STRING 10 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_STARTSTR 11 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_ENDSTR 12 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_WEAK_BOOL 13 + +// google.protobuf.FileDescriptorProto +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_ENUM_TYPE_STARTSUBMSG 3 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SERVICE_STARTSUBMSG 4 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_EXTENSION_STARTSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 6 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SOURCE_CODE_INFO_STARTSUBMSG 7 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_STARTSEQ 8 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_ENDSEQ 9 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_ENDSUBMSG 10 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_ENUM_TYPE_STARTSEQ 11 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_ENUM_TYPE_ENDSEQ 12 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_ENUM_TYPE_ENDSUBMSG 13 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SERVICE_STARTSEQ 14 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SERVICE_ENDSEQ 15 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SERVICE_ENDSUBMSG 16 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_EXTENSION_STARTSEQ 17 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_EXTENSION_ENDSEQ 18 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_EXTENSION_ENDSUBMSG 19 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 20 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SOURCE_CODE_INFO_ENDSUBMSG 21 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_NAME_STRING 22 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_NAME_STARTSTR 23 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_NAME_ENDSTR 24 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PACKAGE_STRING 25 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PACKAGE_STARTSTR 26 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PACKAGE_ENDSTR 27 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_STARTSEQ 28 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_ENDSEQ 29 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_STRING 30 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_STARTSTR 31 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_ENDSTR 32 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PUBLIC_DEPENDENCY_STARTSEQ 33 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PUBLIC_DEPENDENCY_ENDSEQ 34 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PUBLIC_DEPENDENCY_INT32 35 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_STARTSEQ 36 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_ENDSEQ 37 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_INT32 38 + +// google.protobuf.FileDescriptorSet +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_ENDSUBMSG 5 + +// google.protobuf.FileOptions +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_PACKAGE_STRING 6 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_PACKAGE_STARTSTR 7 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_PACKAGE_ENDSTR 8 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_OUTER_CLASSNAME_STRING 9 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_OUTER_CLASSNAME_STARTSTR 10 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_OUTER_CLASSNAME_ENDSTR 11 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_OPTIMIZE_FOR_INT32 12 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_MULTIPLE_FILES_BOOL 13 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_GO_PACKAGE_STRING 14 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_GO_PACKAGE_STARTSTR 15 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_GO_PACKAGE_ENDSTR 16 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_CC_GENERIC_SERVICES_BOOL 17 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_GENERIC_SERVICES_BOOL 18 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_PY_GENERIC_SERVICES_BOOL 19 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_GENERATE_EQUALS_AND_HASH_BOOL 20 + +// google.protobuf.MessageOptions +#define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_MESSAGE_SET_WIRE_FORMAT_BOOL 6 +#define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_NO_STANDARD_DESCRIPTOR_ACCESSOR_BOOL 7 + +// google.protobuf.MethodDescriptorProto +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 3 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_NAME_STRING 4 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_NAME_STARTSTR 5 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_NAME_ENDSTR 6 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_INPUT_TYPE_STRING 7 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_INPUT_TYPE_STARTSTR 8 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_INPUT_TYPE_ENDSTR 9 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_STRING 10 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_STARTSTR 11 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_ENDSTR 12 + +// google.protobuf.MethodOptions +#define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 + +// google.protobuf.ServiceDescriptorProto +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 3 +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_STARTSEQ 4 +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_ENDSEQ 5 +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_ENDSUBMSG 6 +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 7 +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_NAME_STRING 8 +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_NAME_STARTSTR 9 +#define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_NAME_ENDSTR 10 + +// google.protobuf.ServiceOptions +#define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 + +// google.protobuf.SourceCodeInfo +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_ENDSUBMSG 5 + +// google.protobuf.SourceCodeInfo.Location +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_PATH_STARTSEQ 2 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_PATH_ENDSEQ 3 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_PATH_INT32 4 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_SPAN_STARTSEQ 5 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_SPAN_ENDSEQ 6 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_SPAN_INT32 7 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_COMMENTS_STRING 8 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_COMMENTS_STARTSTR 9 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_COMMENTS_ENDSTR 10 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_STRING 11 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_STARTSTR 12 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_ENDSTR 13 + +// google.protobuf.UninterpretedOption +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_STARTSUBMSG 2 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_STARTSEQ 3 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_ENDSEQ 4 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_ENDSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_IDENTIFIER_VALUE_STRING 6 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_IDENTIFIER_VALUE_STARTSTR 7 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_IDENTIFIER_VALUE_ENDSTR 8 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_POSITIVE_INT_VALUE_UINT64 9 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NEGATIVE_INT_VALUE_INT64 10 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_DOUBLE_VALUE_DOUBLE 11 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_STRING_VALUE_STRING 12 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_STRING_VALUE_STARTSTR 13 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_STRING_VALUE_ENDSTR 14 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_AGGREGATE_VALUE_STRING 15 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_AGGREGATE_VALUE_STARTSTR 16 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_AGGREGATE_VALUE_ENDSTR 17 + +// google.protobuf.UninterpretedOption.NamePart +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAMEPART_NAME_PART_STRING 2 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAMEPART_NAME_PART_STARTSTR 3 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAMEPART_NAME_PART_ENDSTR 4 +#define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAMEPART_IS_EXTENSION_BOOL 5 + const upb_symtab *upbdefs_google_protobuf_descriptor(const void *owner); // MessageDefs diff --git a/upb/descriptor/reader.c b/upb/descriptor/reader.c index c9425a3..fdfa4e3 100644 --- a/upb/descriptor/reader.c +++ b/upb/descriptor/reader.c @@ -126,7 +126,7 @@ upb_def **upb_descreader_getdefs(upb_descreader *r, void *owner, int *n) { } upb_sink *upb_descreader_input(upb_descreader *r) { - return (upb_sink*)r->sink; + return &r->sink; } static upb_msgdef *upb_descreader_top(upb_descreader *r) { diff --git a/upb/descriptor/reader.h b/upb/descriptor/reader.h index f9d0046..700fd65 100644 --- a/upb/descriptor/reader.h +++ b/upb/descriptor/reader.h @@ -19,13 +19,10 @@ namespace descriptor { class Reader; } // namespace descriptor } // namespace upb - -typedef upb::descriptor::Reader upb_descreader; -#else -struct upb_descreader; -typedef struct upb_descreader upb_descreader; #endif +UPB_DECLARE_TYPE(upb::descriptor::Reader, upb_descreader); + // Internal-only structs used by Reader. // upb_deflist is an internal-only dynamic array for storing a growing list of @@ -62,11 +59,9 @@ typedef struct { // TODO: make this a runtime-settable property of the Reader instance. #define UPB_MAX_MESSAGE_NESTING 64 -#ifdef __cplusplus - // Class that receives descriptor data according to the descriptor.proto schema // and use it to build upb::Defs corresponding to that schema. -class upb::descriptor::Reader { +UPB_DEFINE_CLASS0(upb::descriptor::Reader, public: // These handlers must have come from NewHandlers() and must outlive the // Reader. @@ -96,12 +91,9 @@ class upb::descriptor::Reader { // Builds and returns handlers for the reader, owned by "owner." static Handlers* NewHandlers(const void* owner); - - private: -#else -struct upb_descreader { -#endif - char sink[sizeof(upb_sink)]; +, +UPB_DEFINE_STRUCT0(upb_descreader, + upb_sink sink; upb_deflist defs; upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; int stack_len; @@ -114,11 +106,9 @@ struct upb_descreader { char *default_string; upb_fielddef *f; -}; +)); -#ifdef __cplusplus -extern "C" { -#endif +UPB_BEGIN_EXTERN_C // { // C API. void upb_descreader_init(upb_descreader *r, const upb_handlers *handlers, @@ -129,11 +119,10 @@ upb_sink *upb_descreader_input(upb_descreader *r); upb_def **upb_descreader_getdefs(upb_descreader *r, void *owner, int *n); const upb_handlers *upb_descreader_newhandlers(const void *owner); -#ifdef __cplusplus -} // extern "C" +UPB_END_EXTERN_C // } +#ifdef __cplusplus // C++ implementation details. ///////////////////////////////////////////////// - namespace upb { namespace descriptor { inline Reader::Reader(const Handlers *h, Status *s) { diff --git a/upb/handlers-inl.h b/upb/handlers-inl.h index 25cbf0a..b4ba4a3 100644 --- a/upb/handlers-inl.h +++ b/upb/handlers-inl.h @@ -128,26 +128,6 @@ UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h) { namespace upb { -template<> -class Pointer<Handlers> { - public: - explicit Pointer(Handlers* ptr) : ptr_(ptr) {} - operator Handlers*() { return ptr_; } - operator RefCounted*() { return UPB_UPCAST(ptr_); } - private: - Handlers* ptr_; -}; - -template<> -class Pointer<const Handlers> { - public: - explicit Pointer(const Handlers* ptr) : ptr_(ptr) {} - operator const Handlers*() { return ptr_; } - operator const RefCounted*() { return UPB_UPCAST(ptr_); } - private: - const Handlers* ptr_; -}; - typedef void CleanupFunc(void *ptr); // Template to remove "const" from "const T*" and just return "T*". diff --git a/upb/handlers.c b/upb/handlers.c index 024cd0c..90df8a6 100644 --- a/upb/handlers.c +++ b/upb/handlers.c @@ -523,21 +523,21 @@ bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type, case UPB_HANDLER_STRING: if (upb_fielddef_isstring(f)) { *s = f->selector_base; - } else if (upb_fielddef_issubmsg(f)) { + } else if (upb_fielddef_lazy(f)) { *s = f->selector_base + 3; } else { return false; } break; case UPB_HANDLER_STARTSTR: - if (upb_fielddef_isstring(f) || upb_fielddef_issubmsg(f)) { + if (upb_fielddef_isstring(f) || upb_fielddef_lazy(f)) { *s = f->selector_base + 1; } else { return false; } break; case UPB_HANDLER_ENDSTR: - if (upb_fielddef_isstring(f) || upb_fielddef_issubmsg(f)) { + if (upb_fielddef_isstring(f) || upb_fielddef_lazy(f)) { *s = f->selector_base + 2; } else { return false; diff --git a/upb/handlers.h b/upb/handlers.h index 6a8193a..ca28cff 100644 --- a/upb/handlers.h +++ b/upb/handlers.h @@ -25,7 +25,6 @@ #include "upb/def.h" #ifdef __cplusplus - namespace upb { class BufferHandle; class BytesHandler; @@ -34,24 +33,13 @@ class Handlers; template <class T> class Handler; template <class T> struct CanonicalType; } // namespace upb - -typedef upb::BufferHandle upb_bufhandle; -typedef upb::BytesHandler upb_byteshandler; -typedef upb::HandlerAttributes upb_handlerattr; -typedef upb::Handlers upb_handlers; -#else -struct upb_bufhandle; -struct upb_byteshandler; -struct upb_handlerattr; -struct upb_handlers; -struct upb_sinkframe; -typedef struct upb_bufhandle upb_bufhandle; -typedef struct upb_byteshandler upb_byteshandler; -typedef struct upb_handlerattr upb_handlerattr; -typedef struct upb_handlers upb_handlers; -typedef struct upb_sinkframe upb_sinkframe; #endif +UPB_DECLARE_TYPE(upb::BufferHandle, upb_bufhandle); +UPB_DECLARE_TYPE(upb::BytesHandler, upb_byteshandler); +UPB_DECLARE_TYPE(upb::HandlerAttributes, upb_handlerattr); +UPB_DECLARE_TYPE(upb::Handlers, upb_handlers); + // The maximum depth that the handler graph can have. This is a resource limit // for the C stack since we sometimes need to recursively traverse the graph. // Cycles are ok; the traversal will stop when it detects a cycle, but we must @@ -92,9 +80,7 @@ extern char _upb_noclosure; // (for example: the STARTSUBMSG handler for field "field15"). typedef int32_t upb_selector_t; -#ifdef __cplusplus -extern "C" { -#endif +UPB_BEGIN_EXTERN_C // Forward-declares for C inline accessors. We need to declare these here // so we can "friend" them in the class declarations in C++. @@ -113,9 +99,7 @@ UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h); UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h); UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h); -#ifdef __cplusplus -} -#endif +UPB_END_EXTERN_C // Static selectors for upb::Handlers. @@ -130,10 +114,8 @@ UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h); typedef void upb_handlerfree(void *d); -#ifdef __cplusplus - // A set of attributes that accompanies a handler's function pointer. -class upb::HandlerAttributes { +UPB_DEFINE_CLASS0(upb::HandlerAttributes, public: HandlerAttributes(); ~HandlerAttributes(); @@ -167,15 +149,13 @@ class upb::HandlerAttributes { private: friend UPB_INLINE const void * ::upb_handlerattr_handlerdata( const upb_handlerattr *attr); - -#else -struct upb_handlerattr { -#endif +, +UPB_DEFINE_STRUCT0(upb_handlerattr, const void *handler_data_; const void *closure_type_; const void *return_closure_type_; bool alwaysok_; -}; +)); #define UPB_HANDLERATTR_INITIALIZER {NULL, NULL, NULL, false} @@ -194,12 +174,10 @@ typedef struct { upb_handlerattr attr; } upb_handlers_tabent; -#ifdef __cplusplus - // Extra information about a buffer that is passed to a StringBuf handler. // TODO(haberman): allow the handle to be pinned so that it will outlive // the handler invocation. -class upb::BufferHandle { +UPB_DEFINE_CLASS0(upb::BufferHandle, public: BufferHandle(); ~BufferHandle(); @@ -236,16 +214,13 @@ class upb::BufferHandle { friend UPB_INLINE const void* ::upb_bufhandle_objtype( const upb_bufhandle *h); friend UPB_INLINE const char* ::upb_bufhandle_buf(const upb_bufhandle *h); -#else -struct upb_bufhandle { -#endif +, +UPB_DEFINE_STRUCT0(upb_bufhandle, const char *buf_; const void *obj_; const void *objtype_; size_t objofs_; -}; - -#ifdef __cplusplus +)); // A upb::Handlers object represents the set of handlers associated with a // message in the graph of messages. You can think of it as a big virtual @@ -258,7 +233,7 @@ struct upb_bufhandle { // // The easiest way to create the *Handler objects needed by the Set* methods is // with the UpbBind() and UpbMakeHandler() macros; see below. -class upb::Handlers { +UPB_DEFINE_CLASS1(upb::Handlers, upb::RefCounted, public: typedef upb_selector_t Selector; typedef upb_handlertype_t Type; @@ -527,17 +502,15 @@ class upb::Handlers { friend UPB_INLINE const void *::upb_handlers_gethandlerdata( const upb_handlers *h, upb_selector_t s); -#else -struct upb_handlers { -#endif - upb_refcounted base; +, +UPB_DEFINE_STRUCT(upb_handlers, upb_refcounted, const upb_msgdef *msg; const upb_handlers **sub; const void *top_closure_type; upb_inttable cleanup_; upb_status status_; // Used only when mutable. upb_handlers_tabent table[1]; // Dynamically-sized field handler array. -}; +)); #ifdef __cplusplus @@ -638,9 +611,10 @@ template <class T> class Handler { } // namespace upb -extern "C" { #endif // __cplusplus +UPB_BEGIN_EXTERN_C + // Native C API. // Handler function typedefs. @@ -765,24 +739,19 @@ UPB_INLINE const void *upb_handlers_gethandlerdata(const upb_handlers *h, return upb_handlerattr_handlerdata(&h->table[s].attr); } -#ifdef __cplusplus - // Handler types for single fields. // Right now we only have one for TYPE_BYTES but ones for other types // should follow. // // These follow the same handlers protocol for fields of a message. -class upb::BytesHandler { +UPB_DEFINE_CLASS0(upb::BytesHandler, public: BytesHandler(); ~BytesHandler(); - - // TODO(haberman): make private and figure out what to friend. -#else -struct upb_byteshandler { -#endif +, +UPB_DEFINE_STRUCT0(upb_byteshandler, upb_handlers_tabent table[3]; -}; +)); void upb_byteshandler_init(upb_byteshandler *h); void upb_byteshandler_uninit(upb_byteshandler *h); @@ -799,12 +768,6 @@ bool upb_byteshandler_setstring(upb_byteshandler *h, bool upb_byteshandler_setendstr(upb_byteshandler *h, upb_endfield_handlerfunc *func, void *d); -#ifdef __cplusplus -namespace upb { -typedef upb_byteshandler BytesHandler; -} -#endif - // "Static" methods bool upb_handlers_freeze(upb_handlers *const *handlers, int n, upb_status *s); upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f); @@ -817,9 +780,8 @@ UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) { // Internal-only. uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f); uint32_t upb_handlers_selectorcount(const upb_fielddef *f); -#ifdef __cplusplus -} // extern "C" -#endif + +UPB_END_EXTERN_C #include "upb/handlers-inl.h" diff --git a/upb/json/typed_printer.h b/upb/json/typed_printer.h index 190aeb3..c9e36f7 100644 --- a/upb/json/typed_printer.h +++ b/upb/json/typed_printer.h @@ -19,20 +19,15 @@ namespace json { class TypedPrinter; } // namespace json } // namespace upb - -typedef upb::json::TypedPrinter upb_json_typedprinter; -#else -struct upb_json_typedprinter; -typedef struct upb_json_typedprinter upb_json_typedprinter; #endif +UPB_DECLARE_TYPE(upb::json::TypedPrinter, upb_json_typedprinter); -/* upb::json::TypedPrinter ****************************************************/ -#ifdef __cplusplus +/* upb::json::TypedPrinter ****************************************************/ // Prints an incoming stream of data to a BytesSink in JSON format. -class upb::json::TypedPrinter { +UPB_DEFINE_CLASS0(upb::json::TypedPrinter, public: TypedPrinter(const upb::Handlers* handlers); ~TypedPrinter(); @@ -50,11 +45,8 @@ class upb::json::TypedPrinter { // Returns handlers for printing according to the specified schema. static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md); - - private: -#else -struct upb_json_typedprinter { -#endif +, +UPB_DEFINE_STRUCT0(upb_json_typedprinter, upb_sink input_; // Pointer to yajl_gen; void* here so we don't have to include YAJL headers. void *yajl_gen_; @@ -63,12 +55,11 @@ struct upb_json_typedprinter { // We track the depth so that we know when to emit startstr/endstr on the // output. int depth_; -}; +)); + +UPB_BEGIN_EXTERN_C // { // Native C API. -#ifdef __cplusplus -extern "C" { -#endif void upb_json_typedprinter_init(upb_json_typedprinter *p, const upb_handlers *h); @@ -80,9 +71,7 @@ upb_sink *upb_json_typedprinter_input(upb_json_typedprinter *p); const upb_handlers *upb_json_typedprinter_newhandlers(const upb_msgdef *md, const void *owner); -#ifdef __cplusplus -} // extern "C" -#endif +UPB_END_EXTERN_C // } #ifdef __cplusplus diff --git a/upb/pb/decoder.h b/upb/pb/decoder.h index 0aa35ec..e43ce10 100644 --- a/upb/pb/decoder.h +++ b/upb/pb/decoder.h @@ -30,23 +30,13 @@ class DecoderMethod; class DecoderMethodOptions; } // namespace pb } // namespace upb - -typedef upb::pb::CodeCache upb_pbcodecache; -typedef upb::pb::Decoder upb_pbdecoder; -typedef upb::pb::DecoderMethod upb_pbdecodermethod; -typedef upb::pb::DecoderMethodOptions upb_pbdecodermethodopts; -#else -struct upb_pbdecoder; -struct upb_pbdecodermethod; -struct upb_pbdecodermethodopts; -struct upb_pbcodecache; - -typedef struct upb_pbdecoder upb_pbdecoder; -typedef struct upb_pbdecodermethod upb_pbdecodermethod; -typedef struct upb_pbdecodermethodopts upb_pbdecodermethodopts; -typedef struct upb_pbcodecache upb_pbcodecache; #endif +UPB_DECLARE_TYPE(upb::pb::CodeCache, upb_pbcodecache); +UPB_DECLARE_TYPE(upb::pb::Decoder, upb_pbdecoder); +UPB_DECLARE_TYPE(upb::pb::DecoderMethod, upb_pbdecodermethod); +UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts); + // The maximum that any submessages can be nested. Matches proto2's limit. // This specifies the size of the decoder's statically-sized array and therefore // setting it high will cause the upb::pb::Decoder object to be larger. @@ -59,20 +49,14 @@ typedef struct upb_pbcodecache upb_pbcodecache; // Internal-only struct used by the decoder. typedef struct { -#ifdef __cplusplus - private: -#endif + UPB_PRIVATE_FOR_CPP // Space optimization note: we store two pointers here that the JIT // doesn't need at all; the upb_handlers* inside the sink and // the dispatch table pointer. We can optimze so that the JIT uses // smaller stack frames than the interpreter. The only thing we need // to guarantee is that the fallback routines can find end_ofs. - -#ifdef __cplusplus - char sink[sizeof(upb_sink)]; -#else upb_sink sink; -#endif + // The absolute stream offset of the end-of-frame delimiter. // Non-delimited frames (groups and non-packed repeated fields) reuse the // delimiter of their parent, even though the frame may not end there. @@ -91,11 +75,9 @@ typedef struct { upb_inttable *dispatch; // Not used by the JIT. } upb_pbdecoder_frame; -#ifdef __cplusplus - // The parameters one uses to construct a DecoderMethod. // TODO(haberman): move allowjit here? Seems more convenient for users. -class upb::pb::DecoderMethodOptions { +UPB_DEFINE_CLASS0(upb::pb::DecoderMethodOptions, public: // Parameter represents the destination handlers that this method will push // to. @@ -105,19 +87,14 @@ class upb::pb::DecoderMethodOptions { // them? The caller should set this iff the lazy handlers expect data that is // in protobuf binary format and the caller wishes to lazy parse it. void set_lazy(bool lazy); - - private: -#else -struct upb_pbdecodermethodopts { -#endif +, +UPB_DEFINE_STRUCT0(upb_pbdecodermethodopts, const upb_handlers *handlers; bool lazy; -}; - -#ifdef __cplusplus +)); // Represents the code to parse a protobuf according to a destination Handlers. -class upb::pb::DecoderMethod /* : public upb::RefCounted */ { +UPB_DEFINE_CLASS1(upb::pb::DecoderMethod, upb::RefCounted, public: // From upb::ReferenceCounted. void Ref(const void* owner) const; @@ -142,11 +119,8 @@ class upb::pb::DecoderMethod /* : public upb::RefCounted */ { private: UPB_DISALLOW_POD_OPS(DecoderMethod, upb::pb::DecoderMethod); -#else -struct upb_pbdecodermethod { -#endif - upb_refcounted base; - +, +UPB_DEFINE_STRUCT(upb_pbdecodermethod, upb_refcounted, // While compiling, the base is relative in "ofs", after compiling it is // absolute in "ptr". union { @@ -186,13 +160,11 @@ struct upb_pbdecodermethod { // the second wire type without needing to do a separate lookup (this case is // less common than an unknown field). upb_inttable dispatch; -}; - -#ifdef __cplusplus +)); // A Decoder receives binary protobuf data on its input sink and pushes the // decoded data to its output sink. -class upb::pb::Decoder { +UPB_DEFINE_CLASS0(upb::pb::Decoder, public: // Constructs a decoder instance for the given method, which must outlive this // decoder. Any errors during parsing will be set on the given status, which @@ -230,9 +202,8 @@ class upb::pb::Decoder { private: UPB_DISALLOW_COPY_AND_ASSIGN(Decoder); -#else -struct upb_pbdecoder { -#endif +, +UPB_DEFINE_STRUCT0(upb_pbdecoder, UPB_QUOTE( // Our input sink. upb_bytessink input_; @@ -286,15 +257,13 @@ struct upb_pbdecoder { #else const uint32_t *callstack[UPB_DECODER_MAX_NESTING]; #endif -}; - -#ifdef __cplusplus +))); // A class for caching protobuf processing code, whether bytecode for the // interpreted decoder or machine code for the JIT. // // This class is not thread-safe. -class upb::pb::CodeCache { +UPB_DEFINE_CLASS0(upb::pb::CodeCache, public: CodeCache(); ~CodeCache(); @@ -327,19 +296,15 @@ class upb::pb::CodeCache { private: UPB_DISALLOW_COPY_AND_ASSIGN(CodeCache); -#else -struct upb_pbcodecache { -#endif +, +UPB_DEFINE_STRUCT0(upb_pbcodecache, bool allow_jit_; // Array of mgroups. upb_inttable groups; -}; - +)); -#ifdef __cplusplus -extern "C" { -#endif +UPB_BEGIN_EXTERN_C // { void upb_pbdecoder_init(upb_pbdecoder *d, const upb_pbdecodermethod *method, upb_status *status); @@ -375,34 +340,12 @@ bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow); const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod( upb_pbcodecache *c, const upb_pbdecodermethodopts *opts); -#ifdef __cplusplus -} /* extern "C" */ -#endif +UPB_END_EXTERN_C // } #ifdef __cplusplus namespace upb { -template<> -class Pointer<pb::DecoderMethod> { - public: - explicit Pointer(pb::DecoderMethod* ptr) : ptr_(ptr) {} - operator pb::DecoderMethod*() { return ptr_; } - operator RefCounted*() { return UPB_UPCAST(ptr_); } - private: - pb::DecoderMethod* ptr_; -}; - -template<> -class Pointer<const pb::DecoderMethod> { - public: - explicit Pointer(const pb::DecoderMethod* ptr) : ptr_(ptr) {} - operator const pb::DecoderMethod*() { return ptr_; } - operator const RefCounted*() { return UPB_UPCAST(ptr_); } - private: - const pb::DecoderMethod* ptr_; -}; - namespace pb { inline Decoder::Decoder(const DecoderMethod* m, Status* s) { diff --git a/upb/pb/textprinter.h b/upb/pb/textprinter.h index eb3e132..97e01f7 100644 --- a/upb/pb/textprinter.h +++ b/upb/pb/textprinter.h @@ -16,15 +16,11 @@ namespace pb { class TextPrinter; } // namespace pb } // namespace upb - -typedef upb::pb::TextPrinter upb_textprinter; -#else -struct upb_textprinter; -typedef struct upb_textprinter upb_textprinter; #endif -#ifdef __cplusplus -class upb::pb::TextPrinter { +UPB_DECLARE_TYPE(upb::pb::TextPrinter, upb_textprinter); + +UPB_DEFINE_CLASS0(upb::pb::TextPrinter, public: // The given handlers must have come from NewHandlers(). It must outlive the // TextPrinter. @@ -40,19 +36,16 @@ class upb::pb::TextPrinter { static reffed_ptr<const Handlers> NewHandlers(const MessageDef* md); private: -#else -struct upb_textprinter { -#endif +, +UPB_DEFINE_STRUCT0(upb_textprinter, upb_sink input_; upb_bytessink *output_; int indent_depth_; bool single_line_; void *subc; -}; +)); -#ifdef __cplusplus -extern "C" { -#endif +UPB_BEGIN_EXTERN_C // { // C API. void upb_textprinter_init(upb_textprinter *p, const upb_handlers *h); @@ -64,8 +57,9 @@ upb_sink *upb_textprinter_input(upb_textprinter *p); const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m, const void *owner); +UPB_END_EXTERN_C // } + #ifdef __cplusplus -} /* extern "C" */ namespace upb { namespace pb { diff --git a/upb/refcounted.h b/upb/refcounted.h index 9e2910b..ab56e4d 100644 --- a/upb/refcounted.h +++ b/upb/refcounted.h @@ -29,20 +29,15 @@ #define UPB_DEBUG_REFS #endif -struct upb_refcounted_vtbl; - #ifdef __cplusplus namespace upb { class RefCounted; } -typedef upb::RefCounted upb_refcounted; -extern "C" { -#else -struct upb_refcounted; -typedef struct upb_refcounted upb_refcounted; #endif -#ifdef __cplusplus +UPB_DECLARE_TYPE(upb::RefCounted, upb_refcounted); + +struct upb_refcounted_vtbl; -class upb::RefCounted { +UPB_DEFINE_CLASS0(upb::RefCounted, public: // Returns true if the given object is frozen. bool IsFrozen() const; @@ -68,9 +63,8 @@ class upb::RefCounted { private: UPB_DISALLOW_POD_OPS(RefCounted, upb::RefCounted); -#else -struct upb_refcounted { -#endif +, +UPB_DEFINE_STRUCT0(upb_refcounted, // A single reference count shared by all objects in the group. uint32_t *group; @@ -91,7 +85,9 @@ struct upb_refcounted { upb_inttable *refs; // Maps owner -> trackedref for incoming refs. upb_inttable *ref2s; // Set of targets for outgoing ref2s. #endif -}; +)); + +UPB_BEGIN_EXTERN_C // { // Native C API. bool upb_refcounted_isfrozen(const upb_refcounted *r); @@ -159,6 +155,8 @@ bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s, // Shared by all compiled-in refcounted objects. extern uint32_t static_refcount; +UPB_END_EXTERN_C // } + #ifdef UPB_DEBUG_REFS #define UPB_REFCOUNT_INIT(refs, ref2s) \ {&static_refcount, NULL, NULL, 0, true, refs, ref2s} @@ -167,8 +165,6 @@ extern uint32_t static_refcount; #endif #ifdef __cplusplus -} /* extern "C" */ - // C++ Wrappers. namespace upb { inline bool RefCounted::IsFrozen() const { diff --git a/upb/shim/shim.h b/upb/shim/shim.h index bc47bbb..0d090db 100644 --- a/upb/shim/shim.h +++ b/upb/shim/shim.h @@ -45,21 +45,21 @@ struct Shim { } // namespace upb -extern "C" { #endif +UPB_BEGIN_EXTERN_C // { + // C API. bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset, int32_t hasbit); const upb_shim_data *upb_shim_getdata(const upb_handlers *h, upb_selector_t s, upb_fieldtype_t *type); -#ifdef __cplusplus -} // extern "C" - -namespace upb { +UPB_END_EXTERN_C // } +#ifdef __cplusplus // C++ Wrappers. +namespace upb { inline bool Shim::Set(Handlers* h, const FieldDef* f, size_t ofs, int32_t hasbit) { return upb_shim_set(h, f, ofs, hasbit); @@ -68,9 +68,7 @@ inline const Shim::Data* Shim::GetData(const Handlers* h, Handlers::Selector s, FieldDef::Type* type) { return upb_shim_getdata(h, s, type); } - -} // namespace - +} // namespace upb #endif #endif // UPB_SHIM_H @@ -28,20 +28,15 @@ class BufferSource; class BytesSink; class Sink; } -typedef upb::BufferSource upb_bufsrc; -typedef upb::BytesSink upb_bytessink; -typedef upb::Sink upb_sink; -#else -struct upb_sink; -struct upb_bufsrc; -struct upb_bytessink; -typedef struct upb_sink upb_sink; -typedef struct upb_bytessink upb_bytessink; -typedef struct upb_bufsrc upb_bufsrc; #endif +UPB_DECLARE_TYPE(upb::BufferSource, upb_bufsrc); +UPB_DECLARE_TYPE(upb::BytesSink, upb_bytessink); +UPB_DECLARE_TYPE(upb::Sink, upb_sink); + // Internal-only struct for the sink. struct upb_sinkframe { + UPB_PRIVATE_FOR_CPP const upb_handlers *h; void *closure; @@ -60,11 +55,43 @@ struct upb_sinkframe { // TODO: make this a runtime-settable property of Sink. #define UPB_SINK_MAX_NESTING 64 -#ifdef __cplusplus - // A upb::Sink is an object that binds a upb::Handlers object to some runtime // state. It represents an endpoint to which data can be sent. -class upb::Sink { +// +// TODO(haberman): right now all of these functions take selectors. Should they +// take selectorbase instead? +// +// ie. instead of calling: +// sink->StartString(FOO_FIELD_START_STRING, ...) +// a selector base would let you say: +// sink->StartString(FOO_FIELD, ...) +// +// This would make call sites a little nicer and require emitting fewer selector +// definitions in .h files. +// +// But the current scheme has the benefit that you can retrieve a function +// pointer for any handler with handlers->GetHandler(selector), without having +// to have a separate GetHandler() function for each handler type. The JIT +// compiler uses this. To accommodate we'd have to expose a separate +// GetHandler() for every handler type. +// +// Also to ponder: selectors right now are independent of a specific Handlers +// instance. In other words, they allocate a number to every possible handler +// that *could* be registered, without knowing anything about what handlers +// *are* registered. That means that using selectors as table offsets prohibits +// us from compacting the handler table at Freeze() time. If the table is very +// sparse, this could be wasteful. +// +// Having another selector-like thing that is specific to a Handlers instance +// would allow this compacting, but then it would be impossible to write code +// ahead-of-time that can be bound to any Handlers instance at runtime. For +// example, a .proto file parser written as straight C will not know what +// Handlers it will be bound to, so when it calls sink->StartString() what +// selector will it pass? It needs a selector like we have today, that is +// independent of any particular upb::Handlers. +// +// Is there a way then to allow Handlers table compaction? +UPB_DEFINE_CLASS0(upb::Sink, public: // Constructor with no initialization; must be Reset() before use. Sink() {} @@ -144,16 +171,13 @@ class upb::Sink { // Copy and assign specifically allowed. // We don't even bother making these members private because so many // functions need them and this is mainly just a dumb data container anyway. -#else -struct upb_sink { -#endif +, +UPB_DEFINE_STRUCT0(upb_sink, const upb_handlers *handlers; void *closure; -}; +)); -#ifdef __cplusplus - -class upb::BytesSink { +UPB_DEFINE_CLASS0(upb::BytesSink, public: BytesSink() {} @@ -170,20 +194,16 @@ class upb::BytesSink { size_t PutBuffer(void *subc, const char *buf, size_t len, const BufferHandle *handle); bool End(); - -#else -struct upb_bytessink { -#endif +, +UPB_DEFINE_STRUCT0(upb_bytessink, const upb_byteshandler *handler; void *closure; -}; - -#ifdef __cplusplus +)); // A class for pushing a flat buffer of data to a BytesSink. // You can construct an instance of this to get a resumable source, // or just call the static PutBuffer() to do a non-resumable push all in one go. -class upb::BufferSource { +UPB_DEFINE_CLASS0(upb::BufferSource, public: BufferSource(); BufferSource(const char* buf, size_t len, BytesSink* sink); @@ -200,16 +220,11 @@ class upb::BufferSource { template <class T> static bool PutBuffer(const T& str, BytesSink* sink) { return PutBuffer(str.c_str(), str.size(), sink); } +, +UPB_DEFINE_STRUCT0(upb_bufsrc, +)); - private: -#else -struct upb_bufsrc { -#endif -}; - -#ifdef __cplusplus -extern "C" { -#endif +UPB_BEGIN_EXTERN_C // { // Inline definitions. @@ -409,9 +424,7 @@ UPB_INLINE bool upb_sink_endsubmsg(upb_sink *s, upb_selector_t sel) { return endsubmsg(s->closure, hd); } -#ifdef __cplusplus -} /* extern "C" */ -#endif +UPB_END_EXTERN_C // } #ifdef __cplusplus diff --git a/upb/symtab.h b/upb/symtab.h index f2baeb7..c0a1976 100644 --- a/upb/symtab.h +++ b/upb/symtab.h @@ -16,27 +16,23 @@ #ifndef UPB_SYMTAB_H_ #define UPB_SYMTAB_H_ +#include "upb/def.h" + #ifdef __cplusplus #include <vector> - namespace upb { class SymbolTable; } -typedef upb::SymbolTable upb_symtab; -#else -struct upb_symtab; -typedef struct upb_symtab upb_symtab; #endif -#include "upb/def.h" +UPB_DECLARE_TYPE(upb::SymbolTable, upb_symtab); typedef struct { + UPB_PRIVATE_FOR_CPP upb_strtable_iter iter; upb_deftype_t type; } upb_symtab_iter; -#ifdef __cplusplus - // Non-const methods in upb::SymbolTable are NOT thread-safe. -class upb::SymbolTable { +UPB_DEFINE_CLASS1(upb::SymbolTable, upb::RefCounted, public: // Returns a new symbol table with a single ref owned by "owner." // Returns NULL if memory allocation failed. @@ -124,21 +120,17 @@ class upb::SymbolTable { private: UPB_DISALLOW_POD_OPS(SymbolTable, upb::SymbolTable); - -#else -struct upb_symtab { -#endif - upb_refcounted base; +, +UPB_DEFINE_STRUCT(upb_symtab, upb_refcounted, upb_strtable symtab; -}; +)); #define UPB_SYMTAB_INIT(symtab, refs, ref2s) \ { UPB_REFCOUNT_INIT(refs, ref2s), symtab } +UPB_BEGIN_EXTERN_C // { + // Native C API. -#ifdef __cplusplus -extern "C" { -#endif // From upb_refcounted. bool upb_symtab_isfrozen(const upb_symtab *s); void upb_symtab_ref(const upb_symtab *s, const void *owner); @@ -173,32 +165,11 @@ void upb_symtab_next(upb_symtab_iter *iter); bool upb_symtab_done(const upb_symtab_iter *iter); const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter); -#ifdef __cplusplus -} /* extern "C" */ +UPB_END_EXTERN_C // } +#ifdef __cplusplus // C++ inline wrappers. namespace upb { - -template<> -class Pointer<SymbolTable> { - public: - explicit Pointer(SymbolTable* ptr) : ptr_(ptr) {} - operator SymbolTable*() { return ptr_; } - operator RefCounted*() { return UPB_UPCAST(ptr_); } - private: - SymbolTable* ptr_; -}; - -template<> -class Pointer<const SymbolTable> { - public: - explicit Pointer(const SymbolTable* ptr) : ptr_(ptr) {} - operator const SymbolTable*() { return ptr_; } - operator const RefCounted*() { return UPB_UPCAST(ptr_); } - private: - const SymbolTable* ptr_; -}; - inline reffed_ptr<SymbolTable> SymbolTable::New() { upb_symtab *s = upb_symtab_new(&s); return reffed_ptr<SymbolTable>(s, &s); @@ -45,7 +45,10 @@ friend class Pointer<full_class_name>; \ friend class Pointer<const full_class_name>; \ UPB_DISALLOW_COPY_AND_ASSIGN(class_name) -#else +#define UPB_ASSERT_STDLAYOUT(type) \ + static_assert(std::is_standard_layout<type>::value, \ + #type " must be standard layout"); +#else // !defined(UPB_CXX11) #define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \ class_name(const class_name&); \ void operator=(const class_name&); @@ -56,13 +59,85 @@ friend class Pointer<full_class_name>; \ friend class Pointer<const full_class_name>; \ UPB_DISALLOW_COPY_AND_ASSIGN(class_name) +#define UPB_ASSERT_STDLAYOUT(type) #endif + #ifdef __cplusplus + #define UPB_PRIVATE_FOR_CPP private: -#else +#define UPB_DECLARE_TYPE(cppname, cname) typedef cppname cname; +#define UPB_BEGIN_EXTERN_C extern "C" { +#define UPB_END_EXTERN_C } +#define UPB_DEFINE_STRUCT0(cname, members) members; +#define UPB_DEFINE_STRUCT(cname, cbase, members) \ + public: \ + cbase* base() { return &base_; } \ + const cbase* base() const { return &base_; } \ + \ + private: \ + cbase base_; \ + members; +#define UPB_DEFINE_CLASS0(cppname, cppmethods, members) \ + class cppname { \ + cppmethods \ + members \ + }; \ + UPB_ASSERT_STDLAYOUT(cppname); +#define UPB_DEFINE_CLASS1(cppname, cppbase, cppmethods, members) \ + UPB_DEFINE_CLASS0(cppname, cppmethods, members) \ + namespace upb { \ + template <> \ + class Pointer<cppname> : public PointerBase<cppname, cppbase> { \ + public: \ + explicit Pointer(cppname* ptr) : PointerBase(ptr) {} \ + }; \ + template <> \ + class Pointer<const cppname> \ + : public PointerBase<const cppname, const cppbase> { \ + public: \ + explicit Pointer(const cppname* ptr) : PointerBase(ptr) {} \ + }; \ + } +#define UPB_DEFINE_CLASS2(cppname, cppbase, cppbase2, cppmethods, members) \ + UPB_DEFINE_CLASS0(cppname, UPB_QUOTE(cppmethods), members) \ + namespace upb { \ + template <> \ + class Pointer<cppname> : public PointerBase2<cppname, cppbase, cppbase2> { \ + public: \ + explicit Pointer(cppname* ptr) : PointerBase2(ptr) {} \ + }; \ + template <> \ + class Pointer<const cppname> \ + : public PointerBase2<const cppname, const cppbase, const cppbase2> { \ + public: \ + explicit Pointer(const cppname* ptr) : PointerBase2(ptr) {} \ + }; \ + } + +#else // !defined(__cplusplus) + #define UPB_PRIVATE_FOR_CPP -#endif +#define UPB_DECLARE_TYPE(cppname, cname) \ + struct cname; \ + typedef struct cname cname; +#define UPB_BEGIN_EXTERN_C +#define UPB_END_EXTERN_C +#define UPB_DEFINE_STRUCT0(cname, members) \ + struct cname { \ + members; \ + }; +#define UPB_DEFINE_STRUCT(cname, cbase, members) \ + struct cname { \ + cbase base; \ + members; \ + }; +#define UPB_DEFINE_CLASS0(cppname, cppmethods, members) members +#define UPB_DEFINE_CLASS1(cppname, cppbase, cppmethods, members) members +#define UPB_DEFINE_CLASS2(cppname, cppbase, cppbase2, cppmethods, members) \ + members + +#endif // defined(__cplusplus) #ifdef __GNUC__ #define UPB_NORETURN __attribute__((__noreturn__)) @@ -75,6 +150,11 @@ #define UPB_UNUSED(var) (void)var +// Code with commas confuses the preprocessor when passed as arguments, whether +// C++ type names with commas (eg. Foo<int, int>) or code blocks that declare +// variables (ie. int foo, bar). +#define UPB_QUOTE(...) __VA_ARGS__ + // For asserting something about a variable when the variable is not used for // anything else. This prevents "unused variable" warnings when compiling in // debug mode. @@ -118,6 +198,25 @@ template <class T> class Pointer; // Casts to any base class, or the type itself (ie. can be a no-op). template <class T> inline Pointer<T> upcast(T *f) { return Pointer<T>(f); } + +template <class T, class Base> +class PointerBase { + public: + explicit PointerBase(T* ptr) : ptr_(ptr) {} + operator T*() { return ptr_; } + operator Base*() { return ptr_->base(); } + + private: + T* ptr_; +}; + +template <class T, class Base, class Base2> +class PointerBase2 : public PointerBase<T, Base> { + public: + explicit PointerBase2(T* ptr) : PointerBase<T, Base>(ptr) {} + operator Base2*() { return Pointer<Base>(*this); } +}; + } #endif @@ -230,13 +329,15 @@ template <class T> class reffed_ptr { /* upb::Status ****************************************************************/ #ifdef __cplusplus -namespace upb { class Status; } -typedef upb::Status upb_status; -#else -struct upb_status; -typedef struct upb_status upb_status; +namespace upb { +class ErrorSpace; +class Status; +} #endif +UPB_DECLARE_TYPE(upb::ErrorSpace, upb_errorspace); +UPB_DECLARE_TYPE(upb::Status, upb_status); + // The maximum length of an error message before it will get truncated. #define UPB_STATUS_MAX_MESSAGE 128 @@ -245,20 +346,18 @@ typedef struct upb_status upb_status; // to recover and proceed, but this is not always possible. typedef bool upb_errcb_t(void *closure, const upb_status* status); -typedef struct { +UPB_DEFINE_CLASS0(upb::ErrorSpace, +, +UPB_DEFINE_STRUCT0(upb_errorspace, const char *name; // Should the error message in the status object according to this code. void (*set_message)(upb_status* status, int code); -} upb_errorspace; - -#ifdef __cplusplus - -typedef upb_errorspace ErrorSpace; +)); // Object representing a success or failure status. // It owns no resources and allocates no memory, so it should work // even in OOM situations. -class upb::Status { +UPB_DEFINE_CLASS0(upb::Status, public: Status(); @@ -289,9 +388,8 @@ class upb::Status { private: UPB_DISALLOW_COPY_AND_ASSIGN(Status); -#else -struct upb_status { -#endif +, +UPB_DEFINE_STRUCT0(upb_status, bool ok_; // Specific status code defined by some error space (optional). @@ -300,7 +398,7 @@ struct upb_status { // Error message; NULL-terminated. char msg[UPB_STATUS_MAX_MESSAGE]; -}; +)); #define UPB_STATUS_INIT {true, 0, NULL, {0}} |