Internal changes

PiperOrigin-RevId: 531222261
pull/12738/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent a2abe0f6d3
commit b0be4f8738
  1. 2
      src/google/protobuf/compiler/parser_unittest.cc
  2. 36
      src/google/protobuf/descriptor.cc
  3. 2
      src/google/protobuf/descriptor.h
  4. 2
      src/google/protobuf/descriptor_unittest.cc

@ -2523,7 +2523,7 @@ TEST_F(ParseDescriptorDebugTest, TestCustomOptions) {
ASSERT_TRUE(pool_.BuildFile(any_import) != nullptr); ASSERT_TRUE(pool_.BuildFile(any_import) != nullptr);
const FileDescriptor* actual = pool_.BuildFile(parsed); const FileDescriptor* actual = pool_.BuildFile(parsed);
ASSERT_TRUE(actual != nullptr); ASSERT_TRUE(actual != nullptr) << error_collector_.text_;
parsed.Clear(); parsed.Clear();
actual->CopyTo(&parsed); actual->CopyTo(&parsed);

@ -1104,6 +1104,7 @@ bool AllowedExtendeeInProto3(const std::string& name) {
return allowed_proto3_extendees->find(name) != return allowed_proto3_extendees->find(name) !=
allowed_proto3_extendees->end(); allowed_proto3_extendees->end();
} }
} // anonymous namespace } // anonymous namespace
// Contains tables specific to a particular file. These tables are not // Contains tables specific to a particular file. These tables are not
@ -2681,6 +2682,7 @@ void Descriptor::CopyTo(DescriptorProto* proto) const {
if (&options() != &MessageOptions::default_instance()) { if (&options() != &MessageOptions::default_instance()) {
proto->mutable_options()->CopyFrom(options()); proto->mutable_options()->CopyFrom(options());
} }
} }
void Descriptor::CopyJsonNameTo(DescriptorProto* proto) const { void Descriptor::CopyJsonNameTo(DescriptorProto* proto) const {
@ -2753,6 +2755,7 @@ void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const {
if (&options() != &FieldOptions::default_instance()) { if (&options() != &FieldOptions::default_instance()) {
proto->mutable_options()->CopyFrom(options()); proto->mutable_options()->CopyFrom(options());
} }
} }
void FieldDescriptor::CopyJsonNameTo(FieldDescriptorProto* proto) const { void FieldDescriptor::CopyJsonNameTo(FieldDescriptorProto* proto) const {
@ -3948,10 +3951,9 @@ class DescriptorBuilder {
internal::FlatAllocator& alloc); internal::FlatAllocator& alloc);
// Allocates an array of two strings, the first one is a copy of `proto_name`, // Allocates an array of two strings, the first one is a copy of
// and the second one is the full name. // `proto_name`, and the second one is the full name. Full proto name is
// Full proto name is "scope.proto_name" if scope is non-empty and // "scope.proto_name" if scope is non-empty and "proto_name" otherwise.
// "proto_name" otherwise.
const std::string* AllocateNameStrings(const std::string& scope, const std::string* AllocateNameStrings(const std::string& scope,
const std::string& proto_name, const std::string& proto_name,
internal::FlatAllocator& alloc); internal::FlatAllocator& alloc);
@ -4208,6 +4210,8 @@ class DescriptorBuilder {
const OneofDescriptorProto& proto); const OneofDescriptorProto& proto);
void ValidateFieldOptions(const FieldDescriptor* field, void ValidateFieldOptions(const FieldDescriptor* field,
const FieldDescriptorProto& proto); const FieldDescriptorProto& proto);
void ValidateFieldFeatures(const FieldDescriptor* field,
const FieldDescriptorProto& proto);
void ValidateEnumOptions(const EnumDescriptor* enm, void ValidateEnumOptions(const EnumDescriptor* enm,
const EnumDescriptorProto& proto); const EnumDescriptorProto& proto);
void ValidateEnumValueOptions(const EnumValueDescriptor* enum_value, void ValidateEnumValueOptions(const EnumValueDescriptor* enum_value,
@ -5596,9 +5600,12 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
} }
// Copy options. // Copy options.
result->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));
@ -6088,9 +6095,12 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
} }
// Copy options. // Copy options.
result->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));
} }
@ -7264,6 +7274,8 @@ void DescriptorBuilder::ValidateFieldOptions(
return; return;
} }
ValidateFieldFeatures(field, proto);
// Only message type fields may be lazy. // Only message type fields may be lazy.
if (field->options().lazy() || field->options().unverified_lazy()) { if (field->options().lazy() || field->options().unverified_lazy()) {
if (field->type() != FieldDescriptor::TYPE_MESSAGE) { if (field->type() != FieldDescriptor::TYPE_MESSAGE) {
@ -7344,6 +7356,10 @@ void DescriptorBuilder::ValidateFieldOptions(
} }
void DescriptorBuilder::ValidateFieldFeatures(
const FieldDescriptor* field, const FieldDescriptorProto& proto) {
}
void DescriptorBuilder::ValidateEnumOptions(const EnumDescriptor* enm, void DescriptorBuilder::ValidateEnumOptions(const EnumDescriptor* enm,
const EnumDescriptorProto& proto) { const EnumDescriptorProto& proto) {
VALIDATE_OPTIONS_FROM_ARRAY(enm, value, EnumValue); VALIDATE_OPTIONS_FROM_ARRAY(enm, value, EnumValue);

@ -299,6 +299,7 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase {
// available extensions of that message. // available extensions of that message.
const MessageOptions& options() const; const MessageOptions& options() const;
// Write the contents of this Descriptor into the given DescriptorProto. // Write the contents of this Descriptor into the given DescriptorProto.
// The target DescriptorProto must be clear before calling this; if it // The target DescriptorProto must be clear before calling this; if it
// isn't, the result may be garbage. // isn't, the result may be garbage.
@ -874,6 +875,7 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase {
// descriptor.proto, and any available extensions of that message. // descriptor.proto, and any available extensions of that message.
const FieldOptions& options() const; const FieldOptions& options() const;
// See Descriptor::CopyTo(). // See Descriptor::CopyTo().
void CopyTo(FieldDescriptorProto* proto) const; void CopyTo(FieldDescriptorProto* proto) const;

@ -566,7 +566,7 @@ TEST_F(FileDescriptorTest, DebugStringRoundTrip) {
ASSERT_EQ("", error_collector.last_error()); ASSERT_EQ("", error_collector.last_error());
proto.set_name(name); proto.set_name(name);
const FileDescriptor* descriptor = pool.BuildFile(proto); const FileDescriptor* descriptor = pool.BuildFile(proto);
ASSERT_TRUE(descriptor != nullptr) << proto.DebugString(); ASSERT_TRUE(descriptor != nullptr) << error_collector.last_error();
EXPECT_EQ(content, descriptor->DebugString()); EXPECT_EQ(content, descriptor->DebugString());
} }
} }

Loading…
Cancel
Save