Automated rollback of commit 74f6da4d26.

PiperOrigin-RevId: 657257908
pull/17650/head
Protobuf Team Bot 8 months ago committed by Copybara-Service
parent 1f9206c703
commit 51763f3e40
  1. 9
      hpb/hpb.h
  2. 50
      hpb_generator/gen_extensions.cc
  3. 8
      hpb_generator/gen_extensions.h
  4. 21
      hpb_generator/gen_messages.cc
  5. 5
      hpb_generator/protoc-gen-upb-protos.cc
  6. 2
      hpb_generator/tests/test_generated.cc

@ -224,12 +224,13 @@ class ExtensionIdentifier : public ExtensionMiniTableProvider {
using Extendee = ExtendeeType;
constexpr explicit ExtensionIdentifier(
uint32_t number, const upb_MiniTableExtension* mini_table_ext)
: ExtensionMiniTableProvider(mini_table_ext), number_(number) {}
const upb_MiniTableExtension* mini_table_ext)
: ExtensionMiniTableProvider(mini_table_ext) {}
private:
uint32_t number_;
constexpr uint32_t number() const { return number_; }
constexpr uint32_t number() const {
return upb_MiniTableExtension_Number(mini_table_ext());
}
friend class PrivateAccess;
};

@ -7,14 +7,9 @@
#include "google/protobuf/compiler/hpb/gen_extensions.h"
#include <cassert>
#include <string>
#include <vector>
#include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/hpb/gen_utils.h"
#include "google/protobuf/compiler/hpb/names.h"
#include "google/protobuf/compiler/hpb/output.h"
#include "google/protobuf/descriptor.h"
namespace google::protobuf::hpb_generator {
@ -43,19 +38,15 @@ void WriteExtensionIdentifierHeader(const protobuf::FieldDescriptor* ext,
if (ext->extension_scope()) {
output(
R"cc(
static constexpr ::hpb::internal::ExtensionIdentifier<$0, $3> $2{$4,
&$1};
static const ::hpb::internal::ExtensionIdentifier<$0, $1> $2;
)cc",
ContainingTypeName(ext), mini_table_name, ext->name(),
CppTypeParameterName(ext), ext->number());
ContainingTypeName(ext), CppTypeParameterName(ext), ext->name());
} else {
output(
R"cc(
inline constexpr ::hpb::internal::ExtensionIdentifier<$0, $3> $2{$4,
&$1};
extern const ::hpb::internal::ExtensionIdentifier<$0, $1> $2;
)cc",
ContainingTypeName(ext), mini_table_name, ext->name(),
CppTypeParameterName(ext), ext->number());
ContainingTypeName(ext), CppTypeParameterName(ext), ext->name());
}
}
@ -69,5 +60,36 @@ void WriteExtensionIdentifiersHeader(
}
}
void WriteExtensionIdentifier(const protobuf::FieldDescriptor* ext,
Output& output) {
std::string mini_table_name =
absl::StrCat(ExtensionIdentifierBase(ext), "_", ext->name(), "_ext");
if (ext->extension_scope()) {
output(
R"cc(
const ::protos::internal::ExtensionIdentifier<$0, $3> $4::$2(&$1);
)cc",
ContainingTypeName(ext), mini_table_name, ext->name(),
CppTypeParameterName(ext), ClassName(ext->extension_scope()));
} else {
output(
R"cc(
const ::protos::internal::ExtensionIdentifier<$0, $3> $2(&$1);
)cc",
ContainingTypeName(ext), mini_table_name, ext->name(),
CppTypeParameterName(ext));
}
}
void WriteExtensionIdentifiers(
const std::vector<const protobuf::FieldDescriptor*>& extensions,
Output& output) {
for (const auto* ext : extensions) {
if (!ext->extension_scope()) {
WriteExtensionIdentifier(ext, output);
}
}
}
} // namespace protobuf
} // namespace google::hpb_generator

@ -8,8 +8,8 @@
#ifndef PROTOBUF_COMPILER_HBP_GEN_EXTENSIONS_H_
#define PROTOBUF_COMPILER_HBP_GEN_EXTENSIONS_H_
#include "google/protobuf/compiler/hpb/output.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/compiler/hpb/output.h"
namespace google::protobuf::hpb_generator {
@ -20,6 +20,12 @@ void WriteExtensionIdentifiersHeader(
Output& output);
void WriteExtensionIdentifierHeader(const protobuf::FieldDescriptor* ext,
Output& output);
void WriteExtensionIdentifiers(
const std::vector<const protobuf::FieldDescriptor*>& extensions,
Output& output);
void WriteExtensionIdentifier(const protobuf::FieldDescriptor* ext,
Output& output);
} // namespace protobuf
} // namespace google::hpb_generator

@ -15,14 +15,15 @@
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/compiler/hpb/gen_accessors.h"
#include "google/protobuf/compiler/hpb/gen_enums.h"
#include "google/protobuf/compiler/hpb/gen_extensions.h"
#include "google/protobuf/compiler/hpb/gen_utils.h"
#include "google/protobuf/compiler/hpb/names.h"
#include "google/protobuf/compiler/hpb/output.h"
#include "google/protobuf/descriptor.h"
#include "upb_generator/common.h"
#include "upb_generator/file_layout.h"
namespace google::protobuf::hpb_generator {
@ -47,6 +48,10 @@ void WriteInternalForwardDeclarationsInHeader(
const protobuf::Descriptor* message, Output& output);
void WriteDefaultInstanceHeader(const protobuf::Descriptor* message,
Output& output);
void WriteExtensionIdentifiersImplementation(
const protobuf::Descriptor* message,
const std::vector<const protobuf::FieldDescriptor*>& file_exts,
Output& output);
void WriteUsingEnumsInHeader(
const protobuf::Descriptor* message,
const std::vector<const protobuf::EnumDescriptor*>& file_enums,
@ -451,6 +456,8 @@ void WriteMessageImplementation(
}
)cc",
ClassName(descriptor));
WriteExtensionIdentifiersImplementation(descriptor, file_exts, output);
}
}
@ -478,6 +485,18 @@ void WriteExtensionIdentifiersInClassHeader(
}
}
void WriteExtensionIdentifiersImplementation(
const protobuf::Descriptor* message,
const std::vector<const protobuf::FieldDescriptor*>& file_exts,
Output& output) {
for (auto* ext : file_exts) {
if (ext->extension_scope() &&
ext->extension_scope()->full_name() == message->full_name()) {
WriteExtensionIdentifier(ext, output);
}
}
}
void WriteUsingEnumsInHeader(
const protobuf::Descriptor* message,
const std::vector<const protobuf::EnumDescriptor*>& file_enums,

@ -13,14 +13,14 @@
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/plugin.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/compiler/hpb/gen_enums.h"
#include "google/protobuf/compiler/hpb/gen_extensions.h"
#include "google/protobuf/compiler/hpb/gen_messages.h"
#include "google/protobuf/compiler/hpb/gen_utils.h"
#include "google/protobuf/compiler/hpb/names.h"
#include "google/protobuf/compiler/hpb/output.h"
#include "google/protobuf/compiler/plugin.h"
#include "google/protobuf/descriptor.h"
namespace google::protobuf::hpb_generator {
namespace {
@ -211,6 +211,7 @@ void WriteSource(const protobuf::FileDescriptor* file, Output& output,
WriteMessageImplementations(file, output);
const std::vector<const protobuf::FieldDescriptor*> this_file_exts =
SortedExtensions(file);
WriteExtensionIdentifiers(this_file_exts, output);
WriteEndNamespace(file, output);
output("#include \"upb/port/undef.inc\"\n\n");

@ -1241,8 +1241,6 @@ TEST(CppGeneratedCode, FieldNumberConstants) {
}
TEST(CppGeneratedCode, ExtensionFieldNumberConstant) {
static_assert(::protos::ExtensionNumber(ThemeExtension::theme_extension) ==
12003);
EXPECT_EQ(12003, ::protos::ExtensionNumber(ThemeExtension::theme_extension));
}

Loading…
Cancel
Save