File indexing completed on 2025-01-31 10:11:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__
0015 #define GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__
0016
0017 #include <cstdint>
0018 #include <string>
0019 #include <utility>
0020 #include <vector>
0021
0022 #include "absl/status/status.h"
0023 #include "absl/strings/string_view.h"
0024 #include "google/protobuf/compiler/code_generator.h"
0025 #include "google/protobuf/cpp_features.pb.h"
0026 #include "google/protobuf/descriptor.pb.h"
0027 #include "google/protobuf/port.h"
0028
0029
0030 #include "google/protobuf/port_def.inc"
0031
0032 namespace google {
0033 namespace protobuf {
0034 namespace compiler {
0035 namespace cpp {
0036
0037
0038
0039
0040 class PROTOC_EXPORT CppGenerator : public CodeGenerator {
0041 public:
0042 CppGenerator() = default;
0043 CppGenerator(const CppGenerator&) = delete;
0044 CppGenerator& operator=(const CppGenerator&) = delete;
0045 ~CppGenerator() override = default;
0046
0047 enum class Runtime {
0048 kGoogle3,
0049 kOpensource,
0050
0051
0052
0053
0054 kOpensourceGoogle3
0055 };
0056
0057 void set_opensource_runtime(bool opensource) {
0058 opensource_runtime_ = opensource;
0059 }
0060
0061
0062
0063
0064
0065
0066 void set_runtime_include_base(std::string base) {
0067 runtime_include_base_ = std::move(base);
0068 }
0069
0070 bool Generate(const FileDescriptor* file, const std::string& parameter,
0071 GeneratorContext* generator_context,
0072 std::string* error) const override;
0073
0074 uint64_t GetSupportedFeatures() const override {
0075 return FEATURE_PROTO3_OPTIONAL | FEATURE_SUPPORTS_EDITIONS;
0076 }
0077
0078 Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; }
0079 Edition GetMaximumEdition() const override { return Edition::EDITION_2023; }
0080
0081 std::vector<const FieldDescriptor*> GetFeatureExtensions() const override {
0082 return {GetExtensionReflection(pb::cpp)};
0083 }
0084
0085 using CodeGenerator::GetEdition;
0086 using CodeGenerator::GetResolvedSourceFeatures;
0087
0088 private:
0089 bool opensource_runtime_ = google::protobuf::internal::IsOss();
0090 std::string runtime_include_base_;
0091
0092 absl::Status ValidateFeatures(const FileDescriptor* file) const;
0093 };
0094 }
0095 }
0096 }
0097 }
0098
0099 #include "google/protobuf/port_undef.inc"
0100
0101 #endif