|
|
|
@ -393,25 +393,35 @@ void DumpEnumValues(const protobuf::EnumDescriptor* desc, Output& output) { |
|
|
|
|
void GenerateExtensionInHeader(const protobuf::FieldDescriptor* ext, |
|
|
|
|
Output& output) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE bool $0_has_$1(const struct $2 *msg) { " |
|
|
|
|
"return _upb_Message_Getext(msg, &$3) != NULL; }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE bool $0_has_$1(const struct $2* msg) { |
|
|
|
|
return _upb_Message_Getext(msg, &$3) != NULL; |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
ExtensionIdentBase(ext), ext->name(), MessageName(ext->containing_type()), |
|
|
|
|
ExtensionLayout(ext)); |
|
|
|
|
|
|
|
|
|
if (ext->is_repeated()) { |
|
|
|
|
} else if (ext->message_type()) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0 $1_$2(const struct $3 *msg) { " |
|
|
|
|
"const upb_Message_Extension *ext = _upb_Message_Getext(msg, &$4); " |
|
|
|
|
"UPB_ASSERT(ext); return *UPB_PTR_AT(&ext->data, 0, $0); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0 $1_$2(const struct $3* msg) { |
|
|
|
|
const upb_Message_Extension* ext = _upb_Message_Getext(msg, &$4); |
|
|
|
|
UPB_ASSERT(ext); |
|
|
|
|
return *UPB_PTR_AT(&ext->data, 0, $0); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(ext), ExtensionIdentBase(ext), ext->name(), |
|
|
|
|
MessageName(ext->containing_type()), ExtensionLayout(ext), |
|
|
|
|
FieldDefault(ext)); |
|
|
|
|
} else { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0 $1_$2(const struct $3 *msg) { " |
|
|
|
|
"const upb_Message_Extension *ext = _upb_Message_Getext(msg, &$4); " |
|
|
|
|
"return ext ? *UPB_PTR_AT(&ext->data, 0, $0) : $5; }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0 $1_$2(const struct $3* msg) { |
|
|
|
|
const upb_Message_Extension* ext = _upb_Message_Getext(msg, &$4); |
|
|
|
|
return ext ? *UPB_PTR_AT(&ext->data, 0, $0) : $5; |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(ext), ExtensionIdentBase(ext), ext->name(), |
|
|
|
|
MessageName(ext->containing_type()), ExtensionLayout(ext), |
|
|
|
|
FieldDefault(ext)); |
|
|
|
@ -469,9 +479,11 @@ void GenerateOneofInHeader(const protobuf::OneofDescriptor* oneof, |
|
|
|
|
"} $0_oneofcases;\n", |
|
|
|
|
fullname); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0_oneofcases $1_$2_case(const $1* msg) { " |
|
|
|
|
"return ($0_oneofcases)*UPB_PTR_AT(msg, $3, int32_t); }\n" |
|
|
|
|
"\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0_oneofcases $1_$2_case(const $1* msg) { |
|
|
|
|
return ($0_oneofcases)*UPB_PTR_AT(msg, $3, int32_t); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
fullname, msg_name, oneof->name(), |
|
|
|
|
GetSizeInit(layout.GetOneofCaseOffset(oneof))); |
|
|
|
|
} |
|
|
|
@ -481,20 +493,29 @@ void GenerateHazzer(const protobuf::FieldDescriptor* field, |
|
|
|
|
Output& output) { |
|
|
|
|
if (layout.HasHasbit(field)) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE bool $0_has_$1(const $0 *msg) { " |
|
|
|
|
"return _upb_hasbit(msg, $2); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE bool $0_has_$1(const $0* msg) { |
|
|
|
|
return _upb_hasbit(msg, $2); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field->name(), layout.GetHasbitIndex(field)); |
|
|
|
|
} else if (field->real_containing_oneof()) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE bool $0_has_$1(const $0 *msg) { " |
|
|
|
|
"return _upb_getoneofcase(msg, $2) == $3; }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE bool $0_has_$1(const $0* msg) { |
|
|
|
|
return _upb_getoneofcase(msg, $2) == $3; |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field->name(), |
|
|
|
|
GetSizeInit(layout.GetOneofCaseOffset(field->real_containing_oneof())), |
|
|
|
|
field->number()); |
|
|
|
|
} else if (field->message_type()) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE bool $0_has_$1(const $0 *msg) { " |
|
|
|
|
"return _upb_has_submsg_nohasbit(msg, $2); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE bool $0_has_$1(const $0* msg) { |
|
|
|
|
return _upb_has_submsg_nohasbit(msg, $2); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field->name(), GetSizeInit(layout.GetFieldOffset(field))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -506,12 +527,18 @@ void GenerateMapGetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
const protobuf::FieldDescriptor* key = entry->FindFieldByNumber(1); |
|
|
|
|
const protobuf::FieldDescriptor* val = entry->FindFieldByNumber(2); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE size_t $0_$1_size(const $0 *msg) {" |
|
|
|
|
"return _upb_msg_map_size(msg, $2); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE size_t $0_$1_size(const $0* msg) { |
|
|
|
|
return _upb_msg_map_size(msg, $2); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field->name(), GetSizeInit(layout.GetFieldOffset(field))); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE bool $0_$1_get(const $0 *msg, $2 key, $3 *val) { " |
|
|
|
|
"return _upb_msg_map_get(msg, $4, &key, $5, val, $6); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE bool $0_$1_get(const $0* msg, $2 key, $3* val) { |
|
|
|
|
return _upb_msg_map_get(msg, $4, &key, $5, val, $6); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field->name(), CType(key), CType(val), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field)), |
|
|
|
|
key->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_STRING |
|
|
|
@ -521,8 +548,11 @@ void GenerateMapGetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
? "0" |
|
|
|
|
: "sizeof(*val)"); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0 $1_$2_next(const $1 *msg, size_t* iter) { " |
|
|
|
|
"return ($0)_upb_msg_map_next(msg, $3, iter); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0 $1_$2_next(const $1* msg, size_t* iter) { |
|
|
|
|
return ($0)_upb_msg_map_next(msg, $3, iter); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(field), msg_name, field->name(), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field))); |
|
|
|
|
} |
|
|
|
@ -530,11 +560,13 @@ void GenerateMapGetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
void GenerateMapEntryGetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
absl::string_view msg_name, Output& output) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0 $1_$2(const $1 *msg) {\n" |
|
|
|
|
" $3 ret;\n" |
|
|
|
|
" _upb_msg_map_$2(msg, &ret, $4);\n" |
|
|
|
|
" return ret;\n" |
|
|
|
|
"}\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0 $1_$2(const $1* msg) { |
|
|
|
|
$3 ret; |
|
|
|
|
_upb_msg_map_$2(msg, &ret, $4); |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(field), msg_name, field->name(), CType(field), |
|
|
|
|
field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_STRING |
|
|
|
|
? "0" |
|
|
|
@ -545,8 +577,11 @@ void GenerateRepeatedGetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
const MessageLayout& layout, |
|
|
|
|
absl::string_view msg_name, Output& output) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0 const* $1_$2(const $1 *msg, size_t *len) { " |
|
|
|
|
"return ($0 const*)_upb_array_accessor(msg, $3, len); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0 const* $1_$2(const $1* msg, size_t* len) { |
|
|
|
|
return ($0 const*)_upb_array_accessor(msg, $3, len); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(field), msg_name, field->name(), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field))); |
|
|
|
|
} |
|
|
|
@ -555,8 +590,11 @@ void GenerateOneofGetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
const MessageLayout& layout, |
|
|
|
|
absl::string_view msg_name, Output& output) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0 $1_$2(const $1 *msg) { " |
|
|
|
|
"return UPB_READ_ONEOF(msg, $0, $3, $4, $5, $6); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0 $1_$2(const $1* msg) { |
|
|
|
|
return UPB_READ_ONEOF(msg, $0, $3, $4, $5, $6); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(field), msg_name, field->name(), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field)), |
|
|
|
|
GetSizeInit(layout.GetOneofCaseOffset(field->real_containing_oneof())), |
|
|
|
@ -610,14 +648,16 @@ void GenerateMapSetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
const protobuf::FieldDescriptor* key = entry->FindFieldByNumber(1); |
|
|
|
|
const protobuf::FieldDescriptor* val = entry->FindFieldByNumber(2); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE void $0_$1_clear($0 *msg) { _upb_msg_map_clear(msg, " |
|
|
|
|
"$2); " |
|
|
|
|
"}\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE void $0_$1_clear($0* msg) { _upb_msg_map_clear(msg, $2); } |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field->name(), GetSizeInit(layout.GetFieldOffset(field))); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE bool $0_$1_set($0 *msg, $2 key, $3 val, upb_Arena *a) " |
|
|
|
|
"{ " |
|
|
|
|
"return _upb_msg_map_set(msg, $4, &key, $5, &val, $6, a); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE bool $0_$1_set($0* msg, $2 key, $3 val, upb_Arena* a) { |
|
|
|
|
return _upb_msg_map_set(msg, $4, &key, $5, &val, $6, a); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field->name(), CType(key), CType(val), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field)), |
|
|
|
|
key->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_STRING |
|
|
|
@ -627,16 +667,22 @@ void GenerateMapSetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
? "0" |
|
|
|
|
: "sizeof(val)"); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE bool $0_$1_delete($0 *msg, $2 key) { " |
|
|
|
|
"return _upb_msg_map_delete(msg, $3, &key, $4); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE bool $0_$1_delete($0* msg, $2 key) { |
|
|
|
|
return _upb_msg_map_delete(msg, $3, &key, $4); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field->name(), CType(key), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field)), |
|
|
|
|
key->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_STRING |
|
|
|
|
? "0" |
|
|
|
|
: "sizeof(key)"); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0 $1_$2_nextmutable($1 *msg, size_t* iter) { " |
|
|
|
|
"return ($0)_upb_msg_map_next(msg, $3, iter); }\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0 $1_$2_nextmutable($1* msg, size_t* iter) { |
|
|
|
|
return ($0)_upb_msg_map_next(msg, $3, iter); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CType(field), msg_name, field->name(), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field))); |
|
|
|
|
} |
|
|
|
@ -645,37 +691,41 @@ void GenerateRepeatedSetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
const MessageLayout& layout, |
|
|
|
|
absl::string_view msg_name, Output& output) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0* $1_mutable_$2($1 *msg, size_t *len) {\n" |
|
|
|
|
" return ($0*)_upb_array_mutable_accessor(msg, $3, len);\n" |
|
|
|
|
"}\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0* $1_mutable_$2($1* msg, size_t* len) { |
|
|
|
|
return ($0*)_upb_array_mutable_accessor(msg, $3, len); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CType(field), msg_name, field->name(), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field))); |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE $0* $1_resize_$2($1 *msg, size_t len, " |
|
|
|
|
"upb_Arena *arena) {\n" |
|
|
|
|
" return ($0*)_upb_Array_Resize_accessor2(msg, $3, len, $4, " |
|
|
|
|
"arena);\n" |
|
|
|
|
"}\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0* $1_resize_$2($1* msg, size_t len, upb_Arena* arena) { |
|
|
|
|
return ($0*)_upb_Array_Resize_accessor2(msg, $3, len, $4, arena); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CType(field), msg_name, field->name(), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field)), SizeLg2(field)); |
|
|
|
|
if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE struct $0* $1_add_$2($1 *msg, upb_Arena *arena) {\n" |
|
|
|
|
" struct $0* sub = (struct $0*)_upb_Message_New(&$3, arena);\n" |
|
|
|
|
" bool ok = _upb_Array_Append_accessor2(\n" |
|
|
|
|
" msg, $4, $5, &sub, arena);\n" |
|
|
|
|
" if (!ok) return NULL;\n" |
|
|
|
|
" return sub;\n" |
|
|
|
|
"}\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE struct $0* $1_add_$2($1* msg, upb_Arena* arena) { |
|
|
|
|
struct $0* sub = (struct $0*)_upb_Message_New(&$3, arena); |
|
|
|
|
bool ok = _upb_Array_Append_accessor2(msg, $4, $5, &sub, arena); |
|
|
|
|
if (!ok) return NULL; |
|
|
|
|
return sub; |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
MessageName(field->message_type()), msg_name, field->name(), |
|
|
|
|
MessageInit(field->message_type()), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field)), SizeLg2(field)); |
|
|
|
|
} else { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE bool $1_add_$2($1 *msg, $0 val, upb_Arena *arena) {\n" |
|
|
|
|
" return _upb_Array_Append_accessor2(msg, $3, $4, &val,\n" |
|
|
|
|
" arena);\n" |
|
|
|
|
"}\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE bool $1_add_$2($1* msg, $0 val, upb_Arena* arena) { |
|
|
|
|
return _upb_Array_Append_accessor2(msg, $3, $4, &val, arena); |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CType(field), msg_name, field->name(), |
|
|
|
|
GetSizeInit(layout.GetFieldOffset(field)), SizeLg2(field)); |
|
|
|
|
} |
|
|
|
@ -723,16 +773,17 @@ void GenerateNonRepeatedSetters(const protobuf::FieldDescriptor* field, |
|
|
|
|
if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
|
!field->containing_type()->options().map_entry()) { |
|
|
|
|
output( |
|
|
|
|
"UPB_INLINE struct $0* $1_mutable_$2($1 *msg, upb_Arena *arena) " |
|
|
|
|
"{\n" |
|
|
|
|
" struct $0* sub = (struct $0*)$1_$2(msg);\n" |
|
|
|
|
" if (sub == NULL) {\n" |
|
|
|
|
" sub = (struct $0*)_upb_Message_New(&$3, arena);\n" |
|
|
|
|
" if (!sub) return NULL;\n" |
|
|
|
|
" $1_set_$2(msg, sub);\n" |
|
|
|
|
" }\n" |
|
|
|
|
" return sub;\n" |
|
|
|
|
"}\n", |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE struct $0* $1_mutable_$2($1* msg, upb_Arena* arena) { |
|
|
|
|
struct $0* sub = (struct $0*)$1_$2(msg); |
|
|
|
|
if (sub == NULL) { |
|
|
|
|
sub = (struct $0*)_upb_Message_New(&$3, arena); |
|
|
|
|
if (!sub) return NULL; |
|
|
|
|
$1_set_$2(msg, sub); |
|
|
|
|
} |
|
|
|
|
return sub; |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
MessageName(field->message_type()), msg_name, field->name(), |
|
|
|
|
MessageInit(field->message_type())); |
|
|
|
|
} |
|
|
|
|