protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__
32 #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__
33 
34 #include <map>
35 #include <string>
36 #include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
37 #include <google/protobuf/descriptor.h>
38 #include <google/protobuf/io/printer.h>
39 
40 namespace google {
41 namespace protobuf {
42 namespace compiler {
43 namespace objectivec {
44 
45 class FieldGenerator {
46  public:
48  const Options& options);
49 
50  virtual ~FieldGenerator();
51 
52  FieldGenerator(const FieldGenerator&) = delete;
53  FieldGenerator& operator=(const FieldGenerator&) = delete;
54 
55  // Exposed for subclasses to fill in.
56  virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const = 0;
57  virtual void GeneratePropertyDeclaration(io::Printer* printer) const = 0;
58  virtual void GeneratePropertyImplementation(io::Printer* printer) const = 0;
59 
60  // Called by GenerateFieldDescription, exposed for classes that need custom
61  // generation.
62 
63  // Exposed for subclasses to extend, base does nothing.
64  virtual void GenerateCFunctionDeclarations(io::Printer* printer) const;
65  virtual void GenerateCFunctionImplementations(io::Printer* printer) const;
66 
67  // Exposed for subclasses, should always call it on the parent class also.
68  virtual void DetermineForwardDeclarations(
69  std::set<std::string>* fwd_decls) const;
71  std::set<std::string>* fwd_decls) const;
72 
73  // Used during generation, not intended to be extended by subclasses.
75  io::Printer* printer, bool include_default) const;
76  void GenerateFieldNumberConstant(io::Printer* printer) const;
77 
78  // Exposed to get and set the has bits information.
79  virtual bool RuntimeUsesHasBit(void) const = 0;
80  void SetRuntimeHasBit(int has_index);
81  void SetNoHasBit(void);
82  virtual int ExtraRuntimeHasBitsNeeded(void) const;
83  virtual void SetExtraRuntimeHasBitsBase(int index_base);
84  void SetOneofIndexBase(int index_base);
85 
86  std::string variable(const char* key) const {
87  return variables_.find(key)->second;
88  }
89 
91  const std::string& field_flags = variable("fieldflags");
92  return field_flags.find("GPBFieldTextFormatNameCustom") !=
93  std::string::npos;
94  }
95  std::string generated_objc_name() const { return variable("name"); }
96  std::string raw_field_name() const { return variable("raw_field_name"); }
97 
98  protected:
100 
101  virtual void FinishInitialization(void);
102  bool WantsHasProperty(void) const;
103 
105  std::map<std::string, std::string> variables_;
106 };
107 
108 class SingleFieldGenerator : public FieldGenerator {
109  public:
110  virtual ~SingleFieldGenerator();
111 
114 
115  virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override;
116  virtual void GeneratePropertyDeclaration(io::Printer* printer) const override;
117 
118  virtual void GeneratePropertyImplementation(io::Printer* printer) const override;
119 
120  virtual bool RuntimeUsesHasBit(void) const override;
121 
122  protected:
124  const Options& options);
125 };
126 
127 // Subclass with common support for when the field ends up as an ObjC Object.
128 class ObjCObjFieldGenerator : public SingleFieldGenerator {
129  public:
130  virtual ~ObjCObjFieldGenerator();
131 
134 
135  virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override;
136  virtual void GeneratePropertyDeclaration(io::Printer* printer) const override;
137 
138  protected:
140  const Options& options);
141 };
142 
143 class RepeatedFieldGenerator : public ObjCObjFieldGenerator {
144  public:
145  virtual ~RepeatedFieldGenerator();
146 
149 
150  virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override;
151  virtual void GeneratePropertyDeclaration(io::Printer* printer) const override;
152 
153  virtual void GeneratePropertyImplementation(io::Printer* printer) const override;
154 
155  virtual bool RuntimeUsesHasBit(void) const override;
156 
157  protected:
159  const Options& options);
160  virtual void FinishInitialization(void) override;
161 };
162 
163 // Convenience class which constructs FieldGenerators for a Descriptor.
164 class FieldGeneratorMap {
165  public:
166  FieldGeneratorMap(const Descriptor* descriptor, const Options& options);
168 
169  FieldGeneratorMap(const FieldGeneratorMap&) = delete;
171 
172  const FieldGenerator& get(const FieldDescriptor* field) const;
173  const FieldGenerator& get_extension(int index) const;
174 
175  // Assigns the has bits and returns the number of bits needed.
176  int CalculateHasBits(void);
177 
178  void SetOneofIndexBase(int index_base);
179 
180  // Check if any field of this message has a non zero default.
181  bool DoesAnyFieldHaveNonZeroDefault(void) const;
182 
183  private:
184  const Descriptor* descriptor_;
185  std::vector<std::unique_ptr<FieldGenerator>> field_generators_;
186  std::vector<std::unique_ptr<FieldGenerator>> extension_generators_;
187 };
188 
189 } // namespace objectivec
190 } // namespace compiler
191 } // namespace protobuf
192 } // namespace google
193 
194 #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__
google::protobuf::compiler::objectivec::FieldGeneratorMap::DoesAnyFieldHaveNonZeroDefault
bool DoesAnyFieldHaveNonZeroDefault(void) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:461
google::protobuf::compiler::objectivec::FieldGeneratorMap::operator=
FieldGeneratorMap & operator=(const FieldGeneratorMap &)=delete
google::protobuf::FieldDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:515
google::protobuf::compiler::objectivec::ObjCObjFieldGenerator::operator=
ObjCObjFieldGenerator & operator=(const ObjCObjFieldGenerator &)=delete
google::protobuf::compiler::objectivec::FieldGenerator::ExtraRuntimeHasBitsNeeded
virtual int ExtraRuntimeHasBitsNeeded(void) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:223
google::protobuf::compiler::objectivec::FieldGeneratorMap::FieldGeneratorMap
FieldGeneratorMap(const Descriptor *descriptor, const Options &options)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:409
google::protobuf::compiler::objectivec::FieldGeneratorMap::extension_generators_
std::vector< std::unique_ptr< FieldGenerator > > extension_generators_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:184
google::protobuf::compiler::objectivec::FieldGenerator::variables_
std::map< std::string, std::string > variables_
Definition: protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:105
google::protobuf::compiler::objectivec::SingleFieldGenerator::SingleFieldGenerator
SingleFieldGenerator(const SingleFieldGenerator &)=delete
google::protobuf::compiler::objectivec::FieldGenerator::SetExtraRuntimeHasBitsBase
virtual void SetExtraRuntimeHasBitsBase(int index_base)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:227
options
double_dict options[]
Definition: capstone_test.c:55
google::protobuf::compiler::objectivec::FieldGenerator::descriptor_
const FieldDescriptor * descriptor_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:100
google::protobuf::compiler::objectivec::FieldGenerator::GenerateCFunctionDeclarations
virtual void GenerateCFunctionDeclarations(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:169
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf::compiler::objectivec::FieldGenerator::WantsHasProperty
virtual bool WantsHasProperty(void) const =0
Definition: protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:257
grpc::protobuf::io::Printer
GRPC_CUSTOM_PRINTER Printer
Definition: src/compiler/config.h:54
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf::compiler::objectivec::SingleFieldGenerator::~SingleFieldGenerator
virtual ~SingleFieldGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:257
google::protobuf::compiler::objectivec::FieldGenerator
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:45
google::protobuf::compiler::objectivec::FieldGeneratorMap::CalculateHasBits
int CalculateHasBits(void)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:437
google::protobuf::compiler::objectivec::Options
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.h:50
google::protobuf::compiler::objectivec::SingleFieldGenerator::operator=
SingleFieldGenerator & operator=(const SingleFieldGenerator &)=delete
google::protobuf::compiler::objectivec::FieldGenerator::FieldGenerator
FieldGenerator(const FieldGenerator &)=delete
google::protobuf::compiler::objectivec::FieldGenerator::variable
string variable(const char *key) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:83
google::protobuf::compiler::objectivec::FieldGenerator::GeneratePropertyImplementation
virtual void GeneratePropertyImplementation(io::Printer *printer) const =0
google::protobuf::compiler::objectivec::FieldGenerator::needs_textformat_name_support
bool needs_textformat_name_support() const
Definition: protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:90
google::protobuf::compiler::objectivec::SingleFieldGenerator::GeneratePropertyDeclaration
virtual void GeneratePropertyDeclaration(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:264
Descriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:121
google::protobuf::compiler::objectivec::FieldGenerator::variable
std::string variable(const char *key) const
Definition: protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:86
google::protobuf::compiler::objectivec::FieldGenerator::GenerateFieldNumberConstant
void GenerateFieldNumberConstant(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:163
google::protobuf::compiler::objectivec::RepeatedFieldGenerator::FinishInitialization
virtual void FinishInitialization(void)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:358
google::protobuf::compiler::objectivec::FieldGenerator::operator=
FieldGenerator & operator=(const FieldGenerator &)=delete
FieldDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:133
google::protobuf::compiler::objectivec::RepeatedFieldGenerator::GeneratePropertyImplementation
virtual void GeneratePropertyImplementation(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:370
google::protobuf::compiler::objectivec::FieldGenerator::RuntimeUsesHasBit
virtual bool RuntimeUsesHasBit(void) const =0
google::protobuf::compiler::objectivec::FieldGeneratorMap::descriptor_
const Descriptor * descriptor_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:182
google::protobuf::compiler::objectivec::FieldGenerator::GeneratePropertyDeclaration
virtual void GeneratePropertyDeclaration(io::Printer *printer) const =0
google::protobuf::compiler::objectivec::FieldGenerator::GenerateFieldStorageDeclaration
virtual void GenerateFieldStorageDeclaration(io::Printer *printer) const =0
google::protobuf::compiler::objectivec::FieldGeneratorMap::get_extension
const FieldGenerator & get_extension(int index) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:433
google::protobuf::compiler::objectivec::FieldGenerator::Make
static FieldGenerator * Make(const FieldDescriptor *field, const Options &options)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:113
google::protobuf::compiler::objectivec::FieldGeneratorMap::SetOneofIndexBase
void SetOneofIndexBase(int index_base)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:455
google::protobuf::compiler::objectivec::FieldGenerator::SetOneofIndexBase
void SetOneofIndexBase(int index_base)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:235
google::protobuf::compiler::objectivec::SingleFieldGenerator::GenerateFieldStorageDeclaration
virtual void GenerateFieldStorageDeclaration(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:259
google::protobuf::compiler::objectivec::RepeatedFieldGenerator::GeneratePropertyDeclaration
virtual void GeneratePropertyDeclaration(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:375
google::protobuf::io::Printer
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/printer.h:181
google::protobuf::compiler::objectivec::RepeatedFieldGenerator::RepeatedFieldGenerator
RepeatedFieldGenerator(const RepeatedFieldGenerator &)=delete
google::protobuf::compiler::objectivec::FieldGenerator::DetermineObjectiveCClassDefinitions
virtual void DetermineObjectiveCClassDefinitions(std::set< std::string > *fwd_decls) const
Definition: protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:192
google::protobuf::compiler::objectivec::RepeatedFieldGenerator::~RepeatedFieldGenerator
virtual ~RepeatedFieldGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:356
google::protobuf::compiler::objectivec::FieldGenerator::SetNoHasBit
void SetNoHasBit(void)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:219
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
key
const char * key
Definition: hpack_parser_table.cc:164
google::protobuf::compiler::objectivec::ObjCObjFieldGenerator::GeneratePropertyDeclaration
virtual void GeneratePropertyDeclaration(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:323
google::protobuf::compiler::objectivec::SingleFieldGenerator::RuntimeUsesHasBit
virtual bool RuntimeUsesHasBit(void) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:299
google::protobuf::compiler::objectivec::RepeatedFieldGenerator::RuntimeUsesHasBit
virtual bool RuntimeUsesHasBit(void) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:405
google::protobuf::compiler::objectivec::RepeatedFieldGenerator::GenerateFieldStorageDeclaration
virtual void GenerateFieldStorageDeclaration(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:365
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
google::protobuf::compiler::objectivec::FieldGenerator::GenerateFieldDescription
void GenerateFieldDescription(io::Printer *printer, bool include_default) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:184
google::protobuf::compiler::objectivec::FieldGeneratorMap::get
const FieldGenerator & get(const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:427
google::protobuf::compiler::objectivec::FieldGenerator::GenerateCFunctionImplementations
virtual void GenerateCFunctionImplementations(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:174
google::protobuf::compiler::objectivec::FieldGenerator::DetermineForwardDeclarations
virtual void DetermineForwardDeclarations(std::set< string > *fwd_decls) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:179
google::protobuf::compiler::objectivec::FieldGeneratorMap::field_generators_
std::vector< std::unique_ptr< FieldGenerator > > field_generators_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:183
google::protobuf::compiler::objectivec::FieldGenerator::variables_
std::map< string, string > variables_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:101
google::protobuf::compiler::objectivec::ObjCObjFieldGenerator::ObjCObjFieldGenerator
ObjCObjFieldGenerator(const ObjCObjFieldGenerator &)=delete
google::protobuf::compiler::objectivec::RepeatedFieldGenerator::operator=
RepeatedFieldGenerator & operator=(const RepeatedFieldGenerator &)=delete
google::protobuf::compiler::objectivec::ObjCObjFieldGenerator::GenerateFieldStorageDeclaration
virtual void GenerateFieldStorageDeclaration(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:318
google::protobuf::compiler::objectivec::FieldGenerator::~FieldGenerator
virtual ~FieldGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:161
google::protobuf::compiler::objectivec::FieldGeneratorMap::~FieldGeneratorMap
~FieldGeneratorMap()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:425
google::protobuf::compiler::objectivec::SingleFieldGenerator
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:104
google::protobuf::compiler::objectivec::ObjCObjFieldGenerator::~ObjCObjFieldGenerator
virtual ~ObjCObjFieldGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:316
descriptor
static const char descriptor[1336]
Definition: certs.upbdefs.c:16
google::protobuf::compiler::objectivec::FieldGenerator::SetRuntimeHasBit
void SetRuntimeHasBit(int has_index)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:215
google::protobuf::compiler::objectivec::FieldGenerator::generated_objc_name
std::string generated_objc_name() const
Definition: protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:95
compiler
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/plugin.pb.cc:21
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf::compiler::objectivec::FieldGenerator::FinishInitialization
virtual void FinishInitialization(void)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:243
google::protobuf::compiler::objectivec::SingleFieldGenerator::GeneratePropertyImplementation
virtual void GeneratePropertyImplementation(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc:278
google::protobuf::compiler::objectivec::FieldGenerator::raw_field_name
std::string raw_field_name() const
Definition: protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h:96


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:34