@ -71,15 +71,13 @@
# include "absl/synchronization/mutex.h"
# include "absl/types/optional.h"
# include "google/protobuf/any.h"
# include "google/protobuf/cpp_features.pb.h"
# include "google/protobuf/descriptor.pb.h"
# include "google/protobuf/descriptor_database.h"
# include "google/protobuf/descriptor_legacy.h"
# include "google/protobuf/descriptor_visitor.h"
# include "google/protobuf/dynamic_message.h"
# ifdef PROTOBUF_FUTURE_EDITIONS
# include "google/protobuf/cpp_features.pb.h"
# include "google/protobuf/feature_resolver.h"
# endif // PROTOBUF_FUTURE_EDITIONS
# include "google/protobuf/generated_message_util.h"
# include "google/protobuf/io/strtod.h"
# include "google/protobuf/io/tokenizer.h"
@ -838,10 +836,8 @@ const char* FileDescriptor::SyntaxName(FileDescriptor::Syntax syntax) {
return " proto2 " ;
case SYNTAX_PROTO3 :
return " proto3 " ;
# ifdef PROTOBUF_FUTURE_EDITIONS
case SYNTAX_EDITIONS :
return " editions " ;
# endif // !PROTOBUF_FUTURE_EDITIONS
case SYNTAX_UNKNOWN :
return " unknown " ;
}
@ -1114,8 +1110,6 @@ bool AllowedExtendeeInProto3(const std::string& name) {
allowed_proto3_extendees - > end ( ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
// Create global defaults for proto2/proto3 compatibility.
FeatureSet * CreateProto2DefaultFeatures ( ) {
FeatureSet * features = new FeatureSet ( ) ;
@ -1247,7 +1241,6 @@ const FeatureSet& GetParentFeatures(const ServiceDescriptor* service) {
const FeatureSet & GetParentFeatures ( const MethodDescriptor * method ) {
return internal : : InternalFeatureHelper : : GetFeatures ( * method - > service ( ) ) ;
}
# endif // PROTOBUF_FUTURE_EDITIONS
} // anonymous namespace
// Contains tables specific to a particular file. These tables are not
@ -1363,15 +1356,11 @@ namespace internal {
class FlatAllocator
: public decltype ( ApplyTypeList < FlatAllocatorImpl > (
SortByAlignment < char , std : : string , SourceCodeInfo ,
FileDescriptorTables ,
# ifdef PROTOBUF_FUTURE_EDITIONS
FeatureSet ,
# endif // PROTOBUF_FUTURE_EDITIONS
// Option types
FileDescriptorTables , FeatureSet ,
// Option types
MessageOptions , FieldOptions , EnumOptions ,
EnumValueOptions , ExtensionRangeOptions , OneofOptions ,
ServiceOptions , MethodOptions , FileOptions > ( ) ) ) {
} ;
ServiceOptions , MethodOptions , FileOptions > ( ) ) ) { } ;
} // namespace internal
@ -2009,10 +1998,8 @@ absl::string_view DescriptorPool::ErrorCollector::ErrorLocationName(
return " OUTPUT_TYPE " ;
case IMPORT :
return " IMPORT " ;
# ifdef PROTOBUF_FUTURE_EDITIONS
case EDITIONS :
return " EDITIONS " ;
# endif // PROTOBUF_FUTURE_EDITIONS
case OTHER :
return " OTHER " ;
}
@ -2125,9 +2112,7 @@ const DescriptorPool* DescriptorPool::generated_pool() {
// ensure that the linker --gc-sections step can strip out the full runtime if
// it is unused.
DescriptorProto : : descriptor ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
pb : : CppFeatures : : descriptor ( ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
return pool ;
}
@ -2544,9 +2529,7 @@ void Descriptor::ExtensionRange::CopyTo(
if ( options_ ! = & ExtensionRangeOptions : : default_instance ( ) ) {
* proto - > mutable_options ( ) = * options_ ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
const Descriptor : : ExtensionRange *
@ -2759,7 +2742,6 @@ FileDescriptor::FileDescriptor() {}
// CopyTo methods ====================================================
# ifdef PROTOBUF_FUTURE_EDITIONS
namespace internal {
FileDescriptorProto InternalFeatureHelper : : GetGeneratorProto (
const FileDescriptor & file ) {
@ -2780,7 +2762,6 @@ FileDescriptorProto InternalFeatureHelper::GetGeneratorProto(
return file_proto ;
}
} // namespace internal
# endif // PROTOBUF_FUTURE_EDITIONS
void FileDescriptor : : CopyTo ( FileDescriptorProto * proto ) const {
CopyHeadingTo ( proto ) ;
@ -2819,25 +2800,18 @@ void FileDescriptor::CopyHeadingTo(FileDescriptorProto* proto) const {
// TODO(liujisi): Also populate when syntax="proto2".
FileDescriptorLegacy : : Syntax syntax = FileDescriptorLegacy ( this ) . syntax ( ) ;
if ( syntax = = FileDescriptorLegacy : : Syntax : : SYNTAX_PROTO3
# ifdef PROTOBUF_FUTURE_EDITIONS
| | syntax = = FileDescriptorLegacy : : Syntax : : SYNTAX_EDITIONS
# endif // !PROTOBUF_FUTURE_EDITIONS
) {
if ( syntax = = FileDescriptorLegacy : : Syntax : : SYNTAX_PROTO3 | |
syntax = = FileDescriptorLegacy : : Syntax : : SYNTAX_EDITIONS ) {
proto - > set_syntax ( FileDescriptorLegacy : : SyntaxName ( syntax ) ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( syntax = = FileDescriptorLegacy : : Syntax : : SYNTAX_EDITIONS ) {
proto - > set_edition ( edition ( ) ) ;
}
# endif // !PROTOBUF_FUTURE_EDITIONS
if ( & options ( ) ! = & FileOptions : : default_instance ( ) ) {
* proto - > mutable_options ( ) = options ( ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
void FileDescriptor : : CopyJsonNameTo ( FileDescriptorProto * proto ) const {
@ -2895,9 +2869,7 @@ void Descriptor::CopyTo(DescriptorProto* proto) const {
proto - > mutable_options ( ) - > CopyFrom ( options ( ) ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
void Descriptor : : CopyJsonNameTo ( DescriptorProto * proto ) const {
@ -2929,7 +2901,6 @@ void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const {
}
// Some compilers do not allow static_cast directly between two enum types,
// so we must cast to int first.
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( is_required ( ) & & FileDescriptorLegacy ( file ( ) ) . syntax ( ) = =
FileDescriptorLegacy : : Syntax : : SYNTAX_EDITIONS ) {
// Editions files have no required keyword, and we only set this label
@ -2951,12 +2922,6 @@ void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const {
proto - > set_type ( static_cast < FieldDescriptorProto : : Type > (
absl : : implicit_cast < int > ( type ( ) ) ) ) ;
}
# else // PROTOBUF_FUTURE_EDITIONS
proto - > set_label ( static_cast < FieldDescriptorProto : : Label > (
absl : : implicit_cast < int > ( label ( ) ) ) ) ;
proto - > set_type ( static_cast < FieldDescriptorProto : : Type > (
absl : : implicit_cast < int > ( type ( ) ) ) ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
if ( is_extension ( ) ) {
if ( ! containing_type ( ) - > is_unqualified_placeholder_ ) {
@ -2995,9 +2960,7 @@ void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const {
proto - > mutable_options ( ) - > CopyFrom ( options ( ) ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
void FieldDescriptor : : CopyJsonNameTo ( FieldDescriptorProto * proto ) const {
@ -3009,9 +2972,7 @@ void OneofDescriptor::CopyTo(OneofDescriptorProto* proto) const {
if ( & options ( ) ! = & OneofOptions : : default_instance ( ) ) {
proto - > mutable_options ( ) - > CopyFrom ( options ( ) ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
void EnumDescriptor : : CopyTo ( EnumDescriptorProto * proto ) const {
@ -3032,9 +2993,7 @@ void EnumDescriptor::CopyTo(EnumDescriptorProto* proto) const {
if ( & options ( ) ! = & EnumOptions : : default_instance ( ) ) {
proto - > mutable_options ( ) - > CopyFrom ( options ( ) ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
void EnumValueDescriptor : : CopyTo ( EnumValueDescriptorProto * proto ) const {
@ -3044,9 +3003,7 @@ void EnumValueDescriptor::CopyTo(EnumValueDescriptorProto* proto) const {
if ( & options ( ) ! = & EnumValueOptions : : default_instance ( ) ) {
proto - > mutable_options ( ) - > CopyFrom ( options ( ) ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
void ServiceDescriptor : : CopyTo ( ServiceDescriptorProto * proto ) const {
@ -3059,9 +3016,7 @@ void ServiceDescriptor::CopyTo(ServiceDescriptorProto* proto) const {
if ( & options ( ) ! = & ServiceOptions : : default_instance ( ) ) {
proto - > mutable_options ( ) - > CopyFrom ( options ( ) ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
void MethodDescriptor : : CopyTo ( MethodDescriptorProto * proto ) const {
@ -3087,9 +3042,7 @@ void MethodDescriptor::CopyTo(MethodDescriptorProto* proto) const {
if ( server_streaming_ ) {
proto - > set_server_streaming ( true ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
RestoreFeaturesToOptions ( proto_features_ , proto ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
// DebugString methods ===============================================
@ -3097,23 +3050,19 @@ void MethodDescriptor::CopyTo(MethodDescriptorProto* proto) const {
namespace {
bool IsGroupSyntax ( const FieldDescriptor * desc ) {
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( FileDescriptorLegacy ( desc - > file ( ) ) . syntax ( ) = =
FileDescriptorLegacy : : SYNTAX_EDITIONS ) {
return false ;
}
# endif // PROTOBUF_FUTURE_EDITIONS
return desc - > type ( ) = = FieldDescriptor : : TYPE_GROUP ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
template < typename OptionsT >
void CopyFeaturesToOptions ( const FeatureSet * features , OptionsT * options ) {
if ( features ! = & FeatureSet : : default_instance ( ) ) {
* options - > mutable_features ( ) = * features ;
}
}
# endif // PROTOBUF_FUTURE_EDITIONS
bool RetrieveOptionsAssumingRightPool (
int depth , const Message & options ,
@ -3295,12 +3244,10 @@ std::string FileDescriptor::DebugStringWithOptions(
SourceLocationCommentPrinter syntax_comment ( this , path , " " ,
debug_string_options ) ;
syntax_comment . AddPreComment ( & contents ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( FileDescriptorLegacy ( this ) . syntax ( ) = =
FileDescriptorLegacy : : SYNTAX_EDITIONS ) {
absl : : SubstituteAndAppend ( & contents , " edition = \" $0 \" ; \n \n " , edition ( ) ) ;
} else // NOLINT(readability/braces)
# endif // PROTOBUF_FUTURE_EDITIONS
{
absl : : SubstituteAndAppend ( & contents , " syntax = \" $0 \" ; \n \n " ,
FileDescriptorLegacy : : SyntaxName (
@ -3341,9 +3288,7 @@ std::string FileDescriptor::DebugStringWithOptions(
}
FileOptions full_options = options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( proto_features_ , & full_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
if ( FormatLineOptions ( 0 , full_options , pool ( ) , & contents ) ) {
contents . append ( " \n " ) ; // add some space if we had options
}
@ -3424,9 +3369,7 @@ void Descriptor::DebugString(int depth, std::string* contents,
contents - > append ( " { \n " ) ;
MessageOptions full_options = options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( proto_features_ , & full_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
FormatLineOptions ( depth , full_options , file ( ) - > pool ( ) , contents ) ;
// Find all the 'group' types for fields and extensions; we will not output
@ -3472,9 +3415,7 @@ void Descriptor::DebugString(int depth, std::string* contents,
extension_range ( i ) - > end_number ( ) - 1 ) ;
}
ExtensionRangeOptions range_options = extension_range ( i ) - > options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( extension_range ( i ) - > proto_features_ , & range_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
std : : string formatted_options ;
if ( FormatBracketedOptions ( depth , range_options , file ( ) - > pool ( ) ,
& formatted_options ) ) {
@ -3586,14 +3527,12 @@ void FieldDescriptor::DebugString(
( is_optional ( ) & & ! FieldDescriptorLegacy ( this ) . has_optional_keyword ( ) ) ) {
label . clear ( ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
// Label is omitted for optional and required fields under editions.
if ( ( is_optional ( ) | | is_required ( ) ) & &
FileDescriptorLegacy ( file ( ) ) . syntax ( ) = =
FileDescriptorLegacy : : SYNTAX_EDITIONS ) {
label . clear ( ) ;
}
# endif // PROTOBUF_FUTURE_EDITIONS
SourceLocationCommentPrinter comment_printer ( this , prefix ,
debug_string_options ) ;
@ -3622,9 +3561,7 @@ void FieldDescriptor::DebugString(
}
FieldOptions full_options = options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( proto_features_ , & full_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
std : : string formatted_options ;
if ( FormatBracketedOptions ( depth , full_options , file ( ) - > pool ( ) ,
& formatted_options ) ) {
@ -3674,9 +3611,7 @@ void OneofDescriptor::DebugString(
absl : : SubstituteAndAppend ( contents , " $0oneof $1 { " , prefix , name ( ) ) ;
OneofOptions full_options = options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( proto_features_ , & full_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
FormatLineOptions ( depth , full_options , containing_type ( ) - > file ( ) - > pool ( ) ,
contents ) ;
@ -3717,9 +3652,7 @@ void EnumDescriptor::DebugString(
absl : : SubstituteAndAppend ( contents , " $0enum $1 { \n " , prefix , name ( ) ) ;
EnumOptions full_options = options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( proto_features_ , & full_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
FormatLineOptions ( depth , full_options , file ( ) - > pool ( ) , contents ) ;
for ( int i = 0 ; i < value_count ( ) ; i + + ) {
@ -3780,9 +3713,7 @@ void EnumValueDescriptor::DebugString(
absl : : SubstituteAndAppend ( contents , " $0$1 = $2 " , prefix , name ( ) , number ( ) ) ;
EnumValueOptions full_options = options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( proto_features_ , & full_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
std : : string formatted_options ;
if ( FormatBracketedOptions ( depth , full_options , type ( ) - > file ( ) - > pool ( ) ,
& formatted_options ) ) {
@ -3815,9 +3746,7 @@ void ServiceDescriptor::DebugString(
absl : : SubstituteAndAppend ( contents , " service $0 { \n " , name ( ) ) ;
ServiceOptions full_options = options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( proto_features_ , & full_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
FormatLineOptions ( 1 , full_options , file ( ) - > pool ( ) , contents ) ;
for ( int i = 0 ; i < method_count ( ) ; i + + ) {
@ -3857,9 +3786,7 @@ void MethodDescriptor::DebugString(
client_streaming ( ) ? " stream " : " " , server_streaming ( ) ? " stream " : " " ) ;
MethodOptions full_options = options ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
CopyFeaturesToOptions ( proto_features_ , & full_options ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
std : : string formatted_options ;
if ( FormatLineOptions ( depth , full_options , service ( ) - > file ( ) - > pool ( ) ,
& formatted_options ) ) {
@ -3875,23 +3802,12 @@ void MethodDescriptor::DebugString(
// Feature methods ===============================================
bool EnumDescriptor : : is_closed ( ) const {
# ifdef PROTOBUF_FUTURE_EDITIONS
return features ( ) . enum_type ( ) = = FeatureSet : : CLOSED ;
# else // PROTOBUF_FUTURE_EDITIONS
PROTOBUF_IGNORE_DEPRECATION_START
return file ( ) - > syntax ( ) ! = FileDescriptor : : SYNTAX_PROTO3 ;
PROTOBUF_IGNORE_DEPRECATION_STOP
# endif // PROTOBUF_FUTURE_EDITIONS
}
bool FieldDescriptor : : is_packed ( ) const {
if ( ! is_packable ( ) ) return false ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( features ( ) . repeated_field_encoding ( ) ! = FeatureSet : : PACKED ) {
# else // PROTOBUF_FUTURE_EDITIONS
if ( FileDescriptorLegacy ( file_ ) . syntax ( ) = =
FileDescriptorLegacy : : Syntax : : SYNTAX_PROTO2 ) {
# endif // PROTOBUF_FUTURE_EDITIONS
return ( options_ ! = nullptr ) & & options_ - > packed ( ) ;
} else {
return options_ = = nullptr | | ! options_ - > has_packed ( ) | | options_ - > packed ( ) ;
@ -3899,13 +3815,8 @@ bool FieldDescriptor::is_packed() const {
}
static bool IsStrictUtf8 ( const FieldDescriptor * field ) {
# ifdef PROTOBUF_FUTURE_EDITIONS
return internal : : InternalFeatureHelper : : GetFeatures ( * field )
. string_field_validation ( ) = = FeatureSet : : MANDATORY ;
# else // PROTOBUF_FUTURE_EDITIONS
return FileDescriptorLegacy ( field - > file ( ) ) . syntax ( ) = =
FileDescriptorLegacy : : Syntax : : SYNTAX_PROTO3 ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
bool FieldDescriptor : : requires_utf8_validation ( ) const {
@ -3915,25 +3826,17 @@ bool FieldDescriptor::requires_utf8_validation() const {
bool FieldDescriptor : : has_presence ( ) const {
if ( is_repeated ( ) ) return false ;
return cpp_type ( ) = = CPPTYPE_MESSAGE | | containing_oneof ( ) | |
# ifdef PROTOBUF_FUTURE_EDITIONS
features ( ) . field_presence ( ) ! = FeatureSet : : IMPLICIT ;
# else // PROTOBUF_FUTURE_EDITIONS
FileDescriptorLegacy ( file_ ) . syntax ( ) = =
FileDescriptorLegacy : : Syntax : : SYNTAX_PROTO2 ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
bool FieldDescriptor : : legacy_enum_field_treated_as_closed ( ) const {
# ifdef PROTOBUF_FUTURE_EDITIONS
return type ( ) = = TYPE_ENUM & &
( features ( ) . GetExtension ( pb : : cpp ) . legacy_closed_enum ( ) | |
enum_type ( ) - > is_closed ( ) ) ;
# else // PROTOBUF_FUTURE_EDITIONS
return type ( ) = = TYPE_ENUM & &
( FileDescriptorLegacy ( file_ ) . syntax ( ) = =
FileDescriptorLegacy : : Syntax : : SYNTAX_PROTO2 | |
enum_type ( ) - > is_closed ( ) ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
// Location methods ===============================================
@ -4134,9 +4037,7 @@ class DescriptorBuilder {
DescriptorPool : : Tables * tables_ ; // for convenience
DescriptorPool : : ErrorCollector * error_collector_ ;
# ifdef PROTOBUF_FUTURE_EDITIONS
absl : : optional < FeatureResolver > feature_resolver_ = absl : : nullopt ;
# endif // PROTOBUF_FUTURE_EDITIONS
// As we build descriptors we store copies of the options messages in
// them. We put pointers to those copies in this vector, as we build, so we
@ -4331,7 +4232,6 @@ class DescriptorBuilder {
absl : : Span < const int > options_path , absl : : string_view option_name ,
internal : : FlatAllocator & alloc ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
// Allocates and resolves any feature sets that need to be owned by a given
// descriptor. This also strips features out of the mutable options message to
// prevent leaking of unresolved features.
@ -4361,7 +4261,6 @@ class DescriptorBuilder {
const DescriptorT * descriptor ) ;
void PostProcessFieldFeatures ( FieldDescriptor & field ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
// 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
@ -4469,13 +4368,11 @@ class DescriptorBuilder {
// Otherwise returns true.
bool InterpretOptions ( OptionsToInterpret * options_to_interpret ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
// Interprets the uninterpreted feature options in the specified Options
// message. On error, calls AddError() on the underlying builder and returns
// false. Otherwise returns true.
bool InterpretFeatures ( OptionsToInterpret * options_to_interpret ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
// Updates the given source code info by re-writing uninterpreted option
// locations to refer to the corresponding interpreted option.
void UpdateSourceCodeInfo ( SourceCodeInfo * info ) ;
@ -4721,14 +4618,12 @@ DescriptorBuilder::DescriptorBuilder(
had_errors_ ( false ) ,
possible_undeclared_dependency_ ( nullptr ) ,
undefine_resolved_name_ ( " " ) {
# ifdef PROTOBUF_FUTURE_EDITIONS
// Ensure that any lazily loaded static initializers from the generated pool
// (e.g. from bootstrapped protos) are run before building any descriptors. We
// have to avoid registering these pre-main, because we need to ensure that
// the linker --gc-sections step can strip out the full runtime if it is
// unused.
pb : : cpp . LazyRegister ( ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
DescriptorBuilder : : ~ DescriptorBuilder ( ) { }
@ -5080,10 +4975,8 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld(
alloc . AllocateStrings ( placeholder_name , placeholder_full_name ) ;
placeholder_enum - > file_ = placeholder_file ;
placeholder_enum - > options_ = & EnumOptions : : default_instance ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
placeholder_enum - > proto_features_ = & FeatureSet : : default_instance ( ) ;
placeholder_enum - > merged_features_ = & FeatureSet : : default_instance ( ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
placeholder_enum - > is_placeholder_ = true ;
placeholder_enum - > is_unqualified_placeholder_ = ( name [ 0 ] ! = ' . ' ) ;
@ -5121,10 +5014,8 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld(
alloc . AllocateStrings ( placeholder_name , placeholder_full_name ) ;
placeholder_message - > file_ = placeholder_file ;
placeholder_message - > options_ = & MessageOptions : : default_instance ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
placeholder_message - > proto_features_ = & FeatureSet : : default_instance ( ) ;
placeholder_message - > merged_features_ = & FeatureSet : : default_instance ( ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
placeholder_message - > is_placeholder_ = true ;
placeholder_message - > is_unqualified_placeholder_ = ( name [ 0 ] ! = ' . ' ) ;
@ -5137,12 +5028,10 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld(
placeholder_message - > extension_ranges_ [ 0 ] . end_ =
FieldDescriptor : : kMaxNumber + 1 ;
placeholder_message - > extension_ranges_ [ 0 ] . options_ = nullptr ;
# ifdef PROTOBUF_FUTURE_EDITIONS
placeholder_message - > extension_ranges_ [ 0 ] . proto_features_ =
& FeatureSet : : default_instance ( ) ;
placeholder_message - > extension_ranges_ [ 0 ] . merged_features_ =
& FeatureSet : : default_instance ( ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
return Symbol ( placeholder_message ) ;
@ -5172,10 +5061,8 @@ FileDescriptor* DescriptorPool::NewPlaceholderFileWithMutexHeld(
placeholder - > package_ = & internal : : GetEmptyString ( ) ;
placeholder - > pool_ = this ;
placeholder - > options_ = & FileOptions : : default_instance ( ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
placeholder - > proto_features_ = & FeatureSet : : default_instance ( ) ;
placeholder - > merged_features_ = & FeatureSet : : default_instance ( ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
placeholder - > tables_ = & FileDescriptorTables : : GetEmptyInstance ( ) ;
placeholder - > source_code_info_ = & SourceCodeInfo : : default_instance ( ) ;
placeholder - > is_placeholder_ = true ;
@ -5322,10 +5209,8 @@ void DescriptorBuilder::AllocateOptions(
descriptor - > full_name ( ) , descriptor - > full_name ( ) , proto , options_path ,
option_name , alloc ) ;
descriptor - > options_ = options ;
# ifdef PROTOBUF_FUTURE_EDITIONS
descriptor - > proto_features_ = & FeatureSet : : default_instance ( ) ;
descriptor - > merged_features_ = & FeatureSet : : default_instance ( ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
// We specialize for FileDescriptor.
@ -5339,10 +5224,8 @@ void DescriptorBuilder::AllocateOptions(const FileDescriptorProto& proto,
absl : : StrCat ( descriptor - > package ( ) , " .dummy " ) , descriptor - > name ( ) , proto ,
options_path , " google.protobuf.FileOptions " , alloc ) ;
descriptor - > options_ = options ;
# ifdef PROTOBUF_FUTURE_EDITIONS
descriptor - > proto_features_ = & FeatureSet : : default_instance ( ) ;
descriptor - > merged_features_ = & FeatureSet : : default_instance ( ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
}
template < class DescriptorT >
@ -5405,7 +5288,6 @@ typename DescriptorT::OptionsType* DescriptorBuilder::AllocateOptionsImpl(
return options ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
template < class DescriptorT >
void DescriptorBuilder : : ResolveFeaturesImpl (
const typename DescriptorT : : Proto & proto , DescriptorT * descriptor ,
@ -5510,8 +5392,6 @@ void DescriptorBuilder::PostProcessFieldFeatures(FieldDescriptor& field) {
}
}
# endif // PROTOBUF_FUTURE_EDITIONS
// A common pattern: We want to convert a repeated field in the descriptor
// to an array of values, calling some method to build each value.
# define BUILD_ARRAY(INPUT, OUTPUT, NAME, METHOD, PARENT) \
@ -5595,9 +5475,7 @@ static void PlanAllocationSize(
alloc . PlanArray < std : : string > ( 2 * values . size ( ) ) ; // name + full_name
for ( const auto & v : values ) {
if ( v . has_options ( ) ) alloc . PlanArray < EnumValueOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( HasFeatures ( v . options ( ) ) ) alloc . PlanArray < FeatureSet > ( 2 ) ;
# endif // !PROTOBUF_FUTURE_EDITIONS
}
}
@ -5608,9 +5486,7 @@ static void PlanAllocationSize(
alloc . PlanArray < std : : string > ( 2 * enums . size ( ) ) ; // name + full_name
for ( const auto & e : enums ) {
if ( e . has_options ( ) ) alloc . PlanArray < EnumOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( HasFeatures ( e . options ( ) ) ) alloc . PlanArray < FeatureSet > ( 2 ) ;
# endif // !PROTOBUF_FUTURE_EDITIONS
PlanAllocationSize ( e . value ( ) , alloc ) ;
alloc . PlanArray < EnumDescriptor : : ReservedRange > ( e . reserved_range_size ( ) ) ;
alloc . PlanArray < const std : : string * > ( e . reserved_name_size ( ) ) ;
@ -5625,9 +5501,7 @@ static void PlanAllocationSize(
alloc . PlanArray < std : : string > ( 2 * oneofs . size ( ) ) ; // name + full_name
for ( const auto & oneof : oneofs ) {
if ( oneof . has_options ( ) ) alloc . PlanArray < OneofOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( HasFeatures ( oneof . options ( ) ) ) alloc . PlanArray < FeatureSet > ( 2 ) ;
# endif // !PROTOBUF_FUTURE_EDITIONS
}
}
@ -5637,9 +5511,7 @@ static void PlanAllocationSize(
alloc . PlanArray < FieldDescriptor > ( fields . size ( ) ) ;
for ( const auto & field : fields ) {
if ( field . has_options ( ) ) alloc . PlanArray < FieldOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( HasFeatures ( field . options ( ) ) ) alloc . PlanArray < FeatureSet > ( 2 ) ;
# endif // !PROTOBUF_FUTURE_EDITIONS
alloc . PlanFieldNames ( field . name ( ) ,
field . has_json_name ( ) ? & field . json_name ( ) : nullptr ) ;
if ( field . has_default_value ( ) & & field . has_type ( ) & &
@ -5657,9 +5529,7 @@ static void PlanAllocationSize(
alloc . PlanArray < Descriptor : : ExtensionRange > ( ranges . size ( ) ) ;
for ( const auto & r : ranges ) {
if ( r . has_options ( ) ) alloc . PlanArray < ExtensionRangeOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( HasFeatures ( r . options ( ) ) ) alloc . PlanArray < FeatureSet > ( 2 ) ;
# endif // !PROTOBUF_FUTURE_EDITIONS
}
}
@ -5671,9 +5541,7 @@ static void PlanAllocationSize(
for ( const auto & message : messages ) {
if ( message . has_options ( ) ) alloc . PlanArray < MessageOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( HasFeatures ( message . options ( ) ) ) alloc . PlanArray < FeatureSet > ( 2 ) ;
# endif // !PROTOBUF_FUTURE_EDITIONS
PlanAllocationSize ( message . nested_type ( ) , alloc ) ;
PlanAllocationSize ( message . field ( ) , alloc ) ;
PlanAllocationSize ( message . extension ( ) , alloc ) ;
@ -5693,9 +5561,7 @@ static void PlanAllocationSize(
alloc . PlanArray < std : : string > ( 2 * methods . size ( ) ) ; // name + full_name
for ( const auto & m : methods ) {
if ( m . has_options ( ) ) alloc . PlanArray < MethodOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( HasFeatures ( m . options ( ) ) ) alloc . PlanArray < FeatureSet > ( 2 ) ;
# endif // !PROTOBUF_FUTURE_EDITIONS
}
}
@ -5706,9 +5572,7 @@ static void PlanAllocationSize(
alloc . PlanArray < std : : string > ( 2 * services . size ( ) ) ; // name + full_name
for ( const auto & service : services ) {
if ( service . has_options ( ) ) alloc . PlanArray < ServiceOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( HasFeatures ( service . options ( ) ) ) alloc . PlanArray < FeatureSet > ( 2 ) ;
# endif // !PROTOBUF_FUTURE_EDITIONS
PlanAllocationSize ( service . method ( ) , alloc ) ;
}
}
@ -5717,20 +5581,15 @@ static void PlanAllocationSize(const FileDescriptorProto& proto,
internal : : FlatAllocator & alloc ) {
alloc . PlanArray < FileDescriptor > ( 1 ) ;
alloc . PlanArray < FileDescriptorTables > ( 1 ) ;
alloc . PlanArray < std : : string > ( 2
# ifdef PROTOBUF_FUTURE_EDITIONS
+ ( proto . has_edition ( ) ? 1 : 0 )
# endif // !PROTOBUF_FUTURE_EDITIONS
) ; // name + package
alloc . PlanArray < std : : string > (
2 + ( proto . has_edition ( ) ? 1 : 0 ) ) ; // name + package
if ( proto . has_options ( ) ) alloc . PlanArray < FileOptions > ( 1 ) ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( proto . has_edition ( ) ) {
alloc . PlanArray < FeatureSet > ( 1 ) ;
if ( HasFeatures ( proto . options ( ) ) ) {
alloc . PlanArray < FeatureSet > ( 1 ) ;
}
}
# endif // !PROTOBUF_FUTURE_EDITIONS
if ( proto . has_source_code_info ( ) ) alloc . PlanArray < SourceCodeInfo > ( 1 ) ;
PlanAllocationSize ( proto . service ( ) , alloc ) ;
@ -5832,7 +5691,6 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
FileDescriptor * result = alloc . AllocateArray < FileDescriptor > ( 1 ) ;
file_ = result ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( proto . has_edition ( ) ) {
Symbol symbol = FindSymbolNotEnforcingDeps ( " google.protobuf.FeatureSet " ) ;
const Descriptor * descriptor = symbol . descriptor ( ) ;
@ -5854,7 +5712,6 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
feature_resolver_ . emplace ( std : : move ( feature_resolver ) . value ( ) ) ;
}
}
# endif // PROTOBUF_FUTURE_EDITIONS
result - > is_placeholder_ = false ;
result - > finished_building_ = false ;
@ -5881,21 +5738,17 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
file_ - > syntax_ = FileDescriptorLegacy : : SYNTAX_PROTO2 ;
} else if ( proto . syntax ( ) = = " proto3 " ) {
file_ - > syntax_ = FileDescriptorLegacy : : SYNTAX_PROTO3 ;
# ifdef PROTOBUF_FUTURE_EDITIONS
} else if ( proto . syntax ( ) = = " editions " ) {
file_ - > syntax_ = FileDescriptorLegacy : : SYNTAX_EDITIONS ;
# endif // !PROTOBUF_FUTURE_EDITIONS
} else {
file_ - > syntax_ = FileDescriptorLegacy : : SYNTAX_UNKNOWN ;
AddError ( proto . name ( ) , proto , DescriptorPool : : ErrorCollector : : OTHER , [ & ] {
return absl : : StrCat ( " Unrecognized syntax: " , proto . syntax ( ) ) ;
} ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( proto . has_edition ( ) ) {
file_ - > edition_ = alloc . AllocateStrings ( proto . edition ( ) ) ;
}
# endif // !PROTOBUF_FUTURE_EDITIONS
result - > name_ = alloc . AllocateStrings ( proto . name ( ) ) ;
if ( proto . has_package ( ) ) {
@ -5964,7 +5817,6 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
return nullptr ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
// Look for feature extensions in regular imports.
if ( feature_resolver_ . has_value ( ) & & dependency ! = nullptr ) {
absl : : Status status = feature_resolver_ - > RegisterExtensions ( * dependency ) ;
@ -5974,7 +5826,6 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
[ & ] { return std : : string ( status . message ( ) ) ; } ) ;
}
}
# endif // PROTOBUF_FUTURE_EDITIONS
if ( dependency = = nullptr ) {
if ( ! pool_ - > lazily_build_dependencies_ ) {
@ -6097,7 +5948,6 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
SuggestFieldNumbers ( result , proto ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
// Interpret only the feature options first. This has to be done in two
// passes, since options defined in this file may have features attached
// to them.
@ -6130,7 +5980,6 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
internal : : VisitDescriptors ( * result , [ & ] ( const FieldDescriptor & field ) {
PostProcessFieldFeatures ( const_cast < FieldDescriptor & > ( field ) ) ;
} ) ;
# endif // PROTOBUF_FUTURE_EDITIONS
// Interpret any remaining uninterpreted options gathered into
// options_to_interpret_ during descriptor building. Cross-linking has made
@ -6479,15 +6328,11 @@ void DescriptorBuilder::CheckFieldJsonNameUniqueness(
} ;
bool involves_default = ! details . is_custom | | ! match . is_custom ;
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( descriptor - > features ( ) . json_format ( ) = =
FeatureSet : : LEGACY_BEST_EFFORT & &
involves_default ) {
# else // PROTOBUF_FUTURE_EDITIONS
if ( syntax = = FileDescriptorLegacy : : SYNTAX_PROTO2 & & involves_default ) {
# endif // PROTOBUF_FUTURE_EDITIONS
// TODO(b/261750676) Upgrade this to an error once downstream protos have
// been fixed.
// TODO(b/261750676) Upgrade this to an error once downstream protos
// have been fixed.
AddWarning ( message_name , field , DescriptorPool : : ErrorCollector : : NAME ,
make_error ) ;
} else {
@ -8004,7 +7849,6 @@ static bool IsStringMapType(const FieldDescriptor* field) {
void DescriptorBuilder : : ValidateFieldFeatures (
const FieldDescriptor * field , const FieldDescriptorProto & proto ) {
# ifdef PROTOBUF_FUTURE_EDITIONS
// Rely on our legacy validation for proto2/proto3 files.
if ( IsLegacyFeatureSet ( field - > features ( ) ) ) return ;
@ -8060,7 +7904,6 @@ void DescriptorBuilder::ValidateFieldFeatures(
AddError ( field - > full_name ( ) , proto , DescriptorPool : : ErrorCollector : : NAME ,
" Only repeated fields can specify `repeated_field_encoding`. " ) ;
}
# endif // PROTOBUF_FUTURE_EDITIONS
}
void DescriptorBuilder : : ValidateOptions ( const EnumDescriptor * enm ,
@ -8459,12 +8302,10 @@ bool DescriptorBuilder::OptionInterpreter::InterpretOptions(
OptionsToInterpret * options_to_interpret ) {
return InterpretOptionsImpl ( options_to_interpret , /*features=*/ false ) ;
}
# ifdef PROTOBUF_FUTURE_EDITIONS
bool DescriptorBuilder : : OptionInterpreter : : InterpretFeatures (
OptionsToInterpret * options_to_interpret ) {
return InterpretOptionsImpl ( options_to_interpret , /*features=*/ true ) ;
}
# endif // PROTOBUF_FUTURE_EDITIONS
bool DescriptorBuilder : : OptionInterpreter : : InterpretOptionsImpl (
OptionsToInterpret * options_to_interpret , bool features ) {
// Note that these may be in different pools, so we can't use the same
@ -9612,12 +9453,10 @@ Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, bool is_lite) {
}
bool IsLazilyInitializedFile ( absl : : string_view filename ) {
# ifdef PROTOBUF_FUTURE_EDITIONS
if ( filename = = " third_party/protobuf/cpp_features.proto " | |
filename = = " google/protobuf/cpp_features.proto " ) {
return true ;
}
# endif // PROTOBUF_FUTURE_EDITIONS
return filename = = " net/proto2/proto/descriptor.proto " | |
filename = = " google/protobuf/descriptor.proto " ;
}
@ -9625,7 +9464,6 @@ bool IsLazilyInitializedFile(absl::string_view filename) {
} // namespace cpp
} // namespace internal
# ifdef PROTOBUF_FUTURE_EDITIONS
absl : : string_view FileDescriptor : : edition ( ) const {
// ASLR will help give this a random value across processes.
static const void * kAntiHyrumText = & kAntiHyrumText ;
@ -9635,7 +9473,6 @@ absl::string_view FileDescriptor::edition() const {
return edition_ = = nullptr ? anti_hyrum_string : * edition_ ;
}
# endif // !PROTOBUF_FUTURE_EDITIONS
} // namespace protobuf
} // namespace google