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);
const FileDescriptor* actual = pool_.BuildFile(parsed);
ASSERT_TRUE(actual != nullptr);
ASSERT_TRUE(actual != nullptr) << error_collector_.text_;
parsed.Clear();
actual->CopyTo(&parsed);

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

@ -299,6 +299,7 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase {
// available extensions of that message.
const MessageOptions& options() const;
// Write the contents of this Descriptor into the given DescriptorProto.
// The target DescriptorProto must be clear before calling this; if it
// 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.
const FieldOptions& options() const;
// See Descriptor::CopyTo().
void CopyTo(FieldDescriptorProto* proto) const;

@ -566,7 +566,7 @@ TEST_F(FileDescriptorTest, DebugStringRoundTrip) {
ASSERT_EQ("", error_collector.last_error());
proto.set_name(name);
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());
}
}

Loading…
Cancel
Save