webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
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>
39 
40 namespace google {
41 namespace protobuf {
42 
43 namespace io {
44 class Printer; // printer.h
45 } // namespace io
46 
47 namespace compiler {
48 namespace objectivec {
49 
51  public:
52  static FieldGenerator* Make(const FieldDescriptor* field,
53  const Options& options);
54 
55  virtual ~FieldGenerator();
56 
57  // Exposed for subclasses to fill in.
58  virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const = 0;
59  virtual void GeneratePropertyDeclaration(io::Printer* printer) const = 0;
60  virtual void GeneratePropertyImplementation(io::Printer* printer) const = 0;
61 
62  // Called by GenerateFieldDescription, exposed for classes that need custom
63  // generation.
64 
65  // Exposed for subclasses to extend, base does nothing.
66  virtual void GenerateCFunctionDeclarations(io::Printer* printer) const;
67  virtual void GenerateCFunctionImplementations(io::Printer* printer) const;
68 
69  // Exposed for subclasses, should always call it on the parent class also.
70  virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const;
71 
72  // Used during generation, not intended to be extended by subclasses.
73  void GenerateFieldDescription(
74  io::Printer* printer, bool include_default) const;
75  void GenerateFieldNumberConstant(io::Printer* printer) const;
76 
77  // Exposed to get and set the has bits information.
78  virtual bool RuntimeUsesHasBit(void) const = 0;
79  void SetRuntimeHasBit(int has_index);
80  void SetNoHasBit(void);
81  virtual int ExtraRuntimeHasBitsNeeded(void) const;
82  virtual void SetExtraRuntimeHasBitsBase(int index_base);
83  void SetOneofIndexBase(int index_base);
84 
85  string variable(const char* key) const {
86  return variables_.find(key)->second;
87  }
88 
90  const string& field_flags = variable("fieldflags");
91  return field_flags.find("GPBFieldTextFormatNameCustom") != string::npos;
92  }
93  string generated_objc_name() const { return variable("name"); }
94  string raw_field_name() const { return variable("raw_field_name"); }
95 
96  protected:
97  FieldGenerator(const FieldDescriptor* descriptor, const Options& options);
98 
99  virtual void FinishInitialization(void);
100  virtual bool WantsHasProperty(void) const = 0;
101 
103  map<string, string> variables_;
104 
105  private:
107 };
108 
110  public:
111  virtual ~SingleFieldGenerator();
112 
113  virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const;
114  virtual void GeneratePropertyDeclaration(io::Printer* printer) const;
115 
116  virtual void GeneratePropertyImplementation(io::Printer* printer) const;
117 
118  virtual bool RuntimeUsesHasBit(void) const;
119 
120  protected:
122  const Options& options);
123  virtual bool WantsHasProperty(void) const;
124 
125  private:
127 };
128 
129 // Subclass with common support for when the field ends up as an ObjC Object.
131  public:
132  virtual ~ObjCObjFieldGenerator();
133 
134  virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const;
135  virtual void GeneratePropertyDeclaration(io::Printer* printer) const;
136 
137  protected:
139  const Options& options);
140 
141  private:
143 };
144 
146  public:
147  virtual ~RepeatedFieldGenerator();
148 
149  virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const;
150  virtual void GeneratePropertyDeclaration(io::Printer* printer) const;
151 
152  virtual void GeneratePropertyImplementation(io::Printer* printer) const;
153 
154  virtual bool RuntimeUsesHasBit(void) const;
155 
156  protected:
158  const Options& options);
159  virtual void FinishInitialization(void);
160  virtual bool WantsHasProperty(void) const;
161 
162  private:
164 };
165 
166 // Convenience class which constructs FieldGenerators for a Descriptor.
168  public:
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  scoped_array<scoped_ptr<FieldGenerator> > field_generators_;
186  scoped_array<scoped_ptr<FieldGenerator> > extension_generators_;
187 
189 };
190 } // namespace objectivec
191 } // namespace compiler
192 } // namespace protobuf
193 } // namespace google
194 #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__
Definition: upb.c:6604
Definition: printer.h:164
const FieldDescriptor * field
Definition: parser_unittest.cc:2279
bool needs_textformat_name_support() const
Definition: objectivec_field.h:89
map< string, string > variables_
Definition: objectivec_field.h:103
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)
Definition: macros.h:40
options
Definition: CodeGeneratorReplayInputs.py:1046
const Descriptor * descriptor_
Definition: field_comparator_test.cc:58
const FieldDescriptor * descriptor_
Definition: objectivec_field.h:102
const Descriptor * descriptor
Definition: descriptor.cc:271
Definition: descriptor.h:172
Definition: objectivec_helpers.h:46
Definition: descriptor.h:439
string raw_field_name() const
Definition: objectivec_field.h:94
Definition: scoped_ptr.h:49
GLuint index
Definition: gl2.h:383
string variable(const char *key) const
Definition: objectivec_field.h:85
Definition: __init__.py:1
string generated_objc_name() const
Definition: objectivec_field.h:93
EGLSetBlobFuncANDROID set
Definition: eglext.h:426
Definition: gflags_completions.h:115
CFArrayRef CFTypeRef key
Definition: AVFoundationCFSoftLinking.h:129