Incremental migration of message.cc to Emit

PiperOrigin-RevId: 531238423
pull/12764/head
Matt Kulukundis 2 years ago committed by Copybara-Service
parent ef39d27a0f
commit fc01c2ec56
  1. 17
      src/google/protobuf/compiler/cpp/field.cc
  2. 31
      src/google/protobuf/compiler/cpp/field_generators/cord_field.cc
  3. 19
      src/google/protobuf/compiler/cpp/field_generators/enum_field.cc
  4. 16
      src/google/protobuf/compiler/cpp/field_generators/map_field.cc
  5. 14
      src/google/protobuf/compiler/cpp/field_generators/message_field.cc
  6. 28
      src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc
  7. 23
      src/google/protobuf/compiler/cpp/field_generators/string_field.cc
  8. 305
      src/google/protobuf/compiler/cpp/message.cc
  9. 166
      src/google/protobuf/compiler/plugin.pb.cc
  10. 1378
      src/google/protobuf/descriptor.pb.cc

@ -39,7 +39,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
@ -112,18 +111,22 @@ std::vector<Sub> FieldVars(const FieldDescriptor* field, const Options& opts) {
} }
void FieldGeneratorBase::GenerateAggregateInitializer(io::Printer* p) const { void FieldGeneratorBase::GenerateAggregateInitializer(io::Printer* p) const {
Formatter format(p, variables_);
if (ShouldSplit(descriptor_, options_)) { if (ShouldSplit(descriptor_, options_)) {
format("decltype(Impl_::Split::$name$_){arena}"); p->Emit(R"cc(
return; decltype(Impl_::Split::$name$_){arena},
)cc");
} else {
p->Emit(R"cc(
decltype($field$){arena},
)cc");
} }
format("decltype($field$){arena}");
} }
void FieldGeneratorBase::GenerateConstexprAggregateInitializer( void FieldGeneratorBase::GenerateConstexprAggregateInitializer(
io::Printer* p) const { io::Printer* p) const {
Formatter format(p, variables_); p->Emit(R"cc(
format("/*decltype($field$)*/{}"); /*decltype($field$)*/ {},
)cc");
} }
void FieldGeneratorBase::GenerateCopyAggregateInitializer( void FieldGeneratorBase::GenerateCopyAggregateInitializer(

@ -263,26 +263,31 @@ void CordFieldGenerator::GenerateByteSize(io::Printer* printer) const {
} }
void CordFieldGenerator::GenerateConstexprAggregateInitializer( void CordFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const { io::Printer* p) const {
Formatter format(printer, variables_);
if (descriptor_->default_value_string().empty()) { if (descriptor_->default_value_string().empty()) {
format("/*decltype($field$)*/{}"); p->Emit(R"cc(
/*decltype($field$)*/ {},
)cc");
} else { } else {
format( p->Emit(
"/*decltype($field$)*/{::absl::strings_internal::MakeStringConstant(\n" {{"Split", ShouldSplit(descriptor_, options_) ? "Split::" : ""}},
" $classname$::Impl_::$1$_default_$name$_func_{})}", R"cc(
ShouldSplit(descriptor_, options_) ? "Split::" : ""); /*decltype($field$)*/ {::absl::strings_internal::MakeStringConstant(
$classname$::Impl_::$Split$_default_$name$_func_{})},
)cc");
} }
} }
void CordFieldGenerator::GenerateAggregateInitializer( void CordFieldGenerator::GenerateAggregateInitializer(io::Printer* p) const {
io::Printer* printer) const {
Formatter format(printer, variables_);
if (ShouldSplit(descriptor_, options_)) { if (ShouldSplit(descriptor_, options_)) {
format("decltype(Impl_::Split::$name$_){}"); p->Emit(R"cc(
return; decltype(Impl_::Split::$name$_){},
)cc");
} else {
p->Emit(R"cc(
decltype($field$){},
)cc");
} }
format("decltype($field$){}");
} }
// =================================================================== // ===================================================================

@ -140,22 +140,21 @@ class SingularEnum : public FieldGeneratorBase {
void GenerateConstexprAggregateInitializer(io::Printer* p) const override { void GenerateConstexprAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc( p->Emit(R"cc(
/*decltype($field_$)*/ $kDefault$ /*decltype($field_$)*/ $kDefault$,
)cc"); )cc");
} }
void GenerateAggregateInitializer(io::Printer* p) const override { void GenerateAggregateInitializer(io::Printer* p) const override {
if (ShouldSplit(descriptor_, options_)) { if (ShouldSplit(descriptor_, options_)) {
p->Emit(R"cc( p->Emit(R"cc(
decltype(Impl_::Split::$name$_) { $kDefault$ } decltype(Impl_::Split::$name$_){$kDefault$},
)cc"); )cc");
return; } else {
}
p->Emit(R"cc( p->Emit(R"cc(
decltype($field_$) { $kDefault$ } decltype($field_$){$kDefault$},
)cc"); )cc");
} }
}
void GenerateCopyAggregateInitializer(io::Printer* p) const override { void GenerateCopyAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc( p->Emit(R"cc(
@ -284,24 +283,24 @@ class RepeatedEnum : public FieldGeneratorBase {
void GenerateConstexprAggregateInitializer(io::Printer* p) const override { void GenerateConstexprAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc( p->Emit(R"cc(
/*decltype($field_$)*/ {} /*decltype($field_$)*/ {},
)cc"); )cc");
if (has_cached_size_) { if (has_cached_size_) {
p->Emit(R"cc( p->Emit(R"cc(
, /*decltype($cached_size_$)*/ { 0 } /*decltype($cached_size_$)*/ {0},
)cc"); )cc");
} }
} }
void GenerateAggregateInitializer(io::Printer* p) const override { void GenerateAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc( p->Emit(R"cc(
decltype($field_$) { arena } decltype($field_$){arena},
)cc"); )cc");
if (has_cached_size_) { if (has_cached_size_) {
// std::atomic has no copy constructor, which prevents explicit aggregate // std::atomic has no copy constructor, which prevents explicit aggregate
// initialization pre-C++17. // initialization pre-C++17.
p->Emit(R"cc( p->Emit(R"cc(
, /*decltype($cached_size_$)*/ { 0 } /*decltype($cached_size_$)*/ {0},
)cc"); )cc");
} }
} }

@ -127,7 +127,9 @@ class Map : public FieldGeneratorBase {
} }
void GenerateConstexprAggregateInitializer(io::Printer* p) const override { void GenerateConstexprAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc(/* decltype($field_$) */ {})cc"); p->Emit(R"cc(
/* decltype($field_$) */ {},
)cc");
} }
void GenerateCopyAggregateInitializer(io::Printer* p) const override { void GenerateCopyAggregateInitializer(io::Printer* p) const override {
@ -140,16 +142,16 @@ class Map : public FieldGeneratorBase {
if (ShouldSplit(field_, *opts_)) { if (ShouldSplit(field_, *opts_)) {
p->Emit(R"cc( p->Emit(R"cc(
/* decltype($Msg$::Split::$name$_) */ { /* decltype($Msg$::Split::$name$_) */ {
$pbi$::ArenaInitialized(), arena $pbi$::ArenaInitialized(),
} arena,
},
)cc"); )cc");
return; } else {
}
p->Emit(R"cc( p->Emit(R"cc(
/* decltype($field_$) */ { $pbi$::ArenaInitialized(), arena } /* decltype($field_$) */ {$pbi$::ArenaInitialized(), arena},
)cc"); )cc");
} }
}
void GenerateConstructorCode(io::Printer* p) const override {} void GenerateConstructorCode(io::Printer* p) const override {}

@ -501,7 +501,9 @@ void SingularMessage::GenerateIsInitialized(io::Printer* p) const {
void SingularMessage::GenerateConstexprAggregateInitializer( void SingularMessage::GenerateConstexprAggregateInitializer(
io::Printer* p) const { io::Printer* p) const {
p->Emit("/*decltype($field_$)*/nullptr"); p->Emit(R"cc(
/*decltype($field_$)*/ nullptr,
)cc");
} }
void SingularMessage::GenerateCopyAggregateInitializer(io::Printer* p) const { void SingularMessage::GenerateCopyAggregateInitializer(io::Printer* p) const {
@ -510,10 +512,14 @@ void SingularMessage::GenerateCopyAggregateInitializer(io::Printer* p) const {
void SingularMessage::GenerateAggregateInitializer(io::Printer* p) const { void SingularMessage::GenerateAggregateInitializer(io::Printer* p) const {
if (ShouldSplit(field_, *opts_)) { if (ShouldSplit(field_, *opts_)) {
p->Emit("decltype(Impl_::Split::$name$_){nullptr}"); p->Emit(R"cc(
return; decltype(Impl_::Split::$name$_){nullptr},
)cc");
} else {
p->Emit(R"cc(
decltype($field_$){nullptr},
)cc");
} }
p->Emit("decltype($field_$){nullptr}");
} }
class OneofMessage : public SingularMessage { class OneofMessage : public SingularMessage {

@ -167,13 +167,13 @@ class SingularPrimitive final : public FieldGeneratorBase {
void GenerateConstexprAggregateInitializer(io::Printer* p) const override { void GenerateConstexprAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc( p->Emit(R"cc(
/*decltype($field_$)*/ $kDefault$ /*decltype($field_$)*/ $kDefault$,
)cc"); )cc");
} }
void GenerateAggregateInitializer(io::Printer* p) const override { void GenerateAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc( p->Emit(R"cc(
decltype($field_$) { $kDefault$ } decltype($field_$){$kDefault$},
)cc"); )cc");
} }
@ -343,17 +343,17 @@ class RepeatedPrimitive final : public FieldGeneratorBase {
void GenerateConstexprAggregateInitializer(io::Printer* p) const override { void GenerateConstexprAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc( p->Emit(R"cc(
/*decltype($field_$)*/ {} /*decltype($field_$)*/ {},
)cc"); )cc");
InitCachedSize(p); GenerateCacheSizeInitializer(p);
} }
void GenerateAggregateInitializer(io::Printer* p) const override { void GenerateAggregateInitializer(io::Printer* p) const override {
ABSL_CHECK(!ShouldSplit(descriptor_, options_)); ABSL_CHECK(!ShouldSplit(descriptor_, options_));
p->Emit(R"cc( p->Emit(R"cc(
decltype($field_$) { arena } decltype($field_$){arena},
)cc"); )cc");
InitCachedSize(p); GenerateCacheSizeInitializer(p);
} }
void GenerateCopyAggregateInitializer(io::Printer* p) const override { void GenerateCopyAggregateInitializer(io::Printer* p) const override {
@ -361,7 +361,13 @@ class RepeatedPrimitive final : public FieldGeneratorBase {
p->Emit(R"cc( p->Emit(R"cc(
decltype($field_$) { from.$field_$ } decltype($field_$) { from.$field_$ }
)cc"); )cc");
InitCachedSize(p); if (HasCachedSize()) {
// std::atomic has no move constructor, which prevents explicit aggregate
// initialization pre-C++17.
p->Emit(R"cc(
, /* $_field_cached_byte_size_$ = */ { 0 }
)cc");
}
} }
void GeneratePrivateMembers(io::Printer* p) const override; void GeneratePrivateMembers(io::Printer* p) const override;
@ -377,13 +383,13 @@ class RepeatedPrimitive final : public FieldGeneratorBase {
return is_packed_varint && HasGeneratedMethods(field_->file(), *opts_); return is_packed_varint && HasGeneratedMethods(field_->file(), *opts_);
} }
void InitCachedSize(io::Printer* p) const { void GenerateCacheSizeInitializer(io::Printer* p) const {
if (!HasCachedSize()) return; if (!HasCachedSize()) return;
// std::atomic has no move constructor, which prevents explicit aggregate // std::atomic has no move constructor, which prevents explicit aggregate
// initialization pre-C++17. // initialization pre-C++17.
p->Emit(R"( p->Emit(R"cc(
,/* $_field_cached_byte_size_$ = */ { 0 } /* $_field_cached_byte_size_$ = */ {0},
)"); )cc");
} }
const FieldDescriptor* field_; const FieldDescriptor* field_;

@ -665,34 +665,31 @@ void SingularString::GenerateConstexprAggregateInitializer(
io::Printer* p) const { io::Printer* p) const {
if (inlined_) { if (inlined_) {
p->Emit(R"cc( p->Emit(R"cc(
/*decltype($field_$)*/ { nullptr, false } /*decltype($field_$)*/ {nullptr, false},
)cc"); )cc");
return; } else {
}
p->Emit(R"cc( p->Emit(R"cc(
/*decltype($field_$)*/ { /*decltype($field_$)*/ {
&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} &::_pbi::fixed_address_empty_string,
} ::_pbi::ConstantInitialized{},
},
)cc"); )cc");
}
} }
void SingularString::GenerateAggregateInitializer(io::Printer* p) const { void SingularString::GenerateAggregateInitializer(io::Printer* p) const {
if (ShouldSplit(field_, options_)) { if (ShouldSplit(field_, options_)) {
ABSL_CHECK(!inlined_); ABSL_CHECK(!inlined_);
p->Emit(R"cc( p->Emit(R"cc(
decltype(Impl_::Split::$name$_) {} decltype(Impl_::Split::$name$_){},
)cc"); )cc");
return; } else if (!inlined_) {
}
if (!inlined_) {
p->Emit(R"cc( p->Emit(R"cc(
decltype($field_$) {} decltype($field_$){},
)cc"); )cc");
} else { } else {
p->Emit(R"cc( p->Emit(R"cc(
decltype($field_$) { arena } decltype($field_$){arena},
)cc"); )cc");
} }
} }

@ -2220,39 +2220,33 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets(io::Printer* p) {
void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) { void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) {
if (HasSimpleBaseClass(descriptor_, options_)) return; if (HasSimpleBaseClass(descriptor_, options_)) return;
Formatter format(p);
format(
"inline void $classname$::SharedCtor(::_pb::Arena* arena) {\n"
" (void)arena;\n");
format.Indent();
// Impl_ _impl_.
format("new (&_impl_) Impl_{");
format.Indent();
const char* field_sep = " ";
const auto put_sep = [&] {
format("\n$1$ ", field_sep);
field_sep = ",";
};
// Note: any fields without move/copy constructors can't be explicitly p->Emit(
// aggregate initialized pre-C++17. {
{"impl_init",
[&] {
// Note: any fields without move/copy constructors can't be
// explicitly aggregate initialized pre-C++17.
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
put_sep(); p->Emit(R"cc(
format("/*decltype($extensions$)*/{::_pbi::ArenaInitialized(), arena}"); /*decltype($extensions$)*/ {::_pbi::ArenaInitialized(), arena},
)cc");
} }
if (!inlined_string_indices_.empty()) { if (!inlined_string_indices_.empty()) {
put_sep(); p->Emit(R"cc(
format("decltype($inlined_string_donated_array$){}"); decltype($inlined_string_donated_array$){},
)cc");
} }
bool need_to_emit_cached_size = !HasSimpleBaseClass(descriptor_, options_); bool need_to_emit_cached_size =
!HasSimpleBaseClass(descriptor_, options_);
if (!has_bit_indices_.empty()) { if (!has_bit_indices_.empty()) {
put_sep(); p->Emit(R"cc(
format("decltype($has_bits$){}"); decltype($has_bits$){},
)cc");
if (need_to_emit_cached_size) { if (need_to_emit_cached_size) {
put_sep(); p->Emit(R"cc(
format("/*decltype($cached_size$)*/{}"); /*decltype($cached_size$)*/ {},
)cc");
need_to_emit_cached_size = false; need_to_emit_cached_size = false;
} }
} }
@ -2262,87 +2256,126 @@ void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) {
if (ShouldSplit(field, options_)) { if (ShouldSplit(field, options_)) {
continue; continue;
} }
put_sep();
field_generators_.get(field).GenerateAggregateInitializer(p); field_generators_.get(field).GenerateAggregateInitializer(p);
} }
if (ShouldSplit(descriptor_, options_)) { if (ShouldSplit(descriptor_, options_)) {
put_sep(); // We can't assign the default split to this->split without the
// We can't assign the default split to this->split without the const_cast // const_cast because the former is a const. The const_cast is
// because the former is a const. The const_cast is safe because we don't // safe because we don't intend to modify the default split
// intend to modify the default split through this pointer, and we also // through this pointer, and we also expect the default split to
// expect the default split to be in the rodata section which is protected // be in the rodata section which is protected from mutation.
// from mutation. p->Emit(
format( {{"instance", DefaultInstanceName(descriptor_, options_,
"decltype($split$){const_cast<Impl_::Split*>" /*split=*/true)}},
"(reinterpret_cast<const Impl_::Split*>(&$1$))}", R"cc(
DefaultInstanceName(descriptor_, options_, /*split=*/true)); decltype($split$){const_cast<Impl_::Split*>(
reinterpret_cast<const Impl_::Split*>(&$instance$))},
)cc");
} }
for (auto oneof : OneOfRange(descriptor_)) { for (auto oneof : OneOfRange(descriptor_)) {
put_sep(); p->Emit({{"name", oneof->name()}},
format("decltype(_impl_.$1$_){}", oneof->name()); R"cc(
decltype(_impl_.$name$_){},
)cc");
} }
if (need_to_emit_cached_size) { if (need_to_emit_cached_size) {
put_sep(); p->Emit(R"cc(
format("/*decltype($cached_size$)*/{}"); /*decltype($cached_size$)*/ {},
)cc");
} }
if (descriptor_->real_oneof_decl_count() != 0) { if (descriptor_->real_oneof_decl_count() != 0) {
put_sep(); p->Emit(R"cc(
format("/*decltype($oneof_case$)*/{}"); /*decltype($oneof_case$)*/ {},
)cc");
} }
if (num_weak_fields_ > 0) { if (num_weak_fields_ > 0) {
put_sep(); p->Emit(R"cc(
format("decltype($weak_field_map$){arena}"); decltype($weak_field_map$){arena},
)cc");
} }
if (IsAnyMessage(descriptor_, options_)) { if (IsAnyMessage(descriptor_, options_)) {
put_sep();
// AnyMetadata has no move constructor. // AnyMetadata has no move constructor.
format("/*decltype($any_metadata$)*/{&_impl_.type_url_, &_impl_.value_}"); p->Emit(R"cc(
/*decltype($any_metadata$)*/ {&_impl_.type_url_,
&_impl_.value_},
)cc");
} }
}},
format.Outdent(); {"inlined_strings_init",
format("\n};\n"); [&] {
if (inlined_string_indices_.empty()) return;
if (!inlined_string_indices_.empty()) {
// Donate inline string fields. // Donate inline string fields.
format.Indent(); // The last bit is the tracking bit for registering ArenaDtor. The
// The last bit is the tracking bit for registering ArenaDtor. The bit is 1 // bit is 1 means ArenaDtor is not registered on construction, and
// means ArenaDtor is not registered on construction, and on demand register // on demand register is needed.
// is needed. p->Emit(
format("if (arena != nullptr) {\n"); {
if (NeedsArenaDestructor() == ArenaDtorNeeds::kOnDemand) { {"mask",
format(" $inlined_string_donated_array$[0] = ~0u;\n"); NeedsArenaDestructor() == ArenaDtorNeeds::kOnDemand
} else { ? "~0u"
format(" $inlined_string_donated_array$[0] = 0xFFFFFFFEu;\n"); : "0xFFFFFFFEu"},
} {"init_body",
for (size_t i = 1; i < InlinedStringDonatedSize(); ++i) { [&] {
format(" $inlined_string_donated_array$[$1$] = ~0u;\n", i); for (size_t i = 1; i < InlinedStringDonatedSize();
++i) {
p->Emit({{"i", i}},
R"cc(
$inlined_string_donated_array$[$i$] = ~0u;
)cc");
} }
format("}\n"); }},
format.Outdent(); },
R"cc(
if (arena != nullptr) {
$inlined_string_donated_array$[0] = $mask$;
$init_body$;
} }
)cc");
}},
{"field_ctor_code",
[&] {
for (const FieldDescriptor* field : optimized_order_) { for (const FieldDescriptor* field : optimized_order_) {
if (ShouldSplit(field, options_)) { if (ShouldSplit(field, options_)) {
continue; continue;
} }
field_generators_.get(field).GenerateConstructorCode(p); field_generators_.get(field).GenerateConstructorCode(p);
} }
}},
if (ShouldForceAllocationOnConstruction(descriptor_, options_)) { {"force_allocation",
format( [&] {
"#ifdef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION\n" if (!ShouldForceAllocationOnConstruction(descriptor_, options_))
"$mutable_unknown_fields$;\n" return;
"#endif // PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION\n"); p->Emit(R"cc(
} //~ force alignment
#ifdef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION
$mutable_unknown_fields$;
#endif // PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION
)cc");
}},
{"clear_oneofs",
[&] {
for (auto oneof : OneOfRange(descriptor_)) { for (auto oneof : OneOfRange(descriptor_)) {
format("clear_has_$1$();\n", oneof->name()); p->Emit({{"name", oneof->name()}},
R"cc(
clear_has_$name$();
)cc");
} }
}},
format.Outdent(); },
format("}\n\n"); R"cc(
inline void $classname$::SharedCtor(::_pb::Arena* arena) {
(void)arena;
new (&_impl_) Impl_{
$impl_init$,
};
$inlined_strings_init$;
$field_ctor_code$;
$force_allocation$;
$clear_oneofs$;
}
)cc");
} }
void MessageGenerator::GenerateInitDefaultSplitInstance(io::Printer* p) { void MessageGenerator::GenerateInitDefaultSplitInstance(io::Printer* p) {
@ -2350,15 +2383,9 @@ void MessageGenerator::GenerateInitDefaultSplitInstance(io::Printer* p) {
auto v = p->WithVars(ClassVars(descriptor_, options_)); auto v = p->WithVars(ClassVars(descriptor_, options_));
auto t = p->WithVars(MakeTrackerCalls(descriptor_, options_)); auto t = p->WithVars(MakeTrackerCalls(descriptor_, options_));
Formatter format(p); p->Emit("\n");
const char* field_sep = " ";
const auto put_sep = [&] {
format("\n$1$ ", field_sep);
field_sep = ",";
};
for (const auto* field : optimized_order_) { for (const auto* field : optimized_order_) {
if (ShouldSplit(field, options_)) { if (ShouldSplit(field, options_)) {
put_sep();
field_generators_.get(field).GenerateConstexprAggregateInitializer(p); field_generators_.get(field).GenerateConstexprAggregateInitializer(p);
} }
} }
@ -2475,86 +2502,92 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) {
void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) { void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) {
auto v = p->WithVars(ClassVars(descriptor_, options_)); auto v = p->WithVars(ClassVars(descriptor_, options_));
auto t = p->WithVars(MakeTrackerCalls(descriptor_, options_)); auto t = p->WithVars(MakeTrackerCalls(descriptor_, options_));
auto c = p->WithVars({{"constexpr", "PROTOBUF_CONSTEXPR"}});
Formatter format(p); Formatter format(p);
if (IsMapEntryMessage(descriptor_) || !HasImplData(descriptor_, options_)) { if (IsMapEntryMessage(descriptor_) || !HasImplData(descriptor_, options_)) {
format( p->Emit(R"cc(
"PROTOBUF_CONSTEXPR $classname$::$classname$(\n" $constexpr$ $classname$::$classname$(::_pbi::ConstantInitialized) {}
" ::_pbi::ConstantInitialized) {}\n"); )cc");
return; return;
} }
format(
"PROTOBUF_CONSTEXPR $classname$::$classname$(\n"
" ::_pbi::ConstantInitialized)");
bool need_to_emit_cached_size = !HasSimpleBaseClass(descriptor_, options_); bool need_to_emit_cached_size = !HasSimpleBaseClass(descriptor_, options_);
format(": _impl_{"); p->Emit(
format.Indent(); {
const char* field_sep = " "; {"init_body",
const auto put_sep = [&] { [&] {
format("\n$1$ ", field_sep); p->Emit("\n");
field_sep = ","; auto indent = p->WithIndent();
};
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
put_sep(); p->Emit(R"cc(
format("/*decltype($extensions$)*/{}"); /*decltype($extensions$)*/ {},
)cc");
} }
if (!inlined_string_indices_.empty()) { if (!inlined_string_indices_.empty()) {
put_sep(); p->Emit(R"cc(
format("/*decltype($inlined_string_donated_array$)*/{}"); /*decltype($inlined_string_donated_array$)*/ {},
)cc");
} }
if (!has_bit_indices_.empty()) { if (!has_bit_indices_.empty()) {
put_sep(); p->Emit(R"cc(
format("/*decltype($has_bits$)*/{}"); /*decltype($has_bits$)*/ {},
)cc");
if (need_to_emit_cached_size) { if (need_to_emit_cached_size) {
put_sep(); p->Emit(R"cc(
format("/*decltype($cached_size$)*/{}"); /*decltype($cached_size$)*/ {},
)cc");
need_to_emit_cached_size = false; need_to_emit_cached_size = false;
} }
} }
for (auto field : optimized_order_) { for (auto* field : optimized_order_) {
if (ShouldSplit(field, options_)) { if (ShouldSplit(field, options_)) {
continue; continue;
} }
put_sep(); field_generators_.get(field)
field_generators_.get(field).GenerateConstexprAggregateInitializer(p); .GenerateConstexprAggregateInitializer(p);
} }
if (ShouldSplit(descriptor_, options_)) { if (ShouldSplit(descriptor_, options_)) {
put_sep(); p->Emit({{"name", DefaultInstanceName(descriptor_, options_,
format("/*decltype($split$)*/const_cast<Impl_::Split*>(&$1$._instance)", /*split=*/true)}},
DefaultInstanceName(descriptor_, options_, /*split=*/true)); R"cc(
/*decltype($split$)*/ const_cast<Impl_::Split*>(
&$name$._instance),
)cc");
} }
for (auto* oneof : OneOfRange(descriptor_)) {
for (auto oneof : OneOfRange(descriptor_)) { p->Emit({{"name", oneof->name()}},
put_sep(); R"cc(
format("/*decltype(_impl_.$1$_)*/{}", oneof->name()); /*decltype(_impl_.$name$_)*/ {},
)cc");
} }
if (need_to_emit_cached_size) { if (need_to_emit_cached_size) {
put_sep(); p->Emit(R"cc(
format("/*decltype($cached_size$)*/{}"); /*decltype($cached_size$)*/ {},
)cc");
} }
if (descriptor_->real_oneof_decl_count() != 0) { if (descriptor_->real_oneof_decl_count() != 0) {
put_sep(); p->Emit(R"cc(
format("/*decltype($oneof_case$)*/{}"); /*decltype($oneof_case$)*/ {},
)cc");
} }
if (num_weak_fields_) { if (num_weak_fields_) {
put_sep(); p->Emit(R"cc(
format("/*decltype($weak_field_map$)*/{}"); /*decltype($weak_field_map$)*/ {},
)cc");
} }
if (IsAnyMessage(descriptor_, options_)) { if (IsAnyMessage(descriptor_, options_)) {
put_sep(); p->Emit(R"cc(
format( /*decltype($any_metadata$)*/ {&_impl_.type_url_,
"/*decltype($any_metadata$)*/{&_impl_.type_url_, " &_impl_.value_},
"&_impl_.value_}"); )cc");
} }
}},
format.Outdent(); },
format("} {}\n"); R"cc(
$constexpr$ $classname$::$classname$(::_pbi::ConstantInitialized)
: _impl_{$init_body$} {}
)cc");
} }
void MessageGenerator::GenerateCopyConstructorBody(io::Printer* p) const { void MessageGenerator::GenerateCopyConstructorBody(io::Printer* p) const {

@ -21,20 +21,18 @@ namespace _pbi = ::google::protobuf::internal;
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace compiler { namespace compiler {
PROTOBUF_CONSTEXPR Version::Version( PROTOBUF_CONSTEXPR Version::Version(::_pbi::ConstantInitialized)
::_pbi::ConstantInitialized): _impl_{ : _impl_{
/*decltype(_impl_._has_bits_)*/{} /*decltype(_impl_._has_bits_)*/ {},
, /*decltype(_impl_._cached_size_)*/{} /*decltype(_impl_._cached_size_)*/ {},
, /*decltype(_impl_.suffix_)*/ { /*decltype(_impl_.suffix_)*/ {
&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} &::_pbi::fixed_address_empty_string,
} ::_pbi::ConstantInitialized{},
},
, /*decltype(_impl_.major_)*/ 0 /*decltype(_impl_.major_)*/ 0,
/*decltype(_impl_.minor_)*/ 0,
, /*decltype(_impl_.minor_)*/ 0 /*decltype(_impl_.patch_)*/ 0,
} {}
, /*decltype(_impl_.patch_)*/ 0
} {}
struct VersionDefaultTypeInternal { struct VersionDefaultTypeInternal {
PROTOBUF_CONSTEXPR VersionDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} PROTOBUF_CONSTEXPR VersionDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
~VersionDefaultTypeInternal() {} ~VersionDefaultTypeInternal() {}
@ -45,17 +43,18 @@ struct VersionDefaultTypeInternal {
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 VersionDefaultTypeInternal _Version_default_instance_; PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 VersionDefaultTypeInternal _Version_default_instance_;
PROTOBUF_CONSTEXPR CodeGeneratorRequest::CodeGeneratorRequest( PROTOBUF_CONSTEXPR CodeGeneratorRequest::CodeGeneratorRequest(::_pbi::ConstantInitialized)
::_pbi::ConstantInitialized): _impl_{ : _impl_{
/*decltype(_impl_._has_bits_)*/{} /*decltype(_impl_._has_bits_)*/ {},
, /*decltype(_impl_._cached_size_)*/{} /*decltype(_impl_._cached_size_)*/ {},
, /*decltype(_impl_.file_to_generate_)*/{} /*decltype(_impl_.file_to_generate_)*/ {},
, /*decltype(_impl_.proto_file_)*/{} /*decltype(_impl_.proto_file_)*/ {},
, /*decltype(_impl_.parameter_)*/ { /*decltype(_impl_.parameter_)*/ {
&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} &::_pbi::fixed_address_empty_string,
} ::_pbi::ConstantInitialized{},
},
, /*decltype(_impl_.compiler_version_)*/nullptr} {} /*decltype(_impl_.compiler_version_)*/ nullptr,
} {}
struct CodeGeneratorRequestDefaultTypeInternal { struct CodeGeneratorRequestDefaultTypeInternal {
PROTOBUF_CONSTEXPR CodeGeneratorRequestDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} PROTOBUF_CONSTEXPR CodeGeneratorRequestDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
~CodeGeneratorRequestDefaultTypeInternal() {} ~CodeGeneratorRequestDefaultTypeInternal() {}
@ -66,23 +65,24 @@ struct CodeGeneratorRequestDefaultTypeInternal {
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_;
PROTOBUF_CONSTEXPR CodeGeneratorResponse_File::CodeGeneratorResponse_File( PROTOBUF_CONSTEXPR CodeGeneratorResponse_File::CodeGeneratorResponse_File(::_pbi::ConstantInitialized)
::_pbi::ConstantInitialized): _impl_{ : _impl_{
/*decltype(_impl_._has_bits_)*/{} /*decltype(_impl_._has_bits_)*/ {},
, /*decltype(_impl_._cached_size_)*/{} /*decltype(_impl_._cached_size_)*/ {},
, /*decltype(_impl_.name_)*/ { /*decltype(_impl_.name_)*/ {
&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} &::_pbi::fixed_address_empty_string,
} ::_pbi::ConstantInitialized{},
},
, /*decltype(_impl_.insertion_point_)*/ { /*decltype(_impl_.insertion_point_)*/ {
&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} &::_pbi::fixed_address_empty_string,
} ::_pbi::ConstantInitialized{},
},
, /*decltype(_impl_.content_)*/ { /*decltype(_impl_.content_)*/ {
&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} &::_pbi::fixed_address_empty_string,
} ::_pbi::ConstantInitialized{},
},
, /*decltype(_impl_.generated_code_info_)*/nullptr} {} /*decltype(_impl_.generated_code_info_)*/ nullptr,
} {}
struct CodeGeneratorResponse_FileDefaultTypeInternal { struct CodeGeneratorResponse_FileDefaultTypeInternal {
PROTOBUF_CONSTEXPR CodeGeneratorResponse_FileDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} PROTOBUF_CONSTEXPR CodeGeneratorResponse_FileDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
~CodeGeneratorResponse_FileDefaultTypeInternal() {} ~CodeGeneratorResponse_FileDefaultTypeInternal() {}
@ -93,17 +93,17 @@ struct CodeGeneratorResponse_FileDefaultTypeInternal {
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_;
PROTOBUF_CONSTEXPR CodeGeneratorResponse::CodeGeneratorResponse( PROTOBUF_CONSTEXPR CodeGeneratorResponse::CodeGeneratorResponse(::_pbi::ConstantInitialized)
::_pbi::ConstantInitialized): _impl_{ : _impl_{
/*decltype(_impl_._has_bits_)*/{} /*decltype(_impl_._has_bits_)*/ {},
, /*decltype(_impl_._cached_size_)*/{} /*decltype(_impl_._cached_size_)*/ {},
, /*decltype(_impl_.file_)*/{} /*decltype(_impl_.file_)*/ {},
, /*decltype(_impl_.error_)*/ { /*decltype(_impl_.error_)*/ {
&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} &::_pbi::fixed_address_empty_string,
} ::_pbi::ConstantInitialized{},
},
, /*decltype(_impl_.supported_features_)*/ ::uint64_t{0u} /*decltype(_impl_.supported_features_)*/ ::uint64_t{0u},
} {} } {}
struct CodeGeneratorResponseDefaultTypeInternal { struct CodeGeneratorResponseDefaultTypeInternal {
PROTOBUF_CONSTEXPR CodeGeneratorResponseDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} PROTOBUF_CONSTEXPR CodeGeneratorResponseDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
~CodeGeneratorResponseDefaultTypeInternal() {} ~CodeGeneratorResponseDefaultTypeInternal() {}
@ -348,23 +348,18 @@ Version::Version(const Version& from)
inline void Version::SharedCtor(::_pb::Arena* arena) { inline void Version::SharedCtor(::_pb::Arena* arena) {
(void)arena; (void)arena;
new (&_impl_) Impl_{ new (&_impl_) Impl_{
decltype(_impl_._has_bits_){} decltype(_impl_._has_bits_){},
, /*decltype(_impl_._cached_size_)*/{} /*decltype(_impl_._cached_size_)*/ {},
, decltype(_impl_.suffix_) {} decltype(_impl_.suffix_){},
decltype(_impl_.major_){0},
, decltype(_impl_.major_) { 0 } decltype(_impl_.minor_){0},
decltype(_impl_.patch_){0},
, decltype(_impl_.minor_) { 0 }
, decltype(_impl_.patch_) { 0 }
}; };
_impl_.suffix_.InitDefault(); _impl_.suffix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.suffix_.Set("", GetArenaForAllocation()); _impl_.suffix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
} }
Version::~Version() { Version::~Version() {
// @@protoc_insertion_point(destructor:google.protobuf.compiler.Version) // @@protoc_insertion_point(destructor:google.protobuf.compiler.Version)
if (auto *arena = _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { if (auto *arena = _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) {
@ -680,20 +675,18 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
inline void CodeGeneratorRequest::SharedCtor(::_pb::Arena* arena) { inline void CodeGeneratorRequest::SharedCtor(::_pb::Arena* arena) {
(void)arena; (void)arena;
new (&_impl_) Impl_{ new (&_impl_) Impl_{
decltype(_impl_._has_bits_){} decltype(_impl_._has_bits_){},
, /*decltype(_impl_._cached_size_)*/{} /*decltype(_impl_._cached_size_)*/ {},
, decltype(_impl_.file_to_generate_){arena} decltype(_impl_.file_to_generate_){arena},
, decltype(_impl_.proto_file_){arena} decltype(_impl_.proto_file_){arena},
, decltype(_impl_.parameter_) {} decltype(_impl_.parameter_){},
decltype(_impl_.compiler_version_){nullptr},
, decltype(_impl_.compiler_version_){nullptr}
}; };
_impl_.parameter_.InitDefault(); _impl_.parameter_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.parameter_.Set("", GetArenaForAllocation()); _impl_.parameter_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
} }
CodeGeneratorRequest::~CodeGeneratorRequest() { CodeGeneratorRequest::~CodeGeneratorRequest() {
// @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorRequest) // @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorRequest)
if (auto *arena = _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { if (auto *arena = _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) {
@ -1050,15 +1043,12 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon
inline void CodeGeneratorResponse_File::SharedCtor(::_pb::Arena* arena) { inline void CodeGeneratorResponse_File::SharedCtor(::_pb::Arena* arena) {
(void)arena; (void)arena;
new (&_impl_) Impl_{ new (&_impl_) Impl_{
decltype(_impl_._has_bits_){} decltype(_impl_._has_bits_){},
, /*decltype(_impl_._cached_size_)*/{} /*decltype(_impl_._cached_size_)*/ {},
, decltype(_impl_.name_) {} decltype(_impl_.name_){},
decltype(_impl_.insertion_point_){},
, decltype(_impl_.insertion_point_) {} decltype(_impl_.content_){},
decltype(_impl_.generated_code_info_){nullptr},
, decltype(_impl_.content_) {}
, decltype(_impl_.generated_code_info_){nullptr}
}; };
_impl_.name_.InitDefault(); _impl_.name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
@ -1073,7 +1063,6 @@ inline void CodeGeneratorResponse_File::SharedCtor(::_pb::Arena* arena) {
_impl_.content_.Set("", GetArenaForAllocation()); _impl_.content_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
} }
CodeGeneratorResponse_File::~CodeGeneratorResponse_File() { CodeGeneratorResponse_File::~CodeGeneratorResponse_File() {
// @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorResponse.File) // @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorResponse.File)
if (auto *arena = _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { if (auto *arena = _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) {
@ -1397,20 +1386,17 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
inline void CodeGeneratorResponse::SharedCtor(::_pb::Arena* arena) { inline void CodeGeneratorResponse::SharedCtor(::_pb::Arena* arena) {
(void)arena; (void)arena;
new (&_impl_) Impl_{ new (&_impl_) Impl_{
decltype(_impl_._has_bits_){} decltype(_impl_._has_bits_){},
, /*decltype(_impl_._cached_size_)*/{} /*decltype(_impl_._cached_size_)*/ {},
, decltype(_impl_.file_){arena} decltype(_impl_.file_){arena},
, decltype(_impl_.error_) {} decltype(_impl_.error_){},
decltype(_impl_.supported_features_){::uint64_t{0u}},
, decltype(_impl_.supported_features_) { ::uint64_t{0u} }
}; };
_impl_.error_.InitDefault(); _impl_.error_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
_impl_.error_.Set("", GetArenaForAllocation()); _impl_.error_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
} }
CodeGeneratorResponse::~CodeGeneratorResponse() { CodeGeneratorResponse::~CodeGeneratorResponse() {
// @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorResponse) // @@protoc_insertion_point(destructor:google.protobuf.compiler.CodeGeneratorResponse)
if (auto *arena = _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) { if (auto *arena = _internal_metadata_.DeleteReturnArena<::google::protobuf::UnknownFieldSet>()) {

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save