|
|
@ -12,6 +12,7 @@ |
|
|
|
#include "google/protobuf/compiler/cpp/extension.h" |
|
|
|
#include "google/protobuf/compiler/cpp/extension.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <string> |
|
|
|
#include <string> |
|
|
|
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
#include "absl/strings/str_replace.h" |
|
|
|
#include "absl/strings/str_replace.h" |
|
|
@ -188,35 +189,58 @@ void ExtensionGenerator::GenerateRegistration(io::Printer* p) { |
|
|
|
$repeated$, $packed$, $enum_name$_IsValid), |
|
|
|
$repeated$, $packed$, $enum_name$_IsValid), |
|
|
|
)cc"); |
|
|
|
)cc"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case FieldDescriptor::CPPTYPE_MESSAGE: |
|
|
|
case FieldDescriptor::CPPTYPE_MESSAGE: { |
|
|
|
p->Emit({{"verify", |
|
|
|
const bool should_verify = |
|
|
|
[&] { |
|
|
|
// Only verify msgs.
|
|
|
|
const bool should_verify = |
|
|
|
descriptor_->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
// Only verify msgs.
|
|
|
|
// Options say to verify.
|
|
|
|
descriptor_->cpp_type() == |
|
|
|
ShouldVerify(descriptor_->message_type(), options_, scc_analyzer_) && |
|
|
|
FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
ShouldVerify(descriptor_->containing_type(), options_, scc_analyzer_); |
|
|
|
// Options say to verify.
|
|
|
|
const auto message_type = FieldMessageTypeName(descriptor_, options_); |
|
|
|
ShouldVerify(descriptor_->message_type(), options_, |
|
|
|
auto v = p->WithVars( |
|
|
|
scc_analyzer_) && |
|
|
|
{{"verify", should_verify |
|
|
|
ShouldVerify(descriptor_->containing_type(), options_, |
|
|
|
? absl::StrCat("&", message_type, "::InternalVerify") |
|
|
|
scc_analyzer_); |
|
|
|
: "nullptr"}, |
|
|
|
if (should_verify) { |
|
|
|
{"message_type", message_type}, |
|
|
|
p->Emit("&$message_type$::InternalVerify,"); |
|
|
|
{"lazy", descriptor_->options().has_lazy() |
|
|
|
} else { |
|
|
|
? descriptor_->options().lazy() ? "kLazy" : "kEager" |
|
|
|
p->Emit("nullptr,"); |
|
|
|
: "kUndefined"}}); |
|
|
|
} |
|
|
|
if (UsingImplicitWeakDescriptor(descriptor_->file(), options_)) { |
|
|
|
}}, |
|
|
|
const auto find_index = [](auto* desc) { |
|
|
|
{"message_type", FieldMessageTypeName(descriptor_, options_)}, |
|
|
|
const std::vector<const Descriptor*> msgs = |
|
|
|
{"lazy", descriptor_->options().has_lazy() |
|
|
|
FlattenMessagesInFile(desc->file()); |
|
|
|
? descriptor_->options().lazy() ? "kLazy" : "kEager" |
|
|
|
return absl::c_find(msgs, desc) - msgs.begin(); |
|
|
|
: "kUndefined"}}, |
|
|
|
}; |
|
|
|
R"cc( |
|
|
|
p->Emit( |
|
|
|
::_pbi::ExtensionSet::RegisterMessageExtension( |
|
|
|
{ |
|
|
|
&$extendee$::default_instance(), $number$, $field_type$, |
|
|
|
{"extendee_table", |
|
|
|
$repeated$, $packed$, &$message_type$::default_instance(), |
|
|
|
DescriptorTableName(descriptor_->containing_type()->file(), |
|
|
|
$verify$, ::_pbi::LazyAnnotation::$lazy$), |
|
|
|
options_)}, |
|
|
|
)cc"); |
|
|
|
{"extendee_index", find_index(descriptor_->containing_type())}, |
|
|
|
|
|
|
|
{"extension_table", |
|
|
|
|
|
|
|
DescriptorTableName(descriptor_->message_type()->file(), |
|
|
|
|
|
|
|
options_)}, |
|
|
|
|
|
|
|
{"extension_index", find_index(descriptor_->message_type())}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
R"cc( |
|
|
|
|
|
|
|
::_pbi::ExtensionSet::RegisterMessageExtension( |
|
|
|
|
|
|
|
::_pbi::GetPrototypeForWeakDescriptor(&$extendee_table$, |
|
|
|
|
|
|
|
$extendee_index$), |
|
|
|
|
|
|
|
$number$, $field_type$, $repeated$, $packed$, |
|
|
|
|
|
|
|
::_pbi::GetPrototypeForWeakDescriptor(&$extension_table$, |
|
|
|
|
|
|
|
$extension_index$), |
|
|
|
|
|
|
|
$verify$, ::_pbi::LazyAnnotation::$lazy$), |
|
|
|
|
|
|
|
)cc"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
p->Emit(R"cc( |
|
|
|
|
|
|
|
::_pbi::ExtensionSet::RegisterMessageExtension( |
|
|
|
|
|
|
|
&$extendee$::default_instance(), $number$, $field_type$, |
|
|
|
|
|
|
|
$repeated$, $packed$, &$message_type$::default_instance(), |
|
|
|
|
|
|
|
$verify$, ::_pbi::LazyAnnotation::$lazy$), |
|
|
|
|
|
|
|
)cc"); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
p->Emit( |
|
|
|
p->Emit( |
|
|
|
R"cc( |
|
|
|
R"cc( |
|
|
|