Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:11:56

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 // Author: kenton@google.com (Kenton Varda)
0009 //  Based on original Protocol Buffers design by
0010 //  Sanjay Ghemawat, Jeff Dean, and others.
0011 //
0012 // Generates C++ code for a given .proto file.
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 // Must be included last.
0030 #include "google/protobuf/port_def.inc"
0031 
0032 namespace google {
0033 namespace protobuf {
0034 namespace compiler {
0035 namespace cpp {
0036 // CodeGenerator implementation which generates a C++ source file and
0037 // header.  If you create your own protocol compiler binary and you want
0038 // it to support C++ output, you can do so by registering an instance of this
0039 // CodeGenerator with the CommandLineInterface in your main() function.
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,     // Use the internal google3 runtime.
0049     kOpensource,  // Use the open-source runtime.
0050 
0051     // Use the open-source runtime with google3 #include paths.  We make these
0052     // absolute to avoid ambiguity, so the runtime will be #included like:
0053     //   #include "third_party/protobuf/.../google/protobuf/message.h"
0054     kOpensourceGoogle3
0055   };
0056 
0057   void set_opensource_runtime(bool opensource) {
0058     opensource_runtime_ = opensource;
0059   }
0060 
0061   // If set to a non-empty string, generated code will do:
0062   //   #include "<BASE>/google/protobuf/message.h"
0063   // instead of:
0064   //   #include "google/protobuf/message.h"
0065   // This has no effect if opensource_runtime = false.
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 }  // namespace cpp
0095 }  // namespace compiler
0096 }  // namespace protobuf
0097 }  // namespace google
0098 
0099 #include "google/protobuf/port_undef.inc"
0100 
0101 #endif  // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__