|
|
@ -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 = |
|
|
|
const bool should_verify = |
|
|
|
// Only verify msgs.
|
|
|
|
// Only verify msgs.
|
|
|
|
descriptor_->cpp_type() == |
|
|
|
descriptor_->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
|
|
|
|
// Options say to verify.
|
|
|
|
// Options say to verify.
|
|
|
|
ShouldVerify(descriptor_->message_type(), options_, |
|
|
|
ShouldVerify(descriptor_->message_type(), options_, scc_analyzer_) && |
|
|
|
scc_analyzer_) && |
|
|
|
ShouldVerify(descriptor_->containing_type(), options_, scc_analyzer_); |
|
|
|
ShouldVerify(descriptor_->containing_type(), options_, |
|
|
|
const auto message_type = FieldMessageTypeName(descriptor_, options_); |
|
|
|
scc_analyzer_); |
|
|
|
auto v = p->WithVars( |
|
|
|
if (should_verify) { |
|
|
|
{{"verify", should_verify |
|
|
|
p->Emit("&$message_type$::InternalVerify,"); |
|
|
|
? absl::StrCat("&", message_type, "::InternalVerify") |
|
|
|
} else { |
|
|
|
: "nullptr"}, |
|
|
|
p->Emit("nullptr,"); |
|
|
|
{"message_type", message_type}, |
|
|
|
} |
|
|
|
|
|
|
|
}}, |
|
|
|
|
|
|
|
{"message_type", FieldMessageTypeName(descriptor_, options_)}, |
|
|
|
|
|
|
|
{"lazy", descriptor_->options().has_lazy() |
|
|
|
{"lazy", descriptor_->options().has_lazy() |
|
|
|
? descriptor_->options().lazy() ? "kLazy" : "kEager" |
|
|
|
? descriptor_->options().lazy() ? "kLazy" : "kEager" |
|
|
|
: "kUndefined"}}, |
|
|
|
: "kUndefined"}}); |
|
|
|
|
|
|
|
if (UsingImplicitWeakDescriptor(descriptor_->file(), options_)) { |
|
|
|
|
|
|
|
const auto find_index = [](auto* desc) { |
|
|
|
|
|
|
|
const std::vector<const Descriptor*> msgs = |
|
|
|
|
|
|
|
FlattenMessagesInFile(desc->file()); |
|
|
|
|
|
|
|
return absl::c_find(msgs, desc) - msgs.begin(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
p->Emit( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
{"extendee_table", |
|
|
|
|
|
|
|
DescriptorTableName(descriptor_->containing_type()->file(), |
|
|
|
|
|
|
|
options_)}, |
|
|
|
|
|
|
|
{"extendee_index", find_index(descriptor_->containing_type())}, |
|
|
|
|
|
|
|
{"extension_table", |
|
|
|
|
|
|
|
DescriptorTableName(descriptor_->message_type()->file(), |
|
|
|
|
|
|
|
options_)}, |
|
|
|
|
|
|
|
{"extension_index", find_index(descriptor_->message_type())}, |
|
|
|
|
|
|
|
}, |
|
|
|
R"cc( |
|
|
|
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( |
|
|
|
::_pbi::ExtensionSet::RegisterMessageExtension( |
|
|
|
&$extendee$::default_instance(), $number$, $field_type$, |
|
|
|
&$extendee$::default_instance(), $number$, $field_type$, |
|
|
|
$repeated$, $packed$, &$message_type$::default_instance(), |
|
|
|
$repeated$, $packed$, &$message_type$::default_instance(), |
|
|
|
$verify$, ::_pbi::LazyAnnotation::$lazy$), |
|
|
|
$verify$, ::_pbi::LazyAnnotation::$lazy$), |
|
|
|
)cc"); |
|
|
|
)cc"); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
p->Emit( |
|
|
|
p->Emit( |
|
|
|
R"cc( |
|
|
|
R"cc( |
|
|
|