Migrate call-sites of ExtensionRangeOption fields.

These are being migrated to accessor methods of the new descriptor-like class.

PiperOrigin-RevId: 532169110
pull/12816/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 3b8a472d07
commit 404ec743ed
  1. 4
      src/google/protobuf/compiler/command_line_interface.cc
  2. 29
      src/google/protobuf/compiler/cpp/message.cc
  3. 3
      src/google/protobuf/compiler/cpp/message.h
  4. 6
      src/google/protobuf/compiler/cpp/parse_function_generator.cc
  5. 2
      src/google/protobuf/compiler/java/helpers.h
  6. 2
      src/google/protobuf/compiler/java/message_serialization.cc
  7. 2
      src/google/protobuf/compiler/java/message_serialization.h
  8. 8
      src/google/protobuf/compiler/objectivec/message.cc
  9. 5
      src/google/protobuf/compiler/python/generator.cc

@ -2937,8 +2937,8 @@ void GatherOccupiedFieldRanges(
ranges->insert(FieldRange(fd->number(), fd->number() + 1));
}
for (int i = 0; i < descriptor->extension_range_count(); ++i) {
ranges->insert(FieldRange(descriptor->extension_range(i)->start,
descriptor->extension_range(i)->end));
ranges->insert(FieldRange(descriptor->extension_range(i)->start_number(),
descriptor->extension_range(i)->end_number()));
}
for (int i = 0; i < descriptor->reserved_range_count(); ++i) {
ranges->insert(FieldRange(descriptor->reserved_range(i)->start,

@ -156,7 +156,7 @@ std::vector<const FieldDescriptor*> SortFieldsByNumber(
struct ExtensionRangeSorter {
bool operator()(const Descriptor::ExtensionRange* left,
const Descriptor::ExtensionRange* right) const {
return left->start < right->start;
return left->start_number() < right->start_number();
}
};
@ -3672,11 +3672,11 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* p,
format("\n");
}
void MessageGenerator::GenerateSerializeOneExtensionRange(
io::Printer* p, const Descriptor::ExtensionRange* range) {
void MessageGenerator::GenerateSerializeOneExtensionRange(io::Printer* p,
int start, int end) {
absl::flat_hash_map<absl::string_view, std::string> vars = variables_;
vars["start"] = absl::StrCat(range->start);
vars["end"] = absl::StrCat(range->end);
vars["start"] = absl::StrCat(start);
vars["end"] = absl::StrCat(end);
Formatter format(p, vars);
format("// Extension range [$start$, $end$)\n");
format(
@ -3832,19 +3832,18 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) {
void AddToRange(const Descriptor::ExtensionRange* range) {
if (!has_current_range_) {
current_combined_range_ = *range;
min_start_ = range->start_number();
max_end_ = range->end_number();
has_current_range_ = true;
} else {
current_combined_range_.start =
std::min(current_combined_range_.start, range->start);
current_combined_range_.end =
std::max(current_combined_range_.end, range->end);
min_start_ = std::min(min_start_, range->start_number());
max_end_ = std::max(max_end_, range->end_number());
}
}
void Flush() {
if (has_current_range_) {
mg_->GenerateSerializeOneExtensionRange(p_, &current_combined_range_);
mg_->GenerateSerializeOneExtensionRange(p_, min_start_, max_end_);
}
has_current_range_ = false;
}
@ -3853,7 +3852,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) {
MessageGenerator* mg_;
io::Printer* p_;
bool has_current_range_ = false;
Descriptor::ExtensionRange current_combined_range_;
int min_start_ = 0;
int max_end_ = 0;
};
// We need to track the largest weak field, because weak fields are serialized
@ -3909,7 +3909,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) {
i < ordered_fields.size() || j < sorted_extensions.size();) {
if ((j == sorted_extensions.size()) ||
(i < descriptor_->field_count() &&
ordered_fields[i]->number() < sorted_extensions[j]->start)) {
ordered_fields[i]->number() <
sorted_extensions[j]->start_number())) {
const FieldDescriptor* field = ordered_fields[i++];
re.Flush();
if (field->options().weak()) {
@ -4001,7 +4002,7 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBodyShuffled(
format("case $1$: {\n", index++);
format.Indent();
GenerateSerializeOneExtensionRange(p, r);
GenerateSerializeOneExtensionRange(p, r->start_number(), r->end_number());
format("break;\n");
format.Outdent();

@ -147,8 +147,7 @@ class MessageGenerator {
// Or, if fields.size() == 1, just call GenerateSerializeOneField().
void GenerateSerializeOneofFields(
io::Printer* p, const std::vector<const FieldDescriptor*>& fields);
void GenerateSerializeOneExtensionRange(
io::Printer* p, const Descriptor::ExtensionRange* range);
void GenerateSerializeOneExtensionRange(io::Printer* p, int start, int end);
// Generates has_foo() functions and variables for singular field has-bits.
void GenerateSingularFieldHasBits(const FieldDescriptor* field,

@ -1281,11 +1281,11 @@ void ParseFunctionGenerator::GenerateParseIterationBody(
if (i > 0) format(" ||\n ");
uint32_t start_tag = WireFormatLite::MakeTag(
range->start, static_cast<WireFormatLite::WireType>(0));
range->start_number(), static_cast<WireFormatLite::WireType>(0));
uint32_t end_tag = WireFormatLite::MakeTag(
range->end, static_cast<WireFormatLite::WireType>(0));
range->end_number(), static_cast<WireFormatLite::WireType>(0));
if (range->end > FieldDescriptor::kMaxNumber) {
if (range->end_number() > FieldDescriptor::kMaxNumber) {
format("($1$u <= tag)", start_tag);
} else {
format("($1$u <= tag && tag < $2$u)", start_tag, end_tag);

@ -333,7 +333,7 @@ struct FieldOrderingByNumber {
struct ExtensionRangeOrdering {
bool operator()(const Descriptor::ExtensionRange* a,
const Descriptor::ExtensionRange* b) const {
return a->start < b->start;
return a->start_number() < b->start_number();
}
};

@ -42,7 +42,7 @@ namespace java {
void GenerateSerializeExtensionRange(io::Printer* printer,
const Descriptor::ExtensionRange* range) {
printer->Print("extensionWriter.writeUntil($end$, output);\n", "end",
absl::StrCat(range->end));
absl::StrCat(range->end_number()));
}
} // namespace java

@ -78,7 +78,7 @@ void GenerateSerializeFieldsAndExtensions(
// number of extension ranges without fields in between them.
const Descriptor::ExtensionRange* range = nullptr;
while (range_idx < sorted_extensions.size() &&
sorted_extensions[range_idx]->end <= field->number()) {
sorted_extensions[range_idx]->end_number() <= field->number()) {
range = sorted_extensions[range_idx++];
}

@ -150,7 +150,7 @@ struct FieldOrderingByStorageSize {
struct ExtensionRangeOrdering {
bool operator()(const Descriptor::ExtensionRange* a,
const Descriptor::ExtensionRange* b) const {
return a->start < b->start;
return a->start_number() < b->start_number();
}
};
@ -177,10 +177,10 @@ struct SimpleExtensionRange {
std::vector<SimpleExtensionRange> result;
result.reserve(sorted_extensions.size());
for (const auto ext : sorted_extensions) {
if (!result.empty() && result.back().end == ext->start) {
result.back().end = ext->end;
if (!result.empty() && result.back().end == ext->start_number()) {
result.back().end = ext->end_number();
} else {
result.emplace_back(ext->start, ext->end);
result.emplace_back(ext->start_number(), ext->end_number());
}
}
return result;

@ -702,8 +702,9 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const {
for (int i = 0; i < message_descriptor.extension_range_count(); ++i) {
const Descriptor::ExtensionRange* range =
message_descriptor.extension_range(i);
printer_->Print("($start$, $end$), ", "start", absl::StrCat(range->start),
"end", absl::StrCat(range->end));
printer_->Print("($start$, $end$), ", "start",
absl::StrCat(range->start_number()), "end",
absl::StrCat(range->end_number()));
}
printer_->Print("],\n");
printer_->Print("oneofs=[\n");

Loading…
Cancel
Save