Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/google/protobuf/compiler/cpp/generator.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 
0037 struct Options;
0038 
0039 // CodeGenerator implementation which generates a C++ source file and
0040 // header.  If you create your own protocol compiler binary and you want
0041 // it to support C++ output, you can do so by registering an instance of this
0042 // CodeGenerator with the CommandLineInterface in your main() function.
0043 class PROTOC_EXPORT CppGenerator final : public CodeGenerator {
0044  public:
0045   CppGenerator() = default;
0046   CppGenerator(const CppGenerator&) = delete;
0047   CppGenerator& operator=(const CppGenerator&) = delete;
0048   ~CppGenerator() override = default;
0049 
0050   enum class Runtime {
0051     kGoogle3,     // Use the internal google3 runtime.
0052     kOpensource,  // Use the open-source runtime.
0053 
0054     // Use the open-source runtime with google3 #include paths.  We make these
0055     // absolute to avoid ambiguity, so the runtime will be #included like:
0056     //   #include "third_party/protobuf/.../google/protobuf/message.h"
0057     kOpensourceGoogle3
0058   };
0059 
0060   void set_opensource_runtime(bool opensource) {
0061     opensource_runtime_ = opensource;
0062   }
0063 
0064   // If set to a non-empty string, generated code will do:
0065   //   #include "<BASE>/google/protobuf/message.h"
0066   // instead of:
0067   //   #include "google/protobuf/message.h"
0068   // This has no effect if opensource_runtime = false.
0069   void set_runtime_include_base(std::string base) {
0070     runtime_include_base_ = std::move(base);
0071   }
0072 
0073   bool Generate(const FileDescriptor* file, const std::string& parameter,
0074                 GeneratorContext* generator_context,
0075                 std::string* error) const override;
0076 
0077   bool GenerateAll(const std::vector<const FileDescriptor*>& files,
0078                    const std::string& parameter,
0079                    GeneratorContext* generator_context,
0080                    std::string* error) const override;
0081 
0082   uint64_t GetSupportedFeatures() const override {
0083     return FEATURE_PROTO3_OPTIONAL | FEATURE_SUPPORTS_EDITIONS;
0084   }
0085 
0086   Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; }
0087   Edition GetMaximumEdition() const override {
0088     return Edition::EDITION_2024;
0089   }
0090 
0091   std::vector<const FieldDescriptor*> GetFeatureExtensions() const override {
0092     return {GetExtensionReflection(pb::cpp)};
0093   }
0094 
0095   using CodeGenerator::GetEdition;
0096   using CodeGenerator::GetResolvedSourceFeatures;
0097 
0098  private:
0099   bool GenerateImpl(const FileDescriptor* file, const std::string& parameter,
0100                     GeneratorContext* generator_context, std::string* error,
0101                     const Options& file_options) const;
0102   bool opensource_runtime_ = google::protobuf::internal::IsOss();
0103   std::string runtime_include_base_;
0104 
0105   absl::Status ValidateFeatures(const FileDescriptor* file) const;
0106 };
0107 }  // namespace cpp
0108 }  // namespace compiler
0109 }  // namespace protobuf
0110 }  // namespace google
0111 
0112 #include "google/protobuf/port_undef.inc"
0113 
0114 #endif  // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__