diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index 23a2fa0b4334..13a340e7ceec 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -133,7 +133,6 @@ cc_library( ":code_generator", ":importer", ":retention", - "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler/allowlists", "@com_google_absl//absl/algorithm", diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index bc7cc97506d0..e879f149bda3 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -22,7 +22,6 @@ #include "absl/strings/str_cat.h" #include "absl/types/span.h" #include "google/protobuf/compiler/allowlists/allowlists.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/descriptor_visitor.h" #include "google/protobuf/feature_resolver.h" @@ -979,7 +978,8 @@ namespace { bool ContainsProto3Optional(const Descriptor* desc) { for (int i = 0; i < desc->field_count(); i++) { - if (FieldDescriptorLegacy(desc->field(i)).has_optional_keyword()) { + if (desc->field(i)->real_containing_oneof() == nullptr && + desc->field(i)->containing_oneof() != nullptr) { return true; } } diff --git a/src/google/protobuf/compiler/java/BUILD.bazel b/src/google/protobuf/compiler/java/BUILD.bazel index 1f771c8f6ea0..bac458730422 100644 --- a/src/google/protobuf/compiler/java/BUILD.bazel +++ b/src/google/protobuf/compiler/java/BUILD.bazel @@ -37,7 +37,6 @@ cc_library( visibility = ["//pkg:__pkg__"], deps = [ ":java_features_bootstrap", - "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:versions", @@ -130,7 +129,6 @@ cc_library( ":names", ":names_internal", "//src/google/protobuf:arena", - "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index 06a0a37afd9e..55b38c1d7571 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -30,7 +30,6 @@ #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/compiler/versions.h" #include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/strtod.h" #include "google/protobuf/wire_format.h" @@ -828,8 +827,7 @@ bool HasRequiredFields(const Descriptor* type) { } bool IsRealOneof(const FieldDescriptor* descriptor) { - return descriptor->containing_oneof() && - !OneofDescriptorLegacy(descriptor->containing_oneof()).is_synthetic(); + return descriptor->real_containing_oneof(); } bool HasRepeatedFields(const Descriptor* descriptor) { diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index 0351c517d1c3..d5f89874570a 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -19,7 +19,6 @@ #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" @@ -407,7 +406,8 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( } void ImmutableMessageFieldGenerator::GenerateKotlinOrNull(io::Printer* printer) const { - if (FieldDescriptorLegacy(descriptor_).has_optional_keyword()) { + if (descriptor_->has_presence() && + descriptor_->real_containing_oneof() == nullptr) { printer->Print(variables_, "public val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n" " get() = $kt_dsl_builder$.$name$OrNull\n"); diff --git a/src/google/protobuf/compiler/java/message_field_lite.cc b/src/google/protobuf/compiler/java/message_field_lite.cc index 17a9fa789f88..45997ef324db 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.cc +++ b/src/google/protobuf/compiler/java/message_field_lite.cc @@ -19,7 +19,6 @@ #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" @@ -309,7 +308,8 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( } void ImmutableMessageFieldLiteGenerator::GenerateKotlinOrNull(io::Printer* printer) const { - if (FieldDescriptorLegacy(descriptor_).has_optional_keyword()) { + if (descriptor_->has_presence() && + descriptor_->real_containing_oneof() == nullptr) { printer->Print(variables_, "public val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n" " get() = $kt_dsl_builder$.$name$OrNull\n"); diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index 8c20affd0fdb..71b368997d11 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -31,7 +31,6 @@ #include "google/protobuf/compiler/java/message_builder_lite.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" diff --git a/src/google/protobuf/compiler/python/BUILD.bazel b/src/google/protobuf/compiler/python/BUILD.bazel index e9501f2b56d4..5fe960417af4 100644 --- a/src/google/protobuf/compiler/python/BUILD.bazel +++ b/src/google/protobuf/compiler/python/BUILD.bazel @@ -26,7 +26,6 @@ cc_library( "@com_github_grpc_grpc//tools/distrib/python/grpcio_tools:__subpackages__", ], deps = [ - "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", diff --git a/src/google/protobuf/compiler/python/generator.cc b/src/google/protobuf/compiler/python/generator.cc index 9b2cdf3d15fd..555e4edef19f 100644 --- a/src/google/protobuf/compiler/python/generator.cc +++ b/src/google/protobuf/compiler/python/generator.cc @@ -48,7 +48,6 @@ #include "google/protobuf/compiler/versions.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/descriptor_visitor.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/io/printer.h" @@ -167,6 +166,17 @@ std::string OptionsValue(absl::string_view serialized_options) { } } +std::string GetLegacySyntaxName(Edition edition) { + switch (edition) { + case Edition::EDITION_PROTO2: + return "proto2"; + case Edition::EDITION_PROTO3: + return "proto3"; + default: + return "editions"; + } +} + } // namespace Generator::Generator() : file_(nullptr) {} @@ -534,8 +544,7 @@ void Generator::PrintFileDescriptor() const { m["descriptor_name"] = kDescriptorKey; m["name"] = file_->name(); m["package"] = file_->package(); - m["syntax"] = std::string( - FileDescriptorLegacy::SyntaxName(FileDescriptorLegacy(file_).syntax())); + m["syntax"] = GetLegacySyntaxName(file_->edition()); m["edition"] = Edition_Name(file_->edition()); m["options"] = OptionsValue(proto_.options().SerializeAsString()); m["serialized_descriptor"] = absl::CHexEscape(file_descriptor_serialized_); diff --git a/src/google/protobuf/compiler/ruby/BUILD.bazel b/src/google/protobuf/compiler/ruby/BUILD.bazel index 62afc3c35a5f..9e921542fcfa 100644 --- a/src/google/protobuf/compiler/ruby/BUILD.bazel +++ b/src/google/protobuf/compiler/ruby/BUILD.bazel @@ -17,7 +17,6 @@ cc_library( "//src/google/protobuf/compiler:__pkg__", ], deps = [ - "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index 12a5c12e7a4e..1d85046b24a1 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -19,7 +19,6 @@ #include "google/protobuf/compiler/retention.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream.h" @@ -320,12 +319,6 @@ bool Generator::Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* generator_context, std::string* error) const { - if (FileDescriptorLegacy(file).syntax() == - FileDescriptorLegacy::Syntax::SYNTAX_UNKNOWN) { - *error = "Invalid or unsupported proto syntax"; - return false; - } - std::unique_ptr output( generator_context->Open(GetOutputFilename(file->name()))); io::Printer printer(output.get(), '$');