webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
objectivec_helpers.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_HELPERS_H__
32 #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
33 
34 #include <string>
35 #include <vector>
36 
39 
40 namespace google {
41 namespace protobuf {
42 namespace compiler {
43 namespace objectivec {
44 
45 // Generator options (see objectivec_generator.cc for a description of each):
46 struct Options {
47  Options();
49 };
50 
51 // Escape C++ trigraphs by escaping question marks to "\?".
52 string EscapeTrigraphs(const string& to_escape);
53 
54 // Strips ".proto" or ".protodevel" from the end of a filename.
55 string StripProto(const string& filename);
56 
57 // Returns true if the name requires a ns_returns_not_retained attribute applied
58 // to it.
59 bool IsRetainedName(const string& name);
60 
61 // Returns true if the name starts with "init" and will need to have special
62 // handling under ARC.
63 bool IsInitName(const string& name);
64 
65 // Gets the name of the file we're going to generate (sans the .pb.h
66 // extension). This does not include the path to that file.
67 string FileName(const FileDescriptor* file);
68 
69 // Gets the path of the file we're going to generate (sans the .pb.h
70 // extension). The path will be dependent on the objectivec package
71 // declared in the proto package.
72 string FilePath(const FileDescriptor* file);
73 
74 // Gets the name of the root class we'll generate in the file. This class
75 // is not meant for external consumption, but instead contains helpers that
76 // the rest of the classes need
77 string FileClassName(const FileDescriptor* file);
78 
79 // These return the fully-qualified class name corresponding to the given
80 // descriptor.
81 string ClassName(const Descriptor* descriptor);
82 string EnumName(const EnumDescriptor* descriptor);
83 
84 // Returns the fully-qualified name of the enum value corresponding to the
85 // the descriptor.
87 
88 // Returns the name of the enum value corresponding to the descriptor.
90 
91 // Reverse what an enum does.
92 string UnCamelCaseEnumShortName(const string& name);
93 
94 // Returns the name to use for the extension (used as the method off the file's
95 // Root class).
97 
98 // Returns the transformed field name.
99 string FieldName(const FieldDescriptor* field);
101 
102 // Returns the transformed oneof name.
104 string OneofName(const OneofDescriptor* descriptor);
106 
107 inline bool HasFieldPresence(const FileDescriptor* file) {
108  return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
109 }
110 
112  return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
113 }
114 
116  return descriptor->options().map_entry();
117 }
118 
119 // Reverse of the above.
120 string UnCamelCaseFieldName(const string& name, const FieldDescriptor* field);
121 
134 };
135 
136 template<class TDescriptor>
137 string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, bool preSpace = true, bool postNewline = false) {
138  if (descriptor->options().deprecated()) {
139  string result = "DEPRECATED_ATTRIBUTE";
140  if (preSpace) {
141  result.insert(0, " ");
142  }
143  if (postNewline) {
144  result.append("\n");
145  }
146  return result;
147  } else {
148  return "";
149  }
150 }
151 
152 string GetCapitalizedType(const FieldDescriptor* field);
153 
155 
157  return GetObjectiveCType(field->type());
158 }
159 
160 bool IsPrimitiveType(const FieldDescriptor* field);
161 bool IsReferenceType(const FieldDescriptor* field);
162 
163 string GPBGenericValueFieldName(const FieldDescriptor* field);
164 string DefaultValue(const FieldDescriptor* field);
165 bool HasNonZeroDefaultValue(const FieldDescriptor* field);
166 
167 string BuildFlagsString(const vector<string>& strings);
168 
169 // Builds a HeaderDoc style comment out of the comments in the .proto file.
171 
172 // Checks the prefix for a given file and outputs any warnings needed, if
173 // there are flat out errors, then out_error is filled in and the result is
174 // false.
176  const Options& generation_options,
177  string* out_error);
178 
179 // Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform
180 // the input into the expected output.
182  public:
184 
185  void AddString(int32 key, const string& input_for_decode,
186  const string& desired_output);
187  size_t num_entries() const { return entries_.size(); }
188  string Data() const;
189 
190  static string DecodeDataForString(const string& input_for_decode,
191  const string& desired_output);
192 
193  private:
195 
196  typedef std::pair<int32, string> DataEntry;
197  vector<DataEntry> entries_;
198 };
199 
200 } // namespace objectivec
201 } // namespace compiler
202 } // namespace protobuf
203 } // namespace google
204 #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
string FieldNameCapitalized(const FieldDescriptor *field)
Definition: objectivec_helpers.cc:442
Definition: upb.c:6604
bool IsPrimitiveType(const FieldDescriptor *field)
Definition: objectivec_helpers.cc:603
string OneofName(const OneofDescriptor *descriptor)
Definition: objectivec_helpers.cc:460
Definition: descriptor.h:801
bool IsRetainedName(const string &name)
Definition: objectivec_helpers.cc:275
string UnCamelCaseEnumShortName(const string &name)
Definition: objectivec_helpers.cc:409
const FieldDescriptor * field
Definition: parser_unittest.cc:2279
Options()
Definition: objectivec_helpers.cc:61
string GPBGenericValueFieldName(const FieldDescriptor *field)
Definition: objectivec_helpers.cc:643
Definition: descriptor.h:136
string UnCamelCaseFieldName(const string &name, const FieldDescriptor *field)
Definition: objectivec_helpers.cc:476
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)
Definition: macros.h:40
const MessageOptions & options() const
ObjectiveCType
Definition: objectivec_helpers.h:122
const Descriptor * descriptor
Definition: descriptor.cc:271
string BuildFlagsString(const vector< string > &strings)
Definition: objectivec_helpers.cc:799
bool ValidateObjCClassPrefix(const FileDescriptor *file, const Options &generation_options, string *out_error)
Definition: objectivec_helpers.cc:988
Definition: descriptor.h:1156
Definition: descriptor.h:172
size_t num_entries() const
Definition: objectivec_helpers.h:187
bool IsMapEntryMessage(const Descriptor *descriptor)
Definition: objectivec_helpers.h:115
string ClassName(const Descriptor *descriptor)
Definition: objectivec_helpers.cc:353
string OneofEnumName(const OneofDescriptor *descriptor)
Definition: objectivec_helpers.cc:452
USVString filename
Definition: ErrorEvent.idl:46
Definition: objectivec_helpers.h:46
Definition: descriptor.h:439
GLint location
Definition: gl2.h:455
string expected_prefixes_path
Definition: objectivec_helpers.h:48
VoEFile * file
Definition: voe_cmd_test.cc:59
int32_t int32
Definition: port.h:130
string FileName(const FileDescriptor *file)
Definition: objectivec_helpers.cc:296
string EnumValueName(const EnumValueDescriptor *descriptor)
Definition: objectivec_helpers.cc:375
Type
Definition: descriptor.h:443
string GetOptionalDeprecatedAttribute(const TDescriptor *descriptor, bool preSpace=true, bool postNewline=false)
Definition: objectivec_helpers.h:137
bool HasPreservingUnknownEnumSemantics(const FileDescriptor *file)
Definition: objectivec_helpers.h:111
Definition: CompareAndSwapTest.cpp:70
EGLImageKHR EGLint * name
Definition: eglext.h:851
Definition: __init__.py:1
bool HasFieldPresence(const FileDescriptor *file)
Definition: objectivec_helpers.h:107
string StripProto(const string &filename)
Definition: objectivec_helpers.cc:267
bool IsReferenceType(const FieldDescriptor *field)
Definition: objectivec_helpers.cc:621
WireFormatLite::FieldType field_type(FieldType type)
Definition: extension_set_heavy.cc:133
result
Definition: target-blank-opener-post-window.php:5
string DefaultValue(const FieldDescriptor *field)
Definition: objectivec_helpers.cc:683
string FieldName(const FieldDescriptor *field)
Definition: objectivec_helpers.cc:427
string EnumName(const EnumDescriptor *descriptor)
Definition: objectivec_helpers.cc:361
bool HasNonZeroDefaultValue(const FieldDescriptor *field)
Definition: objectivec_helpers.cc:754
#define LIBPROTOC_EXPORT
Definition: port.h:98
bool IsInitName(const string &name)
Definition: objectivec_helpers.cc:284
string FilePath(const FileDescriptor *file)
Definition: objectivec_helpers.cc:303
TextFormatDecodeData()
Definition: objectivec_helpers.h:183
Syntax syntax() const
Definition: descriptor.h:1899
string FileClassName(const FileDescriptor *file)
Definition: objectivec_helpers.cc:326
bool map_entry() const
Definition: descriptor.pb.h:6368
string GetCapitalizedType(const FieldDescriptor *field)
Definition: objectivec_helpers.cc:508
Definition: gflags_completions.h:115
Definition: descriptor.h:919
ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type)
Definition: objectivec_helpers.cc:554
string EnumValueShortName(const EnumValueDescriptor *descriptor)
Definition: objectivec_helpers.cc:390
GLsizei const GLchar ** strings
Definition: gl2ext.h:1828
CFArrayRef CFTypeRef key
Definition: AVFoundationCFSoftLinking.h:129
Definition: descriptor.h:736
string EscapeTrigraphs(const string &to_escape)
Definition: objectivec_helpers.cc:263
string ExtensionMethodName(const FieldDescriptor *descriptor)
Definition: objectivec_helpers.cc:421
string OneofNameCapitalized(const OneofDescriptor *descriptor)
Definition: objectivec_helpers.cc:467
string BuildCommentsString(const SourceLocation &location)
Definition: objectivec_helpers.cc:813