Line data Source code
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 :
37 : #include <google/protobuf/descriptor.h>
38 : #include <google/protobuf/descriptor.pb.h>
39 :
40 : namespace google {
41 : namespace protobuf {
42 : namespace compiler {
43 : namespace objectivec {
44 :
45 : // Strips ".proto" or ".protodevel" from the end of a filename.
46 : string StripProto(const string& filename);
47 :
48 : // Returns true if the name requires a ns_returns_not_retained attribute applied
49 : // to it.
50 : bool IsRetainedName(const string& name);
51 :
52 : // Returns true if the name starts with "init" and will need to have special
53 : // handling under ARC.
54 : bool IsInitName(const string& name);
55 :
56 : // Gets the name of the file we're going to generate (sans the .pb.h
57 : // extension). This does not include the path to that file.
58 : string FileName(const FileDescriptor* file);
59 :
60 : // Gets the path of the file we're going to generate (sans the .pb.h
61 : // extension). The path will be dependent on the objectivec package
62 : // declared in the proto package.
63 : string FilePath(const FileDescriptor* file);
64 :
65 : // Gets the name of the root class we'll generate in the file. This class
66 : // is not meant for external consumption, but instead contains helpers that
67 : // the rest of the the classes need
68 : string FileClassName(const FileDescriptor* file);
69 :
70 : // These return the fully-qualified class name corresponding to the given
71 : // descriptor.
72 : string ClassName(const Descriptor* descriptor);
73 : string EnumName(const EnumDescriptor* descriptor);
74 :
75 : // Returns the fully-qualified name of the enum value corresponding to the
76 : // the descriptor.
77 : string EnumValueName(const EnumValueDescriptor* descriptor);
78 :
79 : // Returns the name of the enum value corresponding to the descriptor.
80 : string EnumValueShortName(const EnumValueDescriptor* descriptor);
81 :
82 : // Reverse what an enum does.
83 : string UnCamelCaseEnumShortName(const string& name);
84 :
85 : // Returns the name to use for the extension (used as the method off the file's
86 : // Root class).
87 : string ExtensionMethodName(const FieldDescriptor* descriptor);
88 :
89 : // Returns the transformed field name.
90 : string FieldName(const FieldDescriptor* field);
91 : string FieldNameCapitalized(const FieldDescriptor* field);
92 :
93 : // Returns the transformed oneof name.
94 : string OneofEnumName(const OneofDescriptor* descriptor);
95 : string OneofName(const OneofDescriptor* descriptor);
96 : string OneofNameCapitalized(const OneofDescriptor* descriptor);
97 :
98 0 : inline bool HasFieldPresence(const FileDescriptor* file) {
99 0 : return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
100 : }
101 :
102 0 : inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) {
103 0 : return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
104 : }
105 :
106 0 : inline bool IsMapEntryMessage(const Descriptor* descriptor) {
107 0 : return descriptor->options().map_entry();
108 : }
109 :
110 : // Reverse of the above.
111 : string UnCamelCaseFieldName(const string& name, const FieldDescriptor* field);
112 :
113 : enum ObjectiveCType {
114 : OBJECTIVECTYPE_INT32,
115 : OBJECTIVECTYPE_UINT32,
116 : OBJECTIVECTYPE_INT64,
117 : OBJECTIVECTYPE_UINT64,
118 : OBJECTIVECTYPE_FLOAT,
119 : OBJECTIVECTYPE_DOUBLE,
120 : OBJECTIVECTYPE_BOOLEAN,
121 : OBJECTIVECTYPE_STRING,
122 : OBJECTIVECTYPE_DATA,
123 : OBJECTIVECTYPE_ENUM,
124 : OBJECTIVECTYPE_MESSAGE
125 : };
126 :
127 : string GetCapitalizedType(const FieldDescriptor* field);
128 :
129 : ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type);
130 :
131 0 : inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) {
132 0 : return GetObjectiveCType(field->type());
133 : }
134 :
135 : bool IsPrimitiveType(const FieldDescriptor* field);
136 : bool IsReferenceType(const FieldDescriptor* field);
137 :
138 : string GPBGenericValueFieldName(const FieldDescriptor* field);
139 : string DefaultValue(const FieldDescriptor* field);
140 :
141 : string BuildFlagsString(const vector<string>& strings);
142 :
143 : string BuildCommentsString(const SourceLocation& location);
144 :
145 : // Checks the prefix for a given file and outputs any warnings needed, if
146 : // there are flat out errors, then out_error is filled in and the result is
147 : // false.
148 : bool ValidateObjCClassPrefix(const FileDescriptor* file, string *out_error);
149 :
150 : // Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform
151 : // the input into the the expected output.
152 0 : class LIBPROTOC_EXPORT TextFormatDecodeData {
153 : public:
154 0 : TextFormatDecodeData() {}
155 :
156 : void AddString(int32 key, const string& input_for_decode,
157 : const string& desired_output);
158 0 : size_t num_entries() const { return entries_.size(); }
159 : string Data() const;
160 :
161 : static string DecodeDataForString(const string& input_for_decode,
162 : const string& desired_output);
163 :
164 : private:
165 : GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormatDecodeData);
166 :
167 : typedef std::pair<int32, string> DataEntry;
168 : vector<DataEntry> entries_;
169 : };
170 :
171 : } // namespace objectivec
172 : } // namespace compiler
173 : } // namespace protobuf
174 : } // namespace google
175 : #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
|