diff --git a/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc b/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc index b15801ea51..5a7028bf36 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc @@ -38,6 +38,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/types/optional.h" @@ -300,7 +301,7 @@ class RepeatedPrimitive final : public FieldGeneratorBase { void GenerateClearingCode(io::Printer* p) const override { p->Emit(R"cc( - $field_$.Clear(); + _internal_mutable_$name$()->Clear(); )cc"); } @@ -324,9 +325,7 @@ class RepeatedPrimitive final : public FieldGeneratorBase { void GenerateConstructorCode(io::Printer* p) const override {} - void GenerateCopyConstructorCode(io::Printer* p) const override { - ABSL_CHECK(!ShouldSplit(field_, *opts_)); - } + void GenerateCopyConstructorCode(io::Printer* p) const override {} void GenerateConstexprAggregateInitializer(io::Printer* p) const override { p->Emit(R"cc( @@ -336,6 +335,7 @@ class RepeatedPrimitive final : public FieldGeneratorBase { } void GenerateAggregateInitializer(io::Printer* p) const override { + ABSL_CHECK(!ShouldSplit(descriptor_, options_)); p->Emit(R"cc( decltype($field_$) { arena } )cc"); @@ -343,6 +343,7 @@ class RepeatedPrimitive final : public FieldGeneratorBase { } void GenerateCopyAggregateInitializer(io::Printer* p) const override { + ABSL_CHECK(!ShouldSplit(descriptor_, options_)); p->Emit(R"cc( decltype($field_$) { from.$field_$ } )cc"); @@ -422,7 +423,7 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( } inline void $Msg$::set_$name$(int index, $Type$ value) { $annotate_set$; - $field_$.Set(index, value); + _internal_mutable_$name$()->Set(index, value); // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } inline void $Msg$::add_$name$($Type$ value) { @@ -442,9 +443,11 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( } inline $Type$ $Msg$::_internal_$name$(int index) const { - return $field_$.Get(index); + return _internal_$name$().Get(index); + } + inline void $Msg$::_internal_add_$name$($Type$ value) { + _internal_mutable_$name$()->Add(value); } - inline void $Msg$::_internal_add_$name$($Type$ value) { $field_$.Add(value); } inline const $pb$::RepeatedField<$Type$>& $Msg$::_internal_$name$() const { return $field_$; } @@ -500,7 +503,8 @@ void RepeatedPrimitive::GenerateByteSize(io::Printer* p) const { )cc"); } else { p->Emit(R"cc( - ::_pbi::WireFormatLite::$DeclaredType$Size(this->$field_$) + ::_pbi::WireFormatLite::$DeclaredType$Size( + this->_internal_$name$()) )cc"); } }} // Here and below, we need to disable the default ;-chomping diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 09e541b70c..c0bf81b34c 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -2166,8 +2166,8 @@ void FileDescriptorProto::Clear() { _impl_.enum_type_.Clear(); _impl_.service_.Clear(); _impl_.extension_.Clear(); - _impl_.public_dependency_.Clear(); - _impl_.weak_dependency_.Clear(); + _internal_mutable_public_dependency()->Clear(); + _internal_mutable_weak_dependency()->Clear(); cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x0000003fu) { if (cached_has_bits & 0x00000001u) { @@ -2563,7 +2563,8 @@ failure: // repeated int32 public_dependency = 10; { - std::size_t data_size = ::_pbi::WireFormatLite::Int32Size(this->_impl_.public_dependency_) + std::size_t data_size = ::_pbi::WireFormatLite::Int32Size( + this->_internal_public_dependency()) ; std::size_t tag_size = std::size_t{1} * ::_pbi::FromIntSize(this->_internal_public_dependency_size()); @@ -2573,7 +2574,8 @@ failure: // repeated int32 weak_dependency = 11; { - std::size_t data_size = ::_pbi::WireFormatLite::Int32Size(this->_impl_.weak_dependency_) + std::size_t data_size = ::_pbi::WireFormatLite::Int32Size( + this->_internal_weak_dependency()) ; std::size_t tag_size = std::size_t{1} * ::_pbi::FromIntSize(this->_internal_weak_dependency_size()); @@ -11467,8 +11469,8 @@ void SourceCodeInfo_Location::Clear() { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - _impl_.path_.Clear(); - _impl_.span_.Clear(); + _internal_mutable_path()->Clear(); + _internal_mutable_span()->Clear(); _impl_.leading_detached_comments_.Clear(); cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { @@ -11649,7 +11651,8 @@ failure: // repeated int32 path = 1 [packed = true]; { - std::size_t data_size = ::_pbi::WireFormatLite::Int32Size(this->_impl_.path_) + std::size_t data_size = ::_pbi::WireFormatLite::Int32Size( + this->_internal_path()) ; _impl_._path_cached_byte_size_.Set(::_pbi::ToCachedSize(data_size)); std::size_t tag_size = data_size == 0 @@ -11662,7 +11665,8 @@ failure: // repeated int32 span = 2 [packed = true]; { - std::size_t data_size = ::_pbi::WireFormatLite::Int32Size(this->_impl_.span_) + std::size_t data_size = ::_pbi::WireFormatLite::Int32Size( + this->_internal_span()) ; _impl_._span_cached_byte_size_.Set(::_pbi::ToCachedSize(data_size)); std::size_t tag_size = data_size == 0 @@ -12046,7 +12050,7 @@ void GeneratedCodeInfo_Annotation::Clear() { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - _impl_.path_.Clear(); + _internal_mutable_path()->Clear(); cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000001u) { _impl_.source_file_.ClearNonDefaultToEmpty(); @@ -12213,7 +12217,8 @@ failure: // repeated int32 path = 1 [packed = true]; { - std::size_t data_size = ::_pbi::WireFormatLite::Int32Size(this->_impl_.path_) + std::size_t data_size = ::_pbi::WireFormatLite::Int32Size( + this->_internal_path()) ; _impl_._path_cached_byte_size_.Set(::_pbi::ToCachedSize(data_size)); std::size_t tag_size = data_size == 0 diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 4337182506..b5a92cdfa4 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -8896,14 +8896,14 @@ inline int FileDescriptorProto::public_dependency_size() const { return _internal_public_dependency_size(); } inline void FileDescriptorProto::clear_public_dependency() { - _impl_.public_dependency_.Clear(); + _internal_mutable_public_dependency()->Clear(); } inline ::int32_t FileDescriptorProto::public_dependency(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.public_dependency) return _internal_public_dependency(index); } inline void FileDescriptorProto::set_public_dependency(int index, ::int32_t value) { - _impl_.public_dependency_.Set(index, value); + _internal_mutable_public_dependency()->Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.public_dependency) } inline void FileDescriptorProto::add_public_dependency(::int32_t value) { @@ -8920,9 +8920,11 @@ inline ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>* FileDescriptorProto::m } inline ::int32_t FileDescriptorProto::_internal_public_dependency(int index) const { - return _impl_.public_dependency_.Get(index); + return _internal_public_dependency().Get(index); +} +inline void FileDescriptorProto::_internal_add_public_dependency(::int32_t value) { + _internal_mutable_public_dependency()->Add(value); } -inline void FileDescriptorProto::_internal_add_public_dependency(::int32_t value) { _impl_.public_dependency_.Add(value); } inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>& FileDescriptorProto::_internal_public_dependency() const { return _impl_.public_dependency_; } @@ -8938,14 +8940,14 @@ inline int FileDescriptorProto::weak_dependency_size() const { return _internal_weak_dependency_size(); } inline void FileDescriptorProto::clear_weak_dependency() { - _impl_.weak_dependency_.Clear(); + _internal_mutable_weak_dependency()->Clear(); } inline ::int32_t FileDescriptorProto::weak_dependency(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.weak_dependency) return _internal_weak_dependency(index); } inline void FileDescriptorProto::set_weak_dependency(int index, ::int32_t value) { - _impl_.weak_dependency_.Set(index, value); + _internal_mutable_weak_dependency()->Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.weak_dependency) } inline void FileDescriptorProto::add_weak_dependency(::int32_t value) { @@ -8962,9 +8964,11 @@ inline ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>* FileDescriptorProto::m } inline ::int32_t FileDescriptorProto::_internal_weak_dependency(int index) const { - return _impl_.weak_dependency_.Get(index); + return _internal_weak_dependency().Get(index); +} +inline void FileDescriptorProto::_internal_add_weak_dependency(::int32_t value) { + _internal_mutable_weak_dependency()->Add(value); } -inline void FileDescriptorProto::_internal_add_weak_dependency(::int32_t value) { _impl_.weak_dependency_.Add(value); } inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>& FileDescriptorProto::_internal_weak_dependency() const { return _impl_.weak_dependency_; } @@ -14492,14 +14496,14 @@ inline int SourceCodeInfo_Location::path_size() const { return _internal_path_size(); } inline void SourceCodeInfo_Location::clear_path() { - _impl_.path_.Clear(); + _internal_mutable_path()->Clear(); } inline ::int32_t SourceCodeInfo_Location::path(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.path) return _internal_path(index); } inline void SourceCodeInfo_Location::set_path(int index, ::int32_t value) { - _impl_.path_.Set(index, value); + _internal_mutable_path()->Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.path) } inline void SourceCodeInfo_Location::add_path(::int32_t value) { @@ -14516,9 +14520,11 @@ inline ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>* SourceCodeInfo_Locatio } inline ::int32_t SourceCodeInfo_Location::_internal_path(int index) const { - return _impl_.path_.Get(index); + return _internal_path().Get(index); +} +inline void SourceCodeInfo_Location::_internal_add_path(::int32_t value) { + _internal_mutable_path()->Add(value); } -inline void SourceCodeInfo_Location::_internal_add_path(::int32_t value) { _impl_.path_.Add(value); } inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>& SourceCodeInfo_Location::_internal_path() const { return _impl_.path_; } @@ -14534,14 +14540,14 @@ inline int SourceCodeInfo_Location::span_size() const { return _internal_span_size(); } inline void SourceCodeInfo_Location::clear_span() { - _impl_.span_.Clear(); + _internal_mutable_span()->Clear(); } inline ::int32_t SourceCodeInfo_Location::span(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.span) return _internal_span(index); } inline void SourceCodeInfo_Location::set_span(int index, ::int32_t value) { - _impl_.span_.Set(index, value); + _internal_mutable_span()->Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.span) } inline void SourceCodeInfo_Location::add_span(::int32_t value) { @@ -14558,9 +14564,11 @@ inline ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>* SourceCodeInfo_Locatio } inline ::int32_t SourceCodeInfo_Location::_internal_span(int index) const { - return _impl_.span_.Get(index); + return _internal_span().Get(index); +} +inline void SourceCodeInfo_Location::_internal_add_span(::int32_t value) { + _internal_mutable_span()->Add(value); } -inline void SourceCodeInfo_Location::_internal_add_span(::int32_t value) { _impl_.span_.Add(value); } inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>& SourceCodeInfo_Location::_internal_span() const { return _impl_.span_; } @@ -14834,14 +14842,14 @@ inline int GeneratedCodeInfo_Annotation::path_size() const { return _internal_path_size(); } inline void GeneratedCodeInfo_Annotation::clear_path() { - _impl_.path_.Clear(); + _internal_mutable_path()->Clear(); } inline ::int32_t GeneratedCodeInfo_Annotation::path(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.path) return _internal_path(index); } inline void GeneratedCodeInfo_Annotation::set_path(int index, ::int32_t value) { - _impl_.path_.Set(index, value); + _internal_mutable_path()->Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.path) } inline void GeneratedCodeInfo_Annotation::add_path(::int32_t value) { @@ -14858,9 +14866,11 @@ inline ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>* GeneratedCodeInfo_Anno } inline ::int32_t GeneratedCodeInfo_Annotation::_internal_path(int index) const { - return _impl_.path_.Get(index); + return _internal_path().Get(index); +} +inline void GeneratedCodeInfo_Annotation::_internal_add_path(::int32_t value) { + _internal_mutable_path()->Add(value); } -inline void GeneratedCodeInfo_Annotation::_internal_add_path(::int32_t value) { _impl_.path_.Add(value); } inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField<::int32_t>& GeneratedCodeInfo_Annotation::_internal_path() const { return _impl_.path_; }