Split some proto1 naming functions into a proto1-specific names library.
I had to resort to temporary copy+paste in some cases because the knot of dependencies is so tangled, but I intend to deduplicate these again later once we have a clean dependency graph.
I also exposed the feature helpers to `code_generator_lite.h`. Since our `names.h` libraries generally require access to these functions, I thought they should be available in a "lite" target without having to pull in all of `CodeGenerator`.
PiperOrigin-RevId: 810894675
diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel
index 8b4e3f3..4bf55a3 100644
--- a/src/google/protobuf/compiler/BUILD.bazel
+++ b/src/google/protobuf/compiler/BUILD.bazel
@@ -135,6 +135,7 @@
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
+ "//src/google/protobuf",
"//src/google/protobuf:port",
"@abseil-cpp//absl/strings",
],
diff --git a/src/google/protobuf/compiler/code_generator_lite.h b/src/google/protobuf/compiler/code_generator_lite.h
index bf73c92..397d188 100644
--- a/src/google/protobuf/compiler/code_generator_lite.h
+++ b/src/google/protobuf/compiler/code_generator_lite.h
@@ -8,11 +8,15 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_LITE_H__
#define GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_LITE_H__
+#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/descriptor.pb.h"
+#include "google/protobuf/internal_feature_helper.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
@@ -36,6 +40,23 @@
// Returns true if the proto path corresponds to a known feature file.
PROTOC_EXPORT bool IsKnownFeatureProto(absl::string_view filename);
+namespace generator_internal {
+
+// For code generators and their helper APIs only: provides access to resolved
+// features for the given extension.
+template <typename DescriptorT, typename ExtType, uint8_t field_type,
+ bool is_packed>
+auto GetResolvedFeatureExtension(
+ const DescriptorT& descriptor,
+ const google::protobuf::internal::ExtensionIdentifier<
+ FeatureSet, internal::MessageTypeTraits<ExtType>, field_type,
+ is_packed>& extension) {
+ return ::google::protobuf::internal::InternalFeatureHelper::GetResolvedFeatureExtension(
+ descriptor, extension);
+}
+
+} // namespace generator_internal
+
} // namespace compiler
namespace internal {
diff --git a/src/google/protobuf/compiler/java/name_resolver.cc b/src/google/protobuf/compiler/java/name_resolver.cc
index c515570..e2fc046 100644
--- a/src/google/protobuf/compiler/java/name_resolver.cc
+++ b/src/google/protobuf/compiler/java/name_resolver.cc
@@ -183,7 +183,6 @@
return class_name;
}
-
std::string ClassNameResolver::GetFileClassName(const FileDescriptor* file,
bool immutable) {
return GetFileClassName(file, immutable, false);
diff --git a/src/google/protobuf/internal_feature_helper.h b/src/google/protobuf/internal_feature_helper.h
index f183778..9d1773c 100644
--- a/src/google/protobuf/internal_feature_helper.h
+++ b/src/google/protobuf/internal_feature_helper.h
@@ -13,6 +13,18 @@
namespace google {
namespace protobuf {
+
+namespace compiler::generator_internal {
+template <typename DescriptorT, typename ExtType, uint8_t field_type,
+ bool is_packed>
+auto GetResolvedFeatureExtension(
+ const DescriptorT& descriptor,
+ const google::protobuf::internal::ExtensionIdentifier<
+ FeatureSet, internal::MessageTypeTraits<ExtType>, field_type,
+ is_packed>& extension);
+
+} // namespace compiler::generator_internal
+
namespace internal {
class InternalFeatureHelperTest;
// This class is for internal use only and provides access to the resolved
@@ -31,6 +43,15 @@
friend class ::google::protobuf::compiler::CommandLineInterface;
friend class ::google::protobuf::internal::InternalFeatureHelperTest;
+ template <typename DescriptorT, typename ExtType, uint8_t field_type,
+ bool is_packed>
+ friend auto ::google::protobuf::compiler::generator_internal::
+ GetResolvedFeatureExtension(
+ const DescriptorT& descriptor,
+ const google::protobuf::internal::ExtensionIdentifier<
+ FeatureSet, internal::MessageTypeTraits<ExtType>, field_type,
+ is_packed>& extension);
+
static const DescriptorPool& GetDescriptorPool(const FileDescriptor& file) {
return *file.pool();
}