Internal changes

PiperOrigin-RevId: 647549552
pull/17256/head
Mike Kruskal 5 months ago committed by Copybara-Service
parent c96ad4ffa3
commit 643b0a625f
  1. 4
      editions/codegen_tests/proto2_group.proto
  2. 10
      hpb_generator/gen_enums.cc
  3. 1
      src/google/protobuf/compiler/cpp/BUILD.bazel
  4. 5
      src/google/protobuf/compiler/cpp/enum.cc
  5. 20
      src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
  6. 8
      upb_generator/protoc-gen-upb.cc

@ -12,7 +12,7 @@ package protobuf_editions_test.proto2;
// LINT: ALLOW_GROUPS
message Proto2Group {
optional group Groupfield = 2 {
optional group GroupField = 2 {
optional int32 int32_field = 1;
}
@ -20,7 +20,7 @@ message Proto2Group {
}
extend Proto2Group {
optional group Groupextension = 10 {
optional group GroupExtension = 10 {
optional int32 int32_field = 1;
}
}

@ -85,11 +85,11 @@ void WriteEnumValues(const protobuf::EnumDescriptor* desc, Output& output) {
for (int i = 0; i < value_count; i++) {
values.push_back(desc->value(i));
}
std::sort(values.begin(), values.end(),
[](const protobuf::EnumValueDescriptor* a,
const protobuf::EnumValueDescriptor* b) {
return a->number() < b->number();
});
std::stable_sort(values.begin(), values.end(),
[](const protobuf::EnumValueDescriptor* a,
const protobuf::EnumValueDescriptor* b) {
return a->number() < b->number();
});
for (size_t i = 0; i < values.size(); i++) {
auto value = values[i];

@ -112,6 +112,7 @@ cc_library(
"//src/google/protobuf/compiler:versions",
"//src/google/protobuf/io",
"//src/google/protobuf/io:printer",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_map",

@ -19,6 +19,7 @@
#include <utility>
#include <vector>
#include "absl/algorithm/container.h"
#include "absl/container/btree_map.h"
#include "absl/container/btree_set.h"
#include "absl/container/flat_hash_map.h"
@ -441,12 +442,12 @@ void EnumGenerator::GenerateMethods(int idx, io::Printer* p) {
++index;
offset += e.first.size();
}
absl::c_sort(offsets, [](const auto& a, const auto& b) {
absl::c_stable_sort(offsets, [](const auto& a, const auto& b) {
return a.byte_offset < b.byte_offset;
});
std::vector<Offset> offsets_by_number = offsets;
absl::c_sort(offsets_by_number, [](const auto& a, const auto& b) {
absl::c_stable_sort(offsets_by_number, [](const auto& a, const auto& b) {
return a.number < b.number;
});

@ -152,7 +152,9 @@ void ReflectionClassGenerator::WriteDescriptor(io::Printer* printer) {
printer->Indent();
// TODO: Consider a C#-escaping format here instead of just Base64.
std::string base64 = FileDescriptorToBase64(file_);
std::string base64 = options()->strip_nonfunctional_codegen
? ""
: FileDescriptorToBase64(file_);
while (base64.size() > 60) {
printer->Print("\"$base64$\",\n", "base64", base64.substr(0, 60));
base64 = base64.substr(60);
@ -254,9 +256,21 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
std::vector<std::string> oneofs;
oneofs.reserve(descriptor->oneof_decl_count());
for (int i = 0; i < descriptor->oneof_decl_count(); i++) {
oneofs.push_back(UnderscoresToCamelCase(descriptor->oneof_decl(i)->name(), true));
if (options()->strip_nonfunctional_codegen &&
i >= descriptor->real_oneof_decl_count()) {
// Skip synthetic oneofs, which don't affect any actual behavior
// outside reflection.
break;
}
oneofs.push_back(
UnderscoresToCamelCase(descriptor->oneof_decl(i)->name(), true));
}
if (oneofs.empty()) {
printer->Print("null, ");
} else {
printer->Print("new[]{ \"$oneofs$\" }, ", "oneofs",
absl::StrJoin(oneofs, "\", \""));
}
printer->Print("new[]{ \"$oneofs$\" }, ", "oneofs", absl::StrJoin(oneofs, "\", \""));
}
else {
printer->Print("null, ");

@ -243,10 +243,10 @@ void DumpEnumValues(upb::EnumDefPtr desc, Output& output) {
for (int i = 0; i < desc.value_count(); i++) {
values.push_back(desc.value(i));
}
std::sort(values.begin(), values.end(),
[](upb::EnumValDefPtr a, upb::EnumValDefPtr b) {
return a.number() < b.number();
});
std::stable_sort(values.begin(), values.end(),
[](upb::EnumValDefPtr a, upb::EnumValDefPtr b) {
return a.number() < b.number();
});
for (size_t i = 0; i < values.size(); i++) {
auto value = values[i];

Loading…
Cancel
Save