Cleanup map entry code generation to use a simple Emit.

Also, fix public/private sections. It has no visible effect because these types are internal, though.

PiperOrigin-RevId: 648806976
pull/17309/head
Protobuf Team Bot 5 months ago committed by Copybara-Service
parent 8d1efddeb6
commit 550e428239
  1. 40
      src/google/protobuf/compiler/cpp/message.cc
  2. 2
      src/google/protobuf/compiler/cpp/message.h

@ -1257,6 +1257,12 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) {
GenerateOneofHasBits(p); GenerateOneofHasBits(p);
} }
void MessageGenerator::GenerateVerifyDecl(io::Printer* p) {
}
void MessageGenerator::GenerateAnnotationDecl(io::Printer* p) {
}
void MessageGenerator::GenerateMapEntryClassDefinition(io::Printer* p) { void MessageGenerator::GenerateMapEntryClassDefinition(io::Printer* p) {
Formatter format(p); Formatter format(p);
absl::flat_hash_map<absl::string_view, std::string> vars; absl::flat_hash_map<absl::string_view, std::string> vars;
@ -1265,7 +1271,14 @@ void MessageGenerator::GenerateMapEntryClassDefinition(io::Printer* p) {
auto v = p->WithVars(std::move(vars)); auto v = p->WithVars(std::move(vars));
// Templatize constexpr constructor as a workaround for a bug in gcc 12 // Templatize constexpr constructor as a workaround for a bug in gcc 12
// (warning in gcc 13). // (warning in gcc 13).
p->Emit(R"cc( p->Emit(
{{"decl_verify_func",
[&] {
}},
{"decl_annotate", [&] { GenerateAnnotationDecl(p); }},
{"parse_decls",
[&] { parse_function_generator_->GenerateDataDecls(p); }}},
R"cc(
class $classname$ final class $classname$ final
: public ::$proto_ns$::internal::MapEntry< : public ::$proto_ns$::internal::MapEntry<
$classname$, $key_cpp$, $val_cpp$, $classname$, $key_cpp$, $val_cpp$,
@ -1285,15 +1298,18 @@ void MessageGenerator::GenerateMapEntryClassDefinition(io::Printer* p) {
return reinterpret_cast<const $classname$*>( return reinterpret_cast<const $classname$*>(
&_$classname$_default_instance_); &_$classname$_default_instance_);
} }
)cc");
parse_function_generator_->GenerateDataDecls(p); $decl_verify_func$;
p->Emit(R"cc(
private:
$parse_decls$;
$decl_annotate$;
const $superclass$::ClassData* GetClassData() const PROTOBUF_FINAL; const $superclass$::ClassData* GetClassData() const PROTOBUF_FINAL;
static const $superclass$::ClassDataFull _class_data_; static const $superclass$::ClassDataFull _class_data_;
friend struct ::$tablename$;
};
)cc"); )cc");
format(
" friend struct ::$tablename$;\n"
"};\n");
} }
void MessageGenerator::GenerateImplDefinition(io::Printer* p) { void MessageGenerator::GenerateImplDefinition(io::Printer* p) {
@ -1597,12 +1613,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
~$classname$() PROTOBUF_FINAL; ~$classname$() PROTOBUF_FINAL;
)cc"); )cc");
}}, }},
{"decl_annotate", {"decl_annotate", [&] { GenerateAnnotationDecl(p); }},
[&] { {"decl_verify_func", [&] { GenerateVerifyDecl(p); }},
}},
{"decl_verify_func",
[&] {
}},
{"descriptor_accessor", {"descriptor_accessor",
[&] { [&] {
// Only generate this member if it's not disabled. // Only generate this member if it's not disabled.
@ -1953,7 +1965,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
} }
return *this; return *this;
} }
$decl_annotate$;
$decl_verify_func$; $decl_verify_func$;
inline const $unknown_fields_type$& unknown_fields() const inline const $unknown_fields_type$& unknown_fields() const
@ -2013,6 +2024,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
private: private:
friend class ::$proto_ns$::internal::AnyMetadata; friend class ::$proto_ns$::internal::AnyMetadata;
static ::absl::string_view FullMessageName() { return "$full_name$"; } static ::absl::string_view FullMessageName() { return "$full_name$"; }
$decl_annotate$;
//~ TODO Make this private! Currently people are //~ TODO Make this private! Currently people are
//~ deriving from protos to give access to this constructor, //~ deriving from protos to give access to this constructor,

@ -116,7 +116,9 @@ class MessageGenerator {
// Generate standard Message methods. // Generate standard Message methods.
void GenerateClear(io::Printer* p); void GenerateClear(io::Printer* p);
void GenerateOneofClear(io::Printer* p); void GenerateOneofClear(io::Printer* p);
void GenerateVerifyDecl(io::Printer* p);
void GenerateVerify(io::Printer* p); void GenerateVerify(io::Printer* p);
void GenerateAnnotationDecl(io::Printer* p);
void GenerateSerializeWithCachedSizes(io::Printer* p); void GenerateSerializeWithCachedSizes(io::Printer* p);
void GenerateSerializeWithCachedSizesToArray(io::Printer* p); void GenerateSerializeWithCachedSizesToArray(io::Printer* p);
void GenerateSerializeWithCachedSizesBody(io::Printer* p); void GenerateSerializeWithCachedSizesBody(io::Printer* p);

Loading…
Cancel
Save