From 5ce86a675ea4cfc9dcfc54a9be6141ea6bc371b6 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Mon, 4 Dec 2023 16:13:09 -0800 Subject: [PATCH] Internal changes PiperOrigin-RevId: 587872282 --- src/google/protobuf/compiler/BUILD.bazel | 1 - .../protobuf/compiler/command_line_interface.cc | 6 ++---- src/google/protobuf/compiler/java/helpers.h | 1 - src/google/protobuf/compiler/java/message_lite.cc | 13 ++++--------- src/google/protobuf/compiler/mock_code_generator.cc | 4 +--- src/google/protobuf/compiler/objectivec/BUILD.bazel | 1 - src/google/protobuf/compiler/objectivec/file.cc | 11 +++++------ 7 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index 94f8227241..23a2fa0b43 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -279,7 +279,6 @@ cc_library( deps = [ ":code_generator", "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:descriptor_visitor", "//src/google/protobuf/io", "//src/google/protobuf/stubs", diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 46bbb23fa3..bc7cc97506 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -992,8 +992,7 @@ bool ContainsProto3Optional(const Descriptor* desc) { } bool ContainsProto3Optional(const FileDescriptor* file) { - if (FileDescriptorLegacy(file).syntax() == - FileDescriptorLegacy::Syntax::SYNTAX_PROTO3) { + if (file->edition() == Edition::EDITION_PROTO3) { for (int i = 0; i < file->message_type_count(); i++) { if (ContainsProto3Optional(file->message_type(i))) { return true; @@ -1601,8 +1600,7 @@ bool CommandLineInterface::ParseInputFiles( if (!experimental_editions_ && !absl::StartsWith(parsed_file->name(), "google/protobuf/") && !absl::StartsWith(parsed_file->name(), "upb/")) { - if (FileDescriptorLegacy(parsed_file).syntax() == - FileDescriptorLegacy::Syntax::SYNTAX_EDITIONS) { + if (parsed_file->edition() >= Edition::EDITION_2023) { std::cerr << parsed_file->name() << ": This file uses editions, but --experimental_editions has not " diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index 7248ec19bf..60f963ac68 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -22,7 +22,6 @@ #include "google/protobuf/compiler/java/options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" // Must be last. diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index 6ae00b934c..8c20affd0f 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -473,18 +473,13 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( std::vector chars; int flags = 0; - if (FileDescriptorLegacy(descriptor_->file()).syntax() == - FileDescriptorLegacy::Syntax::SYNTAX_PROTO2) { - if (!context_->options().strip_nonfunctional_codegen) { - flags |= 0x1; - } - } if (descriptor_->options().message_set_wire_format()) { flags |= 0x2; } - if (FileDescriptorLegacy(descriptor_->file()).syntax() == - FileDescriptorLegacy::Syntax::SYNTAX_EDITIONS) { - if (!context_->options().strip_nonfunctional_codegen) { + if (!context_->options().strip_nonfunctional_codegen) { + if (descriptor_->file()->edition() == Edition::EDITION_PROTO2) { + flags |= 0x1; + } else if (descriptor_->file()->edition() >= Edition::EDITION_2023) { flags |= 0x4; } } diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 17f68ae35b..0cf407de90 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -34,7 +34,6 @@ #include "absl/strings/substitute.h" #include "google/protobuf/compiler/plugin.pb.h" #include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/descriptor_visitor.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream.h" @@ -216,8 +215,7 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file, maximum_edition_ = Edition::EDITION_PROTO2; } - if (FileDescriptorLegacy(file).syntax() == - FileDescriptorLegacy::SYNTAX_EDITIONS && + if (file->edition() >= Edition::EDITION_2023 && (suppressed_features_ & CodeGenerator::FEATURE_SUPPORTS_EDITIONS) == 0) { internal::VisitDescriptors(*file, [&](const auto& descriptor) { const FeatureSet& features = GetResolvedSourceFeatures(descriptor); diff --git a/src/google/protobuf/compiler/objectivec/BUILD.bazel b/src/google/protobuf/compiler/objectivec/BUILD.bazel index a3a6fcfec0..b60a59d3a6 100644 --- a/src/google/protobuf/compiler/objectivec/BUILD.bazel +++ b/src/google/protobuf/compiler/objectivec/BUILD.bazel @@ -95,7 +95,6 @@ cc_library( deps = [ ":line_consumer", ":names", - "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", "@com_google_absl//absl/container:btree", diff --git a/src/google/protobuf/compiler/objectivec/file.cc b/src/google/protobuf/compiler/objectivec/file.cc index 857dfd73ee..1e45b375d0 100644 --- a/src/google/protobuf/compiler/objectivec/file.cc +++ b/src/google/protobuf/compiler/objectivec/file.cc @@ -31,7 +31,6 @@ #include "google/protobuf/compiler/objectivec/options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" namespace google { @@ -742,17 +741,17 @@ void FileGenerator::EmitFileDescription(io::Printer* p) const { // mode. syntax = "GPBFileSyntaxUnknown"; } else { - switch (FileDescriptorLegacy(file_).syntax()) { - case FileDescriptorLegacy::Syntax::SYNTAX_UNKNOWN: + switch (file_->edition()) { + case Edition::EDITION_UNKNOWN: syntax = "GPBFileSyntaxUnknown"; break; - case FileDescriptorLegacy::Syntax::SYNTAX_PROTO2: + case Edition::EDITION_PROTO2: syntax = "GPBFileSyntaxProto2"; break; - case FileDescriptorLegacy::Syntax::SYNTAX_PROTO3: + case Edition::EDITION_PROTO3: syntax = "GPBFileSyntaxProto3"; break; - case FileDescriptorLegacy::Syntax::SYNTAX_EDITIONS: + default: syntax = "GPBFileSyntaxProtoEditions"; break; }