Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(684)

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc

Issue 1291903002: Pull new version of protobuf sources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include <map>
32 #include <string>
33
34 #include <google/protobuf/compiler/objectivec/objectivec_primitive_field.h>
35 #include <google/protobuf/stubs/common.h>
36 #include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
37 #include <google/protobuf/io/printer.h>
38 #include <google/protobuf/wire_format.h>
39 #include <google/protobuf/wire_format_lite_inl.h>
40 #include <google/protobuf/stubs/strutil.h>
41 #include <google/protobuf/stubs/substitute.h>
42
43 namespace google {
44 namespace protobuf {
45 namespace compiler {
46 namespace objectivec {
47
48 using internal::WireFormat;
49 using internal::WireFormatLite;
50
51 namespace {
52
53 const char* PrimitiveTypeName(const FieldDescriptor* descriptor) {
54 ObjectiveCType type = GetObjectiveCType(descriptor);
55 switch (type) {
56 case OBJECTIVECTYPE_INT32:
57 return "int32_t";
58 case OBJECTIVECTYPE_UINT32:
59 return "uint32_t";
60 case OBJECTIVECTYPE_INT64:
61 return "int64_t";
62 case OBJECTIVECTYPE_UINT64:
63 return "uint64_t";
64 case OBJECTIVECTYPE_FLOAT:
65 return "float";
66 case OBJECTIVECTYPE_DOUBLE:
67 return "double";
68 case OBJECTIVECTYPE_BOOLEAN:
69 return "BOOL";
70 case OBJECTIVECTYPE_STRING:
71 return "NSString";
72 case OBJECTIVECTYPE_DATA:
73 return "NSData";
74 case OBJECTIVECTYPE_ENUM:
75 return "int32_t";
76 case OBJECTIVECTYPE_MESSAGE:
77 return NULL;
78 }
79
80 // Some compilers report reaching end of function even though all cases of
81 // the enum are handed in the switch.
82 GOOGLE_LOG(FATAL) << "Can't get here.";
83 return NULL;
84 }
85
86 const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) {
87 ObjectiveCType type = GetObjectiveCType(descriptor);
88 switch (type) {
89 case OBJECTIVECTYPE_INT32:
90 return "Int32";
91 case OBJECTIVECTYPE_UINT32:
92 return "UInt32";
93 case OBJECTIVECTYPE_INT64:
94 return "Int64";
95 case OBJECTIVECTYPE_UINT64:
96 return "UInt64";
97 case OBJECTIVECTYPE_FLOAT:
98 return "Float";
99 case OBJECTIVECTYPE_DOUBLE:
100 return "Double";
101 case OBJECTIVECTYPE_BOOLEAN:
102 return "Bool";
103 case OBJECTIVECTYPE_STRING:
104 return ""; // Want NSArray
105 case OBJECTIVECTYPE_DATA:
106 return ""; // Want NSArray
107 case OBJECTIVECTYPE_ENUM:
108 return "Enum";
109 case OBJECTIVECTYPE_MESSAGE:
110 return ""; // Want NSArray
111 }
112
113 // Some compilers report reaching end of function even though all cases of
114 // the enum are handed in the switch.
115 GOOGLE_LOG(FATAL) << "Can't get here.";
116 return NULL;
117 }
118
119 void SetPrimitiveVariables(const FieldDescriptor* descriptor,
120 map<string, string>* variables) {
121 std::string primitive_name = PrimitiveTypeName(descriptor);
122 (*variables)["type"] = primitive_name;
123 (*variables)["storage_type"] = primitive_name;
124 }
125
126 } // namespace
127
128 PrimitiveFieldGenerator::PrimitiveFieldGenerator(
129 const FieldDescriptor* descriptor)
130 : SingleFieldGenerator(descriptor) {
131 SetPrimitiveVariables(descriptor, &variables_);
132 }
133
134 PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {}
135
136 PrimitiveObjFieldGenerator::PrimitiveObjFieldGenerator(
137 const FieldDescriptor* descriptor)
138 : ObjCObjFieldGenerator(descriptor) {
139 SetPrimitiveVariables(descriptor, &variables_);
140 variables_["property_storage_attribute"] = "copy";
141 }
142
143 PrimitiveObjFieldGenerator::~PrimitiveObjFieldGenerator() {}
144
145 RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
146 const FieldDescriptor* descriptor)
147 : RepeatedFieldGenerator(descriptor) {
148 SetPrimitiveVariables(descriptor, &variables_);
149
150 string base_name = PrimitiveArrayTypeName(descriptor);
151 if (base_name.length()) {
152 variables_["array_storage_type"] = "GPB" + base_name + "Array";
153 } else {
154 variables_["array_storage_type"] = "NSMutableArray";
155 }
156 }
157
158 RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {}
159
160 void RepeatedPrimitiveFieldGenerator::FinishInitialization(void) {
161 RepeatedFieldGenerator::FinishInitialization();
162 if (IsPrimitiveType(descriptor_)) {
163 // No comment needed for primitive types.
164 variables_["array_comment"] = "";
165 }
166 }
167
168 } // namespace objectivec
169 } // namespace compiler
170 } // namespace protobuf
171 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698