Remove descriptor_legacy usage from compiler code

PiperOrigin-RevId: 588916746
pull/14970/head
Mike Kruskal 12 months ago committed by Copybara-Service
parent 17f4f915a3
commit 060a9bee84
  1. 1
      src/google/protobuf/compiler/BUILD.bazel
  2. 4
      src/google/protobuf/compiler/command_line_interface.cc
  3. 2
      src/google/protobuf/compiler/java/BUILD.bazel
  4. 4
      src/google/protobuf/compiler/java/helpers.cc
  5. 4
      src/google/protobuf/compiler/java/message_field.cc
  6. 4
      src/google/protobuf/compiler/java/message_field_lite.cc
  7. 1
      src/google/protobuf/compiler/java/message_lite.cc
  8. 1
      src/google/protobuf/compiler/python/BUILD.bazel
  9. 15
      src/google/protobuf/compiler/python/generator.cc
  10. 1
      src/google/protobuf/compiler/ruby/BUILD.bazel
  11. 7
      src/google/protobuf/compiler/ruby/ruby_generator.cc

@ -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",

@ -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;
}
}

@ -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",

@ -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) {

@ -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");

@ -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");

@ -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"

@ -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",

@ -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_);

@ -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",

@ -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<io::ZeroCopyOutputStream> output(
generator_context->Open(GetOutputFilename(file->name())));
io::Printer printer(output.get(), '$');

Loading…
Cancel
Save