hpb: expunge MessageName in favor of upb::generator::CApiMessageType

PiperOrigin-RevId: 686896344
pull/18855/head
Hong Shin 2 months ago committed by Copybara-Service
parent b956147ce1
commit d80ac3a7e6
  1. 5
      hpb_generator/context.h
  2. 98
      hpb_generator/gen_accessors.cc
  3. 28
      hpb_generator/gen_messages.cc
  4. 41
      hpb_generator/gen_repeated_fields.cc

@ -8,7 +8,6 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_HPB_CONTEXT_H__ #ifndef GOOGLE_PROTOBUF_COMPILER_HPB_CONTEXT_H__
#define GOOGLE_PROTOBUF_COMPILER_HPB_CONTEXT_H__ #define GOOGLE_PROTOBUF_COMPILER_HPB_CONTEXT_H__
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
@ -80,10 +79,6 @@ class Context final {
}; };
// TODO: b/373438292 - re-house these 4 legacy funcs post io::Printer move // TODO: b/373438292 - re-house these 4 legacy funcs post io::Printer move
inline std::string MessageName(const google::protobuf::Descriptor* descriptor) {
return upb::generator::CApiMessageType(descriptor->full_name());
}
inline std::string ToCIdent(absl::string_view str) { inline std::string ToCIdent(absl::string_view str) {
return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}, {"-", "_"}}); return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}, {"-", "_"}});
} }

@ -128,7 +128,8 @@ void WriteFieldAccessorsInHeader(const protobuf::Descriptor* desc,
inline $0 $1() const { return $2_$3(msg_); } inline $0 $1() const { return $2_$3(msg_); }
inline void set_$1($0 value) { return $2_set_$3(msg_, value); } inline void set_$1($0 value) { return $2_set_$3(msg_, value); }
)cc", )cc",
CppConstType(field), resolved_field_name, MessageName(desc), CppConstType(field), resolved_field_name,
upb::generator::CApiMessageType(desc->full_name()),
resolved_upbc_name); resolved_upbc_name);
} }
} }
@ -144,7 +145,9 @@ void WriteFieldAccessorHazzer(const protobuf::Descriptor* desc,
if (field->has_presence()) { if (field->has_presence()) {
// Has presence. // Has presence.
ctx.EmitLegacy("inline bool has_$0() const { return $1_has_$2(msg_); }\n", ctx.EmitLegacy("inline bool has_$0() const { return $1_has_$2(msg_); }\n",
resolved_field_name, MessageName(desc), resolved_upbc_name); resolved_field_name,
upb::generator::CApiMessageType(desc->full_name()),
resolved_upbc_name);
} }
} }
@ -155,7 +158,8 @@ void WriteFieldAccessorClear(const protobuf::Descriptor* desc,
Context& ctx) { Context& ctx) {
if (field->has_presence()) { if (field->has_presence()) {
ctx.EmitLegacy("void clear_$0() { $2_clear_$1(msg_); }\n", ctx.EmitLegacy("void clear_$0() { $2_clear_$1(msg_); }\n",
resolved_field_name, resolved_upbc_name, MessageName(desc)); resolved_field_name, resolved_upbc_name,
upb::generator::CApiMessageType(desc->full_name()));
} }
} }
@ -173,8 +177,8 @@ void WriteMapFieldAccessors(const protobuf::Descriptor* desc,
inline void clear_$0() { $1_clear_$3(msg_); } inline void clear_$0() { $1_clear_$3(msg_); }
void delete_$0($2 key); void delete_$0($2 key);
)cc", )cc",
resolved_field_name, MessageName(desc), CppConstType(key), resolved_field_name, upb::generator::CApiMessageType(desc->full_name()),
resolved_upbc_name); CppConstType(key), resolved_upbc_name);
if (val->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) { if (val->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {
ctx.Emit({{"field_name", resolved_field_name}, ctx.Emit({{"field_name", resolved_field_name},
@ -240,7 +244,8 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Context& ctx) {
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,
MessageName(desc), resolved_upbc_name); upb::generator::CApiMessageType(desc->full_name()),
resolved_upbc_name);
// Set string. // Set string.
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
@ -249,7 +254,9 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Context& ctx) {
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,
resolved_upbc_name, MessageName(desc), arena_expression); resolved_upbc_name,
upb::generator::CApiMessageType(desc->full_name()),
arena_expression);
} else if (field->cpp_type() == } else if (field->cpp_type() ==
protobuf::FieldDescriptor::CPPTYPE_MESSAGE) { protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {
ctx.EmitLegacy( ctx.EmitLegacy(
@ -263,7 +270,8 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Context& ctx) {
} }
)cc", )cc",
class_name, MessagePtrConstType(field, /* is_const */ true), class_name, MessagePtrConstType(field, /* is_const */ true),
resolved_field_name, MessageName(desc), resolved_field_name,
upb::generator::CApiMessageType(desc->full_name()),
MessageBaseType(field, /* maybe_const */ false), MessageBaseType(field, /* maybe_const */ false),
resolved_upbc_name); resolved_upbc_name);
@ -282,7 +290,8 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Context& ctx) {
} }
)cc", )cc",
class_name, MessagePtrConstType(field, /* is_const */ false), class_name, MessagePtrConstType(field, /* is_const */ false),
resolved_field_name, MessageName(desc), resolved_field_name,
upb::generator::CApiMessageType(desc->full_name()),
MessageBaseType(field, /* maybe_const */ false), resolved_upbc_name, MessageBaseType(field, /* maybe_const */ false), resolved_upbc_name,
arena_expression, ClassName(desc), field->index()); arena_expression, ClassName(desc), field->index());
} }
@ -292,7 +301,7 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Context& ctx) {
ctx.Emit("} // namespace internal\n\n"); ctx.Emit("} // namespace internal\n\n");
} }
void WriteMapAccessorDefinitions(const protobuf::Descriptor* message, void WriteMapAccessorDefinitions(const protobuf::Descriptor* desc,
const protobuf::FieldDescriptor* field, const protobuf::FieldDescriptor* field,
const absl::string_view resolved_field_name, const absl::string_view resolved_field_name,
const absl::string_view class_name, const absl::string_view class_name,
@ -322,9 +331,10 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), class_name, resolved_field_name, CppConstType(key),
MessagePtrConstType(val, /* is_const */ true), MessageName(message), MessagePtrConstType(val, /* is_const */ true),
MessageName(val->message_type()), optional_conversion_code, upb::generator::CApiMessageType(desc->full_name()),
converted_key_name, upbc_name, upb::generator::CApiMessageType(val->message_type()->full_name()),
optional_conversion_code, converted_key_name, upbc_name,
::upb::generator::MiniTableMessageVarName( ::upb::generator::MiniTableMessageVarName(
val->message_type()->full_name())); val->message_type()->full_name()));
ctx.EmitLegacy( ctx.EmitLegacy(
@ -337,9 +347,10 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), class_name, resolved_field_name, CppConstType(key),
MessagePtrConstType(val, /* is_const */ false), MessageName(message), MessagePtrConstType(val, /* is_const */ false),
MessageName(val->message_type()), optional_conversion_code, upb::generator::CApiMessageType(desc->full_name()),
converted_key_name, upbc_name, upb::generator::CApiMessageType(val->message_type()->full_name()),
optional_conversion_code, converted_key_name, upbc_name,
::upb::generator::MiniTableMessageVarName( ::upb::generator::MiniTableMessageVarName(
val->message_type()->full_name())); val->message_type()->full_name()));
ctx.EmitLegacy( ctx.EmitLegacy(
@ -350,9 +361,10 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), class_name, resolved_field_name, CppConstType(key),
MessagePtrConstType(val, /* is_const */ true), MessageName(message), MessagePtrConstType(val, /* is_const */ true),
MessageName(val->message_type()), optional_conversion_code, upb::generator::CApiMessageType(desc->full_name()),
converted_key_name, upbc_name); upb::generator::CApiMessageType(val->message_type()->full_name()),
optional_conversion_code, converted_key_name, upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
bool $0::set_alias_$1($2 key, $3 value) { bool $0::set_alias_$1($2 key, $3 value) {
@ -361,9 +373,10 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), class_name, resolved_field_name, CppConstType(key),
MessagePtrConstType(val, /* is_const */ false), MessageName(message), MessagePtrConstType(val, /* is_const */ false),
MessageName(val->message_type()), optional_conversion_code, upb::generator::CApiMessageType(desc->full_name()),
converted_key_name, upbc_name); upb::generator::CApiMessageType(val->message_type()->full_name()),
optional_conversion_code, converted_key_name, upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
absl::StatusOr<$3> $0::get_$1($2 key) { absl::StatusOr<$3> $0::get_$1($2 key) {
@ -376,8 +389,9 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), class_name, resolved_field_name, CppConstType(key),
MessagePtrConstType(val, /* is_const */ true), MessageName(message), MessagePtrConstType(val, /* is_const */ true),
MessageName(val->message_type()), upb::generator::CApiMessageType(desc->full_name()),
upb::generator::CApiMessageType(val->message_type()->full_name()),
QualifiedClassName(val->message_type()), optional_conversion_code, QualifiedClassName(val->message_type()), optional_conversion_code,
converted_key_name, upbc_name); converted_key_name, upbc_name);
ctx.Emit( ctx.Emit(
@ -385,8 +399,9 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
{"hpb_field_name", resolved_field_name}, {"hpb_field_name", resolved_field_name},
{"const_key", CppConstType(key)}, {"const_key", CppConstType(key)},
{"PtrMut", MessagePtrConstType(val, false)}, {"PtrMut", MessagePtrConstType(val, false)},
{"upb_msg_name", MessageName(message)}, {"upb_msg_name", upb::generator::CApiMessageType(desc->full_name())},
{"return_type", MessageName(val->message_type())}, {"return_type",
upb::generator::CApiMessageType(val->message_type()->full_name())},
{"proto_class", QualifiedClassName(val->message_type())}, {"proto_class", QualifiedClassName(val->message_type())},
{"optional_conversion_code", optional_conversion_code}, {"optional_conversion_code", optional_conversion_code},
{"converted_key_name", converted_key_name}, {"converted_key_name", converted_key_name},
@ -410,9 +425,10 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
void $0::delete_$1($2 key) { $6$4_$8_delete(msg_, $7); } void $0::delete_$1($2 key) { $6$4_$8_delete(msg_, $7); }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), class_name, resolved_field_name, CppConstType(key),
MessagePtrConstType(val, /* is_const */ false), MessageName(message), MessagePtrConstType(val, /* is_const */ false),
MessageName(val->message_type()), optional_conversion_code, upb::generator::CApiMessageType(desc->full_name()),
converted_key_name, upbc_name); upb::generator::CApiMessageType(val->message_type()->full_name()),
optional_conversion_code, converted_key_name, upbc_name);
} else if (val->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_STRING) { } else if (val->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_STRING) {
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
@ -423,8 +439,8 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), CppConstType(val), class_name, resolved_field_name, CppConstType(key), CppConstType(val),
MessageName(message), optional_conversion_code, converted_key_name, upb::generator::CApiMessageType(desc->full_name()),
upbc_name); optional_conversion_code, converted_key_name, upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
absl::StatusOr<$3> $0::get_$1($2 key) { absl::StatusOr<$3> $0::get_$1($2 key) {
@ -437,15 +453,15 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), CppConstType(val), class_name, resolved_field_name, CppConstType(key), CppConstType(val),
MessageName(message), optional_conversion_code, converted_key_name, upb::generator::CApiMessageType(desc->full_name()),
upbc_name); optional_conversion_code, converted_key_name, upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
void $0::delete_$1($2 key) { $5$4_$7_delete(msg_, $6); } void $0::delete_$1($2 key) { $5$4_$7_delete(msg_, $6); }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), CppConstType(val), class_name, resolved_field_name, CppConstType(key), CppConstType(val),
MessageName(message), optional_conversion_code, converted_key_name, upb::generator::CApiMessageType(desc->full_name()),
upbc_name); optional_conversion_code, converted_key_name, upbc_name);
} else { } else {
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
@ -454,8 +470,8 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), CppConstType(val), class_name, resolved_field_name, CppConstType(key), CppConstType(val),
MessageName(message), optional_conversion_code, converted_key_name, upb::generator::CApiMessageType(desc->full_name()),
upbc_name); optional_conversion_code, converted_key_name, upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
absl::StatusOr<$3> $0::get_$1($2 key) { absl::StatusOr<$3> $0::get_$1($2 key) {
@ -468,15 +484,15 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), CppConstType(val), class_name, resolved_field_name, CppConstType(key), CppConstType(val),
MessageName(message), optional_conversion_code, converted_key_name, upb::generator::CApiMessageType(desc->full_name()),
upbc_name); optional_conversion_code, converted_key_name, upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
void $0::delete_$1($2 key) { $5$4_$7_delete(msg_, $6); } void $0::delete_$1($2 key) { $5$4_$7_delete(msg_, $6); }
)cc", )cc",
class_name, resolved_field_name, CppConstType(key), CppConstType(val), class_name, resolved_field_name, CppConstType(key), CppConstType(val),
MessageName(message), optional_conversion_code, converted_key_name, upb::generator::CApiMessageType(desc->full_name()),
upbc_name); optional_conversion_code, converted_key_name, upbc_name);
} }
} }

@ -22,6 +22,7 @@
#include "google/protobuf/compiler/hpb/gen_utils.h" #include "google/protobuf/compiler/hpb/gen_utils.h"
#include "google/protobuf/compiler/hpb/names.h" #include "google/protobuf/compiler/hpb/names.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "upb_generator/c/names.h"
#include "upb_generator/minitable/names.h" #include "upb_generator/minitable/names.h"
namespace google::protobuf::hpb_generator { namespace google::protobuf::hpb_generator {
@ -101,7 +102,8 @@ void WriteModelAccessDeclaration(const protobuf::Descriptor* descriptor,
assert(arena != nullptr); assert(arena != nullptr);
} // NOLINT } // NOLINT
)cc", )cc",
ClassName(descriptor), MessageName(descriptor)); ClassName(descriptor),
upb::generator::CApiMessageType(descriptor->full_name()));
WriteFieldAccessorsInHeader(descriptor, ctx); WriteFieldAccessorsInHeader(descriptor, ctx);
WriteOneofAccessorsInHeader(descriptor, ctx); WriteOneofAccessorsInHeader(descriptor, ctx);
ctx.EmitLegacy( ctx.EmitLegacy(
@ -114,7 +116,8 @@ void WriteModelAccessDeclaration(const protobuf::Descriptor* descriptor,
$1* msg_; $1* msg_;
upb_Arena* arena_; upb_Arena* arena_;
)cc", )cc",
ClassName(descriptor), MessageName(descriptor), ClassName(descriptor),
upb::generator::CApiMessageType(descriptor->full_name()),
QualifiedClassName(descriptor)); QualifiedClassName(descriptor));
ctx.Emit("};\n"); ctx.Emit("};\n");
} }
@ -203,7 +206,8 @@ void WriteModelPublicDeclaration(
)cc", )cc",
ClassName(descriptor), ClassName(descriptor),
::upb::generator::MiniTableMessageVarName(descriptor->full_name()), ::upb::generator::MiniTableMessageVarName(descriptor->full_name()),
MessageName(descriptor), QualifiedClassName(descriptor)); upb::generator::CApiMessageType(descriptor->full_name()),
QualifiedClassName(descriptor));
WriteUsingAccessorsInHeader(descriptor, MessageClassType::kMessage, ctx); WriteUsingAccessorsInHeader(descriptor, MessageClassType::kMessage, ctx);
WriteUsingEnumsInHeader(descriptor, file_enums, ctx); WriteUsingEnumsInHeader(descriptor, file_enums, ctx);
@ -252,7 +256,8 @@ void WriteModelPublicDeclaration(
friend $0(hpb::interop::upb::MoveMessage<$0>(upb_Message* msg, friend $0(hpb::interop::upb::MoveMessage<$0>(upb_Message* msg,
upb_Arena* arena)); upb_Arena* arena));
)cc", )cc",
ClassName(descriptor), MessageName(descriptor), ClassName(descriptor),
upb::generator::CApiMessageType(descriptor->full_name()),
QualifiedClassName(descriptor)); QualifiedClassName(descriptor));
ctx.Emit("};\n\n"); ctx.Emit("};\n\n");
} }
@ -312,7 +317,8 @@ void WriteModelProxyDeclaration(const protobuf::Descriptor* descriptor,
lhs.arena_ = rhs.arena_; lhs.arena_ = rhs.arena_;
} }
)cc", )cc",
ClassName(descriptor), MessageName(descriptor), ClassName(descriptor),
upb::generator::CApiMessageType(descriptor->full_name()),
QualifiedClassName(descriptor)); QualifiedClassName(descriptor));
ctx.Emit("};\n\n"); ctx.Emit("};\n\n");
} }
@ -329,7 +335,8 @@ void WriteModelCProxyDeclaration(const protobuf::Descriptor* descriptor,
: internal::$0Access(m->msg_, hpb::interop::upb::GetArena(m)) {} : internal::$0Access(m->msg_, hpb::interop::upb::GetArena(m)) {}
$0CProxy($0Proxy m); $0CProxy($0Proxy m);
)cc", )cc",
ClassName(descriptor), MessageName(descriptor)); ClassName(descriptor),
upb::generator::CApiMessageType(descriptor->full_name()));
WriteUsingAccessorsInHeader(descriptor, MessageClassType::kMessageCProxy, WriteUsingAccessorsInHeader(descriptor, MessageClassType::kMessageCProxy,
ctx); ctx);
@ -358,7 +365,8 @@ void WriteModelCProxyDeclaration(const protobuf::Descriptor* descriptor,
lhs.arena_ = rhs.arena_; lhs.arena_ = rhs.arena_;
} }
)cc", )cc",
ClassName(descriptor), MessageName(descriptor)); ClassName(descriptor),
upb::generator::CApiMessageType(descriptor->full_name()));
ctx.Emit("};\n\n"); ctx.Emit("};\n\n");
} }
@ -407,7 +415,8 @@ void WriteMessageImplementation(
return *this; return *this;
} }
)cc", )cc",
ClassName(descriptor), MessageName(descriptor), ClassName(descriptor),
upb::generator::CApiMessageType(descriptor->full_name()),
::upb::generator::MiniTableMessageVarName(descriptor->full_name()), ::upb::generator::MiniTableMessageVarName(descriptor->full_name()),
QualifiedClassName(descriptor)); QualifiedClassName(descriptor));
ctx.Emit("\n"); ctx.Emit("\n");
@ -436,7 +445,8 @@ void WriteMessageImplementation(
} }
$0DefaultTypeInternal _$0_default_instance_ = _$0DefaultTypeBuilder(); $0DefaultTypeInternal _$0_default_instance_ = _$0DefaultTypeBuilder();
)cc", )cc",
ClassName(descriptor), MessageName(descriptor)); ClassName(descriptor),
upb::generator::CApiMessageType(descriptor->full_name()));
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(

@ -81,7 +81,8 @@ void WriteRepeatedFieldsInMessageHeader(const protobuf::Descriptor* desc,
return len; return len;
} }
)cc", )cc",
MessageName(desc), resolved_field_name, resolved_upbc_name); upb::generator::CApiMessageType(desc->full_name()), resolved_field_name,
resolved_upbc_name);
if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) { if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {
ctx.EmitLegacy( ctx.EmitLegacy(
@ -129,7 +130,7 @@ void WriteRepeatedFieldsInMessageHeader(const protobuf::Descriptor* desc,
} }
} }
void WriteRepeatedMessageAccessor(const protobuf::Descriptor* message, void WriteRepeatedMessageAccessor(const protobuf::Descriptor* desc,
const protobuf::FieldDescriptor* field, const protobuf::FieldDescriptor* field,
const absl::string_view resolved_field_name, const absl::string_view resolved_field_name,
const absl::string_view class_name, const absl::string_view class_name,
@ -147,7 +148,7 @@ void WriteRepeatedMessageAccessor(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, MessagePtrConstType(field, /* is_const */ true), class_name, MessagePtrConstType(field, /* is_const */ true),
resolved_field_name, MessageName(message), resolved_field_name, upb::generator::CApiMessageType(desc->full_name()),
MessageBaseType(field, /* maybe_const */ false), upbc_name); MessageBaseType(field, /* maybe_const */ false), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
@ -172,9 +173,9 @@ void WriteRepeatedMessageAccessor(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, MessagePtrConstType(field, /* const */ false), class_name, MessagePtrConstType(field, /* const */ false),
resolved_field_name, MessageName(message), resolved_field_name, upb::generator::CApiMessageType(desc->full_name()),
MessageBaseType(field, /* maybe_const */ false), arena_expression, MessageBaseType(field, /* maybe_const */ false), arena_expression,
upbc_name, ClassName(message), field->index(), upbc_name, ClassName(desc), field->index(),
upb::generator::CApiMessageType(field->message_type()->full_name())); upb::generator::CApiMessageType(field->message_type()->full_name()));
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
@ -186,7 +187,7 @@ void WriteRepeatedMessageAccessor(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, MessagePtrConstType(field, /* is_const */ false), class_name, MessagePtrConstType(field, /* is_const */ false),
resolved_field_name, MessageName(message), resolved_field_name, upb::generator::CApiMessageType(desc->full_name()),
MessageBaseType(field, /* maybe_const */ false), arena_expression, MessageBaseType(field, /* maybe_const */ false), arena_expression,
upbc_name); upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
@ -205,14 +206,14 @@ void WriteRepeatedMessageAccessor(const protobuf::Descriptor* message,
class_name, // $0 class_name, // $0
MessageBaseType(field, /* maybe_const */ false), // $1 MessageBaseType(field, /* maybe_const */ false), // $1
resolved_field_name, // $2 resolved_field_name, // $2
MessageName(message), // $3 upb::generator::CApiMessageType(desc->full_name()), // $3
upbc_name, // $4 upbc_name, // $4
upb::generator::kRepeatedFieldArrayGetterPostfix, // $5 upb::generator::kRepeatedFieldArrayGetterPostfix, // $5
upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6 upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6
); );
} }
void WriteRepeatedStringAccessor(const protobuf::Descriptor* message, void WriteRepeatedStringAccessor(const protobuf::Descriptor* desc,
const protobuf::FieldDescriptor* field, const protobuf::FieldDescriptor* field,
const absl::string_view resolved_field_name, const absl::string_view resolved_field_name,
const absl::string_view class_name, const absl::string_view class_name,
@ -228,14 +229,15 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,
MessageName(message), upbc_name); upb::generator::CApiMessageType(desc->full_name()), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
bool $0::resize_$1(size_t len) { bool $0::resize_$1(size_t len) {
return $2_resize_$3(msg_, len, arena_); return $2_resize_$3(msg_, len, arena_);
} }
)cc", )cc",
class_name, resolved_field_name, MessageName(message), upbc_name); class_name, resolved_field_name,
upb::generator::CApiMessageType(desc->full_name()), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
bool $0::add_$2($1 val) { bool $0::add_$2($1 val) {
@ -245,7 +247,7 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,
MessageName(message), upbc_name); upb::generator::CApiMessageType(desc->full_name()), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
void $0::set_$2(size_t index, $1 val) { void $0::set_$2(size_t index, $1 val) {
@ -256,7 +258,7 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,
MessageName(message), upbc_name); upb::generator::CApiMessageType(desc->full_name()), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
const ::hpb::RepeatedField<$1>::CProxy $0::$2() const { const ::hpb::RepeatedField<$1>::CProxy $0::$2() const {
@ -273,14 +275,14 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message,
class_name, // $0 class_name, // $0
CppConstType(field), // $1 CppConstType(field), // $1
resolved_field_name, // $2 resolved_field_name, // $2
MessageName(message), // $3 upb::generator::CApiMessageType(desc->full_name()), // $3
upbc_name, // $4 upbc_name, // $4
upb::generator::kRepeatedFieldArrayGetterPostfix, // $5 upb::generator::kRepeatedFieldArrayGetterPostfix, // $5
upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6 upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6
); );
} }
void WriteRepeatedScalarAccessor(const protobuf::Descriptor* message, void WriteRepeatedScalarAccessor(const protobuf::Descriptor* desc,
const protobuf::FieldDescriptor* field, const protobuf::FieldDescriptor* field,
const absl::string_view resolved_field_name, const absl::string_view resolved_field_name,
const absl::string_view class_name, const absl::string_view class_name,
@ -296,20 +298,21 @@ void WriteRepeatedScalarAccessor(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,
MessageName(message), upbc_name); upb::generator::CApiMessageType(desc->full_name()), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
bool $0::resize_$1(size_t len) { bool $0::resize_$1(size_t len) {
return $2_resize_$3(msg_, len, arena_); return $2_resize_$3(msg_, len, arena_);
} }
)cc", )cc",
class_name, resolved_field_name, MessageName(message), upbc_name); class_name, resolved_field_name,
upb::generator::CApiMessageType(desc->full_name()), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
bool $0::add_$2($1 val) { return $3_add_$4(msg_, val, arena_); } bool $0::add_$2($1 val) { return $3_add_$4(msg_, val, arena_); }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,
MessageName(message), upbc_name); upb::generator::CApiMessageType(desc->full_name()), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
void $0::set_$2(size_t index, $1 val) { void $0::set_$2(size_t index, $1 val) {
@ -320,7 +323,7 @@ void WriteRepeatedScalarAccessor(const protobuf::Descriptor* message,
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,
MessageName(message), upbc_name); upb::generator::CApiMessageType(desc->full_name()), upbc_name);
ctx.EmitLegacy( ctx.EmitLegacy(
R"cc( R"cc(
const ::hpb::RepeatedField<$1>::CProxy $0::$2() const { const ::hpb::RepeatedField<$1>::CProxy $0::$2() const {
@ -337,7 +340,7 @@ void WriteRepeatedScalarAccessor(const protobuf::Descriptor* message,
class_name, // $0 class_name, // $0
CppConstType(field), // $1 CppConstType(field), // $1
resolved_field_name, // $2 resolved_field_name, // $2
MessageName(message), // $3 upb::generator::CApiMessageType(desc->full_name()), // $3
upbc_name, // $4 upbc_name, // $4
upb::generator::kRepeatedFieldArrayGetterPostfix, // $5 upb::generator::kRepeatedFieldArrayGetterPostfix, // $5
upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6 upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6

Loading…
Cancel
Save