objectivec_primitive_field.cc
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 #include <map>
32 #include <string>
33 
40 
41 namespace google {
42 namespace protobuf {
43 namespace compiler {
44 namespace objectivec {
45 
46 using internal::WireFormat;
47 using internal::WireFormatLite;
48 
49 namespace {
50 
51 const char* PrimitiveTypeName(const FieldDescriptor* descriptor) {
53  switch (type) {
55  return "int32_t";
57  return "uint32_t";
59  return "int64_t";
61  return "uint64_t";
63  return "float";
65  return "double";
67  return "BOOL";
69  return "NSString";
71  return "NSData";
73  return "int32_t";
75  return NULL; // Messages go through objectivec_message_field.cc|h.
76  }
77 
78  // Some compilers report reaching end of function even though all cases of
79  // the enum are handed in the switch.
80  GOOGLE_LOG(FATAL) << "Can't get here.";
81  return NULL;
82 }
83 
84 const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) {
86  switch (type) {
88  return "Int32";
90  return "UInt32";
92  return "Int64";
94  return "UInt64";
96  return "Float";
98  return "Double";
100  return "Bool";
102  return ""; // Want NSArray
103  case OBJECTIVECTYPE_DATA:
104  return ""; // Want NSArray
105  case OBJECTIVECTYPE_ENUM:
106  return "Enum";
108  // Want NSArray (but goes through objectivec_message_field.cc|h).
109  return "";
110  }
111 
112  // Some compilers report reaching end of function even though all cases of
113  // the enum are handed in the switch.
114  GOOGLE_LOG(FATAL) << "Can't get here.";
115  return NULL;
116 }
117 
118 void SetPrimitiveVariables(const FieldDescriptor* descriptor,
119  std::map<string, string>* variables) {
120  std::string primitive_name = PrimitiveTypeName(descriptor);
121  (*variables)["type"] = primitive_name;
122  (*variables)["storage_type"] = primitive_name;
123 }
124 
125 } // namespace
126 
128  const FieldDescriptor* descriptor, const Options& options)
130  SetPrimitiveVariables(descriptor, &variables_);
131 }
132 
134 
136  io::Printer* printer) const {
138  // Nothing, BOOLs are stored in the has bits.
139  } else {
141  }
142 }
143 
146  // Reserve a bit for the storage of the boolean.
147  return 1;
148  }
149  return 0;
150 }
151 
154  // Set into the offset the has bit to use for the actual value.
155  variables_["storage_offset_value"] = StrCat(has_base);
156  variables_["storage_offset_comment"] =
157  " // Stored in _has_storage_ to save space.";
158  }
159 }
160 
162  const FieldDescriptor* descriptor, const Options& options)
164  SetPrimitiveVariables(descriptor, &variables_);
165  variables_["property_storage_attribute"] = "copy";
166 }
167 
169 
171  const FieldDescriptor* descriptor, const Options& options)
173  SetPrimitiveVariables(descriptor, &variables_);
174 
175  string base_name = PrimitiveArrayTypeName(descriptor);
176  if (base_name.length()) {
177  variables_["array_storage_type"] = "GPB" + base_name + "Array";
178  } else {
179  variables_["array_storage_type"] = "NSMutableArray";
180  variables_["array_property_type"] =
181  "NSMutableArray<" + variables_["storage_type"] + "*>";
182  }
183 }
184 
186 
187 } // namespace objectivec
188 } // namespace compiler
189 } // namespace protobuf
190 } // namespace google
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
wire_format_lite.h
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_INT32
@ OBJECTIVECTYPE_INT32
Definition: objectivec_helpers.h:138
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_UINT32
@ OBJECTIVECTYPE_UINT32
Definition: objectivec_helpers.h:139
NULL
NULL
Definition: test_security_zap.cpp:405
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_STRING
@ OBJECTIVECTYPE_STRING
Definition: objectivec_helpers.h:145
google::protobuf::StrCat
string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: strutil.cc:1480
google::protobuf::compiler::objectivec::PrimitiveObjFieldGenerator::PrimitiveObjFieldGenerator
PrimitiveObjFieldGenerator(const FieldDescriptor *descriptor, const Options &options)
Definition: objectivec_primitive_field.cc:161
options
Message * options
Definition: src/google/protobuf/descriptor.cc:3119
FATAL
const int FATAL
Definition: log_severity.h:60
google::protobuf::compiler::objectivec::PrimitiveFieldGenerator::GenerateFieldStorageDeclaration
virtual void GenerateFieldStorageDeclaration(io::Printer *printer) const
Definition: objectivec_primitive_field.cc:135
google::protobuf::compiler::objectivec::PrimitiveFieldGenerator::SetExtraRuntimeHasBitsBase
virtual void SetExtraRuntimeHasBitsBase(int index_base)
Definition: objectivec_primitive_field.cc:152
google::protobuf::compiler::objectivec::Options
Definition: objectivec_helpers.h:50
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
objectivec_helpers.h
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::compiler::objectivec::PrimitiveFieldGenerator::PrimitiveFieldGenerator
PrimitiveFieldGenerator(const FieldDescriptor *descriptor, const Options &options)
Definition: objectivec_primitive_field.cc:127
google::protobuf::compiler::objectivec::PrimitiveFieldGenerator::ExtraRuntimeHasBitsNeeded
virtual int ExtraRuntimeHasBitsNeeded(void) const
Definition: objectivec_primitive_field.cc:144
FieldDescriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:129
google::protobuf::compiler::objectivec::ObjCObjFieldGenerator
Definition: objectivec_field.h:125
strutil.h
google::protobuf::compiler::objectivec::PrimitiveObjFieldGenerator::~PrimitiveObjFieldGenerator
virtual ~PrimitiveObjFieldGenerator()
Definition: objectivec_primitive_field.cc:168
printer.h
GOOGLE_LOG
#define GOOGLE_LOG(LEVEL)
Definition: logging.h:146
google::protobuf::compiler::objectivec::RepeatedFieldGenerator
Definition: objectivec_field.h:140
google::protobuf::compiler::objectivec::PrimitiveFieldGenerator::~PrimitiveFieldGenerator
virtual ~PrimitiveFieldGenerator()
Definition: objectivec_primitive_field.cc:133
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_INT64
@ OBJECTIVECTYPE_INT64
Definition: objectivec_helpers.h:140
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_ENUM
@ OBJECTIVECTYPE_ENUM
Definition: objectivec_helpers.h:147
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_FLOAT
@ OBJECTIVECTYPE_FLOAT
Definition: objectivec_helpers.h:142
google::protobuf::compiler::objectivec::SingleFieldGenerator::GenerateFieldStorageDeclaration
virtual void GenerateFieldStorageDeclaration(io::Printer *printer) const
Definition: objectivec_field.cc:259
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_DATA
@ OBJECTIVECTYPE_DATA
Definition: objectivec_helpers.h:146
google::protobuf::io::Printer
Definition: printer.h:181
type
GLenum type
Definition: glcorearb.h:2695
google::protobuf::compiler::objectivec::ObjectiveCType
ObjectiveCType
Definition: objectivec_helpers.h:137
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_MESSAGE
@ OBJECTIVECTYPE_MESSAGE
Definition: objectivec_helpers.h:148
google::protobuf::compiler::objectivec::RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator
RepeatedPrimitiveFieldGenerator(const FieldDescriptor *descriptor, const Options &options)
Definition: objectivec_primitive_field.cc:170
wire_format.h
google::protobuf::compiler::cpp::PrimitiveTypeName
const char * PrimitiveTypeName(FieldDescriptor::CppType type)
Definition: cpp_helpers.cc:482
google::protobuf::compiler::objectivec::FieldGenerator::variables_
std::map< string, string > variables_
Definition: objectivec_field.h:101
google::protobuf::compiler::objectivec::RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator
virtual ~RepeatedPrimitiveFieldGenerator()
Definition: objectivec_primitive_field.cc:185
google::protobuf::compiler::objectivec::FieldGenerator::descriptor_
const FieldDescriptor * descriptor_
Definition: objectivec_field.h:100
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_DOUBLE
@ OBJECTIVECTYPE_DOUBLE
Definition: objectivec_helpers.h:143
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_UINT64
@ OBJECTIVECTYPE_UINT64
Definition: objectivec_helpers.h:141
objectivec_primitive_field.h
google::protobuf::compiler::objectivec::SingleFieldGenerator
Definition: objectivec_field.h:104
google::protobuf::compiler::objectivec::GetObjectiveCType
ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type)
Definition: objectivec_helpers.cc:665
google::protobuf::compiler::objectivec::OBJECTIVECTYPE_BOOLEAN
@ OBJECTIVECTYPE_BOOLEAN
Definition: objectivec_helpers.h:144
compiler
Definition: plugin.pb.cc:22
google
Definition: data_proto2_to_proto3_util.h:11


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:57