Incremental migration of message.cc to Emit

PiperOrigin-RevId: 556917345
pull/13533/head
Matt Kulukundis 1 year ago committed by Copybara-Service
parent 6d03f9b19b
commit 395e9529bb
  1. 50
      src/google/protobuf/compiler/cpp/field_generators/message_field.cc

@ -544,35 +544,33 @@ class OneofMessage : public SingularMessage {
}; };
void OneofMessage::GenerateNonInlineAccessorDefinitions(io::Printer* p) const { void OneofMessage::GenerateNonInlineAccessorDefinitions(io::Printer* p) const {
p->Emit( p->Emit({{"casted_name",
"void $Msg$::set_allocated_$name$($Submsg$* $name$) {\n" [&] {
" $pb$::Arena* message_arena = GetArenaForAllocation();\n"
" clear_$oneof_name$();\n"
" if ($name$) {\n");
if (field_->file() != field_->message_type()->file()) { if (field_->file() != field_->message_type()->file()) {
// We have to read the arena through the virtual method, because the type // We have to read the arena through the virtual method, because
// isn't defined in this file. // the type isn't defined in this file.
p->Emit( p->Emit(R"cc(reinterpret_cast<$pb$::MessageLite*>($name$))cc");
" $pb$::Arena* submessage_arena =\n"
" $pb$::Arena::InternalGetOwningArena(\n"
" reinterpret_cast<$pb$::MessageLite*>("
"$name$));\n");
} else { } else {
p->Emit( p->Emit(R"cc($name$)cc");
" $pb$::Arena* submessage_arena =\n"
" $pb$::Arena::InternalGetOwningArena($name$);\n");
} }
p->Emit( }}},
" if (message_arena != submessage_arena) {\n" R"cc(
" $name$ = $pbi$::GetOwnedMessage(\n" void $Msg$::set_allocated_$name$($Submsg$* $name$) {
" message_arena, $name$, submessage_arena);\n" $pb$::Arena* message_arena = GetArenaForAllocation();
" }\n" clear_$oneof_name$();
" set_has_$name$();\n" if ($name$) {
" $field_$ = $name$;\n" $pb$::Arena* submessage_arena =
" }\n" $pb$::Arena::InternalGetOwningArena($casted_name$);
"$annotate_set$" if (message_arena != submessage_arena) {
" // @@protoc_insertion_point(field_set_allocated:$pkg.Msg.field$)\n" $name$ = $pbi$::GetOwnedMessage(message_arena, $name$, submessage_arena);
"}\n"); }
set_has_$name$();
$field_$ = $name$;
}
$annotate_set$;
// @@protoc_insertion_point(field_set_allocated:$pkg.Msg.field$)
}
)cc");
} }
void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const {

Loading…
Cancel
Save