Back to home page

EIC code displayed by LXR

 
 

    


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

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 #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_FIELD_BASE_H__
0009 #define GOOGLE_PROTOBUF_COMPILER_CSHARP_FIELD_BASE_H__
0010 
0011 #include <string>
0012 
0013 #include "google/protobuf/compiler/code_generator.h"
0014 #include "absl/container/flat_hash_map.h"
0015 #include "absl/strings/ascii.h"
0016 #include "absl/strings/escaping.h"
0017 #include "absl/strings/str_replace.h"
0018 #include "absl/strings/str_split.h"
0019 #include "google/protobuf/compiler/csharp/csharp_source_generator_base.h"
0020 #include "google/protobuf/descriptor.h"
0021 #include "google/protobuf/io/printer.h"
0022 
0023 namespace google {
0024 namespace protobuf {
0025 namespace compiler {
0026 namespace csharp {
0027 
0028 class FieldGeneratorBase : public SourceGeneratorBase {
0029  public:
0030   FieldGeneratorBase(const FieldDescriptor* descriptor,
0031                      int presenceIndex,
0032                      const Options* options);
0033   ~FieldGeneratorBase();
0034 
0035   FieldGeneratorBase(const FieldGeneratorBase&) = delete;
0036   FieldGeneratorBase& operator=(const FieldGeneratorBase&) = delete;
0037 
0038   virtual void GenerateCloningCode(io::Printer* printer) = 0;
0039   virtual void GenerateFreezingCode(io::Printer* printer);
0040   virtual void GenerateCodecCode(io::Printer* printer);
0041   virtual void GenerateExtensionCode(io::Printer* printer);
0042   virtual void GenerateMembers(io::Printer* printer) = 0;
0043   virtual void GenerateMergingCode(io::Printer* printer) = 0;
0044   virtual void GenerateParsingCode(io::Printer* printer) = 0;
0045   virtual void GenerateParsingCode(io::Printer* printer, bool use_parse_context);
0046   virtual void GenerateSerializationCode(io::Printer* printer) = 0;
0047   virtual void GenerateSerializationCode(io::Printer* printer, bool use_write_context);
0048   virtual void GenerateSerializedSizeCode(io::Printer* printer) = 0;
0049 
0050   virtual void WriteHash(io::Printer* printer) = 0;
0051   virtual void WriteEquals(io::Printer* printer) = 0;
0052   // Currently unused, as we use reflection to generate JSON
0053   virtual void WriteToString(io::Printer* printer) = 0;
0054 
0055  protected:
0056   const FieldDescriptor* descriptor_;
0057   const int presenceIndex_;
0058   absl::flat_hash_map<absl::string_view, std::string> variables_;
0059 
0060   void AddDeprecatedFlag(io::Printer* printer);
0061   void AddNullCheck(io::Printer* printer);
0062   void AddNullCheck(io::Printer* printer, const std::string& name);
0063 
0064   void AddPublicMemberAttributes(io::Printer* printer);
0065   void SetCommonOneofFieldVariables(
0066       absl::flat_hash_map<absl::string_view, std::string>* variables);
0067 
0068   std::string oneof_property_name();
0069   std::string oneof_case_name(); 
0070   std::string oneof_name();
0071   std::string property_name();
0072   std::string name();
0073   std::string type_name();
0074   std::string type_name(const FieldDescriptor* descriptor);
0075   bool has_default_value();
0076   std::string default_value();
0077   std::string default_value(const FieldDescriptor* descriptor);
0078   std::string number();
0079   std::string capitalized_type_name();
0080 
0081  private:
0082   void SetCommonFieldVariables(
0083       absl::flat_hash_map<absl::string_view, std::string>* variables);
0084   std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor);
0085   std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor);
0086 };
0087 
0088 }  // namespace csharp
0089 }  // namespace compiler
0090 }  // namespace protobuf
0091 }  // namespace google
0092 
0093 #endif  // GOOGLE_PROTOBUF_COMPILER_CSHARP_FIELD_BASE_H__
0094