@@ -2612,10 +2612,12 @@ void FileDescriptor::CopyHeadingTo(FileDescriptorProto* proto) const {
2612
2612
}
2613
2613
2614
2614
// TODO(liujisi): Also populate when syntax="proto2".
2615
- if (syntax () == SYNTAX_PROTO3
2615
+ FileDescriptorLegacy::Syntax syntax = FileDescriptorLegacy (this ).syntax ();
2616
+ if (syntax == FileDescriptorLegacy::Syntax::SYNTAX_PROTO3
2616
2617
) {
2617
- proto->set_syntax (SyntaxName (syntax () ));
2618
+ proto->set_syntax (FileDescriptorLegacy:: SyntaxName (syntax));
2618
2619
}
2620
+
2619
2621
if (&options () != &FileOptions::default_instance ()) {
2620
2622
*proto->mutable_options () = options ();
2621
2623
}
@@ -3010,8 +3012,9 @@ std::string FileDescriptor::DebugStringWithOptions(
3010
3012
SourceLocationCommentPrinter syntax_comment (this , path, " " ,
3011
3013
debug_string_options);
3012
3014
syntax_comment.AddPreComment (&contents);
3013
- absl::SubstituteAndAppend (&contents, " syntax = \" $0\" ;\n\n " ,
3014
- SyntaxName (syntax ()));
3015
+ absl::SubstituteAndAppend (
3016
+ &contents, " syntax = \" $0\" ;\n\n " ,
3017
+ FileDescriptorLegacy::SyntaxName (FileDescriptorLegacy (this ).syntax ()));
3015
3018
syntax_comment.AddPostComment (&contents);
3016
3019
}
3017
3020
@@ -3282,7 +3285,7 @@ void FieldDescriptor::DebugString(
3282
3285
3283
3286
// Label is omitted for maps, oneof, and plain proto3 fields.
3284
3287
if (is_map () || real_containing_oneof () ||
3285
- (is_optional () && !has_optional_keyword ())) {
3288
+ (is_optional () && !FieldDescriptorLegacy ( this ). has_optional_keyword ())) {
3286
3289
label.clear ();
3287
3290
}
3288
3291
@@ -3573,7 +3576,8 @@ bool FileDescriptor::GetSourceLocation(SourceLocation* out_location) const {
3573
3576
3574
3577
bool FieldDescriptor::is_packed () const {
3575
3578
if (!is_packable ()) return false ;
3576
- if (file_->syntax () == FileDescriptor::SYNTAX_PROTO2) {
3579
+ if (FileDescriptorLegacy (file_).syntax () ==
3580
+ FileDescriptorLegacy::Syntax::SYNTAX_PROTO2) {
3577
3581
return (options_ != nullptr ) && options_->packed ();
3578
3582
} else {
3579
3583
return options_ == nullptr || !options_->has_packed () || options_->packed ();
@@ -3582,7 +3586,8 @@ bool FieldDescriptor::is_packed() const {
3582
3586
3583
3587
bool FieldDescriptor::requires_utf8_validation () const {
3584
3588
return type () == TYPE_STRING &&
3585
- file ()->syntax () == FileDescriptor::SYNTAX_PROTO3;
3589
+ FileDescriptorLegacy (file_).syntax () ==
3590
+ FileDescriptorLegacy::Syntax::SYNTAX_PROTO3;
3586
3591
}
3587
3592
3588
3593
bool Descriptor::GetSourceLocation (SourceLocation* out_location) const {
@@ -3989,7 +3994,7 @@ class DescriptorBuilder {
3989
3994
const Descriptor* result);
3990
3995
void CheckFieldJsonNameUniqueness (const std::string& message_name,
3991
3996
const DescriptorProto& message,
3992
- FileDescriptor ::Syntax syntax,
3997
+ FileDescriptorLegacy ::Syntax syntax,
3993
3998
bool use_custom_names);
3994
3999
void CheckEnumValueUniqueness (const EnumDescriptorProto& proto,
3995
4000
const EnumDescriptor* result);
@@ -4711,7 +4716,7 @@ FileDescriptor* DescriptorPool::NewPlaceholderFileWithMutexHeld(
4711
4716
placeholder->tables_ = &FileDescriptorTables::GetEmptyInstance ();
4712
4717
placeholder->source_code_info_ = &SourceCodeInfo::default_instance ();
4713
4718
placeholder->is_placeholder_ = true ;
4714
- placeholder->syntax_ = FileDescriptor ::SYNTAX_UNKNOWN;
4719
+ placeholder->syntax_ = FileDescriptorLegacy ::SYNTAX_UNKNOWN;
4715
4720
placeholder->finished_building_ = true ;
4716
4721
// All other fields are zero or nullptr.
4717
4722
@@ -5226,11 +5231,11 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
5226
5231
// TODO(liujisi): Report error when the syntax is empty after all the protos
5227
5232
// have added the syntax statement.
5228
5233
if (proto.syntax ().empty () || proto.syntax () == " proto2" ) {
5229
- file_->syntax_ = FileDescriptor ::SYNTAX_PROTO2;
5234
+ file_->syntax_ = FileDescriptorLegacy ::SYNTAX_PROTO2;
5230
5235
} else if (proto.syntax () == " proto3" ) {
5231
- file_->syntax_ = FileDescriptor ::SYNTAX_PROTO3;
5236
+ file_->syntax_ = FileDescriptorLegacy ::SYNTAX_PROTO3;
5232
5237
} else {
5233
- file_->syntax_ = FileDescriptor ::SYNTAX_UNKNOWN;
5238
+ file_->syntax_ = FileDescriptorLegacy ::SYNTAX_UNKNOWN;
5234
5239
AddError (proto.name (), proto, DescriptorPool::ErrorCollector::OTHER, [&] {
5235
5240
return absl::StrCat (" Unrecognized syntax: " , proto.syntax ());
5236
5241
});
@@ -5681,11 +5686,12 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
5681
5686
5682
5687
void DescriptorBuilder::CheckFieldJsonNameUniqueness (
5683
5688
const DescriptorProto& proto, const Descriptor* result) {
5684
- FileDescriptor::Syntax syntax = result->file ()->syntax ();
5689
+ FileDescriptorLegacy::Syntax syntax =
5690
+ FileDescriptorLegacy (result->file ()).syntax ();
5685
5691
std::string message_name = result->full_name ();
5686
5692
if (pool_->deprecated_legacy_json_field_conflicts_ ||
5687
5693
IsLegacyJsonFieldConflictEnabled (result->options ())) {
5688
- if (syntax == FileDescriptor ::SYNTAX_PROTO3) {
5694
+ if (syntax == FileDescriptorLegacy::Syntax ::SYNTAX_PROTO3) {
5689
5695
// Only check default JSON names for conflicts in proto3. This is legacy
5690
5696
// behavior that will be removed in a later version.
5691
5697
CheckFieldJsonNameUniqueness (message_name, proto, syntax, false );
@@ -5725,7 +5731,7 @@ bool JsonNameLooksLikeExtension(std::string name) {
5725
5731
5726
5732
void DescriptorBuilder::CheckFieldJsonNameUniqueness (
5727
5733
const std::string& message_name, const DescriptorProto& message,
5728
- FileDescriptor ::Syntax syntax, bool use_custom_names) {
5734
+ FileDescriptorLegacy ::Syntax syntax, bool use_custom_names) {
5729
5735
absl::flat_hash_map<std::string, JsonNameDetails> name_to_field;
5730
5736
for (const FieldDescriptorProto& field : message.field ()) {
5731
5737
JsonNameDetails details = GetJsonNameDetails (&field, use_custom_names);
@@ -5769,7 +5775,7 @@ void DescriptorBuilder::CheckFieldJsonNameUniqueness(
5769
5775
};
5770
5776
5771
5777
bool involves_default = !details.is_custom || !match.is_custom ;
5772
- if (syntax == FileDescriptor ::SYNTAX_PROTO2 && involves_default) {
5778
+ if (syntax == FileDescriptorLegacy ::SYNTAX_PROTO2 && involves_default) {
5773
5779
// TODO(b/261750676) Upgrade this to an error once downstream protos have
5774
5780
// been fixed.
5775
5781
AddWarning (message_name, field, DescriptorPool::ErrorCollector::NAME,
@@ -5808,7 +5814,8 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
5808
5814
result->proto3_optional_ = proto.proto3_optional ();
5809
5815
5810
5816
if (proto.proto3_optional () &&
5811
- file_->syntax () != FileDescriptor::SYNTAX_PROTO3) {
5817
+ FileDescriptorLegacy (file_).syntax () !=
5818
+ FileDescriptorLegacy::Syntax::SYNTAX_PROTO3) {
5812
5819
AddError (result->full_name (), proto, DescriptorPool::ErrorCollector::TYPE,
5813
5820
[&] {
5814
5821
return absl::StrCat (
@@ -6221,7 +6228,8 @@ void DescriptorBuilder::CheckEnumValueUniqueness(
6221
6228
// compatibility we issue only a warning for proto2.
6222
6229
if ((pool_->deprecated_legacy_json_field_conflicts_ ||
6223
6230
IsLegacyJsonFieldConflictEnabled (result->options ())) &&
6224
- result->file ()->syntax () == FileDescriptor::SYNTAX_PROTO2) {
6231
+ FileDescriptorLegacy (result->file ()).syntax () ==
6232
+ FileDescriptorLegacy::Syntax::SYNTAX_PROTO2) {
6225
6233
AddWarning (value->full_name (), proto.value (i),
6226
6234
DescriptorPool::ErrorCollector::NAME, make_error);
6227
6235
continue ;
@@ -6585,7 +6593,7 @@ void DescriptorBuilder::CrossLinkMessage(Descriptor* message,
6585
6593
const FieldDescriptor* field = message->field (i);
6586
6594
if (field->proto3_optional_ ) {
6587
6595
if (!field->containing_oneof () ||
6588
- !field->containing_oneof ()-> is_synthetic ()) {
6596
+ !OneofDescriptorLegacy ( field->containing_oneof ()). is_synthetic ()) {
6589
6597
AddError (message->full_name (), proto.field (i),
6590
6598
DescriptorPool::ErrorCollector::OTHER,
6591
6599
" Fields with proto3_optional set must be "
@@ -6598,7 +6606,7 @@ void DescriptorBuilder::CrossLinkMessage(Descriptor* message,
6598
6606
int first_synthetic = -1 ;
6599
6607
for (int i = 0 ; i < message->oneof_decl_count (); i++) {
6600
6608
const OneofDescriptor* oneof = message->oneof_decl (i);
6601
- if (oneof-> is_synthetic ()) {
6609
+ if (OneofDescriptorLegacy ( oneof). is_synthetic ()) {
6602
6610
if (first_synthetic == -1 ) {
6603
6611
first_synthetic = i;
6604
6612
}
@@ -7140,7 +7148,8 @@ void DescriptorBuilder::ValidateFileOptions(FileDescriptor* file,
7140
7148
}
7141
7149
}
7142
7150
}
7143
- if (file->syntax () == FileDescriptor::SYNTAX_PROTO3) {
7151
+ if (FileDescriptorLegacy (file).syntax () ==
7152
+ FileDescriptorLegacy::Syntax::SYNTAX_PROTO3) {
7144
7153
ValidateProto3 (file, proto);
7145
7154
}
7146
7155
}
@@ -7203,8 +7212,10 @@ void DescriptorBuilder::ValidateProto3Field(FieldDescriptor* field,
7203
7212
}
7204
7213
if (field->cpp_type () == FieldDescriptor::CPPTYPE_ENUM &&
7205
7214
field->enum_type () &&
7206
- field->enum_type ()->file ()->syntax () != FileDescriptor::SYNTAX_PROTO3 &&
7207
- field->enum_type ()->file ()->syntax () != FileDescriptor::SYNTAX_UNKNOWN) {
7215
+ FileDescriptorLegacy (field->enum_type ()->file ()).syntax () !=
7216
+ FileDescriptorLegacy::Syntax::SYNTAX_PROTO3 &&
7217
+ FileDescriptorLegacy (field->enum_type ()->file ()).syntax () !=
7218
+ FileDescriptorLegacy::Syntax::SYNTAX_UNKNOWN) {
7208
7219
// Proto3 messages can only use Proto3 enum types; otherwise we can't
7209
7220
// guarantee that the default value is zero.
7210
7221
AddError (
0 commit comments