Internal changes

PiperOrigin-RevId: 531664397
pull/12796/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 748579e321
commit 17a2d53176
  1. 105
      src/google/protobuf/descriptor.cc

@ -3940,14 +3940,14 @@ class DescriptorBuilder {
// later. DescriptorT must be one of the Descriptor messages from // later. DescriptorT must be one of the Descriptor messages from
// descriptor.proto. // descriptor.proto.
template <class DescriptorT> template <class DescriptorT>
typename DescriptorT::OptionsType* AllocateOptions( void AllocateOptions(const typename DescriptorT::Proto& proto,
const typename DescriptorT::Proto& proto, const DescriptorT* descriptor, DescriptorT* descriptor, int options_field_tag,
int options_field_tag, absl::string_view option_name, absl::string_view option_name,
internal::FlatAllocator& alloc); internal::FlatAllocator& alloc);
// Specialization for FileOptions. // Specialization for FileOptions.
FileOptions* AllocateOptions(const FileDescriptorProto& proto, void AllocateOptions(const FileDescriptorProto& proto,
const FileDescriptor* descriptor, FileDescriptor* descriptor,
internal::FlatAllocator& alloc); internal::FlatAllocator& alloc);
// Implementation for AllocateOptions(). Don't call this directly. // Implementation for AllocateOptions(). Don't call this directly.
template <class DescriptorT> template <class DescriptorT>
@ -4869,28 +4869,30 @@ void DescriptorBuilder::ValidateSymbolName(const std::string& name,
// This generic implementation is good for all descriptors except // This generic implementation is good for all descriptors except
// FileDescriptor. // FileDescriptor.
template <class DescriptorT> template <class DescriptorT>
typename DescriptorT::OptionsType* DescriptorBuilder::AllocateOptions( void DescriptorBuilder::AllocateOptions(
const typename DescriptorT::Proto& proto, const DescriptorT* descriptor, const typename DescriptorT::Proto& proto, DescriptorT* descriptor,
int options_field_tag, absl::string_view option_name, int options_field_tag, absl::string_view option_name,
internal::FlatAllocator& alloc) { internal::FlatAllocator& alloc) {
std::vector<int> options_path; std::vector<int> options_path;
descriptor->GetLocationPath(&options_path); descriptor->GetLocationPath(&options_path);
options_path.push_back(options_field_tag); options_path.push_back(options_field_tag);
return AllocateOptionsImpl<DescriptorT>(descriptor->full_name(), auto options = AllocateOptionsImpl<DescriptorT>(
descriptor->full_name(), proto, descriptor->full_name(), descriptor->full_name(), proto, options_path,
options_path, option_name, alloc); option_name, alloc);
descriptor->options_ = options;
} }
// We specialize for FileDescriptor. // We specialize for FileDescriptor.
FileOptions* DescriptorBuilder::AllocateOptions( void DescriptorBuilder::AllocateOptions(const FileDescriptorProto& proto,
const FileDescriptorProto& proto, const FileDescriptor* descriptor, FileDescriptor* descriptor,
internal::FlatAllocator& alloc) { internal::FlatAllocator& alloc) {
std::vector<int> options_path; std::vector<int> options_path;
options_path.push_back(FileDescriptorProto::kOptionsFieldNumber); options_path.push_back(FileDescriptorProto::kOptionsFieldNumber);
// We add the dummy token so that LookupSymbol does the right thing. // We add the dummy token so that LookupSymbol does the right thing.
return AllocateOptionsImpl<FileDescriptor>( auto options = AllocateOptionsImpl<FileDescriptor>(
absl::StrCat(descriptor->package(), ".dummy"), descriptor->name(), proto, absl::StrCat(descriptor->package(), ".dummy"), descriptor->name(), proto,
options_path, "google.protobuf.FileOptions", alloc); options_path, "google.protobuf.FileOptions", alloc);
descriptor->options_ = options;
} }
template <class DescriptorT> template <class DescriptorT>
@ -5448,10 +5450,7 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
BUILD_ARRAY(proto, result, extension, BuildExtension, nullptr); BUILD_ARRAY(proto, result, extension, BuildExtension, nullptr);
// Copy options. // Copy options.
{ AllocateOptions(proto, result, alloc);
FileOptions* options = AllocateOptions(proto, result, alloc);
result->options_ = options; // Set to default_instance later if necessary.
}
// Note that the following steps must occur in exactly the specified order. // Note that the following steps must occur in exactly the specified order.
@ -5607,12 +5606,8 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
} }
// Copy options. // Copy options.
{ AllocateOptions(proto, result, DescriptorProto::kOptionsFieldNumber,
MessageOptions* options = "google.protobuf.MessageOptions", alloc);
AllocateOptions(proto, result, DescriptorProto::kOptionsFieldNumber,
"google.protobuf.MessageOptions", alloc);
result->options_ = options; // Set to default_instance later if necessary.
}
AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result)); AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result));
@ -6102,12 +6097,8 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
} }
// Copy options. // Copy options.
{ AllocateOptions(proto, result, FieldDescriptorProto::kOptionsFieldNumber,
FieldOptions* options = AllocateOptions( "google.protobuf.FieldOptions", alloc);
proto, result, FieldDescriptorProto::kOptionsFieldNumber,
"google.protobuf.FieldOptions", alloc);
result->options_ = options; // Set to default_instance later if necessary.
}
AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result)); AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result));
} }
@ -6138,13 +6129,9 @@ void DescriptorBuilder::BuildExtensionRange(
} }
// Copy options // Copy options
{ AllocateOptions(proto, result,
ExtensionRangeOptions* options = DescriptorProto_ExtensionRange::kOptionsFieldNumber,
AllocateOptions<Descriptor::ExtensionRange>( "google.protobuf.ExtensionRangeOptions", alloc);
proto, result, DescriptorProto_ExtensionRange::kOptionsFieldNumber,
"google.protobuf.ExtensionRangeOptions", alloc);
result->options_ = options;
}
} }
void DescriptorBuilder::BuildReservedRange( void DescriptorBuilder::BuildReservedRange(
@ -6188,12 +6175,8 @@ void DescriptorBuilder::BuildOneof(const OneofDescriptorProto& proto,
result->fields_ = nullptr; result->fields_ = nullptr;
// Copy options. // Copy options.
{ AllocateOptions(proto, result, OneofDescriptorProto::kOptionsFieldNumber,
OneofOptions* options = AllocateOptions( "google.protobuf.OneofOptions", alloc);
proto, result, OneofDescriptorProto::kOptionsFieldNumber,
"google.protobuf.OneofOptions", alloc);
result->options_ = options; // Set to default_instance later if necessary.
}
AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result)); AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result));
} }
@ -6316,12 +6299,8 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto,
} }
// Copy options. // Copy options.
{ AllocateOptions(proto, result, EnumDescriptorProto::kOptionsFieldNumber,
EnumOptions* options = "google.protobuf.EnumOptions", alloc);
AllocateOptions(proto, result, EnumDescriptorProto::kOptionsFieldNumber,
"google.protobuf.EnumOptions", alloc);
result->options_ = options;
}
AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result)); AddSymbol(result->full_name(), parent, result->name(), proto, Symbol(result));
@ -6397,12 +6376,8 @@ void DescriptorBuilder::BuildEnumValue(const EnumValueDescriptorProto& proto,
ValidateSymbolName(proto.name(), result->full_name(), proto); ValidateSymbolName(proto.name(), result->full_name(), proto);
// Copy options. // Copy options.
{ AllocateOptions(proto, result, EnumValueDescriptorProto::kOptionsFieldNumber,
EnumValueOptions* options = AllocateOptions( "google.protobuf.EnumValueOptions", alloc);
proto, result, EnumValueDescriptorProto::kOptionsFieldNumber,
"google.protobuf.EnumValueOptions", alloc);
result->options_ = options;
}
// Again, enum values are weird because we makes them appear as siblings // Again, enum values are weird because we makes them appear as siblings
// of the enum type instead of children of it. So, we use // of the enum type instead of children of it. So, we use
@ -6464,12 +6439,8 @@ void DescriptorBuilder::BuildService(const ServiceDescriptorProto& proto,
BUILD_ARRAY(proto, result, method, BuildMethod, result); BUILD_ARRAY(proto, result, method, BuildMethod, result);
// Copy options. // Copy options.
{ AllocateOptions(proto, result, ServiceDescriptorProto::kOptionsFieldNumber,
ServiceOptions* options = AllocateOptions( "google.protobuf.ServiceOptions", alloc);
proto, result, ServiceDescriptorProto::kOptionsFieldNumber,
"google.protobuf.ServiceOptions", alloc);
result->options_ = options;
}
AddSymbol(result->full_name(), nullptr, result->name(), proto, AddSymbol(result->full_name(), nullptr, result->name(), proto,
Symbol(result)); Symbol(result));
@ -6490,12 +6461,8 @@ void DescriptorBuilder::BuildMethod(const MethodDescriptorProto& proto,
result->output_type_.Init(); result->output_type_.Init();
// Copy options. // Copy options.
{ AllocateOptions(proto, result, MethodDescriptorProto::kOptionsFieldNumber,
MethodOptions* options = AllocateOptions( "google.protobuf.MethodOptions", alloc);
proto, result, MethodDescriptorProto::kOptionsFieldNumber,
"google.protobuf.MethodOptions", alloc);
result->options_ = options;
}
result->client_streaming_ = proto.client_streaming(); result->client_streaming_ = proto.client_streaming();
result->server_streaming_ = proto.server_streaming(); result->server_streaming_ = proto.server_streaming();

Loading…
Cancel
Save